# Snort 3 rule syntax for Snort 2 and Suricata users

What changes when a Snort 2 or Suricata rule moves to Snort 3, including the http_uri change that loads without an error and never fires.

Snort 3 kept the shape of a rule (header, then options in parentheses) but changed how options
are written. Most differences make Snort 3 refuse the rule, which is easy to spot. One doesn't,
and it's the one to look for first.

## The silent one: buffers come before the content

In Snort 2, and in Suricata's older syntax, HTTP buffer keywords modify the content before them:

```
alert tcp any any -> any 80 (msg:"Download"; content:"/download"; http_uri; sid:1;)
```

In Snort 3, `http_uri` is a *sticky buffer*: it applies to the content options **after** it. The
rule above still loads without an error, but the content is no longer tied to the URI and the
`http_uri` at the end has nothing to apply to. Against a capture of exactly that request, it
doesn't fire. Move the buffer in front:

```
alert http any any -> any any (msg:"Download"; http_uri; content:"/download"; sid:1;)
```

The same goes for `http_header`, `http_client_body`, `http_cookie`, `http_method`,
`http_stat_code`, `http_stat_msg` and their raw variants.

## In an `alert http` rule, content with no buffer only sees bodies

Once a rule says `alert http`, a `content` with no buffer in front of it doesn't search the
whole request. In Snort 3 it matches only message bodies. Against a capture of a plain download,
this rule stays silent even though the request starts with `GET`:

```
alert http any any -> any any (msg:"GET request"; content:"GET"; sid:1;)
```

while `content:"MZ"`, the first bytes of the downloaded file, fires. The body it searches is the
decoded one: dechunked and decompressed, so text inside a gzip-compressed response matches
although it isn't in the bytes on the wire. To match the request line, the headers or the status
line, name the buffer: `http_method`, `http_uri` or `http_raw_request` for the request line,
`http_header` for headers, `http_stat_code` or `http_raw_status` for the status line.

## Content modifiers go inside the content

Snort 2 and Suricata write each modifier as its own option with a colon. Snort 3 puts them inside
the `content` option, after commas, without colons:

| Snort 2 and Suricata | Snort 3 |
| --- | --- |
| `content:"GET"; nocase; depth:3;` | `content:"GET", nocase, depth 3;` |
| `content:"x"; distance:0; within:10;` | `content:"x", distance 0, within 10;` |
| `content:"x"; fast_pattern;` | `content:"x", fast_pattern;` |

Snort 3 rejects the separate form (`unknown rule keyword: nocase`), and Suricata rejects the
Snort 3 form.

## Options that are gone

| Snort 2 | Snort 3 |
| --- | --- |
| `uricontent:"/x";` | `http_uri; content:"/x";` |
| `content:"x"; rawbytes;` | `raw_data; content:"x";` |
| `pcre:"/x/U";` (and the other buffer flags: I, P, H, D, M, C, K, S, Y, B) | `http_uri; pcre:"/x/";` |
| `threshold:type limit, ...;` | an `event_filter` in `snort.lua`, or `detection_filter` in the rule |
| `metadata:service http;` | `service:http;` (the old form still loads) |

## Coming from Suricata

Suricata 7 and 8 name their sticky buffers with dots; Snort 3 uses underscores, and not every
buffer has a counterpart:

| Suricata | Snort 3 |
| --- | --- |
| `http.uri` | `http_uri` |
| `http.uri.raw` | `http_raw_uri` |
| `http.header` | `http_header` |
| `http.header.raw` | `http_raw_header` |
| `http.cookie` | `http_cookie` |
| `http.request_body` | `http_client_body` |
| `http.method` | `http_method` |
| `http.stat_code` | `http_stat_code` |
| `http.stat_msg` | `http_stat_msg` |
| `file.data` | `file_data` |

Suricata's `alert http` header has a Snort 3 equivalent (`alert http`), but Suricata has no
`service` option: to limit a Suricata rule to a protocol, put the protocol in the header.

## Testing a converted rule

Snort 3 ships `snort2lua`, which converts Snort 2 configurations and rules. Whether you convert
by hand or with it, run the result against a capture before deploying it: a rule that loads
isn't a rule that matches. [IDS Rule Tester](/) runs rules on Snort 3, Suricata 8 or Suricata 7
against a pcap, and points out the conversions above when it sees them.