1. 程式人生 > >【程式碼審計】大米CMS_V5.5.3 SQL注入漏洞分析

【程式碼審計】大米CMS_V5.5.3 SQL注入漏洞分析

 

0x00 環境準備

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

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

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

測試網站首頁:

 

0x01 程式碼分析

1、首先來看一下全域性過濾程式碼/php_safe.php 第24-33行中:

  1. //$ArrPGC=array_merge($_GET,$_POST,$_COOKIE);  
  2. foreach($_GET as $key=>$value){   
  3.     StopAttack($key,$value,$getfilter);  
  4. }  
  5. foreach($_POST as $key=>$value){   
  6.     StopAttack($key,$value,$postfilter);  
  7. }  
  8. foreach($_COOKIE as $key=>$value){   
  9.     StopAttack($key,$value,$cookiefilter);  

10. }  

這段函式對$_GET,$_POST,$_COOKIE等全域性變數呼叫StopAttack函式進行處理,可以發現如果是從$_REQUEST獲取引數,那麼將繞過全域性過濾防護。

2、漏洞檔案位置1:/Admin/Lib/Action/MemberAction.class.php  第93-110行中:

  1. function cartlist(){  
  2.     $model = D('TradeView');  
  3.     import('ORG.Util.Page');  
  4.     $where ='';  
  5.     if(!empty($_REQUEST['start_time']) && !empty($_REQUEST['end_time'])){  
  6.     $where .= 'member_trade.addtime>='.strtotime($_REQUEST['start_time']." 00:00:00").' and member_trade.addtime<='.strtotime($_REQUEST['end_time']." 23:59:59")." and ";  
  7.         }  
  8.     else if(!empty($_REQUEST['start_time']) && empty($_REQUEST['end_time'])){  
  9.         $where .= 'member_trade.addtime>='.strtotime($_REQUEST['start_time']." 00:00:00").' and member_trade.addtime<='.strtotime($_REQUEST['start_time']." 23:59:59")." and ";  
  10. 10.         }  
  11. 11.     else if(empty($_REQUEST['start_time']) && !empty($_REQUEST['end_time'])){  
  12. 12.         $where .= 'member_trade.addtime>='.strtotime($_REQUEST['end_time']." 00:00:00").' and member_trade.addtime<='.strtotime($_REQUEST['end_time']." 23:59:59")." and ";  
  13. 13.         }  
  14. 14.     if(!empty($_REQUEST['keyword'])){  
  15. 15.         $where .= "article.title like '%".htmlspecialchars(trim($_REQUEST['keyword']))."%' and ";  
  16. 16.         }  
  17. 17.     $where .='1=1';  
  18. 18.             $count = $model->where($where)->count();  
  19. 19.             $p = new Page($count,20);   

2、漏洞檔案位置2:/Admin/Lib/Action/MemberAction.class.php 第126-135行中:

  1. function userlist(){  
  2.     $model = M('member');  
  3.     import('ORG.Util.Page');  
  4.     $where ='';  
  5.     if(!empty($_REQUEST['keyword'])){  
  6.         $where .= "(username like '%".htmlspecialchars(trim($_REQUEST['keyword']))."%' or realname like '%".htmlspecialchars(trim($_REQUEST['keyword']))."%' or address like '%".htmlspecialchars(trim($_REQUEST['keyword']))."%') and ";  
  7.         }  
  8.     $where .='1=1';  
  9.             $count = $model->where($where)->count();  
  10. 10.             $p = new Page($count,20);   
  11. 11.               

在這兩個函式中,將獲取到的$_REQUEST['keyword']引數拼接到SQL語句,然後帶入資料庫執行,導致程式在實現上存在SQL注入漏洞,攻擊者可利用該漏洞獲取資料庫敏感資訊。

0x02 漏洞利用

1、登入後臺,網站後臺--會員系統--會員管理--關鍵字搜尋--注入點:

SQLMAP注入測試:

 

0x03 修復建議

1、使用引數化查詢避免SQL注入

最後

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