nerdexam
GIAC

GSLC · Question #559

Which of the following can be used as a countermeasure against the SQL injection attack? Each correct answer represents a complete solution. Choose two.

The correct answer is C. mysql_real_escape_string() D. Prepared statement. SQL injection is mitigated by escaping user input with the correct character-set-aware function and by using parameterized queries that separate data from SQL logic.

Security Architecture & Engineering

Question

Which of the following can be used as a countermeasure against the SQL injection attack? Each correct answer represents a complete solution. Choose two.

Options

  • Amysql_escape_string()
  • Bsession_regenerate_id()
  • Cmysql_real_escape_string()
  • DPrepared statement

How the community answered

(40 responses)
  • A
    13% (5)
  • B
    8% (3)
  • C
    80% (32)

Why each option

SQL injection is mitigated by escaping user input with the correct character-set-aware function and by using parameterized queries that separate data from SQL logic.

Amysql_escape_string()

mysql_escape_string() is deprecated and does not consider the active connection's character set, meaning multi-byte encoding attacks can bypass its escaping in certain configurations, leaving the application vulnerable.

Bsession_regenerate_id()

session_regenerate_id() is a PHP session management function that creates a new session ID to prevent session fixation attacks - it has no effect on database query construction or SQL injection.

Cmysql_real_escape_string()Correct

mysql_real_escape_string() escapes special characters in user input while accounting for the current database connection's character set, preventing attackers from injecting SQL metacharacters that break query structure.

DPrepared statementCorrect

Prepared statements (parameterized queries) are the most robust defense - they pre-compile the SQL structure and bind user-supplied values as typed parameters, making it structurally impossible for input data to be interpreted as SQL code.

Concept tested: SQL injection prevention using escaping and parameterized queries

Source: https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html

Topics

#SQL injection#input validation#prepared statements#web application security

Community Discussion

No community discussion yet for this question.

Full GSLC Practice