A backdoor is present (via a rogue file, shell, or malicious cronjob),
File permissions are too loose, or
The attacker has elevated privileges, possibly even root access or PHP shell access.
🔥 Immediate Action Plan
1. ✅ Check for Suspicious Cron Jobs
List system-wide and user crons:
crontab -l
ls -la /etc/cron*
Look for unexpected scripts or obfuscated commands (e.g., base64, curl/wget, PHP files being executed).
2. ✅ Tighten File & Directory Permissions
WordPress permissions best practice:
find /var/www/html -type d -exec chmod 755 {} ;
find /var/www/html -type f -exec chmod 644 {} ;
chown -R www-data:www-data /var/www/html
🔐 Plugins like Wordfence should not be writable by the web server (except for logs and cache dirs).
3. ✅ Look for Common Backdoors
Run a quick scan:
grep -Ri --include="*.php" "eval" /var/www/html
grep -Ri "base64_decode" /var/www/html
grep -Ri "gzinflate" /var/www/html
grep -Ri "shell_exec" /var/www/html
Look especially in:
/wp-content/uploads//wp-includes//wp-admin//vendor//tmp/or/dev/shm/
4. ✅ Reinstall Wordfence and Core Files
Reinstall from fresh source (not backup):
wp plugin delete wordfence
wp plugin install wordfence --activate
And reinstall WordPress core:
wp core download --force
⚠️ This won’t affect your content but removes any tampered core files.
5. ✅ Block File Modifications via wp-config.php
Add this to wp-config.php:
define('DISALLOW_FILE_EDIT', true);
define('DISALLOW_FILE_MODS', true); // Blocks plugin/theme updates via admin
Only do this once your site is clean, as it disables web-based plugin/theme edits.
6. ✅ Enable Immutable Flag (Advanced but Powerful)
After cleanup, lock files using Linux chattr (on ext4 filesystems):
chattr +i /var/www/html/wp-content/plugins/wordfence/*
chattr +i /var/www/html/wp-config.php
This makes files immutable, even for root, unless chattr -i is run manually.
7. ✅ Audit Recent Logins and File Changes
Check recent logins:
last
Check recent file modifications:
find /var/www/html -type f -mtime -1 -exec ls -la {} ;
You may also try:
grep -E 'eval|base64|gzinflate|str_rot13' -R /var/www/html
8. ✅ Recommended Tools to Scan
maldet(Linux Malware Detect)rkhunterchkrootkitClamAV
❗ Last Resort: Full Wipe and Rebuild
If you:
Found modifications in multiple system areas,
Suspect rootkits or privilege escalation,
Can’t clean files with confidence,
🔒 Backup only content and DB, and do a fresh OS + WordPress install.
🔐 Immediate Steps:
Put site in maintenance mode. Temporarily prevent front-end access to stop further damage while we fix.
Reset all access:
Change all FTP/SFTP/SSH passwords.
Regenerate WordPress salts in
wp-config.phpusing this generator.Delete and recreate all WordPress admin users with strong passwords.
Disable file modifications: Add the following to
wp-config.php:define('DISALLOW_FILE_MODS', true);
define('DISALLOW_FILE_EDIT', true);
🛠️ Set Up Automated Monitoring (Custom Cron + File Integrity):
Let’s create a custom PHP script that:
Scans files for changes.
Sends alerts.
Restores clean versions if tampered.
Would you like help generating this script?
🔎 Line-by-Line Malware Analysis:
Would you like to upload a few of the infected files so I can help review and clean them manually?
Also, do you have a clean backup (even if outdated)? That would help with comparing file integrity.
Let me know how you’d like to proceed, and we’ll secure this step by step.
