Defensive Security: Introduction
At 02:14 on a Saturday, a laptop in the finance department starts a PowerShell process that downloads a file from a domain registered three days ago. Nobody is awake in finance. The question this course answers is simple to say and hard to build: who notices, how fast, and what do they do next? In most organisations the answer is a security operations centre (SOC): the people, processes and tools that collect telemetry from everything the organisation runs, turn it into alerts, decide which alerts matter, and start the response before an intruder reaches what they came for.
This course is about building and running that capability. You will write the detections yourself, in pandas and in Sigma, on synthetic logs, and measure them the way a SOC lead would.
What a SOC actually does
A SOC has four jobs, and every lesson of this course serves one of them:
- See. Collect logs and telemetry from endpoints, identity systems, networks, cloud services and applications, keep them long enough, and keep their timestamps and field names consistent. Without this, nothing else works.
- Detect. Turn the raw stream into a small number of alerts that each mean something: correlation rules in a SIEM, signatures in an IDS, behaviour rules in an EDR, and hunts for what the rules miss.
- Decide. Triage every alert: is it real, how bad, who owns it? Escalate the real ones, close the rest with a reason, and feed the reasons back into the rules.
- Respond and improve. Contain, hand evidence to incident responders, learn what was missed, and add a detection so it is not missed again.
Threat intelligence feeds the rules with what attackers are doing now; threat hunting looks for what the rules missed and turns each finding into a new rule. The loop at the bottom is the part that separates a SOC that improves from one that only processes tickets.
Defence in depth, measured
No single control sees everything. Defence in depth layers controls so that an intruder who slips past one is caught by another. It is easy to say and easy to overestimate. The program below gives each detection layer a probability of noticing one intrusion and asks how likely it is that every layer misses it.
layers = { # chance that this layer alerts on one particular intrusion (illustrative numbers)
"email gateway": 0.50,
"EDR on the laptop": 0.60,
"network IDS": 0.30,
"identity analytics": 0.40,
"SIEM correlation": 0.35,
}
miss = 1.0
for name, p in layers.items():
miss *= 1 - p
print(f"after {name:20} P(all missed) = {miss:.3f}")
print(f"\nindependent layers: caught with probability {1 - miss:.1%}")
# Layers are rarely independent. Suppose half of all intrusions use a well-known cloud service:
# the gateway, the IDS and the SIEM rule all rely on domain reputation and then ALL miss.
edr_identity_miss = (1 - 0.60) * (1 - 0.40)
miss_corr = 0.5 * edr_identity_miss + 0.5 * miss
print(f"correlated layers: caught with probability {1 - miss_corr:.1%}")after email gateway P(all missed) = 0.500
after EDR on the laptop P(all missed) = 0.200
after network IDS P(all missed) = 0.140
after identity analytics P(all missed) = 0.084
after SIEM correlation P(all missed) = 0.055
independent layers: caught with probability 94.5%
correlated layers: caught with probability 85.3%
Five mediocre layers, none better than 60 %, catch the intrusion 94.5 % of the time if they fail independently. The second number is the honest one: when half of the intrusions defeat three layers at once because all three trust the same domain reputation, the combined chance drops to 85.3 %, and the miss rate almost triples (from 5.5 % to 14.7 %). A defender's job is to make layers different: different data sources (endpoint, identity, network), different methods (signatures, behaviour, statistics), different people looking.
How this course fits the track
This course builds on several others and links to them instead of repeating them:
| You need | Where it is taught |
|---|---|
| CIA, risk, red/blue/purple teams, the law of testing | Security Foundations, especially Red, Blue and Purple Teams |
| Suricata and Snort rules, Zeek logs, IDS tuning, egress logging | Network Security: Suricata and Snort Rules, Zeek Logs with pandas, Tuning Alerts |
| Windows event IDs, Sysmon, a first detection pipeline, honeytokens | Windows & AD Security: The Key Event IDs and Sysmon, A Small Detection Pipeline |
| Malware analysis, forensics, the incident-response lifecycle | Malware Analysis, Digital Forensics & Incident Response |
| Metrics, logs and alerting for reliability (Prometheus, Loki, Alertmanager) | Observability |
DataFrames, groupby, rolling windows, time series |
pandas |
| A one-page overview of security operations | Security Operations in the survey course |
The Observability course and this one use the same machinery (logs, queries, alert rules) for different questions: "is the service healthy?" there, "is someone abusing it?" here.
The lab environment of this course
All data in this course is synthetic: generated by the examples themselves from fixed seeds, with no real users, hosts or organisations.
- The organisation is
lab.test, its internal network10.10.0.0/24(workstationsws01–ws40, servers such asdc01,web01,fs01). - "Internet" addresses come from the documentation ranges
192.0.2.0/24,198.51.100.0/24and203.0.113.0/24(RFC 5737), which never route on the real Internet. - Malicious domains end in
.testor.exampleand point nowhere.
How the examples run
```python runblocks run in your browser (Pyodide, with pandas). They build their own synthetic logs, so you can edit the attack, the thresholds or the data and run them again.```bash runblocks are recorded sandbox sessions (realjq,tshark,awk,sha256sum) in a container with no network, on the sample files bundled with it.- Products that cannot run here (Splunk, Elastic Security, Microsoft Sentinel, Wazuh, Velociraptor, EDR consoles) appear as query snippets in plain fences labelled with their language, or as
```consoletranscripts labelled lab session, on lab addresses. - The
brute-force-detectlab animates a window-and-threshold rule so you can watch precision and recall move as you tune it.
The rules this course keeps
- Defence first, always with the attack's mechanism. Attacks appear only as the traces they leave in logs, so you can detect them. Every detection lesson ends with how the weakness is fixed or prevented.
- Only synthetic data and your own lab. Monitoring other people's systems or traffic needs the same authorization as testing them (Authorization, Scope and Rules of Engagement). Purple-team tests in your lab run only with written approval.
- Measure. A detection is not finished until you know its true and false positives on test data.
Test yourself
Which of these is NOT one of the four jobs of a SOC described in this lesson?
- See: collect and keep telemetry
- Detect: turn telemetry into meaningful alerts
- Exploit: test production systems without notice
- Decide: triage and escalate alerts
Five independent layers each miss an intrusion with probabilities 0.5, 0.4, 0.7, 0.6 and 0.65. What is the chance that all of them miss it?
- About 0.055
- About 0.5
- About 0.4
- Exactly 0
Why does the program's second estimate (85.3 %) come out lower than the first (94.5 %)?
- The layers became worse on their own
- Three layers share a weakness and fail together, so they are not independent
- Rounding errors
- The EDR was removed
Which addresses does this course use for 'Internet' hosts?
- Random public addresses
- The RFC 5737 documentation ranges such as 203.0.113.0/24
- Addresses of well-known companies
- Only 127.0.0.1