Website hacked again: why the hack comes back after cleanup
The site was cleaned and a few days later it redirects again or has a virus. The six most common reasons a hack comes back, and how to check each one.
If a site is hacked again after cleanup, it is almost always because the effects were removed and the cause was not. Most often a hidden backdoor was left on the server, not every password was changed, the hole they came in through is still open, or the infection comes from another site on the same hosting account. Below are six reasons, in the order worth checking them.
1. A backdoor was left
An intruder usually leaves several ways in: a PHP file in the images folder, a plugin in wp-content/mu-plugins, code appended to a file nobody looks at, or an administrator account. Removing the one file the scanner showed leaves the rest.
What to check:
- PHP files in
wp-content/uploads(a developer usesfind wp-content/uploads -name "*.php"), - the
wp-content/mu-pluginsfolder, - core and plugin files compared with the official release:
wp core verify-checksumsandwp plugin verify-checksums --all, - administrator accounts:
wp user list --role=administrator, because an account can be hidden in the dashboard.
2. Not all passwords and keys were changed
Changing the WordPress dashboard password is not enough. If the intruder knows the FTP, hosting or database password, they come back without logging in to WordPress. If they have a saved session, they do not need any password until you change the security keys in wp-config.php.
Change everything at once, from a computer you trust: hosting panel, FTP and SFTP, the database (and the entry in wp-config.php), all administrators, mailboxes on the domain. Then new keys with wp config shuffle-salts. Turn on two-step login wherever you can.
3. The hole is still open
If someone got in through an old version of a plugin and after cleanup that plugin is in the same version, the next automated attack will come in the same way, often within a few days. The same goes for restoring a backup: you restore the old hole as well.
Update WordPress, plugins and the theme right after cleanup. Remove plugins you do not use. If a plugin is no longer developed, look for a replacement. More in the article on outdated plugins.
4. An infected backup
An infection often sits on a site for weeks before anyone notices. A backup from yesterday or last week may already contain malicious code. After the restore everything looks fine, and a few days later the backdoor starts working.
To pick the right backup, a developer finds the date of the first change: from the dates of suspicious files and from the server logs. The backup has to be older than that.
5. Other sites on the same account
If one hosting account holds several sites, for example an old version, a test shop or a friend's site, malicious code from one can change the files of the others. You clean the main site and the infection comes back from the folder next to it.
Check all the sites on the account or move them to separate accounts. Delete old copies and test versions nobody uses.
6. A cron job or something outside the site
In the hosting panel check the cron jobs. A command that downloads a file from a foreign address every hour will recreate the infection after every cleanup. Less often the problem is outside the server: an infected computer from which someone logs in to the panel, or a stolen password saved in a browser.
How to check that it worked this time
Write down the cleanup date and watch the site for several weeks: whether files change, whether new accounts appear, whether site:yoursite.com in Google shows new foreign pages. A plugin that compares files with the official release and notifies you of changes does this for you. The free Ensomedia Security checks, among other things, changed WordPress, plugin and theme files, PHP in uploads and accounts with administrator rights, and sends notifications after a scheduled scan.
If the site was flagged by Google, request a review only when you are sure the infection is not coming back. Another rejection makes the whole matter longer. How to do it is described in the article on what to do when Google warns about your site.
Common questions
Will changing hosting help?
Only if you move a clean site. Moving infected files moves the backdoor too. It does help when the source was other sites on the old account.
Should I rebuild the site from scratch?
Sometimes that is the most sensible option, especially when the site is small and the infection has come back several times. The content is then moved by hand, without old files and without a copy of the database that nobody has reviewed.
If you would rather not do it yourself
The free website check works from the outside, with no password and no account, and shows what the site sends to visitors right now.
If the hack keeps coming back and you want someone to find the cause, order a hacked site fix. We remove malicious code, unknown accounts and redirects, update what let the intruder in and tell you what happened. From $99. We reply within 1 business day with the scope and the price, and you pay only after you accept.