GCIH · Question #53
GCIH Question #53: Real Exam Question with Answer & Explanation
The correct answer is A: escapeshellarg(). PHP provides escapeshellarg() and escapeshellcmd() to sanitize user input before it is passed to shell commands, directly mitigating command injection. Functions like htmlentities() and strip_tags() address HTML/XSS vulnerabilities, not shell injection.
Question
Options
- Aescapeshellarg()
- Bescapeshellcmd()
- Chtmlentities()
- Dstrip_tags()
Explanation
PHP provides escapeshellarg() and escapeshellcmd() to sanitize user input before it is passed to shell commands, directly mitigating command injection. Functions like htmlentities() and strip_tags() address HTML/XSS vulnerabilities, not shell injection.
Common mistakes.
- C. htmlentities() converts special characters to their HTML entity equivalents, which protects against Cross-Site Scripting (XSS) in HTML output but has no effect on how the shell parses commands.
- D. strip_tags() removes HTML and PHP tags from a string to defend against tag-based XSS injection in web output, and provides no protection against shell metacharacter abuse in command injection scenarios.
Concept tested. PHP shell sanitization functions for command injection prevention
Reference. https://www.php.net/manual/en/function.escapeshellarg.php
Topics
Community Discussion
No community discussion yet for this question.