PacketLab
Suricata · Rules and detection

Rule anatomy and actions

Read a signature as a traffic selector plus an explicit detection condition.

Examples target Suricata 8.0.1 on a prepared Linux lab host. Constructed outputs are illustrative, not live sensor results. Commands are lesson examples; no sensor or enforcement is started by this page.

Benign lab files: Constructed HTTP PCAP · Alert rule · Drop rule · SHA-256. Save these with the suggested names. The PCAP is a synthetic 20-frame Ethernet/IPv4/TCP fixture containing complete benign marker and ordinary HTTP exchanges; it is not a recording of real users. It was constructed without transmitting traffic. A successful live Suricata replay is still to be verified.

Start with a harmless signature

alert http 10.10.10.20 any -> 192.0.2.80 8080 (msg:"LAB PacketLab marker"; flow:established,to_server; http.uri; content:"/routecraft-check"; startswith; sid:1000001; rev:1;)

This local signature observes an established HTTP request to the lab service. It is intentionally narrow and is not a malware detector. Save it in local.rules and use the offline fixture from the previous lesson.

Read the condition and identity

flow:established,to_server requires established client-to-server traffic. http.uri selects the normalized URI buffer for following content. content matches the marker bytes; startswith anchors that content at the start of the selected buffer. The message is a label. sid identifies this local rule and rev tracks its revisions; neither value chooses which host to inspect.

Rule options are not arbitrary decoration: moving content before the intended sticky buffer changes the inspection target. A syntactically valid broad match can still be the wrong policy.

Choose an action deliberately

ActionOperational meaning
alertReport a match without making it a blocking rule
dropBlock matching traffic when the active inline integration honors it
rejectSend a supported rejection response; in IPS also drop
passShort-circuit further inspection according to packet/flow semantics

Action precedence and flow handling mean rule-file order is not a simple firewall list. Do not use a broad pass rule merely to quiet one noisy alert: it can hide other detections. Passive placement cannot enforce a drop against the original copy source.

Validate the intended boundary

Illustrative output · selected fields
suricata -T -c /etc/suricata/suricata.yaml -S ./local.rules --init-errors-fatal
Configuration provided was successfully loaded. Exiting.

Then replay the positive and negative fixtures. Change one condition at a time: URI, port or client address. Only matching traffic should produce this local SID; retain the previous rule revision so a bad change can be reversed.

Further reading

Key Takeaways

  • The header selects protocol, endpoints, ports and direction.
  • Options refine stream state and application content.
  • Sticky buffers determine where following content is inspected.
  • Action and active capture mode jointly determine enforcement.
  • A local SID and revision support controlled rule testing and maintenance.

Rule anatomy and actions Quiz

Six questions · four options each · select one answer per question. Submit all answers to see your score and explanations.

1. Which header field limits this rule to the lab service port?
2. What does http.uri select?
3. What does startswith add here?
4. What does rev represent?
5. Why avoid a broad pass to silence one alert?
6. How should a rule boundary be tested?