shutdown57

WordPress Admin Creator

Oct 3rd, 2025
354
0
Never
7
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.25 KB | None | 0 0
  1. <?php
  2. // Nonaktifkan pelaporan error untuk menjaga kebersihan output
  3. error_reporting(0);
  4. ini_set('display_errors', 0);
  5.  
  6. /**
  7.  * Kelas PasswordHash portabel untuk PHP.
  8.  * Diadaptasi dari kelas phpass WordPress untuk penggunaan mandiri.
  9.  */
  10. class PasswordHash {
  11.     var $itoa64;
  12.     var $iteration_count_log2;
  13.     var $portable_hashes;
  14.     var $random_state;
  15.  
  16.     function __construct($iteration_count_log2, $portable_hashes) {
  17.         $this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  18.         if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31) {
  19.             $iteration_count_log2 = 8;
  20.         }
  21.         $this->iteration_count_log2 = $iteration_count_log2;
  22.         $this->portable_hashes = $portable_hashes;
  23.         $this->random_state = microtime();
  24.         if (function_exists('getmypid')) {
  25.             $this->random_state .= getmypid();
  26.         }
  27.     }
  28.  
  29.     function get_random_bytes($count) {
  30.         $output = '';
  31.         if (is_readable('/dev/urandom') && ($fh = @fopen('/dev/urandom', 'rb'))) {
  32.             $output = fread($fh, $count);
  33.             fclose($fh);
  34.         }
  35.         if (strlen($output) < $count) {
  36.             $output = '';
  37.             for ($i = 0; $i < $count; $i += 16) {
  38.                 $this->random_state = md5(microtime() . $this->random_state);
  39.                 $output .= pack('H*', md5($this->random_state));
  40.             }
  41.             $output = substr($output, 0, $count);
  42.         }
  43.         return $output;
  44.     }
  45.  
  46.     function encode64($input, $count) {
  47.         $output = '';
  48.         $i = 0;
  49.         do {
  50.             $value = ord($input[$i++]);
  51.             $output .= $this->itoa64[$value & 0x3f];
  52.             if ($i < $count) {
  53.                 $value |= ord($input[$i]) << 8;
  54.             }
  55.             $output .= $this->itoa64[($value >> 6) & 0x3f];
  56.             if ($i++ >= $count) {
  57.                 break;
  58.             }
  59.             if ($i < $count) {
  60.                 $value |= ord($input[$i]) << 16;
  61.             }
  62.             $output .= $this->itoa64[($value >> 12) & 0x3f];
  63.             if ($i++ >= $count) {
  64.                 break;
  65.             }
  66.             $output .= $this->itoa64[($value >> 18) & 0x3f];
  67.         } while ($i < $count);
  68.         return $output;
  69.     }
  70.  
  71.     function gensalt_private($input) {
  72.         $output = '$P$';
  73.         $output .= $this->itoa64[min($this->iteration_count_log2 + 5, 30)];
  74.         $output .= $this->encode64($input, 6);
  75.         return $output;
  76.     }
  77.  
  78.     function crypt_private($password, $setting) {
  79.         $output = '*0';
  80.         if (substr($setting, 0, 2) == $output) {
  81.             $output = '*1';
  82.         }
  83.         if (substr($setting, 0, 3) != '$P$') {
  84.             return $output;
  85.         }
  86.         $count_log2 = strpos($this->itoa64, $setting[3]);
  87.         if ($count_log2 < 7 || $count_log2 > 30) {
  88.             return $output;
  89.         }
  90.         $count = 1 << $count_log2;
  91.         $salt = substr($setting, 4, 8);
  92.         if (strlen($salt) != 8) {
  93.             return $output;
  94.         }
  95.         $hash = md5($salt . $password, TRUE);
  96.         do {
  97.             $hash = md5($hash . $password, TRUE);
  98.         } while (--$count);
  99.         $output = substr($setting, 0, 12);
  100.         $output .= $this->encode64($hash, 16);
  101.         return $output;
  102.     }
  103.  
  104.     function gensalt_extended($input) {
  105.         $count_log2 = min($this->iteration_count_log2 + 8, 24);
  106.         $count = (1 << $count_log2) - 1;
  107.         $output = '_';
  108.         $output .= $this->itoa64[$count & 0x3f];
  109.         $output .= $this->itoa64[($count >> 6) & 0x3f];
  110.         $output .= $this->itoa64[($count >> 12) & 0x3f];
  111.         $output .= $this->itoa64[($count >> 18) & 0x3f];
  112.         $output .= $this->encode64($input, 3);
  113.         return $output;
  114.     }
  115.  
  116.     function gensalt_blowfish($input) {
  117.         $itoa64 = './ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  118.         $output = '$2a$';
  119.         $output .= chr(ord('0') + $this->iteration_count_log2 / 10);
  120.         $output .= chr(ord('0') + $this->iteration_count_log2 % 10);
  121.         $output .= '$';
  122.         $i = 0;
  123.         do {
  124.             $c1 = ord($input[$i++]);
  125.             $output .= $itoa64[$c1 >> 2];
  126.             $c1 = ($c1 & 0x03) << 4;
  127.             if ($i >= 16) {
  128.                 $output .= $itoa64[$c1];
  129.                 break;
  130.             }
  131.             $c2 = ord($input[$i++]);
  132.             $c1 |= $c2 >> 4;
  133.             $output .= $itoa64[$c1];
  134.             $c1 = ($c2 & 0x0f) << 2;
  135.             $c2 = ord($input[$i++]);
  136.             $c1 |= $c2 >> 6;
  137.             $output .= $itoa64[$c1];
  138.             $output .= $itoa64[$c2 & 0x3f];
  139.         } while (1);
  140.         return $output;
  141.     }
  142.  
  143.     function HashPassword($password) {
  144.         $random = '';
  145.         if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
  146.             $random = $this->get_random_bytes(16);
  147.             $hash = crypt($password, $this->gensalt_blowfish($random));
  148.             if (strlen($hash) == 60) {
  149.                 return $hash;
  150.             }
  151.         }
  152.         if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
  153.             if (strlen($random) < 3) {
  154.                 $random = $this->get_random_bytes(3);
  155.             }
  156.             $hash = crypt($password, $this->gensalt_extended($random));
  157.             if (strlen($hash) == 20) {
  158.                 return $hash;
  159.             }
  160.         }
  161.         if (strlen($random) < 6) {
  162.             $random = $this->get_random_bytes(6);
  163.         }
  164.         $hash = $this->crypt_private($password, $this->gensalt_private($random));
  165.         if (strlen($hash) == 34) {
  166.             return $hash;
  167.         }
  168.         return '*';
  169.     }
  170. }
  171.  
  172. $message = '';
  173. $message_type = ''; // 'success' or 'error'
  174. $db_config_message = '';
  175. $db_config_type = 'info';
  176.  
  177. // --- Otomatis Deteksi Konfigurasi DB ---
  178. $db_host = $db_user = $db_pass = $db_name = null;
  179. $config_file_path = __DIR__ . '/wp-config.php';
  180.  
  181. if (file_exists($config_file_path) && is_readable($config_file_path)) {
  182.     $config_content = file_get_contents($config_file_path);
  183.  
  184.     function extract_db_config($define, $content) {
  185.         if (preg_match("/define\(\s*['\"]" . $define . "['\"]\s*,\s*['\"]([^']*)['\"]\s*\)/", $content, $matches)) {
  186.             return $matches[1];
  187.         }
  188.         return null;
  189.     }
  190.  
  191.     $db_name = extract_db_config('DB_NAME', $config_content);
  192.     $db_user = extract_db_config('DB_USER', $config_content);
  193.     $db_pass = extract_db_config('DB_PASSWORD', $config_content);
  194.     $db_host = extract_db_config('DB_HOST', $config_content);
  195.  
  196.     if ($db_name && $db_user && $db_host) {
  197.         $db_config_message = "Konfigurasi database berhasil dideteksi dari wp-config.php.";
  198.         $db_config_type = 'success';
  199.     } else {
  200.         $db_config_message = "Gagal mendeteksi semua detail database dari wp-config.php. Pastikan file tersebut ada, dapat dibaca, dan formatnya benar.";
  201.         $db_config_type = 'error';
  202.     }
  203. } else {
  204.     $db_config_message = "File wp-config.php tidak ditemukan di direktori ini. Letakkan skrip ini di direktori root WordPress Anda (di mana wp-config.php berada).";
  205.     $db_config_type = 'error';
  206. }
  207.  
  208. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  209.     if ($db_config_type === 'error') {
  210.         $message = $db_config_message;
  211.         $message_type = 'error';
  212.     } else {
  213.         // Ambil dan bersihkan data dari form
  214.         $admin_user = trim(preg_replace('/[^a-zA-Z0-9_]/', '', $_POST['admin_user']));
  215.         $admin_pass = trim($_POST['admin_pass']);
  216.         $admin_email = trim($_POST['admin_email']);
  217.        
  218.         // Validasi input
  219.         if (empty($admin_user) || empty($admin_pass) || empty($admin_email)) {
  220.             $message = 'Detail admin (username, password, email) wajib diisi.';
  221.             $message_type = 'error';
  222.         } elseif (!filter_var($admin_email, FILTER_VALIDATE_EMAIL)) {
  223.             $message = 'Format email tidak valid.';
  224.             $message_type = 'error';
  225.         } else {
  226.             $conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
  227.            
  228.             if ($conn->connect_error) {
  229.                 $message = "Koneksi Gagal: " . $conn->connect_error;
  230.                 $message_type = 'error';
  231.             } else {
  232.                 $prefix = '';
  233.                 $result = $conn->query("SHOW TABLES LIKE '%users'");
  234.                 if ($result && $result->num_rows > 0) {
  235.                     $row = $result->fetch_array();
  236.                     $users_table = $row[0];
  237.                     $prefix = substr($users_table, 0, strpos($users_table, 'users'));
  238.                 } else {
  239.                     $message = "Tidak dapat menemukan tabel 'users'. Pastikan detail database benar.";
  240.                     $message_type = 'error';
  241.                 }
  242.  
  243.                 if (empty($message)) {
  244.                     $users_table_name = $prefix . 'users';
  245.                     $usermeta_table_name = $prefix . 'usermeta';
  246.  
  247.                     $stmt_check = $conn->prepare("SELECT ID FROM $users_table_name WHERE user_login = ? OR user_email = ?");
  248.                     $stmt_check->bind_param('ss', $admin_user, $admin_email);
  249.                     $stmt_check->execute();
  250.                     $stmt_check->store_result();
  251.  
  252.                     if ($stmt_check->num_rows > 0) {
  253.                         $message = "Username atau email sudah terdaftar.";
  254.                         $message_type = 'error';
  255.                     } else {
  256.                         $hasher = new PasswordHash(8, true);
  257.                         $hashed_password = $hasher->HashPassword($admin_pass);
  258.  
  259.                         $stmt_users = $conn->prepare(
  260.                             "INSERT INTO $users_table_name (user_login, user_pass, user_nicename, user_email, user_registered, user_status, display_name) VALUES (?, ?, ?, ?, NOW(), 0, ?)"
  261.                         );
  262.                         $stmt_users->bind_param('sssss', $admin_user, $hashed_password, $admin_user, $admin_email, $admin_user);
  263.                        
  264.                         if ($stmt_users->execute()) {
  265.                             $new_user_id = $stmt_users->insert_id;
  266.  
  267.                             $capabilities = 'a:1:{s:13:"administrator";b:1;}';
  268.                             $stmt_meta1 = $conn->prepare("INSERT INTO $usermeta_table_name (user_id, meta_key, meta_value) VALUES (?, ?, ?)");
  269.                             $meta_key_cap = $prefix . 'capabilities';
  270.                             $stmt_meta1->bind_param('iss', $new_user_id, $meta_key_cap, $capabilities);
  271.                             $stmt_meta1->execute();
  272.                             $stmt_meta1->close();
  273.                            
  274.                             $stmt_meta2 = $conn->prepare("INSERT INTO $usermeta_table_name (user_id, meta_key, meta_value) VALUES (?, ?, ?)");
  275.                             $meta_key_level = $prefix . 'user_level';
  276.                             $user_level = '10';
  277.                             $stmt_meta2->bind_param('iss', $new_user_id, $meta_key_level, $user_level);
  278.                             $stmt_meta2->execute();
  279.                             $stmt_meta2->close();
  280.  
  281.                             $message = "Admin user '<strong>$admin_user</strong>' berhasil dibuat! Silakan login dan HAPUS FILE INI SEKARANG.";
  282.                             $message_type = 'success';
  283.                         } else {
  284.                             $message = "Gagal membuat user: " . $stmt_users->error;
  285.                             $message_type = 'error';
  286.                         }
  287.                         $stmt_users->close();
  288.                     }
  289.                     $stmt_check->close();
  290.                 }
  291.                 $conn->close();
  292.             }
  293.         }
  294.     }
  295. }
  296. ?>
  297. <!DOCTYPE html>
  298. <html lang="id">
  299. <head>
  300.     <meta charset="UTF-8">
  301.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  302.     <title>WordPress Admin Creator</title>
  303.     <script src="https://cdn.tailwindcss.com"></script>
  304.     <style>
  305.         body {
  306.             font-family: 'Inter', sans-serif;
  307.         }
  308.         @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
  309.     </style>
  310. </head>
  311. <body class="bg-gray-100 flex items-center justify-center min-h-screen py-12">
  312.     <div class="w-full max-w-lg mx-auto bg-white rounded-xl shadow-lg p-8 md:p-10">
  313.         <div class="text-center mb-8">
  314.             <h1 class="text-3xl font-bold text-gray-800">WordPress Admin Creator</h1>
  315.             <p class="text-gray-500 mt-2">Buat user admin baru jika Anda kehilangan akses.</p>
  316.         </div>
  317.  
  318.         <div class="bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded-md mb-6" role="alert">
  319.             <p class="font-bold">Peringatan Keamanan!</p>
  320.             <p>Setelah selesai, <strong class="underline">SEGERA HAPUS</strong> file ini dari server Anda untuk melindungi situs Anda.</p>
  321.         </div>
  322.  
  323.         <?php if (!empty($message)): ?>
  324.         <div class="p-4 mb-6 rounded-md <?php echo ($message_type === 'success') ? 'bg-green-100 border-l-4 border-green-500 text-green-700' : 'bg-red-100 border-l-4 border-red-500 text-red-700'; ?>">
  325.             <p><?php echo $message; ?></p>
  326.         </div>
  327.         <?php endif; ?>
  328.  
  329.         <div class="mb-6">
  330.             <h2 class="text-lg font-semibold text-gray-700 border-b pb-2 mb-4">Status Konfigurasi Database</h2>
  331.             <?php
  332.                 $alert_class = 'bg-blue-100 border-blue-500 text-blue-700'; // Default
  333.                 if ($db_config_type === 'success') {
  334.                     $alert_class = 'bg-green-100 border-green-500 text-green-700';
  335.                 } elseif ($db_config_type === 'error') {
  336.                     $alert_class = 'bg-red-100 border-red-500 text-red-700';
  337.                 }
  338.             ?>
  339.             <div class="p-4 rounded-md border-l-4 <?php echo $alert_class; ?>">
  340.                 <p><?php echo $db_config_message; ?></p>
  341.                 <?php if ($db_config_type === 'success'): ?>
  342.                 <ul class="list-disc list-inside mt-2 text-sm">
  343.                     <li><strong>DB Host:</strong> <?php echo htmlspecialchars($db_host); ?></li>
  344.                     <li><strong>DB Name:</strong> <?php echo htmlspecialchars($db_name); ?></li>
  345.                     <li><strong>DB User:</strong> <?php echo htmlspecialchars($db_user); ?></li>
  346.                 </ul>
  347.                 <?php endif; ?>
  348.             </div>
  349.         </div>
  350.  
  351.  
  352.         <form action="" method="POST" <?php if ($db_config_type === 'error') echo 'style="display:none;"'; ?>>
  353.             <div>
  354.                 <h2 class="text-lg font-semibold text-gray-700 border-b pb-2 mb-4">Detail Admin Baru</h2>
  355.                 <div class="space-y-4">
  356.                     <div>
  357.                         <label for="admin_user" class="block text-sm font-medium text-gray-700">Username Admin</label>
  358.                         <input type="text" name="admin_user" id="admin_user" class="mt-1 block w-full px-3 py-2 bg-white border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500" required>
  359.                     </div>
  360.                     <div>
  361.                         <label for="admin_pass" class="block text-sm font-medium text-gray-700">Password Admin</label>
  362.                         <input type="password" name="admin_pass" id="admin_pass" class="mt-1 block w-full px-3 py-2 bg-white border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500" required>
  363.                     </div>
  364.                     <div>
  365.                         <label for="admin_email" class="block text-sm font-medium text-gray-700">Email Admin</label>
  366.                         <input type="email" name="admin_email" id="admin_email" class="mt-1 block w-full px-3 py-2 bg-white border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500" required>
  367.                     </div>
  368.                 </div>
  369.             </div>
  370.  
  371.             <div class="mt-8">
  372.                 <button type="submit" class="w-full flex justify-center py-3 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition-colors">
  373.                     Buat Admin
  374.                 </button>
  375.             </div>
  376.         </form>
  377.     </div>
  378. </body>
  379. </html>
  380.  
  381.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment