Command injection without proper validation
This lab demonstrates a basic command injection vulnerability where user input is directly used in system commands without proper validation or sanitization. The application allows execution of arbitrary commands on the server.
Objective: Inject and execute arbitrary commands to achieve code execution and information disclosure.
// Vulnerable: Direct execution without validation
function execute_command($command) {
if (empty($command)) {
return "No command specified.";
}
// Vulnerable: Direct execution using shell_exec
$output = @shell_exec($command . ' 2>&1');
if ($output === null) {
return "Command execution failed or no output.";
}
return $output;
}
Try these basic commands:
whoami - Current userid - User ID informationpwd - Current directoryls - List filesuname -a - System informationwhoami - Basic commandid; ls - Multiple commandscat /etc/passwd - File readingps aux - Process listingUse these payloads to test the command injection vulnerability: