mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 10:26:23 +00:00
0c6663d0d5
- Add an options parameter to the start() event. This is to be used by addons on startup to add custom options. - Add a running() event that is called once the proxy is up and running. - With the new paradigm we can't log during master __init__, so add a tiny termstatus addon to print proxy status to terminal once we're running.
30 lines
833 B
Python
30 lines
833 B
Python
# Usage: mitmdump -s "iframe_injector.py url"
|
|
# (this script works best with --anticache)
|
|
import sys
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
class Injector:
|
|
def __init__(self, iframe_url):
|
|
self.iframe_url = iframe_url
|
|
|
|
def response(self, flow):
|
|
if flow.request.host in self.iframe_url:
|
|
return
|
|
html = BeautifulSoup(flow.response.content, "html.parser")
|
|
if html.body:
|
|
iframe = html.new_tag(
|
|
"iframe",
|
|
src=self.iframe_url,
|
|
frameborder=0,
|
|
height=0,
|
|
width=0)
|
|
html.body.insert(0, iframe)
|
|
flow.response.content = str(html).encode("utf8")
|
|
|
|
|
|
def start(opts):
|
|
if len(sys.argv) != 2:
|
|
raise ValueError('Usage: -s "iframe_injector.py url"')
|
|
return Injector(sys.argv[1])
|