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"
|
||||
# (this script works best with --anticache)
|
||||
from bs4 import BeautifulSoup
|
||||
from libmproxy.protocol.http import decoded
|
||||
|
||||
|
||||
@ -9,10 +10,13 @@ def start(context, argv):
|
||||
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, ...)
|
||||
c = flow.response.replace(
|
||||
'<body>',
|
||||
'<body><iframe src="%s" frameborder="0" height="0" width="0"></iframe>' % context.iframe_url)
|
||||
if c > 0:
|
||||
context.log("Iframe injected!")
|
||||
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.")
|
Loading…
Reference in New Issue
Block a user