php伪造ip 【转-未测试】

作者:小鱼的互联网观察 发布时间:November 29, 2009 分类:互联网观察

PHP代码

  1. <?php   
  2. $address = 'http://www.xmcase.com/dd.php';//地址,必须有http://之类   
  3. $myip = '.210.3210.34.0.13';   
  4.   
  5. ob_start();   
  6. $mtime = explode(' ', microtime());   
  7. $starttime = $mtime[1] + $mtime[0];   
  8.   
  9. $onoff = (function_exists('ini_get')) ? ini_get('register_globals') : get_cfg_var('register_globals');   
  10.   
  11. if($onoff != 1) {   
  12.         @extract($_POST, EXTR_SKIP);   
  13.         @extract($_GET, EXTR_SKIP);   
  14. }   
  15.   
  16. $self = $_SERVER['PHP_SELF'];   
  17. $myaddress = 'http://'.$_SERVER['HTTP_HOST'].$self;   
  18.   
  19. $comm = '';   
  20.   
  21. if(isset($url) && $url) {   
  22.         $url = str_replace($address''$url);   
  23. }   
  24. /* 
  25. foreach($_POST as $key => $val) { 
  26.         if($comm == '') { 
  27.                 $comm = $key.'='.rawurlencode($val); 
  28.         } else { 
  29.                 $comm = $comm.'&'.$key.'='.rawurlencode($val); 
  30.         } 
  31. } 
  32. */  
  33. $pcomm = '';   
  34. foreach($_POST as $key => $val) {   
  35.         if($pcomm == '') {   
  36.                 $pcomm .= $key.''.urlencode($val);   
  37.         } else {   
  38.                 $pcomm .= $pcomm.'&'.$key.'='.urlencode($val);   
  39.         }   
  40. }   
  41.   
  42. foreach($_GET as $key => $val) {   
  43.         if($key != 'url') {   
  44.                 if($comm == '') {   
  45.                         $comm = $key.'='.rawurlencode($val);   
  46.                 } else {   
  47.                         $comm = $comm.'&'.$key.'='.rawurlencode($val);   
  48.                 }   
  49.         }   
  50. }   
  51.   
  52. if(!$url) {   
  53.         $url = $address;   
  54. else {   
  55.         $url = $address.$url;   
  56.         if($comm) {   
  57.                 if(strstr($url,'?')) {   
  58.                         $url = $url.'&'.$comm;   
  59.                 } else {   
  60.                         $url = $url.'?'.$comm;   
  61.                 }   
  62.         }   
  63. }   
  64.   
  65. if($url) {   
  66.         $cookies'';   
  67.         if(count($_COOKIE)) {   
  68.                 foreach($_COOKIE as $cookie_name => $cookie_var) {   
  69.                         $cookies .= $cookies != '' ? '; '.$cookie_name.'='.$cookie_var : $cookie_name.'='.$cookie_var;   
  70.                 }   
  71.         }   
  72.   
  73.         $temp = @parse_url($url);   
  74.         $temp['port'] = isset($temp['port']) ? $temp['port'] : 80;   
  75.         $temp['path'] = isset($temp['path']) ? $temp['path'] : '/';   
  76.         $temp['file'] = substr($temp['path'], strrpos($temp['path'], '/')+1);   
  77.         $temp['dir'] = substr($temp['path'], 0, strrpos($temp['path'], '/'));   
  78.         $temp['base'] = $temp['scheme'].'://'.$temp['host'].($temp['port'] != 80 ? ':'.$temp['port'] : '').$temp['dir'];   
  79.         $temp['prev_dir'] = $temp['path'] != '/' ? substr($temp['base'], 0, strrpos($temp['base'], '/')+1) : $temp['base'].'/';   
  80.         $fp = @fsockopen($temp['host'], $temp['port'], $errno$errstr, 30);    
  81.         if($fp) {   
  82.                 if($_SERVER['REQUEST_METHOD'] != 'POST') {   
  83.                         @fputs($fp"GET $temp[path]?$temp[query] HTTP/1.1\r\n");   
  84.                 } else {   
  85.                         @fputs($fp"POST $temp[path]?$temp[query] HTTP/1.1\r\n");   
  86.                 }   
  87.                 @fputs($fp"Host: $temp[host]\r\n");    
  88.                 @fputs($fp"Accept: */*\r\n");    
  89.                   @fputs($fp"Referer: [url]http://$temp[url][host]/\r\n");   
  90.                 @fputs($fp"Cookie: $cookies\r\n");    
  91.                 @fputs($fp"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)\r\n");    
  92.                 @fputs($fp"via: 1.1 JEJE1:80 (squid/2.5.STABLE4-NT-CVS)\r\n");   
  93.                 @fputs($fp"X-Forwarded-For: $myip\r\n");   
  94.                 if($_SERVER['REQUEST_METHOD'] == 'POST') {   
  95.                         @fputs($fp"Content-Type: application/x-www-form-urlencoded\r\n");   
  96.                         @fputs($fp"Content-Length: ".strlen($pcomm)."\r\n\r\n");   
  97.                         @fputs($fp$pcomm);   
  98.                 }   
  99.                 @fputs($fp"Connection: Close\r\n\r\n");   
  100.   
  101.                 while($str = @fread($fp, 4096)) {   
  102.   
  103.                         if($str != "\r\n" && preg_match_all("#set-cookie:([^\r\n]*)#i"$str$matches)) {   
  104.                                 foreach($matches[1] as $cookie_info) {   
  105.                                         preg_match('#^\s*([^=;,\s]*)=?([^;,\s]*)#'$cookie_info$match) && list(, $name$value) = $match;   
  106.                                         preg_match('#;\s*expires\s*=([^;]*)#i'$cookie_info$match) && list(, $expires) = $match;   
  107.                                         $expires = isset($expires) ? strtotime($expires) : false;   
  108.                                         $expires = (!is_numeric($expires) || time() > $expires) ? false : $expires;   
  109.                                         setcookie($name$value$expires);   
  110.                                 }   
  111.                                 $str = str_replace($matches[0], ''$str);   
  112.                         }   
  113.                            
  114.                         $Content .= $str;   
  115.                 }   
  116.                 @fclose($fp);   
  117.                 if(strpos($Content'Content-Type: text/html')) {   
  118.                         $Content = substr($Contentstrpos($Content'Content-Type: text/html')+33);   
  119.                 } else {   
  120.                         $Content = substr($Contentstrpos($Contentchr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a))+4);   
  121.                 }   
  122.                    
  123.                 $Content = str_replace(' href="',' href="'.$myaddress.'?url=',$Content);   
  124.                 $Content = str_replace(' href=\'',' href=\''.$myaddress.'?url=',$Content);   
  125.                 $Content = str_replace(' src="',' src="'.$myaddress.'?url=',$Content);   
  126.                 $Content = str_replace(' src=\'',' src=\''.$myaddress.'?url=',$Content);   
  127.                 $Content = str_replace(' src=image',' src="'.$myaddress.'?url=image',$Content);   
  128.                 $Content = str_replace(' src=customavatars/',' src='.$myaddress.'?url=customavatars/',$Content);   
  129.                 $Content = str_replace(' action="',' action="http://oem.taihainet.com/2008jd/',$Content);   
  130.                 $Content = str_replace(' url("',' url("'.$myaddress.'?url=',$Content);   
  131.                 $Content = str_replace('target="saves"',"",$Content); 
  132.                 $Content = str_replace(' background="',' background="'.$myaddress.'?url=',$Content);   
  133.                 $Content = str_replace(' url(\'',' url(\''.$myaddress.'?url=',$Content);   
  134.                 $Content = str_replace($myaddress.'?url=javascript:','javascript:',$Content);   
  135.                 $Content = str_replace(';url=',';url='.$myaddress.'?url=',$Content);   
  136.                    
  137.                 echo $Content;   
  138.         }   
  139. }   
  140.   
  141. ?>   

标签: php伪造ip

互联网观察
php伪造ip 【转-未测试】
本文地址:http://tianmeng.org/archives/175/

相关文章

  • 无相关文章
文档信息

当前暂无评论 »

网站地图 京ICP证030173号