联系电话:0755-27515592
最新动态:

PHP教程

你的位置: 首页>>智慧亿恩>>PHP教程

PHP页面跳转与跨站提交伪造Referer地址来源

点击数:15652015-07-18 11:38:48 来源: 外贸网站建设,深圳外贸网站建设,深圳网站建设,外贸商城网站制作-亿恩科技

新闻摘要:一、尝试过的URL跳转方法 ,代码如下: echo metahttp-equiv=refreshcontent=0;URL= . $url . ; echo scrīptlanguage=Javascrīptwindow.location.href= . $url . ;/scrīpt ; echo scriptlanguage=Javascrīptwindow.location.replace= . $url

一、尝试过的URL跳转方法,代码如下:

  1. echo '<meta http-equiv="refresh" content="0; URL='.$url.'">'; 
  2.  
  3. echo '<scrīpt language="Javascrīpt">window.location.href="'.$url.'";</scrīpt>'; 
  4.  
  5. echo '<script language="Javascrīpt">window.location.replace="'.$url.'";</ script>'; 

以上三种方法均无法传递REFERER地址.

二、使用PHP Socket函数伪造REFER

下面是PHP伪造REFERER代码部分,经过测试可以实现REFERER地址传递,其中$url是输入地址,代码如下:

  1. $uinfo = parse_url($url);//解析URL地址,比如http://vcphp.com/archives/1.html 
  2.  
  3. if($uinfo['path']) // 
  4.  
  5.     $data = $uinfo['path'];//这里得到/archives/1.html 
  6.  
  7. else 
  8.  
  9.     $data = '/';//默认根 
  10.  
  11. if(!$fsp = @fsockopen($uinfo['host'], (($uinfo['port']) ? $uinfo['port'] : "80"), $errno, $errstr, 12)){ 
  12.  
  13.     echo "对不起对方网站暂时无法打开,请您稍后访问:".$uinfo['host'];    exit; 
  14.  
  15. }else{ 
  16.  
  17.     fputs($fsp, "GET “.$data .” HTTP/1.0rn");//如果是跨站POST提交,可使用POST方法 
  18.  
  19.     fputs($fsp, "Host: ".$uinfo['host']."rn"); 
  20.  
  21.     fputs($fsp, "Referer: vcphp.comrn");//伪造REFERER地址 
  22.  
  23.     fputs($fsp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)rnrn"); 
  24.  
  25.     $res=''; 
  26.  
  27.     while(!feof($fsp))  { 
  28.  
  29.         $res.=fgets($fsp, 128); 
  30.  
  31.         if(strstr($res,"200 OK")) { 
  32.  
  33.             header("Location:$url"); exit; 
  34.  
  35.         } 
  36.  
  37.     } 
  38.  
  39. } 
  40.  
  41. //如果是301或302状态码可以继续处理 
  42. //开源代码vcphp.com 
  43. //返回地址大概形式:HTTP/1.1 301 Moved PermanentlynContent-Length: 164nContent-Type: text/htmlnLocation: http://vcphp.com/ 
  44.  
  45. $arr=explode("n",$res); 
  46.  
  47. $arr=explode(": ",$arr[3]);//Location后面是真实重定向地址 
  48.  
  49. header("location:".$arr[0]);//跳转目标地址 
  50.  
  51. exit; 

利用另一种方法 curl)伪造HTTP_REFERER,代码如下:

  1. //PHP(前提是装了curl): 
  2. $ch = curl_init(); 
  3. curl_setopt ($ch, CURLOPT_URL, "http://www.vcphp.com/"); 
  4. curl_setopt ($ch, CURLOPT_REFERER, "http://www.vcphp.com/"); 
  5. curl_exec ($ch); 
  6. curl_close ($ch); 
  7.  
  8. //PHP(不装curl用sock) 
  9. $server = 'blog.qita.in'; 
  10. $host      = 'blog.qita.in'; 
  11. $target    = '/xxx.asp'; 
  12. $referer = 'http://www.baidu.com/';      // Referer 
  13. $port      = 80; 
  14. $fp = fsockopen($server, $port, $errno, $errstr, 30); 
  15. if (!$fp)  
  16. { 
  17.      echo "$errstr ($errno)<br />n"; 
  18. }  
  19. else  
  20. { 
  21.           $out = "GET $target HTTP/1.1rn"; 
  22.           $out .= "Host: $hostrn"; 
  23.           $out .= "Cookie: ASPSESSIONIDSQTBQSDA=DFCAPKLBBFICDAFMHNKIGKEGrn"; 
  24.           $out .= "Referer: $refererrn"; 
  25.           $out .= "Connection: Closernrn"; 
  26.           fwrite($fp, $out); 
  27.           while (!feof($fp))  
  28.           { 
  29.                   echo fgets($fp, 128); 
  30.           } 
  31.           fclose($fp); 
  32. } 
  33.  
【责任编辑:】(Top) 返回页面顶端
贴心
全国7×24小时客服热线
安全
病毒杀除率高于99%
稳定
网站可用性高于99.9%
实力
服务68家上市企业及集团公司
亿恩科技手机站
关注亿恩科技微信

亿恩科技—企业信息化一站式服务专家


Copyright © 2008- 深圳市亿恩科技有限公司版权所有 粤ICP备15056041号

联系我们 | 常见问题 | 在线留言 | 支付方式 | 软件开发 | 我的观点 | 资质荣誉 | 服务流程