SQL Injection
SQL Injection
database.
1) In-band SQLi
2) Inferential SQLi
3) Out-of-band SQLi
In-band SQLi
In-band SQL Injection occurs when an attacker is able to use the same
communication channel to both launch the attack and gather results.
The two most common types of in-band SQL Injection are Error-based SQLi
and Union-based SQLi.
In-band SQLi
Error-based SQLi :
is an in-band SQL Injection technique that relies on error messages thrown by
the database server to obtain information about the structure of the
database.
Union-based SQLi:
is an in-band SQL injection technique that leverages the UNION SQL operator
to combine the results of two or more SELECT statements into a single result
Inferential SQLi
A hacker might get access to user names and passwords in a database by simply inserting " OR
""=" into the user name or password text box:
The code at the server will create a valid SQL statement like this:
SELECT * FROM Users WHERE Name ="" or ""="" AND Pass ="" or ""=""
The SQL above is valid and will return all rows from the "Users" table, since OR ""="" is always TRUE.
Examples
SQL Injection Based on Batched SQL
Statements
A batch of SQL statements is a group of two or more SQL statements, separated
by semicolons.
Example:
SELECT * FROM Users; DROP TABLE Suppliers
Look at the following example:
Example
txtUserId = getRequestString("UserId");
txtSQL = "SELECT * FROM Users WHERE UserId = " + txtUserId;
And the following input:
User id: 105; DROP TABLE Suppliers
The valid SQL statement would look like this:
SELECT * FROM Users WHERE UserId = 105; DROP TABLE Suppliers;
SQL Injection Prevention