php专区

 首页 > php专区 > PHP应用 > 常用功能 > php curl 伪造IP来源程序实现代码 - php高级应用

php curl 伪造IP来源程序实现代码 - php高级应用

分享到:
【字体:
导读:
          今天没事做自己写了一个php curl 伪造IP来源程序实例程序,这里可以伪造IP来源,伪造域名,伪造用户信息 定义伪造用户浏览器信息HTTP_USER_A...

php curl 伪造IP来源程序实现代码

今天没事做自己写了一个php curl 伪造IP来源程序实例程序,这里可以伪造IP来源,伪造域名,伪造用户信息.

定义伪造用户浏览器信息HTTP_USER_AGENT,代码如下:

  1. $binfo =array('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)','Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0','Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; Alexa Toolbar)','Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1; SV1)',$_SERVER['HTTP_USER_AGENT']); 
  2. //123.125.68.* 
  3. //125.90.88.* 

定义伪造IP来源段,这里我找的是百度的IP地址,代码如下:

  1. $cip = '123.125.68.'.mt_rand(0,254); 
  2. $xip = '125.90.88.'.mt_rand(0,254); 
  3. $header = array(  
  4. 'CLIENT-IP:'.$cip,  
  5. 'X-FORWARDED-FOR:'.$xip,  
  6. ); 

利用curl开始向服务器发送伪造信息,代码如下:

  1. function getimgs( $url,$userinfo,$header
  2.  $ch = curl_init(); 
  3.  $timeout = 5; 
  4.  curl_setopt ($ch, CURLOPT_URL, "$url"); 
  5.  curl_setopt ($ch, CURLOPT_HTTPHEADER, $header); 
  6.  curl_setopt ($ch, CURLOPT_REFERER, "http://www.baidu.com/");  
  7.  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
  8.  curl_setopt ($ch, CURLOPT_USERAGENT, "$userinfo"); 
  9.  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);   
  10.  $contents = curl_exec($ch); 
  11.  curl_close($ch); 
  12.  return $contents

获取到数据我们再保存,代码如下:

  1. function saveimgs( $handle ) 
  2.  $fp = fopen('a.jpg',"w"); 
  3.  fwrite($fp,$handle); 
  4.  unset($fp); 
  5.  unset($handle); 

测试伪造IP实例,代码如下:

  1. $url ='http://www.phpfensi.com/img/logo.jpg'
  2. $u = $binfo[mt_rand(0,3)]; 
  3. saveimgs(getimgs($url,$u,$header)); 

这样就在你当前目录保存成功了一个文件a.jpg文件,我现可以查看服务器日志是不是我们自定的用户信息呢?

192.168.1.108 - - [22/Jul/2013:10:29:37 +0800] "GET /test.php HTTP/1.1" 200 1244 "-" "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)"

192.168.1.108 - - [22/Jul/2013:10:29:37 +0800] "GET / HTTP/1.1" 200 40538 "http://www.baidu.com/" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; Alexa Toolbar)"

192.168.1.108 - - [22/Jul/2013:10:29:37 +0800] "GET /test.php HTTP/1.1" 200 1244 "-" "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)"

192.168.1.108 - - [22/Jul/2013:10:29:37 +0800] "GET / HTTP/1.1" 200 40538 "http://www.baidu.com/" "Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0"

看出来了吧,完全正确啊,只是IP地址我怎么没测试出来,这个使用php获取ip地址时会是显示我伪造IP地址了.

分享到:
php curl 分离header和body信息 - php高...
php curl 分离header和body信息 php中可以通过curl来模拟http请求,同时可以获取http response header和body,当然也设置参数可以只获取其中的某一个,当设置同时获取response header和body时候,它们会一同作为结果返回,这时需要我们自己来分离它们。 下面代码是模拟向google一个http GET请求,...
php header()函数设置页面Cache缓存 - ph...
php header()函数设置页面Cache缓存 header()函数在php的使用很大,下面我来介绍利用它实现页面缓存的一些方法,但使用header前必须注意,在它之前不能任何输出,包括空格。 手册上,我们对于cache都是写着如何设置,以便让代码不被cache,代码如下: header("Cache-Control: no-store, no-c...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……