5get_it, el quinto reto del primer flare-on de Fireeye. No puedo más que decirles que este si que me ha costado. Comencemos con el writeup de este keylogger.

Bien comenzamos por descomprimir el challenge “C5.zip”, el cual esta protegido por la contraseña “malware”.

Nota: Todos los archivos de challenge se encuentran dentro de un zip que se descarga [aquí][c2c76e1c] [c2c76e1c]: http://www.flare-on.com/files/2014_FLAREOn_Challenges.zip “Flare-On 2014”

Unzip

Tomamos algo de información base sobre el binario:

Información Base

Ok, tenemos el primer vistazo que nos dice que tratamos con una DLL que no se encuentra empaquetada, con formato PE para 32 bits y que salvo la imagen base, todo parece normal.

Continuemos identificándolo en radare2:

Análisis base de Radare2

El show info all o ia de radare2 nos entrega mucha información, que coincide con lo primero que empezamos a observar, adicionalmente nos devuelve que tenemos bastante funciones importadas (al menos 82) las cuales no coloco en imagen para no perderlas de vista:

NumVaddrBindTypeName
10x10014000NONEFUNCADVAPI32.dll_RegQueryValueExA
20x10014004NONEFUNCADVAPI32.dll_RegOpenKeyExA
30x10014008NONEFUNCADVAPI32.dll_RegSetValueExA
40x1001400cNONEFUNCADVAPI32.dll_RegCreateKeyA
50x10014010NONEFUNCADVAPI32.dll_RegCloseKey
10x10014018NONEFUNCKERNEL32.dll_Sleep
20x1001401cNONEFUNCKERNEL32.dll_GetModuleHandleA
30x10014020NONEFUNCKERNEL32.dll_CopyFileA
40x10014024NONEFUNCKERNEL32.dll_GetModuleFileNameA
50x10014028NONEFUNCKERNEL32.dll_GetLastError
60x1001402cNONEFUNCKERNEL32.dll_GetModuleHandleExA
70x10014030NONEFUNCKERNEL32.dll_AllocConsole
80x10014034NONEFUNCKERNEL32.dll_CreateFileW
90x10014038NONEFUNCKERNEL32.dll_GetStringTypeW
100x1001403cNONEFUNCKERNEL32.dll_LCMapStringW
110x10014040NONEFUNCKERNEL32.dll_HeapSize
120x10014044NONEFUNCKERNEL32.dll_HeapAlloc
130x10014048NONEFUNCKERNEL32.dll_EnterCriticalSection
140x1001404cNONEFUNCKERNEL32.dll_LeaveCriticalSection
150x10014050NONEFUNCKERNEL32.dll_GetCurrentThreadId
160x10014054NONEFUNCKERNEL32.dll_DecodePointer
170x10014058NONEFUNCKERNEL32.dll_GetCommandLineA
180x1001405cNONEFUNCKERNEL32.dll_HeapFree
190x10014060NONEFUNCKERNEL32.dll_CloseHandle
200x10014064NONEFUNCKERNEL32.dll_UnhandledExceptionFilter
210x10014068NONEFUNCKERNEL32.dll_SetUnhandledExceptionFilter
220x1001406cNONEFUNCKERNEL32.dll_IsDebuggerPresent
230x10014070NONEFUNCKERNEL32.dll_EncodePointer
240x10014074NONEFUNCKERNEL32.dll_TerminateProcess
250x10014078NONEFUNCKERNEL32.dll_GetCurrentProcess
260x1001407cNONEFUNCKERNEL32.dll_SetHandleCount
270x10014080NONEFUNCKERNEL32.dll_GetStdHandle
280x10014084NONEFUNCKERNEL32.dll_InitializeCriticalSectionAndSpinCount
290x10014088NONEFUNCKERNEL32.dll_GetFileType
300x1001408cNONEFUNCKERNEL32.dll_GetStartupInfoW
310x10014090NONEFUNCKERNEL32.dll_DeleteCriticalSection
320x10014094NONEFUNCKERNEL32.dll_RtlUnwind
330x10014098NONEFUNCKERNEL32.dll_IsProcessorFeaturePresent
340x1001409cNONEFUNCKERNEL32.dll_GetProcAddress
350x100140a0NONEFUNCKERNEL32.dll_GetModuleHandleW
360x100140a4NONEFUNCKERNEL32.dll_ExitProcess
370x100140a8NONEFUNCKERNEL32.dll_WriteFile
380x100140acNONEFUNCKERNEL32.dll_GetModuleFileNameW
390x100140b0NONEFUNCKERNEL32.dll_HeapCreate
400x100140b4NONEFUNCKERNEL32.dll_HeapDestroy
410x100140b8NONEFUNCKERNEL32.dll_TlsAlloc
420x100140bcNONEFUNCKERNEL32.dll_TlsGetValue
430x100140c0NONEFUNCKERNEL32.dll_TlsSetValue
440x100140c4NONEFUNCKERNEL32.dll_TlsFree
450x100140c8NONEFUNCKERNEL32.dll_InterlockedIncrement
460x100140ccNONEFUNCKERNEL32.dll_SetLastError
470x100140d0NONEFUNCKERNEL32.dll_InterlockedDecrement
480x100140d4NONEFUNCKERNEL32.dll_FreeEnvironmentStringsW
490x100140d8NONEFUNCKERNEL32.dll_WideCharToMultiByte
500x100140dcNONEFUNCKERNEL32.dll_GetEnvironmentStringsW
510x100140e0NONEFUNCKERNEL32.dll_QueryPerformanceCounter
520x100140e4NONEFUNCKERNEL32.dll_GetTickCount
530x100140e8NONEFUNCKERNEL32.dll_GetCurrentProcessId
540x100140ecNONEFUNCKERNEL32.dll_GetSystemTimeAsFileTime
550x100140f0NONEFUNCKERNEL32.dll_SetStdHandle
560x100140f4NONEFUNCKERNEL32.dll_GetConsoleCP
570x100140f8NONEFUNCKERNEL32.dll_GetConsoleMode
580x100140fcNONEFUNCKERNEL32.dll_FlushFileBuffers
590x10014100NONEFUNCKERNEL32.dll_CreateFileA
600x10014104NONEFUNCKERNEL32.dll_LoadLibraryW
610x10014108NONEFUNCKERNEL32.dll_GetCPInfo
620x1001410cNONEFUNCKERNEL32.dll_GetACP
630x10014110NONEFUNCKERNEL32.dll_GetOEMCP
640x10014114NONEFUNCKERNEL32.dll_IsValidCodePage
650x10014118NONEFUNCKERNEL32.dll_HeapReAlloc
660x1001411cNONEFUNCKERNEL32.dll_WriteConsoleW
670x10014120NONEFUNCKERNEL32.dll_MultiByteToWideChar
680x10014124NONEFUNCKERNEL32.dll_SetFilePointer
690x10014128NONEFUNCKERNEL32.dll_SetEndOfFile
700x1001412cNONEFUNCKERNEL32.dll_GetProcessHeap
710x10014130NONEFUNCKERNEL32.dll_ReadFile
10x10014138NONEFUNCUSER32.dll_ShowWindow
20x1001413cNONEFUNCUSER32.dll_GetAsyncKeyState
30x10014140NONEFUNCUSER32.dll_GetWindowLongA
40x10014144NONEFUNCUSER32.dll_DialogBoxIndirectParamW
50x10014148NONEFUNCUSER32.dll_EndDialog
60x1001414cNONEFUNCUSER32.dll_FindWindowA

Tenemos básicamente 3 bibliotecas dinámicas de las que importamos funciones: user32.dll, kernel32.dll y advapi32.dll. Decidí que para este writeup tengamos un enfoque mas estático de lo que a continuación sucede, ya que en un análisis mas tradicional, continuaríamos por la parte dinámica.

Comenzamos por llamar al shorcut de análisis:

AAAA

Ok, con el análisis completado, veamos que funciones pudimos recuperar:

afl

Como el resultado de afl era muy extenso, decidí convertirlo en tabla:

addressnbbssizename
0x10001000485sub.KERNEL32.dll_Sleep_0
0x100010601425fcn.10001060
0x1000124011024fcn.10001240
0x10009340115fcn.10009340
0x100093b0110fcn.100093b0
0x100093c0115fcn.100093c0
0x100093d0115fcn.100093d0
0x100093e0115fcn.100093e0
0x100093f0115fcn.100093f0
0x10009400115fcn.10009400
0x10009410115fcn.10009410
0x10009420115fcn.10009420
0x10009430115fcn.10009430
0x10009440677fcn.10009440
0x10009490115fcn.10009490
0x100094a0115fcn.100094a0
0x100094b0115fcn.100094b0
0x100094c0115fcn.100094c0
0x100094d0677fcn.100094d0
0x10009520115fcn.10009520
0x10009530115fcn.10009530
0x10009540115fcn.10009540
0x10009550115fcn.10009550
0x10009560115fcn.10009560
0x10009570115fcn.10009570
0x10009580115fcn.10009580
0x10009590115fcn.10009590
0x100095a0115fcn.100095a0
0x100095b0115fcn.100095b0
0x100097d08108fcn.100097d0
0x10009840115fcn.10009840
0x10009850446fcn.10009850
0x1000988010139fcn.10009880
0x10009910677fcn.10009910
0x10009960446fcn.10009960
0x100099908108fcn.10009990
0x10009a00446fcn.10009a00
0x10009a30446fcn.10009a30
0x10009a60115fcn.10009a60
0x10009a70446fcn.10009a70
0x10009aa0677fcn.10009aa0
0x10009af0329fcn.10009af0
0x10009b10677fcn.10009b10
0x10009b6012173fcn.10009b60
0x10009c10115fcn.10009c10
0x10009c20115fcn.10009c20
0x10009c308108fcn.10009c30
0x10009ca0446fcn.10009ca0
0x10009cd012173fcn.10009cd0
0x10009d80446fcn.10009d80
0x10009db0115fcn.10009db0
0x10009dc0115fcn.10009dc0
0x10009dd0115fcn.10009dd0
0x10009de0115fcn.10009de0
0x10009e30110fcn.10009e30
0x10009e40110fcn.10009e40
0x10009e50110sub.RETURN_e50
0x10009e60110sub.BACKSPACE_e60
0x10009e70110sub.TAB_e70
0x10009e80110sub.CTRL_e80
0x10009e90110sub.DELETE_e90
0x10009ea0110sub.CAPS_LOCK_ea0
0x10009eb01141274-> 1125sub.USER32.dll_GetAsyncKeyState_eb0
0x1000a4c09162sub.KERNEL32.dll_Sleep_4c0
0x1000a5709157sub.ADVAPI32.dll_RegOpenKeyExA_570
0x1000a6106103sub.SOFTWARE__Microsoft__Windows__CurrentVersion__Run_610
0x1000a6805275sub.KERNEL32.dll_AllocConsole_680
0x1000a7939109fcn.1000a793
0x1000a8007105fcn.1000a800
0x1000a86c18fcn.1000a86c
0x1000a87416251fcn.1000a874
0x1000a97218fcn.1000a972
0x1000a97a11178fcn.1000a97a
0x1000aa2c110fcn.1000aa2c
0x1000aa36123fcn.1000aa36
0x1000aa4d333fcn.1000aa4d
0x1000aa6e315 -> 277fcn.1000aa6e
0x1000aa80443fcn.1000aa80
0x1000aab0336722 -> 305fcn.1000aab0
0x1000ab2a16148sub.KERNEL32.dll_HeapAlloc_b2a
0x1000abbe133fcn.1000abbe
0x1000abe014139fcn.1000abe0
0x1000ac6b19258fcn.1000ac6b
0x1000ad6d110fcn.1000ad6d
0x1000ad7716fcn.1000ad77
0x1000ae4e565sub.KERNEL32.dll_EnterCriticalSection_e4e
0x1000ae8f350sub.KERNEL32.dll_EnterCriticalSection_e8f
0x1000aec1460sub.KERNEL32.dll_LeaveCriticalSection_ec1
0x1000aefd347sub.KERNEL32.dll_LeaveCriticalSection_efd
0x1000af2c28356 -> 332sub.KERNEL32.dll_GetCommandLineA_f2c
0x1000b005420fcn.1000b005
0x1000b09023246 -> 226fcn.1000b090
0x1000b186335entry0
0x1000b1a9458sub.KERNEL32.dll_HeapFree_1a9
0x1000b1e313156sub.KERNEL32.dll_CloseHandle_1e3
0x1000b27f12185fcn.1000b27f
0x1000b33b18fcn.1000b33b
0x1000b343338fcn.1000b343
0x1000b369449fcn.1000b369
0x1000b39a9104fcn.1000b39a
0x1000b402872fcn.1000b402
0x1000b44a17209 -> 187fcn.1000b44a
0x1000b4ec117fcn.1000b4ec
0x1000b51b19fcn.1000b51b
0x1000b52419fcn.1000b524
0x1000b52d115fcn.1000b52d
0x1000b53c7297sub.KERNEL32.dll_IsDebuggerPresent_53c
0x1000b665137sub.KERNEL32.dll_GetCurrentProcess_665
0x1000b68a345sub.KERNEL32.dll_DecodePointer_68a
0x1000b6b7116fcn.1000b6b7
0x1000b6c7766fcn.1000b6c7
0x1000b709319fcn.1000b709
0x1000b71c319fcn.1000b71c
0x1000b72f135fcn.1000b72f
0x1000b760169fcn.1000b760
0x1000b7a5120fcn.1000b7a5
0x1000b94f13156fcn.1000b94f
0x1000b9eb552fcn.1000b9eb
0x1000ba1f37343fcn.1000ba1f
0x1000bb7649581sub.KERNEL32.dll_GetStartupInfoW_b76
0x1000bdbb1083sub.KERNEL32.dll_DeleteCriticalSection_dbb
0x1000be0e74663sub.UTF_8_e0e
0x1000c0a518295sub.KERNEL32.dll_InitializeCriticalSectionAndSpinCount_a5
0x1000c1cf19fcn.1000c1cf
0x1000c1e07144fcn.1000c1e0
0x1000c2d2123fcn.1000c2d2
0x1000c2e9125fcn.1000c2e9
0x1000c302125fcn.1000c302
0x1000c31b123fcn.1000c31b
0x1000c3323262loc.1000c332
0x1000c502443sub.mscoree.dll_502
0x1000c52d123sub.KERNEL32.dll_ExitProcess_52d
0x1000c54519fcn.1000c545
0x1000c54e19fcn.1000c54e
0x1000c557151fcn.1000c557
0x1000c58a736fcn.1000c58a
0x1000c5ae13151fcn.1000c5ae
0x1000c64526320sub.KERNEL32.dll_DecodePointer_645
0x1000c785122fcn.1000c785
0x1000c79b115fcn.1000c79b
0x1000c7aa130fcn.1000c7aa
0x1000c7c8538fcn.1000c7c8
0x1000c7ee23431sub.Runtime_Error_____Program:_7ee
0x1000c99d557fcn.1000c99d
0x1000c9d6130sub.KERNEL32.dll_HeapCreate_9d6
0x1000c9f4120sub.KERNEL32.dll_HeapDestroy_9f4
0x1000ca08115fcn.1000ca08
0x1000ca17440sub.KERNEL32.dll_DecodePointer_a17
0x1000ca3f19sub.KERNEL32.dll_EncodePointer_a3f
0x1000ca51352sub.KERNEL32.dll_TlsGetValue_a51
0x1000ca85165010 -> 148sub.KERNEL32.dll_DecodePointer_a85
0x1000cac23156sub.KERNEL32.DLL_ac2
0x1000cb6419fcn.1000cb64
0x1000cb6d19fcn.1000cb6d
0x1000cb766121sub.KERNEL32.dll_GetLastError_b76
0x1000cbef326fcn.1000cbef
0x1000cc0928279sub.KERNEL32.dll_InterlockedDecrement_c09
0x1000cd2319fcn.1000cd23
0x1000cd2f19fcn.1000cd2f
0x1000cd389110sub.KERNEL32.dll_TlsGetValue_d38
0x1000cda617379sub.KERNEL32.DLL_da6
0x1000cf2111135fcn.1000cf21
0x1000cfa8851fcn.1000cfa8
0x1000cfdb11116fcn.1000cfdb
0x1000d04f2342953sub.KERNEL32.dll_DecodePointer_4f
0x1000dbfb769sub.KERNEL32.dll_Sleep_bfb
0x1000dc40776sub.KERNEL32.dll_Sleep_c40
0x1000dc8c878sub.KERNEL32.dll_Sleep_c8c
0x1000dcda10147sub.KERNEL32.dll_DeleteCriticalSection_cda
0x1000dd6d19fcn.1000dd6d
0x1000dd76774sub.KERNEL32.dll_InitializeCriticalSectionAndSpinCount_d76
0x1000de17123sub.KERNEL32.dll_LeaveCriticalSection_e17
0x1000de2e13185sub.KERNEL32.dll_InitializeCriticalSectionAndSpinCount_e2e
0x1000dee719fcn.1000dee7
0x1000def0451sub.KERNEL32.dll_EnterCriticalSection_ef0
0x1000df2321220fcn.1000df23
0x1000dfff61410fcn.1000dfff
0x1000e19912187sub.KERNEL32.dll_GetModuleFileNameA_199
0x1000e25413151sub.KERNEL32.dll_GetEnvironmentStringsW_254
0x1000e2eb538fcn.1000e2eb
0x1000e33740330fcn.1000e337
0x1000e481332fcn.1000e481
0x1000e4a19155sub.KERNEL32.dll_GetSystemTimeAsFileTime_4a1
0x1000e53c14129sub.KERNEL32.dll_SetStdHandle_53c
0x1000e5bd15134sub.KERNEL32.dll_SetStdHandle_5bd
0x1000e6438105fcn.1000e643
0x1000e6ac9145main
0x1000e74219fcn.1000e742
0x1000e74b139sub.KERNEL32.dll_LeaveCriticalSection_74b
0x1000e77229400 -> 385sub.KERNEL32.dll_InitializeCriticalSectionAndSpinCount_772
0x1000e84419fcn.1000e844
0x1000e90219fcn.1000e902
0x1000e90b991789sub.KERNEL32.dll_GetConsoleMode_90b
0x1000f00812201fcn.1000f008
0x1000f0d418fcn.1000f0d4
0x1000f0dc16206sub.KERNEL32.dll_FlushFileBuffers_dc
0x1000f1ad18fcn.1000f1ad
0x1000f1b518fcn.1000f1b5
0x1000f1c0453fcn.1000f1c0
0x1000f200768fcn.1000f200
0x1000f2503139fcn.1000f250
0x1000f30c786fcn.1000f30c
0x1000f36231356fcn.1000f362
0x1000f4d05610779 -> 668fcn.1000f4d0
0x1000f8311441844sub.KERNEL32.dll_CreateFileA_831
0x1000ff658145fcn.1000ff65
0x1000fffb546fcn.1000fffb
0x10010029132fcn.10010029
0x1001004959516fcn.10010049
0x1001024d126fcn.1001024d
0x1001026736332fcn.10010267
0x100103b3126fcn.100103b3
0x100104358132fcn.10010435
0x100104e5131fcn.100104e5
0x1001050413fcn.10010504
0x10010540117sub.KERNEL32.dll_EncodePointer_540
0x10010551130fcn.10010551
0x1001056f755fcn.1001056f
0x100105a6113sub.KERNEL32.dll_DecodePointer_5a6
0x100105b343419 -> 398sub.KERNEL32.dll_DecodePointer_5b3
0x1001071a315fcn.1001071a
0x10010756115fcn.10010756
0x10010765115fcn.10010765
0x1001077413182sub.KERNEL32.dll_DecodePointer_774
0x1001085b154fcn.1001085b
0x1001089116fcn.10010891
0x10010897123fcn.10010897
0x100108ae335sub.KERNEL32.dll_EncodePointer_8ae
0x100108d123364sub.USER32.DLL_8d1
0x10010a3d16117fcn.10010a3d
0x10010ab228205fcn.10010ab2
0x10010b7f327fcn.10010b7f
0x10010b9a1299fcn.10010b9a
0x10010bfd663fcn.10010bfd
0x10010c3c17143sub.KERNEL32.dll_InterlockedIncrement_c3c
0x10010ccb19153sub.KERNEL32.dll_InterlockedDecrement_ccb
0x10010d6428331fcn.10010d64
0x10010eaf1077fcn.10010eaf
0x10010efc7109fcn.10010efc
0x10010f69112fcn.10010f69
0x10010f75947fcn.10010f75
0x10010fa45100fcn.10010fa4
0x1001100826400sub.KERNEL32.dll_GetCPInfo_8
0x1001119813152sub.KERNEL32.dll_InterlockedDecrement_198
0x1001123319fcn.10011233
0x1001123c12124sub.KERNEL32.dll_GetOEMCP_23c
0x100112b837489sub.KERNEL32.dll_IsValidCodePage_2b8
0x100114a127410 -> 399sub.KERNEL32.dll_InterlockedDecrement_4a1
0x1001160219fcn.10011602
0x1001163b330fcn.1001163b
0x10011659122fcn.10011659
0x1001166f35341sub.KERNEL32.dll_WideCharToMultiByte_66f
0x100117c4129fcn.100117c4
0x100117e1356fcn.100117e1
0x10011819119fcn.10011819
0x1001183011149fcn.10011830
0x100118c515130sub.KERNEL32.dll_HeapAlloc_8c5
0x1001194718173sub.KERNEL32.dll_HeapReAlloc_947
0x100119f41395fcn.100119f4
0x10011a53983fcn.10011a53
0x10011aa6124fcn.10011aa6
0x10011abe666sub.KERNEL32.dll_WriteConsoleW_abe
0x10011b0026278sub.KERNEL32.dll_MultiByteToWideChar_b00
0x10011c16126fcn.10011c16
0x10011c308133sub.KERNEL32.dll_SetFilePointer_c30
0x10011cb512224fcn.10011cb5
0x10011d95110fcn.10011d95
0x10011d9f473fcn.10011d9f
0x10011eeb33438sub.KERNEL32.dll_GetProcessHeap_eeb
0x100120a11371463sub.KERNEL32.dll_ReadFile_a1
0x1001265810117sub.KERNEL32.dll_SetFilePointer_658
0x100126cd13187fcn.100126cd
0x10012788345fcn.10012788
0x100127b521226fcn.100127b5
0x1001289772857 -> 83fcn.10012897
0x100128ea30192fcn.100128ea
0x100129aa551fcn.100129aa
0x100129dd432fcn.100129dd
0x100129fd351sub.KERNEL32.dll_HeapSize_9fd
0x10012a393887fcn.10012a39
0x10012db012105fcn.10012db0
0x10012e1928254fcn.10012e19
0x10012f1747487sub.KERNEL32.dll_MultiByteToWideChar_f17
0x100130fe370fcn.100130fe
0x1001314418231sub.KERNEL32.dll_MultiByteToWideChar_144
0x1001322b364fcn.1001322b
0x1001326b131sub.CONOUT_26b
0x100132a119277fcn.100132a1
0x100133c01697fcn.100133c0
0x10013430122fcn.10013430
0x1001345c13184fcn.1001345c
0x1001367416sub.KERNEL32.dll_RtlUnwind_674

Si ordenamos esta tabla por tamaño, tomando únicamente los 10 primeros lugares tendríamos algo como lo siguiente:

addressnbbssizename
0x1000d04f2342953sub.KERNEL32.dll_DecodePointer_4f
0x1000f8311441844sub.KERNEL32.dll_CreateFileA_831
0x1000e90b991789sub.KERNEL32.dll_GetConsoleMode_90b
0x100120a11371463sub.KERNEL32.dll_ReadFile_a1
0x1000124011024fcn.10001240
0x10012a393887fcn.10012a39
0x1000be0e74663sub.UTF_8_e0e
0x1000bb7649581sub.KERNEL32.dll_GetStartupInfoW_b76
0x1001004959516fcn.10010049
0x100112b837489sub.KERNEL32.dll_IsValidCodePage_2b8

Analicemos esas tres funciones muy grandes que no están identificadas:

Se omiten las variables de inicio y se reduce el font para poder tener mayor visibilidad:

pdf de 10001240

Vaya vaya, parece que aquí se esta cargando algo en el stack… mas aun se nota el texto de Flare-On. Desgraciadamente pdf no logro identificar el tamaño completo de la función, pero eso se puede resolver ampliando el bloque:

pd5552 de 10001240

Rango: 0x10001240 - 0x10009335

Esta función no recibe nada ni devuelve nada, pero lo que si es que algo hace porque podemos ver claramente en la imagen la palabra flare-on mientras se sube al stack.

Ahora bien, este podría ser nuestro destino final en caso de éxito, es decir, el win msg. Tomare esto como valido y continuare viendo como llegar hasta aquí…

Para ello lo primero seria ver que funciones llaman a esta función, para ello ubicaremos cuales son las referencias cruzadas e iremos de función en función.

xref 0x10001240

Como podemos observar, fnc 0x10009af0 es la primera y única función que llama a 0x10001240, veamos su contenido:

pdf 0x10009af0

Tenemos una comparación a 0 en 0x100194fc, que en caso de ser mayor a 0, llama a la función winmsg, pero antes va a llamar a otra función, fcn 0x10001060. Veamos que hay en esta función previa:

pd25 @ 0x10009af0

Esta función como podemos observar se encarga de colocar las equivalencias de esas ubicaciones a 0, como alguna especie de controlador/limpiador. Observamos que tiene 91 referencias! He inclusive por su tamaño no pude extraer toda la función, pero debido a que solo se encarga de inicializar/limpiar (no recibe ni devuelve nada), decidí colocarlo en la siguiente tabla:

#AddressValue
010x100170001
020x100194600
030x100194640
040x100194680
050x1001946c0
060x100194700
070x100194740
080x100194780
090x1001947c0
100x100194800
110x100194840
120x100194880
130x1001948c0
140x100194900
150x100194940
160x100194980
170x1001949c0
180x100194a00
190x100194a40
200x100194a80
210x100194ac0
220x100194b00
230x100194b40
240x100194b80
250x100194bc0
260x100194c00
270x100194c40
280x100194c80
290x100194cc0
300x100194d00
310x100194d40
320x100194d80
330x100194dc0
340x100194e00
350x100194e40
360x100194e80
370x100194ec0
380x100194f00
390x100194f40
400x100194f80
410x100194fc0
420x100195000

Prestando atención al penúltimo resultado, podemos observar que es el valor que hemos evaluado durante la comparación en fcn 0x10009af0, veamos de que manera si podemos escribirlo buscando la referencia hacia esta dirección:

axt 0x100194fc

Como podemos ver, estan las dos funciones que acabamos de explorar, mas una tercera, fcn 0x10009b60, que se encarga de almacenar un 1, justo como buscamos romper el if.

pdf @ 0x10009b60

Tuve nuevamente que reducir el tamaño de fuente para poder tomar la captura.

Bueno, como podemos apreciar, esta función tiene varias cosas diferentes y a la vez comunes con la función anterior. La primera cosa en común es que también es llamada desde sub.USER32.dll_GetAsyncKeyState_10009eb0, presenta un compare, luego set a 0 y finalmente un set a 1 para activar el siguiente flujo o brinco a función.

Su característica principal, es que pareciera que tenemos varios if concatenados, siendo precisos unos 5 cmp, que si ninguno tiene la flag activada, pone en 0 la flag actual y levanta la siguiente. Pero todos los caminos conducen a roma, es decir, todas las comparaciones al final devuelve “o”.

La función anterior (0x10009af0) devolvía “m”, por lo que sea lo que sea GetAsyncKeyState, esta recibiendo estos valores char cuando llama a las funciones.

GetAsyncKeyState

SHORT GetAsyncKeyState(
  int vKey
);

Esta función básicamente recibe la tecla a evaluar y nos devuelve si fue o esta siendo presionada.

Ok, veamos que hace la función sub.USER32.dll_GetAsyncKeyState_10009eb0:

pdf @ sub.USER32.dll_GetAsyncKeyState_10009eb0

El primer vistazo, nos revela muchos jumps, inclusive estamos hablando de un switch case, lo cual seria el tipo de loop adecuado para esto.

Las primeras 3 instrucciones corresponden al stack frame de 8 direcciones, las siguientes 11 instrucciones, desde mov eax, 8 hasta cmp edx, 0xde son las condicionales que nos haran mantenernos dentro de un loop de switch case, básicamente desde 8 hasta 222.

pdf @ sub.USER32.dll_GetAsyncKeyState_10009eb0

Como podemos ver, cuando se rompe el loop, se retorna 0 y termina la función.

Veamos que sucede dentro de este switch:

pdf @ sub.USER32.dll_GetAsyncKeyState_10009eb0

Después de la evaluación inicial, el counter es pasado como argumento a GetAsyncKeyState, es decir si local_4h vale 0x2b, se evaluara si la tecla ‘*’ fue presionada. Ese valor es compartido (tecla presionada ahora o antes) y se compara en el switch, si es no es igual, se va al caso ultimo, si es igual llama a la función correspondiente y brinca hacia el final (0x1000a3a6). En pocas palabras si la tecla “A” o la que sea es presionada, su función correspondiente es llamada.

Esto implica que nosotros controlamos el valor de las flags, presionándolas en el orden correcto debemos llegar a llamar a la función bandera (0x10001240).

Entonces ya que hemos entendido hagamos el reverso de cada letra presionada mediante el siguiente burdo script en python:

#!/usr/bin/env python
  
import r2pipe, os

keys = ["0x10017000","0x10019460","0x10019464","0x10019468","0x1001946c","0x10019470","0x10019474","0x10019478","0x1001947c","0x10019480","0x10019484","0x10019488","0x1001948c","0x10019490","0x10019494","0x10019498","0x1001949c","0x100194a0","0x100194a4","0x100194a8","0x100194ac","0x100194b0","0x100194b4","0x100194b8","0x100194bc","0x100194c0","0x100194c4","0x100194c8","0x100194cc","0x100194d0","0x100194d4","0x100194d8","0x100194dc","0x100194e0","0x100194e4","0x100194e8","0x100194ec","0x100194f0","0x100194f4","0x100194f8","0x100194fc","0x10019500"]

flag = ""

if os.path.isfile("5get_it"):

    r2 = r2pipe.open("5get_it")
    r2.cmd("aaaa")

    for key in keys:
        xrefs = r2.cmdj("axtj " + key)
        for xref in xrefs:
            if xref["opcode"] == "mov dword [" + key + "], 1":
                fcn_called = r2.cmdj("pdfj@" + xref["fcn_name"])
                for eax_ret in fcn_called["ops"]:
                    if "mov eax, 0x100" in eax_ret["disasm"]:
                        flag += r2.cmd("pr 1 @ " + eax_ret["disasm"].split(",")[1])

r2.quit()
print flag

La salida del comando nos devuelve el string:

l0ggingdoturdot5tr0ke5atflaredashondotco

La letra faltante, “m”, se devuelve a la salida del la función de reseteo.

Validemos el DLL contra yara rules:

xbytemx@laptop:~/flare-on2014/challenge05$ yara ~/git/rules/Antidebug_AntiVM_index.yar 5get_it
anti_dbg 5get_it
keylogger 5get_it
win_registry 5get_it
win_files_operation 5get_it

Vemos que da positivo contra tecnicas de antidbg, keylogger, win_registry y win_files_operation. Por ello crearemos un prefix de wine en donde ejecutemos con calma la dll.

Si ejecutamos el dll e ingresamos la salida del comando nos aparecerá el siguiente mensaje:

wineconsole rundll32 5get_it

wineconsole rundll32 5get_it

Nota: La dll se ejecuta en un prefix recien creado para ser eliminado despues.

Traduciendo al formato de la flag:

flag: l0gging.ur.5tr0ke5@flare-on.com


Espero que les haya gustado.

Saludos,