flawopen.com/Command Injection/PHP
Imagine a form where you enter a website to check if it's online. If someone enters 'google.com; cat /etc/passwd', and PHP runs the whole sentence in terminal, they get to read your server passwords.
PHP has multiple built-in shell invocation functions: system(), exec(), passthru(), shell_exec(), and the backtick operator (` `). All of these spawn a shell and execute strings directly.
Command injection in PHP web apps has caused massive breaches in enterprise file sync services and content management systems, enabling root shell access.
OWASP PHP Top 10 vulnerabilities.escapeshellarg() encloses the parameter in single quotes and strips/escapes any existing single quotes, preventing shell metacharacters from breaking out of the parameter string.
escapeshellcmd() only escapes shell metacharacters but allows multiple arguments, enabling flag injection. Always use escapeshellarg() for individual parameter values.
PHP has many execution aliases: exec, shell_exec, passthru, proc_open, popen, and backtick operators. Disabling only one function leaves the others open.
grep -rn "shell_exec(" --include="*.php" .
grep -rn "system(" --include="*.php" .
FILTER_VALIDATE_IP)escapeshellarg()disable_functions = exec,system,shell_exec,passthruproc_open() provides the greatest control over environment, file descriptors, and pipes without passing input through a raw shell.