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.
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
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:
0x05 Do SQLMap injection
As we can see, SQLMap find the time-based blind injection can work, that means this record will guess one by one character.
Then we can find the table and dump the flag!