We Cleaned Up a Hacked WordPress Site and It Got Hacked Again

We cleaned up a hacked WordPress site recently and a little while later it got hacked again. Same site, same attacker, and this time they didn’t need to break anything. They just logged in.

If your site is hacked right now, our emergency WordPress repair team can lock it down today.

We’d done the things you’re supposed to do. We restored the site from a backup, cleaned out the injected code, and reset every user password. So when the attacker showed up again, logged in as a real user, our first thought was that we’d missed a backdoor somewhere in the files.

We hadn’t. The problem was sitting right in the root of the site. The wp-config.php file was dated July, months before the hack and months before our restore.

Why an Old wp-config.php Is Such a Big Deal

The restore had put back the site’s files and database, but it left the existing wp-config.php untouched. That file holds two things an attacker loves. The database password, and the security keys and salts WordPress uses to sign login cookies.

If someone gets a copy of those keys during the first hack, resetting passwords doesn’t lock them out. With the salts in hand they can forge a valid login cookie for any user and walk right in without ever knowing a password. That’s exactly what happened here. Every password was new, and none of it mattered, because the keys that actually controlled the sessions were the same ones the attacker had already stolen.

So here’s the full list of what we do now after a hack, in order. We use wp-cli for most of it because it’s faster and it works the same on every server. If you haven’t tried wp-cli yet, you really should.

1. Back Up the Hacked State First

Before you change a single thing, take a backup of the site exactly as it is. It feels backwards to back up a broken site, but that copy is your evidence. If you need to figure out how they got in later, you’ll want the files and database as the attacker left them.

We make a backup and download it to our shared drive. If you don’t have a backup service, wp-cli and tar will do the job.

wp db export ../hacked-$(date +%F).sql
tar -czf ../hacked-files-$(date +%F).tar.gz .

Store those somewhere off the server. Don’t leave them in a public folder.

2. Reset Every User Password

Every user, not just the admins. wp-cli can reset all of them in one line.

wp user reset-password $(wp user list --field=ID)

By default that emails each user a reset link. If you’d rather tell people yourself first, add --skip-email and reach out to them directly. Either way, plan on telling your users what happened.

3. Change the Database Password

If the attacker read wp-config.php, they have your database password. Change it in MySQL, then update wp-config.php to match.

wp db query "ALTER USER USER() IDENTIFIED BY 'a-long-new-password';"
wp config set DB_PASSWORD 'a-long-new-password'

The site will throw a database connection error for the few seconds between those two commands. That’s normal. Some hosts (SpinupWP is one) don’t show you the database credentials in their dashboard, so you may need to do this from the command line or through your host’s support.

4. Rotate the Salts and Security Keys

This is the step that would have saved us. New salts invalidate every existing login cookie on the site, including any the attacker forged. Everyone gets logged out, attacker included.

wp config shuffle-salts

No wp-cli? Grab a fresh set from the WordPress.org secret-key generator and paste them over the eight define() lines in wp-config.php.

5. Check the wp-config.php Date After Any Restore

This one gets its own step because it’s the one we missed. Any time you restore a site from backup, look at the modified date on wp-config.php.

ls -l wp-config.php

If that date is older than the hack, the restore didn’t touch it, and the old keys and database password are still live. Do steps 3 and 4 again after the restore, even if you already did them before. Restores put old files back. That’s their whole job.

6. Audit Admin Users on Every Site on That Server

Start with the hacked site, then keep going. If other sites live on the same server, assume the attacker had a look around.

wp user list --role=administrator --fields=ID,user_login,user_email,user_registered

For a server with a bunch of sites, loop through them. On a SpinupWP server each site lives in /sites/example.com/files, so this works.

for site in /sites/*/files; do
  echo "== $site"
  wp --path="$site" user list --role=administrator --fields=user_login,user_email,user_registered
done

When we did this for a client with about a dozen sites on one server, we didn’t find a malicious admin, but we did find a user literally named “temp” and a pile of old support logins from former vendors. Those are exactly the accounts nobody watches. Delete what nobody can explain.

7. Delete Unused and Ancient Plugins

Old plugins are the most common front door. On the site in our story, the server logs kept pointing at Revolution Slider (Rev Slider), a plugin that hadn’t been updated in years. We cut the site down to 11 plugins and got rid of it.

wp plugin list --fields=name,status,version,update
wp plugin list --status=inactive --field=name
wp plugin delete revslider

Deactivating isn’t enough. An inactive plugin’s files are still on the server and can still be exploited, so delete anything you aren’t using. While you’re in there, check the versions you’re running against the public vulnerability databases from Wordfence or Patchstack.

You can also check that WordPress core and any plugin from the WordPress.org directory match their official files.

wp core verify-checksums
wp plugin verify-checksums --all

8. Look for Hidden Fake Plugins

Some malware installs itself as a plugin and then hides from the Plugins screen. We’ve seen a fake plugin left over from an old compromise sit quietly for months and then break logins out of nowhere.

Compare what’s actually in the plugins folder against what WordPress reports. Anything in the folder that isn’t in the list deserves a close look. Check must-use plugins too, since they load automatically and don’t show up with regular plugins.

ls wp-content/plugins
wp plugin list --field=name
ls -la wp-content/mu-plugins

Then read the error logs. Broken admin screens and JavaScript errors after a hack are often the injected code (or the old plugin it came in through) telling on itself.

9. Check Outbound Email After Rotating Keys

Rotating everything has side effects. On another hacked site we reset all the passwords and keys, and that included the SendGrid API key the site used for email. The password-reset emails to every user went nowhere, so those users had to reset their passwords manually.

After you rotate keys, update your mail plugin with the new API key and send yourself a test.

wp eval 'var_dump( wp_mail( "[email protected]", "Test", "Testing outbound email" ) );'

If that comes back false or the email never shows up, fix it before you send anyone a password reset.

10. Harden So It Doesn’t Happen Again

Once the site is clean, put some walls up. We run every site we manage behind Cloudflare and keep nightly malware scans running, so a new infection gets caught the next morning instead of weeks later. We also turn off the built-in theme and plugin file editor, which is one less thing an attacker can use once they’re in.

wp config set DISALLOW_FILE_EDIT true --raw

Last, keep plugins updated and put every login for the site in a password manager. During our admin audit we found several sites with no login stored anywhere, and that slows you down at exactly the moment you need to move fast.

The Short Version

A restore fixes the files. It doesn’t fix the secrets. If an attacker had your salts and database password before the restore, they still have them after it, so rotate both and then check the date on wp-config.php to make sure they stuck.

If you’re still deciding whether your site can be cleaned up at all, start with our post on choosing between a cleanup and a full rebuild. And if you’d rather not do any of this yourself, it’s part of what our $125/month maintenance plan covers (backups, nightly malware scans, and a real person reviewing updates).

Change the passwords. Then change the keys.

FAQs

Why did my WordPress site get hacked again after a cleanup?

The most common reasons are a backdoor that got missed, an old plugin that’s still installed, or secrets that never changed. If the attacker copied your security keys and database password the first time, resetting user passwords won’t keep them out. Rotate the salts and the database password too.

Does restoring from a backup replace wp-config.php?

Not always. Many restores leave the existing wp-config.php in place, which means the old keys and database password stay live. Check the file’s modified date after any restore.

How do I change the WordPress salts?

Run wp config shuffle-salts with wp-cli, or generate a new set at the WordPress.org secret-key generator and paste them into wp-config.php. Everyone will be logged out, which is the point.

Is deactivating an old plugin enough?

No. A deactivated plugin’s files are still on the server and can still be exploited. Delete plugins you don’t use, especially old ones like Rev Slider.

Will changing the WordPress salts log everyone out?

Yes, including the attacker.