FlipsideReality Once upon a time, in a land far far away…

23Sep/074

PHP Tor Wrapper

Shamelessly stolen from 0x000000.com. This PHP
function creates a socket connection through Tor and is able to make a
perfect HTTP request that goes through the Tor network. Usually people
use Firefox with FoxyProxy or the Torbutton, but sometimes you'll need
scripts that can access other sites through the Tor router, and this is
a PHP script that does just that. Pretty simple, but effective.

What you need further:

- Install Tor and Privoxy bundle.
- Have PHP, like the WAMP server.

That's it, plug it into your exploits or test scripts and you can call
all your scripts through the Tor router now, and thereby be a little
safer instead of using bad proxies.

<?phpfunction tor_wrapper($url){
$ua = array('Mozilla','Opera','Microsoft Internet Explorer','ia_archiver');
$op = array('Windows','Windows XP','Linux','Windows NT','Windows 2000','OSX');
$agent  = $ua[rand(0,3)].'/'.rand(1,8).'.'.rand(0,9).' ('.$op[rand(0,5)].' '.rand(1,7).'.'.rand(0,9).'; en-US;)';
# Tor address & port
$tor = '127.0.0.1:9050';
# set a timeout.
        $timeout = '300';
        $ack = curl_init();
         curl_setopt ($ack, CURLOPT_PROXY, $tor);
         curl_setopt ($ack, CURLOPT_URL, $url);
        curl_setopt ($ack, CURLOPT_HEADER, 1);
          curl_setopt ($ack, CURLOPT_USERAGENT, $agent);
         curl_setopt ($ack, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt ($ack, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt ($ack, CURLOPT_TIMEOUT, $timeout);
        $syn = curl_exec($ack);
        # $info = curl_getinfo($ack);
        curl_close($ack);
        # $info['http_code'];
   return $syn;}
        # example:
        $wrapped = tor_wrapper("http://www.sillysite.com?page=1' OR 1=1");
        echo $wrapped;?>
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Comments (4) Trackbacks (0)
  1. Hi,

    Hey this is great, I have been looking for something like this.

    However, I get an error when I use the above code.

    Its says that TOR is a SOCKS proxy, not an HTTP proxy!!

    Could you help me with this?

    Thanks.
    Gautamm.

  2. utiliza el puerto 8118

  3. @Guatamm. To modify the above script for Socks5 support (socks4 not supported), add:

    curl_setopt( $ack, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);

  4. I have a test.php. When I call http://127.0.0.1/test.php I see the same problem. My question is where to put the tor_wrapper function?

    thanks


Leave a comment


No trackbacks yet.