Nmap

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 c1:99:4b:95:22:25:ed:0f:85:20:d3:63:b4:48:bb:cf (RSA)
|   256 0f:44:8b:ad:ad:95:b8:22:6a:f0:36:ac:19:d0:0e:f3 (ECDSA)
|_  256 32:e1:2a:6c:cc:7c:e6:3e:23:f4:80:8d:33:ce:9b:3a (ED25519)
3000/tcp open  http    Grafana http
|_http-favicon: Unknown favicon MD5: F69DADBD5936359AF76AAB84559E849F
|_http-trane-info: Problem with XML parsing of /evox/about
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
| http-robots.txt: 1 disallowed entry 
|_/
| http-title: Grafana
|_Requested resource was /login
9090/tcp open  http    Golang net/http server (Go-IPFS json-rpc or InfluxDB API)
|_http-favicon: Unknown favicon MD5: 5EE43B38986A144D6B5022EA8C8F748F
| http-methods: 
|_  Supported Methods: GET OPTIONS
| http-title: Prometheus Time Series Collection and Processing Server
|_Requested resource was /graph

Enumeration

On 3000 there is a Grafana login page.
On 9090 there is a Prometheus dashboard.

Our Grafana version (v8.3.0) is vulnerable to Directory Traversal. We can read files on the server.

HackTricks has some useful files.

Exploitation

https://github.com/davidrxchester/Grafana-8.3-Directory-Traversal/blob/main/readFiles.py

First:
/etc/grafana/grafana.ini

# default admin user, created on startup
;admin_user = admin

# default admin password, can be changed before first start of grafana,  or in profile settings
;admin_password = admin

# used for signing
;secret_key = SW2YcwTIb9zpOOhoPsMm

Now:
/var/lib/grafana/grafana.db

{"basicAuthPassword":"anBneWFNQ2z+IDGhz3a7wxaqjimuglSXTeMvhbvsveZwVzreNJSw+hsV4w=="}

User is sysadmin

rometheusPrometheusserverhttp://localhost:9090sysadmin

We will use Grafana-Decryptor
https://github.com/Sic4rio/Grafana-Decryptor-for-CVE-2021-43798

SuperSecureP@ssw0rd

We can read /etc/passwd and notice that sysadmin is a user on thee box. SSH?
It works.

Privilege Escalation

Sysadmin cannot run sudo.

However, they are in the disk group, so we can use debugfs potentially to read sensitive files.

$ id
uid=1001(sysadmin) gid=1001(sysadmin) groups=1001(sysadmin),6(disk)

root:$6$mAe2JsSJSmg1n45O$78rgk3B6HaklRIPcLOtwP9aX5i.0aPF16NVm39i1cz3K7StTajlI2LFBp.WSxiAAyoB4SQd5qc123HVmH0HXJ/

Let’s try to crack it. No luck. Let’s look elsewhere.

files /.ssh/id_rsa

Found their private key!
Copy to a file on our attacker machine and voi la!

Done!