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--,每周原创一篇技术干货。