Tor - is a connection-oriented anonymizing communication service.

Install Tor

sudo apt install tor


Start/Restart/Stop Tor Service

# Start
sudo service tor start

# Restart
sudo service tor restart

# Stop
sudo service tor stop

# Status
sudo service tor statur


Proxychains

Proxychains forces any TCP connection made by any given application to follow through proxy like TOR or any other SOCKS4, SOCKS5 or HTTP(S) proxy.

    vim /etc/proxychains.conf

    # -----------------------------------------------------

    # If performing nmap for port scan through proxychains, comment out the following. Otherwise it will hang and crash.

   proxy_dns

If you lost a configuration file, download from the repository.

    wget https://raw.githubusercontent.com/haad/proxychains/master/src/proxychains.conf -O /etc/proxychains.conf

Now start the Tor service and run the following command to open the Firefox via proxychains.

proxychains firefox

Anonymize Traffic with Tor

We can anonymize our traffic using Tor proxy and proxychains. Please note that this method does not provide complete anonymity.

- https://geekflare.com/anonymize-linux-traffic/
- https://0x00sec.org/t/how-to-become-a-ghost-hacker-merozey-tips/591
- https://0x00sec.org/t/anonymity-basics/722
- https://www.edureka.co/blog/proxychains-anonsurf-macchanger-ethical-hacking/

Privacy Friendly OS


Anonymization

1. Configure Proxychains

First off, find the location of the proxychains configuration file.

find / -type f -name "*proxychains*" 2>/dev/null

Assume we found /etc/proxychains.conf then modify this file.

vim /etc/proxychains

We need to remove # in front of dynamic_chains, then comment out the strict_chain line and the random_chain line.
In addition, check the proxy_dns is uncommented for avoiding our DNS to be leaked.

...

dynamic_chain

...

# strict_chain

...

# random_chain

...

proxy_dns

Add socks4 127.0.0.1 9050 and socks5 127.0.0.1 9050 in the ProxyList section.

[ProxyList]
socks4  127.0.0.1 9050
socks5  127.0.0.1 9050

2. Start Tor Service

Before using proxychains, we need to start Tor service.

systemctl start tor

# Check the status
systemctl status tor

3. Use Proxychains

Now we can execute arbitrary command with proxychains. Our traffic should be anonymous thanks to Tor.

# Open Firefox browser.
proxychains firefox dnsleaktest.com

proxychains nmap x.x.x.x

To check our public ip address from command line, run the following command.

proxychains curl ifcfg.me

If we don't want to append proxychains command every time, proxychains bash command eliminates the need to do that.

proxychains bash

# Confirm our public ip
curl ifcfg.me

4. Use Burp Suite

To use Burp Suite over Tor proxy, setup the SOCKS proxy in Burp Suite as below.

  1. Open Burp Suite. We need to normally start Burp Suite without proxychains command.
  2. Go to Proxy tab and click Proxy settings. Settings window opens.
  3. In Settings window, go to User tab at the left pane, and click Network → Connections.
  4. In SOCKS proxy section, click the switch "Override options for this project only", and fill the following forms:

    SOCKS proxy host: 127.0.0.1
    SOCKS proxy port: 9050
    
    5. After that, check "Use SOCKS proxy". 6. Close the Settings window.

After setting up, we can use Burp Suite built-in browser over Tor proxy.

5. Stop Tor Service

After using proxychains and Tor, stop the Tor service.

systemctl stop tor


Check Your IP

After anonyzation, check your ip.

https://www.dnsleaktest.com/


Change MAC Address

macchanger -r ens33

Create Tor Onion Service with Nginx

- https://community.torproject.org/onion-services/setup/

1. Setup Tor

1. Install Tor

# on Debian/Ubuntu
sudo apt install tor

# on Fedora
sudo dnf install tor

Then enable and start tor service.

sudo systemctl enable tor
sudo systemctl start tor

# Check status
sudo systemctl status tor

2. Configure Tor Onion Service

Edit /etc/tor/torrc for adding the following lines (remove # at the target lines and modify values):

HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 80 unix:/var/run/tor/hidden_service.sock

3. Restart Tor Service

sudo systemctl restart tor

4. Check Your Onion Domain

Your onion domain is stored at /var/lib/tor/hidden_service/hostname.

cat /var/lib/tor/hidden_service/hostname


2. Setup Nginx

1. Install Nginx

# on Debian/Ubuntu
sudo apt install nginx

# on Fedora
sudo dnf install nginx

2. Create Website Contents

Here we create a directory /var/www/onion and put the contents here.

mkdir -p /var/www/onion
touch /var/www/onion/index.html

Then write contents for index.html such as below:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Hidden Site</title>
    </head>
    <body>
        <h1>Welcome to Hidden Site</h1>
    </body>
</html>

After that change permission for allow nginx to read files under /var/www/onion.

chown -R nginx:nginx /var/www/onion

Remember to update permission of /var/www/onion with above command every time you add new files/directories under /var/www/onion.

3. Configure Nginx

Create /etc/nginx/conf.d/onion.conf and add the following directive. Replace <your-onion-address>.onion with your Onion domain stored at /var/lib/tor/hidden_service/hostname.

server {
    listen unix:/var/run/tor/hidden_service.sock;
    server_name <your-onion-address>.onion;
    access_log /var/log/nginx/hidden_service.log;
    index index.html;
    root /var/www/onion;

    location / {
        root /var/www/onion;
        index index.html index.htm;
    }   
}

4. Start Nginx Server

Before starting the Nginx, if the SELinux is activated, temporarily disable the SELinux to give Nginx permission to process UNIX sockets (/var/run/tor/hidden_service.sock).

# 0: Set `Permissive` mode temporarily
setenforce 0

# Check status (the `Permissive` mode is expected)
getenforce

Then start Nginx.

sudo systemctl enable nginx
sudo systemctl start nginx

# Check status
sudo systemctl status nginx


3. Access To You Onion Service

Using Tor Browser, you can access to the onion service by entering your .onion domain. See the domain in /var/lib/tor/hidden_service/hostname.

To monitor access log, use tail command.

tail -f /var/log/nginx/hidden_service.log


4. Backup HiddenServiceDir

To keep your onion service available for a long time, make a backup copy of the /var/lib/tor/hidden_service directory somewhere.

When starting Hidden Service using this directory, just simply copy it to /var/lib/tor/ as below:

cp -r /path/to/hidden_service /var/lib/tor/

Then modify /etc/tor/torrc and start tor service.


5. (Optional) Get Vanity Address

If you want to use a custom Onion domain with arbitrary prefix such as exampleabcdef....onion, you can generate it using mkp224o.

1. Install Dependencies

# on Debian/Ubuntu
apt install gcc libc6-dev libsodium-dev make autoconf

# on Fedora
sudo dnf install -y gcc
sudo dnf install -y glibc-static
sudo dnf install -y libsodium-devel
sudo dnf install -y make
sudo dnf install -y autoconf

2. Build the mkp224o Project

git clone https://github.com/cathugger/mkp224o.git
cd mkp224o
./autogen.sh
./configure
make

3. Generate Vanity Address

# -d: Specify output directory
# -n: The number of domains to generate
./mkp224o -d domains -n 5 mysite

# Result examples:
mysiteabcdef.....onion
mysite012334.....onion
mysiteef0123.....onion
mysite789abc.....onion
mysite345def.....onion

4. Copy the Key Files

After generating, the key files are saved under domains/mysite...onion directory.

ls domains/mysiteabcdef....onion

hostname hs_ed25519_public_key hs_ed25519_secret_key

Choose one domain and copy these files to /var/lib/tor/hidden_service/ .

cd domains/mysiteabcdef....onion
cp domains/mysiteabcdef/* /var/lib/tor/hidden_service/

5. Update the Nginx Config

Replace the original onion domain to our vanity address in /etc/nginx/conf.d/onion.conf

server {
    ...
    server_name mysiteabcdef....onion;
    ...
}

6. Restart Tor and Nginx

Now restart Tor and Nginx to apply the domain.

sudo systemctl restart tor
sudo systemctl restart nginx

Access to mysite...onion in Tor Browser.


6. (Optional) Make Your Onion Service To Be More Secure

If you want your onion service to be more secure, add additional configurations.

Hide Nginx Version

Usually the Nginx version is displayed in the HTTP response header such as below:

Server: nginx/1.24.0

You may want to hide the version. To hide it, add the server_tokens off in the /etc/nginx/nginx.conf as follow:

http {

    ...

    server_tokens off;

    ...

}

This hide the Nginx version from the Server header such as below:

Server: nginx

Rate Limiting Requests

Reference: https://www.nginx.com/blog/rate-limiting-nginx/

By rate limiting requests per second (or millisecond), it may prevent DDoS attacks.
Add limit_req_zone and limit_req directives to /etc/nginx/conf.d/onion.conf.

limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;

Server {
    ...

    location / {
        limit_req zone=mylimit burst=20 nodelay;
        ...
    }
}