-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_mitm_proxy.py
63 lines (48 loc) · 1.62 KB
/
start_mitm_proxy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
#!/usr/bin/python3
from mitmproxy.options import Options
from mitmproxy.proxy.config import ProxyConfig
from mitmproxy.proxy.server import ProxyServer
from mitmproxy.tools.dump import DumpMaster
import argparse
GOOGLE_URL = 'googleapis.com'
class Addon(object):
def __init__(self, token):
super().__init__()
self.token = token
def request(self, flow):
'''
Simple search and replace of the token in the HTTP request
'''
if GOOGLE_URL in flow.request.pretty_url:
# print(flow.request.pretty_url)
# print(flow.request.headers)
if 'oauth2' not in flow.request.pretty_url:
flow.request.headers['authorization'] = 'Bearer %s' % self.token
class ProxyMaster(DumpMaster):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def run(self):
try:
DumpMaster.run(self)
except KeyboardInterrupt:
self.shutdown()
if __name__ == "__main__":
# Parse args
parser = argparse.ArgumentParser()
parser.add_argument("--token", type=str, help="Auth token")
parser.add_argument("--port", type=str, help="Port to listen to")
args = parser.parse_args()
# Set options
options = Options(
listen_host='0.0.0.0',
listen_port=int(args.port),
http2=True
)
config = ProxyConfig(options)
# Create master
master = ProxyMaster(options, with_termlog=False, with_dumper=False)
master.server = ProxyServer(config)
master.addons.add(Addon(args.token))
# Run the proxy
master.run()