Skip to content

Create Snort rules

Posted on:September 8, 2021 at 12:00 AM

Table of contents

Open Table of contents

Intro

Snort and Suricata use the same language and structure of their rules. Different about that is an option provided of both and feature provided. For example, Snort don’t have a specific rule option for HTTP Header just general-purpose, but Suricata have more specific HTTP Header for each purpose like HTTP User-Agent, HTTP Method, etc.

Motivation

While learning for Preparing LKS Province, the Material very excited for me is IDS. Because I can explore Intrusion Detection System tools, like Suricata and Snort. Have a few Challenges in Installing and Writing rules for IDS, like you should know how to manually compile software from source, and Writing rules for IDS with a minimal false-positive result. And now I wanna share with you what I learn in writing rules with Snort and Suricata.

Snort rules

Snort has 2 parts of rules, the first is Rule Header and the second is Rule Option. below is example of snort rules.

Snort rules

Rule Header

Rule Header contains the information that defines the who, where and what of packet, as well as what to do in the event that a packet with all the attributes indicated in the rule should show up.

Snort Rule Header

actions

actions used for notice snort what should action if found packet with rule database. snort have 3 in IDS mode, like alert, log, and pass. but if you running snort “inline mode” or IPS you have 3 additional action option, like drop, reject, and sdrop.

actionsFunction
alertgenerating alert using selected alert method, and log packet.
logJust log it.
passignore packet
dropblock and log packet
rejectblock, log it, and send TCP reset if protocol is TCP and ICMP port unreachable message if protocol is UDP.
sdropblock packet but don’t create log

Protocol

available protocol in snort,

ProtocolFunction
TCP
ICMP
UDP

IP Address

you can define with variable, CIDR block, or you can use all (any) keywords for all IP addresses.

Example
Variableipvar MY_NET 102.159.23.2
Single IP Address192.168.0.1
CIDR block192.168.0.0/24
IP List[10.10.10.10, 192.168.0.0/24]
Single IP Negation!192.168.0.1
Negation CIDR block!192.168.0.0/24
Negation IP List![10.10.10.0/24, 172.16.0.1]
Any IP Addressesany

Port

same as IP Address you can define it with variable, and also define any port, static port, range port, and negation port

Example
Variableportvar MY_PORTS [22,80,3028:4028]
Static port80
port 1 - 1024any
Less than or equal to (<=):1024
Ignore static port!80
Ignore port range!600:610
Port range100:200

Direction

in snort have 2 Direction ”->” and ”<>“. Direction operator mean considered to be the traffic coming from the source host, and the address and port information on the right side of the operator is the destination host.

OperatorFunction
->source to destination
<>source to destination or vice versa

Rule Options

Snort Rule Option

Rule options form the heart of Snort’s intrusion detection engine, combining ease of use with power and flexibility. All Snort rule options are separated from each other using the semicolon (;) character. Rule option keywords are separated from their arguments with a colon (:) character.

Snort have 4 category of rule options, for each category have different purpose. like

General Rules

optionfunctions
msgmessage to print
referencereference to help identify an attack
gidGroup id, by default 1 (advance user)
siduniquely number to easily identified rules
revrevision number
classtypecategorize rules detected attack
priorityseverity level to rules
metadatametadata for rules, in dictionary format, key and values