Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Jugando con los artefactos de Cobalt Strike y Radare2

Últimamente parece que en cualquier incidente que se precie utilizan Cobalt Strike, así que echemos un vistazo a diferentes artefactos que nos podemos encontrar. Ya  hablé de las shellcodes incluídas en los mismos aquí y aquí, tratando de ver las diferencias con las generadas por Metasploit.

Así que para no repetirme, veremos algún detalle más de este tipo de binarios y así poder identificarlos rápidamente. Hay una serie de artefactos, así lo llama la propia herramienta (“artifact”), que llevan dentro una shellcode que descargaría el “beacon” y poder así “infectar” el equipo de quien lo ejecute. Podemos localizarlos de la siguiente manera .

He hablado alguna vez de imphash, que no es más que un hash que se obtiene de la suma de las funciones importadas (IAT) que utiliza el binario, en este caso imphash:"dc25ee78e2ef4d36faa0badf1e7461c9"

Con este simple script se puede obtener:

import pefile
pe = pefile.PE(sys.argv[1])
print "Import Hash: %s" % pe.get_imphash()

Fuente: https://www.fireeye.com/blog/threat-research/2014/01/tracking-malware-import-hashing.html

Si cogemos los 2 diferentes tipos de binarios que hemos visto en la página de Hybrid Analysis, vemos que ambos coinciden (“artifact” y “beacon”):

$ python imphash.py
c5870b786d4a01b27b079bbf2ce6d36...
...eae7c07378c0346e9cd0dde30c699b59c_artifact.exe
pe.imphash() == "dc25ee78e2ef4d36faa0badf1e7461c9" (14K)

$ python imphash.py
decebaee0cb23bd96b42f0fa0edf7063...
...716307c592ccaef3f1864b4adf1c2a0a_beacon.exe
pe.imphash() == "dc25ee78e2ef4d36faa0badf1e7461c9" (278K)

Lo que indicaría que son generados de la misma forma. En cuanto a ese imphash, veamos que funciones son importadas:

[0x004014b0]> ii
[Imports]
nth vaddr bind type lib name
――――――――――――――――――――――――――――――――――――――――――
1 0x00406138 NONE FUNC KERNEL32.dll CloseHandle
2 0x0040613c NONE FUNC KERNEL32.dll ConnectNamedPipe
3 0x00406140 NONE FUNC KERNEL32.dll CreateFileA
4 0x00406144 NONE FUNC KERNEL32.dll CreateNamedPipeA
5 0x00406148 NONE FUNC KERNEL32.dll CreateThread
6 0x0040614c NONE FUNC KERNEL32.dll DeleteCriticalSection
7 0x00406150 NONE FUNC KERNEL32.dll EnterCriticalSection
8 0x00406154 NONE FUNC KERNEL32.dll FreeLibrary
9 0x00406158 NONE FUNC KERNEL32.dll GetCurrentProcess
10 0x0040615c NONE FUNC KERNEL32.dll GetCurrentProcessId
11 0x00406160 NONE FUNC KERNEL32.dll GetCurrentThreadId
12 0x00406164 NONE FUNC KERNEL32.dll GetLastError
13 0x00406168 NONE FUNC KERNEL32.dll GetModuleHandleA
14 0x0040616c NONE FUNC KERNEL32.dll GetProcAddress
15 0x00406170 NONE FUNC KERNEL32.dll GetStartupInfoA
16 0x00406174 NONE FUNC KERNEL32.dll GetSystemTimeAsFileTime
17 0x00406178 NONE FUNC KERNEL32.dll GetTickCount
18 0x0040617c NONE FUNC KERNEL32.dll InitializeCriticalSection
19 0x00406180 NONE FUNC KERNEL32.dll LeaveCriticalSection
20 0x00406184 NONE FUNC KERNEL32.dll LoadLibraryA
21 0x00406188 NONE FUNC KERNEL32.dll LoadLibraryW
22 0x0040618c NONE FUNC KERNEL32.dll QueryPerformanceCounter
23 0x00406190 NONE FUNC KERNEL32.dll ReadFile
24 0x00406194 NONE FUNC KERNEL32.dll SetUnhandledExceptionFilter
25 0x00406198 NONE FUNC KERNEL32.dll Sleep
26 0x0040619c NONE FUNC KERNEL32.dll TerminateProcess
27 0x004061a0 NONE FUNC KERNEL32.dll TlsGetValue
28 0x004061a4 NONE FUNC KERNEL32.dll UnhandledExceptionFilter
29 0x004061a8 NONE FUNC KERNEL32.dll VirtualAlloc
30 0x004061ac NONE FUNC KERNEL32.dll VirtualProtect
31 0x004061b0 NONE FUNC KERNEL32.dll VirtualQuery
32 0x004061b4 NONE FUNC KERNEL32.dll WriteFile
1 0x004061bc NONE FUNC msvcrt.dll __dllonexit
2 0x004061c0 NONE FUNC msvcrt.dll __getmainargs
3 0x004061c4 NONE FUNC msvcrt.dll __initenv
4 0x004061c8 NONE FUNC msvcrt.dll __lconv_init
5 0x004061cc NONE FUNC msvcrt.dll __set_app_type
6 0x004061d0 NONE FUNC msvcrt.dll __setusermatherr
7 0x004061d4 NONE FUNC msvcrt.dll _acmdln
8 0x004061d8 NONE FUNC msvcrt.dll _amsg_exit
9 0x004061dc NONE FUNC msvcrt.dll _cexit
10 0x004061e0 NONE FUNC msvcrt.dll _fmode
11 0x004061e4 NONE FUNC msvcrt.dll _initterm
12 0x004061e8 NONE FUNC msvcrt.dll _iob
13 0x004061ec NONE FUNC msvcrt.dll _lock
14 0x004061f0 NONE FUNC msvcrt.dll _onexit
15 0x004061f4 NONE FUNC msvcrt.dll _unlock
16 0x004061f8 NONE FUNC msvcrt.dll _winmajor
17 0x004061fc NONE FUNC msvcrt.dll abort
18 0x00406200 NONE FUNC msvcrt.dll calloc
19 0x00406204 NONE FUNC msvcrt.dll exit
20 0x00406208 NONE FUNC msvcrt.dll fprintf
21 0x0040620c NONE FUNC msvcrt.dll free
22 0x00406210 NONE FUNC msvcrt.dll fwrite
23 0x00406214 NONE FUNC msvcrt.dll malloc
24 0x00406218 NONE FUNC msvcrt.dll memcpy
25 0x0040621c NONE FUNC msvcrt.dll signal
26 0x00406220 NONE FUNC msvcrt.dll sprintf
27 0x00406224 NONE FUNC msvcrt.dll strlen
28 0x00406228 NONE FUNC msvcrt.dll strncmp
29 0x0040622c NONE FUNC msvcrt.dll vfprintf

Entre otras llama la atención estas 2: VirtualAlloc yVirtualProtect ( lo hemos visto en otros artículos )

Veamos que se esconde dentro del binario:

Ponemos el breakpoint correspondiente en VirtualProtect.

Vemos el tamaño de la shellcode en el registro ecx (31e en hexa, 798 en decimal) y donde podemos encontrarla en el registro ebx (0x20000).

Lo vemos más en detalle en la siguiente captura.

En este punto ya podemos guardarla.

Solamente nos queda comprobar si esto realmente hace lo que hemos visto, que seguro que sí.

Llegados a este punto, siempre pienso lo mismo, he tenido que ejecutar el binario para obtener la shellcode, pero sin ejecutarlo, ¿podría?

Si editamos el binario, vemos esta zona:

Vemos muchas A, pensé que podría ser donde se ubicaría la shellcode cifrada. Esas A podrían ser algo como un relleno.

Me llamó la atención que en muchos de estos binarios, se repetía estos opcodes

Vale, seleccionamos esta zona:

Y la guardamos en un fichero.

Vamos a localizar esta zona en el binario.

Primero busco las A. Si nos acordamos del tamaño de la shellcode, eran 798 bytes, por lo que para no pillarnos las manos, pongo algo más. Y ahí la tenemos. Podía haber buscado los primeros opcodes que veíamos, pero voy a lo conocido, las A.

Necesito saber exactamente cual es la dirección que va a usar el binario para acceder a esta zona, me posiciono en el sitio correcto.

Veo si hay referencia a esa dirección:

No las hay, avanzo 8, esto no lo hago porque sí, ya lo he analizado antes y sé lo que va a hacer. Aquí ya vemos una zona donde es usada esa dirección.

Y donde se descifra esa shellcode es justo después del VirtualAlloc.

Quedando de la siguiente manera nuestro script de descifrado:

Vemos como obtenemos los mismos resultados que con el debugging, esta vez sin ejecutar el binario. Seguiremos de cerca este tipo de binarios.

Una forma rápida de detectarlos, como he mencionado al principio del artículo es por el imphash. Así que esta regla yara puede ayudarnos.

import "pe"
rule artifact_cobaltstrike_x32 {
meta:
description = "Yara rule for detect Cobaltstrike artifact x32"
author = "by Rafa"
last_updated = "2019-07-14"
category = "informational"
strings:
$a1 = "%c%c%c%c%c%c%c%c%cMSSE-%d-server" wide ascii
$a2 = { 10 22 00 00 }
condition:
pe.imphash() == "dc25ee78e2ef4d36faa0badf1e7461c9" and
filesize
uint16(0) == 0x5A4D and all of them
}

Vemos si funciona:

$ ls *.exe | wc -l
64
$ yara artifact.yar .| wc -l
64

Parece que sí, el resultado de las detecciones:

$ yara artifact.yar .
artifact_cobaltstrike_x32 ./9a42eca4df1bb5dfe0b7d2c2b28e10e88a0c35d881ad20f162174f9bb579c197_artifact.exe
artifact_cobaltstrike_x32 ./d04e0d4ef5f6dea2b68aad4f688090ec861fd2c158bc94c489e9f9486c9fb4c2_artifact.exe
artifact_cobaltstrike_x32 ./6c762972cf95bf6da96fe64c3a335756aedb871060af90eb6bd87fc683f6492c_artifact.exe
artifact_cobaltstrike_x32 ./9a0c4694d4ad3fd8917149bf2cf1baf4b2d37532b5b02cdca14356277c931039_artifact.exe
artifact_cobaltstrike_x32 ./809cad4ddd921f0bbdcaa267dd6fb5d2528730c5d55df773846dc7b63643ba6c_artifact.exe
artifact_cobaltstrike_x32 ./07f1888b3febc5971660147d4c6c3ad1c8fda262a797c8bff375ad6f0704413d_artifact.exe
artifact_cobaltstrike_x32 ./6eb1b9271c95edc0c095c50777bfabdc15f543a9295222760a8c9e124f096a41_artifact.exe
artifact_cobaltstrike_x32 ./00641d85e6cb840f92c630ae0cfecd00e70e2efb16ed8b8a1bd026bdeebb56c0_artifact.exe
artifact_cobaltstrike_x32 ./1df6465b13e110ff7501683c7481e625cf9201e1dacdc36288a17bfd4058181c_artifact.exe
artifact_cobaltstrike_x32 ./7a1602e83f42292c7630b3914cf391bfd49f7e3f641288d3446a4b015785d321_artifact.exe
artifact_cobaltstrike_x32 ./a94d39f150647a226e3f3952cdfc4906a9049f75379a467e908db6707a61907f_artifact.exe
artifact_cobaltstrike_x32 ./2d12f7359ea4dcaa0ab7c1090e84a2bd48cfa6bab4cee641adb504bfcd1f3b9b_artifact.exe
artifact_cobaltstrike_x32 ./eb1d75f02e09b08c65e1541bddcd6888c334977bb1fb603fa45dcd1a836bb406_artifact.exe
artifact_cobaltstrike_x32 ./7166c84bb35b94a497851bffefe7cce60788e9bccbbf550cd162ec8ddc0c9266_artifact.exe
artifact_cobaltstrike_x32 ./30d197817fb19ee3a39d9ff8246c731c3b8c543f8c6ef387eb2ff7e9c581adf6_artifact.exe
artifact_cobaltstrike_x32 ./9a8548f1797803a6a29f128a141dcf93d0333e1203774ecbdc295a6b072ee77b_artifact.exe
artifact_cobaltstrike_x32 ./4a045d9205935a73d7d9b3b6e961fc1e5b3516d380a5ea28d3f0a8f576d6439b_artifact.exe
artifact_cobaltstrike_x32 ./b894ae0ec3b677692b9f78ca1492b012f0a38be98e6e0eb6c67077c2b3e92cb4_artifact.exe
artifact_cobaltstrike_x32 ./dd12b3d1f17ec5638aa1f017cb75b649f9dad046406406d7ac00e9d81b2cff63_artifact.exe
artifact_cobaltstrike_x32 ./e3a3f134fbdad25ee4635c5df3d660317bbc71cade0e4dfab71f82cf8cb0dfe0_artifact.exe
artifact_cobaltstrike_x32 ./917632c0529845fb50248729b04accd55ab00dfc142b5750a73c145eb1aea3e8_artifact.exe
artifact_cobaltstrike_x32 ./9675f832a7dfda9e5cbbc6ae409b8d630392e56c29fe4e110d27134100e31d52_artifact.exe
artifact_cobaltstrike_x32 ./f4d59b65f2b22854a305736005bf68c042355f2b0b4b8609d5b0c9ecc827eacc_artifact.exe
artifact_cobaltstrike_x32 ./940256445907dff1f5151a7aca61841d7aa29ee9ff47f99b9b4bc57cbbebb50f_artifact.exe
artifact_cobaltstrike_x32 ./10cb3101476923121269b245367c7c71a98c736f649395dbd15693c8d0effe08_artifact.exe
artifact_cobaltstrike_x32 ./1cc92fca43c469507fb343d066e9cf81c8ae318276b41d5f3cf1e2f76e1daa5d_artifact.exe
artifact_cobaltstrike_x32 ./0e36be5524820cedba0ecd76131158d0317f760f51b8174ff381ef16365696c7_artifact.exe
artifact_cobaltstrike_x32 ./ab4c3289480dedf8cae5201845d6023053aaf10d22772104e0b240aaf2a022d3_artifact.exe
artifact_cobaltstrike_x32 ./f61d8c2577a766c572d7fed898e88e19656dae5baf0f120b71c6a39432f56adb_artifact.exe
artifact_cobaltstrike_x32 ./1f2ea18e34d8bcf435eb6f571b9ae2182675ae6357d282679ef669797aa6f38b_artifact.exe
artifact_cobaltstrike_x32 ./6b343662dbbb95d71bad796312884b1defbeb930cc8f61a2b76444a969328920_artifact.exe
artifact_cobaltstrike_x32 ./43df13e176eb083a6af986fc75bf37985ead4053c9b128fa27285a2e5f306c59_artifact.exe
artifact_cobaltstrike_x32 ./06f8004835c5851529403f73ad23168b1127315d02c68e0153e362a73f915c72_artifact.exe
artifact_cobaltstrike_x32 ./a0e76ae8143c4e8605cd95b80f4f13b9099889925b35b79a872d66f9bac0c8ff_artifact.exe
artifact_cobaltstrike_x32 ./32822d9af524b0d8280f5df0ba5ce8bcab26c2d94cd45b7c360529ae516cf2e3_artifact.exe
artifact_cobaltstrike_x32 ./c2d9bbd5163a8e733483bf5d0d4959f053a2307d275b81eb38e69d87f1f5df7e_artifact.exe
artifact_cobaltstrike_x32 ./56861f8382d10a3d50ea0571eb44d8b04da84931166a9a5707fdbc1cf60035b3_artifact.exe
artifact_cobaltstrike_x32 ./3bd5f6f088a2668f9d3a8161c961d52417a36b75af5adaf9f1288f7992ebf604_artifact.exe
artifact_cobaltstrike_x32 ./b97b606aef81420a441aba88b42c44aa8e102390434be5714d33bb07645912d2_artifact.exe
artifact_cobaltstrike_x32 ./72c179e143cb25e8f78e6bd3d116deca1db3b97db93db521a6a60503103857bf_artifact.exe
artifact_cobaltstrike_x32 ./d13a3c54759d69d02a0a4fdeb0bd1977149edc5087073f60cfcb9a0484a1bcd7_artifact.exe
artifact_cobaltstrike_x32 ./dbbcb955538dc2fb65f4336f5a5b397d735dc10b20428d9d164a4284856295f4_artifact.exe
artifact_cobaltstrike_x32 ./8880ae12848d889ac6e527e1bbd412248ea33d6da3545e4bc062ea8b29863516_artifact.exe
artifact_cobaltstrike_x32 ./fef6d4f9ed87c5f991660a768772cd8d723e07b4b9861ecc63e47ed69f6c62d1_artifact.exe
artifact_cobaltstrike_x32 ./7d6384399f121e1295243ea82f3422c6f46c619f5777bb4e5c34152e1a4b5bef_artifact.exe
artifact_cobaltstrike_x32 ./a0cfec815cb74a7671265fd5e0790a2a79c05fe0ef16d2d0c87584049d06658b_artifact.exe
artifact_cobaltstrike_x32 ./6043c45ca9038e45457bb13133109d647417776cd57b75468821f2b68d190a1c_artifact.exe
artifact_cobaltstrike_x32 ./c4979b7f2d10da7da13a3e6b4688448d919d0a7bb7bc571d58546e99263c3e9c_artifact.exe
artifact_cobaltstrike_x32 ./bca4d36e65fc970e7a9a44f41037aae025501c0aac578487d62fa719ebe2f295_artifact.exe
artifact_cobaltstrike_x32 ./61ffe0a4549a36746a342b3bb75f0b0d2964cc6e15a4597fa7c34e3ca6065d76_artifact.exe
artifact_cobaltstrike_x32 ./85a1659c7ba9ded0c1b84b34b505f48237d495d0179c28f6c1d5a95bd87064d8_artifact.exe
artifact_cobaltstrike_x32 ./9972402dcc080a826c0010948d8c32ab4fce83c13d30e3e2eb074d4c31a2b9af_artifact.exe
artifact_cobaltstrike_x32 ./4873a1f74b1245009c083b0fb90900d4ed01a5c651b3ed9c2e716e61ba5079be_artifact.exe
artifact_cobaltstrike_x32 ./6496905d4e7677f0a80dac27722ce8fddd18256830d44f4d13709d7978626f49_artifact.exe
artifact_cobaltstrike_x32 ./ed4bb84c5625b997bd5cb8bcda272277e1c0c89dc0a2d771931aff7dc6776453_artifact.exe
artifact_cobaltstrike_x32 ./4bd09b224117790ac61c8dbe039df1e3a0548626887b7b06d1abff0101e3d989_artifact.exe
artifact_cobaltstrike_x32 ./c5870b786d4a01b27b079bbf2ce6d36eae7c07378c0346e9cd0dde30c699b59c_artifact.exe
artifact_cobaltstrike_x32 ./f9727ea0ffb9a8581d821a25c01fdde9bffc7b22847573b0b601483fcdabbdbe_artifact.exe
artifact_cobaltstrike_x32 ./9a0aeaeae4483c51d51428ec32800e37d7c9de4b51d7f3e7f7f63cec59d77584_artifact.exe

Espero que os haya gustado, hasta otra!!



This post first appeared on Ciber Seguridad, please read the originial post: here

Share the post

Jugando con los artefactos de Cobalt Strike y Radare2

×

Subscribe to Ciber Seguridad

Get updates delivered right to your inbox!

Thank you for your subscription

×