How to Remove Malware from Your WordPress Site and Secure It for the Future

WordPress is a powerful and widely used content management system, but its popularity also makes it a target for hackers and malware attacks. If you suspect your WordPress site has been compromised, it's essential to act quickly to remove the malware and secure your site. Here’s a comprehensive guide to help you clean your WordPress site of malware.

Signs Your WordPress Site May Be Infected

  • Unfamiliar links or content on your website.
  • Decreased website performance or speed.
  • Unexpected redirects to unknown sites.
  • Warning messages from your browser or search engines.
  • Your hosting provider suspends your account.

Step 1: Backup Your Website

Before making any changes, create a complete backup of your site. This ensures you can recover your data if anything goes wrong. create a manual backup using your hosting provider's cPanel or an FTP client like FileZilla.

 

Step 2: Identify the Malware

Scan your WordPress site to pinpoint the infected files. 
Your hosting provider likely offers advanced tools for website malware scanning. Consider reaching out to them for a comprehensive scan of your entire website.

Recommended tools:

  • Sucuri SiteCheck: Free online scanner.
  • Wordfence Security: A WordPress plugin that scans for malware.
  • MalCare: Automated scanning and cleaning tool.
  • Hosting Scanners: Many hosting providers like SiteGround or Bluehost offer built-in malware detection tools.

You can perform a live scan of your site using Sucuri SiteCheck. It will generate a detailed report, identifying infected files and pinpointing where malicious code has been injected.

 

 

Step 3: Remove Malware-Infected Files

Once you’ve identified the infected files, you need to clean or replace them.

Option 1: Manually Remove Malware

  1. Access Your Site: Use an FTP client or your hosting cPanel.
  2. Locate Infected Files: Check for unusual code or scripts in the following locations:
  • wp-content/uploads
  • wp-content/themes
  • wp-content/plugins
  • wp-config.php

Clean or Delete: Remove malicious code or replace the file with a clean version from a backup.

Option 2: Use a Malware Removal Tool

  • Use plugins like Sucuri Security or MalCare to automate the cleaning process. These tools scan and clean your site with minimal manual intervention.

Steps 4: Remove a Hacked Database Injection

1. Backup Everything

Before making any changes, create a full backup of:

  • Your WordPress files and folders.
  • Your database (use phpMyAdmin or a similar tool).

2. Scan for Malicious Code

  • Database Search:
    • Use tools like phpMyAdmin or Adminer to search for suspicious or injected code.
    • Common keywords to look for:
      • script (used for injecting malicious JavaScript)

      • eval or base64_decode (common in obfuscated PHP code)

      • iframe tags

      • UNION SELECT or SQL commands that shouldn't exist.

  • Example SQL query to find injections:

 

3. Clean the Database

 

  • Manually remove any identified malicious code:

    • Navigate to the affected table (e.g., wp_postswp_options, or wp_users).

    • Edit and clean the infected rows by removing malicious scripts or restoring the content from a backup.

  • Automated Cleanup:

    • Use a plugin like WP-DBManager or Sucuri for database repair if available.

 Step 4: Update Everything

Outdated themes, plugins, and WordPress cores are common entry points for hackers.

  • Update WordPress core to the latest version.

  • Update all plugins and themes.

  • Remove unused or outdated plugins and themes.

 

 Step 5: Secure Your Website

1. Update Everything

Outdated themes, plugins, and WordPress cores are common entry points for hackers.

  • Update WordPress core to the latest version.

  • Update all plugins and themes.

  • Remove unused or outdated plugins and themes.

2. Configure Proper File Permissions

    Ensure correct permissions find attached table for proper file permision
    all wordpress website folder structure shoule be have proper file foleder permission as mentioned in below table

Name

File/Folder

 Recommended permissions

root directory

/public_html/

755

wp-includes/

/public_html/wp-includes

755

.htaccess

/public_html/.htaccess

644

wp-admin/index.php

/public_html/wp-admin/index.php

644

wp-admin/js/

/public_html/wp-admin/js/

755

wp-content/themes/

/public_html/wp-content/themes

755

wp-content/plugins/

/public_html/wp-content/plugins

755

wp-admin/

/public_html/wp-admin

755

wp-content/

/public_html/wp-content

755

wp-config.php

/public_html/wp-config.php

640

 3. Change All Credentials

  • Update:

    • WordPress admin password.

    • Database user password.

    • FTP credentials.

    • Hosting control panel password.

  • Check for unauthorized users in wp_users and delete any suspicious accounts.

4. Disable Directory Browsing:

   Use the cPanel "Indexes" Feature

 

  1. Go to the Indexes Tool:

    • In cPanel, navigate to the Advanced section and click on Indexes.

  2. Select the Directory:

    • Choose the directory you want to configure (e.g., public_html).

  3. Set to "No Indexing":

    • Select the No Indexing option to disable directory browsing for that folder.

  4. Save Settings.

 

  • Add the Following Code in your .htaccess file inside public_html folder to Disable Directory Browsing:

Options -Indexes

 

 

5. Harden Security:

Use plugins like WordfenceiThemes Security, or Sucuri to add extra layers of protection.

  • Wordfence Monitor Traffic for Unexpected IP Requests:

    Enable Live Traffic View

  1. Go to your WordPress dashboard and navigate to Wordfence > Tools > Live Traffic.

  2. Live Traffic View displays real-time data about:

    • Visitors (including crawlers and bots).

    • Blocked IPs and failed login attempts.

    • Suspicious activities such as repeated 404 errors.

    Identify Suspicious IPs

  • Look for patterns such as:

    • Excessive login attempts (Brute force).

    • Repeated access to wp-login.php or admin pages.

    • Requests to non-existent pages or files.

    • Large numbers of requests in a short time (indicative of DDoS attacks).

     Block IP Addresses Manually

  1. Navigate to Wordfence > Firewall > Blocking.

  2. Add the IP(s) you want to block:

    • Enter the IP address.

    • Optionally, provide a reason for the block (for your reference).

  3. Set a duration for the block (e.g., permanently or for a specific time).

  4. Save your changes.

 

 

Enjoyed this article? Stay informed by joining our newsletter!

Comments

You must be logged in to post a comment.

Related Articles
About Author

I am a passionate and detail-oriented software/web developer with 5 years of experience in creating efficient, user-friendly, and scalable applications and websites. Skilled in JavaScript, Python, and PHP and familiar with popular frameworks like React, Django, and Laravel, I specialize in delivering high-quality software solutions tailored to meet clients' specific needs. My journey in technology began with a fascination for problem-solving and innovation. Over the years, I have successfully developed e-commerce platforms, responsive websites for small businesses, and custom CRM systems for enterprises. My work emphasizes clean code, modern design principles, and optimal performance to ensure client satisfaction. When I'm not coding, I enjoy exploring new tech trends, contributing to open-source projects, and playing chess. I am committed to lifelong learning and staying at the forefront of advancements in the software industry. Motto: "Turning ideas into impactful digital experiences."