client now listens on a socket and gets SO_ORIGINAL_DST correctly.

This commit is contained in:
Avery Pennarun 2010-05-01 18:03:45 -04:00
parent f84b87d7eb
commit a818105dfe
2 changed files with 33 additions and 0 deletions

27
client.py Normal file
View 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
View File

@ -0,0 +1,6 @@
import sys, os
def log(s):
sys.stdout.flush()
sys.stderr.write(s)
sys.stderr.flush()