HackTheBox - Registry

Featured image

Hello Guys , I am Faisal Husaini. My username on HTB is ferllen. Also join me on discord.

The IP of this box is 10.10.10.159

Port Scan

Running nmap on it , we get

placeholder

We see 4 Open ports on port 22, 80 , 443, 8000 and 8001 respectively

Moving onto the Web Part

Web Part

Checking the lowest web port, i.e, Port 80

placeholder

We see an nginx server message, so we now run directory against this but this time I am gonna use WFUZZ instead of Gobuster

placeholder

Well when fuzzing the main webpage, we got four entries out of which I first bruteforced the /install directory but end up with nothing interesting

placeholder

On fuzzing the /bolt directory, we got pretty few entries , so moving onto the /bolt/bolt directory

placeholder

We get redirected to a login page, so I bruteforced the login part for user admin using Burp Intruder

placeholder

We can see that the password strawberry gives us a 302 status code which means its redirecting us somewhere so we use it as our password

placeholder

We got logged in successfully

Also we saw that we got an install directory before, looking further into it

placeholder

We see some junk file, trying to get this onto our box using wget

placeholder

We see that it is a zip file , so we extracted and see the contents

placeholder

We see two files, ca.crt and readme.md, checking the readme.md file we see that it says that it has docker running so I will scan for vhosts and see that

placeholder

Wee see that we have docker.registry.htb, so I have added the vhost into my /etc/hosts file

placeholder

We see its nothing but blank, running WFuzz against for directory bruteforcing

placeholder

We see that we have a directory named v2, looking further into it

placeholder

We get a basic authentication, trying the default admin admin creds

placeholder

We get a blank API, checking the catalogs

placeholder

Looking for the catalogs, we see that we have a repository named bolt-image

placeholder

Moving further on checking the tag lists, we see that we have a tag latest on the bolt-image repository

placeholder

We downloaded the file to our box and then checked the contents of it

placeholder

We have some blobsums so we move on getting each of them to our box

placeholder

Like the above way, we get the blobsum files to our machine

placeholder

We are good to go and since these all files were gzip compressed, we have to unzip and check all of those, for the sake of time we skip that part in this writeup and move onto the main part

placeholder

One of the blobsum folder, we got a file named 01-ssh.sh and looking further into it we saw that it has something which leaks a passphrase to a ssh key, so there might be the ssh key too somewhere, upon looking more

placeholder

We found the folder containing the ssh keys and also a file named config

placeholder

We see that the config file reveals the Username , Port and the Hostname, so we connect to the box through SSH

placeholder

Putting the passphrase and now we are in so we get our User Flag

placeholder

Moving onto the priv esc part

Privilege Escalation

As we remember from the above part that we had access onto the Bolt webpage, we move onto the Configuration option and then move onto changing the config.yml file

placeholder

Here we add php to accepted file types list so that we can upload a php file

placeholder

Here we have our file upload functionality and upload our php file

placeholder

Good to go and we upload our file and see

placeholder

Our file got uploaded and accessing that

placeholder

We see that it got uploaded but nothing to display as we didnt put our command

placeholder

Here we can confirm that our script is running perfectly, but in just like less than 15 seconds

placeholder

We see that our file gets removed automatically and everything gets reset, even the changed in the config.yml file we made, so we do all the stuff as fast as possible and then redo our bash one liner reverse shell command

placeholder

This bash one liner reverse shell command doesnt work as the webpage cannot reach our IP

placeholder

Here we remote port forwarded to the box and then also do some changed in our reverse shell technique

placeholder

We created a new php reverse shell script and then move onto uploading it

placeholder

We are set to go and access our php script and looking back into the netcat listener

placeholder

We got reverse shell successfully

placeholder

Looking on the sudo -l command we see that user www-data can run restic backup command with sudo without password

placeholder

We created our initial repository by the above command

placeholder

Here we start the rest-server on the same directory as the repository created and also the server started on port 8000

placeholder

Again remote port forwarding the port 8000 to the box through SSH

placeholder

Now we ran the command with sudo and created the backup of the /root directory onto our box

placeholder

We see that the snapshot is created on our local machine by name snapshots

placeholder

Now we restored the backup snapshot and then see that we have the contents of the root folder

placeholder

We can see the root folder on our box and into that we have the contents

placeholder

Here we got the root flag and also we can see that we have .ssh containing the ssh keys for the root user

placeholder

So we now connect to the root user through SSH

placeholder

The box is completed as we got complete access of it, hope you enjoyed the writeup

References

Restic Server