mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 02:10:59 +00:00
update iframe injector example to use BeautifulSoup
This commit is contained in:
parent
25284792a5
commit
9ec7963f8e
@ -1,5 +1,6 @@
|
|||||||
# Usage: mitmdump -s "iframe_injector.py url"
|
# Usage: mitmdump -s "iframe_injector.py url"
|
||||||
# (this script works best with --anticache)
|
# (this script works best with --anticache)
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
from libmproxy.protocol.http import decoded
|
from libmproxy.protocol.http import decoded
|
||||||
|
|
||||||
|
|
||||||
@ -9,10 +10,13 @@ def start(context, argv):
|
|||||||
context.iframe_url = argv[1]
|
context.iframe_url = argv[1]
|
||||||
|
|
||||||
|
|
||||||
def handle_response(context, flow):
|
def response(context, flow):
|
||||||
|
if flow.request.host in context.iframe_url:
|
||||||
|
return
|
||||||
with decoded(flow.response): # Remove content encoding (gzip, ...)
|
with decoded(flow.response): # Remove content encoding (gzip, ...)
|
||||||
c = flow.response.replace(
|
html = BeautifulSoup(flow.response.content)
|
||||||
'<body>',
|
if html.body:
|
||||||
'<body><iframe src="%s" frameborder="0" height="0" width="0"></iframe>' % context.iframe_url)
|
iframe = html.new_tag("iframe", src=context.iframe_url, frameborder=0, height=0, width=0)
|
||||||
if c > 0:
|
html.body.insert(0, iframe)
|
||||||
context.log("Iframe injected!")
|
flow.response.content = str(html)
|
||||||
|
context.log("Iframe inserted.")
|
Loading…
Reference in New Issue
Block a user