Unpacking
MITRE ATT&CK · T1027 phase: defense-evasion
Unpacking, packer/stub katmanını soyup gerçek kod ve veriyi ortaya çıkarmaktır. Amaç “her packer’ı otomatik kırmak” değil; OEP (Original Entry Point) civarında belleği dump edip statik analize dönmektir.
Ön koşullar
Section titled “Ön koşullar”- Packer ipucu (DIE, bölüm adları, az import)- Debugger + dump aracı (x64dbg+Scylla, gdb, pe-sieve)- Snapshot; anti-debug farkındalığıGenel iş akışı
Section titled “Genel iş akışı”-
Tespit — UPX mi, bilinen packer mi, custom mı?
-
Bilinen araç — UPX
-d, özel unpacker varsa dene. -
Runtime — stub’ı adımla; VirtualAlloc + kopyalama döngüsünü izle.
-
OEP — orijinal entry’ye gelince (tipik pushad/popad veya jmp gerçek kod).
-
Dump & fix — IAT onar (Scylla); dump’ı Ghidra’da aç.
-
Doğrula — strings/import anlamlı mı; değilse erken dump etmişsindir.
UPX ve bilinen paketler
Section titled “UPX ve bilinen paketler”diec ./sample.binupx -t ./sample.binupx -d -o sample_unpacked.bin ./sample.binfile sample_unpacked.binUPX bozulmuş/modified ise -d başarısız olur → manuel OEP yolu.
Manuel OEP (özet)
Section titled “Manuel OEP (özet)”PE (x64dbg):1. Entry’de dur2. ESP/stack’e hardware BP (sık “pushad” tekniği) veya VirtualAlloc dönüşüne BP3. Yazılan bölgede yürütme başlayınca OEP adayı4. Scylla: IAT Autosearch → Get Imports → DumpELF (gdb):1. break *entry / TLS callback sonrası2. mprotect/mmap RWX bölgelerini izle3. OEP’te gcore veya dd if=/proc/PID/mem …4. Yeniden file/strings/ghidra# Linux process memory ipucu (PID bilinirken)cat /proc/$(pgrep -n sample)/mapsgcore -o /tmp/sample.core $(pgrep -n sample)Dump sonrası kontrol
Section titled “Dump sonrası kontrol”file ./dump.exestrings -a -n 8 ./dump.exe | rg -i 'http|\.dll|password'rabin2 -i ./dump.exe | headHâlâ anlamsızsa: çok erken dump, şifreleme katmanı ikinci tur, veya process hollowing (başka image) — child process’i de dump et.
upx · unpack
embedded toolupx -d -o ./sample_unpacked.bin ./sample.binYalnızca gerçek UPX ise. Modified UPX’te manuel OEP gerekir.
upx · unpack
Section titled “upx · unpack”upx -d -o ./sample_unpacked.bin ./sample.binTipik tuzaklar
Section titled “Tipik tuzaklar”- Anti-debug: OEP’e gelmeden çıkış → Frida/patch- Çok katmanlı packer: dump → tekrar DIE- .NET: native packer + managed; dnSpy ile modülleri ayrıca aç- Sadece overlay şifreli veri: kod değil config dump’ıZincir
Section titled “Zincir”DIE → custom packer → x64dbg VirtualAlloc BP → Scylla dump + IAT fix → Ghidra’da C2 / ransomware note