Snort RPM Based Installation with SnortSnarf and Snort Rule Creation Methods on Linux RHEL /CentOS / Fedora

Snort RPM Based Installation with SnortSnarf and Snort Rule Creation Methods on Linux RHEL /CentOS / Fedora

RPM Based Installation of Snort with SnortSnarf and Snort Rule Creation Methods:

written by: Muhammad Farrukh Siddique

Snort is an open source Network Intrusion Detection System
Snort can also act as Sniffer and Logger
In this section we will discuss the more beneficial part of Snort that is Intrusion Detection System (IDS)

Snort can also be installed on Windows Platform which will be covered later.
Currently the Operating System is CentOS-5.3

Snort Installation and Configuration:

First of all download and install the following required packages

# snort and snort-mysql rpm (download-able from
# mysql and mysql-server-5.0 with all affected packages
# libpcap
# Apache
# php5
# php-cli
# php-common
# php-devel
# php-ldap
# Php5-mysql

You can check these rpms through rpm -qa command.
you can install missing packages either from source DVD or through yum command

After downloading snort rpms, just install them

[root@snortserver tmp]# rpm -ivh snort-
[root@snortserver tmp]# rpm -ivh snort-mysql-

now configure some basic settings for snort:

# vim /etc/snort/snort.conf
Change var HOME_NET any to var HOME_NET # you can give a single ip address or range of IP addresses by syntax [,] and similarly different networks can also be defined as [,]
Change var EXTERNAL_NET any to var EXTERNAL_NET !$HOME_NET # (It states that everything except HOME_NET is external).
The rule path should be
var RULE_PATH /etc/snort/rules
save and exit

Now add rules to /etc/snort/rules directory

just download all the .rules file from the link one by one.

or just follow a simple way, i have created all the links for your convenience and time saving.

# cd /tmp
# mkdir rules
# cd rules
# vim download-rules.txt*checkout*/snort/rules/attack-responses.rules?rev=*checkout*/snort/rules/backdoor.rules?rev=1.50*checkout*/snort/rules/bad-traffic.rules?rev=*checkout*/snort/rules/chat.rules?rev=1.27*checkout*/snort/rules/ddos.rules?rev=*checkout*/snort/rules/deleted.rules?rev=1.39*checkout*/snort/rules/dns.rules?rev=1.42*checkout*/snort/rules/dos.rules?rev=1.43*checkout*/snort/rules/experimental.rules?rev=1.80*checkout*/snort/rules/finger.rules?rev=1.29*checkout*/snort/rules/ftp.rules?rev=1.63*checkout*/snort/rules/icmp-info.rules?rev=1.25*checkout*/snort/rules/icmp.rules?rev=1.27*checkout*/snort/rules/imap.rules?rev=*checkout*/snort/rules/info.rules?rev=1.31*checkout*/snort/rules/misc.rules?rev=1.59*checkout*/snort/rules/local.rules?rev=1.13*checkout*/snort/rules/multimedia.rules?rev=1.15*checkout*/snort/rules/mysql.rules?rev=1.13*checkout*/snort/rules/netbios.rules?rev=1.54*checkout*/snort/rules/nntp.rules?rev=1.16*checkout*/snort/rules/oracle.rules?rev=1.21*checkout*/snort/rules/other-ids.rules?rev=1.12*checkout*/snort/rules/p2p.rules?rev=1.20*checkout*/snort/rules/pop2.rules?rev=1.14*checkout*/snort/rules/pop3.rules?rev=1.26*checkout*/snort/rules/porn.rules?rev=1.12*checkout*/snort/rules/rservices.rules?rev=1.24*checkout*/snort/rules/scan.rules?rev=*checkout*/snort/rules/shellcode.rules?rev=1.27*checkout*/snort/rules/smtp.rules?rev=1.48*checkout*/snort/rules/snmp.rules?rev=1.19*checkout*/snort/rules/sql.rules?rev=1.32*checkout*/snort/rules/telnet.rules?rev=1.40*checkout*/snort/rules/tftp.rules?rev=1.21*checkout*/snort/rules/web-attacks.rules?rev=1.21*checkout*/snort/rules/web-cgi.rules?rev=*checkout*/snort/rules/web-client.rules?rev=1.27*checkout*/snort/rules/web-coldfusion.rules?rev=1.30*checkout*/snort/rules/web-frontpage.rules?rev=1.35*checkout*/snort/rules/web-iis.rules?rev=1.84*checkout*/snort/rules/web-misc.rules?rev=*checkout*/snort/rules/web-php.rules?rev=1.23*checkout*/snort/rules/x11.rules?rev=1.20
save and exit
# wget -i download-rules.txt
it will download all the rules at once saving a lot of time.

[you can start snort by simple creating blank .rules files but remember with blank rule files snort will not detect anything]

after downloading the rules in a directory. Copy the directory on another location. Rename each file to rule-name.rules and then paste the files in /etc/snort/rules directory

change the ownership of newly created rules files

# chown snort.root /etc/snort/rules/*

Keep the original rules directory and match weekly the revision version of each rule on the site to incorporate changes accordingly.

some rules can also be download and copied in rules directory from
 then append these lines in inlude section of/etc/snort/snort.conf file for each new rule
include $RULE_PATH/bleeding.rules
 include $RULE_PATH/bleeding-attack_response.rules
 include $RULE_PATH/bleeding-dos.rules
 include $RULE_PATH/bleeding-drop.rules
 include $RULE_PATH/bleeding-dshield.rules
 include $RULE_PATH/bleeding-exploit.rules
 include $RULE_PATH/bleeding-game.rules
 include $RULE_PATH/bleeding-inappropriate.rules
 include $RULE_PATH/bleeding-malware.rules
 include $RULE_PATH/bleeding-p2p.rules
 include $RULE_PATH/bleeding-scan.rules
 include $RULE_PATH/bleeding-virus.rules
 include $RULE_PATH/bleeding-web.rules

Now its time to start snort

Start snort

# /etc/init.d/snortd start

Remember syslogd daemon must be running in order to take logs

The log file named ‘alert’ will be generated in /var/log/snort directory

now do a port scan and check the alerts in /var/log/snort/alert file, if you have defined a complete subnet in HOME_NET variable then you can do a port scan of any host but that host must be reachable by snort server
If you have some network issues then try stopping iptables and SElinux for test purpose

if you have nmap installed then simple run the command to scan ports

# nmap localhost

you can see alerts in real time by command

# tailf /var/log/snort/alert

At this time snort is running fine and generating alerts
Now lets move to an interesting section

Creating your own Snort Rules:

you can also use Snort Rule Generator or some other utilities but its better to write a rule in a file. lets do it

We are going to create a rule for generating alerts whenever someone is trying to open

# vim /etc/snort/rules/youtube.rules
alert tcp any any -> any any (content:""; msg:"someone is accessing youtube"; sid:1000003; rev:1;)
save and exit

now add the rule path in snort.conf

#vim /etc/snort/snort.conf
append the line in include section as
include $RULE_PATH/youtube.rules
save and exit

and restart snort daemon to take affect changes

# /etc/init.d/snortd restart

lets describe the rule:

alert tcp any any -> any any (content:""; msg:"someone is accessing youtube"; sid:1000003; rev:1;)
tcp = protocol
 1st any = Source IP (your local IP in this case)
 2nd any = Source Port
 -> = request for
 3rd any = Destination IP (youtube IP in this case)
 4th any = Destination Port (that would be 80 in this case)
 sid = snort unique id which snort uses to differentiate different alerts and their descriptions
 rev = version number
Now after creating the rule and restarting the snort daemon, lets check our new rule working status
just type

# elinks

wait for youtube to be loaded

or Open a browser and type

then view the alerts

# cat /var/log/snort/alert

you will see some alerts like

[**] [1:100003:1] someone is accessing [**] [Priority: 0] {TCP} ->
[**] [1:100003:1] someone is accessing [**] [Priority: 0] {TCP} ->


In order to get better results we will have to manage alerts in a more descriptive form

So lets install and configure SnortSnarf an html generator for snort alerts

make sure that you have installed Apache and its running

[root@snortserver ~]# /etc/init.d/httpd status
 httpd (pid 2992 2991 2990 2989 2988 2987 2986 2985 2983) is running...
 [root@snortserver ~]#

otherwise just start it

# /etc/init.d/httpd start

make sure that you have installed perl5 packages because SnortSnarf depends on perl based Time modules

lets start

download snortsnarf from

# cd /etc
# wget
# tar -zxvf SnortSnarf-1.0.tar.gz

Now you have to download and install Time modules needed for snortsnarf from

# wget
# tar -zxvf Time-modules-2006.0814.tar.gz
# cd Time-modules-2006.0814

install the modules by following commands:

# perl
# make
# make test
# make install

After successfull installation of Time modules, create a destination directory where snortsnarf will generate html pages as an output

# mkdir /var/www/html/ids

Now run snortsnarf

# cd /etc/SnortSnarf-1.0
# ./ -d /var/www/html/ids/ /var/log/snort/alert

where -d defines output directory and /var/log/snort/alert is the source file to take input.

The above command shows a similar output on the console

[root@snortserver SnortSnarf-1.0]# ./ -d /var/www/html/ids/ /var/log/snort/alert
 Using an array as a reference is deprecated at include/SnortSnarf/ line 290.
 Using an array as a reference is deprecated at include/SnortSnarf/ line 266.
 SnortFileInput: input file /var/log/snort/alert exists but is length 0; skipping it
 [root@snortserver SnortSnarf-1.0]#

if your /var/log/snort/alert file is not empty then you will not see the last output line

Cron Job for SnortSnarf:

Create a cron job to automatically run the snorsnarf script to append alerts in html pages

first of all make a simple script

# cd /etc
# touch snortsnarf
# vim snortsnarf
cd /etc/SnortSnarf-1.0
 ./ -d /var/www/html/ids /var/log/snort/alert
save and exit

make the script executable

# chmod +x snortsnarf

now define a new cron job to run snortsnarf after every 5 minutes

# crontab -e
*/5 * * * * /etc/snortsnarf
save and exit

*/5 means that snortsnarf will be run after every 5 minutes, you can adjust the time accordingly.

restart the cron and Apache daemons

# /etc/init.d/crond restart
# /etc/init.d/httpd restart

now create a simple port scan and generate alerts in /var/log/snort/alert file and then open your browser and type http://localhost/ids

You can see the alerts, further click the alerts and find some more information and go on.

Now snort IDS with SnortSnarf has been successfully configured, Alhamdullilah