Last active
April 19, 2017 15:48
-
-
Save wtnabe/2c14c23da7d5bcc9605bbcde0a356033 to your computer and use it in GitHub Desktop.
mitmproxy script for injecting script tag for loading weinre
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
import argparse | |
class Weinrer: | |
def __init__(self, host, port): | |
self.host = host | |
self.port = port | |
def response(self, flow): | |
text = flow.response.text | |
if len(text) > 0 and hasattr(text, 'find') and text.find('</head>') > -1: | |
flow.response.set_text(text.replace( | |
'</head>', | |
'<script src="http://{self.host}:{self.port}/target/target-script-min.js#anonymous"></script></head>'.format(self=self))) | |
def start(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('host', type=str, default='localhost') | |
parser.add_argument('port', type=str, default='8080') | |
args = parser.parse_args() | |
return Weinrer(args.host, args.port) | |
""" | |
Usage: | |
$ mitmproxy -s 'weinre.py 192.168.0.5 8080' | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment