diff options
author | Maximilian Hils <git@maximilianhils.com> | 2014-09-05 15:05:44 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2014-09-05 15:05:44 +0200 |
commit | f2570c773aa18e4ac236b1cf7f43acfb4ca080dd (patch) | |
tree | 10ed3ad13060e33864a8cd00c54317340d07425c | |
parent | a7a3b5703adff7de12fb479a90ea2628465a4486 (diff) | |
download | mitmproxy-f2570c773aa18e4ac236b1cf7f43acfb4ca080dd.tar.gz mitmproxy-f2570c773aa18e4ac236b1cf7f43acfb4ca080dd.tar.bz2 mitmproxy-f2570c773aa18e4ac236b1cf7f43acfb4ca080dd.zip |
iframe injector example: use inline script
-rwxr-xr-x | examples/iframe_injector | 50 | ||||
-rw-r--r-- | examples/iframe_injector.py | 18 | ||||
-rw-r--r-- | test/test_examples.py | 2 |
3 files changed, 20 insertions, 50 deletions
diff --git a/examples/iframe_injector b/examples/iframe_injector deleted file mode 100755 index 8b1e02f1..00000000 --- a/examples/iframe_injector +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python -""" - Zap encoding in requests and inject iframe after body tag in html responses. - Usage: - iframe_injector http://someurl/somefile.html -""" -from libmproxy import controller, proxy -import os -import sys - - -class InjectingMaster(controller.Master): - def __init__(self, server, iframe_url): - controller.Master.__init__(self, server) - self._iframe_url = iframe_url - - def run(self): - try: - return controller.Master.run(self) - except KeyboardInterrupt: - self.shutdown() - - def handle_request(self, msg): - if 'Accept-Encoding' in msg.headers: - msg.headers["Accept-Encoding"] = 'none' - msg.reply() - - def handle_response(self, msg): - if msg.content: - c = msg.replace('<body>', '<body><iframe src="%s" frameborder="0" height="0" width="0"></iframe>' % self._iframe_url) - if c > 0: - print 'Iframe injected!' - msg.reply() - - -def main(argv): - if len(argv) != 2: - print "Usage: %s IFRAME_URL" % argv[0] - sys.exit(1) - iframe_url = argv[1] - config = proxy.ProxyConfig( - cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem") - ) - server = proxy.ProxyServer(config, 8080) - print 'Starting proxy...' - m = InjectingMaster(server, iframe_url) - m.run() - -if __name__ == '__main__': - main(sys.argv) diff --git a/examples/iframe_injector.py b/examples/iframe_injector.py new file mode 100644 index 00000000..7042dbab --- /dev/null +++ b/examples/iframe_injector.py @@ -0,0 +1,18 @@ +# Usage: mitmdump -s "iframe_injector.py url" +# (this script works best with --anticache) +from libmproxy.protocol.http import decoded + + +def start(ctx, argv): + if len(argv) != 2: + raise ValueError('Usage: -s "iframe_injector.py url"') + ctx.iframe_url = argv[1] + + +def handle_response(ctx, flow): + with decoded(flow.response): # Remove content encoding (gzip, ...) + c = flow.response.replace( + '<body>', + '<body><iframe src="%s" frameborder="0" height="0" width="0"></iframe>' % ctx.iframe_url) + if c > 0: + ctx.log("Iframe injected!")
\ No newline at end of file diff --git a/test/test_examples.py b/test/test_examples.py index d18b5862..d557080e 100644 --- a/test/test_examples.py +++ b/test/test_examples.py @@ -12,6 +12,8 @@ def test_load_scripts(): tmaster = tservers.TestMaster(config.ProxyConfig()) for f in scripts: + if "iframe_injector" in f: + f += " foo" # one argument required if "modify_response_body" in f: f += " foo bar" # two arguments required script.Script(f, tmaster) # Loads the script file.
\ No newline at end of file |