WWW

Immediate Action Plan in case of a malware attack on the site or the site is compromised

  • Home
  • Careers
  • Immediate Action Plan in case of a malware attack on the site or the site is compromised
If malware isΒ able to modify files, including core plugins like Wordfence, this is a critical security breach β€” it suggests either:
  1. A backdoor is present (via a rogue file, shell, or malicious cronjob),

  2. File permissions are too loose, or

  3. 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


❗ 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:

  1. Put site in maintenance mode. Temporarily prevent front-end access to stop further damage while we fix.

  2. Reset all access:

    • Change all FTP/SFTP/SSH passwords.

    • Regenerate WordPress salts in wp-config.php using this generator.

    • Delete and recreate all WordPress admin users with strong passwords.

  3. 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.

Leave A Comment

Web with Wordpress Logo
Web with Wordpress Logo

Our purpose is to build solutions that remove barriers preventing people from doing their best work.

Cart
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare