PHP用CURL伪造IP和来源

1 curl.php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://localhost/php/phpproject1/curlTo.php");

curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:8.8.8.8', 'CLIENT-IP:8.8.8.8'));  //构造IP

curl_setopt($ch, CURLOPT_REFERER, "http://www.gosoa.com.cn/ ");   //构造来路

curl_setopt($ch, CURLOPT_HEADER, 0);

$out = curl_exec($ch);

curl_close($ch);

 2 curlTo.php

  

function getClientIp() {

    if (!empty($_SERVER["HTTP_CLIENT_IP"]))

        $ip = $_SERVER["HTTP_CLIENT_IP"];

    else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))

        $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];

    else if (!empty($_SERVER["REMOTE_ADDR"]))

        $ip = $_SERVER["REMOTE_ADDR"];

    else

        $ip = "err";

    return $ip;

}



echo "<br>IP: " . getClientIp() . "";

echo "<br>referer: " . $_SERVER["HTTP_REFERER"];

原文:PHP用CURL伪造IP和来源

 

用socket也可以试试

$server = 'www.readdomain.cn';

$host = 'www.fromdomain.cn';

$target = '/xxx.php';

$referer = 'http://www.aslibra.com/'; // Referer

$port = 80;

$fp = fsockopen($server, $port, $errno, $errstr, 30);

if (!$fp)

{

echo "$errstr ($errno)<br />\n";

}

else

{

$out = "GET $target HTTP/1.1\r\n";

$out .= "Host: $host\r\n";

$out .= "Cookie: SESSIONID=test\r\n";

$out .= "Referer: $referer\r\n";

$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);

while (!feof($fp))

{

echo fgets($fp, 128);

}

fclose($fp);

}

 

你可能感兴趣的:(curl)