4-SQL Injections Flashcards
1-Intro to SQL Injections 2-Subverting Query Logic 3-Using Comments 4-Union Clause 5-Union Injection
What is SQL Injection?
A) A type of network attack that disrupts database connections
B) A security measure to prevent unauthorized database access
C) A technique used to attack data-driven applications by inserting malicious SQL statements into execution fields
D) A method of optimizing SQL queries to improve performance
C) A technique used to attack data-driven applications by inserting malicious SQL statements into execution fields
Explanation: SQL Injection is a technique where an attacker injects malicious SQL statements into the execution fields of a data-driven application, which can manipulate or steal data.
How can SQL Injection occur in web applications?
A) By properly sanitizing user inputs
B) By using parameterized queries
C) By directly including unsanitized user input in SQL queries
D) By restricting database user privileges
C) By directly including unsanitized user input in SQL queries
Explanation: SQL Injection typically occurs when user input is included directly into SQL queries without proper sanitization, allowing attackers to manipulate the queries.
What is the primary defense against SQL Injection?
A) Implementing strict network access controls
B) Using complex SQL commands
C) Sanitizing and validating all user inputs
D) Increasing the number of database administrators
C) Sanitizing and validating all user inputs
Explanation: The primary defense against SQL Injection is sanitizing and validating all user inputs to ensure that they do not contain malicious SQL.
Which PHP function demonstrates a vulnerable way to handle user input for SQL queries?
A) mysqli_real_escape_string()
B) prepare()
C) query() with direct user input concatenation
D) bindParam()
C) query() with direct user input concatenation
Explanation: Using the query() function with direct concatenation of user inputs, as shown in the document, demonstrates a vulnerable approach that can lead to SQL Injection.
What does the following PHP code snippet indicate about SQL Injection risk?
~~~
$query = “SELECT * FROM users WHERE username = ‘” . $username . “’”;
~~~
A) It is secure against SQL Injection because it uses single quotes.
B) It is vulnerable to SQL Injection if $username is not properly sanitized.
C) It is only vulnerable to XSS attacks, not SQL Injection.
D) It is safe as long as the database uses encryption.
B) It is vulnerable to SQL Injection if $username is not properly sanitized.
Explanation: The code snippet is vulnerable to SQL Injection if the variable $username is not properly sanitized, as it directly includes user input in the SQL query.
What type of SQL Injection involves errors displayed by the database to help the attacker?
A) Union-based SQL Injection
B) Error-based SQL Injection
C) Blind SQL Injection
D) Time-based SQL Injection
B) Error-based SQL Injection
Explanation: Error-based SQL Injection exploits error messages from the database to gather information about its structure, which can be used by the attacker.
How can an attacker use the SQL UNION operator in an SQL Injection attack?
A) To delete data from the database
B) To modify database permissions
C) To combine results of two queries into a single result set
D) To perform a denial of service attack
C) To combine results of two queries into a single result set
Explanation: In an SQL Injection attack, the UNION operator can be used to combine the results of two distinct queries into a single result set, potentially disclosing sensitive data.
What is Blind SQL Injection?
A) An attack that is immediately visible to the database administrator
B) An attack that uses boolean conditions to infer data from the database
C) An attack that directly reveals database errors
D) An attack that involves direct interaction with the database’s physical server
B) An attack that uses boolean conditions to infer data from the database
Explanation: Blind SQL Injection involves crafting SQL queries that return true or false results based on boolean conditions, allowing the attacker to infer data without directly seeing it.
What is the purpose of the LIKE SQL operator in an injection attack?
A) To update data in the database
B) To format retrieved data
C) To search for a specific pattern in column data
D) To encrypt data
C) To search for a specific pattern in column data
Explanation: In SQL Injection, the LIKE operator can be used to search for data that matches a specific pattern, which can be exploited to extract information.
Which SQL Injection method involves delaying the response from the database?
A) Union-based SQL Injection
B) Error-based SQL Injection
C) Blind SQL Injection
D) Time-based SQL Injection
D) Time-based SQL Injection
Explanation: Time-based SQL Injection involves queries that delay the database response, using functions like SLEEP(), to infer information based on the response time.
What is the goal of subverting query logic in the context of SQL injection?
A) To speed up database performance
B) To bypass web application security mechanisms
C) To enhance database encryption
D) To create more efficient SQL queries
B) To bypass web application security mechanisms
Explanation: Subverting query logic in SQL injection aims to bypass security mechanisms, often to gain unauthorized access or retrieve sensitive data from a web application.
How can the SQL OR operator be used to bypass authentication?
A) By making the query return false regardless of input
B) By ensuring both conditions must be true for the query to return true
C) By allowing the query to return true if at least one of the conditions is true
D) By making the query dependent on user input only
C) By allowing the query to return true if at least one of the conditions is true
Explanation: The OR operator can bypass authentication by allowing the query to return true if at least one condition is true, which can be manipulated by SQL injection to always be true.
What is the typical result when an SQL query includes an incorrect number of quotes due to injection?
A) The query runs faster
B) The database automatically corrects the syntax
C) It leads to a syntax error in the SQL query
D) It optimizes the query’s execution plan
C) It leads to a syntax error in the SQL query
Explanation: An incorrect number of quotes in an SQL query due to injection often results in a syntax error, which can indicate to an attacker that the input is being processed in the query.
What does the SQL injection payload admin’ OR ‘1’=’1 aim to achieve?
A) It restricts the query results to the admin user only
B) It deletes the admin user from the database
C) It allows the query to always return true, bypassing authentication
D) It encrypts the communication between the client and server
C) It allows the query to always return true, bypassing authentication
Explanation: The payload admin’ OR ‘1’=’1 is designed to make the SQL query always return true, effectively bypassing authentication by subverting the query logic.
What might a successful SQL injection indicate about the web application’s security?
A) High level of encryption
B) Robust error handling
C) Insufficient input sanitization
D) Strong user authentication mechanisms
C) Insufficient input sanitization
Explanation: A successful SQL injection typically indicates insufficient input sanitization, allowing attackers to inject malicious SQL into the application.
In SQL injection, what is the purpose of using comments (– or #)?
A) To annotate the SQL code for better readability
B) To deactivate certain parts of the SQL query to manipulate its logic
C) To encrypt the remainder of the SQL query
D) To increase the execution speed of the query
B) To deactivate certain parts of the SQL query to manipulate its logic
Explanation: In SQL injection, comments are used to deactivate parts of the SQL query to manipulate its logic and bypass security measures, such as authentication.
Which SQL operator is crucial for performing an authentication bypass during an SQL injection attack?
A) AND
B) OR
C) NOT
D) LIKE
B) OR
Explanation: The OR operator is crucial in SQL injection attacks for performing authentication bypasses, as it allows parts of the SQL query to return true, potentially ignoring other conditions.
What character is commonly injected into SQL queries to disrupt their structure?
A) *
B) %
C) #
D) ‘ (single quote)
D) ‘ (single quote)
Explanation: The single quote (‘) is commonly injected into SQL queries to disrupt their structure by prematurely terminating text strings, leading to syntax errors or altered query logic.
What type of SQL injection involves adding SQL code after a valid input?
A) Tautology-based SQL injection
B) Union-based SQL injection
C) Piggy-backed SQL injection
D) Inference-based SQL injection
C) Piggy-backed SQL injection
Explanation: Piggy-backed SQL injection involves adding additional SQL statements or code after a valid input to execute unauthorized commands or bypass security.
What method is described by injecting 1’=’1 into a SQL query?
A) Length-based SQL injection
B) Performance-based SQL injection
C) Tautology-based SQL injection
D) Encryption-based SQL injection
C) Tautology-based SQL injection
Explanation: Injecting 1’=’1 is a method of tautology-based SQL injection where the injection forces the query to always evaluate to true, subverting its logic.