Intrusion Detection and Network Security Monitoring
How an IDS differs from an inline IPS and where each sits, signature versus anomaly detection, the anatomy of a Suricata rule and how to tune it with address variables and sticky buffers, and what Zeek logs add.
Contentsand lesson path
On this page
- Why it matters
- IDS or IPS: placement and trade-offs
- Signatures, anomalies and the data behind them
- Anatomy of a Suricata rule, and how to tune one
- Check your understanding
- Apply it
- Review prompt
Lessons of Network Defense & Monitoring
- Zones, Trust and Deny-by-Default Design Worked example · 25 min
- Intrusion Detection and Network Security Monitoring Concept · 15 min
- Running Suricata and Zeek on a Lab Network Lab · 30 min
- Hunting Scans, Beacons and Floods in Captures and Flows Lab · 30 min
- Securing the Edge: NAC, Wi-Fi, ZTNA and DDoS Escalation Concept · 25 min
- Network Defense Check Knowledge check · 10 questions
What you will learn
- Deploy an IDS/IPS and a network security monitor (for example Suricata and Zeek) on a lab network and write or tune a rule for a specific threat.
Prerequisites: Networking Basics
01. Why it matters
A firewall decides which flows may pass. It does not tell you what happened inside an allowed flow. Malware calling home on port 443, an attacker probing an admin page on your public website, or a laptop sweeping the server subnet can all use flows the firewall permits. Network security monitoring (NSM) is the practice of collecting and analysing network data so that you can detect such activity and investigate it afterwards.
Two open-source tools cover most of NSM. Suricata is an intrusion detection system (IDS): it inspects traffic against rules and raises alerts, and it can also run as an intrusion prevention system (IPS) that drops matching traffic. Zeek is a network monitor: it records what each connection and protocol transaction looked like, whether or not anything looked bad. This lesson explains how they work and how to write a rule that catches a real threat without burying analysts in noise. The next lesson runs both on a capture.
02. IDS or IPS: placement and trade-offs
An IDS is passive. It receives a copy of the traffic from a switch SPAN port (a port that mirrors other ports) or from a network tap (a device that copies the signal on a cable). Because it is not in the path, a crash or a slow rule cannot break production traffic. The cost is that it can only alert. NIST SP 800-94 also notes that a SPAN port may drop copies when the switch is busy, so a passive sensor can miss traffic.
An IPS is inline: traffic passes through it, for example through an nftables queue rule (Suricata in NFQUEUE mode) or as a bridge between two interfaces (AF_PACKET inline mode). Now a drop rule really stops the attack, but the sensor becomes part of the network. A false positive blocks a real user, and an overloaded or crashed sensor blocks everyone unless you plan for it. The Suricata documentation describes the safety valves: the nftables queue ... bypass option lets packets through when no program is listening on the queue, which keeps the link up but also removes the blocking. In IPS mode, Suricata also sets its exception policies to drop by default, so traffic it cannot parse is blocked rather than waved through.
Most teams therefore start in IDS mode, measure which rules fire and how often they are wrong, and only then switch a small set of high-confidence rules to drop.
03. Signatures, anomalies and the data behind them
Signature detection matches known patterns: a URI, a byte string, a TLS server name. It is precise and easy to explain, but it only finds what someone has already described. Anomaly detection compares traffic with a baseline of normal behaviour, for example a workstation that suddenly talks to a never-seen host every 60 seconds. It can find new threats, but it needs a good baseline and produces more questions than answers.
Both need data. NSM teams usually keep four kinds, from cheapest to most expensive:
- alerts: rule matches, small and actionable;
- flow records: one line per connection with addresses, ports, bytes and duration, such as NetFlow, IPFIX or Zeek
conn.log; - protocol metadata: what was said inside each protocol, such as DNS names, HTTP URIs and TLS server names;
- full packet capture: every byte, very useful but expensive to keep for long.
Zeek produces the middle two. It writes one log per protocol: conn.log for every connection, dns.log, http.log, ssl.log for TLS handshakes, notice.log for findings from its scripts, and weird.log for protocol violations. Protocol log lines carry a uid that links them to their connection in conn.log. Zeek and Suricata can both add a Community ID, a hash of the connection's addresses, ports and protocol that is the same in both tools, so you can jump from a Suricata alert to the matching Zeek records. This matters because an alert only tells you that a pattern matched; the logs tell you what else that host did.
04. Anatomy of a Suricata rule, and how to tune one
A rule has an action, a header and options. In alert http $EXTERNAL_NET any -> $HOME_NET any (...), the action is alert (others include drop, reject and pass), the protocol is http, and the header says from any port on external addresses to any port on internal ones. $HOME_NET and $EXTERNAL_NET are address variables defined in suricata.yaml; by default EXTERNAL_NET is !$HOME_NET, everything that is not home. Options sit in brackets and end with semicolons: msg is the alert text, sid a unique rule number and rev its revision.
The most important options for precision are sticky buffers. A sticky buffer names one parsed field, and every content match after it looks only in that field. http.uri; content:"/admin"; looks in the request URI only. tls.sni; content:"cdn-sync.example"; looks at the Server Name Indication, the host name a client sends in clear text in its TLS ClientHello. That is why you can match a TLS destination without decrypting anything. The reverse also holds: HTTP keywords such as http.uri and http.host see nothing inside HTTPS unless the traffic is decrypted before the sensor. In TLS 1.3, the handshake messages after the ServerHello, including the server certificate, are encrypted, so the SNI, and the DNS lookup before it, are what an observer still sees. Encrypted Client Hello (ECH) hides the real server name, and encrypted DNS hides the lookup, so this visibility is shrinking.
Tuning means narrowing a noisy rule to the threat you care about. The main tools are:
- restrict the header: if internal admins trigger an "admin page" rule all day, change the source to
$EXTERNAL_NET; - use a sticky buffer so the pattern cannot match in a header, a cookie or a body by accident;
- add anchors such as
startswithandendswith, andflow:established,to_serverso only client requests in real sessions are checked; - use thresholds or suppression for a source you have checked and accepted.
Changing alert to drop is not tuning: a noisy rule that drops traffic blocks users. Lowering an alert's priority hides the noise but keeps it. And nocase widens a match, which is right for case-insensitive names such as SNI, but it does not reduce false positives.
Sticky buffers come before the content they apply to. The older style, content:"/admin"; http_uri;, put a modifier after the content, and mixing the two styles is a common mistake. Suricata checks rules with -T, which loads the configuration and rules and then exits. Save the two rules below as check.rules; the second one has the order wrong. The test was run with Suricata 8.0.0 from the Alpine 3.23 packages.
alert http $EXTERNAL_NET any -> $HOME_NET any (msg:"LAB admin path"; \
flow:established,to_server; http.uri; content:"/admin"; startswith; \
sid:1000002; rev:1;)
alert http $EXTERNAL_NET any -> $HOME_NET any (msg:"LAB admin path, wrong order"; \
flow:established,to_server; content:"/admin"; http.uri; \
sid:1000005; rev:1;)docker run --rm -v "$PWD:/lab" -w /lab alpine:3.23 sh -c 'apk add -q suricata &&
suricata -T -S check.rules -l /tmp > test.log 2>&1; echo "exit=$?"'
grep -E '^E: (detect-parse|suricata)' test.logexit=1
E: detect-parse: rule 1000005 setup buffer http_uri but didn't add matches to it
E: suricata: Loading signatures failed.Suricata set up the http.uri buffer but found no content after it, and one bad rule makes the whole test fail with exit code 1. Move http.uri; before content:"/admin";, run the same command again, and it prints exit=0 with no errors. Run -T in your deployment pipeline before every rule change, so a typo fails the build instead of a sensor.
05. Check your understanding
06. Apply it
For the skill project, write down your sensor design before you build it:
- where each sensor sits in the zone layout from lesson 1 (which links it sees, SPAN or tap), and whether it runs as IDS or IPS, with a reason;
- the value of
HOME_NETfor your lab; - one rule for a specific threat, with its header, sticky buffer and anchors, and a sentence on what false positives it could still produce.
In Running Suricata and Zeek on a Lab Network you test exactly this kind of rule against a capture.
07. Review prompt
Without looking back, explain:
- What you gain and what you risk when a sensor moves from a SPAN port to inline.
- The difference between an alert, a flow record and protocol metadata, with one question each can answer.
- What a sticky buffer is, and why
tls.sniworks without decryption. - Three ways to tune a noisy rule, and two changes that look like tuning but are not.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.