PHP代码审计笔记--任意文件下载漏洞

 

在文件下载操作中,文件名及路径由客户端传入的参数控制,并且未进行有效的过滤,导致用户可恶意下载任意文件。

 

 

 0x01 客户端下载

常见于系统中存在文件(附件/文档等资源)下载的地方。

漏洞示例代码:

1.    <?php  
2.        $filename = $_GET['filename'];  
3.        echo file_get_contents($filename);  
4.        header('Content-Type: imgage/jpeg');  
5.        header('Content-Disposition: attachment; filename='.$filename);  
6.        header('Content-Lengh: '.filesize($filename));  
7.    ?>  

文件名用户可控,导致存在任意文件下载漏洞,攻击者提交url:

  1. test.php?filename=test.php  

即可下载test.php源码,可实现跨目录下载系统中的任意文件。

 

 

 0x02 服务端下载

常见于系统第三方补丁升级/插件安装、远程图片本地化。

 

 

 

 

任意文件读取

漏洞示例代码:

<?php
    $filename = $_GET['filename'];
    readfile($filename);
?>

可以看到参数并未进行任何过滤或处理,直接导入readfile函数中执行,导致程序在实现上存在任意文件读取漏洞。

 

相对路径  物理路径  fuzz

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   查看apache的配置文件
   /root/.bash_history          查看历史命令
   /root/.mysql_history
   /proc/self/fd/fd[0-9]*(文件标识符)
   /proc/mounts
   /porc/config.gz
 
index.php?f=../../../../../../etc/passwd

  1. /root/.ssh/authorized_keys

  2. /root/.ssh/id_rsa

  3. /root/.ssh/id_ras.keystore

  4. /root/.ssh/known_hosts //记录每个访问计算机用户的公钥

  5. /etc/passwd

  6. /etc/shadow

  7. /etc/my.cnf //mysql配置文件

  8. /etc/httpd/conf/httpd.conf //apache配置文件

  9. /root/.bash_history //用户历史命令记录文件

  10. /root/.mysql_history //mysql历史命令记录文件

  11. /proc/mounts //记录系统挂载设备

  12. /porc/config.gz //内核配置文件

  13. /var/lib/mlocate/mlocate.db //全文件路径

  14. /porc/self/cmdline //当前进程的cmdline参数

 
 

 

修复建议:要下载的文件地址保存至数据库中。文件路径保存至数据库,让用户提交文件对应ID下载文件。

 

参考链接:https://wenku.baidu.com/view/4f8e19e0b1717fd5360cba1aa8114431b90d8ee0.html

 

转载于:https://www.cnblogs.com/xiaozi/p/10601513.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值