diff options
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/quicktun.socks4a/README | 12 | ||||
-rwxr-xr-x | contrib/quicktun.socks4a/quicktun.socks4a | 111 | ||||
-rw-r--r-- | contrib/quicktun.socks4a/run | 28 |
3 files changed, 151 insertions, 0 deletions
diff --git a/contrib/quicktun.socks4a/README b/contrib/quicktun.socks4a/README new file mode 100644 index 0000000..29a4359 --- /dev/null +++ b/contrib/quicktun.socks4a/README @@ -0,0 +1,12 @@ +hacking quicktun through socks4a: + peer one should set REMOTE_FLOAT = 0 + peer two should set REMOTE_FLOAT = 1 + + i've never actually tested this. but + it should "just work" with minimal + shit. if it's really that bad you + can complain to /relayhell/d3v11. + +depends: + quicktun.raw, socat, daemontools, + a lot of fucking patience diff --git a/contrib/quicktun.socks4a/quicktun.socks4a b/contrib/quicktun.socks4a/quicktun.socks4a new file mode 100755 index 0000000..c6d1947 --- /dev/null +++ b/contrib/quicktun.socks4a/quicktun.socks4a @@ -0,0 +1,111 @@ +#!/usr/bin/env python +import subprocess, socket, select, fcntl, sys, os + +DEBUG = os.getenv( 'DEBUG' ,'1' ) +TUN_MODE = os.getenv( 'TUN_MODE' ,'1' ) +INTERFACE = os.getenv( 'ppp-tortun' ,'1' ) +REMOTE_FLOAT = int(os.getenv('REMOTE_FLOAT' ,'1' )) + +LOCAL_ADDRESS = os.getenv( 'LOCAL_ADDRESS' ,'127.0.0.1' ) +LOCAL_PORT = int(os.getenv('LOCAL_PORT' ,'2998' )) + +REMOTE_ADDRESS = os.getenv( 'REMOTE_ADDRESS','127.0.0.2' ) +REMOTE_PORT = int(os.getenv('REMOTE_PORT' ,'2998' )) + +DST_ADDRESS = os.getenv( 'DST_ADDRESS' ,'127.0.0.3' ) +DST_PORT = os.getenv( 'DST_PORT' ,'2998' ) + +SOCKS_ADDRESS = os.getenv( 'LOCAL_ADDRESS' ,'127.0.0.1' ) +SOCKS_PORT = os.getenv( 'LOCAL_PORT' ,'9050' ) + +tcp = socket.socket( + socket.AF_INET,socket.SOCK_STREAM) +tcp.setsockopt (socket.SOL_SOCKET,socket.SO_REUSEADDR,1 ) +tcp.setblocking (0 ) +tcp.bind ((LOCAL_ADDRESS,LOCAL_PORT )) +tcp.listen (1 ) +tcp_poll = select.poll( ) +tcp_poll.register(tcp.fileno(),select.POLLIN|select.POLLPRI ) + +udp = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) +udp.setsockopt (socket.SOL_SOCKET,socket.SO_REUSEADDR,1 ) +udp.setblocking (0 ) +udp.bind ((REMOTE_ADDRESS,REMOTE_PORT )) +udp_poll = select.poll( ) +udp_poll.register(udp.fileno(),select.POLLIN|select.POLLPRI ) + +if REMOTE_FLOAT==0: + tun = subprocess.Popen ( + [ 'socat','stdio','socks4a:'+SOCKS_ADDRESS+':' + +DST_ADDRESS+':'+DST_PORT + +',socksport='+SOCKS_PORT + ], + stdout = subprocess.PIPE, + stdin = subprocess.PIPE, ) + tun_stdout = tun.stdout.fileno ( ) + tun_stdin = tun.stdin.fileno ( ) + tun_poll = select.poll ( ) + tun_poll.register ( + tun.stdout.fileno(), select.POLLIN|select.POLLPRI) + +while REMOTE_FLOAT==1: + if len(tcp_poll.poll(65536))>0: + tun = tcp.accept ()[0] + tun_stdout = tun.fileno ( ) + tun_stdin = tun.fileno ( ) + tun_poll = select.poll ( ) + tun_poll.register ( + tun.fileno(), select.POLLIN|select.POLLPRI) + break + +fcntl.fcntl(tun_stdin,fcntl.F_SETFL,fcntl.fcntl( + tun_stdin,fcntl.F_GETFL)&~os.O_NONBLOCK|os.O_NONBLOCK) +fcntl.fcntl(tun_stdout,fcntl.F_SETFL,fcntl.fcntl( + tun_stdout,fcntl.F_GETFL)&~os.O_NONBLOCK|os.O_NONBLOCK) + +tun = subprocess.Popen(['/usr/sbin/quicktun.raw'], +stdout = subprocess.PIPE, +stdin = subprocess.PIPE ) + +recvq = str( ) +sendq = str( ) + +while 1: + if len(udp_poll.poll(128))>0: + buffer = str( ) + buffer = udp.recv(1024 ) + if len(buffer)==0: + break + sendq = sendq + buffer + + if len(tun_poll.poll(128))>0: + buffer = str( ) + buffer = os.read(tun_stdout,1024 ) + if len(buffer)==0: + break + recvq = recvq + buffer + + if len(sendq)>0: + try: + sendq = sendq[os.write(tun_stdin,sendq[:1024] ) + :] + except OSError as ex: + if ex.errno!=11: + break + + if len(recvq)>0: + try: + recvq = recvq[udp.sendto(recvq[:1024], + (LOCAL_ADDRESS,LOCAL_PORT )) + :] + except OSError as ex: + if ex.errno!=11: + break + + if len(sendq)>65536*128: + break + + if len(recvq)>65536*128: + break + +tun.terminate( ) diff --git a/contrib/quicktun.socks4a/run b/contrib/quicktun.socks4a/run new file mode 100644 index 0000000..181f2cd --- /dev/null +++ b/contrib/quicktun.socks4a/run @@ -0,0 +1,28 @@ +#!/bin/sh -e + +export DEBUG='1' +export TUN_MODE='1' +export INTERFACE='ppp-tortun' +export REMOTE_FLOAT='1' + +export LOCAL_ADDRESS='127.0.0.1' +export LOCAL_PORT='2998' + +export REMOTE_ADDRESS='127.0.0.2' +export REMOTE_PORT='2998' + +export DST_ADDRESS='127.0.0.3' +export DST_PORT='2998' + +export SOCKS_ADDRESS='127.0.0.1' +export SOCKS_PORT='9050' + +( + sleep 8 + ip addr add $LOCAL_PEER_ADDRESS peer $REMOTE_PEER_ADDRESS/32 dev $INTERFACE scope link + ip addr add $LOCAL_ROUTER_ADDRESS/32 dev $INTERFACE scope global + ip link set dev $INTERFACE up + ping -c 1 -I $INTERFACE $REMOTE_PEER_ADDRESS -r -w 5 >/dev/null 2>&1 +) & + +exec "`pwd`"/quicktun.socks4a |