-
-
Save dweinstein/754bbb2013ed4f619e74d21709f3c3c9 to your computer and use it in GitHub Desktop.
extract params for gpapi automatically from a mitmproxy trace
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
#!/usr/bin/env python | |
import base64 | |
import binascii | |
import hashlib | |
import json | |
import os | |
import sys | |
import urllib | |
import datetime | |
from mitmproxy import io | |
from mitmproxy import exceptions | |
def dumps(data_dict): | |
import json | |
js = None | |
for possible_encoding in ["utf-8", "ISO-8859-1"]: | |
try: | |
js = json.dumps(data_dict, encoding=possible_encoding) | |
break | |
except UnicodeDecodeError: | |
pass | |
if js is None: | |
raise UnicodeDecodeError | |
return js | |
def handle_download(flow): | |
headers = flow.request.headers | |
ua = headers.get('user-agent') | |
if not handle_download.GOT_DOWNLOAD_UA: | |
print ("downloadUserAgent=\"{}\"".format(ua)) | |
handle_download.GOT_DOWNLOAD_UA = True | |
handle_download.GOT_DOWNLOAD_UA = False | |
def handle_details(flow): | |
headers = flow.request.headers | |
ua = headers.get('user-agent') | |
device_id = headers.get('x-dfe-device-id') | |
if not handle_details.GOT_API_UA: | |
print ("apiUserAgent=\"{}\"".format(ua)) | |
print ("ANDROID_ID=\"{}\"".format(device_id)) | |
handle_details.GOT_API_UA = True | |
handle_details.GOT_API_UA = False | |
def handle_flow(flow): | |
if "/details" in flow.request.url: | |
handle_details(flow) | |
if "/Download" in flow.request.url: | |
handle_download(flow) | |
def main(input_path, search_points=[], assumptions=[]): | |
with open(input_path, "rb") as logfile: | |
freader = io.FlowReader(logfile) | |
try: | |
for f in freader.stream(): | |
handle_flow(f) | |
except exceptions.FlowReadException as v: | |
sys.stderr.write("Flow file corrupted. Stopped loading.\n") | |
raise v | |
if __name__ == "__main__": | |
import argparse | |
parser = argparse.ArgumentParser(description='mitmdump log extractor') | |
parser.add_argument('input', help='input file path') | |
args = parser.parse_args() | |
main(input_path=args.input) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment