Ultimate Snort Cheat Sheet
Ultimate Snort Cheat Sheet
The industry standard for Network Intrusion Detection & Prevention (NIDS/IPS).
1. Operation Modes
Snort can run in three distinct modes: Sniffer, Packet Logger, and NIDS.
Sniffer Mode
Read packets off the wire and display them.
-v: Verbose (Headers), -d: Data (Payload).
Logger Mode
Log packets to disk.
-l: Specify log directory.
NIDS Mode
Analyze traffic against a rule set.
-c: Configuration file.
2. Running Snort (NIDS)
Common commands for running Snort as a daemon or console app.
Console Output (Debug)
Print alerts directly to the screen (good for testing).
Daemon Mode (Production)
Run in background (`-D`).
Key Flags
| Flag | Description |
|---|---|
-A console | Print alerts to terminal |
-q | Quiet mode (no banner/stats) |
-c [file] | Path to configuration |
-i [iface] | Interface to listen on (eth0) |
-T | Test configuration mode (Dry Run) |
3. Rule Syntax
The core of Snort. Rules live in local.rules.
Structure
Example Rule
| Component | Description |
|---|---|
| Action | alert, log, pass, drop, reject |
| Proto | tcp, udp, icmp, ip |
| Direction | -> (One way), <> (Bidirectional) |
| Variables | $HOME_NET, $EXTERNAL_NET, $HTTP_PORTS |
4. Rule Options (Payload Detection)
The logic inside the parenthesis (...).
Meta Data
msg:"Text": The alert message displayed.sid:1000001: Snort ID (Must be > 1,000,000 for local rules).rev:1: Revision number.classtype:trojan-activity: Categorizes the alert.
Payload Content
content:"|90 90 90|": Match binary (hex) content (NOP Sled).content:"/bin/sh": Match string.nocase: Case insensitive match.depth:5: Search only first 5 bytes.offset:10: Start searching after byte 10.
PCRE (Regex)
Advanced matching using Perl Compatible Regular Expressions.
5. Filtering & Logging
BPF Filters (Berkeley Packet Filter)
Ignore noise by adding BPF filters at the end of the command (like tcpdump).
Log Formats
- Unified2: Binary format (standard). Requires Barnyard2 to read/export.
- Pcap: Standard packet capture (readable by Wireshark).
- CSV: Comma separated text (deprecated but simple).
Read PCAP with Snort
Replay a saved pcap file through Snort to test if it triggers alerts.
6. Testing Your Config
Always run a configuration check after editing rules.
Look for "Snort successfully validated the configuration!" at the end of the output.
Post a Comment