漏洞介绍
一些网站由于业务需求,可能提供文件查看或下载的功能,如果对用户查看或下载的文件不做限制,则恶意用户
就能够查看或下载任意的文件,可以是源代码文件、敏感文件等。
利用条件
*存在读文件的函数
*读取文件的路径用户可控且未校验或校验不严*输出了文件内容漏洞危害
下载服务器任意文件,如脚本代码,服务及系统配置文件等
可用得到的代码进一步代码审计,得到更多可利用漏洞任意文件读取
代码形式如下几种:
<?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);?><?php $filename = "test.txt"; echo file_get_contents($filename);?><?php $filename = $_GET['f']; echo file_get_contents($filename);?>###$filename没有经过校验,或者校验不严格,用户可控制这个变量读取任意的文件。比如:/etc/passwd,./index.php等等任意文件下载
直接下载:
<a href=“http://www.xxxx.com/xxx.rar”>??</a>
用header()下载:
<?php
$filename = $_GET['f'];
header('Content-Type:image/gif'); header('Content-Disposition: attachment; filename='.$filename); header('Content-Length: '.filesize($filename)); readfile($filename); ?>###$filename没有经过校验,或者校验不严格,用户可控制这个变量读取任意的文件。比如:/etc/passwd,./index.php等等漏洞利用代码
readfile.php?file=/etc/passwd
readfile.php?file=../../../../../../../../etc/passwdreadfile.php?file=../../../../../../../../etc/passwd%00Google search
inurl:"readfile.php?file="
inurl:"read.php?file="inurl:"download.php?file="inurl:"down.php?file="漏洞挖掘
可以用Google hacking或web漏洞扫描器
从链接上看,形如: readfile.php?file=***.txt download.php?file=***.rar从参数名看,形如: &RealPath= &FilePath= &filepath= &Path= &path= &inputFile= &url= &urls= &Lang= &data= &readfile= &filep= &src= &menu= META-INF WEB-INF
敏感文件
Windows:
C:\boot.ini C:\Windows\System32\inetsrv\MetaBase.xml C:\Windows\repair\sam //存储系统初次安装的密码 C:\Program Files\mysql\my.ini //Mysql配置 C:\Program Fiels\mysql\data\mysql\user.MYD //Mysql root C:\Windows\php.ini //php配置信息 C:\Winsows\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_hstory /proc/self/fd/fd[0-9]*(文件标识符) /proc/mounts /proc/config.gz漏洞验证
index.php?f=../../../../../../../etc/passwd
index.php?f=../index.phpindex.php?f=file:///etc/passwd注:当参数f的参数值为php文件时,若是文件被解析则是文件包含漏洞, 若显示源码或提示下载则是文件查看与下载漏洞修复方案
过滤点(.)使用户在url中不能回溯上级目录
正则严格判断用户输入参数的格式php.ini 配置open_basedir限定文件访问范围