Route through socks

From D3xt3r01.tk
Jump to navigationJump to search

WHAT

I was trying to get another computer get out via a tor ( because the app on that computer doesn't support socks .. :| ) So, I routed the whole computer directly through the socks ..

Note: It only works for tcp connections :) ( So, don't expect ICMP testing )

HOW

On the gateway I checked out via svn this shiny piece of code

cd ~
svn checkout http://badvpn.googlecode.com/svn/trunk/ badvpn-read-only
cd ~/badvpn-read-only
cmake ~/badvpn-read-only -DBUILD_NOTHING_BY_DEFAULT=1 -DBUILD_TUN2SOCKS=1
make

Then, In order to get that other computer through the socks .. here's what I did

echo "105 TUN2SOCKS" >> /etc/iproute2/rt_tables # only do this ONCE, no need to add it again .. 

ip tuntap add dev tun0 mode tun user _youruser_ # replace _youruser_ with your account
ifconfig tun0 10.0.0.1/24 up
ssh _somesshserver_ -D 2080 # Connect to your server .. maybe you want to add -i _identityfile_ or -p port ?
~/badvpn-read-only/tun2socks/badvpn-tun2socks --tundev tun0 --netif-ipaddr 10.0.0.2 --netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:2080
ip ru add from 192.168.1.175/32 table TUN2SOCKS # this would be the ip of the other computer that uses this machine as a gateway !
ip ru add from 10.0.0.0/24 table TUN2SOCKS
ip ru add to 10.0.0.0/24 table TUN2SOCKS
ip ro add 10.0.0.0/24 dev tun0 table TUN2SOCKS
ip ro add default via 10.0.0.2 table TUN2SOCKS

That's it .. now if you'd like ( on your laptop for example ) to route everything through the socks ( maybe you have some apps that don't know about proxy stuff ) ..

ip ro del default
ip ro add _sshserver_ via 192.168.1.1 # you still need to know how to get to your ssh server.. replace 192.168.1.1 with your normal gateway ..  
ip tuntap add dev tun0 mode tun user _youruser_ # replace _youruser_ with your account
ifconfig tun0 10.0.0.1/24 up
ip ro add default via 10.0.0.2
ssh _somesshserver_ -D 2080 # Connect to your server .. maybe you want to add -i _identityfile_ or -p port ?
~/badvpn-read-only/tun2socks/badvpn-tun2socks --tundev tun0 --netif-ipaddr 10.0.0.2 --netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:2080


RESOURCES

WIKI page of badvpn's tun2socks project