Command injection with security filters that can be bypassed
This lab demonstrates command injection vulnerabilities where basic security filters are implemented but can be bypassed using various techniques. The application filters dangerous commands and characters but doesn't prevent all attack vectors.
Objective: Bypass security filters to achieve command injection and code execution.
// Vulnerable: Basic filters that can be bypassed
function execute_command_with_filters($command) {
$dangerous_commands = ['rm', 'del', 'rmdir', 'format', 'fdisk'];
$dangerous_chars = [';', '|', '&', '`', '$', '(', ')', '<', '>'];
$dangerous_patterns = ['/etc/passwd', '/etc/shadow', '/proc/'];
// Basic filter check (can be bypassed)
$is_dangerous = false;
foreach ($dangerous_commands as $cmd) {
if (stripos($command, $cmd) !== false) {
$is_dangerous = true;
break;
}
}
// Still vulnerable to bypass techniques
if (!$is_dangerous) {
$output = @shell_exec($command . ' 2>&1');
return $output;
}
}
The following are filtered:
These commands should work:
whoami - Current userid - User ID informationpwd - Current directoryls - List filesuname -a - System informationUse these payloads to bypass the security filters: