Skip to main content
Legia

Cybersecurity

After a Website Is Hacked: Finding Backdoors and Making Sure the System Is Clean

Deleting the pages an attacker defaced does not mean the website is clean. This guide covers the order of recovery for servers and applications after a breach, from securing evidence to making sure no backdoor is left behind.

SEO and Content Specialist

8 min read Reviewed by Legia Cybersecurity Team

Silhouettes of people in a room of glowing blue dots of light

Short answer: recovery after a website is hacked follows an order: secure evidence and logs before changing anything, look for backdoors (web shells, new accounts, scheduled tasks, extra SSH keys), decide whether to rebuild or restore from a backup proven clean, close the entry point and change all credentials, then check again before going online and watch for signs the attacker is trying to return. Deleting the defaced pages alone is not enough.

A hacked website is usually noticed from visible symptoms: the home page changes, gambling or drug links appear, visitors are redirected to another site, or Google shows a warning. The natural first reaction is to remove those symptoms as fast as possible. The problem is that symptoms are only the part meant to be seen. An attacker who got in often leaves a way back, and if that way is not found, a “cleaned” website can be hacked again through the same route.

This guide covers recovery steps for a hacked website from the side of the company’s own servers and applications, based on NIST and CISA. Who decides and who is contacted during an incident is set out in the Cyber Incident Response Plan. If the incident started from an email, the first steps are in An Employee Clicked a Phishing Link.

Recovering a hacked website starts with evidence, not fixes

The first step after a website is hacked is to secure evidence, because that evidence shows the entry point and what the attacker changed. A joint advisory from CISA and the cybersecurity authorities of Australia, Canada, New Zealand, and the United Kingdom (AA20-245A) lists common mistakes in incident handling, including:

  • Fixing systems before data is secured, so volatile data, such as memory contents, is lost.
  • Not preserving logs, so the incident cannot be fully traced.
  • Coordinating over the same network that is being handled. Use a channel outside that network.
  • Fixing only the symptoms, for example blocking one IP address without finding out how the malicious file arrived.

NIST SP 800-123 recommends starting analysis with the most ephemeral data: current network connections, memory contents, file timestamps, and logged-in users. NIST also cautions that isolating the server must be done carefully, because some attackers configure systems to erase evidence when the server is disconnected or rebooted. One method it mentions is reconfiguring the nearest upstream switch or router rather than unplugging the server.

Copy web server logs, system logs, database logs, and firewall logs to another location before anything is changed.

Illustration: cybersecurity

Where do backdoors usually hide?

A backdoor is an entry point left by an attacker so they can return without repeating the original attack. On websites, the form most often discussed is the web shell, which CISA describes as a script uploaded to a web server to administer the machine remotely. The table below summarizes where to look, from CISA (alert TA15-314A on web shells and advisory AA20-245A) and NIST SP 800-123:

LocationWhat to look forReference
Website foldersFiles modified more recently than the last application update, unfamiliar files in public folders, files containing words such as eval or cmd.exeCISA TA15-314A
Web server logsPOST requests to files that are not scripts, addresses visited by only a few browser typesCISA TA15-314A
AccountsUnknown local or domain users, oddly formatted usernames, Linux accounts with interactive shells, changes to authorized_keysCISA AA20-245A
Persistence mechanismsScheduled tasks, running services, entries that run automatically at startupCISA AA20-245A
Temporary foldersScripts and executables in /tmp, /var/tmp, and /dev/shmCISA AA20-245A
Processes and networkUnknown processes connecting to the internet, ports listening without reason, new connections on previously unused portsCISA AA20-245A
Software and dataChanges to software, configuration, and data, plus tools left behind by the attackerNIST SP 800-123

File checks are easiest if you have a “known good” copy. CISA recommends creating such a copy and backing it up offline before an incident, so changes can be spotted by comparing the two. Check similar servers too. NIST SP 800-123 names hosts in the same IP address range, hosts with the same or similar passwords, hosts with a trust relationship, and hosts running the same operating system and applications.

Rebuild the server or restore from backup?

This is the biggest decision in recovery. NIST SP 800-123 gives two options: reinstall the operating system, applications, updates, and content from scratch, or restore the server from backup. The second option is described as riskier, because the backup may have been made after the server was compromised, so restoring it also restores the attacker’s access.

Factor (NIST SP 800-123)Leans toward restoring from backupLeans toward rebuilding
Attacker’s level of accessRegular user or guestRoot, administrator, or system
Understanding of the attacker’s actionsClear from logs and evidenceMuch is unknown
Duration of compromiseShort, with known timingLong, or unknown since when
Extent of compromiseOne serverSeveral hosts on the network

The “leans toward” columns are derived from NIST’s conclusion below, not fixed rules.

NIST concludes: the lower the access the attacker gained and the better their actions are understood, the less risk in restoring from backup and patching the vulnerability. Where the attacker’s actions are less known or their access was high, NIST recommends reinstalling the operating system, server software, and applications from the maker’s original distribution, and restoring data only from a known good backup.

NIST SP 800-61 Rev. 3 adds that the integrity of backups should be checked before use: look for indicators of compromise, file corruption, and other integrity issues. For highly sophisticated attackers whose full scope is not revealed, NIST says replacing the hardware of compromised systems may be necessary.

Close the entry point and change credentials

A website restored without closing its entry point is just waiting to be hacked again. NIST SP 800-61 Rev. 3 describes eradication as eliminating persistence mechanisms and entry points, including deleting malware, disabling breached accounts, and identifying and mitigating all exploited vulnerabilities, across all affected hosts and services.

  1. Find the root cause: an outdated plugin or module, a leaked password, an unrestricted upload form, or admin access exposed to the internet.
  2. Apply all updates. CISA recommends patching internet-facing systems immediately, starting at the attacker’s point of entry, while making sure those systems are not compromised again during patching.
  3. Disable unneeded services, as NIST SP 800-123 recommends.
  4. Change all passwords and keys: application admin, database, hosting panel, FTP or SFTP, and API keys. NIST SP 800-123 asks that passwords on other hosts be changed too if they may have been seen by the compromised server or are also used there. CISA adds reissuing certificates for affected accounts and devices.
  5. Do it once the scope is known. CISA AA20-245A warns that hasty credential resets, before all of the attacker’s access is mapped, can tip the attacker off while they still hold other credentials.

Safer web server configuration, from TLS to file permissions, is summarized in Hardening Company Web Servers.

Making sure the system is clean before going back online

According to NIST SP 800-61 Rev. 3, restored assets should be checked for indicators of compromise, and the root cause remediated, before production use. Recovery actions are also verified for correctness before the system is put back online. The practical order:

  1. Test the server’s security before reconnecting it, as NIST SP 800-123 recommends. Vulnerability scanning helps find outdated versions and missing updates.
  2. Confirm the website works normally with the system owner, and restore essential services in the right order.
  3. Reconnect and monitor for signs the attacker is trying to get back in, for example requests to old web shell addresses or logins from the same addresses.
  4. Declare recovery complete based on the agreed criteria, then write a report recording the incident, the actions taken, and the lessons learned.

If Google flags the website as dangerous

If Google detects hacked content or malware, its findings appear in the Security Issues report in Search Console. Google’s help says every issue must be fixed on all pages, because fixing only some pages does not earn a partial return to search results. Once everything is fixed and tested, select Request Review and explain the issue, the steps taken to fix it, and the outcome. For hacked content and malware, a review can take from a few days to a few weeks, and requests should not be resubmitted before a decision arrives.

How Legia does it

Legia does not provide 24-hour monitoring or on-call incident handling, so the investigation steps above are carried out by your internal team or an incident response provider. Legia’s role comes after and before an incident. Vulnerability Assessment checks websites, applications, servers, and cloud for other gaps that remain open, with manually verified findings, a report ranked by priority, and a retest after fixes, usually within 2 to 4 weeks. To prove whether a gap in a website or web application can still be exploited, Penetration Testing is available with written authorization and an agreed scope, usually 3 to 6 weeks. If you would rather hand over the fixes, Legia handles them through Server Installation & Management or Website Maintenance, billed separately. Other services are on the Cyber Security page.

Frequently asked questions

Can the website be restored straight from yesterday’s backup?

Only if that backup is proven to have been made before the compromise and has been checked for indicators of compromise. NIST SP 800-123 cautions that backups may be made after a server is compromised, so restoring them also restores the attacker’s access.

How long does recovering a hacked website take?

There is no general figure. It depends on the same factors as the rebuild decision: the attacker’s level of access, the duration and extent of the compromise, and how clearly their actions show in the logs. If Google has already shown a warning, add the review time, which Google says can be a few days to a few weeks.

What if customer data was taken?

That incident is critical and involves the legal team. Notification duties under the Personal Data Protection Law and the roles during an incident are covered in the Cyber Incident Response Plan.

Is security testing needed after the website recovers?

It is recommended. The attacker has already proven a gap exists, and other gaps with the same pattern may remain. A check after recovery also confirms the fixes actually closed the entry point.

Sources

Category Cybersecurity

Keep reading

Related articles

All Articles