Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tor is not an HTTP Proxy

I am using cloud server Ubuntu 12.04 as tor proxy server for scrapping purpose. The issue I am facing right now it is showing error

HTTP/1.0 501 Tor is not an HTTP Proxy Content-Type: text/html; charset=iso-8859-1

$url = 'http://whatismyipaddress.com';
$agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';

$ch = curl_init('http://whatismyipaddress.com'); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 
curl_setopt($ch, CURLOPT_PROXY, 'https://127.0.01:9050/'); 
curl_exec($ch); 
curl_close($ch);

$result=curl_exec($ch);

Need to help what I'm missing. I have already trying to use

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); 
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);

a request is loading and session expire with no result.

like image 296
junjoi Avatar asked Aug 15 '16 06:08

junjoi


People also ask

Is Tor a Web proxy?

Tor is a free-to-use network of access points called nodes that work like proxies for your connection. It's also the name of the browser you use to connect to this network. When you use the Tor browser, your connection gets routed through several of these nodes before arriving at its end destination.

How do I change my proxy settings on Tor?

1) Launch the Tor Browser browser. 2) On the right hand side, click on open menu and Click on Options. 5) A new window is opened called Connection Settings. 6) Click on use Manual Proxy Configuration, enter the IP address and Port number.


1 Answers

This is true, Tor is not an HTTP proxy, but is instead a SOCKS v5 proxy.

Based on your cURL option CURLOPT_HTTPPROXYTUNNEL, you are telling cURL to try to use Tor's proxy incorrectly (as an HTTP proxy).

The correct way would be to get rid of the proxy tunnel option and just set the proxy and SOCKS proxy type:

$proxy = '127.0.0.1:9050';  // no https:// or http://; just host:port
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);

If you don't have PHP 5.5.23 or greater (which introduce CURLPROXY_SOCKS5_HOSTNAME), you can use curl_setopt($ch, CURLOPT_PROXYTYPE, 7);

If the cURL version PHP is compiled with is less than 7.18.0, it did not support SOCSK5 with hostname lookups, so you'll have to fall back to CURLPROXY_SOCKS5 and know that your DNS lookups will not go over Tor and potentially be exposed.

Side Note: I wrote a PHP library called TorUtils which provides a number of classes for interacting with Tor in PHP. One class is provides is the TorCurlWrapper which abstracts the logic above and forces cURL to use Tor's SOCKS proxy correctly. There is a usage example here. You can install the library using composer require dapphp/torutils or by downloading the package and adding it to your code.

like image 113
drew010 Avatar answered Sep 19 '22 13:09

drew010