本文章來給大家介紹二種利用php來實現頁面跳轉與跨站提交偽造Referer地址來源具體實現,方法主要用到了fsockopen,curl兩個函數,有需要了解的朋友可進入參考。
一、嘗試過的URL跳轉方法
代碼如下 復制代碼echo '<meta http-equiv="refresh" content="0; URL='.$url.'">';
echo '<scrīpt language="Javascrīpt">window.location.href="'.$url.'";</scrīpt>';
echo '<script language="Javascrīpt">window.location.replace="'.$url.'";</ script>';
以上三種方法均無法傳遞REFERER地址。
二、使用PHP Socket函數偽造REFER
下面是PHP偽造REFERER代碼部分,經過測試可以實現REFERER地址傳遞,其中$url是輸入地址。
$uinfo = parse_url($url);//解析URL地址,比如http://php100.com/archives/1.html
if($uinfo['path']) //
$data = $uinfo['path'];//這裡得到/archives/1.html
else
$data = '/';//默認根
if(!$fsp = @fsockopen($uinfo['host'], (($uinfo['port']) ? $uinfo['port'] : "80"), $errno, $errstr, 12)){
echo "對不起對方網站暫時無法打開,請您稍後訪問:".$uinfo['host']; exit;
}else{
fputs($fsp, "GET “.$data .” HTTP/1.0rn");//如果是跨站POST提交,可使用POST方法
fputs($fsp, "Host: ".$uinfo['host']."rn");
fputs($fsp, "Referer: php100.comrn");//偽造REFERER地址
fputs($fsp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)rnrn");
$res='';
while(!feof($fsp)) {
$res.=fgets($fsp, 128);
if(strstr($res,"200 OK")) {
header("Location:$url"); exit;
}
}
}
//如果是301或302狀態碼可以繼續處理
//返回地址大概形式:HTTP/1.1 301 Moved PermanentlynContent-Length: 164nContent-Type: text/htmlnLocation: http://php100.com/
$arr=explode("n",$res);
$arr=explode(": ",$arr[3]);//Location後面是真實重定向地址
header("location:".$arr[0]);//跳轉目標地址
exit;
利用另一種方法 curl)偽造HTTP_REFERER
//PHP(前提是裝了curl):
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://www.bkjia.com/");
curl_setopt ($ch, CURLOPT_REFERER, "http://www.bkjia.com/");
curl_exec ($ch);
curl_close ($ch);
//PHP(不裝curl用sock)
$server = 'blog.qita.in';
$host = 'blog.qita.in';
$target = '/xxx.asp';
$referer = 'http://www.baidu.com/'; // Referer
$port = 80;
$fp = fsockopen($server, $port, $errno, $errstr, 30);
if (!$fp)
{
echo "$errstr ($errno)<br />n";
}
else
{
$out = "GET $target HTTP/1.1rn";
$out .= "Host: $hostrn";
$out .= "Cookie: ASPSESSIONIDSQTBQSDA=DFCAPKLBBFICDAFMHNKIGKEGrn";
$out .= "Referer: $refererrn";
$out .= "Connection: Closernrn";
fwrite($fp, $out);
while (!feof($fp))
{
echo fgets($fp, 128);
}
fclose($fp);
}