Sins of SQL Injection Flashcards
What is SQL injection?
SQL injection occurs when an attacker provides a database application with malformed data that is used to build a SQL statement using string concatenation.
What does SQL stand for?
Structured Query Language
What is an example of malformed data in SQL injection?
Expecting a number for a calculation but receiving an alphabetical character or sentence instead.
What is string concatenation?
String concatenation is the process of adding characters, words, or sentences together to form a new string.
Provide an example of a SQL statement vulnerable to injection.
Select creditcard_no from customer where customer_id = ‘+ id
How can an attacker exploit this vulnerability?
By providing an input such as ‘1 or 2 > 1’ which retrieves all credit card information from the database.
What are two methods to prevent SQL injection?
Validation and Sanitization.
How does validation help prevent SQL injection?
Validation ensures the input is of the expected type, such as checking if id is a number.
What is the purpose of sanitization in preventing SQL injection?
Sanitization removes illegal characters from the input to ensure it is safe.
What are prepared statements and how do they help prevent SQL injection?
Prepared statements use placeholders for inputs and ensure that inputs are treated as data, not executable code.
Why is it important to understand the database you are using in the context of SQL injection?
To know if it supports stored procedures, the comment operator, and if it allows attackers to call extended functionality.
What should you use to build SQL statements securely?
Parameterized queries, also known as prepared statements, placeholders, or parameter binding.
Where should database connection information be stored?
In a location outside the application, such as a protected configuration file or the Windows registry.
Why should you encrypt sensitive database data?
To protect it from unauthorized access and ensure data privacy.
Why should you avoid simply stripping out “bad words” from input?
Because there are many variants and escapes that may not be detected, and it can sometimes leave remnants of bad words.