empirecms最新版(v7.5)后台多处getshell分析
字数 975 2025-08-29 08:31:35
EmpireCMS v7.5 后台多处Getshell漏洞分析报告
漏洞概述
EmpireCMS v7.5 后台存在多处文件上传和代码执行漏洞,攻击者可以利用这些漏洞在服务器上获取webshell权限。本报告详细分析了两处典型漏洞的利用方式和原理。
漏洞一:LoadInMod功能文件上传漏洞
漏洞位置
ecmsmod.php 第155-162行
漏洞代码分析
elseif($enews=="LoadInMod") {
$file=$_FILES['file']['tmp_name'];
$file_name=$_FILES['file']['name'];
$file_type=$_FILES['file']['type'];
$file_size=$_FILES['file']['size'];
LoadInMod($_POST,$file,$file_name,$file_type,$file_size,$logininid,$loginin);
}
LoadInMod函数分析
function LoadInMod($add,$file,$file_name,$file_type,$file_size,$userid,$username){
// 验证权限
CheckLevel($userid,$username,$classid,"table");
// 基本验证
$tbname=RepPostVar(trim($add['tbname']));
if(!$file_name||!$file_size||!$tbname) {
printerror("EmptyLoadInMod","");
}
// 文件类型验证
$filetype=GetFiletype($file_name);
if($filetype!=".mod") {
printerror("LoadInModMustmod","");
}
// 表名检查
$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$tbname' limit 1");
if($num) {
printerror("HaveLoadInTb","");
}
// 文件上传
$path=ECMS_PATH."e/data/tmp/mod/uploadm".time().make_password(10).".php";
$cp=@move_uploaded_file($file,$path);
if(!$cp) {
printerror("EmptyLoadInMod","");
}
DoChmodFile($path);
@include($path); // 关键漏洞点
}
漏洞利用方式
- 构造一个.mod扩展名的文件,内容为PHP代码
- 通过后台LoadInMod功能上传该文件
- 文件会被上传到
e/data/tmp/mod/目录下并包含执行
示例攻击代码
<?php
file_put_contents("shell.php","<?php phpinfo(); ?>");
?>
漏洞利用限制
- 需要后台管理员权限
- 文件名包含随机部分(make_password(10)),但不需要预测,因为包含操作会执行上传的文件
漏洞二:AddUserpage功能代码注入漏洞
漏洞位置
ecmscom.php 第46行
漏洞代码分析
if($enews=="AddUserpage") {
AddUserpage($_POST,$logininid,$loginin);
}
AddUserpage函数分析
function AddUserpage($add,$userid,$username){
// 权限检查
CheckLevel($userid,$username,$classid,"userpage");
// 参数处理
$classid=(int)$add[classid];
$title=$add['title'];
$path=$add['path'];
$pagetext=$add['pagetext'];
// 基本验证
if(empty($title)||empty($path)) {
printerror("EmptyUserpagePath","history.go(-1)");
}
// 过滤处理
$title=hRepPostStr($title,1);
$path=hRepPostStr($path,1);
$pagetext=RepPhpAspJspcode($pagetext); // 关键过滤函数
$pagetitle=RepPhpAspJspcode($add[pagetitle]);
$pagekeywords=RepPhpAspJspcode($add[pagekeywords]);
$pagedescription=RepPhpAspJspcode($add[pagedescription]);
// 数据库操作
$tempid=(int)$add['tempid'];
$gid=(int)$add['gid'];
$sql=$empire->query("insert into {$dbtbpre}enewspage(...) values(...)");
$id=$empire->lastid();
// 关键漏洞点
ReUserpage($id,$pagetext,$path,$title,$pagetitle,$pagekeywords,$pagedescription,$tempid);
// ...
}
RepPhpAspJspcode函数分析
function RepPhpAspJspcode($string){
global $public_r;
// 关键问题:$public_r[candocode]默认为1,导致过滤无效
if(!$public_r[candocode]){
// 实际过滤代码不会执行
$string=str_replace("<\\","<\\",$string);
$string=str_replace("\\>","\\>",$string);
$string=str_replace("<?","<?",$string);
$string=str_replace("<%","<%",$string);
if(@stristr($string,' language')) {
$string=preg_replace(array('!<script!i','!</script>!i'),array('<script','</script>'),$string);
}
}
return $string;
}
ReUserpage函数分析
function ReUserpage($id,$pagetext,$path,$title="",$pagetitle,$pagekeywords,$pagedescription,$tempid=0){
global $public_r;
if(empty($path)) {
return "";
}
$path=eReturnTrueEcmsPath().'e/data/'.$path;
DoFileMkDir($path);//建目录
// 模板处理
if($tempid) {
$pagestr=GetPageTemp($tempid);
} else {
$pagestr=$pagetext;
}
$pagestr=InfoNewsBq("page".$id,$pagestr); // 关键处理
$pagestr=RepUserpageVar($pagetext,$title,$pagetitle,$pagekeywords,$pagedescription,$pagestr,$id);
$pagestr=str_replace("[!--news.url--]",$public_r['newsurl'],$pagestr);
WriteFiletext($path,$pagestr); // 写入文件
}
InfoNewsBq函数分析
function InfoNewsBq($classid,$indextext){
// ...
$file=eReturnTrueEcmsPath().'e/data/tmp/temp'.$classid.'.php';
// ...
$indextext=stripSlashes($indextext);
$indextext=ReplaceTempvar($indextext);
$indextext=DoRepEcmsLoopBq($indextext);
$indextext=RepBq($indextext);
// 写入临时文件
WriteFiletext($file,AddCheckViewTempCode().$indextext);
// 包含执行
ob_start();
include($file); // 关键漏洞点
$string=ob_get_contents();
ob_end_clean();
$string=RepExeCode($string);
return $string;
}
漏洞利用方式
- 通过AddUserpage功能提交恶意代码
- 由于RepPhpAspJspcode过滤失效,代码会被保留
- 最终通过InfoNewsBq函数的include操作执行恶意代码
示例攻击代码
<?php
file_put_contents("shell.php","<?php phpinfo(); ?>");
?>
漏洞利用限制
- 需要后台管理员权限
- 默认配置下($public_r[candocode]=1)可直接利用
漏洞修复建议
-
LoadInMod漏洞修复:
- 移除不必要的文件包含操作(@include($path))
- 增加文件内容安全检查
-
AddUserpage漏洞修复:
- 修改默认配置,设置$public_r[candocode]=0
- 使用更安全的RepPhpAspJspcodeText函数替代RepPhpAspJspcode
- 避免在InfoNewsBq函数中直接包含用户可控内容
-
通用建议:
- 对所有用户输入进行严格过滤
- 避免在文件操作中使用用户可控参数
- 限制后台功能权限
总结
EmpireCMS v7.5后台存在多处安全漏洞,主要问题集中在文件上传和代码执行方面。攻击者可以利用这些漏洞在获取后台权限后进一步获取服务器控制权。建议用户及时更新到最新版本或按照修复建议进行安全加固。