1. 程式人生 > >【程式碼審計】大米CMS_V5.5.3 目錄遍歷漏洞分析

【程式碼審計】大米CMS_V5.5.3 目錄遍歷漏洞分析

 

0x00 環境準備

大米CMS官網:http://www.damicms.com

網站原始碼版本:大米CMS_V5.5.3試用版(更新時間:2017-04-15)

程式原始碼下載:http://www.damicms.com/downes/dami.rar

測試網站首頁:

 

0x01 程式碼分析

1、漏洞檔案位置:/Admin/Lib/Action/TplAction.class.php  第20-43行中:

  1. public function index()  
  2. {  
  3.     $dirpath = $this
    ->dirpath();//當前目錄  
  4.     $dirlast = $this->dirlast();//上一層目錄  
  5.     import("ORG.Util.Dir");  
  6.     $dir = new Dir($dirpath);  
  7.     $list_dir = $dir->toArray();  
  8.     if (empty($list_dir))  
  9.     {  
  10. 10.         $this->error('該資料夾下面沒有檔案!');  
  11. 11.     }  
  12. 12.     foreach($list_dir as $key=>$value)  
  13. 13.     {  
  14. 14.         $list_dir[$key]['pathfile'] = dami_url_repalce($value['path'],'desc').'|'.$value['filename'];  
  15. 15.     }  
  16. 16.     $_SESSION['tpl_jumpurl'] = '?s=Tpl/index/id/'.dami_url_repalce($dirpath,'desc');  
  17. 17.     if($dirlast && $dirlast != '.')  
  18. 18.     {  
  19. 19.         $this->assign('dirlast',dami_url_repalce($dirlast,'desc'));  
  20. 20.     }  
  21. 21.     $this->assign('dirpath',$dirpath);  
  22. 22.     $this->assign('list_dir',list_sort_by($list_dir,'mtime','desc'));  
  23. 23.     $this->display('index');  

24. }  

這段函式獲取當前目錄及上一層目錄引數,然後進行列目錄等操作,我們繼續看一下程式是如何獲取當前目錄的引數的呢?

2、漏洞檔案位置:/Admin/Lib/Action/TplAction.class.php  第45-61行中:

  1. public function dirpath()  
  2. {  
  3.     $id = dami_url_repalce(trim($_GET['id']));  
  4.     if ($id)   
  5.     {  
  6.         $dirpath = $id;  
  7.     }  
  8.     else  
  9.     {  
  10. 10.         $dirpath ='./Web/Tpl';  
  11. 11.     }  
  12. 12.     if (!strpos($dirpath,'Tpl'))   
  13. 13.     {  
  14. 14.         $this->error("不在模板資料夾範圍內!");  
  15. 15.     }  
  16. 16.     return $dirpath;  

17. }  

從GET方式獲取引數id,判斷引數是否為空,預設目錄是./web/tpl,然後檢測引數中是否包含tpl字串,最後返回當前目錄。我們可以構造引數id,繞過程式碼檢測,從而導致程式在實現上存在目錄遍歷漏洞,攻擊者可利用該漏洞獲取敏感資訊。

0x02 漏洞利用

1、登入後臺,程式碼檢測引數中是否包含tpl字串,因此我們可以在引數包含.\\Web\\Tpl\\,然後通過..\\,跳轉到上一層目錄,獲取網站目錄結構。

獲取網站根目錄Payload:

http://127.0.0.1/admin.php?s=/Tpl/index/id/.\\Web\\Tpl\\..\\..\\

2、可以繼續通過..\\遍歷磁碟目錄,獲取更多敏感資訊。

0x03 修復建議

1、過濾..等可能的惡意字元,防止目錄跳轉,最為推薦的方法;

2、正則判斷使用者輸入的引數的格式,看輸入的格式是否合法:這個方法的匹配最為準確和細緻,但是有很大難度,需要大量時間配置規則。

最後

歡迎關注個人微信公眾號:Bypass--,每週原創一篇技術乾貨。