Capture the flag (CTF)

Hack the Box (HTB) machines walkthrough series — Joker

Security Ninja
March 23, 2020 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 Joker.

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.

Note: Only write-ups of retired HTB machines are allowed. The machine in this article, named Joker, is retired.

The walkthrough

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 Joker machine IP is 10.10.10.21.
  3. We will adopt the usual methodology of performing penetration testing to begin. Let’s start with enumeration in order to learn as much information about the machine as possible.
  4. As usual, let’s start with the nmap scan to learn more about the services running on this machine.
  5. As we can see, port 22 and proxy is running on this machine on 3128. [CLICK IMAGES TO ENLARGE]

    <<nmap -sC -sV -oA Joker 10.10.10.21>>


  6. We’ll run a full UDP port scan on this machine as well.

    <<nmap -sU -T4 10.10.10.21>>


  7. This also reveals a lot of other ports. TFTP looks especially interesting among them.

    Now we know that squid proxy is running on this machine and its default password location is at /etc/squid/passwords, we’ll log in and extract that.

    <<tftp 10.10.10.21>>

    <<get /etc/squid/passwords>>


  8. We run john on this password.

    <<john --wordlist=/usr/share/wordlists/rockyou.txt passwords>>


  9. We got the password! Now let’s move onto the next enumeration. Since squid is running on this machine, let’s change the browser proxy to point to the same.
  10. As soon we change that and try to access the page, we are asked to enter a username and password. Doing so, it gives us a hint: “kalamari.”
  11. Entering the username and password discovered above, we get the page below.
  12. We tried to enumerate this page, but it looks like we hit a dead end. We’ll go back to enumeration to brute-force the directories via proxy.

    <<dirb http://127.0.0.1 -p 10.10.10.21:3128 -P kalamari:ihateseafood -r>>

  13. We got a hit on the console page. Browsing that gives us a Python Interpreter page. This strikes to get a reverse shell directly via Python Interpreter. After trying for a bit, I was not able to get a TCP shell back on a nc listener.

    After much enumeration and looking into tables, it looks like TCP outbound is blocked. So we switch to get back a UDP via socat listener, as shown below.

  14. We got the shell back, but we need to elevate in order to get the user flag. Checking the sudo permissions for the user, it looks like we can run sudoedit as user alekos. The interesting thing is the wild cards in the path.

    <<sudo -l>>


  15. Exploiting the wildcard vulnerability created a directory named lhm under /var/www/testing and created the page default.html. We then make a symbolic link to the key of user alekos so that we can overwrite it with our own generated key.

    <<ln -s /home/alekos/.ssh.authorized_keys layout.html>>


  16. We now generate our own key.

    <<ssh-keygen>>


  17. We run the elevated sudoedit command and paste the generated public key.

    <<sudoedit -u alekos /var/www/testing/lhm/layout.html>>


  18. After that, we can login with user alekos via the private key we created above.
  19. We enumerate to grab user.txt.

    <<cat user.txt>>


  20. Now enumerating under this, we can see there are two directories, Backup and Development. Backup is actually taking backups of the Development directory!
  21. Since it has been executed as root but owned by our user, we can try it to take a backup of the root directory instead.
  22. We rename the development directory and configure a symbolic link of root to Development.
  23. After five minutes, it gives us a new compressed folder which is of the actual root directory. We enumerate to grab the root flag.


This is a nice machine with a lot of emphasis on deep enumeration and how to exploit elevated permissions with wildcards.

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’ll be continuing this series with more in the way of interesting machines.

Security Ninja
Security Ninja