Modulares Exploit-Framework für CVE-2024-38077 (Windows RDL Heap Overflow) mit ASLR-Bypass, Heap-Grooming, ROP-Ketten-Generierung und DLL-Injection-Payloads für Pre-Auth Remote Code Execution.
Dieses Dokument erklärt jede Komponente des Frameworks, warum sie existiert und wie die Ausnutzung eines Heap-Buffer-Overflows auf modernem Windows funktioniert.
Der Windows Remote Desktop Licensing Service (lserver.exe) enthält einen Heap-Buffer-Overflow in der Funktion CDataCoding::DecodeData.
┌─────────────────────────────────────────────────────────────┐
│ VULNERABILIDADE: Cálculo incorreto de tamanho │
├─────────────────────────────────────────────────────────────┤
│ 1. Cliente envia dados Base64 de tamanho N │
│ 2. Servidor calcula: buffer_size = (N / 4) * 3 │
│ 3. Servidor aloca buffer de 'buffer_size' bytes │
│ 4. Decode Base64 REALMENTE escreve: ceil(N * 3/4) bytes │
│ 5. Se N não é múltiplo de 4: OVERFLOW! │
└─────────────────────────────────────────────────────────────┘
Konkretes Beispiel:
(4001 / 4) * 3 = 1000 * 3 = 3000 Bytes alloziertceil(4001 * 0.75) = 3001 Bytes geschrieben┌─────────────────────────────────────────────────────────────────┐
│ EXPLOIT CHAIN │
├──────────┬──────────┬──────────┬──────────┬──────────┬─────────┤
│ LEAK │ MODEL │ WRITE │ GROOM │ TRIGGER │ EXECUTE │
│ (ASLR) │ (Target) │ (Where) │ (Heap) │ (Use) │ (RCE) │
├──────────┼──────────┼──────────┼──────────┼──────────┼─────────┤
│ leak.py │target_ │write_ │heap_ │trigger │code_ │
│ │model.py │primitive │controller│.py │reuse.py │
│ │ │.py │.py │ │ │
└──────────┴──────────┴──────────┴──────────┴──────────┴─────────┘
↓ ↓
┌───────────┐ ┌──────────────┐
│ execution │ │ payload │
│ .py │ │ .py │
└───────────┘ └──────────────┘
↓ ↓
┌───────────────────────────────────────────────────────────┐
│ mitigations.py │
│ (DEP, ASLR, CFG awareness) │
└───────────────────────────────────────────────────────────┘
↓
┌───────────────────────────────────────────────────────────┐
│ exploit.py │
│ (Orchestrator) │
└───────────────────────────────────────────────────────────┘
primitives.py - FundamentLow-Level-Utilities zur Speichermanipulation.
Exploits benötigen:
# Pack/Unpack - Converter inteiros para bytes e vice-versa
p64(0xDEADBEEF) # → b'\xef\xbe\xad\xde\x00\x00\x00\x00'
p32(0x41414141) # → b'AAAA'
u64(b'\x41\x42...') # → 0x... (int)
# Padrão Cíclico - Para identificar offset de crash
cyclic(100) # Gera sequência De Bruijn
cyclic_find(pattern, value) # Encontra offset do valor
# Alinhamento - Memória precisa estar alinhada
align(0x1003, 0x10) # → 0x1010 (alinha para 16 bytes)
Reales Problem: Du verursachst einen Crash und das RIP enthält 0x61616171.
cyclic_find(pattern, 0x61616171) → exakter Offset!leak.py - ASLR-BypassAddress Space Layout Randomization: Bei jedem Boot/Start ändern sich die Adressen.
Boot 1: ntdll.dll @ 0x7FFA12340000
Boot 2: ntdll.dll @ 0x7FFB98760000
Boot 3: ntdll.dll @ 0x7FFC55550000
Ohne zu wissen, wo sich der Speicher befindet:
class LeakInfo:
"""Container para endereços vazados"""
heap_base: int # Base do heap
ntdll_base: int # Base do ntdll.dll
kernel32_base: int # Base do kernel32.dll
# ...
class LeakProvider:
"""Orquestrador de fontes de leak"""
sources: List[LeakSource]
def obtain() -> LeakInfo:
# Tenta cada fonte até conseguir
| Quelle | Funktionsweise | Wann verwenden |
|---|---|---|
ManualLeakSource | Benutzer stellt Adressen bereit | Lab/Debug mit Zugriff auf das Ziel |
ResponseLeakSource | Extrahiert aus RPC-Antworten | Wenn der Dienst Zeiger preisgibt |
TimingLeakSource | Zeitlicher Seitenkanal | Theoretisch, sehr schwierig |
In Demonstrationen/Labs kannst du:
--ntdll-base 0x7ffa... angebenDas simuliert einen echten Leak und ermöglicht es, den Rest der Kette zu testen.
target_model.py - Ziel-MappingModellierung der verwundbaren und angrenzenden Datenstrukturen.
Overflow ≠ Exploitation. Wir müssen wissen:
class VulnerableBuffer:
"""O buffer que vai sofrer overflow"""
allocation_size: int # Quanto foi alocado
write_size: int # Quanto será escrito
overflow_amount: int # Diferença = overflow
def calculate_overflow(input_size):
# Simula o bug de cálculo
alloc = (input_size // 4) * 3
actual = ((input_size + 3) // 4) * 3
return alloc, actual, actual - alloc
class AdjacentObject:
"""Objeto que será corrompido (adjacente no heap)"""
fields: List[StructField]
has_vtable: bool # Tem tabela virtual?
has_function_ptr: bool # Tem ponteiro de função?
# Objeto hipotético baseado em análise reversa
license_req = AdjacentObject(
name="CLicenseRequest",
typical_size=0x100,
has_vtable=True
)
# Campos mapeados
license_req.add_field("vtable", 0x00, 8, VTABLE, is_target=True)
license_req.add_field("refcount", 0x08, 4, REFCOUNT)
license_req.add_field("callback", 0x10, 8, CALLBACK, is_target=True)
is_target=True?Markiert für die Exploitation nützliche Felder:
vtable: Wenn wir es überschreiben, kontrollieren wir Methodenaufrufecallback: Wenn wir es überschreiben, kontrollieren wir, wann der Callback aufgerufen wirdwrite_primitive.py - Kontrolliertes SchreibenDer Overflow schreibt sequenzielle Daten. Aber wir brauchen: