【程式碼審計】XYHCMS V3.5任意檔案下載漏洞分析
阿新 • • 發佈:2018-12-13
0x00 環境準備
XYHCMS官網:http://www.xyhcms.com/
網站原始碼版本:XYHCMS V3.5(2017-12-04 更新)
程式原始碼下載:http://www.xyhcms.com/Show/download/id/2/at/0.html
測試網站首頁:
0x01 程式碼分析
1、漏洞檔案位置:/App/Manage/Controller/DatabaseController.class.php 第365-379行:
- public function downFile() {
- if (empty($_GET['file']) || empty($_GET['type']) || !in_array($_GET['type'], array("zip", "sql"))) {
- $this->error("下載地址不存在");
- }
- $path = array("zip" => $this->getDbPath() . "Zip/", "sql" => $this->getDbPath() . '/');
- $filePath = $path[$_GET['type']] . $_GET['file'];
- if (!file_exists($filePath)) {
- $this->error("該檔案不存在,可能是被刪除");
- }
- 10. $filename = basename($filePath);
- 11. header("Content-type: application/octet-stream");
- 12. header('Content-Disposition: attachment; filename="' . $filename . '"');
- 13. header("Content-Length: " . filesize($filePath));
- 14. readfile($filePath);
15. }
這段函式中對提交的引數進行處理,首先判斷file/type引數是否為空及type檔案型別,然後拼接成完整的檔案路徑,檢測檔案是否存在。可以看出並沒有對下載的檔案做任何限制,導致程式在實現上存在任意檔案下載漏洞,可以構造引數下載伺服器任意檔案,如指令碼程式碼,服務及系統配置檔案等;可用得到的程式碼進一步程式碼審計,得到更多可利用漏洞。
0x02 漏洞利用
1、登入網站後臺,資料庫配置檔案路徑:\\App\\Common\\Conf\\db.php
因此‘/’作為引數邊界識別符,我們可以用‘\\’,來替換,組成相對路徑地址,下載資料庫配置檔案,構造url連結如下:
http://127.0.0.1/xyhai.php?s=/Database/downFile/file/..\\..\\..\\App\\Common\\Conf\\db.php/type/zip
2、成功跳出下載框,下載成功後,開啟配置檔案,獲取資料庫敏感資訊:
0x03 修復建議
1、在下載前對傳入的引數進行過濾,直接將..替換成空,就可以簡單實現防範的目的
2、最好還是可以對待下載檔案型別進行二次檢查,判斷是否允許下載型別。
最後
歡迎關注個人微信公眾號:Bypass--,每週原創一篇技術乾貨。