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

Leave a Reply

Be the First to Comment!

Notify of
wpDiscuz