I´m trying to connect to different websites via PHP through Tor/Privoxy. The PHP scripts and Tor/Privoxy run on the same server.
Privoxy is configured as follows
forward-socks4a / 127.0.0.1:9050 .
forward-socks5 / 127.0.0.1:9050 .
confdir /etc/privoxy
logdir /var/log/privoxy
logfile logfile
actionsfile match-all.action
actionsfile default.action
actionsfile user.action
filterfile default.filter
debug 32
debug 128
debug 1024
debug 4096
debug 8192
user-manual /usr/share/doc/privoxy/user-manual
listen-address 127.0.0.1:8118
toggle 1
enable-remote-toggle 0
enable-edit-actions 0
enable-remote-http-toggle 0
buffer-limit 4096
Tors configuration
SocksPort 9050
SocksPolicy accept 127.0.0.1
SocksPolicy reject *
Log warn syslog
RunAsDaemon 1
DataDirectory /var/lib/tor
I´m trying to connect using a script I found at PHP SSL stream_socket_client won't use created $context which I modified slightly to fit my needs
<?php
$desthost = "derdualstudent.de";
$port = 80;
$conflag = STREAM_CLIENT_CONNECT;
try
{
$socket = stream_socket_client( "tcp://127.0.0.1:8118", $errno, $errstr, 15, $conflag );
fwrite( $socket, pack( "C3", 0x05, 0x00, 0x00 ) );
$server_status = fread( $socket, 2048 );
if ( $server_status == pack( "C2", 0x05, 0x00 ) )
{
// Connection succeeded
}
else
{
die( "SOCKS Server does not support this version and/or authentication method of SOCKS.\r\n" );
}
fwrite( $socket, pack( "C5", 0x05, 0x01, 0x00, 0x03, strlen( $desthost ) ) . $desthost . pack( "n", $port ) );
$server_buffer = fread( $socket, 10 );
if ( ord( $server_buffer[0] ) == 5 && ord( $server_buffer[1] ) == 0 && ord( $server_buffer[2] ) == 0 )
{
// Connection succeeded
}
else
{
die( "The SOCKS server failed to connect to the specificed host and port. ( " . $desthost . ":" . $port . " )\r\n" );
}
stream_socket_enable_crypto( $socket, TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT );
}
catch ( Exception $e )
{
die( $e->getMessage() );
}
if ( $socket === FALSE )
{
die( "bad socket" );
}
fwrite( $socket, "GET /\n" );
echo fread( $socket, 10255 );
?>
The script drops dead with "SOCKS Server does not support this version and/or authentication method of SOCKS.". I experimented with the authentication (0x00 and 0x01 both don´t work).
There is also a script a colleague of me wrote on the same server
<?php
$vOpts = array('http'=>array(
'method'=>"GET",
'request_fulluri'=>TRUE,
'proxy'=>'tcp://localhost:8118',
'header'=>"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.8) Gecko/20051111 Firefox/16.0\r\n"."Accept-language: de\r\n"."\r\n"
));
$vContext = stream_context_create($vOpts);
$vFile = file_get_contents("http://www.derdualstudent.de?tor=1",FALSE,$vContext);
?>
This produces the error
PHP Warning: file_get_contents(http://www.derdualstudent.de?tor=1): failed to open stream: HTTP request failed! HTTP/1.0 503 Forwarding failure
in /home/pi/php_scripts/temp.php on line 9
The logs of Tor and Privoxy contain no helpful informations.