2 minute read

How to use Bash anonymously

Introduction

Today I’ll briefly explain how to provide the Tor anonymity guarantee to almost any scripts and CLI tools that you have in your pocket.

The most complicated question would be: «For what?», and, to be honest, I can’t come up with a strong answer. Maybe you are a hacker, or you just enjoy being hidden and safe, or you simply need to test your app from Madagascar, who knows?

Installation

brew install tor
brew install torsocks

Usage

  • Start proxy server:
tor
  • Figure out your current IP address and location:
ip2cc $(curl -s ifconfig.me)
  • Proxy it through Tor and check it out one more time:
ip2cc $(curl -s --socks5 127.0.0.1:9050 ifconfig.me)

Looks like it has changed, right? It was a quick win. Worth mentioning that by default Tor takes an IP address randomly, but we can specify the exact country using Tor country codes. Let’s open a connection, for instance, from Canada and close it from New Zealand.

  • Stop pre-created proxy server:
killall tor
  • Create torrc file:
touch torrc
  • Put entry and exit nodes in torrc file (ca and nz as we decided above):
echo "EntryNodes {ca}
ExitNodes {nz}" > torrc
  • Start proxy server providing the configured torrc file:
tor -f torrc
  • Check your location out:
ip2cc $(curl -s --socks5 127.0.0.1:9050 ifconfig.me)

Github

  • So, now you’d like to clone github repo anonymously. Why do you need that? Ok, never mind, let’s just do it:
curl -sOL --socks5 127.0.0.1:9050 https://github.com/{username}/{reponame}/archive/{branch}.zip
  • Wait, you even think about working on that repo anonymously? I didn’t go that far, but I have something for ya:

https://stackoverflow.com/a/37100346

The show must go on

  • It worth noticing that some CLI tools provide an argument to get a proxy server path (e.g.: youtube.dl) and this way you can strain all their traffic through Tor:
youtube-dl "youtube.com/watch?v={id}" --proxy socks5://127.0.0.1:9050
  • To be honest, there is a much easier way to cover all that stuff, it’s where torsocks comes. For example:
torify curl -s ifconfig.me

Torify simply wraps all the traffic that any provided tool will request and thoroughly proxies it through itself. Let’s take a look at it from a different example, imagine that for the sake of fun or for any other reasons you need to anonymously install some groundbreaking ruby gem.

  • Here we go:
torify gem install bundler
  • You’d say: «Now you’re talking», but there is always BUT. Sometimes you may face an error like:
ERROR: /usr/bin/{toolname} is located in a directory protected by Apple's System Integrity Protection.
  • If so, just copy-pasta that binary to your local execution folder (but it’s possibly no more a workaround for macOS Big Sur users):
cp /usr/bin/{toolname} /usr/local/bin

Conclusion

Fun fact: now you know how to wear a mask on your tools and scripts 😷

Updated: