nerdexam
GIAC

GPEN · Question #34

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 C. escapeshellarg() D. escapeshellcmd(). PHP's escapeshellarg() and escapeshellcmd() sanitize data passed to shell commands to prevent injection, while htmlentities() and strip_tags() target HTML/XSS issues and offer no protection against OS command injection.

Web Application Penetration Testing

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

  • Ahtmlentities()
  • Bstrip_tags()
  • Cescapeshellarg()
  • Descapeshellcmd()

How the community answered

(40 responses)
  • A
    5% (2)
  • B
    15% (6)
  • C
    80% (32)

Why each option

PHP's escapeshellarg() and escapeshellcmd() sanitize data passed to shell commands to prevent injection, while htmlentities() and strip_tags() target HTML/XSS issues and offer no protection against OS command injection.

Ahtmlentities()

htmlentities() converts HTML special characters to their HTML entity equivalents to mitigate XSS in rendered output, but it does not escape shell metacharacters and provides no protection against command injection.

Bstrip_tags()

strip_tags() removes HTML and PHP tags from a string to reduce XSS risk, but it has no effect on the shell-level metacharacters that enable command injection attacks.

Cescapeshellarg()Correct

escapeshellarg() wraps user input in single quotes and escapes embedded single quotes, ensuring the input is treated as a single safe literal argument rather than being parsed as shell metacharacters or additional commands.

Descapeshellcmd()Correct

escapeshellcmd() escapes shell metacharacters such as semicolons, pipes, ampersands, and backticks within a command string, preventing attackers from appending or injecting additional OS commands.

Concept tested: PHP functions mitigating OS command injection

Source: https://www.php.net/manual/en/function.escapeshellarg.php

Topics

#command injection#escapeshellarg#escapeshellcmd#input validation

Community Discussion

No community discussion yet for this question.

Full GPEN Practice