HackTheBox - Book

Featured image

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

The IP of this box is 10.10.10.176

Port Scan

Running NMAP full port scan on it , we get

placeholder

We just get only 2 Open Ports, one for SSH running on Port 22 and other for web running on Port 80

Moving to the web part

Port 80 — Web

Running the IP on the browser, we get

placeholder

Trying default credentials, we don’t get any luck so we move towards the Sign Up page

placeholder

We now put our details to create an account

placeholder

Now we just signup and then login through the created account

placeholder

After login, we see that we have a cool website , looking further more

placeholder

We have something in Contact Us page which leaked the admin email address

placeholder

We try for SQL Truncation Attack by intercepting the request in Burp

placeholder

Now we forward the request and then try to login to the admin user

placeholder

Clicking on Sign In, we see

placeholder

We don’t see any differences here as its looks all the same as a normal user like we created before

placeholder

Running Gobuster scan, we see a useful directory named /admin

placeholder

Opening the link, we see that we have a different Admin Sign In Page created for admin

placeholder

So we now sign in using the credentials we created from SQL Truncation

placeholder

We logged in successfully as admin and we see completely different stuff from before

placeholder

Now moving back to the normal user section, and going to the Collections area, we see that we can upload a file with author name and book title

placeholder

So at first I try to upload a php webshell

placeholder

We get a popup stating that the admin will evaluate the upload and update the list

placeholder

On the Admin page area, going to the collections section and downloading the both of the PDF

placeholder

The users pdf file contains the list of Names and Emails of accounts created on the page

placeholder

On the Collections PDF file, we see that our file which we uploaded shows here, also you notice that the name and author is also reflecting on the PDF , so we try some HTML Injections

placeholder

We try the to bold the author name and book title and see the results

placeholder

We see that our HTML Injection worked, so we will now move into getting XSS which will help us getting local file reads, for which we will use the below command

<script>x=new XMLHttpRequest;x.onload=function(){document.write(this.responseText)};x.open("GET","file:///etc/passwd");x.send();</script>

placeholder

We now try this on both Book Title and Author section and then see the results

placeholder

We got the contents of /etc/passwd file, we see that there is a user named reader, so we will try to get the ssh keys of it using the below command

<script>x=new XMLHttpRequest;x.onload=function(){document.write(this.responseText)};x.open("GET","file:///home/reader/.ssh/id_rsa");x.send();</script>

placeholder

We got the ssh key for the user read, but when try to copy the key from here , we were having some issues as it wasnt copying in properly format

So we use ghostscript to copy the contents of the pdf into a file

placeholder

We see we copied the key file along with some unwanted text which we later remove it manually

placeholder

We connected to user reader and now moving on to get user flag

placeholder

Privilege Escalation

Running PSPY , we see that logrotate is being ran by root during few intervals

placeholder

We found an exploit for it and before that have to prepare our payload

placeholder

Now we run the exploit and see the backups directly which was in home folder of user reader which contained log files for logrotate

placeholder

We copied so that it triggers the exploit and then we see

placeholder

We see that it copied the root ssh key to our created directory and we can read it below

placeholder

Now we move into connecting to root user

placeholder

Moving onto getting the root flag

placeholder

References

Abusing a race condition in logrotate to elevate privileges

SQL Truncation Attack

Local File Read via XSS in Dynamically Generated PDF

Hack The Box