from:http://www.cnbraid.com/2016/09/14/phpcms/
0x01 背景
周末审计了下phpcms的最新版本,前台已经很难找到漏洞了,故看了看后台相关的代码,发现还是有一处可以拿shell的漏洞。由于默认安装后需要超级管理员权限,故该漏洞很鸡肋,但感觉应该会在其它cms中也存在,所以主要分享下挖掘思路~
PS:使用的测试环境是php5.6(已经移除gpc选项)
0x02 漏洞分析
漏洞起源:
yoursitephpsso_serverphpcmsmodulesadminsystem.php下的uc函数:
<?php
public function uc() {
if (isset($_POST['dosubmit'])) {
$data = isset($_POST['data']) ? $_POST['data'] : '';
$data['ucuse'] = isset($_POST['ucuse']) && intval($_POST['ucuse']) ? intval($_POST['ucuse']) : 0;
$filepath = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.'system.php';
$config = include $filepath;
$uc_config = '<?php '."ndefine('UC_CONNECT', 'mysql');n";
foreach ($data as $k => $v) {
$old[] = "'$k'=>'".(isset($config[$k]) ? $config[$k] : $v)."',";
$new[] = "'$k'=>'$v',";
$uc_config .= "define('".strtoupper($k)."', '$v');n";
}
$html = file_get_contents($filepath);
$html = str_replace($old, $new, $html);
$uc_config_filepath = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.'uc_config.php';
@file_put_contents($uc_config_filepath, $uc_config);
@file_put_contents($filepath, $html);
$this->db->insert(array('name'=>'ucenter', 'data'=>array2string($data)), 1,1);
showmessage(L('operation_success'), HTTP_REFERER);
}
$data = array();
$r = $this->db->get_one(array('name'=>'ucenter'));
if ($r) {
$data = string2array($r['data']);
}
include $this->admin_tpl('system_uc');
}
...
将表单中的数据$data按照键值对遍历并以如下形式存储到$uc_config变量里:
$uc_config .= "define('".strtoupper($k)."', '$v');n"; |
上面只是对$k变量进行了字母转大写处理,然后就写到yoursitephpsso_servercachesconfigsuc_config.php中了,所以这里应该可以构造一句话木马写入到uc_config.php中,从而拿到webshell。
0x03 漏洞证明
通过观察uc_config.php,我们构造一句话木马的方法如下(审查元素或者代理改包均可):
0x04 漏洞修复
我这里引入了特殊字符的数组$array_key_safe = array(“,”, “;”, “‘“, “(“, “)”, ““);
然后在foreach循环时对$k进行过滤如下:
public function uc() { |
当然这个修补方法很暴力~
本文始发于微信公众号(关注安全技术):PHPCMS V9最新版本后台设计缺陷导致getshell
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论