Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the Tor api to make an anonymous proxy server

I am making an app which makes lots of api calls to some site. The trouble I've run into is that the site has a limit on the number of api calls that can be made per minute. To get around this I was hoping to use Tor in conjunction with node-http-proxy to create a proxy table which uses anonymous ip addresses taken from the tor api.

So my question is, how possible is this, and what tools would you recommend for getting it done. My app is written in javascript, so solutions involving things like node-tor are preferable.

like image 496
Loourr Avatar asked Jul 31 '13 16:07

Loourr


People also ask

Can you use Tor as a proxy?

Using the Tor browser, you can hide your online activity from network surveillance and traffic analysis. You can configure your Web browser — Mozilla Firefox, Google Chrome and Internet Explorer — to use the Tor proxy, and your communications are anonymized as long as the Tor browser is running in the background.

Do I need Tor to use Proxychains?

To setup proxychains you will first need the tor service, most of the time the service is preinstalled. To check if there is tor service available or not just use this command.

What is Proxychains Tor?

What Are Proxychains ? Proxychains is a UNIX program that helps us to redirect our network traffic so as to hide our true IP address. It redirects our TCP connections through several proxies like TOR, SOCKS4, SOCKS5, and HTTP(S).


1 Answers

I've found a reasonable solution using tor and curl command line tools via Node.js.

Download the tor command-line tool and set it in your $PATH.

Now, we can send requests through this local tor proxy which will establish a "circuit" through the TOR network. Let's see our IP address using http://ifconfig.me. You can copy paste all of these things into your Node REPL:

var cp = require('child_process'),
    exec = cp.exec,
    spawn = cp.spawn,
    tor = spawn('tor'),
    puts = function(err,stdo,stde){ console.log(stdo) },
    child;

After this, you may want to build in a delay while the tor proxy is spawned & sets itself up.

Next, let's go through the TOR network and ask http://ifconfig.me what IP address is accessing it.

function sayIP(){
  child = exec('curl --proxy socks5h://localhost:9050 http://ifconfig.me',puts);
}

sayIP();

If you want a new IP address, restarting tor by turning it off and then on seems to be the most reliable method:

function restartTor(){
  tor.kill('SIGINT');
  tor = spawn('tor');
}

restartTor();

Note: There is another way I've seen people describe getting a new IP address (setting up a new "circuit") on the fly, but it only seems to work about 10% of the time in my tests. If you want to try it:

Find & copy torrc.sample to torrc, then change torrc as follows:

  1. Uncomment ControlPort 9051 (9050 is the local proxy, opening 9051 lets us control it)
  2. Uncomment & set CookieAuthentication 0.
  3. Uncomment HashedControlPassword and set to result of:

    $ tor --hash-password "your_password"

Then you could use a function like this to send a NEWNYM signal to your local tor proxy to try getting a new IP address without restarting.

function newIP(){
  var signal = 'echo -e "AUTHENTICATE \"your_password\"\r\nsignal NEWNYM\r\nQUIT" | nc -v 127.0.0.1 9051';
  child = exec(signal,puts);
}

newIP();
like image 78
Adam Avatar answered Oct 13 '22 00:10

Adam