Test Remote Code Execution vulnerabilities with direct command execution
This lab contains a critical Remote Code Execution (RCE) vulnerability through direct command execution. The application passes user input directly to the shell_exec() function without any filtering or validation.
shell_exec($_GET['cmd']) with no input validation.
Objective: Understand how command injection vulnerabilities work and practice safe exploitation techniques in a controlled environment.
<?php
if (isset($_GET['cmd'])) {
$cmd = $_GET['cmd'];
$output = shell_exec($cmd);
}
?>
This vulnerability demonstrates:
To prevent command injection:
command1 ; command2 - Run sequentiallycommand1 && command2 - Run if first succeedscommand1 || command2 - Run if first failscommand1 | command2 - Pipe outputcommand1 & - Run in backgroundcat /etc/passwd - View user accountsls -la /home/ - List home directoriesuname -a - System informationid - Current user privilegesps aux - Running processesnetstat -tulpn - Network connections