Snort Config and Rules
Snort Config and Rules
Snort Config and Rules
Synopsis
In this article we will learn the make up of Snort rules and how we can
we configure them on windows to get alerts for any attacks performed.
There are various IDS (Intrusion Detection System) and IPS(Intrusion
Prevention System) methods available to use, but one of the best and
most common method is Snort.
What is Snort?
Snort is a Free and Open Source Network Intrusion Prevention
and Detection System. It uses a rule-based language combining
signature, protocol and anomaly inspection methods to detect malicious
activity such as DOS attacks, Buffer overflows, stealth port scans, CGI
attacks, SMB probes, OS fingerprinting attempts, and more. It is capable
of performing real time traffic analysis and packet logging on IP
networks.
The Snort rule language is very flexible, and creation of new rules is
relatively simple.
Snort rules help in differentiating between normal internet activities
and malicious activities.
The direction operators <> and -> indicate the direction of interest for
the traffic, this means traffic can either flow in one direction or in bi -
directionally. Keyword any can be used to define any IP addresses,
numeric IP addresses must be used with a CIDR (Classless Inter-
domain Routing) netmask. In snort rules the port numbers can be listed
in many ways, including any ports, negation etc. Port ranges are
indicated with Range operator :.
Usually snort rules were written in a single line, but with the new version
snort rules can be written in multi line. This can be done by adding a
backslash \ to the end of the line. This multiple line helps, if a rule is
very large and difficult to understand.
*log tcp any 192.168.1.0/24 It will log traffic from various ports and will go to ports which are
:1024 -> 400: greater than or equal to 400
log udp any any 92.168.1.0/24 It will log traffic from any port and destination ports ranging from
-> 1:1024 1 to 1024
Snort rules must be written in such a way that it describes all the
following events properly:
Snort -V
Extract all the Snort rules folders, that you donwloaded before and
from there copy all the content from folder to c:\Snort\rules
After you have copied all the contents the main task starts here, Go
to c:/Snort/etc and open**Snort.conf** with wordpad. CONF
stands for configure.
Snort.conf has Nine different sections, First thing we will set the
variables. The first variable we have is HOME_NET, You can leave this
to any but it is preferred to put your machine IP address, In my case
the IP is 192.168.73.129
Also change
the WHITE_LIST_PATH and BLACK_LIST_PATH from**../rules**
toc:\Snort\rules
That’s all for step one, and there is nothing much to do in step two
but set #config logdir: to **config logdir:c:\Snort\log **,
this will help snort to write the output in a particular location.
In Snort.conf file, find and replace ipvar to var. By default the string
ipvar is not recognized by snort, so we replace it with var. To find and
replace press Ctrl + H and in find what field write ipvar and the
replace field write var and click Replace all.
The last step is to remove the back slash and add comment
characters # on lines 501 to 507. These lines can be found above
step6.
Save the snort.conf file and close the window.
In my case, I don’t have any criteria so it will load on any ICMP packet it
receives. In the above rule we have also provide a signature id (sid)
which is highly required. Bciy convention when you write your own snort
rules, you have to start above 999999
where X is your device index number. In My case its 1 . Hit Enter and
you are all set.
Performance Considerations:
If snort occupies high cpu usage without high amounts of traffic to
analyze, it may be indicative of too high a volume of traffic, insufficient
system resources, or some other process is consuming most of the
CPU. Although sometimes, too many rules are added, in which the
packet queue drops the packet because it fills before snort has a chance
to look at them. Best practice is to only enable rules you need so snort
can spend more time grabbing packets from the queue. Never enable all
rules or you will most likely experience performance issues. For
example, if you are in a Windows only environment, then only enable
Windows related rules. In addition, use Berkeley Packet Filters (BPF) to
limit traffic to machines or ports that need to be inspected. For example,
if you have a network backup server, it’s best to tell Snort to ignore
traffic from it since it will generate a large amount of traffic. BPF’s are
added as the last command-line options to snort:
This command will run Snort and just show the IP and
TCP/UDP/ICMP headers, nothing else. If you want to see the
application data in transit, try the following:
./snort -vd
This rule tells Snort that you want to print out the data link and
TCP/IP headers as well as application data into the directory
./log, and you want to log the packets relative to the 192.168.1.0
class C network. All incoming packets will be recorded into
subdirectories of the log directory, with the directory names being
based on the address of the remote (non-192.168.1) host. Note
that if both hosts are on the home network, then they are
recorded based upon the higher of the two's port numbers, or in
the case of a tie, the source address. If you're on a high speed
network or you want to log the packets into a more compact form
for later analysis you should consider logging in "binary mode".
Binary mode logs the packets in "tcpdump format" to a single
binary file in the logging directory:
./snort -l ./log -b
For more info on how to use the BPF interface, read the man
page.
Where snort.conf is the name of your rules file. This will apply the
rules set in the snort.conf file to each packet to decide if an action
based upon the rule type in the file should be taken. If you don't
specify an output directory for the program, it will default to
/var/log/snort. One thing to note about the last command line is
that if Snort is going to be used in a long term way as an IDS, the
"-v" switch should be left off the command line for the sake of
speed. The screen is a slow place to write data to, and packets
can be dropped while writing to the display. It's also not
necessary to record the data link headers for most applications,
so the so it's not necessary to specify the -e switch either.
./snort -d -h 192.168.1.0/24 -l ./log -c snort.conf
This will configure Snort to run in it's most basic NIDS form,
logging packets that the rules tell it to in plain ASCII to a
hierarchical directory structure (just like packet logger mode).
Once this is done running, all of the data will be sitting in the log
directory in its normal decoded format. Cool, eh?
This will read the packets from a log file and dump the packets to
the screen, obfuscating only the addresses from the
192.168.1.0/24 class C network.