Insights

Practical Notes on Cybersecurity, Threat Analysis & Incident Postmortems for Everyday Troubleshooting

November 26, 2026
0:00
A common belief in hosting is that an incident ends once the malicious file is deleted or the site is restored from last week's backup. The scanner comes back clean, the site loads, and the ticket gets closed. Then, a few days later, the same site starts redirecting to spam again, or the server's IP shows up on a blocklist. The cleanup removed what the attacker left behind. It did nothing about how they got in. This article explains why that happens, what an intrusion usually consists of beyond the visible payload, and a practical order of work that holds up in production: preserve, trace, close, restore, and write it down.
Most compromises on shared hosting and small VPS setups have at least three parts. The first is the entry point: a vulnerable plugin, an outdated CMS, a reused password, an exposed admin panel, or a leaked SSH key. The second is persistence, meaning something that lets the attacker come back without repeating the original attack. The third is the payload, which is the part the owner actually sees: spam pages, redirects, a crypto miner, outbound mail. Cleanup usually targets the payload because it is the only visible part. If the entry point is still open, the attacker, or more often an automated script that scans the internet for the same weakness, simply goes through it again. Restoring a backup has the same gap. The backup contains the same vulnerable plugin version and the same credentials, and sometimes it already contains the persistence mechanism if the compromise started before the backup was taken. This is why support engineers often hear "we restored it and it came back." The restore worked as designed. It returned the server to a state that was already exploitable.
Persistence takes different forms depending on how much access the attacker got. With web-level access, the most common form is a webshell: a small script, usually PHP on hosting servers, that runs whatever commands are sent to it over HTTP. Webshells are often a few lines long, get dropped into upload folders or theme directories, and use names chosen to blend in. Some attackers also inject code into existing legitimate files so that no new file appears at all. With shell or root access, the options widen: scheduled jobs, added SSH keys, modified system libraries, new user accounts, or services that start at boot. Earlier articles on this site cover several of these specific traces, so this article won't repeat them. Credentials are the part people forget most often. If an attacker could read wp-config.php or a .env file, they now have the database password and possibly API keys or SMTP credentials. Deleting the webshell doesn't revoke any of that.
The instinct under pressure is to delete everything suspicious immediately. The problem is that the evidence you need to find the entry point gets deleted along with it. File timestamps, the webshell's filename, and the running process list all help you answer "how did they get in," and they are easy to destroy. If the server is a VPS and your platform supports it, a disk snapshot taken before any changes is the cleanest way to preserve state. Check with your provider or hypervisor whether snapshots are available and whether they include memory. If that isn't possible, at least record the live state somewhere safe. The commands below are read-only on the system itself. They write a few small files, so ideally send the output off the server instead of storing it on the compromised disk.
BASH
mkdir -p /root/ir-notes
ps auxf > /root/ir-notes/processes.txt
ss -tunap > /root/ir-notes/sockets.txt
last -F > /root/ir-notes/logins.txt
lastb -F > /root/ir-notes/failed-logins.txt 2>/dev/null
The process tree shows what is running and under which user. The socket list shows unexpected listeners or outbound connections. The login history shows who logged in and from where. Copy suspicious files somewhere outside the web root before deleting them, and keep the relevant access logs, which may rotate away within days. Containment comes first. If the server is actively sending spam, attacking others, or leaking data, you can block outbound traffic or take the site offline before collecting everything. Evidence matters, but stopping ongoing harm matters more.
Tracing an intrusion usually means working backwards from the earliest suspicious event you can find. A practical starting point on a hosting server is to list recently changed PHP files.
BASH
find /home/*/public_html -type f -name '*.php' -ctime -14 -printf '%CY-%Cm-%Cd %CH:%CM %p
' | sort
This uses ctime, the time the file's metadata last changed, instead of mtime. Attackers commonly backdate mtime with touch so their file looks as old as its neighbours. Ordinary tools cannot set ctime directly, so it usually reflects when the file actually appeared or changed. Adjust the path for your layout. A file in an uploads folder, or a core file changed outside any update window, is worth a closer look. Once you have a suspicious file and its time, go to the web server access logs around that time and look at which scripts received POST requests. Webshells are typically driven by POST, and a PHP file that suddenly receives many POSTs from a few IPs stands out.
BASH
awk '6 ~ /POST/ {print7}' /path/to/access.log | grep -i 'php' | sort | uniq -c | sort -rn | head -20
The field positions assume the common combined log format. Custom formats, Nginx setups, and some control panels shift the fields, and log locations vary by panel and version, so confirm both before trusting the output. The requests just before the webshell first appeared often reveal the entry point: a request to a plugin's upload handler, a login to an admin panel from an unfamiliar IP, or an exploit pattern against a known vulnerable path. If logs show a successful admin login with no prior failures, suspect stolen or reused credentials rather than a software bug. On Windows servers the trail looks different, and tracing ransomware entry through RDP logon events covers that case. After you identify the entry point, close it before restoring anything. In practice that means a few steps:
  1. Patch or remove the vulnerable component.
  2. Rotate every credential the attacker could have read, including database passwords, CMS admin accounts, application secrets, API keys, and SSH keys.
  3. Restore clean files, or rebuild from known-good sources.
  4. Watch the logs for the same pattern over the following days.
If the entry point was SSH or a remote admin service, hardening SSH against brute force is the natural next step. Sometimes you won't find the entry point, because logs have rotated or the attacker cleaned them. In that case the safe assumption is that every credential is compromised and every installed component is suspect. A rebuild from clean sources with fresh credentials is slower than a cleanup, but it is the only option that doesn't depend on a guess.
A postmortem is a short written account of what happened, why, and what changes as a result. On small teams it often gets skipped once the site is back up, which is how the same incident gets handled from scratch three months later by someone who never saw the first one. A useful postmortem doesn't need to be long. It should include a timeline with the earliest known malicious activity, when it was detected, and when it was contained. It should name the entry point, or state honestly that it wasn't found. It should list what persistence was found and removed, which credentials were rotated, and what will change, with each action assigned to a person. The gap between the first malicious activity and detection, often called dwell time, is worth recording even when it is uncomfortable. A long gap usually points to a monitoring problem, not a cleanup problem, and that is the gap most worth fixing. Write the postmortem without blame. If the cause was an unpatched plugin, the useful question is why the update process missed it, and the person who didn't click update is the wrong focus. Blame makes people hide details, and missing details make the next investigation harder. For support teams, the same structure works as a ticket note. A junior engineer who picks up a reinfection ticket can read the earlier note, see which entry point was closed, and immediately check whether it reopened or whether this is a different one.
When a compromise shows up, resist the urge to delete first. Contain anything causing active harm, capture the live state and logs, find where the attacker came in, and close that path along with every credential they could have touched. Only then clean or restore, and write down what happened while it is fresh. Restoring from backup is the last step of that sequence.

Join My Newsletter & Get Updates!

Get notified whenever a new technical guide, server infrastructure breakdown, or personal reflection goes live, plus a curated weekly digest.