Tunneling traffic over tor network using proxychains

Fazle Arefin
System Weakness
Published in
2 min readJan 3, 2022

--

VPNs are great for hiding your IP address. However, you are at the mercy of the VPN provider to protect your identity. This is where tor comes in. You can route your traffic over the tor network without any costly VPN subscription. The tor network is decentralized and hence it is harder to track traffic over the tor network and hence it is better at protecting your identity. tor is not just for browsing the dark web.

Note that tor network can be very slow since the traffic is passing through 3 different nodes. It may not be ideal for hacking your geo-location to watch Netflix content from another country.

Instructions below are for Ubuntu 20.04. You will need to do your homework for other distributions.

00. Install tor and make sure it is running

sudo apt install tor
sudo systemctl enable tor --now
systemctl status tor

Optionally, specify the exit node country/countries (RU is Russia, look up 2 letter ISO code for other countries)

echo 'ExitNodes {RU}' | sudo tee --append /etc/tor/torrc
sudo systemctl restart tor

01. Install proxychains4

sudo apt install proxychains4

Optionally, make proxychains4 use SOCKS5 protocol

sudo sed -i -E 's|^socks[0–9]?.*|socks5 127.0.0.1 9050|' /etc/proxychains4.conf

02. Let’s see it in action

Check your location without going through tor network

vagrant@ubuntu-focal:~$ curl https://ipinfo.io/city
Warsaw
vagrant@ubuntu-focal:~$

I am from Warsaw, Poland(?)

Check your location going through tor network

vagrant@ubuntu-focal:~$ proxychains4 curl ipinfo.io/city
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain … 127.0.0.1:9050 … ipinfo.io:80 … OK
Moscow
vagrant@ubuntu-focal:~$

Now I am from Moscow, Russia!

ssh can be tunneled through tor as well

vagrant@ubuntu-focal:~$ nc -vz github.com 22
Connection to github.com 22 port [tcp/ssh] succeeded!
vagrant@ubuntu-focal:~$
vagrant@ubuntu-focal:~$ proxychains4 nc -vz github.com 22
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain … 127.0.0.1:9050 … github.com:22 … OK
Connection to github.com 22 port [tcp/ssh] succeeded!
vagrant@ubuntu-focal:~$

Make Firefox (or Google Chrome) use the tor network

Using proxychains4

Close all open browser windows of Firefox (or google chrome) first and then launch Firefox (or google chrome) from the terminal

proxychains4 firefox

Using Firefox Plugins

An easier approach is to use the FoxyProxy extension for Firefox. That way you won’t have to close your existing browser session and relaunch.

After you have installed FoxyProxy, you need to use the following settings in FoxyProxy to route traffic through Tor:

Proxy Type: SOCKS5
Proxy IP address: 127.0.0.1
Port: 9050

(There is another official plugin from Firefox as well called Firefox Multi-Account Containers using which you can have certain tabs open in the tor container to use tor and others not. You need to configure a tor container and set socks://localhost:9050 in Advanced Proxy settings.)

Troubleshooting

If you get timed out when using proxychains, simply restart the tor service to create a new circuit or use a new country in /etc/tor/torrc and restart tor service

sudo systemctl restart tor

Disclaimer

All information here is for educational purpose.

--

--