Ortica
Let’s talk ↗

· 7 min read

Hacked website: what to do first, how to clean it, how to stop it happening again

If your website has been hacked, don’t delete anything, change your passwords and save a copy of the site as it is now. Then you need to find the hole the attack came through, because removing the malware without closing it means getting hacked again before long.

In short: if your website has been hacked, the first thing is don’t delete anything. Change the WordPress, hosting and FTP passwords, save a copy of the site as it is now and tell whoever manages it. Then you need to work out how the attack got in: removing the malware without closing the hole is the surest way to get hacked again a few days later.

We’re writing this as people who look after more than 200 sites. The examples are from WordPress, but the reasoning applies to any site.

How can I tell if my website has been hacked?

A hacked site doesn’t always show it on the home page. Attackers usually want to use it without being noticed: to send visitors elsewhere, publish spam pages or send emails. The most common signs:

  • strange redirects: people coming from Google end up on betting, pharmacy or fake prize sites, while you, typing the address in yourself, see the normal site;
  • pages in languages you don’t have in Google’s results (search “site:yourdomain.com” and see what comes up);
  • the browser warning “Deceptive site ahead” or “The site ahead contains malware”;
  • an email from Google Search Console reporting security issues;
  • your hosting suspending the site or blocking outgoing email because of suspicious traffic;
  • admin users you don’t recognise, plugins you didn’t install, files with odd names in the site’s folder.

One of these signs is enough to treat the site as compromised until proven otherwise.

What to do in the first few hours

The first moves decide how easy the clean-up will be. In this order:

  • Change the passwords: WordPress admins, hosting control panel, FTP or SFTP, the database if you can. If you use the same password anywhere else, change that too.
  • Save a copy of the site as it is now, files and database, even though it’s infected. It’s for working out what happened, not for putting back online.
  • Check your backups: how many you have, how old they are, where they’re stored. A backup kept on the same server may be infected too.
  • Tell your hosting provider: they’ve often already seen something in the logs and can tell you whether other sites on the same account are affected.
  • Open Google Search Console and look at the Security issues report: it shows what Google has found and on which pages.

If the site sells online, consider putting it into maintenance mode while the work is done: better a day offline than customers sent to a scam site.

What not to do

Avoid

Why

Deleting files at random

You lose the traces that show how the attack got in

Just reinstalling WordPress

The malicious code often sits in the database and the uploads folder, and the hole stays open

Restoring the latest backup without checking it

If the attack is old, the backup may be infected too

Installing five security plugins at once

It slows the site down and complicates the diagnosis, without removing anything

Asking Google for a review straight away

If the clean-up isn’t complete the request is rejected, and you start again

How to remove malware from a WordPress site

A proper clean-up has four steps, and the first is the most important.

1. Analysis

It starts from the copy of the site: a scan of the files and the database, a comparison of the WordPress core, themes and plugins with the original versions, a check of the users and the server logs. The goal is to find the way in: usually an old plugin with a known vulnerability, a weak or stolen password, or another hacked site on the same hosting.

2. Clean-up

We remove the files added by the attack, the code injected into existing files and the code hidden in the database (in options, posts, users). Core, theme and plugins are put back from the original sources rather than patched by hand. If there’s a clean backup from before the attack, we consider starting again from there and recovering the content and orders that came in afterwards separately.

3. Closing the hole

The vulnerable plugin is updated or replaced, passwords and WordPress security keys are changed again, unnecessary accounts are removed, file permissions and the PHP version are put right. Without this step the clean-up doesn’t last.

4. Google and the hosting provider

Once the site is clean, you ask Google to review it from Search Console with the Request review button, explaining what was found and what was done. Google itself says the review can take from a few days to a few weeks; once it passes, the “dangerous site” warning disappears. Spam pages left in the results are removed separately. If the hosting provider had suspended the site or its email, you show them the problem is solved.

It isn’t always possible to recover everything. A badly compromised site, with no backups and a theme edited by hand over the years, is sometimes better rebuilt from its content. You find that out after the analysis, not before.

How to stop it happening again

Most of the sites we see hacked twice have the same problem: they were cleaned, but nobody looked after them afterwards. The things that really matter are few:

  • regular updates to WordPress, themes and plugins, tested first on a copy of the site (staging);
  • fewer plugins, and only maintained ones: an abandoned plugin is a door left open;
  • unique passwords and two-factor authentication for everyone who runs the site;
  • a system that blocks intrusion attempts before they reach WordPress;
  • automatic backups stored off the server, with tested restores: they’re what lets you go back to before the attack;
  • monitoring with alerts if the site changes or goes down.

It’s the work we describe in the note on WordPress support and that we do with WordPress maintenance.

What to ask whoever cleans up your site

  • Will you tell me how the attack got in, or just what you removed?
  • Have you closed the hole, or only cleaned the files?
  • Have you also checked the database and the other sites on the same hosting?
  • Who requests the review from Google, and who follows up on the answer?
  • Will you tell me the price before you start, after looking at the site?

With us it works like this: first an analysis, then we tell you what we found and what the clean-up costs, before we begin. If we already look after the site under a maintenance plan, malware that’s easy to spot is removed as part of the plan; complex cases, or sites we don’t look after, are quoted separately. The details are on the page about the hacked WordPress site.

Ortica is two people, Riccardo and Davide, working on the web since 2016: the person who answers is the person doing the work, with no middlemen.

FAQ

The questions
people ask us.

My website has been hacked: should I take it offline?

If it’s sending visitors to other sites or collecting data, yes: a maintenance page is better than customers landing on a scam. Before you take it down, though, save a copy of the files and database as they were, because you need them to work out what happened.

Is a security plugin enough to remove the malware?

Usually not. A scanner finds the best-known suspicious files, but it often misses code in the database and doesn’t close the hole the attack came through. It’s useful as a tool, not as a complete clean-up.

Why was my site hacked if I didn’t do anything?

Usually that’s exactly why. Attacks are almost always automated: programs that scan the web for sites with an old plugin or a weak password. You don’t need to be an interesting target, just behind on your updates.

How long does Google take to remove the “dangerous site” warning?

After you request a review from Search Console, Google says anything from a few days to a few weeks. Only make the request once the clean-up is complete: if Google still finds problems it rejects it, and you have to start again.

Can I just restore a backup and be done with it?

Only if the backup is from before the attack and stored off the server. Even then the hole has to be closed, or the restored site will be hacked again the same way. Orders and content that came in after the backup have to be recovered separately.

Notes

Want to talk it over?
Write to us.

Tell us what you need: you’ll hear back from us, with a written quote if it makes sense.

Let’s talk