8 - SQL Injection
8 - SQL Injection
-SQL injection attacks, also called SQLi attacks, are a type of vulnerability in
the code of websites and
web apps that allows attackers to hijack back-end processes and access, extract,
and delete confidential
information from your databases.
-SQL statements often use arguments to pass data from users into a secured database
or vice versa. Unless the
values in these user-supplied SQL arguments are secured by sanitizing or prepared
statements, attackers can use
the places where your app communicates with a database with a SQL argument to gain
access to confidential
information and other secured areas.
-----------------------------------------------------------------------------------
---------------------------------
**SQL INJECTION BASED ON 1=1 IS ALWAYS TRUE:
SELECT UserId, Name, Password FROM Users WHERE UserId = 105 or 1=1;
-The SQL above is valid and will return ALL rows from the "Users" table, since OR
1=1 is always TRUE.
-----------------------------------------------------------------------------------
---------------------------------
**SQL INJECTION BASED ON ""="" IS ALWAYS TRUE:
SELECT * FROM Users WHERE Name ="John Doe" AND Pass ="myPass"
Change to:
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.
-----------------------------------------------------------------------------------
---------------------------------
**SQL INJECTION BASED ON BATCHED SQL STATEMENTS:
-A batch of SQL statements is a group of two or more SQL statements, separated by
semicolons.
-The SQL statement below will return all rows from the "Users" table, then delete
the "Suppliers" table.
-----------------------------------------------------------------------------------
---------------------------------
-----------------------------------------------------------------------------------
---------------------------------
-----------------------------------------------------------------------------------
---------------------------------