Maximus Agency Start a project
Securing Your WordPress: A Step-by-Step Guide to Recovery and Hardening After a Hack
← Insights

Security

Securing Your WordPress: A Step-by-Step Guide to Recovery and Hardening After a Hack

04 Sep 2024 · Grant Brits

Checksums, wp-cli, core reinstalls, permissions, Fail2Ban, Cloudflare, and Wordfence: the practical recovery path after a WordPress compromise.

WordPress can be one of the trickiest things to host if you do it yourself and own the security pitfalls. Cloudflare helps with DDoS, geo blocks, and behavioural throttling, but what do you do when you find out you have already been hacked?

Here is the recovery path that worked for us.

File integrity: the WordPress core

Checksums tell you whether core files are intact. With WP-CLI on the server, you can verify every site in a loop. Intrusive files that should not exist get deleted. Modified core files get replaced with a clean download:

wp core download --skip-content --force

--skip-content keeps themes, plugins, and wp-config.php alone. --force overwrites compromised core files.

Final checks

  • Run wp user list and remove any unexpected admin users.
  • Rotate database passwords and update wp-config.php.
  • Optionally regenerate WordPress salts.
  • Fix permissions:
find . -type d -exec chmod 755 {} \; && find . -type f -exec chmod 644 {} \; && chmod 600 wp-config.php

Lock the doors

Install Wordfence (or equivalent). Use Fail2Ban, iptables, and Cloudflare. Add reCAPTCHA to login and forms. Update plugins and themes. Delete unused themes and deactivated plugins; idle code is still executable.

If you use Nginx, deny PHP execution under uploads:

location ~* /wp-content/uploads/ {
    location ~ \.php$ {
        deny all;
    }
}

Then go spend time with your family. The internet sucks, but a hardened box sucks less.

Enquire

Got a similar problem?

Forms land in our admin the same day, and we get an email. Cat and Grant read them. No ticket queue.