
Collezione di script radare2 per l'analisi di malware: estrazione di binari da dump di memoria, patch degli header PE e decodifica degli import di funzioni hashate nello shellcode.
Una 'collezione' di script da utilizzare con radare2.
Questo script estrae file da dump di memoria (MDMP), dato un offset e una dimensione. Oltre all'estrazione, supporta anche la patch di base per file PE estratti. Al momento della scrittura, applicherà la patch agli offset all'interno delle intestazioni delle sezioni PE.
Requisiti
pip install r2pipe
Output di esempio con argomenti predefiniti:
Esempi
$ python2 ./r2_bin_carver.py ./memory.dmp 0x04af0000 0x2f000
[+] Carving to ./memory.dmp.0x04af0000
Output di esempio per l'estrazione binaria con controllo del magic e patch:
$ python2 ./r2_bin_carver.py -p -b MZ ./memory.dmp 0x04af0000 0x2f000
[+] Checking for magic: MZ - 4d5a
[+] Magic found, carving...
[+] Carving to ./memory.dmp.0x04af0000
[+] Patching...
[+] Found 3 sections to patch
[+] Patching Section 0.
Setting VirtualSize to 0x1fb0
Setting PointerToRawData to 0x1000
[+] Patching Section 1.
Setting VirtualSize to 0x5b7f
Setting PointerToRawData to 0x3000
[+] Patching Section 2.
Setting VirtualSize to 0x254d2
Setting PointerToRawData to 0x9000
[+] Pathing done
Questo script decodifica gli hash delle funzioni tramite ricerca in un database di hash pre-generato. Gestisce la generazione, la ricerca e l'analisi per le tecniche di hashing supportate.
Requisiti
pip install pefile r2pipe sqlite3
Tecniche Supportate
Le tecniche di hashing attualmente supportate.
$ python2 ./r2_hash_func_decoder.py -l
Suported Hashing Techniques:
- doublepulsar
- metasploit
Generazione del Database
Questo crea hash per tutte le funzioni esportate di una DLL o EXE, per tutte le tecniche di hashing supportate.
$ python2 ./r2_hash_func_decoder.py -g ntdll.dll
Generating Hashes:
Processing ./ntdll.dll...
Ricerca nel Database
Ricerca manuale nel database per un dato hash.
$ python2 ./r2_hash_func_decoder.py -s 0x6f721347
Searching for 0x6F721347...
- metasploit: ntdll.dll!RtlExitUserThread()
Analisi automatica in radare2
Questo cerca tutte le funzioni definite in radare2 per hash da decodificare per una data tecnica.
$ r2 shellcode
> af @ 0x0
> afl
0x00000000 31 931 fcn.00000000
> #!pipe python2 ./r2_hash_func_decoder.py -a doublepulsar
Analysing:
Function: fcn.00000000 0x0 931
|_ 0x0000001f movabs rcx, 0x3e1481df ntoskrnl.exe!PsLookupProcessByProcessId
|_ 0x0000003e movabs rcx, 0xa0031eba ntoskrnl.exe!PsGetProcessImageFileName
|_ 0x0000005d movabs rcx, 0xfffffffff9e70684 ntoskrnl.exe!KeStackAttachProcess
|_ 0x0000007c movabs rcx, 0x15ebfe4f ntoskrnl.exe!PsGetProcessPeb
|_ 0x0000009b movabs rcx, 0xa4ac30f9 ntoskrnl.exe!KeUnstackDetachProcess
|_ 0x000000ba movabs rcx, 0xecd0beca ntoskrnl.exe!ObfDereferenceObject
|_ 0x000000d9 movabs rcx, 0xffffffff5d9fb8ae ntdll.dll!ZwAllocateVirtualMemory
|_ 0x000000f8 movabs rcx, 0xffffffffe3690194 ntoskrnl.exe!ExAllocatePool
|_ 0x00000117 movabs rcx, 0xffffffffb80010f6 ntoskrnl.exe!KeInitializeApc
|_ 0x00000136 movabs rcx, 0xffffffffd25fd6ca ntoskrnl.exe!KeInsertQueueApc
|_ 0x00000155 movabs rcx, 0x1124a879 ntoskrnl.exe!KeGetCurrentThread
|_ 0x00000174 movabs rcx, 0x4f90c637 ntoskrnl.exe!PsGetCurrentProcess
|_ 0x00000193 movabs rcx, 0x10fee76c ntoskrnl.exe!PsGetThreadTeb
Oltre a quanto sopra, aggiungerà commenti alle righe appropriate:
[snip]
0x00000017 e8bc060000 call 0x6d8 ;[1]
│ 0x0000001c 4889c3 mov rbx, rax
│ 0x0000001f 48b9df81143e. movabs rcx, 0x3e1481df ; ntoskrnl.exe!PsLookupProcessByProcessId
│ 0x00000029 e826050000 call 0x554 ;[2]
│ 0x0000002e 4885c0 test rax, rax
│ ┌─< 0x00000031 0f8455030000 je 0x38c ;[3]
│ │ 0x00000037 4889059c0700. mov qword [0x000007da], rax ; [0x7da:8]=0
│ │ 0x0000003e 48b9ba1e03a0. movabs rcx, 0xa0031eba ; ntoskrnl.exe!PsGetProcessImageFileName
│ │ 0x00000048 e807050000 call 0x554 ;[2]
│ │ 0x0000004d 4885c0 test rax, rax
│ ┌──< 0x00000050 0f8436030000 je 0x38c ;[3]
│ ││ 0x00000056 488905850700. mov qword [0x000007e2], rax ; [0x7e2:8]=0
│ ││ 0x0000005d 48b98406e7f9. movabs rcx, 0xfffffffff9e70684 ; ntoskrnl.exe!KeStackAttachProcess
│ ││ 0x00000067 e8e8040000 call 0x554 ;[2]
[snip]