Snort IPS Tutorial
Snort IPS Tutorial
Snort IPS Tutorial
Based on
Vmware ESXi, Snort and Debian Linux
Step-by-step Tutorial
2015
Chapter:
Vladimir Koychev
I.
II.
III.
IV.
V.
VI.
VII.
VIII.
IX.
X.
References ................................................................................................................................................................ 9
Chapter:
Contents
I.
Setup overview
The tutorial aims to give general instructions on how to setup Intrusion Prevention System using VMware
ESXi , Snort in IPS mode and Debian Linux. The main goal of such a setup is adding protection over a local
network by passing all external traffic to IPS component for inspection. The setup sketch below:
II.
III.
IV.
Snort Installation
1. Install Snort
cd /usr/src
wget https://www.snort.org/downloads/snort/snort-2.9.7.0.tar.gz
tar -zxf snort-2.9.7.0.tar.gz && cd snort-2.9.7.0
./configure --enable-sourcefire && make && make install
2. Create Snort directories:
mkdir /usr/local/etc/snort
mkdir /usr/local/etc/snort/rules
mkdir /var/log/snort
mkdir /usr/local/lib/snort_dynamicrules
3. Create empty rules files:
touch /usr/local/etc/snort/rules/white_list.rules
touch /usr/local/etc/snort/rules/black_list.rules
touch /usr/local/etc/snort/rules/local.rules
touch /usr/local/etc/snort/rules/snort.rules
touch /usr/local/etc/snort/sid-msg.map
4. Create snort user and grant privileges:
groupadd snort && useradd -g snort snort
chown snort:snort /var/log/snort
5. Copy snort configuration files:
V.
6.
7.
8.
9.
10.
PulledPork Installation
Default Snort installation doesnt contain any rules/signatures. Snort rules can be created by the user (see
https://www.snort.org/ for more information), downloaded manually or automatically using PulledPork. The
following instructions describe the installation and configuration of PulledPork.
1. Install PulledPork:
cd /usr/src
wget https://pulledpork.googlecode.com/files/pulledpork-0.7.0.tar.gz
tar xzf pulledpork-0.7.0.tar.gz && cd pulledpork-0.7.0
cp pulledpork.pl /usr/local/bin/ && chmod +x /usr/local/bin/pulledpork.pl
cd etc && cp * /usr/local/etc/snort/
2. Snort can use community rules (freely available) and the registered rules. In order to use
registered rules, it is necessary to be obtained Oinkcode via registration at:
https://www.snort.org/
3. Configure PulledPork (edit /usr/local/etc/snort/pulledpork.cong):
VI.
cp /usr/src/snort-2.9.7.0/etc/*.conf* /usr/local/etc/snort
cp /usr/src/snort-2.9.7.0/etc/*.map /usr/local/etc/snort
Configure Snort (edit snort.conf)
vim /usr/local/etc/snort/snort.conf
Line #45 - ipvar HOME_NET 172.26.12.0/22 make this match your internal network;
Line #48 - ipvar EXTERNAL_NET !$HOME_NET
Line #104 - var RULE_PATH rules
Line #109 - var WHITE_LIST_PATH rules
Line #110 - var BLACK_LIST_PATH rules
Line #293 - add this to the end after decompress_depth 65535 max_gzip_mem
104857600
Line #521 - add this line - output unified2: filename snort.log, limit 128
Line #543 - delete or comment out all of the include $RULE_PATH lines except:
include $RULE_PATH/local.rules
include $RULE_PATH/snort.rules add after local.rules
Make sure at line #265 the following rules are uncommented:
preprocessor normalize_ip4
preprocessor normalize_tcp: ips ecn stream
preprocessor normalize_icmp4
preprocessor normalize_ip6
preprocessor normalize_icmp6
On line #188 at the end of step #2 of snort.cong add:
config policy_mode:inline
Configure daq at line #159 in snort.cong
config daq: afpacket
config daq_dir: /usr/local/lib/daq
config daq_mode: inline
config daq_var: buffer_size_mb=1024
Save changes to snort.conf
vim / usr/local/etc/snort/pulledpork.cong
If Oinkcode available add it on line #19 and #26 e.g. rule_url=https://www.snort.org/regrules/|snortrules-snapshot-2970.tar.gz|1234123412313232132321321313113131312321 or
comment out for community rules only;
Leave line #27 uncommented to use the Emerging Threats rules;
Line #71: change to: rule_path=/usr/local/etc/snort/rules/snort.rules
Line #86: change to: local_rules =/usr/local/etc/snort/rules/local.rules
Line #89: change to: sid_msg=/usr/local/etc/snort/sid-msg.map
Line #112: change to: config_path=/usr/local/etc/snort/snort.conf
Line #124: change to: distro=Debian-7-7
Line #139: change to: black_list=/usr/local/etc/snort/rules/black_list.rules
Line #200: make sure the following paths are available and uncommented:
enablesid=/usr/local/etc/snort/enablesid.conf
dropsid=/usr/local/etc/snort/dropsid.conf
disablesid=/usr/local/etc/snort/disablesid.conf
modifysid=/usr/local/etc/snort/modifysid.conf
Save changes to pulledpork.conf
4. IMPORTANT: Default configuration only alerts upon rule/signature match, no matter if Snort
configured in Inline mode. Therefore the action upon match should be changed from alert to
DROP;
vim /usr/local/etc/snort/dropsid.conf (For more information: https://www.snort.org)
Make sure all lines are commented;
vim /usr/local/etc/snort/ modifysid.conf
Add to the end of the file: * "^\s*alert" "DROP"
Reboot the VM;
5. Run PulledPork
/usr/local/bin/pulledpork.pl -c /usr/local/etc/snort/pulledpork.conf -T -l
6. Create cronjob
* */1 * * * /usr/local/bin/pulledpork.pl -c /usr/local/etc/snort/pulledpork.conf -T -l
>/dev/null 2>&1
Barnyard installation
Barnyard2 is an open source interpreter for Snort unified2 binary output files. Its primary use is allowing
Snort to write to disk in an efficient manner and leaving the task of parsing binary data into various formats
to a separate process that will not cause Snort to miss network traffic. https://github.com/firnsy/barnyard2
1. Install Barnyard2;
cd /usr/src
wget https://github.com/binf/barnyard2/tree/bug-fix-release
unzip bug-fix-release.zip
cd barnyard2-bug-fix-release
autoreconf -fvi -I ./m4 && ./configure --with-mysql --with-mysql-libraries=/usr/lib/x86_64linux-gnu
make && make install
2. Configure Barnyard2
cd /etc && cp barnyard2.conf /usr/local/etc/snort
mkdir /var/log/barnyard2
VII.
VIII.
Using Snort
1. Snort in inline mode no database logging (console alerts):
snort -d -A console -u snort -g snort -c /usr/local/etc/snort/snort.conf -i eth1:eth2 -Q
2. Snort in inline mode no database logging (Logged alerts):
snort -d -A full -u snort -g snort -c /usr/local/etc/snort/snort.conf -i eth1:eth2 -Q
3. Snort in inline mode and database logging (console alerts):
snort -d -A console -u snort -g snort -c /usr/local/etc/snort/snort.conf -i eth1:eth2 -Q &
/usr/local/bin/barnyard2 -c /usr/local/etc/snort/barnyard2.conf -d /var/log/snort -f
snort.log -w /usr/local/etc/snort/bylog.waldo -C /usr/local/etc/snort/classification.config
4. Snort in inline mode and database logging (Logged alerts):
snort -d -A full -u snort -g snort -c /usr/local/etc/snort/snort.conf -i eth1:eth2 -Q &
/usr/local/bin/barnyard2 -c /usr/local/etc/snort/barnyard2.conf -d /var/log/snort -f
snort.log -w /usr/local/etc/snort/bylog.waldo -C /usr/local/etc/snort/classification.config
5. Snort in inline mode no database logging no snort status (console alerts):
snort -q -d -A console -u snort -g snort -c /usr/local/etc/snort/snort.conf -i eth1:eth2 -Q
Installing BASE
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. - http://sourceforge.net/projects/secureideas/
1. Configure Apache & PHP
cp /etc/apache2/sites-available/default-ssl /etc/apache2/sites-enabled
vim /etc/php5/apache2/php.ini
Line #452: change to: error_reporting = E_ALL & ~E_NOTICE
a2enmod ssl
IX.
References
1. ^ https://www.snort.org/
2. ^ Jason Weir, Snort 2.9.6.x on Debian 7.6, https://s3.amazonaws.com/snort-orgsite/production/document_files/files/000/000/049/original/Debian___Snort_based_Intrusion_Dete
ction_System.pdf?AWSAccessKeyId=AKIAIXACIED2SPMSC7GA&Expires=1426706767&Signature=EBD
oAqabQuhmyzrOI2EqkPXjccc%3D
3. ^ Yaser Mansour, Snort IPS using DAQ AFPacket, https://s3.amazonaws.com/snort-orgsite/production/document_files/files/000/000/013/original/Snort_IPS_using_DAQ_AFPacket.pdf?A
WSAccessKeyId=AKIAIXACIED2SPMSC7GA&Expires=1426706931&Signature=J5vvL1BXS1lJYBngaNeu
%2F70Ssvo%3D
4. ^ http://sourceforge.net/projects/secureideas/
5. ^ https://github.com/firnsy/barnyard2
Chapter: References
X.