The intention of SQL injection is to reveal or manipulate sensitive information from the database by injecting commands into existing queries.
- Bypassing authentication
- Revealing sensitive information
- Compromise data integrity
- Erase database
- Remote code execution
- sqlmap
SQL stands for Structured Query Language.
SQL tutorial here
Use the same communication channel to launch the attack and get the result.
- Server throw an error message
- Error message is useful during the development, but should be disabled it when the application is live
- System stored procedure
- End of line comment
- Illegal / Logically incorrect query
- Tautology (something that is inherently true, like " OR 1=1")
Involves the UNION SQL operator, to combine the queries.
Select the password
from table1
and table2
using UNION:
SELECT password FROM table1
UNION
SELECT password FROM table2
- Known as Blind SQL Injection
- No data is transferred from the via the application, the attacker sending payloads, then observe the web application's response and behavior.
Sending an SQL query to the database which send a different result depending on whether the query returns TRUE or FALSE result, the HTTP response will change or remain the same.
This type of attack is slow, attacker need to enumerate the database, character by character.
Attacker send a query, force the database to wait for a specified time before respond. The respond time indicate that the query TRUE or FALSE.
Depends on the features allowed on the database server (DNS, HTTP request), so not a very common attack.
Use different channel to launch the attack.
- Collect the information about the web application, server, OS, database, ...
- Identify vulnerabilities
- Evaluate input fields
- Select the appropriate type of SQL Injection, based on the gathered information
- Enumerate the database (Postgre, MySQL, Oracle, ...)
- Identify privilege level of users
- Passwords and hashes grabbing
- Transfer database to a remote machine
- Inserting inline comment in between keywords
- Character encoding
- String Concatenation
- Obfuscated codes
- Manipulating white spaces
- Hex encoding
- Sophisticated matches
- Penetration testing (manual, with tool)
- Source code analysis
- Wep Application Firewall (WAF)
- Remove debugging messages
- Database account with minimal privileges
- Input validation
- Filter data
- Customize error messages
- IDS