HackTheBox — Ambassador

Ambassador from hackthebox was medium rated machine which involved exploiting Local File Inclusion in Grafana through which we can view the sqlite database for grafana which will have the base64 encoded password for developer user through which we can login, from /opt directory we can find Consul API token through git commits allowing us to interact with consul’s Services api to gain remote command execution as root.


From port 80 we’ll see a page talking about using developer account to login to SSH

Fuzzing on this site didn’t really returned something

PORT 3000 (Grafana)

On port 3000 there’s an instance of grafana 8.2.0 running


We don’t know the password but we can check for vulnerabilities for version 8.2.0, which turns out to be vulnerable to Local FIle Inclusion

To exploit this we can make a request to public/plugins/plugin-name and then followed by the LFI payload, using a script from github, this is lopping through the plguins to find the plugins which are available and make the request to read any local file you want

We can exploit this manually

Reading /var/lib/grafana/grafana.db will show us the database for grafana having the admin hash

We can read /etc/grafana/grafana.ini which has the admin login password

We can login with the admin user with password we found

But there wasn’t anything from where we could move forward so this was most likely a rabbit hole, following this article to decrypt the password , we can load the sqlite database through sqlite3

This is the password for mysql database for grafana user

From whackywidget database we can find the password for developer user which is in base64 encoding you could tell as at the end there's ==

We can just decode it from base64 and get the plaintext

Having the password we can login through ssh

With sudo -l we can try checking if this user can run anything as root or as other user

Privilege Escalation

Running pspy it was removing the config file of consul which gave away that root must be something to do with it

Going to /opt directory there's a directory named my-app which has .git so we can check the commits which reveals a token

This token belongs to consul through which we can make API calls and this service is running on port 8500

This can be exploited by creating service executing a reverse shell using the token we have found,it can be done in two ways

Method 1

To exploit it manually we have to create a config file for health checks which will execute commands, so we’ll create the config file in /etc/consul.d/config.d , the format of the config file can be in HCL or JSON

We’ll first create a bash script to trigger the reverse shell

Next creating the health check script

Now copying this file /etc/consul.d/config.d/ as we the folder is owned by developer group

And we are going to register the health check and reload to check for new service or update

consul reload -token=bb03b43b-1d81-d62b-24b5-39540ee469b5

This will give us a shell back as root user but the connection just closes

So we could make bash a SUID instead or could put a ssh in root’s directory, so I went with making SUID

Or with +s

Again copying it, registering and reloading to check the new scripts

With bash -p we can run bash as the user who owns it which is root

Method 2

I found an exploit for consul on metasploit and in order to use that we would first need to port forward 8500 through chisel so that we can access it

Making sure if we are able to make a request

Now firing up msf and using the exploit exploit/multi/misc/consul_service_exec




Smol Pentester | CTF Player | UwU

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store