| Writing Snort Rules www.snort.org & Intrusion Detection with SNORT ch3. by Rehman Pearson HigherEd |
Snort Installation
Download and Extract the latest version of Snort from Snort website.
Install Snort
Verify the Snort installation
Create the required files and directory
Execute Snort.
2
Snort
Snort uses a simple rules description language that is flexible and
quite powerful.
Snort rules contain two logical sections:
The rule header ( the rule’s action, protocol, source and destination IP
addresses and netmasks, source and destination port numbers)
The rule options (alert messages and information on which parts of the packet
should be inspected to determine if the rule action should be taken)
ex. alert tcp any any -> any any (msg:”Sample alert”;)
alert tcp any any -> 192.168.0.1/24 any
(msg:”Given access”;)
3
Rules
The text up to the parenthesis is the rule header and the rule options is
the section inside the parenthesis.
The word before the colons is called the keyword.
– means that a rule continues in the next line
The Rule Actions
There are 5 default rule actions and 3 actions in inline mode
4
Snort Modes
Inline
When Snort is in Inline mode, it acts as an IPS allowing drop rules to trigger. (drop – block and log the packet).
Snort can be configured to run in inline mode using the command line argument -Q and snort config option policy_mode as follows:
snort -Q
config policy_mode:inline
Passive (Tap)
When Snort is in Passive mode, it acts as a IDS. Drop rules are not loaded (without -treat-drop-as-alert). Snort can be configured to passive
mode using the snort config option policy_mode as follows:
config policy_mode:tap
Inline-Test
Inline-Test mode simulates the inline mode of snort, allowing evaluation of inline behavior without affecting traffic. (Uses the copy of the
packet). Snort can be configured to run in inline-test mode using the command line option (-enable-inline-test) or using the snort config option
policy_mode as follows:
snort –enable-inline-test
config policy_mode:inline_test
5
The Rule Actions
The Rule Actions
alert – generate an alert using the selected alert method, and then log the
packet
log – log the packet
pass – ignore the packet
activate – alert and then turn on another dynamic rule
dynamic – remain idle until activated by an activate rule , then act as a log rule
drop – block and log the packet
reject – block the packet, log it, and then send a TCP reset if the protocol is TCP
or an ICMP port unreachable message if the protocol is UDP.
sdrop – block the packet but do not log it.
6
The Rule Actions
Protocol Field
TCP
UDP
ICMP
IP
Others (ARP, RARP, GRE, …)
Port numbers may be specified in a number of ways, including any
ports, static port definitions, ranges, and by negation.
Hands-On Ethical Hacking and Network Defense, Second Edition
7
The Rule Actions
8
The Rules
Port negation is indicated by using the negation operator !. The negation operator
may be applied against any of the other rule types (except any)
The direction operator -> indicates the orientation, or direction, of the traffic that
the rule applies to.
There is also a bidirectional operator, which is indicated with a <> symbol.
log tcp !192.168.1.0/24 any <> 192.168.1.0/24 23
9
The Rules
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.
There are four major categories of rule options.
general
These options provide information about the rule but do not have any affect during detection
payload
These options all look for data inside the packet payload and can be inter-related
non-payload
These options look for non-payload data
post-detection
These options are rule specific triggers that happen after a rule has “fired.”
10
General Options Rule
| Table: General rule option keywords | |
| Keyword | Description |
| msg | The msg keyword tells the logging and alerting engine the message to print with the packet dump or alert. |
| reference | The reference keyword allows rules to include references to external attack identification systems. |
| gid | The gid keyword (generator id) is used to identify what part of Snort generates the event when a particular rule fires. |
| sid | The sid keyword is used to uniquely identify Snort rules. |
| rev | The rev keyword is used to uniquely identify revisions of Snort rules. |
| classtype | The classtype keyword is used to categorize a rule as detecting an attack that is part of a more general type of attack class. |
| priority | The priority keyword assigns a severity level to rules. |
| metadata | The metadata keyword allows a rule writer to embed additional information about the rule, typically in a key-value format. |
11
Content Keyword
12
The content keyword – An important feature of Snort is to find a data pattern inside a packet. It may
be presented as an ASCII string or as binary data in the form of hexadecimal characters.
ex. alert tcp 192.168.1.0/24 any -> ![192.168.1.0/24] any
(content: “GET”; msg: “GET matched”;)
The GET keyword is used in many HTTP related attacks. If it is used binary version then,
content: “GET” becomes content: “ | 47 45 54 |”
The content-list keyword is used with a file name.
ex. alert ip any any -> 192.168.1.0/24 any (content-list:
“filename”; msg: “A word matched”;)
Dsize Keyword
The dsize keyword is used to find the length of the data part of a packet. Many
attacks use buffer overflow vulnerabilities by sending large size packets. You can
find out if a packet contains data >=< than a certain number.
ex. alert ip any any -> 192.168.1.0/24 any (dsize: > 6000;
msg: “Large size IP packet detected”;)
The flags keyword is used to find out which flag bits are set inside the TCP header.
ex. alert tcp any any -> 192.168.1.0/24 any (flags: SF;
msg: “SYNC-FIN packet detected”;)
13
Itype Keyword
The itype keyword is used to detect attacks that use the type field in
the ICMP packet header.
ICMP type filed values
0 Echo reply
3 Destination unreachable
4 Source quench
5 Redirect
8 Echo request
11 Time exceed
12 Parameter problem
13 Timestamp request
14 Timestamp reply
15 Information request
16 Information reply
ex. alert icmp any any -> any any (itype: 4;
msg: “ICMP Source Quench Message received”;)
14
Logto Keyword
The logto keyword is used to log packets to a special file.
ex. alert icmp any any -> any any (logto:logto_log;)
The react keyword is used with a rule to terminate a session to block some sites or services.
ex. alert tcp 192.168.1.0/24 any -> any 80 (msg: “Outgoing
HTTP connection”; react: block;)
alert tcp 192.168.1.0/24 any -> any 80 (msg: “Outgoing
HTTP connection”; react: warn, msg;)
Block is the basic modifier. Warn modifier is used to send a visual notice to the source.
15
Resp Keyword
The resp keyword is used to knock down hacker activity by sending response
packets to the host that originates a packet matching the rule.
The Snort should be compiled with –enable-flexresp command line option.
The following rule will send a TCP Reset packet to the sender whenever an
attempt to reach TCP port 8080 on the local network is made.
ex. alert tcp any any -> 192.168.1.0/24 8080 (resp: rst_snd;)
16
Sid Keyword
The sid keyword is used to add a Snort ID to rules.
Output modules or log scanners can use SID to identify rules.
Authors have reserved SID ranges for rules as shown below:
Range 0-99 is reserved for future use.
Range 100-1,000,000 is reserved for rules that come with Snort distribution.
All numbers above 1,000,000 can be used for local rules.
The only argument to this keyword is a number.
The following rule adds SID equal to 1000001.
ex. alert ip any any -> any any (ipopts: lsrr;
msg: “Loose source routing attempt”; sid: 1000001;)
17
The Snort Configuration File
Snort uses configuration file at startup time.
The file snort.conf contains six basic sections:
Variable definitions
Config parameters
Preprocessor configurations
Output module configurations
Defining new action types
Rules configuration and include files
18
19
The Snort Configuration File Setup
Set the variables for your network
Configure dynamic loaded libraries
Configure preprocessors
Configure output plugins
Add any runtime config directives
Customize your rule set
Variables
Are used in the configuration file.
Represent very convenient way of creating rules
ex. HOME_NET – your home network
EXTERNAL_NET
var HOME_NET 192.168.1.0/24
var HOME_NET [192.168.1.0/24,192.168.10.0/24]
Later on you can use this variable HOME_NET in your rules:
ex. alert ip any any -> $HOME_NET any (ipopts: lsrr;
msg: “Loose source routing attempt”;)
20
Config Directives
The config directives in the snort.conf file allow a user to configure
many general settings for Snort. Examples include the location of log
files, the order of applying rules and so on.
These directives can be used to replace many command line options
as well. The general format of applying a config directive is as follows:
config directive_name[: value]
21
Preprocessor
These are differently called input plug-ins
Operate on received packets before Snort rules are applied to them.
The general format of configuring a preprocessor is as follows:
preprocessor <preprocessor_name>[: <configuration_options>]
The first part of the line is the keyword preprocessor. The name of the preprocessor follows this keyword.
If the preprocessor can accept some options or arguments, you can list these options after a colon character at the end of
the name of preprocessor, which is optional.
The following is an example of a line in the configuration file for IP defragmentation
preprocessor frag2
22
Output Module
Are also called output plug-ins, manipulate output from Snort rules.
Ex. If you want to log information to a database
output <output_module_name>[: <configuration_options>]
ex. output database: alert, mysql, user=rr password=boota
dbname=snort host=localhost
Stores log massages to MySQL database
Output module contains the database name, database server address, user name
and password.
23
Defining New Action Types
Snort has predefined action types.
You can also define your own action types.
The following action type creates alert messages that are logged into the database
as well as in a file in the tcpdump format:
ruletype dump_database
type alert
output database: alert, mysql, user=rr dbname=snort
host=localhost
output log_tcpdump: tcpdump_log_file
dump_database icmp any any -> 192.168.1.0/24 any
(fragbits: D; msg: “Don’t Fragment bit set”;
24
Rules Configuration
The last part of the configuration file.
The rules configuration is the place in the configuration file where you
can put your rules.
You can include these text files in the snort.conf file using the “include”
keyword.
Snort comes with many predefined rule files. The names of these rule
files end with .rule.
25
Include Files
Inside the main configuration files you can include other files using the
include keyword.
Most of the predefined rules that come with the Snort distribution are
found in include files.
These rule files are included in the main snort.conf file using the
“include” keyword.
The following is an example of including myrules.rules file in the main
configuration file.
include myrules.rules
26
Order of Rules
The rules can be categorized into three basic types.
1. Alert rules
2. Pass rules
3. Log rules
When a packet is received by Snort, it is checked in this order. Each
packet has to go through all Alert rule checks before it is allowed to
pass.
This scheme is the most secure since no packet passes through
without being checked against all alert types.
27
BASE & ACID
“BASE is the Basic Analysis and Security Engine. It is based on the
code from the Analysis Console for Intrusion Databases (ACID)
project. This application provides a web front-end to query and
analyze the alerts coming from a SNORT IDS system.”
Using SID, tools like ACID can display the actual rule that generated a
particular alert.
ACID – Analysis Console for Intrusion Databases (ACID), a PHPbased analysis engine to search and process a database of security
events generated by IDS.
28
Writing Good Rules
Although it is not mandatory, you should use the following parts in the
options for each rule:
A message part using the msg keyword.
Rule classification, using the classification keyword.
Use a number to identify a rule with the help of the sid keyword.
If the vulnerability is known, always use a reference to a URL where
more information can be found using the reference keyword.
Always use the rev keyword in rules to keep a record of different rule
versions.
29
The post Verify the Snort installation appeared first on My Assignment Online.