# How to randomize 44 TOR instances with IPFW for better anonimity.



## Maxiu (Aug 10, 2017)

For mixing tor's instances and do hell in log wee will use FoxyProxy and Spoofing User Angent ads-on for Firefox with custom config.

0. Install tor.
1. Configuring TOR deamon.
On default compilation without edit source code of TOR, we can enable max 10 Tor instances. Without default tor config max avaliabile instances is 9. For enable it we must edit tor deamon.

So:
`ee /usr/local/etc/rc.d/tor`

Find this part


```
if [ -z "${instance}" -a -n "${tor_instances}" ]; then
  inst_only="$2"
  inst_done=0
  for i in ${tor_instances}; do
    inst_name=${i%%:*}
    if [ -z "${inst_only}" -o "${inst_name}" = "${inst_only}" ]; then
      echo -n "${name} instance ${inst_name}: "
      if ! slave_instance=${i} /usr/local/etc/rc.d/tor "$1"; then
        exit_code=1
      fi
      inst_done=$((inst_done+1))
    fi
  done
  if [ -z "${inst_only}" -o "${inst_only}" = "main" ]; then
    checkyesno tor_disable_default_instance && return $exit_code
    echo -n "${name} main instance: "
  elif [ -n "${inst_only}" ]; then
    [ $inst_done -gt 0 ] || err 1 "${name} instance '$inst_only' isn't defined"
    return  $exit_code
  fi
fi
```

And change section inst_only="$2" to inst_only="$9" escape ee and save changes.

Mumbers 2-9 is a numbers avalible tor proces. Custom name of theme can be setting in rc.conf, for easier to edit every proces will be named using number.

1a. Configuring TOR config file for every instances.
In this step we will configuring IP and port using by TOR:

Go to tor config directory:
`cd /usr/local/etc/tor/`

clear torrc file, remove it and do it again, or search and find SOCKPort secion and add follow:
`SOCKSPort 127.0.0.1:10001`

now copy TORRC config file to the same folder but change name like this:
`cp torrc torrc@2`

edit it and change listenig port like this:
`SOCKSPort 127.0.0.1:10002`

Now copy again torrc config but set name as @3
`cp torrc torrc@3`

edit it and change listenig port like this:
`SOCKSPort 127.0.0.1:10003`

and repet this operation 44 times 

Now he have preparing config for 44 instances of TOR.

1b. Enable tor in head swiching table.
For enable first 10 tor instances, add in /etc/rc.conf at follow:

```
tor_enable="YES"
tor_instances="9 8 7 6 5 4 3 2"
```

2. MORE OF TOR.
Now we have a 10 (default is torrc) tor instances, listening on 127.0.0.1:10001-10009.
For more of them we must do "new" deamon. So we just can copy deamon, bin file, and little changing it. So:

```
cp /usr/local/etc/rc.d/tor /usr/local/etc/rc.d/tor2
cp /usr/local/etc/tor /usr/local/etc/tor2
cp /usr/local/bin/tor /usr/local/bin/tor2
cp /var/db/tor /var/db/tor2
```

repeat this operation 6 times.

2a Edit tor deamon.
Change oryginal file like this shame (use online comparing site)
This is oryginal: https://pastebin.com/hrYqxi69
This is edit: https://pastebin.com/sXaESP3i

and reapet it for every new deamon.

and follow in rc.conf

```
tor_enable="YES"
tor_instances="9 8 7 6 5 4 3 2"

tor2_enable="YES"
tor2_instances="17 16 15 14 13 12 11 10"
tor2_disable_default_instance="YES"

tor3_enable="YES"
tor3_instances="26 25 24 23 22 21 20 19 18"
tor3_disable_default_instance="YES"

tor4_enable="YES"
tor4_instances="35 34 33 32 31 30 29 28 27"
tor4_disable_default_instance="YES"

tor5_enable="YES"
tor5_instances="44 43 42 41 40 39 38 37 36"
tor5_disable_default_instance="YES"
```
do it by hand for every deamon:

```
mkdir -p ${/var/db/tor} &&
chown ${_tor}:${_tor} ${/var/db/tor} &&
chmod 0700 $/var/db/tor} &&

mkdir -p ${/var/db/tor2} &&
chown ${_tor}:${_tor} ${/var/db/tor2} &&
chmod 0700 $/var/db/tor2} &&

mkdir -p ${/var/db/tor3} &&
chown ${_tor}:${_tor} ${/var/db/tor3} &&
chmod 0700 $/var/db/tor3} &&
```

...

Now we have a 44 TOR instances listening on 127.0.0.1:10001-10044

3. IPFW.
Connection from TOR can be restricted using wirewall like a "normal" insternet I am using IPFW so for ipfw config scheme look like this:


```
#ab="denny"
ab="allow"

#log="log"
log=""

all="TCP"

ipfw -q add $ab $log $all from 127.0.0.1 10001 to 127.0.0.1 via lo0
ipfw -q add $ab $log $all from 127.0.0.1 to 127.0.0.1 10001 via lo0

ipfw -q add $ab $log $all from 127.0.0.1 10002 to 127.0.0.1 via lo0
ipfw -q add $ab $log $all from 127.0.0.1 to 127.0.0.1 10002 via lo0

ipfw -q add $ab $log $all from 127.0.0.1 10003 to 127.0.0.1 via lo0
ipfw -q add $ab $log $all from 127.0.0.1 to 127.0.0.1 10003 via lo0

ipfw -q add $ab $log $all from 127.0.0.1 10004 to 127.0.0.1 via lo0
ipfw -q add $ab $log $all from 127.0.0.1 to 127.0.0.1 10004 via lo0

ipfw -q add $ab $log $all from 127.0.0.1 10005 to 127.0.0.1 via lo0
ipfw -q add $ab $log $all from 127.0.0.1 to 127.0.0.1 10005 via lo0
```

4. RANDOMIZE IT!
For randomize it easiest way is using FoxyProxy. In future i will be using a SQUID and VPN via TOR.

4a Install FoxyProxy for firefox. Do somewhere tor.pac file and paste at follow:


```
var proxies = [
  "SOCKS5 127.0.0.1:10001",
  "SOCKS5 127.0.0.1:10002",
  "SOCKS5 127.0.0.1:10003",
  "SOCKS5 127.0.0.1:10004",
  "SOCKS5 127.0.0.1:10005",
  "SOCKS5 127.0.0.1:10006",
  "SOCKS5 127.0.0.1:10007",
  "SOCKS5 127.0.0.1:10008",
  "SOCKS5 127.0.0.1:10009",
  "SOCKS5 127.0.0.1:10010",
  "SOCKS5 127.0.0.1:10011",
  "SOCKS5 127.0.0.1:10012",
  "SOCKS5 127.0.0.1:10013",
  "SOCKS5 127.0.0.1:10014",
  "SOCKS5 127.0.0.1:10016",
  "SOCKS5 127.0.0.1:10017",
  "SOCKS5 127.0.0.1:10018",
  "SOCKS5 127.0.0.1:10019",
  "SOCKS5 127.0.0.1:10020",
  "SOCKS5 127.0.0.1:10021",
  "SOCKS5 127.0.0.1:10022",
  "SOCKS5 127.0.0.1:10023",
  "SOCKS5 127.0.0.1:10024",
  "SOCKS5 127.0.0.1:10025",
  "SOCKS5 127.0.0.1:10026",
  "SOCKS5 127.0.0.1:10027",
  "SOCKS5 127.0.0.1:10028",
  "SOCKS5 127.0.0.1:10029",
  "SOCKS5 127.0.0.1:10030",
  "SOCKS5 127.0.0.1:10031",
  "SOCKS5 127.0.0.1:10032",
  "SOCKS5 127.0.0.1:10033",
  "SOCKS5 127.0.0.1:10034",
  "SOCKS5 127.0.0.1:10035",
  "SOCKS5 127.0.0.1:10036",
  "SOCKS5 127.0.0.1:10037",
  "SOCKS5 127.0.0.1:10038",
  "SOCKS5 127.0.0.1:10039",
  "SOCKS5 127.0.0.1:10040",
  "SOCKS5 127.0.0.1:10041",
  "SOCKS5 127.0.0.1:10042",
  "SOCKS5 127.0.0.1:10043",
  "SOCKS5 127.0.0.1:10044", 
      ],
  counter = -1;

 function FindProxyForURL(url, host) {
   counter++;
   if (counter == proxies.length) counter = 0;
   return proxies[counter];
 }
```

And add it to FoxyProxy add it into FoxyProxy by automatic .pac configuration.

5. For more anonimity install https://addons.mozilla.org/pl/firefox/addon/random-agent-spoofer/ and set random for every url set canvas, screen resolution, etc.

Enjoy.

PS:


----------

