-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom_proxy.py
51 lines (41 loc) · 1.5 KB
/
custom_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
from proxy.http.proxy import HttpProxyBasePlugin
from proxy.http.parser import HttpParser
from proxy.common.utils import tls_interception_enabled
import proxy
import sys
from pprint import pprint
class OntologyTimeMachinePlugin(HttpProxyBasePlugin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def do_intercept(self, _request: HttpParser) -> bool:
"""By default returns True (only) when necessary flags
for TLS interception are passed.
When TLS interception is enabled, plugins can still disable
TLS interception by returning False explicitly. This hook
will allow you to run proxy instance with TLS interception
flags BUT only conditionally enable interception for
certain requests.
"""
print(f'Do intercept triggered: {vars(_request)}')
# if _request._is_https_tunnel:
# return False
if _request.host == b'example.org':
return True
if _request.host == b'www.example.org':
return False
else:
return True
if __name__ == '__main__':
sys.argv += [
'--ca-key-file', 'ca-key.pem',
'--ca-cert-file', 'ca-cert.pem',
'--ca-signing-key-file', 'ca-signing-key.pem',
]
sys.argv += [
'--hostname', '0.0.0.0',
'--port', '8899',
'--log-level', 'e',
# '--basic-auth', 'user:pass',
'--plugins', __name__ + '.OntologyTimeMachinePlugin'
]
proxy.main()