Home >php教程 >php手册 >php用Curl伪造客户端源IP

php用Curl伪造客户端源IP

WBOY
WBOYOriginal
2016-05-25 16:50:191344browse

在网上找了很多种用Curl伪造客户端源IP的一些方法,几乎都是使用curl函数,后来查证了此函数的使用果然是强大,不但可以伪造客户端源IP还可以伪造代理IP哦,下面我们来看看代码。

一般服务器获取客户IP有三种情况

1.在没用代理的情况下:

#http://www.phprm.com

REMOTE_ADDR =客户IP

HTTP_VIA = 空

HTTP_X_FORWARDED_FOR = 空

2.在使用代理且代理服务器有设置转发客户端IP的情况:

REMOTE_ADDR = 代理服务器 IP

HTTP_VIA = 代理服务器 IP

HTTP_X_FORWARDED_FOR = 客户IP

HTTP_VIA和HTTP_X_FORWARDED_FOR值可通过添加Header头自定义,进而可通过此隐藏客户端IP,前提是服务器端有启用X_FORWARDED_FOR。

测试效果,服务器端新建PHP程序.

实例代码一,代码如下

<?php 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "http://localhost/index.php"); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(&#39;X-FORWARDED-FOR:8.8.8.8&#39;, &#39;CLIENT-IP:8.8.8.8&#39;));  
//构造IP 
curl_setopt($ch, CURLOPT_REFERER, "http://www.phprm.com/ ");   //构造来路 
curl_setopt($ch, CURLOPT_HEADER, 1); 
$out = curl_exec($ch); 
curl_close($ch);
?>

实例代码二,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"]; 
echo "IP: " . getClientIp() . ""; 
echo "referer: " . $_SERVER["HTTP_REFERER"];
?>

伪造成功,这是不是给"刷票"的朋友提供了很好的换IP的方案,哈哈。

结果:

HTTP/1.1 200 OK Date: Wed, 03 Apr 2013 06:20:42 GMT Server: Apache/2.2.22 (Win32) PHP/5.3.13 
X-Powered-By: PHP/5.3.13 Content-Length: 44 Content-Type: text/html 
IP: 8.8.8.8 
referer: http://www.phprm.com/

下面看关于curl函数

curl相关函数列表:

curl_init — 初始化一个CURL会话
curl_setopt — 为CURL调用设置一个选项
curl_exec — 执行一个CURL会话
curl_close — 关闭一个CURL会话
curl_version — 返回当前CURL版本
1>curl_init — 初始化一个CURL会话


Statement:
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