Hacked Website: What to Do in the First 24 Hours
You can tell a hacked website by the things it does that nobody set it up to do. It redirects visitors to unrelated sites, Google warns about it, or the host has suspended the account for sending spam. Sometimes the only sign is a new administrator or a file nobody knows about.
In security I keep threat, vulnerability and risk apart. An outdated site or a weak password is a vulnerability. A security incident happens when it gets exploited.
And once it has happened, the worst thing to do is to start deleting right away.
You delete the suspicious file, restore a backup and the attacker comes back. Not because the cleanup did not work, but because the way in stayed open.
A hacked website is not a disgrace. It is an incident that needs a systematic process.
This is how I handle the first 24 hours.
1. Preserve the evidence
Before I delete or update anything, I make a copy of the compromised system. Ideally a snapshot of the whole server, or at least the files and the database. The access and system logs matter most.
Hosts often keep them only for a limited time. They may hold the answer to how the attacker got in.
I also record when the incident was discovered, the current state of the site and the changes made. Where possible, I keep the original file timestamps and record checksums of the important artefacts.
The copy is for analysis and serves as evidence. It is not a backup to restore the site from. I keep it separately, with restricted access, and work with it in an isolated environment where possible.
2. Isolate the site and replace the credentials
We isolate the site from the internet, or at least block its public traffic at the server, reverse proxy or hosting level.
CMS maintenance mode is not enough. An uploaded PHP file can still be reached directly by its URL, and malicious code can run outside the CMS itself.
If the site cannot be taken offline completely, I limit traffic to the bare minimum. The priority is to stop further damage: spam, data leaks and communication with the attacker.
Then I change the credentials the attacker could have reached:
- administrator and hosting accounts,
- FTP, SFTP and SSH,
- the database password,
- API keys and tokens,
- active logins and sessions,
- SSH keys in
authorized_keys, - credentials for SMTP, cloud services and deployment,
- WordPress salts or Drupal
hash_salt.
I change them from a computer I know is clean. If the attacker compromised the administrator’s laptop, they can get the new password from it again.
I don’t forget other sites and services that use the same credentials either. One compromised site must not be the gateway to the others.
3. Find out how the attacker got in
Without this, any cleanup is only temporary.
The first thing I check is updates. Outdated core, plugins, modules, libraries or other software can contain a known vulnerability the attacker exploited.
Automated scanning and attacks run at a large scale today. A bot goes through a site, detects the CMS and its version, and then tries known vulnerabilities. The attacker often did not pick your site at all. It just matched a filter.
Automated attacks are not new. AI can, however, speed up parts of the reconnaissance and preparation further.
Then I look at the logs:
- suspicious POST requests,
- logins from unusual IP addresses,
- attempts to reach administration interfaces,
- file uploads,
- requests for non-existent or suspicious PHP files,
- changes of permissions and new accounts.
I also check the CMS users, the database and changed files.
A site in Git makes this much easier. git status and git diff show changes to tracked files and new files that are not ignored. They don’t reveal everything, though. Files in .gitignore, such as uploaded files, I have to go through separately.
On WordPress I use WP-CLI:
wp core verify-checksums
wp plugin verify-checksums --all
The first command checks the core files against the official checksums. The second checks plugins whose checksums are available in the WordPress.org directory.
Custom plugins, some commercial plugins, themes, mu-plugins, configuration and uploaded files, for example, stay unverified.
On Drupal I compare core, modules and libraries with a clean Composer install and the custom code in Git. I check security advisories, for example, with:
composer audit
With older versions of Drush, drush pm:security can be used too.
I want to know two things: how the attacker got in, and when.
The date of the breach decides which backup can be used at all. A backup taken after the compromise may contain the malware and the back doors.
4. Security scan with an AI agent
Once I know the rough extent of the incident, I also have the site go through a security audit against OWASP ASVS .
It is not only about looking for malware. I want to find out whether the site has other vulnerabilities the attacker could use again.
I use an AI agent with access to the source code and the security documentation. Claude Code with the Security skill helps me go through the application systematically, checking configuration, authentication, authorisation, input handling and other security areas.
OWASP ASVS serves as the checklist. The agent goes through the relevant requirements and looks for implementations that are insufficient or missing. The result is a list of suspicions and recommendations to verify, not an automatic confirmation that the site is secure.
The AI agent can, for example, reveal:
- missing permission checks,
- unsafe handling of user input,
- suspicious changes in PHP code,
- weak configuration of security headers,
- insufficient protection of administration functions,
- potential SQL injection or XSS.
I then verify the findings by hand and, where needed, with tests. AI can miss a problem, but it can also flag safe code as vulnerable.
The goal is not to let AI fix the site automatically. The goal is to get a systematic overview of the security state and to verify that no other open way in is left after the malware is removed.
5. Clean the site up from the source
The attacker may have left several back doors. A PHP file among the images, a modified core file, a scheduled task, malicious JavaScript in the database or another administrator account.
That is why I don’t delete file by file, and I don’t consider an antivirus scan a complete solution.
I redeploy core, modules and themes from official sources. I restore the custom code from Git. All of it ideally into an empty directory, not over the original installation, where unknown files can stay behind.
Separately, I go through:
- the uploaded files and what they really contain,
- the database and stored JavaScript,
- cron and other scheduled tasks,
.htaccessand.user.ini,- the server and PHP configuration,
- SSH keys and other access,
- accounts and permissions in the CMS.
I use a backup only when I am sufficiently sure it was made before the breach and contains no compromised code.
If I don’t know the extent of the incident or suspect the whole server is compromised, I restore the system from a clean image. Cleaning the web files alone is not enough in that case.
6. Close the hole and restore operation safely
Before the site goes live, I update core and extensions. I remove unused plugins, modules, themes and old accounts.
I turn on MFA for administrators and set the permissions so the site cannot write to its own code. It should write only to the directories where it really needs to, typically the storage for uploaded files.
I also check that the sites on the server are separated. If they share a system user and have access to the same files, compromising one site can endanger all the others.
I change the passwords, keys and tokens from step 2 once more. The attacker could have obtained the new ones from the configuration as well, for example from settings.php or wp-config.php.
Only then do I make the site available again.
In the following days I watch the logs, new files, administrator accounts and unusual requests. Restoring operation is not the end of the incident. It is the start of verifying that the attacker does not come back.
What runs in parallel
If Google flagged the site as dangerous, the warning does not go away on its own.
After the cleanup, I check the status in Google Search Console and request a review if needed. Google has to verify again that the site no longer contains harmful content.
Personal data
If the attacker could have reached customers’ personal data, it has to be assessed whether there was a personal data breach under the GDPR.
The controller has to report the breach to the data protection authority without undue delay and, where feasible, within 72 hours of becoming aware of it. The exception is when the breach is unlikely to result in a risk to the rights and freedoms of natural persons.
If the risk is high, the people concerned have to be informed as well.
The deadline runs from discovering the incident, not from finishing the cleanup. The technical work and the assessment of the GDPR obligations therefore have to run in parallel.
Hosting
If the host blocked the site, I inform them about the incident and the measures taken.
I also ask for their logs. They can contain information that is not available on the site itself, such as records of network traffic, logins or actions of security systems.
Zero trust
My rule is that when someone hacks one website, it has to end there. It must not be a way into other sites on the same server.
For that I need separate accounts and permissions, code in Git, backups off the server, logs that last longer than a few days, and continuous updates.
Then the attacker’s way in can be established from data, not guessed.
I like breaking things in a test environment. That is how I know what they look like when they break for real.
Faith has no place in IT. Mechanisms do.
How I check security against OWASP ASVS is described in the Security skill .
If your website has been hacked, write to me via the contact form , at info@ludekkvapil.cz , in the chat on this site, on Messenger or on LinkedIn .