6-Mitigations Flashcards

Mitigating SQL Injection

1
Q

What is the most effective method to prevent SQL injection attacks?
A) Using regular expressions to validate input
B) Employing parameterized queries
C) Limiting user privileges
D) Implementing Web Application Firewalls (WAF)

A

B) Employing parameterized queries

Explanation: Using parameterized queries is considered the most effective method to prevent SQL injections because it separates SQL code from the data, preventing attackers from manipulating the SQL executed by the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What role does input sanitization play in preventing SQL injections?
A) It formats the output of queries
B) It removes or escapes special characters in user inputs
C) It speeds up the processing of queries
D) It compresses the data to be stored in the database

A

B) It removes or escapes special characters in user inputs

Explanation: Input sanitization involves removing or escaping special characters that could be used in SQL injection attacks, rendering injected SQL code ineffective.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is it important to limit database privileges for web application users?
A) To enhance the performance of the database
B) To reduce the storage requirements of the database
C) To prevent unauthorized data access or modifications
D) To increase the concurrency capabilities of the database

A

C) To prevent unauthorized data access or modifications

Explanation: Limiting database privileges is crucial to ensuring that even if an SQL injection occurs, the damage or potential data leakage can be minimized because the attacker cannot perform actions beyond their privileges.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does a Web Application Firewall (WAF) help mitigate SQL injection?
A) By encrypting all data transfers
B) By physically isolating the database server
C) By detecting and blocking malicious SQL code in HTTP requests
D) By optimizing SQL queries automatically

A

C) By detecting and blocking malicious SQL code in HTTP requests

Explanation: WAFs help prevent SQL injections by inspecting incoming HTTP requests and blocking those that contain malicious SQL, thereby protecting the application despite potential vulnerabilities in its code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of using the mysqli_real_escape_string() function in PHP?
A) To duplicate strings in the database
B) To encrypt passwords
C) To escape special characters in strings to be used in SQL queries
D) To convert all strings to lowercase

A

C) To escape special characters in strings to be used in SQL queries

Explanation: The mysqli_real_escape_string() function is used to escape potentially harmful characters in strings that will be used in SQL queries, preventing them from breaking out of data context and injecting malicious code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does input validation check for in user submissions?
A) Correct syntax of SQL commands
B) Compatibility of data with database types
C) Conformance of data to expected patterns, such as email formats
D) Speed of data entry by the user

A

C) Conformance of data to expected patterns, such as email formats

Explanation: Input validation ensures that data submitted by users matches expected patterns (e.g., email addresses, phone numbers), which helps prevent SQL injection by rejecting unexpected inputs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What type of user account is recommended for web applications to interact with databases?
A) An account with DBA privileges
B) An account with minimum necessary privileges
C) An account with full read and write privileges
D) An account with guest access only

A

B) An account with minimum necessary privileges

Explanation: Web applications should interact with databases using accounts that have the minimum necessary privileges to perform required tasks, reducing the risk of severe exploitation through SQL injection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does setting secure_file_priv to NULL in MySQL accomplish?
A) Allows files to be read from and written to any directory
B) Restricts file operations to a specific directory
C) Disables the ability to read from and write files to the filesystem
D) Encrypts all file operations

A

C) Disables the ability to read from and write files to the filesystem

Explanation: Setting secure_file_priv to NULL in MySQL disables the ability to use SQL commands to read from or write files to the server’s filesystem, enhancing security by limiting SQL injection impacts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does parameterized querying prevent SQL injection?
A) By executing SQL commands faster
B) By checking user credentials before executing queries
C) By separating SQL logic from data inputs
D) By compressing the query data

A

C) By separating SQL logic from data inputs

Explanation: Parameterized queries prevent SQL injection by separating SQL code from data inputs. Placeholders are used for data, which is then safely processed by the database driver, preventing injected code execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which PHP function is used to bind variables to a prepared SQL statement?
A) mysqli_bind_param()
B) mysqli_stmt_bind_param()
C) mysqli_prepare()
D) mysqli_execute()

A

B) mysqli_stmt_bind_param()

Explanation: The mysqli_stmt_bind_param() function is used to bind variables to a prepared SQL statement, ensuring that the values are handled as data and not executable code, which is crucial for preventing SQL injection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly