Snort from scratch (Part I)
An IDS is a security tool, that allow us to monitor our network
events searching attempts to compromise the security of our systems.
It’s possible matching predefinied rules emulating the behaviour of an
attack and it’s possible to deny the package or simply alert us to an
email or sending messages to log. Basically we can find two types of
IDS:
SNORT
Snort is a NIDS, implements real time scanning of attack detection and port scanning detecting. The basic architecture of snort:

For this post I’ll explain how to install and configure snort from the source code in CentOS 6 and download free ruleset for snort and configure for be used.
Installing dependencies and preparing the environment
- Installing rpmforge repository:
- Install prerequisites packages:
- Downloading and installing daq:
- Creating snort user and tree directories:
Installing Snort and configuring the ruleset
- Downloading and installing snort:
- Downloading open source ruleset from emerging:
- Edit snort configuration:
Configuring the init script for Snort
- Create sysconfig snort configuration:
- Adding the init script:
- Start snort at system boot time:
- Starting snort:
Testing the basic functionality of port scanning detection with nmap
- HIDS: Host based IDS, monitors the activity of a single machine, searching anomaling behaviors.
- NID: Network IDS, capture and analyze network packages to search attack patterns.
SNORT
Snort is a NIDS, implements real time scanning of attack detection and port scanning detecting. The basic architecture of snort:
- Packet capture module: Used to capture network traffic using libpcap library.
- Decoder: It ensures to form the data structures of the packages captured and identify the network protocol.
- Preprocessor: prepocessors are plugins developed generally in C and
process the packets provided by the decoder and ensambles the packets
received. This preprocessors are configured in snort.conf file
configuration. Some preprocessor examples may be:
- sfPortscan
- Frag3
- HTTP
- SSH
- To see a complete list visit: http://manual.snort.org/node17.html - Detection engine: Analyze the packets based in our rules configued.
- Detection plugins: Used to modify the behaviour of the detection engine.
- Output plugins: Defines how and where saves the alters and the packages generated.
For this post I’ll explain how to install and configure snort from the source code in CentOS 6 and download free ruleset for snort and configure for be used.
Installing dependencies and preparing the environment
- Installing rpmforge repository:
# yum -y install libdnet libdnet-devel libpcap libpcap-devel daq gcc make flex bison pcre pcre-devel zlib zlib-devel |
# cd /tmp ; wget http://www.snort.org/downloads/1850 -O daq-1.1.1.tar.gz# tar -xzvf daq-1.1.1.tar.gz# cd daq-1.1.1/# ./configure# make && make install# ldconfig -v |
# groupadd snort# useradd -g snort snort# mkdir /usr/local/snort# mkdir /etc/snort# mkdir /var/log/snort# mkdir /var/run/snort# chown snort:snort /var/log/snort# chown snort:snort /var/run/snort |
- Downloading and installing snort:
# cd /tmp ; wget http://www.snort.org/downloads/1862 -O snort-2.9.3.1.tar.gz# tar -xzvf snort-2.9.3.1.tar.gz# cd snort-2.9.3.1/# ./configure --prefix /usr/local/snort --enable-sourcefire --enable-ipv6# make && make install# ln -s /usr/local/snort/bin/snort /usr/bin/snort# cp /tmp/snort-2.9.3.1/etc/snort.conf /etc/snort/# cp /tmp/snort-2.9.3.1/etc/unicode.map /etc/snort/# cp /tmp/snort-2.9.3.1/etc/classification.config /etc/snort/# cp -r /usr/local/snort/lib/snort_dynamicpreprocessor/ /usr/local/lib/# cp -r /usr/local/snort/lib/snort_dynamicengine /usr/local/lib/ |
# cd /etc/snort ; wget http://rules.emergingthreats.net/open/snort-2.9.0/emerging.rules.tar.gz && wget http://rules.emergingthreats.net/open/snort-2.9.0/reference.config# tar -xzvf emerging.rules.tar.gz# touch /etc/snort/rules/white_list.rules /etc/snort/rules/black_list.rules# chown -R snort:snort /etc/snort/ |
# vi /etc/snort/snort.conf |
ipvar HOME_NET 192.168.1.0/24var RULE_PATH /etc/snort/rulesvar SO_RULE_PATH /etc/snort/so_rulesvar PREPROC_RULE_PATH /etc/snort/preproc_rulesvar WHITE_LIST_PATH /etc/snort/rulesvar BLACK_LIST_PATH /etc/snort/rulesinclude $RULE_PATH/emerging.confoutput alert_full /var/log/snort/alert |
- Create sysconfig snort configuration:
# vi /etc/sysconfig/snort |
#### General ConfigurationINTERFACE=eth0CONF=/etc/snort/snort.confUSER=snortGROUP=snortPASS_FIRST=0#### Logging & AlertingLOGDIR=/var/log/snortALERTMODE=fastDUMP_APP=1BINARY_LOG=1NO_PACKET_LOG=0PRINT_INTERFACE=0 |
# vi /etc/init.d/snortd |
#!/bin/bash## snort Start up the Snort Intrusion Detection System daemon ## chkconfig: 2345 55 25# description: Snort is a Open Source Intrusion Detection System# This service starts up the snort daemon. ## processname: snort# pidfile: /var/run/snort_eth0.pid### BEGIN INIT INFO# Provides: snort# Required-Start: $local_fs $network $syslog# Required-Stop: $local_fs $syslog# Should-Start: $syslog# Should-Stop: $network $syslog# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: Start up the Snort Intrusion Detection System daemon# Description: Snort is an application for Open Source Intrusion Detection.# This service starts up the Snort IDS daemon.### END INIT INFO# source function library. /etc/rc.d/init.d/functions# pull in sysconfig settings[ -f /etc/sysconfig/snort ] && . /etc/sysconfig/snortRETVAL=0prog="snort"lockfile=/var/lock/subsys/$prog# Some functions to make the below more readableSNORTD=/usr/bin/snort#OPTIONS="-A fast -b -d -D -i eth0 -u snort -g snort -c /etc/snort/snort.conf -l /var/log/snort"#PID_FILE=/var/run/snort_eth0.pid# Convert the /etc/sysconfig/snort settings to something snort can# use on the startup line.if [ "$ALERTMODE"X = "X" ]; thenALERTMODE=""elseALERTMODE="-A $ALERTMODE"fiif [ "$USER"X = "X" ]; thenUSER="snort"fiif [ "$GROUP"X = "X" ]; thenGROUP="snort"fiif [ "$BINARY_LOG"X = "1X" ]; thenBINARY_LOG="-b"elseBINARY_LOG=""fiif [ "$LINK_LAYER"X = "1X" ]; thenLINK_LAYER="-e"elseLINK_LAYER=""fiif [ "$CONF"X = "X" ]; thenCONF="-c /etc/snort/snort.conf"elseCONF="-c $CONF"fiif [ "$INTERFACE"X = "X" ]; thenINTERFACE="-i eth0"PID_FILE="/var/run/snort_eth0.pid"elsePID_FILE="/var/run/snort_$INTERFACE.pid"INTERFACE="-i $INTERFACE"fiif [ "$DUMP_APP"X = "1X" ]; thenDUMP_APP="-d"elseDUMP_APP=""fiif [ "$NO_PACKET_LOG"X = "1X" ]; thenNO_PACKET_LOG="-N"elseNO_PACKET_LOG=""fiif [ "$PRINT_INTERFACE"X = "1X" ]; thenPRINT_INTERFACE="-I"elsePRINT_INTERFACE=""fiif [ "$PASS_FIRST"X = "1X" ]; thenPASS_FIRST="-o"elsePASS_FIRST=""fiif [ "$LOGDIR"X = "X" ]; thenLOGDIR=/var/log/snortfi# These are used by the 'stats' optionif [ "$SYSLOG"X = "X" ]; thenSYSLOG=/var/log/messagesfiif [ "$SECS"X = "X" ]; thenSECS=5fiif [ ! "$BPFFILE"X = "X" ]; thenBPFFILE="-F $BPFFILE"firunlevel=$(set -- $(runlevel); eval "echo $$#" )start(){[ -x $SNORTD ] || exit 5echo -n $"Starting $prog: "daemon
--pidfile=$PID_FILE $SNORTD $ALERTMODE $BINARY_LOG $LINK_LAYER
$NO_PACKET_LOG $DUMP_APP -D $PRINT_INTERFACE $INTERFACE -u $USER -g
$GROUP $CONF -l $LOGDIR $PASS_FIRST $BPFFILE $BPF && success ||
failureRETVAL=$?[ $RETVAL -eq 0 ] && touch $lockfileechoreturn $RETVAL}stop(){echo -n $"Stopping $prog: "killproc $SNORTDif [ -e $PID_FILE ]; thenchown -R $USER:$GROUP /var/run/snort_eth0.* && rm -f /var/run/snort_eth0.pi*fiRETVAL=$?# if we are in halt or reboot runlevel kill all running sessions# so the TCP connections are closed cleanlyif [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; thentrap TERMkillall $prog 2> /dev/nulltrap TERMfi[ $RETVAL -eq 0 ] && rm -f $lockfileechoreturn $RETVAL}restart() {stopstart}rh_status() {status -p $PID_FILE $SNORTD}rh_status_q() {rh_status > /dev/null 2>&;1}case "$1" instart)rh_status_q && exit 0start;;stop)if ! rh_status_q; thenrm -f $lockfileexit 0fistop;;restart)restart;;status)rh_statusRETVAL=$?if [ $RETVAL -eq 3 -a -f $lockfile ] ; thenRETVAL=2fi;;*)echo $"Usage: $0 {start|stop|restart|status}"RETVAL=2esacexit $RETVAL |
# chmod +x /etc/init.d/snortd# chkconfig --levels 235 snortd on |
# /etc/init.d/snortd start |
# tail -f /var/log/snort/alert |
Nhận xét
Đăng nhận xét