Lesson 11 · 45 minutes
Classify incidents, name who is told and check an incident log
- Describe the incident response cycle and name the current NIST guide for it
- Classify an incident into a severity level with a rule, and name who is told and how fast
- Check an incident log for steps that were skipped, and measure the time to contain
The lab folder as it stands after this lesson. Unzip it in ~/krlab.
More
The zip holds every file that the course has printed up to here. To start this lesson with the files of the earlier lessons only, take the zip of the lesson before. Type the code yourself first: you learn more.
Scenario
After Friday's break-in the director of Fernwood Press calls a short meeting. She asks three things. "What counts as a big incident here, and who must I be told about? Who runs the response? And the incident log of last week looks odd: can you check it?" You have no plan on paper yet. You write the rules as a small program, because a rule that a program applies is a rule that every analyst applies the same way.
Recall
Lesson 4: which verdict gets priority P1, and what makes the program choose it?
A true positive with impact. The program chooses it when the address had a successful login for a user from an address that is not the usual one of that user, or when the rule has the severity high.
Lesson 10: a patch cannot go in this week. What else can you do?
Reduce the exposure: close the port, add a filter, turn off the feature. Record it as a compensating control with an owner and an end date, and keep the fix on the list.
The idea
An incident is an event, or a group of events, that harms or threatens the confidentiality, integrity or availability of your systems or data. Most alerts are not incidents. An alert becomes an incident when triage says that it is real and that it matters.
The guide that most teams use is NIST SP 800-61. NIST is the US National Institute of Standards and Technology. The current edition is Revision 3, published in April 2025, with the title "Incident Response Recommendations and Considerations for Cybersecurity Risk Management: A CSF 2.0 Community Profile". It replaces Revision 2 of 2012. Revision 2 described four phases: preparation, detection and analysis, containment, eradication and recovery, and post-incident activity. Revision 3 builds the cycle on the six Functions of the NIST Cybersecurity Framework (CSF) 2.0: Govern, Identify and Protect prepare the organisation, and Detect, Respond and Recover are the response itself. Lessons learned feed back into improvement of all six. The document also discusses the roles inside and outside an organisation. Take the current text from NIST: this lesson gives a working model, not a summary of the standard.
- Detect → Respond: analyse, then act
- Respond → Recover: contain, restore
- Recover → Improve: lessons for all
- Improve → Detect: better rules, plans
Govern, Identify and Protect prepare you and sit outside this loop. Improvement takes lessons from all Functions, so the diagram shows it as a step of its own.
The rest of this lesson turns the response into three things that a program can check.
Severity levels. Our policy has four. A level says how many people to wake, and how fast to talk. The SOC (security operations centre) is the team that watches the alerts and keeps the queue of them.
| Level | When | Who is told | First message | Updates |
|---|---|---|---|---|
| SEV1 | Confirmed, and customer data is exposed or a most critical system (5) is hit | Incident lead, management, legal, communications | 15 min | 60 min |
| SEV2 | Confirmed, and a system of criticality 3 or more, or 3 or more systems | Incident lead, system owner, IT manager | 30 min | 2 h |
| SEV3 | Confirmed, one small system | System owner | 4 h | daily |
| SEV4 | Not confirmed or only attempted | The SOC queue | next day | none |
Roles. The incident lead decides and speaks for the team, and one person holds that role at a time. The analyst investigates. The system owner knows the system and can approve a shutdown. The IT administrator acts on systems. Communications writes to staff and customers, and legal advises on what must be told to authorities and when. One writer, one channel: all messages go out through the lead, in facts, and a guess is marked as a guess.
States. An incident moves through six states in order. A state may not be skipped, with one exception: when analysis shows that nothing real happened (a phishing mail that nobody opened), the incident goes from analysing straight to closed. If new evidence shows a wider breach, it may go back from contained to analysing. A closed incident stays closed.
- detected → analysing: facts are checked
- analysing → contained: harm stops growing
- contained → eradicated: the cause is removed
- eradicated → recovered: systems restored
- recovered → closed: the incident ends
- contained → analysing: a wider breach
- analysing → closed: nothing real found
Worked example
1. Get the incident list
incidents.json holds eight incidents from the last weeks. Each has a flag confirmed, the number of systems, the highest criticality of the systems and a flag for customer data.
cat > incidents.json <<'EOT'
[
{"id": "INC-101", "summary": "Phishing mail reported, nobody clicked", "confirmed": false, "systems": 0, "criticality": 0, "customer_data": false},
{"id": "INC-102", "summary": "Adware on one editor laptop", "confirmed": true, "systems": 1, "criticality": 2, "customer_data": false},
{"id": "INC-103", "summary": "Admin pages used with a stolen password, customer export", "confirmed": true, "systems": 1, "criticality": 4, "customer_data": true},
{"id": "INC-104", "summary": "Build server broken into", "confirmed": true, "systems": 1, "criticality": 3, "customer_data": false},
{"id": "INC-105", "summary": "Mass login attempts on the VPN, all failed", "confirmed": false, "systems": 1, "criticality": 4, "customer_data": false},
{"id": "INC-106", "summary": "Customer database down for two hours, disk full", "confirmed": true, "systems": 1, "criticality": 5, "customer_data": false},
{"id": "INC-107", "summary": "The same unwanted program on three workstations", "confirmed": true, "systems": 3, "criticality": 2, "customer_data": false},
{"id": "INC-108", "summary": "Staff wiki page changed by a stranger", "confirmed": true, "systems": 1, "criticality": 2, "customer_data": false}
]
EOT2. Classify, and name who is told
classify is the table above as code. It checks the cases from the highest level down, so the first match wins. PLAN is a dictionary from a level to who is told, the minutes to the first message and the minutes between updates.
PLAN = {
"SEV1": {"tell": ["incident lead", "management", "legal", "communications"], "first": 15, "update": 60},
"SEV2": {"tell": ["incident lead", "system owner", "it manager"], "first": 30, "update": 120},
"SEV3": {"tell": ["system owner"], "first": 240, "update": 1440},
"SEV4": {"tell": ["soc queue"], "first": 1440, "update": None},
}
def classify(inc):
if not inc["confirmed"]:
return "SEV4"
if inc["customer_data"] or inc["criticality"] >= 5:
return "SEV1"
if inc["criticality"] >= 3 or inc["systems"] >= 3:
return "SEV2"
return "SEV3"3. Check the order of the states
NEXT is a dictionary from a state to the list of states that may follow it. bad_moves walks through the log in time order, remembers the last state of each incident, and reports every move that NEXT does not allow. time_to_contain reads the first time of each state (setdefault adds a key only when it is not there yet) and gives the minutes from detected to contained.
NEXT = {
"detected": ["analysing"],
"analysing": ["contained", "closed"],
"contained": ["eradicated", "analysing"],
"eradicated": ["recovered"],
"recovered": ["closed"],
"closed": [],
}
def bad_moves(rows):
last, bad = {}, []
for incident, _time, state in rows:
if incident in last and state not in NEXT[last[incident]]:
bad.append((incident, last[incident], state))
last[incident] = state
return bad
def time_to_contain(rows):
seen, result = {}, {}
for incident, time, state in rows:
seen.setdefault(incident, {}).setdefault(state, time)
for incident, states in seen.items():
if "detected" in states and "contained" in states:
result[incident] = minutes(states["detected"], states["contained"])
return resultminutes(a, b) is a helper in the finished file that gives the minutes between two times.
4. The incident log
phase_log.csv has one line for each change of state: the incident, the time in UTC and the new state.
cat > phase_log.csv <<'EOT'
incident,time,state
INC-101,2026-11-20T09:00:00Z,detected
INC-101,2026-11-20T09:10:00Z,analysing
INC-101,2026-11-20T09:30:00Z,closed
INC-103,2026-11-20T13:03:00Z,detected
INC-103,2026-11-20T13:10:00Z,analysing
INC-103,2026-11-20T13:50:00Z,contained
INC-103,2026-11-20T15:00:00Z,eradicated
INC-103,2026-11-20T16:30:00Z,recovered
INC-103,2026-11-21T09:00:00Z,closed
INC-104,2026-11-20T08:00:00Z,detected
INC-104,2026-11-20T08:20:00Z,contained
INC-104,2026-11-20T09:00:00Z,eradicated
INC-104,2026-11-20T10:00:00Z,recovered
INC-104,2026-11-20T10:30:00Z,closed
INC-106,2026-11-20T02:00:00Z,detected
INC-106,2026-11-20T02:10:00Z,analysing
INC-106,2026-11-20T03:00:00Z,contained
INC-106,2026-11-20T03:30:00Z,eradicated
INC-106,2026-11-20T04:00:00Z,closed
INC-107,2026-11-20T10:00:00Z,detected
INC-107,2026-11-20T10:05:00Z,analysing
INC-107,2026-11-20T10:35:00Z,contained
INC-107,2026-11-20T11:30:00Z,eradicated
INC-107,2026-11-20T12:30:00Z,recovered
INC-107,2026-11-20T13:00:00Z,closed
INC-107,2026-11-21T08:00:00Z,analysing
EOT5. The finished file
Save incident.py, which holds PLAN, NEXT, classify, bad_moves, time_to_contain and a main part that prints the results.
The finished file: incident.py
incident.py
"""incident.py: severity levels, who is told, and the check of an incident log.
python3 incident.py [incidents.json] [phase_log.csv]
"""
import csv
import json
import sys
from datetime import datetime
# What each level means for people and for time: who is told, minutes until the first message, minutes between updates.
PLAN = {
"SEV1": {"tell": ["incident lead", "management", "legal", "communications"], "first": 15, "update": 60},
"SEV2": {"tell": ["incident lead", "system owner", "it manager"], "first": 30, "update": 120},
"SEV3": {"tell": ["system owner"], "first": 240, "update": 1440},
"SEV4": {"tell": ["soc queue"], "first": 1440, "update": None},
}
# The states of an incident, and the states that may follow each one.
NEXT = {
"detected": ["analysing"],
"analysing": ["contained", "closed"],
"contained": ["eradicated", "analysing"],
"eradicated": ["recovered"],
"recovered": ["closed"],
"closed": [],
}
def classify(inc):
"""The severity level of an incident, from what is confirmed and what it touches."""
if not inc["confirmed"]:
return "SEV4"
if inc["customer_data"] or inc["criticality"] >= 5:
return "SEV1"
if inc["criticality"] >= 3 or inc["systems"] >= 3:
return "SEV2"
return "SEV3"
def bad_moves(rows):
"""Every change of state that NEXT does not allow. `rows` are (incident, time, state) in time order."""
last, bad = {}, []
for incident, _time, state in rows:
if incident in last and state not in NEXT[last[incident]]:
bad.append((incident, last[incident], state))
last[incident] = state
return bad
def when(text):
"""A time of the form 2026-11-20T13:03:00Z as a datetime."""
return datetime.fromisoformat(text.replace("Z", "+00:00"))
def minutes(a, b):
"""Minutes between two times."""
return (when(b) - when(a)).total_seconds() / 60
def time_to_contain(rows):
"""Minutes from `detected` to `contained` for every incident that reached `contained`."""
seen, result = {}, {}
for incident, time, state in rows:
seen.setdefault(incident, {}).setdefault(state, time)
for incident, states in seen.items():
if "detected" in states and "contained" in states:
result[incident] = minutes(states["detected"], states["contained"])
return result
if __name__ == "__main__":
incidents = json.load(open(sys.argv[1] if len(sys.argv) > 1 else "incidents.json"))
for inc in incidents:
sev = classify(inc)
print(f"{inc['id']} {sev} tell {len(PLAN[sev]['tell'])} first message within {PLAN[sev]['first']} min {inc['summary']}")
with open(sys.argv[2] if len(sys.argv) > 2 else "phase_log.csv", newline="") as src:
rows = [(r["incident"], r["time"], r["state"]) for r in csv.DictReader(src)]
for incident, old, new in bad_moves(rows):
print(f"bad move in {incident}: {old} -> {new}")
times = time_to_contain(rows)
print(f"time to contain: {', '.join(f'{k} {v:.0f} min' for k, v in times.items())}; mean {sum(times.values()) / len(times):.1f} min")python3 incident.pyINC-101 SEV4 tell 1 first message within 1440 min Phishing mail reported, nobody clicked
INC-102 SEV3 tell 1 first message within 240 min Adware on one editor laptop
INC-103 SEV1 tell 4 first message within 15 min Admin pages used with a stolen password, customer export
INC-104 SEV2 tell 3 first message within 30 min Build server broken into
INC-105 SEV4 tell 1 first message within 1440 min Mass login attempts on the VPN, all failed
INC-106 SEV1 tell 4 first message within 15 min Customer database down for two hours, disk full
INC-107 SEV2 tell 3 first message within 30 min The same unwanted program on three workstations
INC-108 SEV3 tell 1 first message within 240 min Staff wiki page changed by a stranger
bad move in INC-104: detected -> contained
bad move in INC-106: eradicated -> closed
bad move in INC-107: closed -> analysing
time to contain: INC-103 47 min, INC-104 20 min, INC-106 60 min, INC-107 35 min; mean 40.5 minTwo incidents are SEV1: the customer export, and the database that was down, which is the one system of criticality 5. The two unconfirmed ones are SEV4. The log has three bad moves. INC-104 went from detected to contained and skipped the analysis: someone acted before they knew the scope. INC-106 went from eradicated to closed and skipped the recovery: nobody wrote down that the service was back. INC-107 was reopened after it was closed, which the policy does not allow: it needs a new incident that points to the old one. The mean time to contain of the four incidents that reached that state is 40.5 minutes.
Your turn
A second list and a second log came in. Management adds a rule: an incident in which an outsider logged in to a system is at least SEV2, whatever else is true. The new field is outsider_login. Save the data, copy incident.py to a new file and add the rule there.
cat > incidents2.json <<'EOT'
[
{"id": "INC-201", "summary": "Port scan from one address, all blocked", "confirmed": false, "systems": 0, "criticality": 0, "customer_data": false, "outsider_login": false},
{"id": "INC-202", "summary": "Stranger logged in to a staff laptop", "confirmed": true, "systems": 1, "criticality": 2, "customer_data": false, "outsider_login": true},
{"id": "INC-203", "summary": "Shipment database encrypted by unknown software", "confirmed": true, "systems": 1, "criticality": 5, "customer_data": false, "outsider_login": false},
{"id": "INC-204", "summary": "Four test servers show the same strange process", "confirmed": true, "systems": 4, "criticality": 1, "customer_data": false, "outsider_login": false},
{"id": "INC-205", "summary": "Mail relay used to send spam", "confirmed": true, "systems": 1, "criticality": 3, "customer_data": false, "outsider_login": false},
{"id": "INC-206", "summary": "Customer list found on a public page", "confirmed": true, "systems": 1, "criticality": 3, "customer_data": true, "outsider_login": false}
]
EOTcat > phase_log2.csv <<'EOT'
incident,time,state
INC-202,2026-12-01T08:00:00Z,detected
INC-202,2026-12-01T08:05:00Z,analysing
INC-202,2026-12-01T08:35:00Z,contained
INC-202,2026-12-01T09:30:00Z,eradicated
INC-202,2026-12-01T10:00:00Z,recovered
INC-202,2026-12-01T10:30:00Z,closed
INC-203,2026-12-01T01:00:00Z,detected
INC-203,2026-12-01T01:20:00Z,analysing
INC-203,2026-12-01T02:00:00Z,eradicated
INC-203,2026-12-01T02:10:00Z,contained
INC-203,2026-12-01T03:00:00Z,recovered
INC-203,2026-12-01T03:30:00Z,closed
INC-205,2026-12-01T11:00:00Z,detected
INC-205,2026-12-01T11:10:00Z,contained
INC-205,2026-12-01T12:00:00Z,eradicated
INC-205,2026-12-01T12:20:00Z,recovered
INC-205,2026-12-01T12:30:00Z,closed
EOTCheck yourself
Why is the state "contained" before "eradicated" and not the other way round?
Containing stops the harm from growing: you cut the attacker off. Eradicating removes the cause, and it needs time and a clear picture. If you remove the cause first, you may tip off the attacker, who can then do more harm, and you may destroy evidence that you needed. Stop first, then clean.
The incident lead says "I think the data is safe". How should that go into a message to management?
As an assumption with its reason, for example: "We assume that no data left, because the export log shows no large answer. We have not checked the database log yet. We will confirm by 15:00." Facts and assumptions are labelled, so that nobody acts on a guess as if it were known.
Our policy says SEV1 needs a first message within 15 minutes. Why set a time and not leave it to the lead?
Under pressure people delay the message until they know more, and the people who must decide (management, legal) then act late. A fixed time makes the first message short and early. It says what is known, what is not, and when the next message comes.
What does NIST SP 800-61 Revision 3 add to the old four-phase cycle?
It links incident response to the six Functions of the Cybersecurity Framework 2.0. Govern, Identify and Protect (the preparation) are part of the same risk management as Detect, Respond and Recover, and lessons learned feed improvement back into all of them. Response is no longer a separate team activity at the end of a chain.
Field notes
- Write the plan before the incident: the roles with names and phone numbers, the severity table, the places where the team talks, and the people who may approve a shutdown. During an incident nobody has time to look for them.
- Keep an out-of-band channel. If the attacker is in the mail system or in the chat tool, the response team must talk somewhere else.
- Check what you must report, to whom and when: laws, contracts and cyber insurance all set rules, and the times can be short. Ask legal in advance and take the dates from the current texts, never from memory.
- Practise. A table-top exercise, where the team talks through a made-up incident for an hour, finds more holes in a plan than reading it.
- Record the time of every state change. The times give you the measures of the process (time to detect, to contain, to recover), and you cannot improve what you do not measure.