NetVM: CDP via userspace relay (REDIRECT to loopback did not establish)
This commit is contained in:
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
"""TCP relay: listen on the netns veth IP:CDP_PORT, forward to 127.0.0.1:CDP_PORT.
|
||||
Chromium binds DevTools to loopback only; this exposes it on the veth IP for
|
||||
the host (and SSH-forwarded operators). Runs inside the netns. No dependencies.
|
||||
Usage: netvm-cdp-relay.py <listen_ip> <listen_port> <target_ip> <target_port>
|
||||
"""
|
||||
import socket, threading, sys
|
||||
|
||||
def pipe(src, dst):
|
||||
try:
|
||||
while True:
|
||||
data = src.recv(65536)
|
||||
if not data:
|
||||
break
|
||||
dst.sendall(data)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
for s in (src, dst):
|
||||
try: s.shutdown(socket.SHUT_RDWR)
|
||||
except OSError: pass
|
||||
s.close()
|
||||
|
||||
def handle(client, target):
|
||||
try:
|
||||
upstream = socket.create_connection(target, timeout=10)
|
||||
except OSError:
|
||||
client.close()
|
||||
return
|
||||
threading.Thread(target=pipe, args=(client, upstream), daemon=True).start()
|
||||
pipe(upstream, client)
|
||||
|
||||
def main():
|
||||
listen_ip, listen_port, target_ip, target_port = sys.argv[1], int(sys.argv[2]), sys.argv[3], int(sys.argv[4])
|
||||
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
srv.bind((listen_ip, listen_port))
|
||||
srv.listen(16)
|
||||
while True:
|
||||
client, _ = srv.accept()
|
||||
threading.Thread(target=handle, args=(client, (target_ip, target_port)), daemon=True).start()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user