The first hour of a security incident on a Linux server
An unknown process uses all the CPU, a user you did not create can log in, the hosting provider reports outgoing attacks from your IP, or a scanner found a web shell. What you do in the first hour decides whether you can later tell what happened, and whether the attacker keeps a way back in. The steps assume a team without a security department; follow them in order.
Minute 0 to 5: start a log and decide who leads
- Open a text file or a ticket on another machine, not on the affected server. Write down every step with the time in UTC: what you saw, what you ran, what you changed.
- One person leads and decides. Others collect information and ask before they change anything.
- Do not discuss details in chat channels the attacker might be able to read, such as a team chat whose token was on the server.
Minute 5 to 20: save what disappears first
Some evidence is gone after a reboot or a cleanup. Collect it before you contain, unless the attack is causing damage right now.
Take a snapshot of the disk
Most cloud and VPS providers can snapshot a running server from their console. It costs little and keeps the state of the file system for later analysis.
Copy the volatile state to another machine
Run the commands from your workstation over SSH, so the output never lands on the compromised disk:
host=web1.example.com
out="evidence-$host-$(date -u +%Y%m%dT%H%MZ).txt"
ssh root@"$host" '
date -u; uptime; who; last -F -n 50
ps auxwwf
ss -tupan
ls -l /proc/*/exe 2>/dev/null | grep "(deleted)"
ls -la /tmp /var/tmp /dev/shm
crontab -l; ls -la /etc/cron.* /var/spool/cron 2>/dev/null
systemctl list-units --type=service --state=running
systemctl list-timers --all
' > "$out" 2>&1
sha256sum "$out"
The (deleted) line lists processes whose program file was removed after it started, a common trick of malware:
lrwxrwxrwx 1 root root 0 Nov 26 02:50 /proc/8/exe -> /tmp/x (deleted)
Copy the logs
Copy journalctl and the files in /var/log (auth, web server, application) of the past weeks. Attackers delete logs, and this copy and the snapshot may be the only ones you will have.
If the server runs containers, also save docker ps -a, docker inspect of each container and docker diff <container>, which lists files changed inside a container.
Minute 20 to 40: cut the attacker off
Isolate the server without shutting it down
A firewall rule at the provider that blocks all traffic except SSH from your own address is best: it does not depend on the compromised system, and the attacker cannot undo it from inside. Shutting down loses the memory state and running processes; do it only if the server is actively harming others and you cannot isolate it.
Rotate secrets from a clean machine
Assume that the attacker knows every secret on the server:
- SSH keys that log in to other systems, and
authorized_keysentries on other servers that trust this one; - API tokens and cloud credentials (deploy keys, object storage keys, the API token of the DNS provider);
- database passwords, especially when the database is reachable from elsewhere;
- secrets in
.envfiles and in environment variables of containers; - TLS private keys, if the attacker had root.
Revoke first, then create new ones, and do not install the new ones on the compromised server. Secrets in .env files and Git lists where secrets hide.
Check the neighbours
Find the other servers that share keys, networks or accounts with this one, and look at their logins and processes too.
Minute 40 to 60: decide what comes next
Who has to be told
- Under the EU GDPR (article 33), a personal data breach has to be reported to the supervisory authority without undue delay and, where feasible, within 72 hours after you become aware of it, unless it is unlikely to result in a risk to people. Article 34 adds a duty to inform the people concerned when the risk is high.
- Under the Swiss Federal Act on Data Protection (article 24), a breach that is likely to result in a high risk has to be reported to the FDPIC as soon as possible.
- Contracts with customers often require notice too. Your hosting provider wants to know if the server attacks others.
Write down when you became aware: the deadlines run from there.
Rebuild, do not clean
An attacker with root can hide in many places. Build a new server from a known good image or configuration, restore data from a backup made before the compromise, fix the way in, and only then go live again. Backups and restore tests covers the backup side. Keep the old disk snapshot for analysis.
Find the way in
Common entry points on small servers: a known vulnerability in a web application or plugin, a reused or leaked password, an exposed admin panel or database, a stolen SSH key, a compromised CI pipeline. Check the findings of your last scans for the system; a KEV finding is a strong lead.
What not to do
- Do not run cleanup scripts from the internet on the server.
- Do not delete suspicious files before you have copies and hashes of them.
- Do not log in to other servers from the compromised one.
- Do not reuse the compromised server after "cleaning", and do not restore a backup without checking that it predates the compromise.
- Do not contact the attacker.
Prepare this before you need it
- Know how to snapshot and firewall a server at your provider, and who has the access.
- Keep a list of the secrets each server holds and how to rotate each one.
- Keep logs on a second system (a log server or the log service of the provider), so an attacker cannot delete all copies.
- Keep the contact of the data protection authority and of someone who does incident response for a living.
Sources
- Regulation (EU) 2016/679 (GDPR), articles 33 and 34
- Swiss Federal Act on Data Protection (FADP), article 24
/proc/*/execheck tested in adebian:bookworm-20261027-slimcontainer on 2026-11-26
Check your servers every day
The Vulnpocalypse collector reports the packages and settings of a server once a day, and the digest lists what to fix, most urgent first.
Vulnpocalypse