|
tun2socks
Introductiontun2socks is used to "socksify" TCP (IPv4 only) connections at the network layer. It implements a TUN virtual network interface which accepts all incoming TCP connections (regardless of destination IP), and forwards them through a SOCKS server. This allows you to forward all connections through SOCKS, without any need for application support. It can be used, for example, to forward connections through a remote SSH server. Because of how it works, it can even be installed on a Linux router to transparently forward clients through SOCKS. Installationtun2socks is part of BadVPN. If you're on Linux, just build BadVPN with its CMake build system (or use the Gentoo overlay, the Arch AUR or Ubuntu PPA packages). Note that you need the NSS and OpenSSL libraries to do that. Alternatively, you can use a shell script to compile tun2socks only, in case the CMake or library dependencies are problematic for you: http://badvpn.googlecode.com/svn/trunk/compile-tun2sock.sh . If you're on Windows, simply grab the Windows build of BadVPN. Example (tunelling through SSH)First create a TUN device:
Configure IP for the device: assign IP address 10.0.0.1, netmask 255.255.255.0. Now start the program (on Linux, run it as <someuser>): badvpn-tun2socks --tundev <tun_spec> --netif-ipaddr 10.0.0.2 --netif-netmask 255.255.255.0 --socks-server-addr 127.0.0.1:1080 where <tun_spec> is:
NOTE: --netif-ipaddr 10.0.0.2 is not a typo. It specifies the IP address of the virtual router inside the TUN device, and must be different than the IP of the TUN interface itself. Now you should be able to ping the virtual router's IP (10.0.0.2). Connect to the SSH server, passing -D localhost:1080 to the ssh command to enable dynamic forwarding. This will make ssh open a local SOCKS server which badvpn-tun2socks will use. If you use Putty, go to Connection->SSH->Tunnels, type 1080 in Source port, choose Dynamic and click Add. All that remains is to route connections through the TUN device instead of the existing default gateway. This is done as follows:
This will make all external connections go through the TUN device, except for the SSH connection (else SSH would go through the TUN device, which would go through... SSH). For example (assuming there are no existing default routes with metric <=6; otherwise remove them or change their metrics), in Linux: route add <IP_of_SSH_server> gw <IP_of_original_gateway> metric 5 <same for DNS> route add default gw 10.0.0.2 metric 6 Or on Windows (NOTE: tun2socks must be running and the interface of the default gateway must be working for these to succeed): route add <IP_of_SSH_server> <IP_of_original_gateway> metric 5 <same for DNS> route add 0.0.0.0 mask 0.0.0.0 10.0.0.2 metric 6 These routes will not persist across a reboot. You should probably make scripts that install and remove them. You can remove a route by changing the add to del or delete, depending on whether you're in Linux or Windows. UDP forwardingtun2socks can forward UDP, however this requires a daemon, badvpn-udpgw to run on the remote SSH server. To enable UDP forwarding:
Using with TorThe goal here is to have all connections initiating from a virtual machine go through Tor via tun2socks. NOTE: It is not currently possible to use tun2socks with Tor on a single host without a virtual machine; that would require dynamically updating the routing table based on which Tor nodes are used. WARNING: software in the VM may reveal information about you without your knowledge. The Tor project recommends only using the Tor Browser Bundle as your web browser. However, it is not possible to properly use this browser together with transparent proxying as described here. You should however at least use something like Chrome's Incognito mode; however, this is not equivalent to using the bundle. You can read more about the privacy features of the Tor Browser Bundle you may be missing on in this document. NOTE: DNS queries done by the guest will be slower than if applications were directly configured to use Tor. The following steps show how to set transparent proxying for the virtual machine.
All traffic from the VM should now be going through TOR. TCP connections will be intercepted by tun2socks and will be sent through Tor's SOCKS server; DNS queries will be sent by the guest's OS directly to Tor's DNS server. UDP will not work because Tor doesn't support UDP. This configuration has been tested using a Linux host and a Windows XP guest; however, it should work with any OS combination assuming the relevant software (tor, tun2socks) is supported. In particular, you're limited to Linux and Windows guests. NOTE: Tor will issue warnings that IP addresses come without hostnames: "Warning: Your application (using socks5 to port 80) is giving Tor only an IP address....". This is normal and you might be able to silence it by adding these to torrc: SafeSocks 0 TestSocks 0 WarnUnsafeSocks 0 |