Briefing: writing Suricata rules
Suricata is a high-performance, open-source IDS/IPS (Intrusion Detection and Prevention System). It inspects network traffic against a set of rules and raises an alert whenever traffic matches one. In this lab you write rules that catch specific malicious traffic inside captured packets.
Anatomy of a rule
A rule is a single line with two parts: a header, then a set of options in parentheses.
action protocol src_ip src_port -> dst_ip dst_port (options)
A concrete example that alerts on any TCP traffic heading to port 4444:
alert tcp any any -> any 4444 (msg:"Suspicious 4444"; sid:1000001; rev:1;)
- action: what to do on a match. Here you always use
alert. - protocol:
tcp,udp,http,dns,tls, and so on. - src / dst ip and port:
anymatches everything, or use a literal like10.10.0.123and80. - -> is the direction (source to destination).
<>matches either way. - options live inside the parentheses, and each one ends with
;: msg:"...";the text shown with the alert. The checker looks at this, so match the wording the challenge asks for exactly.sid:NNNN;a unique rule id (any number, for example1000001).rev:1;the rule revision.- matching keywords such as
content:"...";,http.uri;,dns.query;andpcre:"/.../";let you match on the payload or on protocol fields.
How these challenges are graded
- Write your rule or rules into a file, for example
nano myrules.rules. - Run the checker:
/shared/suricata.sh myrules.rules. - Read its output carefully. When your rule fires correctly on the capture, the checker prints your flag.
Read the suricata.sh script itself to understand which capture it runs your
rules against and what its output means. That tells you exactly what traffic
you need to match.
Keep the official Suricata rule reference open: keywords like dns.query,
http.uri, http.host, content and pcre each have a precise syntax.