Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 3 of 6 · Lab · 30 min · revision 2

Running Suricata and Zeek on a Lab Network

Build a seeded capture of lab traffic, run Suricata 8 over it with a noisy rule and then tuned rules using $EXTERNAL_NET, http.uri, tls.sni and dns.query, run Zeek 9.0 over the same capture, and join an alert to its Zeek records by Community ID.

Contentsand lesson path

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.
  • Analyse packet captures, flow data and connection logs to identify scanning, lateral movement, beaconing, DNS anomalies or a volumetric flood, and for a flood follow a DDoS runbook that escalates to the upstream or scrubbing provider.

Prerequisites: Networking Basics

01. Goal and setup

You will run a real IDS and a real network monitor over the same traffic and use them together. The traffic comes from a capture that you generate with a script, so everyone gets the same packets with the same timestamps. It contains internal admins using an admin page, an internet visitor whose request only mentions /admin in a header, an internet host probing the admin login, and a workstation that looks up and connects to a known command-and-control (C2) name over TLS.

Reading a capture with -r exercises the same detection engine and the same rules as a live sensor on a SPAN port. What it skips is the capture tuning (interfaces, packet loss, CPU), which you need on a real link; the last exercise in Apply it runs the same rules live on the lesson 1 firewall.

You need: Docker, Python 3.10 or later, and about 250 MB of disk for two containers. Tested versions: Scapy 2.8.0; Suricata 8.0.0 from the alpine:3.23 packages (the upstream 8.0 line was at 8.0.8 in November 2026, and the rule syntax below is the same); Zeek 9.0.1, the current long-term support (LTS) line, from the Zeek project's package repository for Debian 12 (bookworm).

Folder layout at the end of the lab
nsm-lab/
├── pcaplib.py, make_lab03.py   step 2: build lab03.pcap
├── naive.rules, local.rules    steps 4 and 5: Suricata rules
├── out-naive/, out/            Suricata output (eve.json)
├── install-zeek.sh, zeek-obs.asc   step 6
└── zeek/                       Zeek logs

02. Step 1: Create the folder and a Python environment

Terminal
mkdir nsm-lab && cd nsm-lab
python3 -m venv .venv
.venv/bin/pip install -q scapy==2.8.0
.venv/bin/python -c "import scapy; print(scapy.__version__)"
Expected output
2.8.0

03. Step 2: Generate the capture

Scapy builds packets layer by layer. pcaplib.py makes complete TCP conversations (handshake, request, response, close) because Suricata and Zeek only parse application protocols in sessions they can follow. client_hello builds a minimal TLS ClientHello by hand, so you can see that the server name sits in plain bytes in the first packet.

Python · nsm-lab/pcaplib.py
"""Small helpers that build complete, deterministic TCP, UDP and TLS packets."""
import struct

from scapy.all import DNS, DNSQR, DNSRR, IP, TCP, UDP, Ether

MAC_A, MAC_B = "02:00:00:00:00:0a", "02:00:00:00:00:0b"


def pkt(t, src, dst, l4, data=b""):
    p = Ether(src=MAC_A, dst=MAC_B) / IP(src=src, dst=dst) / l4
    if data:
        p = p / data
    p.time = t
    return p


def tcp_session(t, cli, srv, sport, dport, request, response=b""):
    """Handshake, one request, one optional response, then a clean close."""
    c, s, out = 1000, 5000, []

    def add(dt, to_server, flags, data=b""):
        if to_server:
            l4 = TCP(sport=sport, dport=dport, flags=flags, seq=c, ack=s)
            out.append(pkt(t + dt, cli, srv, l4, data))
        else:
            l4 = TCP(sport=dport, dport=sport, flags=flags, seq=s, ack=c)
            out.append(pkt(t + dt, srv, cli, l4, data))

    add(0.00, True, "S")
    c += 1
    add(0.01, False, "SA")
    s += 1
    add(0.02, True, "A")
    add(0.03, True, "PA", request)
    c += len(request)
    if response:
        add(0.04, False, "PA", response)
        s += len(response)
    add(0.05, True, "FA")
    c += 1
    add(0.06, False, "FA")
    s += 1
    add(0.07, True, "A")
    return out


def http_get(t, cli, srv, sport, path, extra=""):
    req = f"GET {path} HTTP/1.1\r\nHost: {srv}\r\nUser-Agent: lab\r\n{extra}\r\n"
    resp = "HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nok"
    return tcp_session(t, cli, srv, sport, 80, req.encode(), resp.encode())


def client_hello(sni):
    """A minimal TLS ClientHello. The server name travels in clear text."""
    name = sni.encode()
    ext = struct.pack("!HHHBH", 0, len(name) + 5, len(name) + 3, 0, len(name)) + name
    body = (b"\x03\x03" + bytes(32) + b"\x00"         # version, random, session id
            + b"\x00\x04\x13\x01\xc0\x2f"  # two cipher suites
            + b"\x01\x00"                      # no compression
            + struct.pack("!H", len(ext)) + ext)
    hs = b"\x01" + len(body).to_bytes(3, "big") + body
    return b"\x16\x03\x01" + struct.pack("!H", len(hs)) + hs


def dns_pair(t, cli, resolver, sport, qid, name, qtype="A", answer=None, rcode=0):
    """One DNS query and its response."""
    q = DNS(id=qid, rd=1, qd=DNSQR(qname=name, qtype=qtype))
    an = DNSRR(rrname=name, type=qtype, ttl=300, rdata=answer) if answer else None
    r = DNS(id=qid, qr=1, rd=1, ra=1, rcode=rcode,
            qd=DNSQR(qname=name, qtype=qtype), an=an)
    return [pkt(t, cli, resolver, UDP(sport=sport, dport=53), q),
            pkt(t + 0.01, resolver, cli, UDP(sport=53, dport=sport), r)]
Python · nsm-lab/make_lab03.py
"""Write lab03.pcap: admin-path requests, a TLS session to a C2 name, DNS."""
from datetime import datetime, timezone

from scapy.all import wrpcap

from pcaplib import client_hello, dns_pair, http_get, tcp_session

T0 = datetime(2026, 11, 2, 9, 0, tzinfo=timezone.utc).timestamp()
WEB, RESOLVER = "10.1.30.10", "10.1.20.53"
pkts = []
for i in range(3):  # internal admins use the admin console every minute
    pkts += http_get(T0 + 60 * i, "10.1.99.10", WEB, 40001 + i, "/admin/")
pkts += http_get(T0 + 200, "203.0.113.77", WEB, 51000, "/blog/",
                 "Referer: http://news.example.com/admin/tips\r\n")
pkts += http_get(T0 + 260, "203.0.113.50", WEB, 52000, "/admin/login")
pkts += dns_pair(T0 + 300, "10.1.10.23", RESOLVER, 33001, 0x1001,
                 "cdn-sync.example", answer="198.51.100.66")
pkts += tcp_session(T0 + 301, "10.1.10.23", "198.51.100.66", 45001, 443,
                    client_hello("cdn-sync.example"))
pkts += dns_pair(T0 + 320, "10.1.10.15", RESOLVER, 33002, 0x1002,
                 "www.example.com", answer="203.0.113.80")
pkts += tcp_session(T0 + 321, "10.1.10.15", "203.0.113.80", 45002, 443,
                    client_hello("www.example.com"))
pkts.sort(key=lambda p: p.time)
wrpcap("lab03.pcap", pkts)
print(f"wrote lab03.pcap: {len(pkts)} packets")
Terminal
.venv/bin/python make_lab03.py
sha256sum lab03.pcap
Expected output (same hash with Scapy 2.8.0)
wrote lab03.pcap: 58 packets
062a97e8a168713e8e9beb0916b66419069f536116873895554870eba7b0b03f  lab03.pcap

04. Step 3: Start a Suricata container

Terminal
docker run -d --name nsm-suricata -v "$PWD:/lab" -w /lab alpine:3.23 sleep infinity
docker exec nsm-suricata apk add -q suricata jq
docker exec nsm-suricata suricata -V
Expected output (a later Alpine update may show a higher 8.0.x)
This is Suricata version 8.0.0 RELEASE

05. Step 4: Run a naive rule and count the noise

The goal is to detect internet hosts probing the admin pages of the website. A first attempt matches /admin anywhere in traffic to the home network. Save it as naive.rules. In the command, -r reads the capture, -S loads only this rule file, -l sets the output folder, -k none skips checksum checks (captures taken on a sending host often have bad checksums), and --set defines HOME_NET as the lab network.

Suricata rule · nsm-lab/naive.rules
alert http any any -> $HOME_NET any (msg:"LAB admin path"; content:"/admin"; \
    sid:1000001; rev:1;)
Terminal
mkdir -p out-naive
docker exec nsm-suricata suricata -r lab03.pcap -S naive.rules -l out-naive \
  -k none --runmode single --set vars.address-groups.HOME_NET="[10.1.0.0/16]" \
  | grep 'pcap: read'
docker exec nsm-suricata jq -r 'select(.event_type == "alert")
  | [.timestamp[11:19], .src_ip, .dest_ip, .alert.signature] | @tsv' out-naive/eve.json
Expected output (columns are tab-separated)
i: pcap: read 1 file, 58 packets, 3982 bytes
09:00:00    10.1.99.10    10.1.30.10    LAB admin path
09:01:00    10.1.99.10    10.1.30.10    LAB admin path
09:02:00    10.1.99.10    10.1.30.10    LAB admin path
09:03:20    203.0.113.77    10.1.30.10    LAB admin path
09:04:20    203.0.113.50    10.1.30.10    LAB admin path

Suricata writes its results to eve.json, one JSON event per line: alerts, but also http, dns, flow and other events. Five alerts, and only the last one is the threat. Three come from 10.1.99.10, an administrator on the management network doing their job. The fourth comes from 203.0.113.77, whose request was for /blog/; the string /admin appeared only in its Referer header. A rule that fires five times for one real event trains analysts to ignore it.

06. Step 5: Tune the rule and add TLS and DNS detections

Save local.rules. Rule 1000002 changes three things: the source is $EXTERNAL_NET, the sticky buffer http.uri limits the match to the request URI, and startswith anchors it to the start of the path. flow:established,to_server checks only client-to-server data in a real session. Rule 1000003 matches the C2 name in tls.sni with nocase (host names are case-insensitive) and endswith, so x.cdn-sync.example matches too. So would notcdn-sync.example; adding the dotprefix transform before content:".cdn-sync.example" closes that gap. Rule 1000004 catches the DNS lookup of the same name. The --set for community-id asks Suricata to add a Community ID to each event; outputs.1 is the position of eve-log in this suricata.yaml.

Suricata rules · nsm-lab/local.rules
alert http $EXTERNAL_NET any -> $HOME_NET any (msg:"LAB external admin path request"; \
    flow:established,to_server; http.uri; content:"/admin"; startswith; \
    classtype:web-application-attack; sid:1000002; rev:1;)
alert tls $HOME_NET any -> $EXTERNAL_NET any (msg:"LAB TLS to known C2 name"; \
    flow:established,to_server; tls.sni; content:"cdn-sync.example"; nocase; endswith; \
    classtype:trojan-activity; sid:1000003; rev:1;)
alert dns $HOME_NET any -> any any (msg:"LAB DNS lookup of known C2 name"; \
    dns.query; content:"cdn-sync.example"; nocase; endswith; \
    classtype:trojan-activity; sid:1000004; rev:1;)
Terminal
mkdir -p out
docker exec nsm-suricata suricata -r lab03.pcap -S local.rules -l out \
  -k none --runmode single --set vars.address-groups.HOME_NET="[10.1.0.0/16]" \
  --set outputs.1.eve-log.community-id=true | grep 'pcap: read'
docker exec nsm-suricata jq -r 'select(.event_type == "alert")
  | [.timestamp[11:19], .src_ip, .alert.signature_id, .community_id]
  | @tsv' out/eve.json
Expected output (columns are tab-separated)
i: pcap: read 1 file, 58 packets, 3982 bytes
09:04:20    203.0.113.50    1000002    1:hQ6azrTzFsYFb+lquCPFJhMrq4w=
09:05:00    10.1.10.23    1000004    1:beq4FuUSji1wZ0em+J3IZpUjljc=
09:05:01    10.1.10.23    1000003    1:MZKTY2Mic3Kl6njuz3iJYhjDknw=

One web alert, for the real probe, plus the DNS lookup and the TLS connection to the C2 name. Each tuning step removes a different false positive. When this lab was built, a version with only the $EXTERNAL_NET change still alerted on the Referer request; the sticky buffer removed it. No decryption was needed for rule 1000003: the name came from the ClientHello.

07. Step 6: Install Zeek and run it over the same capture

Zeek publishes Debian packages through the openSUSE Build Service. The zeek-9.0-core package installs Zeek under /opt/zeek without the cluster tools, which this lab does not need. Download the repository signing key on your host, then save the install script. apt checks every package against that key, which is why the repository URL can be plain HTTP: the slim image ships without the CA certificates that HTTPS needs.

Shell · nsm-lab/install-zeek.sh
#!/bin/sh
# Install Zeek 9.0 (LTS line) from the Zeek project's openSUSE Build Service repo.
set -e
REPO=http://download.opensuse.org/repositories/security:/zeek/Debian_12/
echo "deb [signed-by=/lab/zeek-obs.asc] $REPO /" > /etc/apt/sources.list.d/zeek.list
apt-get update -qq
apt-get install -y -qq --no-install-recommends zeek-9.0-core "$@" > /dev/null
/opt/zeek/bin/zeek --version
Terminal
KEY=https://download.opensuse.org/repositories/security:zeek/Debian_12/Release.key
curl -fsSL "$KEY" -o zeek-obs.asc
docker run -d --name nsm-zeek -v "$PWD:/lab" -w /lab debian:12-slim sleep infinity
docker exec nsm-zeek sh /lab/install-zeek.sh
mkdir -p zeek
docker exec nsm-zeek sh -c 'cd zeek && /opt/zeek/bin/zeek -C \
  -r ../lab03.pcap policy/protocols/conn/community-id-logging && ls'
Expected output (apt may also print a debconf notice)
/opt/zeek/bin/zeek version 9.0.1
conn.log
dns.log
files.log
http.log
packet_filter.log
ssl.log

-C tells Zeek to ignore checksums, like -k none for Suricata. The script community-id-logging adds a community_id column to conn.log. Zeek ran no rules. It wrote one log per protocol it recognised, for every connection.

08. Step 7: Read the Zeek logs

By default Zeek writes tab-separated logs with a header. zeek-cut prints the columns you name, and -u shows timestamps in UTC.

Terminal
Z="docker exec -i nsm-zeek /opt/zeek/bin/zeek-cut"
$Z -u ts id.orig_h id.resp_h id.resp_p service conn_state history < zeek/conn.log
echo; $Z id.orig_h method uri referrer < zeek/http.log
echo; $Z id.orig_h query answers rcode_name < zeek/dns.log
echo; $Z id.orig_h id.resp_h server_name < zeek/ssl.log
Expected output (columns are tab-separated)
2026-11-02T09:00:00+0000    10.1.99.10    10.1.30.10    80    http    SF    ShADdFf
2026-11-02T09:01:00+0000    10.1.99.10    10.1.30.10    80    http    SF    ShADdFf
2026-11-02T09:02:00+0000    10.1.99.10    10.1.30.10    80    http    SF    ShADdFf
2026-11-02T09:03:20+0000    203.0.113.77    10.1.30.10    80    http    SF    ShADdFf
2026-11-02T09:04:20+0000    203.0.113.50    10.1.30.10    80    http    SF    ShADdFf
2026-11-02T09:05:01+0000    10.1.10.23    198.51.100.66    443    ssl    SF    ShADFf
2026-11-02T09:05:00+0000    10.1.10.23    10.1.20.53    53    dns    SF    Dd
2026-11-02T09:05:20+0000    10.1.10.15    10.1.20.53    53    dns    SF    Dd
2026-11-02T09:05:21+0000    10.1.10.15    203.0.113.80    443    ssl    SF    ShADFf

10.1.99.10    GET    /admin/    -
10.1.99.10    GET    /admin/    -
10.1.99.10    GET    /admin/    -
203.0.113.77    GET    /blog/    http://news.example.com/admin/tips
203.0.113.50    GET    /admin/login    -

10.1.10.23    cdn-sync.example    198.51.100.66    NOERROR
10.1.10.15    www.example.com    203.0.113.80    NOERROR

10.1.10.23    198.51.100.66    cdn-sync.example
10.1.10.15    203.0.113.80    www.example.com

conn.log is a flow record for every connection, including the ones no rule cared about. conn_state SF means a normal start and finish, and history spells out what happened: S SYN, h SYN-ACK, A ACK, D and d data from each side, F and f FIN, with upper case for the originator. http.log shows why the naive rule misfired: the /admin string sits in the referrer column. ssl.log holds the server name of both TLS sessions, the benign one too, which is what you need when a new C2 name is published and you want to know who contacted it last week.

09. Step 8: Join an alert to its Zeek records

Take the Community IDs of alerts 1000002 and 1000003 from step 5 and look them up in conn.log. Both tools computed the same hash from the same five values (addresses, ports, protocol), so no clock matching is needed.

Terminal
docker exec -i nsm-zeek /opt/zeek/bin/zeek-cut id.orig_h id.resp_h \
  id.resp_p service orig_bytes community_id < zeek/conn.log \
  | grep -F -e '1:MZKTY2Mic3Kl6njuz3iJYhjDknw=' -e '1:hQ6azrTzFsYFb+lquCPFJhMrq4w='
docker rm -f nsm-suricata nsm-zeek
Expected output (columns are tab-separated)
203.0.113.50    10.1.30.10    80    http    64    1:hQ6azrTzFsYFb+lquCPFJhMrq4w=
10.1.10.23    198.51.100.66    443    ssl    79    1:MZKTY2Mic3Kl6njuz3iJYhjDknw=

From here an analyst pivots: same host in dns.log (it resolved cdn-sync.example one second before), same destination in conn.log over the past days, same server name in ssl.log from other hosts. That is the NSM workflow in short: the alert says where to look, and the logs say what happened.

10. Troubleshooting

11. Check your understanding

Practice check · 3 questions

Rules and logs in this lab

Three questions about what you ran.

Q1. You rerun step 5 without the `--set vars.address-groups.HOME_NET=...` option. The packaged `suricata.yaml` sets `HOME_NET` to the three RFC 1918 private ranges. What happens to the alerts?
Q2. An alert for rule 1000003 arrives. You want the bytes sent and the protocol Zeek saw for that exact connection. What is the most reliable join?
Q3. You tighten rule 1000003 to `tls.sni; dotprefix; content:".cdn-sync.example"; nocase; endswith;`. Which TLS server names does it alert on now: `cdn-sync.example`, `x.cdn-sync.example`, `mycdn-sync.example`?
Practice only: not graded, not saved, not evidence.

12. Apply it

Extend the lab towards the skill project:

  • Add to make_lab03.py an internal host fetching /admin/backup.zip from the internet, and write a rule with the right header and buffer for that outbound case. Rerun steps 2 and 5 and check that only the new request alerts.
  • Write a one-paragraph analyst note for alert 1000003: what fired, which logs you checked, what you concluded and what you would do next.
  • Go live: rebuild the lesson 1 lab with suricata added to its apk add line (before ip link set eth0 down, which cuts the container off from the package mirror), copy local.rules into the lesson 1 lab folder (mounted at /lab), run suricata -i dmz -S /lab/local.rules -l /tmp -k none in the background inside zones-fw, and send a cleartext request for /admin to 10.1.30.10 from the inet namespace on the port the firewall allows. Check eve.json: does rule 1000002 fire? Explain the result, thinking about the allowed port and how Suricata recognises HTTP.
  • Run Zeek with LogAscii::use_json=T and compare the JSON conn.log with the tab-separated one. The next lab, Hunting Scans, Beacons and Floods, uses JSON.

13. Review prompt

Without looking back:

  1. Name the three changes that turned the naive admin rule into rule 1000002, and the false positive each one removed.
  2. Why could Suricata match the C2 name in a TLS session without decrypting it?
  3. What does Zeek record that Suricata alerts do not, and why does that matter a week later?
  4. How does a Community ID let you join records from two different tools?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check