In this article we talk about Tor browser: how to install it, how to sandbox it, and some tips on how to increase the security of the setup.
Also, we have a short demo video covering some of the sandboxing aspects discussed below.
Before we start, let’s get into the habit of deleting some files when we shut down the computer. For this you need a systemd unit file (see Appendix 1) and a simple script. Copy the unit file in
/etc/systemd/system directory, and the script in /etc. The script is as follows:
First, we look at
.cache in home user directory. This is the place where where most programs store runtime information, such as the webpages you visited, torrent trackers you connected to, and all that emails you thought you deleted – all 3 GB of them! It is a very good idea to delete this directory at shutdown. Next time when you log in, an empty
~/.cache directory will be created.
After that, we look at
/etc/machine-id. This is a world-readable file containing a huge random number:
Sort of a serial number, it is used to uniquely identify Linux computers. You definitely don’t want something like this. But since it is required by systemd, let’s generate a brand-new one on shutdown. Next time we start, the computer has a new identity.
Note: Actually, there is another copy of this file in
/var/lib/dbus/machine-id, so we have to deal with both of them.
Installing Tor Browser
Download the browser from torproject website. It comes as a tar software archive that you unpack in your home directory:
The software is extracted in
~/tor-browser_en-US. Mount this directory on top of your home using Firejail’s
$ firejail –private=~/tor-browser_en-US ./start-tor-browser.desktop
The browser starts in a container filesystem created on-the-fly by Firejail. Take a look around, no personally identifiable information should be available:
- home directory with the files from the software archive and some miscellaneous config files created by the browser
- virtually empty
- small subset of system files in
- private /bin and /usr/bin directories have a very small subset of system executables; only the files required by Tor browser to function are present in these directories
- most of everything else is re-mounted read-only after some basic cleanup
Use a network namespace for additional fun and glory. This is basically a new TCP/IP stack in kernel space:
- a random unused IP address is obtained by ARP-probing your network
- the MAC address allocated by kernel is random by default
- brand new interfaces and routing table
- and a network firewall
Find the name of your Ethernet interface (eth0):
… and start tor:
Locking Down the Network
The network namespace takes care of two things. First, it makes your main system network stack invisible to the program running inside the sandbox. The sandbox Ethernet interface is connected to the main system in such a way, no network traffic is possible between the sandbox and the main system. So, if you have and SSH server running on your system, the attacker would not be able to access it.
The second reason is once we have a new network stack, we can deploy a firewall to further restrict the traffic. The default firewall is a generic desktop firewall that drops incoming TCP connections, but in the case of Tor browser we can do much better!
Tor browser talks to the onion network using a very small number of IP addresses: a guard node, and one or two more guards in case the main one fails. Using
--netlock option, Firejail detects these guards at startup, and builds and deploys a firewall that allows only traffic going to/coming from these guards. We call this network locking.
More about netlocker in the video demo.
The previous command is ugly, but you can set a desktop starter to make your life easier (see Appendix 2).
You can also use firetools to check your new network setting.
Not many people know Tor also offers a DNS proxy service. It is restricted to A, AAAA, and PTR requests, enough to run a browser or any other desktop application.
The service is built directly in Tor communication protocol, and it follows the same privacy and security principles as HTTP: at least 3 layers of redirection and randomization in a cluster of several thousand servers.
Start by installing tor package from your distro (Debian example):
Debian starts the proxy automatically upon install. Open
/etc/tor/torrc in a text editor and add the following lines at the end of the file:
Restart the proxy:
Tor should be running in this moment on UDP port 53, try it out:
266 ms query time means your domain was resolved by a server on a different continent. It happens a lot with Tor. The numbers I am getting are between 200 and 400 ms. If you end up with an exit node on your continent, probably the query crossed the Atlantic twice.
Try it out, is not so bad! For comparison, I get 50 to 100 ms query time for on-continent connections in our own Firejail DNS over HTTPS proxy project.
You can find out where the circuit is terminated using torsocks (
apt-get install torsocks):
As Tor rebuilds the circuit every few minutes, the DNS traffic is continuously moving to another random server.
Odds and Ends
firejail –net=none vlc” (or equivalent) when you play music or videos downloaded over Tor. Media players have the bad habit of going on the web to grab whatever was promised in the metadata. In the process, they de-anonymize the user.
When you are using a DNS proxy – Tor, DoH, or otherwise – it is a good idea to cut down the DNS traffic coming from your browser. On a regular IPv4-only network go in
about:config and disable IPv6 (
network.dns.disableIPv6). This will remove half the traffic. Also, install an adblocker – about 40% of all DNS exchanges are ads.
Appendix 1 – systemd unit file
Reload systemd configuration and enable the service:
Appendix 2 – Tor Browser desktop file
Add an icon somewhere in your home directory and link it in your desktop file, then move the desktop file in