【程式碼審計】大米CMS_V5.5.3 目錄遍歷漏洞分析
阿新 • • 發佈:2018-12-03
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行中:
- public function index()
- {
- $dirpath = $this
- $dirlast = $this->dirlast();//上一層目錄
- import("ORG.Util.Dir");
- $dir = new Dir($dirpath);
- $list_dir = $dir->toArray();
- if (empty($list_dir))
- {
- 10. $this->error('該資料夾下面沒有檔案!');
- 11. }
- 12. foreach($list_dir as $key=>$value)
- 13. {
- 14. $list_dir[$key]['pathfile'] = dami_url_repalce($value['path'],'desc').'|'.$value['filename'];
- 15. }
- 16. $_SESSION['tpl_jumpurl'] = '?s=Tpl/index/id/'.dami_url_repalce($dirpath,'desc');
- 17. if($dirlast && $dirlast != '.')
- 18. {
- 19. $this->assign('dirlast',dami_url_repalce($dirlast,'desc'));
- 20. }
- 21. $this->assign('dirpath',$dirpath);
- 22. $this->assign('list_dir',list_sort_by($list_dir,'mtime','desc'));
- 23. $this->display('index');
24. }
這段函式獲取當前目錄及上一層目錄引數,然後進行列目錄等操作,我們繼續看一下程式是如何獲取當前目錄的引數的呢?
2、漏洞檔案位置:/Admin/Lib/Action/TplAction.class.php 第45-61行中:
- public function dirpath()
- {
- $id = dami_url_repalce(trim($_GET['id']));
- if ($id)
- {
- $dirpath = $id;
- }
- else
- {
- 10. $dirpath ='./Web/Tpl';
- 11. }
- 12. if (!strpos($dirpath,'Tpl'))
- 13. {
- 14. $this->error("不在模板資料夾範圍內!");
- 15. }
- 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--,每週原創一篇技術乾貨。