Blame | Last modification | View Log | RSS feed
#!/bin/sh# $Id$## snortd Start/Stop the snort IDS daemon.## chkconfig: 2345 40 60# description: snort is a lightweight network intrusion detection tool that \# currently detects more than 1100 host and network \# vulnerabilities, portscans, backdoors, and more.## Source function library.. /etc/rc.d/init.d/functions# Source the local configuration file. /etc/sysconfig/snort# 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 [ "$CONF"X = "X" ]; thenCONF="-c /etc/snort/snort.conf"elseCONF="-c $CONF"fiif [ "$INTERFACE"X = "X" ]; thenINTERFACE="-i eth0"elseINTERFACE="-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"fi####################################### Now to the real heart of the matter:# See how we were called.case "$1" instart)echo -n "Starting snort: "cd $LOGDIRif [ "$INTERFACE" = "-i ALL" ]; thenfor i in `cat /proc/net/dev|grep eth|awk -F ":" '{ print $1; }'`domkdir -p "$LOGDIR/$i"chown -R $USER:$GROUP $LOGDIRdaemon /usr/local/bin/snort $ALERTMODE $BINARY_LOG $NO_PACKET_LOG $DUMP_APP -D $PRINT_INTERFACE -i $i -u $USER -g $GROUP $CONF -l $LOGDIR/$i $PASS_FIRST $BPFFILE $BPFdoneelse# check if more than one interface is givenif [ `echo $INTERFACE|wc -w` -gt 2 ]; thenfor i in `echo $INTERFACE | sed s/"-i "//`domkdir -p "$LOGDIR/$i"chown -R $USER:$GROUP $LOGDIRdaemon /usr/local/bin/snort $ALERTMODE $BINARY_LOG $NO_PACKET_LOG $DUMP_APP -D $PRINT_INTERFACE -i $i -u $USER -g $GROUP $CONF -l $LOGDIR/$i $PASS_FIRST $BPFFILE $BPFdoneelse# Run with a single interface (default)daemon /usr/local/bin/snort $ALERTMODE $BINARY_LOG $NO_PACKET_LOG $DUMP_APP -D $PRINT_INTERFACE $INTERFACE -u $USER -g $GROUP $CONF -l $LOGDIR $PASS_FIRST $BPFFILE $BPFfifitouch /var/lock/subsys/snortecho;;stop)echo -n "Stopping snort: "killproc snortrm -f /var/lock/subsys/snortecho;;reload)echo "Sorry, not implemented yet";;restart)$0 stop$0 start;;condrestart)[ -e /var/lock/subsys/snort ] && $0 restart;;status)status snort;;stats)TC=125 # Trailing context to grepSNORTNAME='snort' # Process name to look forif [ ! -x "/sbin/pidof" ]; thenecho "/sbin/pidof not present, sorry, I cannot go on like this!"exit 1fi#Grab Snort's PIDPID=`pidof -o $$ -o $PPID -o %PPID -x ${SNORTNAME}`if [ ! -n "$PID" ]; then # if we got no PID then:echo "No PID found: ${SNORTNAME} must not running."exit 2fiecho ""echo "*******"echo "WARNING: This feature is EXPERIMENTAL - please report errors!"echo "*******"echo ""echo "You can also run: $0 stats [long | opt]"echo ""echo "Dumping ${SNORTNAME}'s ($PID) statistics"echo "please wait..."# Get the date and tell Snort to dump stats as close together in# time as possible--not 100%, but it seems to work.startdate=`date '+%b %e %H:%M:%S'`# This causes the stats to be dumped to syslogkill -USR1 $PID# Sleep for $SECS secs to give syslog a chance to catch up# May need to be adjusted for slow/busy systemssleep $SECSif [ "$2" = "long" ]; then # Long formategrep -B 3 -A $TC "^$startdate .* snort.*: ={79}" $SYSLOG | \grep snort.*:elif [ "$2" = "opt" ]; then # OPTimize format# Just show stuff useful for optimizing Snortegrep -B 3 -A $TC "^$startdate .* snort.*: ={79}" $SYSLOG | \egrep "snort.*: Snort analyzed |snort.*: dropping|emory .aults:"else # Default formategrep -B 3 -A $TC "^$startdate .* snort.*: ={79}" $SYSLOG | \grep snort.*: | cut -d: -f4-fi;;*)echo "Usage: $0 {start|stop|reload|restart|condrestart|status|stats (long|opt)}"exit 2esacexit 0