The order of disposal after a website is injected with malicious code, whether to cut off the entry first or clean the files first.
Discover that the site has been hacked or **malicious scripts, the correct emergency handling sequence is to cut off the entry first, then clean the files. The judgment basis is very simple: deleting files when the entry is still effective is equivalent to dragging water while not turning off the tap. The standard sequence is four steps: cut off the access path and write path still in use, clean up malicious files, repair the exploited entry vulnerability and review in the same round, and finally rotate all possible leaked credentials. The typical consequence of executing out of order is recurrence within a few days after cleaning up.
Four steps of handling sequence
The first step is to stop the entry that is in effect. Change the suspicious write directory to read-only, disable exploited features, limit unnecessary ports from being exposed at the entry layer, and at the same time retain the scene snapshot to avoid not being able to backtrack later. The goal here is not to 'make the site look clean', but to make the attacker lose the ability to write again.
The second step is to clean up files. There are hundreds or even thousands of system or application code files, and it is unreliable to identify them manually one by one. Professional practice recommends using automated detection and processing capabilities directly, first scanning the Web directory, and then conducting a comprehensive review: scheduled tasks, temporary directories, and abnormal network connections are the most likely places to leave secondary entry points. Only handling the reported file is the most common mistake at this step.
The third step is to repair the entry and review. After cleaning, you must answer 'How did it come in?' Upload missing validation, writable template, unpatched injection defects, weak passwords, or reused credentials are common answers. After the repair, confirm the repair status item by item from a vulnerability management perspective, rather than just looking at the page recovery.
The fourth step is to rotate credentials and rebuild monitoring. Passwords, interface signature keys, database accounts, any content that may appear in configuration files or has been read, should be treated as leaked. When going online, enable monitoring for captured anomalies, file changes, and login failures, otherwise the next discovery will still rely on visitor reports.
Why clearing files alone will always recur
Three reasons overlap. First, the entry has not been repaired, and the write permission is still in place; second, Webshells are often not just one place, and after deleting the main file, the residual bypass scripts will rebuild it; third, if the credentials have been leaked, the competition between the cleaning action and the attacker's ability to re-enter is just a race against time. The professional document states this clearly: it depends on emergency response to investigate the cause of the intrusion, find vulnerabilities, and clean up the malware to ensure the system is secure and reliable before strengthening protection to avoid secondary intrusion or repeated trojan horse attacks.
By the way, here's a counterintuitive point: deleting and reinstalling the entire site also belongs to just cleaning the files. A reinstall without a traceability conclusion only brings uncertainty into the new environment.
What do the four layers of reinforcement do?
Reinforcement should be done layer by layer, and the things that each layer blocks are different.
Limit the exposed surface at the entry layer: the security group and firewall only allow necessary ports, do not put database Web management tools on the public network, and do not directly open back-end management systems to the public network. This is especially true for content sites, as many intrusion paths are not complex vulnerabilities, but accessible management pages.
Application layer attack behavior: Web application firewall handles injection, abnormal upload, and common scanning. The content management system itself also bears a part: AnQiCMS built-in JWT authentication, and in the README, the content sensitive word filtering and anti-capture interference code are included in the defense mechanism against SQL injection and XSS attacks; the form side can also connect to reCAPTCHA verification code, blocking machine submissions for registration and comments at the entrance. These mechanisms belong to the daily defense line and cannot replace the traceability in the emergency stage.
Version layer narrows the known defect window: Keep an eye on and update the latest version and security patches released by the official, avoid using versions that have stopped being maintained. Staying on the old branch is equivalent to publicly exposing your exposure in the announcement.
Data layer retains the ability to recover: AnQiCMS supports the backup and recovery of data and static files. The backup should be accepted according to 'recoverable' rather than 'done', and only exporting unverified backups does not have the value of rollback in emergencies.
The position of backup and recovery in emergencies
Backups play two roles in emergencies: rollback points and forensic materials. Rollback points allow for a known clean version to revert to when cleanup fails; forensic materials provide a basis for determining the time of intrusion, comparing the differences between backups and the working directory often allows for the direct identification of modified files.
Therefore, after the event, the backup strategy should be adjusted: increase the number of retained copies of key directories, incorporate recovery drills into routine inspections, and ensure that the backup files themselves are not on the same writable entry point as the work site. If the backup directory can be directly accessed via a Web path, the event handling is just a change of position for the risk.
Common questions
Can we restore the entire site backup first?Can it be restored, but the entry vulnerabilities and credential issues will not disappear with the backup. After recovery, you still need to go through the two steps of tracing and rotation.
How long after cleaning can you confirm safety?Take the review result as the standard: full disk scan with no residue, entry repair with conclusion, credentials have been rotated, monitoring is online, all four items are in place to achieve phased convergence.
Should we notify the search engine?If the site is used for redirection or content injection, repair it first and then submit for review to avoid applying for inclusion review with problem pages.