aboutsummaryrefslogtreecommitdiffstats
path: root/examples/iframe_injector
diff options
context:
space:
mode:
authorRouli <rouli.net@gmail.com>2013-01-17 17:33:29 +0200
committerRouli <rouli.net@gmail.com>2013-01-17 17:33:29 +0200
commit446f9f0a0fc12159ba663d3b8bdc8f1206a197c7 (patch)
tree9cb474c3154fb4146cce41e40e25b4a8e3e57d46 /examples/iframe_injector
parent20fa6a30839500207d7d509fe3b8697dbd22a33e (diff)
parent280dd94198931bcd819848a70d68f6f5d9f3270b (diff)
downloadmitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.tar.gz
mitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.tar.bz2
mitmproxy-446f9f0a0fc12159ba663d3b8bdc8f1206a197c7.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'examples/iframe_injector')
-rwxr-xr-xexamples/iframe_injector50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/iframe_injector b/examples/iframe_injector
new file mode 100755
index 00000000..6dd28674
--- /dev/null
+++ b/examples/iframe_injector
@@ -0,0 +1,50 @@
+#!/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._ack()
+
+ 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._ack()
+
+
+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)