Sometimes the Tor Browser just isn’t the hammer for your particular nail. If you’re in the command line and want to run a pings or or a curl through onion services, then you’ll need to expand your Tor toolbox. I wanted to SSH into a server and decided I wanted to do this over Tor. Command line Tor isn’t that straight forward these days. In the end, I got it done, but I’m not terribly happy with the method. But if you want to SSH into a server over Tor, then this may work for you.
Wanna read ’bout it? did a blog here ’bout it. Here it goes…
There are a lot of guides out there to accomplish Tor commands, many of them are out of date, or won’t really apply to your operating system. Here’s a fairly up-to-date one for Linux users. Here’s a less-up-to-date one for Mac or Debian/Ubuntu users. Both of those also don’t mention you need to install torsocks, or leave out a couple of configuratons that you may with you knew about. None of them seem to include what you need to actually operate Tor effectively from the command line for at least the most common of tasks: switching it on, turning it off, updating it and running your commands through it. Unfortunately, the Tor site itself is of no real use when it comes to reasonably current or readable documentation.
I’ve cobbled together bits of those to for setting it up on a Mac, since that’s what I was using at the time. Assuming you’re using an OSX rig similar to mine (of a reasonably recent version) then this may work for you. Eventually, this post will join the ranks of outdated how-to blog posts sitting out there on the web. But if you’re in the early part of the year 2018 and using the High Sierra OS on a machine you have reasonable system administraion access to, then this will/should work.
To get things going, you’ll need to install Homebrew to get the packages, if it’s not already on your machine.
Now, install Tor and torsocks:
brew install tor torsocks
Now, we need to edit the torrc file
Find and uncomment the line containing:
Right below that, be sure to uncomment the HashedControlPassword to prevent session hijacking.
Find, uncomment, and change the ‘1’ to a ‘0’ on this line:
Both the pass and cookie configs are there to ward off attacks. The torrc file seems to tell you to just pick either the password or the cookie, but when not using the password, you’ll get an error when trying to start up Tor in the next step.
Save all that as a different file, just called torrc.
Start Tor with:
You should see it start up with listening and handshakes and ending at “bootstrapped 100%: Done.” Congrats. You’ve just set up Tor running as a background process. Groovy. Let’s check if it works. If you were just installing and running the Tor Project’s flagship software, The Tor Browser, then this is as easy as visiting https://check.torproject.org. Checking from the command line in your Mac isn’t so straight forward.
First, let’s see your REAL public IP (the one that Tor isn’t anonymising). There are loads of ways to do this, but I’m including here the one that will be ALMOST identical to how you’ll repeat the process from behind Tor.
Find your real public IP by hitting whatismyipaddress.com (via its IP):
code>wget 188.8.131.52:80 -O - -o /dev/null | cut -d" " -f6 | sed 's/<\/body><\/html>//'
Find the IP address that Tor tells your destination is you:
torify 2> /dev/null wget 184.108.40.206:80 -O - -o /dev/null | cut -d" " -f6 | sed 's/<\/body><\/html>//'
You could use torify or torsocks interchangeably on the above command, but you’ll notice we’ve added some lines to take care of a number of errors that torify or torsocks will throw up on the Mac. For your real IP, you could could have just written curl 220.127.116.11:80 and it would have given you the same result, only with some html mess around it. However, if you just try to
torify curl 18.104.22.168:80 then…
ERROR: /usr/bin/curl is located in a directory protected by Apple's System Integrity Protection.
The same will happen if you try to torify or torsocks any command. This feature started with Mac’s ‘El Capitain’ OS. You should be happy that your machine is trying to keep you from destroying it, but this is fairly annoying in practice as it will make recipes for any command as simple as a ping much more difficult to sort out, and really, if you’re trying to command line from behind Tor, you’re probably not interested in simple things.
So how to connect to a server with SSH over Tor on your Mac? There are all kinds of reasons you may want to do this, and all leave those to you. But there’s no uniform way to do all your commands through Torify or Torsocks. You’ve either got to hunt this stuff down, or just become Expert of All the Things. To SSH over Tor, see Lorenzo Milesi’s self described “more lame” method, which actually does work pretty well.
So that works. But it just solves the SSH issue. Also, it’s a work-around. Work-arounds are messy. They can/will possibly cause problems elsewhere, and you generally need to keep a lot of notes so you can undo things. For example, you could disable System Integrity Protection, but I really don’t think most (any) users should go there, especially just to muck about with some Tor commands. If your a software developer, it might make sense. If you’re in the information security end of things, you should be happy it’s there, and leave alone. My goal is to find a way to peck commands that run over the Tor network into this Mac’s terminal program without having to fenestrate what’s basically a strong line of defence against malware in the process.
So, the options seem to be as of now:
- Ditch running Tor on the Mac itself and connect it to an external Tor router box (extra thing to carry, maintain and update, not necessarily useful in some situations);
- Fire up the Tails OS or another Linux OS, and run commands through that (Not terribly convenient and doesn’t have a lot of the other things I also want to access installed. Defeats the purpose of wanting this to work on this Mac).
- Tunnel/remote access to another machine that’s set up properly for all this (enjoyable but ultimately diverting)
- Justify budget for an entirely different and more ideal machine. (feeds tech shoppping urge, but arguably the worst option).
Ideal: The Tor Project is great at App-based solutions that require zero/minimal configuration. A terminal emulator that runs the Tor requirements in the background would be marvellous, and could best deal with Apple’s system integrity protection.
Alternate ideal: Something that runs as fluid and as simple as Torghost is supposed to on Kali Linux .
Likely next steps: Look for a Terminal emulator add on for Firefox that would work in the Tor browser; support a project that wraps a terminal emulator in a nice Tor package; miss Vidalia (though, on Android, Orbot VPN’s a terminal app, interestingly); Set up a Tor router box and just get over it.