wafwaf -- Hack The Box -- Web SQL injection

0x00 Problem


0x01 Check the Source Code

We open the website and only see the source code on the website.

As we can see, there is a WAF will filter some characters and words, that means the normal injection will not work.

However, we can see, there is a json_decode() function will decode JSON data, that means the data can be accepted should be JSON format. 

The example JSON format data is like: /u0074, /u0075.

In addition, there is a "php://input", accesses the read-only stream of the requested raw data, executing the data in the post request as PHP code.


0x02 Local Test

We can launch an Apache server to test it.


I copy the source code and make a little change to test this. This file is in /var/www/html.



We will construct the data first.

This time I use 'select' as an example. The word transfer to ASCII, then to hex, then replace the '\0x' as '\u00'. This can be test in the browser console.


At the end, we can test it with curl.

As we can see, the SQL query decode the data and change back to 'select'!


0x03 Construct SQLMap tamper scripts

Because the data will be encoded first, the normal SQLMap will not work.

So we need to encode payloads first. Then SQLMap will fetch these encoded JSON data to do the injection attack.

As we know, SQLMap has a temper folder which contains a lot of encode function, but I didn't find any script can encode as JSON format, so I write a script by myself.



0x04 Construct Raw Data 

If you remember, the source code use 'php://input', and we cannot use the normal SQLMap command to do this, like 

sqlmap -u http://$IP:PORT?id=1

Because we cannot use any parameter directly.

We have to construct raw data by ourselves.

Then we can use Burpsuite to do this. Send a real request to the server, intercept it and copy it in the text file. Here is my command -x means go through proxy: 

curl -i  http://178.128.40.63:30736/ --data '{"user":"*"}' -x 127.0.0.1:8080 



0x05 Do SQLMap injection

We are going to use the raw data and jsonencode script to run SQLMap.
The raw request is in 1.txt.


sqlmap -r 1.txt --tamper=jsonencode -dbs 

As we can see, SQLMap find the time-based blind injection can work, that means this record will guess one by one character.


Here is the database we found:


Then we can find the table and dump the flag!











Popular posts from this blog

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

Cheat sheet for security+