aboutsummaryrefslogtreecommitdiffstats
path: root/examples/iframe_injector.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-02-18 09:19:05 +1300
committerAldo Cortesi <aldo@nullcube.com>2016-02-18 09:27:08 +1300
commit92597f82ea8e4747ce1836ecd5eb2479486e8647 (patch)
tree2aa391b558d92c0122a16c155d3375d31221cde4 /examples/iframe_injector.py
parent49464de1cb159361c16a232b3d8c267b36e95483 (diff)
downloadmitmproxy-92597f82ea8e4747ce1836ecd5eb2479486e8647.tar.gz
mitmproxy-92597f82ea8e4747ce1836ecd5eb2479486e8647.tar.bz2
mitmproxy-92597f82ea8e4747ce1836ecd5eb2479486e8647.zip
Docs and examples to top level
Diffstat (limited to 'examples/iframe_injector.py')
-rw-r--r--examples/iframe_injector.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/iframe_injector.py b/examples/iframe_injector.py
new file mode 100644
index 00000000..fc38b136
--- /dev/null
+++ b/examples/iframe_injector.py
@@ -0,0 +1,27 @@
+# Usage: mitmdump -s "iframe_injector.py url"
+# (this script works best with --anticache)
+from bs4 import BeautifulSoup
+from mitmproxy.models import decoded
+
+
+def start(context, argv):
+ if len(argv) != 2:
+ raise ValueError('Usage: -s "iframe_injector.py url"')
+ context.iframe_url = argv[1]
+
+
+def response(context, flow):
+ if flow.request.host in context.iframe_url:
+ return
+ with decoded(flow.response): # Remove content encoding (gzip, ...)
+ html = BeautifulSoup(flow.response.content)
+ if html.body:
+ iframe = html.new_tag(
+ "iframe",
+ src=context.iframe_url,
+ frameborder=0,
+ height=0,
+ width=0)
+ html.body.insert(0, iframe)
+ flow.response.content = str(html)
+ context.log("Iframe inserted.")