[{"content":"What is Tor? Tor is a free overlay network that enables anonymous communication.\nIt is built on free and open-source software and run by over seven thousand volunteer-operated relays worldwide, as well as by millions of users who route their internet traffic through random paths across these relays.\nThis technique is called onion routing.\nInstalling Tor First, we need to install the Tor service on our server.\nThis guide uses a Debian-based distribution.\nStart by updating the package lists and upgrading the installed packages:\nsudo apt update \u0026amp;\u0026amp; sudo apt upgrade Next, install Tor:\nsudo apt install tor Then start the service and enable it at boot:\nsudo systemctl enable --now tor By default, Tor runs no hidden service. It only exposes a SOCKS5 proxy on port 9050, which acts as a gateway to the Tor network.\nSetting up a hidden service Now that Tor is installed, we can configure our hidden service.\nThis guide covers a basic configuration. More advanced options are documented in the torrc manual.\nHow does a hidden service work? To configure a hidden service correctly, it helps to understand what Tor is doing.\nA hidden service is essentially port forwarding through Tor.\nThe commented section of the default configuration file describes it like this:\nHiddenServicePort x y:z says to redirect requests on port x to the address y:z. So Tor forwards ports under a hidden service directory, which holds the generated keys and the hostname derived from them:\nHiddenServiceDir /var/lib/tor/hservice_example/ HiddenServicePort 80 127.0.0.1:80 HiddenServicePort 22 127.0.0.1:22 The URL of the hidden service (its hostname) is stored in /var/lib/tor/hservice_example/hostname.\nNow that we know how it works, we can set up our own.\nEditing torrc Tor\u0026rsquo;s main configuration file is /etc/tor/torrc.\nIf, for example, we have a web server running on port 80 that we want to expose to the Tor network, we append the following lines:\nHiddenServiceDir /var/lib/tor/webserver/ HiddenServicePort 80 127.0.0.1:80 If we also want SSH access through Tor, we can add another HiddenServicePort:\nHiddenServiceDir /var/lib/tor/webserver/ HiddenServicePort 80 127.0.0.1:80 HiddenServicePort 22 127.0.0.1:22 Clients then reach SSH through Tor\u0026rsquo;s SOCKS5 proxy, for example with torsocks ssh user@youraddress.onion.\nYou can forward any TCP port. Some protocols won\u0026rsquo;t work well (such as FTP, which opens extra connections), but most do.\nAfter saving the file, restart Tor and read your new address:\nsudo systemctl restart tor sudo cat /var/lib/tor/webserver/hostname Tip: make your services listen only on 127.0.0.1, so they are reachable through Tor and not directly from the internet.\nCustom hostname generation That\u0026rsquo;s nice, but how do I get a custom address like the one The Pirate Bay uses?\npiratebayo3klnzokc(...).onion The hostname is derived from the service\u0026rsquo;s key pair, so getting a custom prefix means generating keys over and over until one matches. That takes computational work, and each extra character multiplies the time needed.\nFor this we use mkp224o, which generates version 3 onion addresses.\nClone the repository and follow its build instructions. Then run it with the prefix you want:\n./mkp224o -d ~/onions mysite Each match is saved as a directory containing hostname, hs_ed25519_public_key and hs_ed25519_secret_key. To use one, copy it over your HiddenServiceDir and fix the ownership and permissions, or Tor will refuse to start:\nsudo cp -r ~/onions/mysiteXXXX.onion/* /var/lib/tor/webserver/ sudo chown -R debian-tor:debian-tor /var/lib/tor/webserver sudo chmod 700 /var/lib/tor/webserver sudo systemctl restart tor ","permalink":"https://s0ck37.github.io/posts/001/","summary":"\u003ch2 id=\"what-is-tor\"\u003eWhat is Tor?\u003c/h2\u003e\n\u003cp\u003eTor is a free overlay network that enables anonymous communication.\u003cbr\u003e\nIt is built on free and open-source software and run by over seven thousand volunteer-operated relays worldwide, as well as by millions of users who route their internet traffic through random paths across these relays.\u003cbr\u003e\nThis technique is called onion routing.\u003c/p\u003e\n\u003ch2 id=\"installing-tor\"\u003eInstalling Tor\u003c/h2\u003e\n\u003cp\u003eFirst, we need to install the Tor service on our server.\u003cbr\u003e\nThis guide uses a Debian-based distribution.\u003cbr\u003e\nStart by updating the package lists and upgrading the installed packages:\u003c/p\u003e","title":"How to Set Up a Tor Hidden Service"}]