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.
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)- A89% (51)
- C7% (4)
- D4% (2)
Why each option
PHP's escapeshellcmd() and escapeshellarg() sanitize shell metacharacters in OS commands and arguments respectively, directly mitigating command injection vulnerabilities.
escapeshellcmd() escapes shell metacharacters such as semicolons, pipes, redirects, and backticks within an entire command string, preventing attackers from injecting additional OS commands.
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.
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.
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
Community Discussion
No community discussion yet for this question.