#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.
- Packet StreamReassemble TCP stream and track flow state
- App ParserDecode HTTP, DNS or TLS protocol fields
- MPM Pre-filterScreen buffers using fast_pattern content
- Full OptionsEvaluate offsets, PCRE and emit alert or drop
Consider a Suricata rule detecting a lab HTTP C2 beacon check-in:
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.
$ 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:8080After 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;: Withoutflow, a single stateless TCP rule can be triggered by half-open scans or server-side responses echoing error text. - Putting
fast_patternon 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;aftercontent:"/path";as a modifier, whereas Suricata and Snort 3 placehttp.uri;beforecontent:"/path";as a sticky buffer. - Expecting payload inspection inside TLS: On HTTPS traffic without TLS decryption,
http.uriandhttp.request_bodyare invisible; pivot totls.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;withfast_pattern;on a distinctive string keeps false positives low and sensor throughput high. - Always test syntax with
suricata -Tand verify behaviour offline withsuricata -r <pcap>before promoting rules to production sensors or IPSdroppolicies.