【程式碼審計】大米CMS_V5.5.3 SQL注入漏洞分析
阿新 • • 發佈: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、首先來看一下全域性過濾程式碼/php_safe.php 第24-33行中:
- //$ArrPGC=array_merge($_GET,$_POST,$_COOKIE);
- foreach($_GET as $key=>$value){
- StopAttack($key,$value,$getfilter);
- }
- foreach($_POST as $key=>$value){
- StopAttack($key,$value,$postfilter);
- }
- foreach($_COOKIE as $key=>$value){
- StopAttack($key,$value,$cookiefilter);
10. }
這段函式對$_GET,$_POST,$_COOKIE等全域性變數呼叫StopAttack函式進行處理,可以發現如果是從$_REQUEST獲取引數,那麼將繞過全域性過濾防護。
2、漏洞檔案位置1:/Admin/Lib/Action/MemberAction.class.php 第93-110行中:
- function cartlist(){
- $model = D('TradeView');
- import('ORG.Util.Page');
- $where ='';
- if(!empty($_REQUEST['start_time']) && !empty($_REQUEST['end_time'])){
- $where .= 'member_trade.addtime>='.strtotime($_REQUEST['start_time']." 00:00:00").' and member_trade.addtime<='.strtotime($_REQUEST['end_time']." 23:59:59")." and ";
- }
- else if(!empty($_REQUEST['start_time']) && empty($_REQUEST['end_time'])){
- $where .= 'member_trade.addtime>='.strtotime($_REQUEST['start_time']." 00:00:00").' and member_trade.addtime<='.strtotime($_REQUEST['start_time']." 23:59:59")." and ";
- 10. }
- 11. else if(empty($_REQUEST['start_time']) && !empty($_REQUEST['end_time'])){
- 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. }
- 14. if(!empty($_REQUEST['keyword'])){
- 15. $where .= "article.title like '%".htmlspecialchars(trim($_REQUEST['keyword']))."%' and ";
- 16. }
- 17. $where .='1=1';
- 18. $count = $model->where($where)->count();
- 19. $p = new Page($count,20);
2、漏洞檔案位置2:/Admin/Lib/Action/MemberAction.class.php 第126-135行中:
- function userlist(){
- $model = M('member');
- import('ORG.Util.Page');
- $where ='';
- if(!empty($_REQUEST['keyword'])){
- $where .= "(username like '%".htmlspecialchars(trim($_REQUEST['keyword']))."%' or realname like '%".htmlspecialchars(trim($_REQUEST['keyword']))."%' or address like '%".htmlspecialchars(trim($_REQUEST['keyword']))."%') and ";
- }
- $where .='1=1';
- $count = $model->where($where)->count();
- 10. $p = new Page($count,20);
- 11.
在這兩個函式中,將獲取到的$_REQUEST['keyword']引數拼接到SQL語句,然後帶入資料庫執行,導致程式在實現上存在SQL注入漏洞,攻擊者可利用該漏洞獲取資料庫敏感資訊。
0x02 漏洞利用
1、登入後臺,網站後臺--會員系統--會員管理--關鍵字搜尋--注入點:
SQLMAP注入測試:
0x03 修復建議
1、使用引數化查詢避免SQL注入
最後
歡迎關注個人微信公眾號:Bypass--,每週原創一篇技術乾貨。