Snort: Architecture and Rule Syntax
What you'll learn: How the most popular open-source IDS/IPS processes network traffic and how to write detection rules from scratch.
Understanding Snort's Architecture
Snort is like a security guard reading every letter that passes through the mail room. It inspects network packets in real-time using a modular architecture with three key components:
Packet Decoder – Captures raw network traffic and breaks it down into protocol layers (Ethernet → IP → TCP/UDP → Application data).
Preprocessors – Normalize and reconstruct traffic before analysis. They handle fragmentation reassembly, stream reassembly (putting TCP sessions back together), HTTP normalization, and protocol anomaly detection. Think of preprocessors as translators that make messy real-world traffic readable.
Detection Engine – The heart of Snort. It matches preprocessed packets against your ruleset using pattern matching and generates alerts when threats are detected.
Rule Syntax Fundamentals
Snort rules follow a simple structure:
action protocol source_ip source_port -> dest_ip dest_port (rule options)
Example rule:
alert tcp any any -> 192.168.1.0/24 80 (msg:"Possible SQL Injection"; content:"SELECT"; nocase; sid:1000001;)
This means: "Alert on TCP traffic from any source to my internal network on port 80 if it contains 'SELECT' (case-insensitive)."
Rule components:
- Action –
alert,log,pass,drop(IPS mode) - Protocol –
tcp,udp,icmp,ip - Addresses/Ports –
any, specific IPs, CIDR ranges - Direction –
->(one-way) or<>(bidirectional) - Options – Detection conditions, metadata
Key Takeaway: Snort's three-stage architecture (decode → preprocess → detect) combined with flexible rule syntax lets you build precise network intrusion detection by matching patterns in normalized traffic streams.