Home > php教程 > php手册 > body text

php curl伪造referer与来源IP实例

WBOY
Release: 2016-05-26 08:20:21
Original
1120 people have browsed it

php curl伪造referer与来源IP非常的简单,今天做一个图片采集的也有做过,下面我把两个例子都整理一下,供大家参考.

例子1,代码如下:

<?php 
	$post_data = array ( 
	  "user" => "gongwen", 
	  "pwd" => "123456" 
	); 
	 
	$header_ip = array( 
	  &#39;CLIENT-IP:88.88.88.88&#39;, 
	  &#39;X-FORWARDED-FOR:88.88.88.88&#39;, 
	); 
	 
	$referer=&#39;http://www.phprm.com&#39;; 
	 
	$ch = curl_init(); 
	curl_setopt ($ch, CURLOPT_URL, &#39;http://localhost/curl/two.PHP&#39;); 
	 
	//伪造来源referer 
	curl_setopt ($ch,CURLOPT_REFERER,$referer); 
	 
	//伪造来源ip 
	curl_setopt($ch, CURLOPT_HTTPHEADER, $header_ip); 
	 
	//提交post传参 
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
	 
	//加上这个表示执行curl_exec是把输出做为返回值,不会输出到浏览器 
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
	$out_put=curl_exec ($ch); 
	curl_close ($ch); 
	echo $out_put;
Copy after login

two.php

<?php 
	 //请求来源referer 
	 echo &#39;[HTTP_REFERER]<br>&#39;; 
	 echo $_SERVER[&#39;HTTP_REFERER&#39;]; 
	 
	 //请求来源ip 
	 //[注]此处的IP打印顺序是目前很多开源系统的IP获取顺序  
	 echo &#39;<hr>[IP]<br>&#39;; 
	 echo $_SERVER[&#39;HTTP_CLIENT_IP&#39;]; 
	 echo &#39;<br>&#39;; 
	 echo $_SERVER[&#39;HTTP_X_FORWARDED_FOR&#39;]; 
	 echo &#39;<br>&#39;; 
	 echo $_SERVER[&#39;REMOTE_ADDR&#39;]; 
	 
	 //POST数据 
	 echo &#39;<hr>[POST]<br><pre class="brush:php;toolbar:false">&#39;; 
	 var_dump($_POST); 
	 echo &#39;
Copy after login
';

例子2,代码如下:

function getImagesUrl( $url,$userinfo,$header) 
{ 
    $ch = curl_init(); 
    $timeout = 1; 
    curl_setopt ($ch, CURLOPT_URL, "$url"); 
    curl_setopt ($ch, CURLOPT_HTTPHEADER, $header); 
    curl_setopt ($ch, CURLOPT_REFERER, "http://www.phprm.com/");  
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ch, CURLOPT_USERAGENT, "$userinfo"); 
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);      
    $contents = curl_exec($ch); 
    curl_close($ch); 
    //echo $contents; 
    return $contents ; 
     
} 
 
function saveurl( $handle ,$filename) 
{ 
    $fp = fopen($filename,"w"); 
    fwrite($fp,$handle); 
    unset($fp); 
    unset($handle); 
} 
 
$binfo =array(&#39;Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.2; AskTbPTV/5.17.0.25589; Alexa Toolbar)&#39;,&#39;Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0&#39;,&#39;Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; Alexa Toolbar)&#39;,&#39;Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1; SV1)&#39;,$_SERVER[&#39;HTTP_USER_AGENT&#39;]); 
//123.125.68.* 
//125.90.88.*  
$cip = &#39;123.125.68.&#39;.mt_rand(0,254); 
$xip = &#39;125.90.88.&#39;.mt_rand(0,254); 
$header = array(  
&#39;CLIENT-IP:&#39;.$cip,  
&#39;X-FORWARDED-FOR:&#39;.$xip,  
);  
$u = $binfo[mt_rand(0,3)]; 
 
$get_file = getImagesUrl($value,$u,$header); 
saveurl($get_file,&#39;a.jpg&#39;);
Copy after login

即可.


教程地址:

欢迎转载!但请带上文章地址^^

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template