mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-01-01 03:29:38 +01:00
client now listens on a socket and gets SO_ORIGINAL_DST correctly.
This commit is contained in:
parent
f84b87d7eb
commit
a818105dfe
27
client.py
Normal file
27
client.py
Normal file
@ -0,0 +1,27 @@
|
||||
import struct
|
||||
from socket import *
|
||||
from helpers import *
|
||||
|
||||
|
||||
def original_dst(sock):
|
||||
SO_ORIGINAL_DST = 80
|
||||
SOCKADDR_MIN = 16
|
||||
sockaddr_in = sock.getsockopt(SOL_IP, SO_ORIGINAL_DST, SOCKADDR_MIN)
|
||||
(proto, port, a,b,c,d) = struct.unpack('!hhBBBB', sockaddr_in[:8])
|
||||
assert(htons(proto) == AF_INET)
|
||||
ip = '%d.%d.%d.%d' % (a,b,c,d)
|
||||
return (ip,port)
|
||||
|
||||
|
||||
def main(remotename, subnets):
|
||||
log('Starting sshuttle proxy.\n')
|
||||
listener = socket()
|
||||
listener.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
|
||||
listener.bind(('0.0.0.0',1234))
|
||||
listener.listen(10)
|
||||
log('Listening on %r.\n' % (listener.getsockname(),))
|
||||
while 1:
|
||||
s,srcip = listener.accept()
|
||||
dstip = original_dst(s)
|
||||
print 'Incoming connection from %r to %r.' % (srcip,dstip)
|
||||
|
6
helpers.py
Normal file
6
helpers.py
Normal file
@ -0,0 +1,6 @@
|
||||
import sys, os
|
||||
|
||||
def log(s):
|
||||
sys.stdout.flush()
|
||||
sys.stderr.write(s)
|
||||
sys.stderr.flush()
|
Loading…
Reference in New Issue
Block a user