SyntaxPilot
Courses/Cybersecurity Fundamentals/Lesson 26

Cybersecurity Fundamentals · Lesson 26 of 90 · 14 min

Intrusion detection and network monitoring

IDSIPSNIDS vs HIDSsignature-based vs anomaly-based detectiontrue/false positives and negativesNetFlow/IPFIXpacket capture (PCAP) as evidencenetwork baselineNDRSuricata and Zeek (what they are)honeypotsdeception technologyencrypted traffic visibility trade-offs

These are the notes for Cybersecurity Fundamentals (defensive), episode 26. So far we built walls (firewalls, segmentation), tunnels (VPNs) and locks (WPA3, 802.1X). Today we admit that someone will get in anyway, and invent the ways to notice: the intrusion detection system (IDS), signatures and signature-based detection, normalisation, the four outcomes (true/false positives and negatives), the base-rate fallacy and alert fatigue, precision, baselines and anomaly-based detection, flow records with NetFlow and IPFIX, the intrusion prevention system (IPS), NIDS vs HIDS, packet capture (PCAP) as evidence, NDR, what Suricata and Zeek are, honeypots, honeytokens and deception technology, scan detection, and the encrypted-traffic visibility trade-off. Every term is explained the first time it appears, and the Glossary at the end defines them all again.

Ravi's shops, every host, address, flow, login and request here are made up. Addresses are private (RFC 1918, like 10.1.3.40) or documentation-only (RFC 5737, like 192.0.2.30, 198.51.100.5, 203.0.113.66). Every detector is a toy simulation in plain Python: no packets are captured or sent. Every code sample runs with Python 3.13 using only the standard library; outputs are real, copied from actual runs.

The problems you'll solve

Problem Idea it teaches
An intruder explores for three weeks, unnoticed Detection vs prevention, IDS, signature, SOC, analyst, triage
The same attack, spelled differently URL encoding, evasion, normalisation
A "99% accurate" detector buries the team True/false positives/negatives, base rate, alert fatigue, precision, tuning
Brand-new attacks have no signature Baseline, anomaly detection, flow records, NetFlow, IPFIX, standard deviation
Why not block automatically? IPS, inline, false positives as outages, NIDS vs HIDS, PCAP, NDR, Suricata, Zeek
Too many alarms; catch the intruder in the act Honeypot, honeytoken, deception technology, port-scan detection
We encrypted everything; now we can't see Metadata, SNI, endpoint visibility, TLS inspection trade-offs

Problem 1: nobody notices

A phishing email works, and an attacker logs in to Ravi's network with a stolen staff password (initial access, episode 4). For three weeks they explore server after server (lateral movement). The firewall allowed everything, because a real staff login was used, and its logs sat on a disk nobody read.

Prevention (firewalls, VPNs, locks) decides what is allowed. Allowed is not the same as safe. Detection means noticing an attack that prevention let through.

A shop A network
A burglar alarm: doesn't lock anything, it shouts IDS (intrusion detection system): software that watches activity and raises an alert when something looks like an attack
Posters of known shoplifters A signature: a pattern that matches a known attack. Using them is signature-based detection
A guard who checks every alarm: real thief or the cat? A security analyst who triages (sorts and checks) each alert, usually in a SOC (security operations centre)

Demo 1: a tiny signature IDS

Three signatures: a piece of an SQL injection (' or 1=1, covered properly in episode 38), the ../ of path traversal (climbing out of a folder, episode 47), and the name of an old scanning tool. Five web requests arrive.

from urllib.parse import unquote
SIGNATURES = {"SQLi": "' or 1=1", "traversal": "../", "old scanner": "nikto"}
NORMALISE = False                                # <- match raw text, or decode it first

def ids(request):
    text = unquote(unquote(request)).lower() if NORMALISE else request.lower()
    hits = [name for name, pattern in SIGNATURES.items() if pattern in text]
    return "ALERT: " + ", ".join(hits) if hits else "-"

for req in ["GET /item?id=7",
            "GET /item?id=7' OR 1=1--",
            "GET /files?name=../../etc/passwd",
            "GET /files?name=%2e%2e%2f%2e%2e%2fetc/passwd",          # the same attack, URL-encoded
            "GET /item?id=7%27%20OR%201%3D1--"]:
    print(f"{ids(req):16} {req}")

Output with NORMALISE = False:

-                GET /item?id=7
ALERT: SQLi      GET /item?id=7' OR 1=1--
ALERT: traversal GET /files?name=../../etc/passwd
-                GET /files?name=%2e%2e%2f%2e%2e%2fetc/passwd
-                GET /item?id=7%27%20OR%201%3D1--

The normal request: no alert. The two plain attacks: caught. But the last two lines are the very same attacks, URL-encoded: %2e is a dot, %2f a slash, %27 a quote, %20 a space, %3D an equals sign. The web server decodes them and processes them; the IDS matched raw text and saw nothing. Changing an attack's spelling so a detector misses it is called evasion.

Why? The signature matched the spelling, not the meaning.

The fix: normalise first

Normalisation means converting input to one standard form, the way the server will interpret it, before matching: decode URL encoding (sometimes twice), lowercase, and reassemble messages split across several packets.

Output with NORMALISE = True:

-                GET /item?id=7
ALERT: SQLi      GET /item?id=7' OR 1=1--
ALERT: traversal GET /files?name=../../etc/passwd
ALERT: traversal GET /files?name=%2e%2e%2f%2e%2e%2fetc/passwd
ALERT: SQLi      GET /item?id=7%27%20OR%201%3D1--

All four attacks are caught. The deeper limit remains: signatures only know attacks someone has already seen and written down. A brand-new attack (a zero-day, episode 8) has no poster yet.

Problem 2: false positives and the base rate

Every alarm decision has four possible outcomes:

Alert Silence
Real attack True positive (TP) False negative (FN): a missed attack, the worst kind
Normal activity False positive (FP): wasted time, the cat set it off True negative (TN)

Demo 2: a "99% accurate" detector

It catches 99% of attacks and wrongly flags 1% of normal events. A day at Ravi's shops has 100,000 login events, 10 of them real attacks.

import random
random.seed(26)
EVENTS, ATTACKS = 100_000, 10                    # a day of logins at Ravi's shops: 10 are real attacks
DETECT, FALSE_ALARM = 0.99, 0.01                 # "99% accurate": catches 99%, wrongly flags 1%

tp = fn = fp = tn = 0
for i in range(EVENTS):
    attack = i < ATTACKS
    alert = random.random() < (DETECT if attack else FALSE_ALARM)
    if attack and alert: tp += 1
    elif attack: fn += 1
    elif alert: fp += 1
    else: tn += 1
print(f"true positives  {tp:6}   (attack, alert)")
print(f"false negatives {fn:6}   (attack, silence)")
print(f"false positives {fp:6}   (normal, alert)")
print(f"true negatives  {tn:6}   (normal, silence)")
print(f"alerts: {tp + fp}, of which real: {tp / (tp + fp):.1%}")

Output:

true positives      10   (attack, alert)
false negatives      0   (attack, silence)
false positives   1004   (normal, alert)
true negatives   98986   (normal, silence)
alerts: 1014, of which real: 1.0%

All 10 attacks caught, and 1,004 false alarms. Only 1% of alerts are real: the analyst digs through about a hundred false alarms for each real one.

Why? Attacks are rare. 1% of a huge number of normal events is far larger than 99% of a tiny number of attacks. Ignoring how rare the thing you're looking for is (its base rate) is the base-rate fallacy. Overwhelmed analysts start ignoring alerts (alert fatigue), and that's how real attacks get missed.

Useful measures:

  • Precision = TP / (TP + FP): of the alerts, how many were real? (1% here.)
  • Recall (detection rate) = TP / (TP + FN): of the real attacks, how many did we catch? (100% here.)
  • False-positive rate = FP / (FP + TN): of the normal events, how many raised an alarm? (about 1% here.)

So detection is always tuned: rules adjusted to the environment, context added (is this server even vulnerable to that attack?), and precision measured over time.

Problem 3: baselines and anomaly detection

A neighbourhood shop Anomaly detection
Knows his regulars: milk at 7, bread at 8 A baseline: what normal looks like
A regular buys 40 phones at 3 a.m.: noticed without any poster An anomaly: far from the baseline. Anomaly-based detection alerts on it, so it can catch attacks nobody has seen before
...but it's a wedding order Unusual isn't always wrong: anomaly detection has its own false positives

Flow records: a phone bill for the network

A flow record is a summary of one conversation: source and destination address, ports, protocol, start time, duration, and how many bytes and packets. It's like a line on a phone bill: who called whom, when, how long, how much, but not what was said.

  • NetFlow: the flow-record format that started at Cisco; routers and firewalls export it.
  • IPFIX (IP Flow Information Export): the open IETF standard based on NetFlow.
  • Flow records are small, cheap to keep for months, and still work when the traffic is encrypted.

Demo 3: a baseline from 14 days of flows

For each machine: the mean (average) of megabytes sent out per day, and the standard deviation, the size of its usual day-to-day wobble. The z-score = (today − mean) / standard deviation says how many "usual wobbles" today is from normal; above 3 we call it an anomaly.

from statistics import mean, stdev
# NetFlow-style records: who talked to whom, how much. No contents. MB sent out per day, last 14 days:
BASELINE = {"pos-server":  [40, 42, 38, 41, 39, 44, 40, 43, 37, 41, 42, 40, 39, 41],
            "backup-box":  [900, 880, 910, 890, 905, 0, 0, 895, 900, 885, 910, 0, 0, 900],
            "hr-laptop":   [120, 95, 140, 110, 130, 20, 15, 125, 105, 135, 115, 25, 10, 120]}
TODAY = [("pos-server", "203.0.113.66", 4200), ("backup-box", "198.51.100.5", 1800),
         ("hr-laptop", "192.0.2.30", 160)]

for host, dst, mb in TODAY:
    m, s = mean(BASELINE[host]), stdev(BASELINE[host])
    z = (mb - m) / s                                 # how many "usual wobbles" away from normal?
    verdict = "ANOMALY" if z > 3 else "normal"
    print(f"{host:10} {mb:5} MB  usual {m:4.0f} +/- {s:3.0f}  z = {z:6.1f}  {verdict}")

Output:

pos-server  4200 MB  usual   40 +/-   2  z = 2176.0  ANOMALY
backup-box  1800 MB  usual  641 +/- 421  z =    2.8  normal
hr-laptop    160 MB  usual   90 +/-  49  z =    1.4  normal
  • The point-of-sale server usually sends about 40 MB ± 2. Today: 4,200 MB to an unknown address, over two thousand wobbles away. Anomaly, with no signature. This is exactly what stolen card data leaving looks like (exfiltration).
  • The backup box sent double its usual amount and was rated normal: its baseline includes days the backup doesn't run (zeros), so its wobble is huge. A baseline is only as good as its comparison: compare like with like (Practice 2 fixes it).
  • The HR laptop is within its normal range.

Problem 4: IDS vs IPS, NIDS vs HIDS, PCAP, NDR

Why only alert? An IPS (intrusion prevention system) sits inline: traffic must pass through it, so it can drop what matches. An IDS usually watches a copy of the traffic, so it can only alert.

Demo 4: one rule, two modes

MODE = "IDS"                                         # <- "IDS": watch and alert, "IPS": sit inline and block
RULE = ("union select", "SQL injection")              # a signature

def handle(request):
    if RULE[0] in request.lower():
        if MODE == "IPS":
            return f"DROPPED ({RULE[1]})"
        return f"delivered, alert sent ({RULE[1]})"
    return "delivered"

for who, req in [("attacker", "GET /item?id=1 UNION SELECT card FROM cards"),
                 ("customer", "GET /search?q=trade union select committee chairs"),
                 ("customer", "GET /search?q=steel chairs")]:
    print(f"{MODE}  {who:9} {handle(req)}")

Output with MODE = "IDS":

IDS  attacker  delivered, alert sent (SQL injection)
IDS  customer  delivered, alert sent (SQL injection)
IDS  customer  delivered

Output with MODE = "IPS":

IPS  attacker  DROPPED (SQL injection)
IPS  customer  DROPPED (SQL injection)
IPS  customer  delivered

The attacker is dropped. So is a customer searching for "trade union select committee chairs", whose search happens to contain union select. An IDS false positive wastes time; an IPS false positive blocks real customers, which hurts availability (the A of the CIA triad, episode 2). Teams run new rules in alert-only mode first, measure false positives, and switch on blocking only for precise rules.

Where the sensor sits

NIDS (network IDS) HIDS (host IDS)
Watches A copy of traffic at a choke point (via a switch SPAN port or a network tap) One machine: logins, processes, changes to important files, logs
Sees Every machine's traffic at once What happens inside the machine, even if its traffic is encrypted
Misses Encrypted payloads, traffic that never crosses the sensor Other machines; can be tampered with if the host is fully taken over

You want both.

Evidence: packet capture

Full packet capture saves every byte of every packet, usually as PCAP files (the standard capture file format, opened in tools like Wireshark). It's the strongest evidence of exactly what happened, but it's huge, so it's often kept only for days, while flow records are kept for months. Evidence must be handled carefully so it holds up later (chain of custody: a record of who collected and handled it).

NDR

NDR (network detection and response) products combine flow records, packet capture, signatures, anomaly detection and automated responses (for example isolating a machine) in one system.

Two famous open-source sensors

Tool What it is Think of it as
Suricata "A high performance Network IDS, IPS and Network Security Monitoring engine", open source, "owned by a community-run non-profit foundation, the Open Information Security Foundation (OISF)" (Suricata docs) The alarm: signatures, alerts, inline blocking
Zeek (called Bro until it was renamed in 2018) "A comprehensive platform for network traffic analysis"; first deployed in the mid-1990s; maintained by researchers and engineers at ICSI (Berkeley) and NCSA (Urbana-Champaign) (Zeek FAQ) The detailed notebook: logs every connection, DNS lookup, certificate, which analysts and scripts search

Problem 5: honeypots and deception

Remember the base-rate problem. Here is a detector with almost no false alarms.

Catching a thief Deception
A drawer of marked banknotes no honest employee touches Honeypot: a decoy system (like a fake "old backup database") that no real job ever uses
A fake key labelled "safe" Honeytoken: a fake password, account, file or API key left where only an intruder would find it
Touch it and the alarm rings, almost never falsely A high-confidence alert

Using decoys like this is deception technology.

Demo 5: one decoy and a scan detector

Exploring many machines and ports quickly is a port scan (episode 19). The program counts how many different host:port pairs each source tries.

from collections import defaultdict
HONEYPOTS = {"10.1.9.9"}                       # "old-backup-db": a decoy no real job ever uses
FLOWS = [("10.1.2.15", "10.1.0.5", 443), ("10.1.2.15", "10.1.0.6", 443),        # (source, destination, port)
         ("10.1.3.40", "10.1.0.5", 22), ("10.1.3.40", "10.1.0.6", 22), ("10.1.3.40", "10.1.0.7", 22),
         ("10.1.3.40", "10.1.0.8", 445), ("10.1.3.40", "10.1.0.9", 3389), ("10.1.3.40", "10.1.9.9", 5432),
         ("10.1.2.15", "10.1.0.5", 443)]

touched = defaultdict(set)
for src, dst, port in FLOWS:
    touched[src].add((dst, port))
    if dst in HONEYPOTS:
        print(f"HONEYPOT ALERT: {src} touched decoy {dst}:{port}")
for src, targets in touched.items():
    if len(targets) >= 5:
        print(f"SCAN ALERT: {src} tried {len(targets)} different host:port pairs")
print("normal sources:", [s for s, t in touched.items() if len(t) < 5])

Output:

HONEYPOT ALERT: 10.1.3.40 touched decoy 10.1.9.9:5432
SCAN ALERT: 10.1.3.40 tried 6 different host:port pairs
normal sources: ['10.1.2.15']

10.1.3.40 touched the decoy database, which nothing legitimate ever does, and tried six different host:port pairs: almost certainly our intruder. The normal laptop stays quiet. Three weeks of silence, solved by one decoy.

Problem 6: encrypted traffic

We moved everything to TLS and VPNs (episodes 22, 25), so a network IDS can no longer read payloads; signature matching on encrypted traffic sees only noise. Three answers:

  1. Metadata still works: flows, DNS lookups, certificates, and the server name sent in the TLS handshake (SNI, episode 22). Demos 3 and 5 never read a single payload.
  2. Watch the endpoints, where traffic is decrypted anyway: HIDS, endpoint logs.
  3. TLS inspection on company-managed devices: a firewall decrypts, inspects and re-encrypts. It sees more, but it holds the keys to everyone's traffic (a juicy target), breaks some apps (especially ones that pin certificates, episode 22), and raises privacy questions.

It's a trade-off between visibility and privacy plus new attack surface, not a free win.

The next problem

Every defence so far leans on cryptography. But a perfect lock is useless if the key is pasted into code on GitHub. Next episode: using cryptography correctly: key management and post-quantum cryptography.

The whole chain

  1. Nobody notices → IDS, signatures, SOC, triage.
  2. Encoded attacks slip by → normalise first.
  3. 1,004 false alarms → TP/FP/FN/TN, the base rate, precision, tuning.
  4. New attacks → baseline, anomaly detection, NetFlow/IPFIX.
  5. Block automatically? → IPS, and its false positives.
  6. Where to watch → NIDS, HIDS, PCAP, NDR, Suricata, Zeek.
  7. Too many alarms → honeypots, honeytokens, scan alerts.
  8. Can't read TLS → metadata, endpoints, the TLS inspection trade-off.

...and you just invented a security monitoring system.

Common mistakes (and what they print)

Mistake What you see Why it's wrong Fix
Matching raw request text - GET /files?name=%2e%2e%2f%2e%2e%2fetc/passwd Encoding changes the spelling Normalise (decode), then match
Trusting "99% accurate" alerts: 1014, of which real: 1.0% Attacks are rare (base rate) Tune, add context, measure precision
A noisy baseline backup-box 1800 MB ... z = 2.8 normal Off days inflate the wobble Compare like with like
New rule straight into IPS IPS customer DROPPED (SQL injection) IPS false positive = outage Alert-only first, then block
Logs collected, nobody reads them Three weeks of silence Data isn't detection Alerts, triage, ownership in a SOC
Only a network sensor Encrypted payloads invisible NIDS can't read TLS Add HIDS / endpoint logs, use metadata

Mini project: Ravi's mini SOC

Three detectors (normalised signatures, a flow baseline, a honeypot plus a honeytoken account) over one day's made-up events, with alerts ranked by confidence.

# Ravi's mini SOC: three detectors over one day's made-up events, alerts ranked by confidence
from urllib.parse import unquote
from statistics import mean, stdev

SIGNATURES = {"SQL injection": "' or 1=1", "path traversal": "../"}
HONEYPOTS = {"10.1.9.9"}
HONEYTOKENS = {"svc_backup_old"}
BASELINE_MB = {"pos-server": [40, 42, 38, 41, 39, 44, 40, 43, 37, 41]}

EVENTS = [
    {"type": "http", "src": "192.0.2.10", "req": "GET /item?id=7"},
    {"type": "http", "src": "198.51.100.23", "req": "GET /files?name=%2e%2e%2fetc/passwd"},
    {"type": "flow", "src": "pos-server", "dst": "203.0.113.66", "mb": 4200},
    {"type": "flow", "src": "10.1.3.40", "dst": "10.1.9.9", "mb": 1},
    {"type": "login", "src": "10.1.3.40", "user": "svc_backup_old"},
    {"type": "login", "src": "10.1.2.15", "user": "priya"},
]

def detect(e):
    if e["type"] == "http":
        text = unquote(unquote(e["req"])).lower()              # normalise first
        for name, pattern in SIGNATURES.items():
            if pattern in text: return ("medium", f"signature: {name} from {e['src']}")
    if e["type"] == "flow":
        if e["dst"] in HONEYPOTS: return ("high", f"honeypot {e['dst']} touched by {e['src']}")
        hist = BASELINE_MB.get(e["src"])
        if hist and (e["mb"] - mean(hist)) / stdev(hist) > 3:
            return ("high", f"anomaly: {e['src']} sent {e['mb']} MB to {e['dst']}")
    if e["type"] == "login" and e["user"] in HONEYTOKENS:
        return ("high", f"honeytoken account '{e['user']}' used from {e['src']}")
    return None

alerts = [a for a in map(detect, EVENTS) if a]
for level, text in sorted(alerts, key=lambda a: a[0] != "high"):
    print(f"[{level.upper():6}] {text}")
print(f"{len(EVENTS)} events, {len(alerts)} alerts")

Output:

[HIGH  ] anomaly: pos-server sent 4200 MB to 203.0.113.66
[HIGH  ] honeypot 10.1.9.9 touched by 10.1.3.40
[HIGH  ] honeytoken account 'svc_backup_old' used from 10.1.3.40
[MEDIUM] signature: path traversal from 198.51.100.23
6 events, 4 alerts

All three high-confidence alerts point at the same story: 10.1.3.40 used a honeytoken account and touched the decoy, and the POS server is shipping data out. That correlation (several alerts telling one story) is what an analyst looks for. Ideas to extend it: add a scan detector from Demo 5; give each alert a host so you can group them; print a timeline.

Practice

1. Change the base rate. Re-run Demo 2's detector with 10, 1,000 and 10,000 attacks in 100,000 events. What happens to the share of real alerts?

Solution
import random
random.seed(26)
for attacks in (10, 1_000, 10_000):
    tp = fp = 0
    for i in range(100_000):
        attack = i < attacks
        alert = random.random() < (0.99 if attack else 0.01)
        tp += attack and alert
        fp += (not attack) and alert
    print(f"{attacks:6} attacks in 100,000 events -> {tp + fp:6} alerts, {tp / (tp + fp):6.1%} real")

Output:

    10 attacks in 100,000 events ->   1014 alerts,   1.0% real
  1000 attacks in 100,000 events ->   2009 alerts,  49.4% real
 10000 attacks in 100,000 events ->  10812 alerts,  91.8% real

The detector didn't change; only how common attacks are. Precision depends on the base rate, which is why the same product can be great in one network and useless in another.

2. Fix the backup-box baseline. Compute the backup box's baseline only from days the backup actually ran, and re-check today's 1,800 MB.

Solution
from statistics import mean, stdev
backup = [900, 880, 910, 890, 905, 0, 0, 895, 900, 885, 910, 0, 0, 900]
run_days = [mb for mb in backup if mb > 0]          # compare like with like: only days the backup ran
for name, hist in [("all days", backup), ("backup days", run_days)]:
    m, s = mean(hist), stdev(hist)
    z = (1800 - m) / s
    print(f"{name:11} usual {m:5.0f} +/- {s:4.0f}  today 1800 MB  z = {z:6.1f}  {'ANOMALY' if z > 3 else 'normal'}")

Output:

all days    usual   641 +/-  421  today 1800 MB  z =    2.8  normal
backup days usual   898 +/-   10  today 1800 MB  z =   89.6  ANOMALY

Comparing like with like turns a missed doubling into a clear anomaly.

3. Honeytoken accounts. Two fake accounts exist that no person or job uses. Alert on any login attempt with them.

Solution
HONEYTOKENS = {"svc_backup_old", "admin_test"}      # fake accounts no person or job ever uses
LOGINS = [("09:02", "priya", "10.1.2.15"), ("09:15", "meena", "10.1.2.31"),
          ("02:47", "svc_backup_old", "10.1.3.40"), ("02:48", "admin_test", "10.1.3.40")]
for time, user, src in LOGINS:
    if user in HONEYTOKENS:
        print(f"{time} HONEYTOKEN ALERT: '{user}' tried from {src}: isolate {src}")
print("ordinary logins:", [u for _, u, _ in LOGINS if u not in HONEYTOKENS])

Output:

02:47 HONEYTOKEN ALERT: 'svc_backup_old' tried from 10.1.3.40: isolate 10.1.3.40
02:48 HONEYTOKEN ALERT: 'admin_test' tried from 10.1.3.40: isolate 10.1.3.40
ordinary logins: ['priya', 'meena']

4. Precision, recall, false-positive rate. Compute all three for the vendor detector (TP 10, FP 1,004, FN 0, TN 98,986) and a tuned detector (TP 9, FP 40, FN 1, TN 99,950).

Solution
def scores(tp, fp, fn, tn):
    precision = tp / (tp + fp)          # of the alerts, how many were real?
    recall = tp / (tp + fn)             # of the real attacks, how many did we catch?
    fpr = fp / (fp + tn)                # of the normal events, how many raised an alarm?
    return precision, recall, fpr
for name, counts in [("vendor detector", (10, 1004, 0, 98986)), ("tuned detector", (9, 40, 1, 99950))]:
    p, r, f = scores(*counts)
    print(f"{name:16} precision {p:6.1%}  recall {r:6.1%}  false-positive rate {f:6.3%}")

Output:

vendor detector  precision   1.0%  recall 100.0%  false-positive rate 1.004%
tuned detector   precision  18.4%  recall  90.0%  false-positive rate 0.040%

Tuning traded a little recall (one missed attack) for 18 times better precision. Whether that's worth it is a judgement call the SOC makes deliberately, ideally covering the gap with another detector.

5. Concept check. For each, IDS or IPS, NIDS or HIDS? (a) Block a known worm's exact network pattern at the internet edge; (b) notice that /etc/passwd changed on one server; (c) try out a brand-new, untested rule; (d) see what happens inside encrypted sessions on a laptop.

Solution

(a) An IPS (inline NIDS), because the signature is precise. (b) A HIDS (file integrity monitoring on that host). (c) IDS / alert-only mode first, to measure false positives. (d) A HIDS / endpoint sensor, where the traffic is already decrypted.

Quick quiz

Four alerts arrive at the SOC. Which is most likely a real attack?

  • A: signature union select in a search box
  • B: a laptop sent 20% more data than usual
  • C: a login touched the decoy database
  • D: a server is busier on Monday morning
Answer

C. A honeypot has no legitimate users, so any touch is suspicious and false positives are very rare. A can be a customer's search (Demo 4), B is within normal wobble, and D is a normal weekly pattern.

Interview questions

  1. IDS vs IPS? An IDS monitors (usually a copy of traffic) and alerts; an IPS sits inline and can block. IPS false positives cause outages, so rules are proven in alert mode first.
  2. Signature-based vs anomaly-based detection? Signatures match known attack patterns: precise, explainable, blind to new attacks and easy to evade without normalisation. Anomaly detection learns a baseline and flags deviations: can catch new attacks, but produces false positives and needs tuning.
  3. What's a false positive vs a false negative, and which is worse? FP: alert on benign activity (wastes time, causes fatigue). FN: missed attack. FNs are usually worse, but floods of FPs cause FNs indirectly via alert fatigue.
  4. Explain the base-rate fallacy in detection. When attacks are rare, even a small false-positive rate on a huge number of benign events produces many more false alarms than true alerts, so precision is low despite high "accuracy".
  5. NIDS vs HIDS? NIDS watches network traffic at choke points and sees many hosts at once but not encrypted payloads; HIDS watches one host's logs, processes and files and sees post-decryption activity.
  6. What is NetFlow/IPFIX, and why is it useful? Flow records summarising conversations (addresses, ports, bytes, times), not contents. Cheap to store long-term, work on encrypted traffic, good for baselines, exfiltration and lateral-movement detection.
  7. When do you want full packet capture? For incident investigation and evidence: exact contents of what happened. It's expensive, so it's kept briefly or captured selectively.
  8. What are Suricata and Zeek? Suricata (OISF): open-source IDS/IPS/NSM engine with signatures and inline blocking. Zeek (formerly Bro): open-source network traffic analysis framework producing rich logs for analysis and scripting.
  9. What is a honeypot / honeytoken, and why are their alerts valuable? Decoy systems or credentials with no legitimate use; any interaction is suspicious, so alerts are high-confidence with very few false positives.
  10. How do you keep visibility when everything is encrypted? Use metadata (flows, DNS, SNI, certificates), endpoint telemetry, and selectively TLS inspection on managed devices, weighing privacy, risk and breakage.

Glossary

Term Meaning in plain words Example
Prevention Controls that decide what is allowed Firewalls, VPNs
Detection Noticing an attack that prevention let through The burglar alarm
Initial access How an attacker first gets in (episode 4) A phished password
Lateral movement Moving from one machine to others inside a network Server after server
IDS (intrusion detection system) Software that watches activity and alerts on likely attacks Demo 1
Alert A message telling defenders something suspicious happened ALERT: traversal
Signature A pattern matching a known attack "../"
Signature-based detection Detecting by matching signatures Demo 1
SQL injection An attack that sneaks database commands into input (episode 38) ' OR 1=1--
Path traversal An attack using ../ to climb out of an allowed folder (episode 47) ../../etc/passwd
URL encoding Writing characters as % + hex code in web addresses %2e = .
Evasion Changing an attack's form so a detector misses it URL-encoding the attack
Normalisation Converting input to one standard form before matching Decode, then lowercase
Zero-day An attack or flaw unknown to defenders (episode 8) No signature exists yet
Security analyst The person who investigates alerts The guard
Triage Sorting and checking alerts to decide which matter Real thief or the cat?
SOC Security operations centre: the team that monitors and responds The team watching Ravi's alerts
True positive (TP) Real attack, and an alert 10 in Demo 2
False positive (FP) Normal activity, but an alert 1,004 in Demo 2
False negative (FN) Real attack, and silence The backup-box doubling in Demo 3
True negative (TN) Normal activity, and silence 98,986 in Demo 2
Base rate How common the thing you're looking for is 10 attacks in 100,000 events
Base-rate fallacy Ignoring the base rate when judging a detector "99% accurate" yet 1% of alerts real
Alert fatigue Analysts ignoring alerts because most are false Real attacks get missed
Precision Share of alerts that are real: TP / (TP + FP) 1.0% in Demo 2
Recall (detection rate) Share of real attacks caught: TP / (TP + FN) 100% in Demo 2
False-positive rate Share of normal events that alert: FP / (FP + TN) ~1%
Tuning Adjusting rules to the environment to cut false positives Practice 4
Baseline A record of what normal looks like 14 days of flows
Anomaly Activity far from the baseline 4,200 MB from the POS server
Anomaly-based detection Alerting on deviations from the baseline Demo 3
Mean The average 40 MB a day
Standard deviation The size of the usual wobble around the mean ± 2 MB
z-score How many standard deviations a value is from the mean 2176.0
Flow record A summary of one conversation: who, whom, ports, when, how much; no contents One line of NetFlow
NetFlow The flow-record format that started at Cisco Exported by routers
IPFIX IP Flow Information Export: the IETF standard for flow records NetFlow's open successor
Metadata Data about traffic, not its contents Flows, DNS, SNI
Exfiltration Taking stolen data out of a network 4.2 GB to 203.0.113.66
IPS (intrusion prevention system) An inline detector that can block Demo 4, MODE = "IPS"
Inline Traffic must pass through the device An IPS between internet and servers
Availability Systems working when needed (the A of CIA, episode 2) The blocked customer
Alert-only mode Running a rule that alerts but doesn't block New rules start here
NIDS Network IDS: watches traffic on the wire A sensor at the internet link
HIDS Host IDS: watches one machine's logins, processes, files /etc/passwd changed
Choke point A place all traffic must pass The internet link
SPAN port / tap A switch port that copies traffic / a device that copies traffic off a cable Feeds a NIDS
PCAP / full packet capture Saving every byte of every packet; .pcap files Evidence for an investigation
Chain of custody A record of who collected and handled evidence Keeps PCAPs trustworthy
NDR Network detection and response: flows, PCAP, detection and response in one Isolating an infected host
Suricata Open-source network IDS/IPS/NSM engine from the OISF The alarm
OISF Open Information Security Foundation, the non-profit behind Suricata —
Zeek (formerly Bro) Open-source network traffic analysis framework that writes rich logs The notebook
Network security monitoring (NSM) Collecting and analysing network data to find intrusions Suricata + Zeek
Honeypot A decoy system no real job uses 10.1.9.9, "old-backup-db"
Honeytoken A fake credential, file or key that only an intruder would use svc_backup_old
Deception technology Using decoys to detect intruders Honeypots + honeytokens
Port scan Probing many hosts or ports quickly to find services (episode 19) 6 host:port pairs in a row
Correlation Linking several alerts into one story Mini project
SNI Server Name Indication: the site name sent in the TLS handshake (episode 22) Visible even with TLS
TLS inspection Decrypting, inspecting and re-encrypting HTTPS on managed devices NGFW feature (episode 24)
Endpoint A device people use or a server: laptop, phone, server Where HIDS runs

Summary

  • Prevention fails sometimes; detection notices. An IDS alerts; analysts in a SOC triage.
  • Signatures catch known attacks, but only after normalisation; they can't catch new ones.
  • Rare attacks mean false positives dominate (the base-rate fallacy): a "99% accurate" detector gave 1% real alerts. Measure precision and recall, and tune.
  • Anomaly detection compares against a baseline, often built from NetFlow/IPFIX flow records; baselines must compare like with like.
  • An IPS blocks inline, so its false positives are outages: alert-only first. NIDS watch the wire, HIDS watch the host; PCAP is the strongest evidence; NDR combines them. Suricata is the alarm, Zeek the notebook.
  • Honeypots and honeytokens give high-confidence alerts; scan detection spots exploration.
  • Encryption hides payloads: rely on metadata and endpoints, and weigh TLS inspection carefully.

Next episode: using cryptography correctly: don't roll your own, the key lifecycle, KMS and HSMs, envelope encryption, timing side channels, crypto agility and post-quantum cryptography.

Sources: Suricata documentation, "What is Suricata" (docs.suricata.io); Zeek FAQ (old.zeek.org). Code outputs from Python 3.13. Fetched 3 Nov 2026.