Linux Incident Response and Digital Forensics
Exit

Lesson 1 of 12 · Fundamentals

The incident response cycle and preparation

40 min Debian 12

Objective

Know in what order to act when a Linux server is compromised, who does what on the team, and what must be ready before the crisis so nothing is improvised on the day.

The essentials

  • Incident response follows a cycle: preparation, detection and analysis, containment, eradication, recovery, lessons learned. Skipping a step is costly (you reinstall before understanding, the attacker comes back through the same door).
  • The first rule is to not destroy evidence: do not power off, do not "clean up" by hand, do not run a tool that overwrites the disk.
  • Every action is written in a logbook timestamped in UTC, with its author.
  • Preparation happens cold: contacts, emergency access rights, centralized logs, a trusted tool kit with hashes, playbooks, drills.
  • You answer a business question, not only a technical one: which data, which customers, which legal obligations?

1. The six phases

The model most used in the field breaks response into six steps. Official guides sometimes group them differently (the US NIST guide, in its 2025 revision, maps them onto the Cybersecurity Framework CSF 2.0 functions: govern, identify, protect, detect, respond, recover), but the work on the ground is the same.

Phase Question Example on ml-web-01
Preparation Are we ready? Logs forwarded to ml-log-01, backups tested, tool kit ready
Detection and analysis What is really happening? A CPU-spike alert, then an unknown root login in auth.log
Containment How to stop the bleeding without erasing traces? Pull the server off the public network, keep it powered on, block the IP
Eradication What did the attacker leave? Remove the added SSH key, the hidden account, the cron task, fix the flaw
Recovery How to return to service with confidence? Rebuild from a clean image, restore verified data, watch closely
Lessons learned What do we learn? Blameless review, dated action plan, updated playbooks

It is not a straight line: during eradication you often find a second affected machine and go back to analysis.

Short and long containment

  • Short term: cut off the attacker as fast as possible (firewall rule, cloud security group, network cable, disabling an account).
  • Long term: keep serving customers during the investigation (a clean replacement server, a maintenance page).

Cutting the power is almost always a mistake: RAM (processes, connections, encryption keys, deleted-but-open files) vanishes. You isolate from the network, keep the machine on, collect (lesson 1.2).

2. The team and roles

Even in a small shop, each role has a name before the crisis:

Role Mission
Incident lead Decides, prioritizes, keeps the logbook, talks to management
Analysts Collect, analyze, propose technical measures
System administrators Execute containment and recovery actions
Communication Internal, customer and press messages (lesson 4.1)
Legal / data protection officer Legal obligations, complaint, notifications
Management Arbitrates costly choices (shutting a service, refusing a ransom, going public)

In Morocco, public administrations and critical infrastructure also have an obligation to notify the DGSSI (lesson 4.1). The contact must be in the sheet before the incident.

3. The logbook

An investigation runs for days; without a logbook, nobody knows who restarted what and when. One line per action:

# Simple format: UTC time | author | action
date -u +%Y-%m-%dT%H:%M:%SZ          # 2026-10-20T08:15:00Z
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) | ops | ml-web-01 removed from public security group" >> logbook.txt

Rules:

  • always UTC (the server, the firewall and the SIEM are not necessarily in the same zone; Morocco has changed its time several times);
  • append (>>), never overwrite; the logbook itself is part of the case file;
  • record the decisions and their reasons too ("decided not to power off: memory capture planned").

4. The trusted tool kit

On a compromised machine, ls, ps or netstat may have been replaced to hide the attacker. So you prepare clean binaries and their hashes cold:

mkdir -p /media/ir-key/tools && cd /media/ir-key/tools
cp /usr/bin/{ls,find,grep,stat,sha256sum,ps,ss,lsof} .   # from a clean machine of the same version
sha256sum * > SHA256SUMS
# On the day, on the suspect server, run the tools from the key:
/media/ir-key/tools/sha256sum -c /media/ir-key/tools/SHA256SUMS
/media/ir-key/tools/ls -la /tmp

Add: a blank, formatted collection disk, a network cable, printed playbooks, the contacts list, tested collection scripts (lesson 1.2), and emergency access (a break-glass account, access to the cloud provider's console).

5. Preparing, concretely

  • Inventory: which machines, which data, who owns them.
  • Logs: persistent, time-synced (NTP), copied off the server.
  • Backups: offline or immutable, restore tested.
  • Playbooks: "compromised account", "defaced web server", "ransomware", "data breach".
  • Tabletop drills: two hours per quarter, one scenario, everyone plays their role.

Common pitfalls

  • Powering off or rebooting "to be safe": half the evidence leaves with the memory.
  • Reinstalling right away without understanding the attacker's entry: they come back through the same flaw next week.
  • Alerting the team on the mail system that may be compromised: use a separate channel (phone, off-domain messaging).
  • Mixed local times: a timeline off by an hour leads to wrong conclusions.

Lab

You prepare the response to incident INC-2026-0007:

  1. open the logbook with a first UTC-timestamped line;
  2. add a second line without overwriting the first;
  3. build the trusted tool kit and its hash file;
  4. sort the actions taken during the incident into the right phase of the cycle.

Quiz

  1. List the six phases in order.
  2. Why must you not power off a compromised server?
  3. What is the difference between containment and eradication?
  4. Why record times in UTC in the logbook?
  5. What is the SHA256SUMS file of the tool kit for?
Answers
  1. Preparation, detection and analysis, containment, eradication, recovery, lessons learned.
  2. RAM (processes, connections, deleted-but-open files, keys) disappears at shutdown; it is often the best evidence.
  3. Containment stops the attacker from doing more; eradication removes what they installed and fixes the flaw used.
  4. To compare sources from different time zones (server, firewall, SIEM, cloud provider) without error.
  5. To verify, on the day, that the kit's tools have not been modified.

Practical exercises

To do on Debian 12

Do this lab on your own machine

The terminal is yours: a Linux VM (VirtualBox, VMware, Hyper-V, WSL…) or Docker/Podman. The ml tool prepares the exercise and checks your work; the lesson is validated here automatically.

Create a free account to get your personal command and have your labs checked automatically.

Create my account

Tasks

  1. Open the incident logbook: create /root/ir/journal-de-bord.txt whose first line starts with the current UTC time in the format 2026-10-20T08:15:00Z, followed by " | ops | " then some text (e.g. opening INC-2026-0007).
    Show a hintdate -u +%Y-%m-%dT%H:%M:%SZ gives the UTC time in the right format; use it in an echo.
    Show the solution
    echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) | ops | ouverture INC-2026-0007" > /root/ir/journal-de-bord.txt

    Check : head -n 1 /root/ir/journal-de-bord.txt 2>/dev/null | grep -Eq "^20[0-9]{2}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]Z \| ops \| .+"

  2. Add a second line to the logbook in the same format (UTC time, " | ops | ", text): the logbook is never overwritten, it is appended to.
    Show a hintUse >> (append), not > (overwrite).
    Show the solution
    echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) | ops | serveur isolé, collecte des preuves en cours" >> /root/ir/journal-de-bord.txt

    Check : f=/root/ir/journal-de-bord.txt; test "$(grep -Ec "^20[0-9]{2}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]Z \| ops \| .+" $f)" -ge 2 && sort -c $f

  3. Prepare the trusted tool kit: copy ls, find, grep, stat and sha256sum (from /usr/bin) into /root/ir/outils/, then create /root/ir/outils/SHA256SUMS with the hashes of the five tools (file names without a path).
    Show a hintcd /root/ir/outils then sha256sum ls find grep stat sha256sum > SHA256SUMS
    Show the solution
    mkdir -p /root/ir/outils && cd /root/ir/outils && for o in ls find grep stat sha256sum; do cp /usr/bin/$o .; done && sha256sum ls find grep stat sha256sum > SHA256SUMS

    Check : cd /root/ir/outils 2>/dev/null && for o in ls find grep stat sha256sum; do test -x $o && grep -Eq "^[0-9a-f]{64} $o$" SHA256SUMS || exit 1; done && sha256sum -c --quiet SHA256SUMS

  4. Sort the six actions in /root/ir/actions.txt by phase: create /root/ir/phases.txt with one line per action, "number phase", where the phase is one word among preparation, detection, confinement, eradication, reprise, retour.
    Show a hintIsolating without powering off is containment; removing what the attacker left is eradication; rebuilding is recovery.
    Show the solution
    printf "%s\n" "1 confinement" "2 retour" "3 reprise" "4 eradication" "5 detection" "6 preparation" > /root/ir/phases.txt

    Check : test "$(sed "s/é/e/g;s/É/e/g" /root/ir/phases.txt 2>/dev/null | tr -d "\r" | tr A-Z a-z | awk "NF>=2{print \$1\":\"\$2}" | sort | tr "\n" " ")" = "1:confinement 2:retour 3:reprise 4:eradication 5:detection 6:preparation "