Secure communication using Tor and socat

July 3, 2023    Article    242 words    2 mins read

If you didn’t know, people can send you messages using socat and the Tor network, all communication is encrypted by Tor, no DNS lookups are performed and it’s impossible to identify who is sending you the messages (or who is receiving them, for what matters).

You only need Tor and socat installed.

On Linux add the lines below to your /etc/tor/torrc file:

HiddenServiceDir /var/lib/tor/hidden-chat/
HiddenServicePort 21334

On macOS you can use the path where Homebrew is installed and the torrc file is in /opt/homebrew/etc (create if it does not exist):

HiddenServiceDir /opt/homebrew/var/tor-hidden-chat/
HiddenServicePort 21334

Basically you create a Tor hidden service on port 21334 (you can use any port you like, change 21334 to any free port on your system, from all the lines below).

Get the hostname of your hidden service (Linux):

$ cat /var/lib/tor/hidden-chat/hostname

Or macOS:

$ cat /opt/homebrew/var/tor-hidden-chat/hostname

And you can give the hidden service hostname to the person you want to communicate with. On the machine that runs the Tor hidden service setup a socat listener on port 21334:

$ socat TCP4-LISTEN:21334,bind=,reuseaddr READLINE

Now people can send you messages using socat (and readline) to your Tor hidden address:

$ socat READLINE SOCKS4A:,socksport=9050

On systems where readline is not available to socat (gah, Debian), people can use stdio to send messages:

$ socat - SOCKS4A:,socksport=9050

Anything that is typed in the first console will get sent to the other one (and vice versa).

Have fun.