SQL Injection Cheat Sheet
SQL Injection Cheat Sheet
SQL Injection Cheat Sheet
With more than 20 percent of all web vulnerabilities being attributed to SQL injection,
this is the second most common software vulnerability. Therefore, having the ability
to find and prevent SQL injection should be top of mind for web developers and
security personnel. In general, a SQL injection attack exploits a web application that
does not properly validate or encode user-supplied input and then uses that input as
part of a query or command against a back-end database. For example, a typical
form may ask for an ID and create a URL:
"http://www.somewebsite.com/id/id.asp?id=somedata". An attacker using
SQL injection may enter "somedata or 1=1". If the web application does not
properly validate or encode the user-supplied data and sends it directly to the
database, the reply to the query will expose all IDs in the database, since the
condition "1=1" is always true. This is a basic example, but it illustrates the
importance of sanitizing user-supplied data before using it in a query or
command.
The following video tutorial on SQL injection walks you through more on topics such
as "what is SQL injection?" "methods of SQL injection protection" and "how to avoid
a SQL injection attack."
Lets look at the example code below.
You will notice that user input is required to run this query. The interpreter will execute
the command based on the inputs received for the username and password
fields.
If an attacker provides or 0=0 as the username and password, then the query will be
constructed as:
String SQLQuery =SELECT Username, Password FROM users WHERE
Username= or 0=0 AND Password= or 0=0;
Since under all circumstances, zero will be equal to zero, the query will return all records
in the database. In this way, an unauthorized user will be able to view sensitive
information.
The following SQL Injection Cheat Sheet provides a summary of everything you need to
know about SQL injection. The SQL Injection Cheat Sheet contains the key concepts of
a SQL injection attack, a SQL injection example and tips to avoid a SQL injection hack.
Download our SQL Injection Cheat Sheet
To further illustrate injection attacks and preventative steps, we've created this original
infographic titled "What is SQL injection," which serves as a visual tutorial to
demonstrate how you might be vulnerable to injection attacks, how you can prevent SQL
injection and an additional example of SQL injection. If you like this infographic, please
share it. And you can embed it on your website with the HTML code below it.