-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathndbproxy-mitmproxy.py
More file actions
54 lines (42 loc) · 1.63 KB
/
ndbproxy-mitmproxy.py
File metadata and controls
54 lines (42 loc) · 1.63 KB
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
# NOTE: this is currently non-functioning
import atexit
from mitmproxy import ctx
from mitmproxy import http
class NdbProxy:
"""Proxy connection between Node<-->Chrome debugger with a stable URL"""
def __init__(self):
self.bridge = NdbBridge("localhost", 8273)
self.bridge.start()
atexit.register(self.bridge.kill)
def done(self):
print("proxy: done")
self.bridge.kill()
def load(self, loader): # pylint: disable=no-self-use
""" mitmproxy load hook """
loader.add_option(
name="out-file",
typespec=str,
default="",
help="File to output WebSocket messages to",
)
def request(self, flow: http.HTTPFlow) -> None:
"""mitmproxy request hook"""
print("proxy: request")
if flow.request.path != "/debugger":
return
req_headers = flow.request.headers
if not (req_headers["Connection"] == "Upgrade" and req_headers["Upgrade"] == "websocket"):
return
flow.request.host = self.bridge.listen_host
flow.request.port = self.bridge.listen_port
flow.request.path = "/"
def websocket_message(self, flow: http.HTTPFlow) -> None: # pylint: disable=no-self-use
"""mitmproxy websocket_message hook"""
assert flow.websocket is not None
msg = flow.websocket.messages[-1]
kind = "client" if msg.from_client else "server"
file = getattr(ctx.options, 'out-file')
if file:
with open(file, "a") as handle:
handle.write(json.dumps({kind: json.loads(msg.text)}) + "\n")
addons = []