很久之前freebuf上看的一篇文章,这两天打算沉下心,从php入手,好好学习、分析一下有关网络安全的知识。
第一步:创建需要访问的php页面
<?php
header("Content-type: text/html; charset=utf-8");
header('Content-Type:image/png'); //创建图片
$myfile = fopen("testfile.txt", "w+"); //创建txt文件用于存储获取到的信息
$im = imagecreatetruecolor (1,1); //创建x、y坐标为1的黑色图片
$background_color = imagecolorallocatealpha($im, 255, 255, 255);//设置图片颜色和透明度(红、绿、蓝、透明度)
imagepng($im); //创建图片
imagedestroy($im); //销毁图片
function get_ip() //获取ip及相关信息
{
static $ipFrom = ['HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP','HTTP_FORWARDED_FOR','HTTP_FORWARDED','REMOTE_ADDR'];
//http_client_ip:代理服务器ip址;
//http_x_forwarded_for:用户代理ip,X-Forwarded-For:client, proxy1, proxy2格式;
//http_x_forwarded:用户代理信息
//http_x_cluster_client_ip:默认代理服务器ip;
//http_forwarded_for:用户代理ip
//http_forwarded:包含代理服务器的客户端的信息,即由于代理服务器在请求路径中的介入而被修改或丢失的信息。
//remote_add:用户最后一次与服务器握手的ip地址
foreach ($ipFrom as $key) //把ipfrom的值赋给key,并判断bool值
{
{
foreach (explode(',', $_SERVER[$key]) as $ip)//把,作为分隔符,同时把key格式化为[server]并赋值给ip,判断bool。
{
$ip = ($ip);
if ((bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))
//通过指定过滤器过滤;
//filter_validate_ip:把值作为ip验证
//filter_flag_ip4: 要求值是合法的 IPv4
//filter_flag_no_priv_range:要求值是 RFC 指定的私域 IP
//filter_flag_no_res_range:要求值不在保留的 IP 范围内。该标志接受 IPV4 和 IPV6 值。
{
return $ip;
}
}
}
}
return '127.0.0.1';
}
$ip=get_ip();//获取ip
if(isset($_SERVER['HTTP_REFERER'])) //获取http_referer
{
$from=$_SERVER['HTTP_REFERER'];
}
$client= $_SERVER['HTTP_USER_AGENT']; //获取用户浏览器
fwrite($myfile, $ip);//输出ip
fwrite($myfile, $from);//输出http_referer
fwrite($myfile, $client);//输出用户浏览器
?>
第二步
插入邮件图片链接选项
第三步
打开 http://XXX/testfile.txt 获取目标邮箱相关信息
鸣谢:dxkite大神给的思路 https://www.freebuf.com/articles/database/185954.html