Member-only story
Using Ruby to access Onion network over SOCKS proxy
Source code lives here.
Tor provides a SOCKS proxy so that you can have any application using the same to connect the Onion network. The Tor Browser also provides the same service on port 9150. In this post, we will see how can we use the same SOCKS proxy to access the Internet.
Before the start, we need to install Tor to use it as a proxy.
# For Debian-like distros, you can find a guide over here.
#
brew install tor
Then launch Tor. The default port is 9050.
brew services start tor
Basically, Net::HTTP
doesn’t support SOCKS proxy out-of-the-box (the same issue is actual for httparty, faraday, Curl::Easy
), so the only way is to use socksify
Gem:
gem install socksify
--Fetching socksify-1.7.1.gem
--Successfully installed socksify-1.7.1
--Parsing documentation for socksify-1.7.1
--Installing ri documentation for socksify-1.7.1
--Done installing documentation for socksify after 0 seconds
1 gem installed
First of all, let’s visit some onion site using the Tor browser to get real request headers.
After this, writing the actual code is very simple, we will be doing a GET
request to http://hydr@rzxpnΣw4@f.onion.