WordPress Security Guide

WordPress Malware Removal: What a Proper Cleanup Actually Includes

Deleting the infected files is the easy part. The work that decides whether your site stays clean is finding how the attacker got in, removing every persistence mechanism they left behind, and closing the path before you put the site back in front of customers.

Written by Rana Shahwaiz Aslam, CEH Certified, Xequent. Updated August 2026.

  • CEH Certified
  • Top Rated Plus on Upwork
  • 100% Job Success
  • Handled directly, not outsourced
Before you touch anything

Treat a hacked site as an incident, not a cleanup task

The instinct when you find malicious code is to delete it immediately. Resist that for an hour. The moment you start deleting, you destroy the evidence that tells you how the attacker got in, what else they touched, and whether they still have access. A cleanup that skips this step is a cleanup you will repeat.

Three things happen first. Take a full copy of the site as it currently is, infected, including the database, and store it somewhere the live site cannot reach. Note the timestamps of every suspicious file you have already found. Then pull whatever access logs your host retains, because the request that dropped the first payload is usually still in them.

Contain before you investigate

If the site is actively serving malware to visitors, redirecting traffic, or sending spam, containment comes before investigation. Putting the site into maintenance mode, disabling outbound mail, or placing it behind an access rule stops the ongoing damage while you work. On a site handling payments, containment is not optional.

Assume the credentials are gone

If an attacker had file write access, treat every credential reachable from that server as compromised: WordPress administrator accounts, database user, FTP and SFTP, hosting panel, and any API keys sitting in wp-config.php or a plugin settings table. Rotating these later, after the cleanup, is a common reason sites get reinfected during the cleanup itself.

Files and database

Clean both layers, because malware rarely lives in only one

A WordPress infection almost always spans the filesystem and the database. Cleaning one and declaring victory is the single most common failure in do-it-yourself recovery.

On the filesystem

Replace WordPress core wholesale with a fresh copy of the same version rather than trying to clean individual core files. Do the same for every plugin and theme that is still available from a trusted source. This is faster and more reliable than diffing thousands of files, and it removes injected code you have not spotted yet.

What cannot be replaced wholesale is the uploads directory, wp-config.php, .htaccess, and any custom or abandoned plugin with no clean source. These get reviewed by hand. Executable files inside wp-content/uploads are a strong signal on their own, because nothing legitimate puts PHP there.

In the database

Check the options table for injected script tags and unexpected autoloaded rows, the users table for administrator accounts you do not recognise, the posts and postmeta tables for hidden spam blocks, and any table holding theme or widget content. On a multisite install, repeat per site. Pharma hacks and SEO spam injections live here far more often than in files, which is exactly why file-only scans keep reporting a clean site that is still serving spam to Google.

The part most cleanups miss

Hunt persistence before you call it clean

An attacker who has been on a site for more than a few hours has usually left more than one way back in. Persistence is the reason a site gets reinfected within a week of a cleanup that looked complete.

The mechanisms worth checking every time:

  • Extra administrator accounts, sometimes with plausible names and a recent registration date.
  • Scheduled tasks, both WordPress cron entries and server crontab, which can re-download a payload minutes after you delete it.
  • Must-use plugins in wp-content/mu-plugins, which load automatically and never appear in the plugin list.
  • Modified .htaccess rules that conditionally redirect based on user agent or referrer, so the site looks fine to you and redirects the visitor arriving from Google.
  • Injected code in the active theme, particularly functions.php and header or footer templates.
  • Rogue SSH keys or hosting panel accounts where the compromise reached the server rather than just the application.

Match the timeline

Use the timestamp of the earliest known malicious file as your anchor, then look at everything modified in the same window. Attackers frequently reset timestamps on the obvious payload and forget the helper file they wrote three minutes earlier.

Closing the door

Find the entry point, or you are just resetting the clock

Cleanup without root cause is temporary. In practice the entry point is almost always one of a short list: a known vulnerability in an outdated plugin or theme, a weak or reused administrator password, a compromised hosting or FTP account, a nulled premium plugin carrying a backdoor from the day it was installed, or a neighbouring site on the same shared hosting account.

Access logs settle it faster than guesswork. Look for POST requests to unusual paths around the first malicious file timestamp, requests to files that should not accept POST at all, and successful logins from addresses that do not match your team. If the entry point genuinely cannot be determined from available evidence, say so, and compensate by hardening every plausible path rather than pretending you found it.

This is also where a security hardening pass stops being optional. Cleanup removes the current infection. Hardening is what changes the outcome next time.

Verification

Prove the site is clean instead of assuming it

Verification is a separate step with its own checklist, not a feeling that you got everything.

  • Re-run file integrity checks against a fresh core and plugin baseline and confirm zero unexpected differences.
  • Fetch the homepage and several inner pages while spoofing Googlebot as the user agent, then compare against a normal browser request. Cloaked spam only appears under the crawler.
  • Check a Google site: search for indexed spam URLs that need removal.
  • Confirm no unexpected outbound connections or mail queue activity.
  • Review Search Console for security issues and manual actions, and request review only after everything above passes.
  • Watch the site for at least a week. Reinfection usually shows within days, and it tells you the persistence hunt missed something.

Full detail on the detection side of this is in the WordPress malware scanning guide.

After recovery

Harden, document, then reduce the attack surface at the edge

The window immediately after a cleanup is the best time to fix the things that made the site an easy target. Update everything to current versions. Remove plugins and themes that are deactivated but still installed, because inactive code is still reachable code. Enforce strong unique passwords and two factor authentication on every administrator account. Apply least privilege so contributors are not administrators. Disable file editing in the dashboard. Confirm backups actually run and that you have tested a restore.

Write down what happened

A short written record of what was found, what was removed, what the entry point was and what changed afterwards is worth more than it sounds. It is what lets you answer the client or the payment processor, and it is what makes the next review faster.

Add an edge layer once the application is clean

With the site clean and hardened, edge controls reduce how much hostile traffic reaches the application at all. Rate limiting on wp-login.php and xmlrpc.php, WAF rules matched to your real endpoints, and bot controls tuned to your traffic all cut the volume of automated attempts significantly. Start with the Cloudflare WAF setup guide and the bot protection guide. Edge protection does not replace application security, it just means far fewer attempts get to try.

When to bring in help

Signs the cleanup is beyond a plugin scan

Handle it yourself when the infection is recent, the entry point is obvious, you have a clean backup and the site is not handling payments or sensitive data. Bring in a specialist when any of the following are true:

  • The site has been reinfected after a previous cleanup.
  • Multiple sites on the same hosting account are affected.
  • The site is flagged by Google Safe Browsing or blocklisted by a security vendor.
  • Customer data, payments or login credentials may have been exposed.
  • There is no reliable backup from before the compromise.
  • You cannot determine when or how the compromise started.

The cost of a second failed cleanup is usually higher than doing the first one properly, because by then the site has also lost rankings and, on an ecommerce store, orders.

Get this implemented

WordPress cleanup and protection services

If the site is live and infected, the sequence below matters more than the tooling. These are the engagements that cover it end to end.

WordPress Malware Removal

Full incident handling for hacked sites: containment, investigation, cleanup, verification and a written report of what was found.

Explore this service →

Security Hardening

Close the access paths that allowed the compromise so the cleanup holds. Accounts, file permissions, configuration and plugin exposure.

Explore this service →

Managed Security

Ongoing monitoring, updates and response for businesses that do not want to notice the next infection from a customer email.

Explore this service →
Frequently asked questions

WordPress malware removal questions

How long does WordPress malware removal take?

A straightforward single-site infection with clean backups is usually resolved within a day. Sites with no backups, multiple infected installs on one hosting account, or a compromise that has been running for months take longer, because the investigation has to establish how far the attacker moved before anything is deleted.

Can I just restore a backup instead?

Only if you know the backup predates the compromise and the original entry point has been closed. Restoring to a point where the vulnerable plugin is still installed usually results in reinfection within days. A restore is a recovery step, not a security fix.

Will a security plugin remove the malware for me?

Plugin scanners are good at flagging known malicious signatures in files. They are much weaker at database injections, malicious administrator accounts, cron-based persistence and modified core files that still pass a checksum. They are a detection aid, not a cleanup process.

What is a pharma hack and why does it keep coming back?

A pharma hack injects hidden spam content, usually pharmaceutical keywords, that is served only to search engine crawlers. It recurs because the payload is typically stored in the database or a cron job rather than in an obvious file, so a file-only cleanup misses it entirely. See the section on persistence above.

Do I need to tell Google after the site is clean?

If Search Console shows a security issue or the site was flagged by Safe Browsing, request a review once the cleanup is verified. Requesting a review while the payload is still present usually results in a second, longer flag.

Do you work with hosting providers during a cleanup?

Yes. Some steps, including account level scans, server side log retrieval and shared hosting isolation, are faster through the host. Coordination usually shortens the investigation rather than complicating it.

Explore the Related Security Service

Use this guide alongside the relevant commercial service: security services, WordPress security, Cloudflare security, and click fraud prevention.

Direct help

Need this implemented on your website?

Talk directly with Xequent about WordPress security, Cloudflare protection or click-fraud controls.

Direct Expert Contact

Speak directly with Rana Shahwaiz Aslam

Xequent is operated by Rana Shahwaiz Aslam. The current professional profile shows 100% Job Success, Top Rated Plus, 37 jobs, and 851 hours on Upwork, with pricing scoped to the engagement rather than an open-ended hourly meter. Rana's profile title identifies him as CEH Certified and focused on managed Cloudflare security and cybersecurity.

WhatsApp RanaEmail