Tag: polipo

How to set up multiple Tor instances with Polipo in Windows

How to set up multiple Tor instances with Polipo in Windows

Tor is free software and an open network that helps you defend against traffic analysis, a form of network surveillance that threatens personal freedom and privacy, confidential business activities and relationships, and state security.

By default, Tor opens a SOCK proxy on port 9050 that allow internet traffic to go through to access Tor network.

In this post, we will show how to set up multiple Tor instances on the same Windows machine.

If you want to set up multiple Tor instances with Polipo on Linux, read this post instead.

Install Tor

Installing Tor on Windows is easy.

Go to Tor official download page to download Tor.

Normally, if you download Tor Browser package, you will have a Tor Browser that is already configured to use Tor as a proxy to access the internet.

In our case, we will set up multiple instances of Tor as multiple proxies, which means we need Tor only, so you can download the Expert Bundle.

After you download it, unzip it to wherever you like. The extracted folder should contains:

  • <parent folder>/Tor: contains executable files (exe and dlls)
  • <parent folder>/Data/Tor: the folder contains the data that Tor use to look up geo location of IPs.

If you run tor.exe in the /Tor folder, you can already start a Tor instance now.

Install Polipo

Tor proxy supports SOCKS protocol but does not support HTTP proxy protocol.

To help Tor function as a proxy protocol, we can use Polipo to make a tunnel where Polipo will open a HTTP proxy and transfer the packets between its HTTP proxy and Tor’s SOCKS proxy. That way, an application can leverage Tor’s power even if that application can only communicate through HTTP proxy.

You can download Polipo here.

After downloading Polipo, just extract the zip file. We only need that polipo.exe file.

Set up multiple instances folder structure

In order to run multiple instances, we must set up different port and data folder for each instance using command line arguments.

My set up goes like this

  • MultiTor\bin\Tor: Tor executable folder (contains tor.exe and dlls)
  • MultiTor\bin\Data: Tor geoip folder (extracted from downloaded Tor package)
  • MultiTor\bin\Polipo: Polipo executable folder (contains polipo.exe)
  • MultiTor\data\tor-10001: data folder of Tor instance listening on port 10001
  • MultiTor\data\tor-10002: data folder of Tor instance listening on port 10002

In the above set up, I will use the same executable file for all instances, but different data folders for each instance.

You can have you own set up, as long as the data folders are different among instances.

Start the first instance

Now, to start the first instance, I switch to MultiTor folder and run the following command

bin\Tor\tor.exe GeoIPFile bin\Data\Tor\geoip GeoIPv6File bin\Data\Tor\geoip6 SOCKSPort 127.0.0.1:10001 CONTROLPort 127.0.0.1:20001 DATADirectory data\tor-10001

The command above will start a Tor instance that has

  • 10001 as SOCKS proxy port
  • 20001 as CONTROL port
  • data\tor-10001 as data folder

We will also start a Polipo instance that tunnels through that Tor instance

bin\Polipo\polipo socksParentProxy="127.0.0.1:10001" proxyPort=30001 proxyAddress="127.0.0.1"

The command above will start a Polipo instance that has

  • 30001 as HTTP proxy port
  • talks to Tor proxy on port 10001

Start the next instances

To start the second instance, first we have to edit the command a little bit so that it will start the first instance in a new window, releasing the current command line cursor.

To do that, add start command at the beginning of the script

start bin\Tor\tor.exe GeoIPFile bin\Data\Tor\geoip GeoIPv6File bin\Data\Tor\geoip6 SOCKSPort 127.0.0.1:10001 CONTROLPort 127.0.0.1:20001 DATADirectory data\tor-10001
start bin\Polipo\polipo socksParentProxy="127.0.0.1:10001" proxyPort=30001 proxyAddress="127.0.0.1"

Now we can start the second instance following the same pattern

start bin\Tor\tor.exe GeoIPFile bin\Data\Tor\geoip GeoIPv6File bin\Data\Tor\geoip6 SOCKSPort 127.0.0.1:10002 CONTROLPort 127.0.0.1:20002 DATADirectory data\tor-10002
start bin\Polipo\polipo socksParentProxy="127.0.0.1:10002" proxyPort=30002 proxyAddress="127.0.0.1"

Note that the port numbers and the data folder have been changed for the second instance.

We can start as many instances as we want in this way.

Automate the task

To start a lot of instances, we can make a .bat file to automate the task as following

start_all_tor.bat

CD C:\Tools\MultiTor\
SETLOCAL
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /L %%G IN (10001,1,10100) DO (
 SET /a sp=%%G+0
 SET /a cp=%%G+10000
 echo !sp!
 echo !cp!
 mkdir data\tor-!sp!
 start bin\Tor\tor.exe GeoIPFile bin\Data\Tor\geoip GeoIPv6File bin\Data\Tor\geoip6 SOCKSPort 127.0.0.1:!sp! CONTROLPort 127.0.0.1:!cp! DATADirectory data\tor-!sp!
)
ENDLOCAL

start_all_polipo.bat

CD C:\Tools\MultiTor\
SETLOCAL
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /L %%G IN (10001,1,10100) DO (
 SET /a sp=%%G+0
 SET /a pp=%%G+20000
 echo !sp!
 echo !cp!
 start bin\Polipo\polipo socksParentProxy="127.0.0.1:!sp!" proxyPort=!pp! proxyAddress="127.0.0.1"
)
ENDLOCAL

The first batch script will start 100 Tor proxy instances that listen on port 10001-10100 and have control port from 20001-20100 with data folder from data\tor-10001 to data\tor-10100

The second batch script will start 100 Polipo proxy intances that listen on port 30001-30100 and talks to Tor proxy instances on port 10001-10100 correspondingly.

To stop all the instances, you can run a script like this

stop_all_tor.bat

taskkill /IM tor.exe /F

stop_all_polipo.bat

taskkill /IM polipo.exe /F
How to set up multiple Tor instances with Polipo on Linux

How to set up multiple Tor instances with Polipo on Linux

Tor is free software and an open network that helps you defend against traffic analysis, a form of network surveillance that threatens personal freedom and privacy, confidential business activities and relationships, and state security.

By default, Tor opens a SOCK proxy on port 9050 that allow internet traffic to go through to access Tor network.

In this post, we will show how to set up multiple Tor instances on the same Linux machine.

If you want to set up multiple Tor instances with Polipo on Windows, read this post instead.

Install Tor

On Ubuntu

$ apt update
$ apt install tor

After that, Tor should be accessible via /usr/bin/tor

Install Polipo

Tor proxy supports SOCKS protocol but does not support HTTP proxy protocol.

To help Tor function as a proxy protocol, we can use Polipo to make a tunnel where Polipo will open a HTTP proxy and transfer the packets between its HTTP proxy and Tor’s SOCKS proxy. That way, an application can leverage Tor’s power even if that application can only communicate through HTTP proxy.

On Ubuntu

$ apt update
$ apt install polipo

Start the first instance

After Tor is installed, we can start Tor right away by running /usr/bin/tor.

However, to run multiple instances of Tor, we still have some extra tasks to do.

First of all, when a Tor instance runs, it will need the following things set up

  • a SOCKSPort, where its proxy listens on
  • a CONTROLPort, where it listens to commands from user
  • a DATADirectory, where it use to save data.

Different instances must have these things set up differently.

Fortunately, Tor allows us to set up these things using command line arguments like this

$ /usr/bin/tor SOCKSPort 10001 CONTROLPort 20001 DATADirectory /tmp/tor10001/data

You can also specify which IP address for your Tor instance to listen on

$ /usr/bin/tor SOCKSPort 127.0.0.1:10001 CONTROLPort 127.0.0.1:20001 DATADirectory /tmp/tor10001/data

Let’s start the first instance now

$ mkdir -p /tmp/tor10001/data
$ /usr/bin/tor SOCKSPort 10001 CONTROLPort 20001 DATADirectory /tmp/tor10001/data

We will also start a Polipo instance that tunnels through that Tor instance

$ polipo socksParentProxy="127.0.0.1:10001" proxyPort=30001 proxyAddress="127.0.0.1"

The command above will start a Polipo instance that has

  • 30001 as HTTP proxy port
  • talks to Tor proxy on port 10001

Start the next instances

In order to start the next instnace, first you have to relaunch the first instance to run in background with nohup command

$ mkdir -p /tmp/tor10001/data
$ nohup /usr/bin/tor SOCKSPort 10001 CONTROLPort 20001 DATADirectory /tmp/tor10001/data &
$ nohup polipo socksParentProxy="127.0.0.1:10001" proxyPort=30001 proxyAddress="127.0.0.1" &

nohup also keeps your Tor instance running after you log out of your ssh session.

You can now start the next instances following the same pattern, just change the arguments appropriately

$ mkdir -p /tmp/tor10002/data
$ nohup /usr/bin/tor SOCKSPort 10002 CONTROLPort 20002 DATADirectory /tmp/tor10002/data &
$ nohup polipo socksParentProxy="127.0.0.1:10002" proxyPort=30002 proxyAddress="127.0.0.1" &

Notice the params has changed to 10002 and 20002 correspondingly.

Automate the task

If you want to start a lot of instances, you can make a script to start all the instances automatically like this

start_all_tor.sh

#!/bin/bash

a=10001
b=20001
n=10100

echo "Start multiple Tors"
echo "Begin port " $a
echo "End port " $n

while [ $a -le $n ]
do 
    echo "Start Tor on port" $a
    mkdir -p /tmp/tor$a/data
    nohup /usr/bin/tor SOCKSPort $a CONTROLPort $b DATADirectory /tmp/tor$a/data &
    a=$(($a + 1)) 
    b=$(($b + 1)) 
done

The above script will start 100 Tor instances with SOCKSPort from 10001 to 10100, CONTROLPort from 20001 to 20100 with corresponding data folders.

start_all_polipo.sh

#!/bin/bash
a=10001
b=30001
n=10100
echo "Start multiple Polipo "
echo "Begin port " $a
echo "End port " $n

while [ $a -le $n ]
do
    echo "Start Polipo " $a
    nohup polipo socksParentProxy="127.0.0.1:$a" proxyPort=$b proxyAddress="127.0.0.1" &
    a=$(($a + 1))
    b=$(($b + 1))
done

To stop all the instances, you can run a script like this

stop_all_tor.sh

#!/bin/bash
ps aux | grep tor | awk '{print $2}' | xargs kill -9

stop_all_polipo.sh

#!/bin/bash
ps aux | grep polipo | awk '{print $2}' | xargs kill -9