SQL Injection
SQLi is a common web application vulnerability that is caused by unsanitized user input being inserted into SQL queries.
Automatization with sqlmap
Note: request.txt
is a request saved in BurpSuite.
Dumping a Table
Union Attack
When an application is vulnerable to SQL injection and the results of the query are returned within the application's responses, the UNION
keyword can be used to retrieve data from other tables within the database.
MySQL syntax for the example:
Column Number Enumeration
After detect that the application is vulnerable to SQLi we need to know how many columns are queried. To do that task we are going to use order by to guess the number of columns retrieved. The idea is to increment the number until get an error.
Output Layout
Now that we know how many columns are in the table, we can use this information to retrieve information. But we need to before understand where this information will be displayed, so we are going to set parameteres to that fields.
Extracting Data from Database
Now knowing that the third column is for descriptions, we can put there all information.
Read files
Some databases allows us to read or write files in the filesystem.
From SQLi to RCE
Since we are allowed to upload files, we can upload a webshell to the web root.
In case of exploiting a Microsoft SQL Server check this:
Login Bypass
The most classic ones:
Then others:
Knowing the username
When we are aware of some username we can impersonate him with SQLi by introducing the username and commenting the rest of the SQL Query.
Error Based SQLi
Use CONVERT or CAST to force an ERROR and see the output of the query on errors logs.
Example of Microsoft SQL Server:
Blind SQLi
A SQLi is blind because we don't have access to the error log or any type of output which difficult a lot the process of exploitation.
Time Based
Since we are not aware about any type of error or output we can use sleeps.
If it loads for four seconds extra we know that the database is processing our sleep()
command.
Dump tables
It can also be done with sqlmap or manually with a custom script. In that case the script is dumping MD5 hashes from password field.
Note: MD5 hash are hexadecimal with 33 character length.
References
Last updated
Was this helpful?