今天我们来做一个简单的假的ip地址访问网站,这个可以利用php curl或fsockopen来实现,有需要的同学可以参考一下方案很简单的,不过此方案不完美对第三方工具没有用.
HTTP-REFERER这个变量已经越来越不可靠了,完全就是可以伪造出来的东东.
1.php 请求 2.php 。
1.php代码:
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://localhost/2.php"); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'X-FORWARDED-FOR:8.8.8.8', 'CLIENT-IP:8.8.8.8' )); //构造IP curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/ "); //构造来路 curl_setopt($ch, CURLOPT_HEADER, 1); $out = curl_exec($ch); curl_close($ch); ?>
2.php代码如下:
<?php function getClientIp() { if (!emptyempty($_SERVER["HTTP_CLIENT_IP"])) $ip = $_SERVER["HTTP_CLIENT_IP"]; else if (!emptyempty($_SERVER["HTTP_X_FORWARDED_FOR"])) $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; else if (!emptyempty($_SERVER["REMOTE_ADDR"])) $ip = $_SERVER["REMOTE_ADDR"]; else $ip = "err"; return $ip; } echo "IP: " . getClientIp() . ""; echo "referer: " . $_SERVER["HTTP_REFERER"]; ?>
伪造成功,这是不是给"刷票"的朋友提供了很好的换IP的方案,再看一下相对复杂的处理办法,PHP(前提是装了curl),PHP代码如下:
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.phprm.com"); curl_setopt($ch, CURLOPT_REFERER, "http://www.phprm.com/"); curl_exec($ch); curl_close($ch); ?>
PHP(不装curl用sock),代码如下:
<?php $server = '127.0.0.1'; $host = '127.0.0.1'; $target = '/xxx.asp'; $referer = 'http://127.0.0.1/'; // Referer $port = 80; $fp = fsockopen($server, $port, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET $target HTTP/1.1\r\n"; $out.= "Host: $hostrn"; $out.= "Cookie: ASPSESSIONIDSQTBQSDA=DFCAPKLBBFICDAFMHNKIGKEG\r\n"; $out.= "Referer: $referer\r\n"; $out.= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?>
IP也可以伪造,代码如下:
<?php $fp = fsockopen("192.168.0.128", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br>\n"; } else { $msg = "GET /003.php HTTP/1.0\r\n"; $msg.= "Host: 192.168.0.128\r\n"; $msg.= "Referer: http://www.phprm.com\r\n"; $msg.= "Client-IP: 1.1.1.1\r\n"; $msg.= "X-Forwarded-For: 1.1.1.1\r\n"; //主要是这里来构造IP $msg.= "Connection: Close\r\n\r\n"; fputs($fp, $msg); while (!feof($fp)) { echo fgets($fp, 1024); } fclose($fp); } ?>
记住用fsockopen时,命令最后一定要有\r\n\r\n,不然会超时.
其实这个可以用$_SERVER['REMOTE_ADDR']来得到正确IP,但是人们为了得到代理访问IP,而采用的得到IP的方法往往不是$_SERVER['REMOTE_ADDR'],这就为我们提供了机会.
文章地址:
转载随意^^请带上本文地址!