Skip to content

How to harden WordPress against reinfection after a hack

By William · · updated · 5 min read

How to harden WordPress against reinfection after a hack

You stop reinfection by closing the door the attacker used: force 2FA on every login, lock file permissions, block PHP execution in the uploads folder, cap login attempts, and keep a short allowlist of plugins. Do these before you restore the site, not after.

Isolate the site before you touch anything

Take the site offline with a maintenance page or a .htaccess deny so the backdoor stops running while you work. If you leave the site live, the attacker can re-inject code while you are cleaning.

Snapshot the current files and database so you can diff them against a clean copy later. Without this snapshot, you cannot prove what was added or changed.

Change every credential that was on the site: admin, FTP, database, hosting panel, and any API keys. A single unchanged password is enough for the attacker to return.

Note the exact redirect URL or warning text; it tells you which exploit family you are dealing with. For example, a redirect to a gambling domain often points to a specific plugin vulnerability, while a generic "this site may harm your computer" warning suggests a broader malware injection.

Find the backdoor, not just the malware

Diff every file in wp-content, wp-includes and the root against a fresh WordPress download of the same version. Any file that exists in your copy but not in the fresh download is suspect.

Search the database for injected URLs, base64 strings and unknown admin users in wp_options and wp_users. A new admin user you do not recognise is a direct backdoor.

Check for a rogue .php file in wp-content/uploads or a renamed .htaccess that re-enables PHP execution. These are common hiding spots for shells that scanners miss.

Lock the login and every account

Force two-factor authentication on every admin and editor account, not just your own. An editor account is enough to install a malicious plugin.

Illustration: Lock the login and every account

This blocks one of the most common reinfection paths.

Limit login attempts per IP per hour and log out of every other session. This slows down brute-force attacks and removes active sessions the attacker may still hold.

Cut the plugin and theme attack surface

Remove every plugin and theme you do not actively use. Inactive plugins do not execute code unless activated, but they still ship stale code that can be exploited if a vulnerability is disclosed and the plugin is later reactivated.

Keep a written allowlist of the plugins you run and check each one against the 78,000-plus available on WordPress.org [1] so you know what you are keeping. A short list is easier to audit than a long one.

Update core, themes and plugins to the latest version before you restore the site, not after. Restoring an old version puts the same vulnerability back in place.

If a plugin is no longer maintained, replace it with a maintained alternative or remove it. An unmaintained plugin will not receive security patches for newly disclosed vulnerabilities.

Harden the database and the server

WordPress runs on PHP with a MySQL or MariaDB database [1], so the database user should have the minimum privileges it needs, not root. A root database user can drop tables or read other databases on the same server.

Move the wp-config.php file above the web root or restrict access to it so the database password is not readable. If the file is readable, an attacker who finds it has your database credentials.

Enable automatic daily backups of files and database and store the copy off the server. A backup on the same server can be deleted or corrupted by the same attacker.

Turn on server-level logging for failed logins and file changes so the next intrusion is visible within hours, not days. Without logs, you may not notice a reinfection until customers report it.

Get Google to review and the host to unsuspend

Submit a reconsideration request in Search Console with a short note: what was injected, how it was removed, and what you changed to prevent it returning. Google needs to see that the issue is fixed, not just that the site is back online.

Ask the host to unsuspend only after the files are clean and the credentials are rotated; send them the diff so they can verify.

Check the site in a clean browser and in Google's Safe Browsing status before you tell customers it is back. A cached warning or a residual redirect will send customers away even if the site is clean.

If this happens, repeat the backdoor search from the beginning.

What this checklist does not cover

This guide does not test whether a specific scanner, host or plugin works on your stack; verify each tool on a staging copy first.

Illustration: What this checklist does not cover

It does not replace a forensic review if the hack involved customer data, payment details or a breach of a privacy obligation.

It does not cover the legal or notification steps that apply in your jurisdiction after a data breach.

The settings to change, in order

Step 1: isolate and snapshot. Step 2: find the backdoor. Step 3: rotate every credential. Step 4: force 2FA and lock permissions. Step 5: block PHP in uploads. Step 6: trim the plugin allowlist. Step 7: update core, themes and plugins. Step 8: harden the database user and wp-config. Step 9: set up off-server backups. Step 10: request the Google review and host unsuspension.

Print this list and tick each box before you restore the site; a skipped step is the step the next attacker uses.

Keep the list with the site's credentials so the next person who maintains it does the same ten steps. If you want a printable version with checkboxes and a credential log, see the WordPress Hack Recovery Guide pack.

Frequently asked questions

How do I stop a dropped shell from running in the uploads folder?

This blocks one of the most common reinfection paths.

How long should I monitor the site after fixing the hack?

If this happens, repeat the backdoor search from the beginning.

Sources

  1. WordPress – Wikipedia (en.wikipedia.org)

Related on this site

This article was drafted with AI assistance and checked before publication.

Free calculator: Website hack downtime cost calculator

The full guide: WordPress Hack Recovery Checklist

Free sample: WordPress Hack Recovery Checklist
Get the free sample now, and new guides by e-mail.