Education › Security › Stage 4: Operations & response

Security incident response

Preparation, detection, containment, eradication, recovery and lessons learned — with a real playbook.

Advanced ~35 min read Module 14 of 16

At some point a detection fires and it is real, or a customer emails a screenshot of your data, or a cloud bill arrives with ten thousand dollars of GPU instances you never launched. What happens in the next few hours decides whether this is a contained incident or a company-defining breach. Security incident response borrows the structure of the SRE incident process — roles, a commander, timelines, blameless review — and adds what is different when there is an adversary: evidence must be preserved, containment must not tip them off before it is complete, and the scope is almost always larger than the first alert suggests. This module gives you the phases, the playbooks, the evidence-handling basics and the communication rules to run one well.

After this module you can
  • Describe the incident lifecycle: preparation, detection and analysis, containment, eradication, recovery, lessons learned
  • Run the first hour: declare, assign roles, preserve evidence, scope before acting
  • Choose containment actions that stop the attacker without destroying evidence or alerting them prematurely
  • Eradicate and recover from a known-good state, and verify the attacker is gone
  • Write a blameless security postmortem and handle notification obligations

The lifecycle and why preparation is most of it

The standard model (from NIST's incident handling guide) has six phases: preparation, detection and analysis, containment, eradication, recovery, and post-incident activity. Teams that do well in the middle four did the work in the first one: logs are centralised and retained, roles are defined, playbooks exist for the common scenarios, contact details for legal, communications, the cloud provider and law enforcement are written down, and everyone has practised at least once. Improvising all of that at 3 a.m. with an attacker inside is the failure mode.

  • Playbooks for the likely incidents: leaked credential, phished account, malware on an endpoint, web application compromise, ransomware, insider misuse, cloud account takeover. One page each: how to confirm, how to contain, who to call.
  • Roles: incident commander (decisions and coordination), investigation lead (technical analysis), communications lead (internal and external updates), scribe (timeline). Same people can hold several roles in a small team, but the roles must be named.
  • Access ready: break-glass credentials for investigators, the ability to isolate hosts and revoke sessions quickly, forensic tooling installed before it is needed.
  • Contacts: legal counsel, cyber insurance, the cloud provider's abuse or security contact, a forensics firm on retainer, relevant regulators' notification routes.
  • Practice: a tabletop exercise per quarter, walking through a scenario and finding the gaps in the playbooks.

The first hour: declare, preserve, scope

When an alert or a report looks real, declare the incident early and loudly; it is cheap to stand down a false alarm and expensive to lose an hour. Assign the roles. Start the timeline: a shared document where the scribe records every observation, decision and action with a UTC timestamp. Then, before touching anything, preserve evidence: snapshot the affected instances and volumes, export the relevant logs to a separate location, capture running process and connection lists, and note the hashes of anything you collect.

Volatile evidence from a suspect Linux host, collected to a separate location before any remediation.
bash
EVID=/mnt/evidence/$(hostname)-$(date -u +%Y%m%dT%H%M%SZ)
sudo mkdir -p "$EVID" && cd "$EVID" || exit 1

sudo ps -eo pid,ppid,user,lstart,etime,cmd --sort=lstart > processes.txt
sudo ss -tunapee > sockets.txt
sudo lsof -nP > open_files.txt 2>/dev/null
last -F > logins.txt; sudo lastb -F > failed_logins.txt 2>/dev/null
sudo cat /etc/passwd /etc/group > accounts.txt
sudo crontab -l -u root > cron_root.txt 2>/dev/null; ls -la /etc/cron* /var/spool/cron > cron_files.txt 2>&1
sudo systemctl list-units --type=service --all > services.txt
sudo find / -xdev -mmin -1440 -type f ! -path '/proc/*' -printf '%TY-%Tm-%Td %TH:%TM %u %p\n' > modified_24h.txt 2>/dev/null

sha256sum ./* > SHA256SUMS
# and in the cloud console or CLI: snapshot the instance's volumes now, tag them "evidence", restrict access

Then scope before you act. The alert that fired is one footprint; the attacker has usually been in longer and wider. Pivot from what you know: which credential, which host, which IP, which time window. Search the central logs for every use of that credential, every connection from that IP, every host that talked to the compromised one, every new user, key, role or scheduled task created in the window. Write each new finding in the timeline. Containment that misses part of the footprint tells the attacker you are coming and leaves them a way back in.

Watch out

Do not reboot, reimage, or "just clean it up" before evidence is preserved and scope is understood. You destroy the record of what happened and you may stop only one of the attacker's three footholds.

Containment: stop the bleeding, keep the evidence

Containment stops the attacker from doing more damage while you finish understanding the incident. Choose actions that are reversible where possible and quiet where it matters: revoking a credential and rotating it, isolating a host at the network layer (security group with no rules, or a quarantine VLAN) while keeping it running for analysis, blocking an IP or an ASN at the edge, disabling a user's sessions and tokens, taking a compromised service off the load balancer. For an active, capable intruder, coordinate so that all footholds are cut at once; cutting one at a time is a signal.

ScenarioContain firstThen
Leaked cloud keyRevoke the key; deny the identity in a policyAudit its use; find what it created; rotate everything it could read
Phished accountRevoke all sessions and tokens; reset password and MFACheck mail rules, OAuth grants, downloads; look for lateral logins
Compromised hostNetwork-isolate; snapshot; keep it runningCollect evidence; identify the entry; check siblings
Web app compromiseBlock the exploited path at the WAF or edge; rotate app secretsFind the vulnerability; check for webshells, new admin users, data access
RansomwareDisconnect affected segments; protect backups nowIdentify strain and entry; do not pay reflexively; engage legal

Record every containment action in the timeline with who did it and when. Some actions have side effects for customers (a blocked range, an offline service); the incident commander weighs those with the business, but the default when data is leaving is to stop it now and apologise for the outage later.

Eradication and recovery

Eradication removes the attacker's presence: the malware, the webshell, the added user, the persistence in cron or a systemd unit, the forwarding rule in the mailbox, the extra IAM role, the SSH key in authorized_keys. Because you rarely find everything by hand, prefer rebuilding from known-good sources over cleaning: redeploy the service from the pipeline, re-create the host from the image, restore data from a backup taken before the intrusion (verify the backup is clean and the restore actually works). Close the entry point: patch the vulnerability, fix the misconfiguration, enforce the MFA that was missing.

Recovery brings services back with heightened monitoring: watch for the indicators you collected (IPs, domains, hashes, user agents, the attacker's habits) and for any repeat of the entry technique. Rotate every credential the attacker could have reached, not just the one they used. Confirm with the detection team that the alerts that should fire on a return actually fire. Only when the timeline shows a clear entry, full scope, complete containment and eradication, and a clean recovery does the incident close.

Checking common persistence locations on a Linux host during eradication.
bash
sudo find / -xdev -name authorized_keys -exec sh -c 'echo "== $1"; cat "$1"' _ {} \; 2>/dev/null
sudo ls -la /etc/cron.d /etc/cron.daily /var/spool/cron/crontabs 2>/dev/null
sudo systemctl list-unit-files --state=enabled | grep -v '^unit'
sudo find /etc/systemd/system /lib/systemd/system -newer /etc/hostname -name '*.service' 2>/dev/null
sudo grep -rl 'curl\|wget\|base64 -d' /etc/rc.local /etc/profile.d /home/*/.bashrc /root/.bashrc 2>/dev/null
sudo find / -xdev -perm -4000 -newer /etc/hostname -type f 2>/dev/null

Communication, notification and the postmortem

Inside the company, the communications lead sends short, regular updates (every hour during the active phase) on a fixed channel: what is known, what is being done, what is needed. Speculation stays out of writing; facts and next steps go in. Outside the company, notification is often a legal obligation with a clock: personal data breaches under GDPR must be reported to the regulator within 72 hours of awareness, and many jurisdictions and contracts have their own rules. Involve legal counsel early, keep the timeline accurate because it becomes the evidence of what you knew when, and tell affected customers what happened, what it means for them and what you have done — plainly, without minimising.

After recovery, run a blameless postmortem exactly as the SRE track describes: the timeline, the root cause and the contributing causes, what went well, what did not, and actions with owners and dates. Security incidents add specific questions: how long was the attacker present before detection (dwell time), which detection should have fired earlier, which control would have stopped the entry, and what evidence was missing. Then update the playbooks and detections, and schedule the tabletop that rehearses the next one.

Tip

Measure the program by the numbers that improve outcomes: time from entry to detection, time from detection to containment, and percentage of playbook steps that worked as written. Each incident should move at least one of them.

Hands-on practice

Run a tabletop and build your playbooks

  1. Write one-page playbooks for three scenarios: leaked cloud key, phished employee account, compromised web server. Each has: how to confirm, evidence to preserve, containment steps in order, who to call, and how to know it is over.
  2. Run the evidence-collection script from the lesson on a test host and inspect the outputs. Note which files would tell you about a new user, a cron persistence, or an active outbound connection.
  3. Practise host isolation in a cloud test account: replace an instance's security group with one that has no rules, confirm the instance is unreachable, and confirm you can still snapshot its volumes.
  4. Pick one of your playbooks and run a 45-minute tabletop with two colleagues: one plays the incident commander, one the investigator, one injects new facts every ten minutes ("the key was also used from a new region"). Write down every gap you find.
  5. Draft the internal update template (known, doing, needed) and the customer notification template (what, impact on you, what we did, what you should do). Have someone outside engineering read them.
  6. For your last real or simulated incident, compute dwell time and time to containment, and identify the single detection that would have shortened dwell time the most.
Cheat sheet

Security incident response — at a glance

Main things to focus on

  • Preparation is most of it: playbooks, roles, contacts, evidence tooling, practice
  • First hour: declare, assign roles, start the UTC timeline, preserve evidence, scope before acting
  • Contain reversibly and quietly; cut all footholds at once; record every action
  • Eradicate by rebuilding from known-good, close the entry, rotate everything reachable
  • Recover with heightened monitoring for the collected indicators; close only when scope is complete
  • Communicate facts on a schedule; know the notification clocks; blameless postmortem with dwell time

Roles and phases

commander / investigation lead / comms lead / scribeNamed per incident, even in a small team
prepare -> detect & analyse -> contain -> eradicate -> recover -> learnNIST lifecycle
declare earlyStanding down is cheap; lost hours are not
timeline: UTC, observation / decision / action, whoThe single source of truth and the legal record

Evidence

snapshot volumes, tag evidence, restrict accessBefore any change to the host
ps -eo ... --sort=lstart / ss -tunapee / lsof -nPProcesses, sockets, files: volatile, collect first
last -F / lastb -F / auth.logLogins and attempts
find / -mmin -1440 -type fFiles changed in the window
sha256sum collected filesIntegrity of what you collected
export central logs for the window to a separate storeDo not rely on retention during the incident

Containment moves

revoke key / disable identity / explicit deny policyCredential incidents
revoke all sessions + tokens; reset password and MFAAccount takeover
security group with no rules; keep runningHost isolation that preserves evidence
block path at WAF/edge; remove from load balancerWeb application compromise
disconnect segments; protect backups firstRansomware
all footholds at onceDo not tip off a capable intruder

Eradication and recovery

rebuild from pipeline/image; restore verified clean backupCleaning by hand misses things
check: authorized_keys, cron, systemd units, rc files, setuid, mail rules, OAuth grants, IAMPersistence locations
rotate everything the attacker could reachNot just what they used
monitor the collected indicatorsIPs, domains, hashes, user agents, techniques
close when: entry known, scope complete, eradicated, recoveredNot before

Communication and learning

hourly internal update: known / doing / neededFacts only, fixed channel
GDPR: 72 hours to the regulatorKnow your clocks; involve legal early
customer notice: what, impact, what we did, what you should doPlain, not minimised
postmortem + dwell time + which detection should have firedBlameless, with owners and dates
metrics: entry->detect, detect->contain, playbook accuracyWhat should improve each time

Common pitfalls

  • Rebooting or reimaging the first compromised host before evidence and scope; the record is gone and the other footholds remain.
  • Containing one credential and declaring victory while the attacker's second key keeps working.
  • Cleaning a host by hand and trusting it; rebuild from known-good instead.
  • Rotating only the credential that was used, not everything it could read.
  • Speculating in written updates that later become the legal record.
  • Closing the incident without a postmortem, so the same entry works again next quarter.
Quiz

Check your understanding

5 questions · 4 to pass · answers are explained as you go. Your best score is saved on this device only.

Progress and quiz scores are saved in this browser only. Back up or restore on the hub.

Was this lesson useful? Tell me what to improve →