originally from git.lmitsystems.de/lukas/brainfuck2ook.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0KB

  1. # Usage: mitmdump -s "js_injector.py src"
  2. # (this script works best with --anticache)
  3. from bs4 import BeautifulSoup
  4. from mitmproxy import ctx, http
  5. import argparse
  6. class Injector:
  7. def __init__(self, path):
  8. self.path = path
  9. def response(self, flow: http.HTTPFlow) -> None:
  10. if self.path:
  11. html = BeautifulSoup(flow.response.content, "html.parser")
  12. print(self.path)
  13. print(flow.response.headers["content-type"])
  14. if flow.response.headers["content-type"] == 'text/html':
  15. print(flow.response.headers["content-type"])
  16. script = html.new_tag(
  17. "script",
  18. src=self.path,
  19. type='application/javascript')
  20. html.body.insert(0, script)
  21. flow.response.content = str(html).encode("utf8")
  22. print("Script injected.")
  23. def start():
  24. parser = argparse.ArgumentParser()
  25. parser.add_argument("path", type=str)
  26. args = parser.parse_args()
  27. return Injector(args.path)