This is a tutorial based on my experience with installing Snort IDS with the BASE system to view, dissect and graph alerts. This is a very straightforward install thanks to FreeBSD's ports system. If you choose another operating system like Linux, note that you probably will have to install from source because the package management systems like aptitude are severely out of date.
Let's begin!
# Locate Snort in the FreeBSD ports tree and cd into that directory:
cd /usr/ports/security/snort
# Change to the root user and install
sudo make install clean
It will ask you a few questions in a ncurses interface, choose the database you will be using. I choose MySQL because it is already installed, but I recommend PostgreSQL for its speed and ease of use.
When it finishes compiling we need to install oinkmaster. Oinkmaster is a port that will get the latest signatures from snort.org. Configuration instructions for this are followed after we install.
#Locate oinkmaster and cd into its directory
cd /usr/ports/security/oinkmaster
# Change to root user and install
sudo make install clean
Now you need to goto snort.org and register in order to receive the latest snort definitions. You will receive a hash which you'll place in your configuration file. Save this hash. It's time to setup the configuration file for oinkmaster and then run it to receive over 500MB of definitions.
# change the name of oinkmaster.conf.sample to oinkmaster.conf
mv /usr/local/etc/oinkmaster.conf.sample /usr/local/etc/oinkmaster.conf
# open this up with your favorite editor
ee /usr/local/etc/oinkmaster.conf
Inside this configuration you need to look for this line: Example for Snort-Current.
Change the to the hash you saved earlier (replacing the < , > symbols as well).
Now the next part which I ran into trouble with was that when we run oinkmaster like:
oinkmaster -o /usr/local/etc/snort/rules
I realized that there was not enough space in my /tmp directory.
[root@mysystem ~]$ df
Filesystem 1K-blocks Used Avail Capacity Mounted on
/dev/ad2s1a 507630 220226 246794 47% /
devfs 1 1 0 100% /dev
/dev/ad2s1e 507630 164 466856 0% /tmp
/dev/ad2s1f 146367154 9481038 125176744 7% /usr
/dev/ad2s1d 1998574 1489084 349606 81% /var
So I changed the directory where oinkmaster saves the tar.gz to another directory that was in a larger partition.
# change the directory if your /tmp partition is under 500MB
tmpdir = /home/someuser/snort/
Now that oinkmaster has enough room to download and extract the tarball we can run our command again:
oinkmaster -o /usr/local/etc/snort/rules
Our rules are up to date, now we need to setup a database so that Snort can save alerts and BASE can display them on the web.
# login as root to MySQL, create a database and user for snort
mysql -u root -p
CREATE DATABASE `snort`;
GRANT ALL PRIVILEGES ON snort.* to 'snort'@'localhost' IDENTIFIED by 'somepasswordhere';
Now we setup our database with tables and the appropriate data with a script that was included in the port.
#login to MySQL as the snort user and direct all the data from create_mysql into the database
mysql -u snort -p snort < usr/local/share/examples/snort/create_mysql</code>
There are a few more things to do to make snort work. We first have to edit the snort.conf so that it knows about our database. We also have to add snort to our startup options (rc.conf).
#open up snort.conf and optimize and configure some settings (make sure your db settings are correct)
ee /usr/local/etc/snort/snort.conf</code>
#uncomment the following lines (and configure):
# config detection: search-method lowmem
# output alert_syslog: LOG_AUTH LOG_ALERT
# output database: log, mysql, user=snort password=mysnortpassword dbname=snort host=localhost
Also make sure to uncomment all the include $RULE_PATH lines, or if you want, only uncomment the ones you wish to monitor, which will increase speed but decrease definitions to check for.
Enable snort in rc.conf:
sudo ee /etc/rc.conf # and adding snort_enable=”YES”</code>
Let's install BASE now:
cd /usr/ports/databases/adobd; sudo make install clean
cd /usr/ports/security/base; sudo make install clean
Setup apache to point to the directory base is installed in and restart apache.
#start snort
sudo /usr/local/etc/rc.d/snort start
Login to your BASE site and follow the instructions and now your IDS system is installed.
Using Snort with BASE:
This is the BASE main screen on my server. It give the user an easy to use interface to view different alerts.
I find it best to view the unique alerts on this main screen and check the details of those packet captures.
Here is a display of the unique alerts. It shows the total amount of times that specific alert was triggered. You can open up a specific incident and view the pcap file in many different formats.
Here is a payload of the MSSQL Slammer worm. It is the most active alert on my server, however it poses no threat to me because I do not run Windows.
There is even graphing functions:
It is useful to know about what is going on in your network and Snort is an excellent tool to assist with this. However, Snort IDS will not stop attacks, it only displays what has happened. There are other tools to actually stop attacks, like Snort-Inline (modes such as PRM or packet replace mode, change the data so it becomes useless).
You need to supplement your server with PF (packet filtering) in order to maintain a good degree of security. If you notice, there has been no alerts of port scanning. My PF configuration stops this kind of activity completely.
Other tools to increase your awareness of an incident on FreeBSD would be to install TripWire which shows what files were modified, created or deleted on your system. Also some configuration changes like putting your OpenSSH server on a higher port so bots do not brute force it. With some scripts and IPTables you can blacklist certain IP's from repeated brute force attempts against your server. You should also always use a remote logging system because it is very easy for the attacker to clean the logs once the attacker has root access to your server.