aboutsummaryrefslogtreecommitdiffstats
path: root/examples/iframe_injector.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2014-09-07 12:59:35 +1200
committerAldo Cortesi <aldo@corte.si>2014-09-07 12:59:35 +1200
commit3d62e90dbf7ea05283e16752531a261e53a4bb47 (patch)
treec3f5aed62bcf13378522968a1c77375dc8102b53 /examples/iframe_injector.py
parent0e0cff638c1e055275e77e2af0ae540542f77197 (diff)
parentfdd7b2f108717900e39e3d0ab220ee65b79304ef (diff)
downloadmitmproxy-3d62e90dbf7ea05283e16752531a261e53a4bb47.tar.gz
mitmproxy-3d62e90dbf7ea05283e16752531a261e53a4bb47.tar.bz2
mitmproxy-3d62e90dbf7ea05283e16752531a261e53a4bb47.zip
Merge pull request #342 from mitmproxy/server_change_api
Server change api
Diffstat (limited to 'examples/iframe_injector.py')
-rw-r--r--examples/iframe_injector.py18
1 files changed, 18 insertions, 0 deletions
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