What to Do When Your Website Is Hacked
Follow a calm order of steps to contain a break-in, preserve evidence, clean or rebuild your site, notify the right people and close the hole.
Key takeaways
- Take the site offline or into maintenance mode if visitors could be harmed while you investigate.
- Preserve files, database and logs before cleaning, because they show what happened and may be needed later.
- Change passwords, keys and sessions from a device you trust, starting with the accounts that control everything else.
- Rebuilding from clean sources and a known-good backup is more reliable than hunting for every planted file.
- Find and close the entry point, check legal notification duties and request review of any search or browser warnings.
If your website has been hacked, limit the damage first, save a copy of what happened, change credentials from a clean device, then rebuild from trusted sources and fix the weakness that let the attacker in. Deleting the odd file you noticed and carrying on usually leaves a way back.
You may need help. If the site handles payments or sensitive personal data, or you can't tell how far the intrusion went, contact your host and an experienced incident response professional early.
Recognize the signs
Compromises don't always deface the home page. Many aim to stay hidden. Watch for:
- Redirects to unrelated sites, sometimes only for visitors on phones or arriving from search.
- Pages, links or search listings about products you never sell.
- Unknown administrator accounts, plugins, scheduled tasks or files.
- Browser or search engine warnings that the site is unsafe.
- Your host suspending the account for sending spam or serving malware.
- Customers reporting card fraud after buying from you.
- Unexplained spikes in outgoing traffic, email or processor use.
Confirm with a second look from another device or network. A single visitor's redirect can come from malware or an extension on their own computer.
Understand what the attacker may want
The purpose of an intrusion shapes what you need to check. Many are automated: a script found a known weakness and added the site to a large collection of compromised machines. Common uses include sending spam, hosting phishing pages, injecting hidden links to boost other sites, redirecting visitors, mining cryptocurrency and stealing card or login details typed into forms.
You may see only one of these while others run quietly. A site with spam pages may also have a stolen database. Assume the attacker could read anything the website itself could read, including configuration files, stored credentials and customer records, until evidence shows otherwise.
That assumption tells you how wide to cast your reset. A mail password saved in a configuration file should be changed even if you see no sign of mail abuse. So should API keys for payments, storage or marketing tools. Check those outside services for activity you don't recognize, such as new users, new payout details or unusual sending volume.
If several sites share one hosting account, treat all of them as suspect. Malware that reaches one folder can often write to its neighbors, and cleaning a single site leaves the others to reinfect it.
Contain the damage
Decide quickly whether visitors are at risk. If the site serves malware, collects payment or sign-in details or redirects people, take it offline or restrict access to your own address. A static maintenance page, ideally served from somewhere separate with a 503 status, is enough.
Tell your host. They can often see activity you can't, may have clean snapshots and need to know if other systems are affected. Pause scheduled mail and any integration that could spread the problem. If card data may be involved, contact your payment provider promptly; your agreement likely requires it.
Avoid wiping or reinstalling in a panic. You would destroy the evidence of how it happened.
Preserve evidence
Copy the current files, database and configuration, and export web server, application, sign-in and hosting control panel logs before they rotate away. Take snapshots if your platform allows. Store these separately, label them as compromised and don't run them.
Start a timeline: when you noticed, what you saw, each action and who did it. If you later involve law enforcement, an insurer or a regulator, this record saves reconstruction from memory.
Take back control of accounts
Use a computer you have reason to trust, since infostealing malware on an administrator's machine is one way site credentials get stolen. Work roughly from the top down:
- Email accounts that can reset other passwords.
- Domain registrar and DNS provider. Check that records and contacts are unchanged.
- Hosting control panel, SSH and file transfer accounts. Remove unknown SSH keys.
- Website administrator accounts. Delete ones nobody can explain.
- Database passwords, API keys, mail credentials and application secret keys.
End all active sessions, turn on multi-factor authentication and give each person a unique password. If user password hashes may have been taken, require resets and warn users not to reuse the old password elsewhere.
If you suspect the domain itself was taken over, see domain hijacking and prevention.
Find out what happened
Look for the earliest sign. File modification times can help, though attackers can alter them. Compare your files with fresh copies of the same software versions or with version control. Search logs around the earliest change for unusual POST requests, successful sign-ins from unfamiliar places and requests to odd file names; reading server logs covers the basics.
The common entry points are unpatched software, abandoned plugins or themes, reused or stolen passwords, flaws in custom code and a compromised computer or third-party script.
Clean or rebuild
Rebuilding is the safer choice. Provision a clean environment, install current supported versions of the server software and content system from official sources, and add only the plugins and themes you need, downloaded fresh.
Then bring back your data. Choose a backup from before the first sign of intrusion, remembering that the compromise may be older than it looks. Inspect the database for unknown users, injected scripts and altered settings. Review uploaded files and make sure the upload folder cannot execute code. If you must recover newer content from the compromised copy, move it selectively and inspect it.
If rebuilding isn't possible right away, a reputable malware cleanup service can help. Treat any in-place cleanup as provisional and watch closely. If attackers had administrator access to the server itself, rebuild the server.
When you can't find the cause
Sometimes logs are missing or too short to show how the break-in happened. In that case, close every plausible route. Rebuild on a clean environment, update everything, remove each component you can do without, reset all credentials and require multi-factor authentication wherever it is offered.
Check the computers and phones used to manage the site for malware, and review who has access, including past contractors and connected applications. Then lengthen your log retention and add file change alerts, so that if the problem returns you can see how.
Working with help
Your host's support team can often confirm what they detected, share logs and restore snapshots, though cleaning your application is usually outside basic plans. A security firm or experienced developer can go further. Before hiring, ask what they will deliver: a description of the entry point, a list of changes made, and any monitoring or guarantee period.
Grant access through new, separate accounts and remove them when the work ends. Be careful about who you let in during a crisis, and verify that anyone contacting you really is who they claim to be, using contact details you look up yourself.
If you have cyber insurance, read the policy early. Some require prompt notice or the use of approved responders.
Close the hole before reopening
Apply updates, remove unused software, correct file permissions and fix any vulnerable custom code. Limit administrative interfaces to known addresses where practical. Consider a web application firewall as an extra layer, not a substitute for patching.
Test on a private copy first, then reopen and verify forms, sign-in and checkout. For stores, check payment pages for unfamiliar scripts, the technique described in card skimming on websites.
Clear warnings and tell people
If search engines or browsers flag your site, sign in to the webmaster tools, read the security issues listed and request a review after cleanup. Review timing varies. Check whether your domain or server address landed on email blocklists and follow each list's removal process.
Notification duties depend on where you and your users are, what data was exposed and your contracts. Many places have breach notification laws with deadlines, and card payments carry their own obligations. Get legal advice quickly if personal or payment data may be involved.
When you tell customers, say what happened, what information was affected, what you've done and what they should do. Don't speculate or promise more certainty than you have.
Watch and learn
For several weeks, check logs, file changes, new accounts and outgoing mail more often than usual. A reappearance means something was missed.
Afterward, write down the cause and the changes that would have prevented or revealed it sooner. The usual list is short: automatic updates, multi-factor authentication, off-site backups you've tested, file change monitoring and fewer plugins. Add them to your maintenance checklist so they outlast the memory of a bad week.
What not to do
Don't "hack back" or probe systems you suspect belong to the attacker; it can break laws and often hits another victim's machine. Be wary of unsolicited offers to fix your site that arrive right after an incident. And don't pay a demand on impulse: payment guarantees nothing, and may raise legal issues. Speak with professionals and law enforcement first.