Skip to main content
Network Detection Rules with Suricata & Snort
Lesson 18 of 21

Network Detection Rules with Suricata & Snort

Author network IDS/IPS signatures in Suricata and Snort, scope rules with flow and application-layer sticky buffers, and validate detections against PCAP captures.

Advanced 28 min Reverse engineering
Authorised environments only — The techniques described here are used only in training labs and on systems you own or have written permission to test.

Learning objectives

  • Explain the header and option structure shared by Suricata and Snort detection rules
  • Scope network signatures using flow state, network variables and application-layer sticky buffers
  • Select strong fast_pattern anchors and relative byte offsets to keep packet inspection fast
  • Validate and troubleshoot custom rules offline against PCAP files before deploying to IDS or IPS sensors

Recommended first: Security Monitoring & Log Collection PipelinesMITRE ATT&CK Mapping, IoCs & Operational Threat IntelDetection Engineering & Portable Rules with Sigma

#Why this matters

Sigma monitors host and cloud logs, and YARA inspects files on disk or in memory. Suricata and Snort cover the third pillar of SOC visibility: network traffic on the wire. Even when an attacker compromises an unmanaged appliance that runs no EDR agent, every command-and-control (C2) check-in, DNS tunnel or lateral scan still crosses network sensors.

In IDS (Intrusion Detection System) mode, sensors log alerts passively from a network tap or SPAN port. In IPS (Intrusion Prevention System) mode, sensors sit inline and can drop malicious flows immediately. Both engines share a closely related rule language that lets defenders turn PCAP observations into fast, stateful signatures.

#Anatomy of a Suricata and Snort rule

Every rule has two parts: a header defining who is talking over which protocol, and options in parentheses defining what payload or protocol traits must match.

  1. Packet StreamReassemble TCP stream and track flow state
  2. App ParserDecode HTTP, DNS or TLS protocol fields
  3. MPM Pre-filterScreen buffers using fast_pattern content
  4. Full OptionsEvaluate offsets, PCRE and emit alert or drop

Consider a Suricata rule detecting a lab HTTP C2 beacon check-in:

suricata
alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"LAB C2 HTTP Beacon POST"; flow:established,to_server; http.method; content:"POST"; http.uri; content:"/api/v1/checkin"; fast_pattern; http.user_agent; content:"Mozilla/5.0 (LabBeacon)"; classtype:trojan-activity; sid:1000001; rev:1;)
Header token Meaning in the example Common alternatives
alert Action when all options match drop, reject, pass
http Application protocol parser tcp, udp, icmp, dns, tls
$HOME_NET any Source IP variable and port 10.10.10.0/24, any, [80,443]
-> Traffic direction (source to destination) <> (bidirectional)
$EXTERNAL_NET any Destination IP variable and port any, !$HOME_NET

Using $HOME_NET and $EXTERNAL_NET (configured in suricata.yaml or snort.conf) clarifies direction and prevents internal health checks from triggering outbound C2 alerts. Custom local rules should use sid values starting at 1000000 (and increment rev on every edit) so they never collide with community or vendor rulesets.

#Sticky buffers and payload modifiers

Early IDS rules matched raw TCP payloads, which forced engines to scan every packet byte and broke whenever HTTP headers changed order. Modern Suricata and Snort 3 rely on protocol parsers and sticky buffers: once you declare http.uri;, every content or pcre option after it searches only the normalized HTTP URI until the next sticky buffer appears.

Buffer / Modifier Purpose Notes
flow:established,to_server; Requires completed TCP handshake toward server Stops spoofed single-packet alerts
http.method; / http.uri; Targets normalized HTTP verb or URI path In Snort 2, modifiers like http_uri; followed content instead
http.request_body; Inspects POST body bytes Useful for encoded C2 tasking payloads
dns.query; / tls.sni; Targets DNS query name or TLS SNI hostname Works even when TLS payload is encrypted
nocase; / startswith; / endswith; Controls case sensitivity and buffer anchors Prefer startswith/endswith over heavy pcre
depth:N; offset:M; Bounds search to N bytes starting at byte M Cuts inspection cost on large payloads
distance:N; within:M; Searches relative to the previous content match Chains two markers inside binary protocols
fast_pattern; Picks which content enters the fast pre-filter Always attach to the longest, rarest string

Notice how fast_pattern; works in the beacon rule above: "POST" appears in millions of legitimate requests, whereas "/api/v1/checkin" is rare. Marking "/api/v1/checkin" with fast_pattern; ensures Suricata skips evaluating the rest of the rule on normal traffic.

#Testing rules offline against PCAPs

Before loading a custom signature onto a sensor, test syntax with -T and replay a captured PCAP offline with -r. Using -S loads only your custom rule file so output stays clean.

Validating syntax and replaying a lab PCAP with Suricata
$ suricata -T -c /etc/suricata/suricata.yaml -S rules/lab_c2.rules
Notice: suricata: Configuration provided was successfully loaded.

$ suricata -r captures/lab_beacon.pcap -S rules/lab_c2.rules -l ./logs/
$ cat ./logs/fast.log
11/19/2026-04:12:08.412901  [**] [1:1000001:1] LAB C2 HTTP Beacon POST [**] [Classification: A Network Trojan was detected] [Priority: 1] {TCP} 10.10.10.25:51422 -> 192.0.2.44:8080

After checking fast.log, inspect ./logs/eve.json (jq 'select(.event_type=="alert")' logs/eve.json) to confirm the full parsed HTTP metadata, flow ID and payload snippet match what you observed in the PCAP.

#Defending and common mistakes

  • Omitting flow:established,to_server;: Without flow, a single stateless TCP rule can be triggered by half-open scans or server-side responses echoing error text.
  • Putting fast_pattern on common tokens: Choosing "GET", "HTTP/1.1" or "/index" forces the engine to evaluate full rule options on almost every web session, spiking CPU and packet drops.
  • Confusing Snort 2 and Suricata syntax: Snort 2 places http_uri; after content:"/path"; as a modifier, whereas Suricata and Snort 3 place http.uri; before content:"/path"; as a sticky buffer.
  • Expecting payload inspection inside TLS: On HTTPS traffic without TLS decryption, http.uri and http.request_body are invisible; pivot to tls.sni, certificate fields or flow-metadata heuristics instead.

#Summary

  • Suricata and Snort rules pair a five-tuple/direction header with stateful options to detect or block malicious network traffic.
  • Application-layer sticky buffers (http.uri, http.user_agent, dns.query, tls.sni) restrict matching to normalized protocol fields rather than raw packet streams.
  • Combining flow:established,to_server; with fast_pattern; on a distinctive string keeps false positives low and sensor throughput high.
  • Always test syntax with suricata -T and verify behaviour offline with suricata -r <pcap> before promoting rules to production sensors or IPS drop policies.

Knowledge check

Sign in to take the test, complete lessons and save your progress. Log in

Practice: test your knowledge