web安全漏洞-任意文件下载漏洞

web安全漏洞-任意文件下载漏洞

php代码

1
2
3
4
5
6
7
8
<?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); //Content-Disposition 响应头,设置文件在浏览器打开还是下载
header('Content-Lengh: '.filesize($filename));
?>

window环境演示

环境介绍

C盘根目录-存放了flag.txt

www目录-有phpinfo.php

将上面代码,运行,访问,burpsuite抓包

linux环境演示

演示环境为bee蜂箱

首先打开虚拟机,查看环境IP

本地浏览器访问

burpsuite抓包

漏洞检测

*.php?file=/etc/passwd
*
.php?file=../../../../../../../../etc/passwd
****.php?file=../../../../../../../../etc/passwd%00

漏洞修复

  • 禁用../的使用
  • 使用open_basedir将下载文件限定为一个指定目录里
  • 正则严格判断用户输入参数的格式

漏洞探测-google语法

  • inrul:”readfile.php?file=“

可探测敏感信息

  • Linux:
  • ​ /root/.ssh/authorized_keys

  • ​ /root/.ssh/id_rsa

  • ​ /root/.ssh/id_ras.keystore

  • ​ /root/.ssh/known_hosts

  • ​ /etc/httpd/conf/httpd.conf

  • ​ /root/.bash_history

  • ​ /root/.mysql_history

  • ​ /proc/self/fd/fd[0-9]*(文件标识符)

  • ​ /proc/mounts

  • ​ /porc/config.gz

  • ​ /etc/passwd

  • ​ /etc/shadow

  • ​ /etc/my.cnf

  • Windows:
  • ​ C:\Program Files\mysql\my.ini

  • ​ C:\Program Files\mysql\data\mysql\user.MYD

  • ​ C:\Windows\php.ini

  • ​ C:\Windows\my.ini

  • ​ C:\boot.ini

  • ​ C:\Windows\System32\inetsrv\MetaBase.xml

  • ​ C:\Windows\repair\sam //存储系统初次安装的密码

代码审计挖掘经验

  • 查看网站,相应功能点—-查找相应代码文件

  • 搜索文件读取得函数

    file_get_contents(),fopen(),readfile(),fread(),fgets()等。

  • 文件包含函数include

经典举例—-phpcms v9 任意文件读取漏洞