nerdexam
GIAC

GSLC · Question #540

Which of the following functions can you use to mitigate a command injection attack? Each correct answer represents a complete solution. Choose all that apply.

The correct answer is A. escapeshellcmd() B. escapeshellarg(). PHP's escapeshellcmd() and escapeshellarg() sanitize shell metacharacters in OS commands and arguments respectively, directly mitigating command injection vulnerabilities.

Security Architecture & Engineering

Question

Which of the following functions can you use to mitigate a command injection attack? Each correct answer represents a complete solution. Choose all that apply.

Options

  • Aescapeshellcmd()
  • Bescapeshellarg()
  • Chtmlentities()
  • Dstrip_tags()

How the community answered

(57 responses)
  • A
    89% (51)
  • C
    7% (4)
  • D
    4% (2)

Why each option

PHP's escapeshellcmd() and escapeshellarg() sanitize shell metacharacters in OS commands and arguments respectively, directly mitigating command injection vulnerabilities.

Aescapeshellcmd()Correct

escapeshellcmd() escapes shell metacharacters such as semicolons, pipes, redirects, and backticks within an entire command string, preventing attackers from injecting additional OS commands.

Bescapeshellarg()Correct

escapeshellarg() wraps a single argument in quotes and escapes any embedded quotes, ensuring user-supplied data is treated strictly as a literal argument and cannot break out of the intended command context.

Chtmlentities()

htmlentities() converts HTML special characters to their entity equivalents, which prevents cross-site scripting (XSS) attacks against HTML output but does nothing to neutralize OS shell metacharacters used in command injection.

Dstrip_tags()

strip_tags() removes HTML and PHP tags from a string to prevent HTML injection or certain XSS vectors, but it does not address shell metacharacters and provides no protection against command injection.

Concept tested: PHP functions mitigating OS command injection

Source: https://owasp.org/www-community/attacks/Command_Injection

Topics

#command injection#input sanitization#escapeshellcmd#secure coding

Community Discussion

No community discussion yet for this question.

Full GSLC Practice