Snort 3 rules allow arbitrary whitespace, including multi-line formatting. Use
# for end-of-line comments, #begin/#end blocks for multi-line comments, or /* */ for C-style inline comments.Rule Actions (Header)
The action is the first word in a rule and determines what happens when the rule matches.| Action | Mode | Description |
|---|---|---|
alert | Any | Generate an alert event and log the triggering packet. |
log | Any | Log the packet without generating an alert. |
pass | Any | Ignore the packet; no alert, no logging. |
drop | Inline IPS | Drop the packet silently. |
reject | Inline IPS | Drop the packet and send a TCP reset (or ICMP unreachable for UDP). |
rewrite | Inline IPS | Replace matched content and reinject the modified packet. |
drop, reject, and rewrite only take effect when Snort is running in inline mode (e.g., using the afpacket DAQ with a bridged pair). In IDS mode they behave like alert.General Options
These options provide metadata and identification for the rule.| Option | Syntax | Description |
|---|---|---|
msg | msg:"<text>"; | Human-readable alert message. Appears in alert output. |
sid | sid:<n>; | Signature ID. Unique within a generator ID. |
gid | gid:<n>; | Generator ID. Defaults to 1 for text rules, 3 for SO rules. |
rev | rev:<n>; | Rule revision number. Increment when the rule is updated. |
classtype | classtype:<name>; | Classification name. Must match an entry in classifications. |
priority | priority:<n>; | Alert priority. Overrides the priority set by classtype. |
metadata | metadata:<key value>, ...; | Arbitrary key-value pairs (unquoted, comma-separated). |
reference | reference:<scheme>,<id>; | Link to an external vulnerability database entry. |
rem | rem:"<comment>"; | Rule comment that is carried with the rule itself. |
Rules are identified in the format
gid:sid:rev. Internal Snort components use GIDs in the 100s range (e.g., the decoder is GID 116). List all built-in GIDs with snort --list-gids.Detection Options
content
Matches a literal byte sequence in the current buffer. Can be a text string or a mix of text and hex bytes.| Sub-option | Syntax | Description |
|---|---|---|
nocase | nocase; | Case-insensitive match. |
rawbytes | rawbytes; | Match on raw bytes, bypassing any normalisation. |
depth | depth:<n>; | Search only the first n bytes of the buffer (from the start or from offset). |
offset | offset:<n>; | Start searching at byte n from the beginning of the buffer. |
distance | distance:<n>; | Start searching n bytes after the end of the previous match (relative). |
within | within:<n>; | Require this match to occur within n bytes of the previous match. |
fast_pattern | fast_pattern; | Designate this content as the fast pattern for rule grouping. |
pcre
Matches using a Perl-compatible regular expression.i (case-insensitive), s (dot matches newline), m (multiline), U (match URI buffer), R (relative to last match).
regex
Matches using a Hyperscan-accelerated regular expression. Requires Snort built with Hyperscan support.isdataat
Verifies that data exists at a specific position in the current buffer. Useful as a bounds check.dsize
Matches on the size of the packet payload.Flow Options
flow
Controls which side of a connection the rule applies to and what session state is required.| Option | Description |
|---|---|
established | Match only on established TCP sessions. |
to_server / from_client | Match traffic from client to server. |
to_client / from_server | Match traffic from server to client. |
stateless | Match regardless of flow state (no stream required). |
no_stream | Do not match on rebuilt stream packets. |
only_stream | Only match on rebuilt stream packets (not raw). |
flowbits
Sets or tests per-flow boolean flags, enabling stateful multi-rule correlation.| Action | Description |
|---|---|
set,<name> | Set the named flag for this flow. |
isset,<name> | Match only if the named flag is set. |
unset,<name> | Clear the named flag. |
isnotset,<name> | Match only if the named flag is not set. |
toggle,<name> | Toggle the named flag. |
noalert | Suppress the alert for this rule (used to set bits without alerting). |
service
Restates the rule’s associated service, placing it in the corresponding service rule group. Makes the rule service-based rather than port-based.HTTP Buffer Selectors
These sticky buffer options set the detection cursor to a specific HTTP field. Subsequentcontent and pcre options match within that buffer.
| Option | Description |
|---|---|
http_uri | Normalised request URI. |
http_raw_uri | Raw (un-normalised) request URI. |
http_method | HTTP request method (e.g., GET, POST). |
http_header | Normalised HTTP request or response headers. |
http_raw_header | Raw HTTP headers. |
http_client_body | HTTP request body (POST data). |
http_stat_code | HTTP response status code. |
http_stat_msg | HTTP response status message. |
file_data | Decoded file content (HTTP response body, email attachments, etc.). Supports stateful evaluation across packet boundaries. |
pkt_data | Raw TCP reassembled payload bytes. Supports stateful evaluation across packet boundaries. |
Stateful evaluation is supported for
pkt_data and file_data. If a match spans packet boundaries, rule evaluation pauses and resumes when more data arrives.Byte Rule Options
byte_test
Extracts a numeric value from the packet and compares it against a constant.| Parameter | Description |
|---|---|
<bytes> | Number of bytes to extract (1–10). |
<operator> | Comparison: =, !=, <, >, <=, >=, &, ^. |
<value> | Value to compare against. |
<offset> | Byte offset from the start of the buffer (or from last match if relative). |
byte_jump
Moves the detection cursor by an amount extracted from the packet. Useful for navigating length-prefixed fields.byte_extract
Extracts a value from the packet and stores it in a named variable for use in subsequent options.byte_math
Performs arithmetic on an extracted byte value and stores the result in a named variable.Threshold / Suppression Options
threshold (in-rule)
Limits how often a rule can fire for a given source or destination within a time window. Embedded in the rule itself.type | Behaviour |
|---|---|
limit | Log only the first count events in the time window. |
threshold | Log every countth event. |
both | Log the first event and then every countth after that. |
detection_filter
Prevents a rule from firing until the rate threshold is met. The rule must matchcount times within seconds before the first alert is generated.
Complete Example Rule
The following rule combines multiple option categories to detect a specific HTTP-based exploit pattern:Rule loading methods
Rule loading methods
There are several ways to load rules into Snort:
- Configuration file — set
ips.includeorips.rulesin your Lua config. - Command line — use
-R <file>to load an additional rules file. - Stdin — use
--stdin-ruleswith shell redirection. - Inline Lua — use
--luato pass a rule as a string. - Include statements — use
includeinside a rules file to load other rules files.
Fast patterns and rule groups
Fast patterns and rule groups
Snort compiles rules into multi-pattern search engines (MPSE) grouped by protocol, port, and service. Understanding how rules are grouped affects detection performance:
- A port-based rule (
alert tcp any 80 -> any any) is added to a port group; both protocol and port are evaluated. - A service-based rule (e.g., uses
http_uri,service:http, oralert http) is added to a service group; port evaluation is skipped when the service is identified. - The fast pattern is chosen automatically as the longest content; use
fast_patternto designate a more selective one. - Negated contents, and contents with non-zero offset/depth that are also case-sensitive, are not eligible for fast pattern selection.
GID / SID reference
GID / SID reference
Rules are referenced as
gid:sid:rev:| GID | Description |
|---|---|
| 1 | Standard text rules (default). |
| 3 | Shared-object (SO) rules. |
| 100+ | Internal Snort components (e.g., decoder = 116). |

