Most hacked WordPress sites we see in Sri Lanka were not targeted. A bot found an old plugin or a weak password and used it, along with thousands of other sites that week. That is good news: the way in is usually ordinary, and so is the fix. The order matters, though. Clean first and close the hole later, and you will be doing it all again next week.
Signs your site has been hacked
- Google shows “This site may be hacked” under your listing, or Chrome shows a red warning page.
- Mobile visitors, or visitors from Google, are sent to a casino, pharmacy or “you won a prize” page, while you see your normal site.
- Search results for your domain show pages you never wrote, often in Japanese or full of product names.
- Your host emails you about spam, high CPU use or “malicious files”, or suspends the account.
- New admin users appear in WordPress, or you can no longer log in.
1. Take a full copy before you touch anything
Copy every file and export the database, exactly as they are. You will need them to work out how the attacker got in, and to rescue content if something goes wrong during the cleanup. Store the copy off the server.
2. Lock the attacker out
Change these passwords, from a device you trust:
- your hosting control panel and SFTP or SSH accounts;
- the database user (then update
wp-config.phpto match); - every WordPress administrator;
- the email accounts tied to the hosting and the domain.
Then generate new WordPress salts in wp-config.php. That logs out everyone, including the attacker’s stolen sessions. Delete any admin users you do not recognise, but note their usernames and creation dates first.
3. Find out how they got in
Look for the cause before you remove the symptoms. The usual suspects:
- An outdated plugin or theme with a known vulnerability. Compare versions against the plugin’s changelog.
- A “nulled” (pirated) theme or plugin, which often ships with a backdoor already inside.
- A reused or weak admin password, which shows up as many failed logins followed by a success in the access logs.
- Another site on the same hosting account, which can infect every site next to it.
The web server’s access logs around the time the first infected file appeared usually tell the story.
4. Remove every trace
- Replace WordPress core with a fresh copy of the same version. Do not try to clean core files by hand.
- Reinstall every plugin and theme from the official source, rather than cleaning the old copies.
- Search
wp-content/uploadsfor PHP files. Uploads should contain images and documents, almost never PHP. - Check the database for injected scripts in posts, widgets and the
wp_optionstable, and for unknown entries inwp_users. - Check
.htaccessfiles and scheduled tasks (cron jobs) for redirects and re-infection scripts.
Tools such as WP-CLI’s wp core verify-checksums, ClamAV or Linux Malware Detect help, but none of them catch everything. Trust the fresh copies more than any scanner.
5. Close the hole and harden the site
Update everything, remove plugins you do not use, turn off file editing in the dashboard (DISALLOW_FILE_EDIT), and add two-factor login for administrators. If the cause was another site on the same account, that site needs cleaning too.
6. Clear the warnings
Once the site is clean, request a review in Google Search Console under Security issues, and check blacklists such as Google Safe Browsing. Google’s review usually takes a few days. If your host suspended the account, send them what you found and fixed.
7. Watch it afterwards
Set up file change monitoring and uptime checks, and keep automatic backups that are stored away from the server. The first two weeks after a cleanup are when a missed backdoor shows itself.
When to call for help
If the site keeps getting reinfected, handles payments or customer data, or you simply cannot afford a week offline, bring in someone who does this every week. A reinfection after a half-done cleanup costs more than doing it properly once.