-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.release v2.0.0 2.Personal customized version of 爱问医生
- Loading branch information
1 parent
6486e29
commit 8b7e70c
Showing
20 changed files
with
446 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# -*- coding: utf-8 -*- | ||
import gzip | ||
import os | ||
import urllib | ||
import urllib.parse | ||
import urllib.error | ||
from pprint import pprint | ||
|
||
import mitmproxy | ||
from mitmproxy import http | ||
from mitmproxy import ctx | ||
import base64 | ||
import json | ||
from garbevents.settings import Settings as ST | ||
|
||
|
||
class GetData: | ||
""" | ||
Personal customized version of 爱问医生 | ||
A engine HTTP request class. | ||
""" | ||
events_list = [] | ||
|
||
@staticmethod | ||
def chunks(arr, n): | ||
""" | ||
:param arr: | ||
:param n: | ||
:return: | ||
""" | ||
return [arr[i:i + n] for i in range(0, len(arr), n)] | ||
|
||
@staticmethod | ||
def gzip_decompress(data): | ||
""" | ||
解密上报数据 | ||
:param data: | ||
:return: | ||
""" | ||
try: | ||
return gzip.decompress(data) | ||
except AttributeError: | ||
from io import StringIO | ||
|
||
buf = StringIO() | ||
buf.write(data) | ||
fd = gzip.GzipFile(fileobj=buf, mode="r") | ||
fd.rewind() | ||
value = fd.read() | ||
fd.close() | ||
return value | ||
|
||
def request(self, flow: mitmproxy.http.HTTPFlow): | ||
""" | ||
代理服务数据分析 | ||
:param flow: | ||
:return: | ||
""" | ||
|
||
request_data = flow.request | ||
self.request_url = request_data.url | ||
|
||
if ST.url in self.request_url: | ||
|
||
ctx.log.info("Get the complete URL after splitting ====>{}".format(self.request_url.split('?')[0])) | ||
api = self.request_url.split('?')[0].split('/')[3] | ||
ctx.log.error("Get API address after splitting ====>{}".format(api)) | ||
|
||
request_content = str(self.request_url).split('&')[1].split('=')[1] | ||
ctx.log.info("Get encrypted data after splitting ====>{}".format(request_content)) | ||
|
||
gzip_data = urllib.parse.unquote(request_content) | ||
data_list = [json.loads(base64.b64decode(gzip_data).decode('utf8', errors='ignore'))] | ||
|
||
for result_list in data_list: | ||
ctx.log.error("Get JSON string after decrypting data ====>") | ||
pprint(result_list) | ||
|
||
try: | ||
event = result_list["event"] | ||
ctx.log.error("Get the event name after decrypting the data ====>{}".format(event)) | ||
self.events_list.append(event) | ||
except KeyError: | ||
ctx.log.warn("No events!") | ||
event_list = list(set(self.events_list)) | ||
|
||
if not os.path.exists(ST.report_path): | ||
os.mkdir(ST.report_path) | ||
ctx.log.info(ST.report_path + 'Successfully created!') | ||
|
||
file = open('{}/now_event.txt'.format(ST.report_path), 'w') | ||
for line in event_list: | ||
file.write(line + '\n') | ||
ctx.log.warn("Current event name collection ====>{}".format(event_list)) | ||
lost_list = list(set(ST.all_events).difference(set(event_list))) | ||
ctx.log.warn("Missing event name collection ====>{}".format(lost_list)) | ||
file = open('{}/lost_event.txt'.format(ST.report_path), 'w') | ||
for line in lost_list: | ||
file.write(line + '\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# -*- coding: utf-8 -*- | ||
import base64 | ||
import gzip | ||
import os | ||
import urllib | ||
import urllib.parse | ||
import urllib.error | ||
from pprint import pprint | ||
|
||
import mitmproxy | ||
from mitmproxy import http | ||
from mitmproxy import ctx | ||
import json | ||
from garbevents.settings import Settings as ST | ||
|
||
|
||
class GetData: | ||
""" | ||
Personal customized version of GrowingIO | ||
A garbevents HTTP request class. | ||
""" | ||
events_list = [] | ||
|
||
@staticmethod | ||
def chunks(arr, n): | ||
""" | ||
:param arr: | ||
:param n: | ||
:return: | ||
""" | ||
return [arr[i:i + n] for i in range(0, len(arr), n)] | ||
|
||
@staticmethod | ||
def gzip_decompress(data): | ||
""" | ||
解密上报数据 | ||
:param data: | ||
:return: | ||
""" | ||
try: | ||
return gzip.decompress(data) | ||
except AttributeError: | ||
from io import StringIO | ||
|
||
buf = StringIO() | ||
buf.write(data) | ||
fd = gzip.GzipFile(fileobj=buf, mode="r") | ||
fd.rewind() | ||
value = fd.read() | ||
fd.close() | ||
return value | ||
|
||
def request(self, flow: mitmproxy.http.HTTPFlow): | ||
""" | ||
代理服务数据分析 | ||
:param flow: | ||
:return: | ||
""" | ||
|
||
request_data = flow.request | ||
self.request_url = request_data.url | ||
|
||
if ST.url in self.request_url: | ||
|
||
ctx.log.info("Get the complete URL after splitting ====>{}".format(self.request_url)) | ||
api = self.request_url.split('/')[3] | ||
ctx.log.error("Get API address after splitting ====>{}".format(api)) | ||
|
||
request_content = flow.request.content.decode('utf8', errors='ignore') | ||
ctx.log.info("Get encrypted data after splitting ====>{}".format(request_content)) | ||
|
||
gzip_data = urllib.parse.unquote(request_content) | ||
data_list = json.loads(gzip_data) | ||
|
||
for result_list in data_list: | ||
ctx.log.error("Get JSON string after decrypting data ====>") | ||
pprint(result_list) | ||
|
||
try: | ||
event = result_list["n"] | ||
ctx.log.error("Get the event name after decrypting the data ====> {}".format(event)) | ||
self.events_list.append(event) | ||
except KeyError: | ||
ctx.log.warn("No events!") | ||
event_list = list(set(self.events_list)) | ||
|
||
if not os.path.exists(ST.report_path): | ||
os.mkdir(ST.report_path) | ||
ctx.log.info(ST.report_path + 'Successfully created!') | ||
|
||
file = open('{}/now_event.txt'.format(ST.report_path), 'w') | ||
for line in event_list: | ||
file.write(line + '\n') | ||
ctx.log.warn("Current event name collection ====>{}".format(event_list)) | ||
lost_list = list(set(ST.all_events).difference(set(event_list))) | ||
ctx.log.warn("Missing event name collection ====>{}".format(lost_list)) | ||
file = open('{}/lost_event.txt'.format(ST.report_path), 'w') | ||
for line in lost_list: | ||
file.write(line + '\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.