Skip to content
Security and SSL6 min read

How to clean up a hacked website

Short answer

Change every password first, then restore a clean backup from before the infection; if you have none, replace core files and plugins with fresh copies and delete unknown files. Next, check admin users, cron jobs and .htaccess files for backdoors, update everything, scan again, and request a review in Google Search Console if your site was flagged.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Before you start
  2. Step by step
  3. Troubleshooting
  4. On ArabyHost

Typical signs of a hacked site: visitors from Google or on mobile are redirected to spam or gambling pages, unknown admin users appear, Google shows “This site may be hacked”, your host or a scanner reports malware, or your domain starts sending spam. Work through the steps in order. Cleaning files before changing passwords, or restoring a backup without closing the hole, usually means being hacked again within days.

Before you start

  • Access to cPanel, the CMS admin area, and your domain registrar.
  • A clean computer. Stolen FTP or cPanel passwords often come from malware on the site owner’s own PC, so run a full antivirus scan there first.
  • A few quiet hours, and if the site is a store, a note of recent orders or content that a restore might remove.

Step by step

1. Contain and keep a copy

Put the site into maintenance mode if you can. Download a copy of the infected site and database for later analysis and store it separately, clearly labelled. Never restore from this copy; it exists only to help you find how the attacker got in.

2. Change every password

Do this before anything else, otherwise the attacker simply logs back in:

  • cPanel, every FTP account, and every email account.
  • Database users. After changing the password in Databases » MySQL Databases, update DB_PASSWORD in wp-config.php or your app’s .env.
  • All CMS administrators, and the domain registrar.
  • API keys and tokens stored in your code or .env files.

On WordPress, also invalidate all existing logins by replacing the security keys (salts) in wp-config.php. Over SSH: wp config shuffle-salts.

3. Restore a clean backup (the quicker route)

Work out roughly when the infection started, then restore from a date before it. In cPanel, open JetBackup, choose a backup from before that date, and restore the home directory files and the databases. Anything added after that date (posts, orders, uploads) will be lost, so export it first and re-add it afterwards. The WordPress backup and restore guide walks through the screens. Then continue with steps 5 to 8: a restore removes the malware but not the weakness that let it in.

4. No clean backup? Replace files instead of patching them

Don’t try to edit infected files line by line. Replace everything that can be downloaded fresh. For WordPress, with WP-CLI:

wp core verify-checksums
wp plugin verify-checksums --all
wp core download --force --skip-content

The first two commands list core and plugin files that differ from the official versions; the third re-downloads WordPress core without touching wp-content. Reinstall every plugin and theme from its official source, and delete any you can’t get from one. What you keep (wp-config.php, the uploads folder, your own theme changes) must be reviewed by hand.

5. Hunt for backdoors

Attackers leave ways back in. Search for them over SSH:

# PHP files where only images should be
find ~/public_html/wp-content/uploads -type f -name "*.php"
# files modified in the last 7 days, newest first
find ~/public_html -type f -mtime -7 -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r
# common obfuscation patterns (review each hit; some are legitimate)
grep -rlE "eval\s*\(\s*(base64_decode|gzinflate|str_rot13)" --include=*.php ~/public_html

Without SSH, use Files » File Manager and sort folders by Last Modified. Then check each of these:

  • Users: in WordPress, Users » All Users, filtered by Administrator, or wp user list --role=administrator. Delete anyone you don’t recognise.
  • Cron jobs: Advanced » Cron Jobs in cPanel (or crontab -l), and WordPress scheduled events with wp cron event list. Remove commands that download or run unknown scripts.
  • .htaccess files in every folder: find ~/public_html -name ".htaccess". Look for redirects to unknown domains, rules that only apply to search-engine visitors, and auto_prepend_file. Check .user.ini and php.ini files for the same directive.
  • Database: in phpMyAdmin, search wp_options and wp_posts for <script and for domains you don’t know, and confirm siteurl and home are your own address.
  • Email: in Email » Forwarders, remove forwarders you didn’t create; attackers use them to read password-reset emails.
  • Other sites in the same account: an old install next to the main site can reinfect it. Clean them too, or delete them.

6. Close the hole

Update the CMS, all plugins and themes, and the PHP version. Delete anything you don’t use. To find the entry point, open Metrics » Raw Access, download the access log, and look for POST requests to odd files around the time the first malicious file appeared. Typical culprits: an outdated plugin, a reused password, or a pirated theme.

7. Scan again and keep watching

Run a new malware scan, compare against the previous results, and check the site from a private window and from a phone. Repeat the backdoor checks from step 5 for the next one or two weeks.

8. Remove Google’s warning

In Google Search Console open Security & Manual Actions » Security issues. Once the site is clean, tick that you’ve fixed the issues and click Request Review. If you haven’t set up Search Console yet, follow the Search Console setup guide.

Troubleshooting

  • Malware returns a few hours later: a backdoor or cron job was missed, or a password is still known to the attacker (check your own computer again).
  • The site breaks after replacing files: a plugin was reinstalled at a different version, or a custom file was overwritten. Check the error log and reinstall the matching version.
  • Only mobile or Google visitors are redirected: the injected code checks the browser and referrer. Reproduce it with curl -sI -A "Mozilla/5.0 (iPhone)" -e "https://www.google.com/" https://example.com/ and look at the location header.
  • You can’t find the source: restore the oldest backup that’s still clean, or bring in a security specialist rather than leaving a half-cleaned site online.

Once the site is clean, harden it with protect your site from hacking.

On ArabyHost

Imunify360 security runs on the servers and scans files for malware, and every account is isolated with CloudLinux CageFS, so an infection in one account can’t spread to other customers’ accounts. Inside your own account, though, all sites share the same files, which is why step 5 includes your other sites. Daily JetBackup backups mean you can usually take the quicker route: restore files and databases from a date before the infection in cPanel, opened with one click from the Araby Panel. The Araby AI assistant in the panel can read your error logs if something breaks during cleanup, and Arabic support is available if you need help choosing the right backup.

FAQ

Should I restore a backup or clean the site by hand?

Restoring a backup from before the infection is faster and more reliable, as long as you also close the hole the attacker used. Clean by hand only when no clean backup exists, or when restoring would lose too much recent content.

How do I find out when the site was infected?

Look at the modification dates of suspicious files, the first unusual requests in the access log, and when warnings or spam complaints started. Then pick a backup from a few days before the earliest sign.

Why did the hack come back after I cleaned it?

Usually a backdoor was missed, such as a PHP file in the uploads folder, a cron job or a hidden admin user, or the original hole (an outdated plugin or a leaked password) was never closed.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.