Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 1
#!/bin/sh
2
# $Id$
3
#
4
# snortd         Start/Stop the snort IDS daemon.
5
#
6
# chkconfig: 2345 40 60
7
# description:  snort is a lightweight network intrusion detection tool that \
8
#                currently detects more than 1100 host and network \
9
#                vulnerabilities, portscans, backdoors, and more.
10
#
11
 
12
# Source function library.
13
. /etc/rc.d/init.d/functions
14
 
15
# Source the local configuration file
16
. /etc/sysconfig/snort
17
 
18
# Convert the /etc/sysconfig/snort settings to something snort can
19
# use on the startup line.
20
if [ "$ALERTMODE"X = "X" ]; then
21
   ALERTMODE=""
22
else
23
   ALERTMODE="-A $ALERTMODE"
24
fi
25
 
26
if [ "$USER"X = "X" ]; then
27
   USER="snort"
28
fi
29
 
30
if [ "$GROUP"X = "X" ]; then
31
   GROUP="snort"
32
fi
33
 
34
if [ "$BINARY_LOG"X = "1X" ]; then
35
   BINARY_LOG="-b"
36
else
37
   BINARY_LOG=""
38
fi
39
 
40
if [ "$CONF"X = "X" ]; then
41
   CONF="-c /etc/snort/snort.conf"
42
else
43
   CONF="-c $CONF"
44
fi
45
 
46
if [ "$INTERFACE"X = "X" ]; then
47
   INTERFACE="-i eth0"
48
else
49
   INTERFACE="-i $INTERFACE"
50
fi
51
 
52
if [ "$DUMP_APP"X = "1X" ]; then
53
   DUMP_APP="-d"
54
else
55
   DUMP_APP=""
56
fi
57
 
58
if [ "$NO_PACKET_LOG"X = "1X" ]; then
59
   NO_PACKET_LOG="-N"
60
else
61
   NO_PACKET_LOG=""
62
fi
63
 
64
if [ "$PRINT_INTERFACE"X = "1X" ]; then
65
   PRINT_INTERFACE="-I"
66
else
67
   PRINT_INTERFACE=""
68
fi
69
 
70
if [ "$PASS_FIRST"X = "1X" ]; then
71
   PASS_FIRST="-o"
72
else
73
   PASS_FIRST=""
74
fi
75
 
76
if [ "$LOGDIR"X = "X" ]; then
77
   LOGDIR=/var/log/snort
78
fi
79
 
80
# These are used by the 'stats' option
81
if [ "$SYSLOG"X = "X" ]; then
82
   SYSLOG=/var/log/messages
83
fi
84
 
85
if [ "$SECS"X = "X" ]; then
86
   SECS=5
87
fi
88
 
89
if [ ! "$BPFFILE"X = "X" ]; then
90
   BPFFILE="-F $BPFFILE"
91
fi
92
 
93
######################################
94
# Now to the real heart of the matter:
95
 
96
# See how we were called.
97
case "$1" in
98
  start)
99
        echo -n "Starting snort: "
100
        cd $LOGDIR
101
        if [ "$INTERFACE" = "-i ALL" ]; then
102
           for i in `cat /proc/net/dev|grep eth|awk -F ":" '{ print $1; }'`
103
           do
104
                mkdir -p "$LOGDIR/$i"
105
                chown -R $USER:$GROUP $LOGDIR
106
                daemon /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 $BPF
107
           done
108
        else
109
           # check if more than one interface is given
110
           if [ `echo $INTERFACE|wc -w` -gt 2 ]; then
111
              for i in `echo $INTERFACE | sed s/"-i "//`
112
                do
113
                  mkdir -p "$LOGDIR/$i"
114
                  chown -R $USER:$GROUP $LOGDIR
115
                  daemon /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 $BPF
116
             done
117
           else
118
              # Run with a single interface (default)
119
              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 $BPF
120
           fi
121
        fi
122
        touch /var/lock/subsys/snort
123
        echo
124
        ;;
125
  stop)
126
        echo -n "Stopping snort: "
127
        killproc snort
128
        rm -f /var/lock/subsys/snort
129
        echo
130
        ;;
131
  reload)
132
        echo "Sorry, not implemented yet"
133
        ;;
134
  restart)
135
        $0 stop
136
        $0 start
137
        ;;
138
  condrestart)
139
        [ -e /var/lock/subsys/snort ] && $0 restart
140
        ;;
141
  status)
142
        status snort
143
        ;;
144
  stats)
145
        TC=125                          # Trailing context to grep
146
        SNORTNAME='snort'               # Process name to look for
147
 
148
        if [ ! -x "/sbin/pidof" ]; then
149
           echo "/sbin/pidof not present, sorry, I cannot go on like this!"
150
           exit 1
151
        fi
152
 
153
        #Grab Snort's PID
154
        PID=`pidof -o $$ -o $PPID -o %PPID -x ${SNORTNAME}`
155
 
156
        if [ ! -n "$PID" ]; then        # if we got no PID then:
157
           echo "No PID found: ${SNORTNAME} must not running."
158
           exit 2
159
        fi
160
 
161
        echo ""
162
        echo "*******"
163
        echo "WARNING:  This feature is EXPERIMENTAL - please report errors!"
164
        echo "*******"
165
        echo ""
166
        echo "You can also run: $0 stats [long | opt]"
167
        echo ""
168
        echo "Dumping ${SNORTNAME}'s ($PID) statistics"
169
        echo "please wait..."
170
 
171
        # Get the date and tell Snort to dump stats as close together in
172
        # time as possible--not 100%, but it seems to work.
173
        startdate=`date '+%b %e %H:%M:%S'`
174
 
175
        # This causes the stats to be dumped to syslog
176
        kill -USR1 $PID
177
 
178
        # Sleep for $SECS secs to give syslog a chance to catch up
179
        # May need to be adjusted for slow/busy systems
180
        sleep $SECS
181
 
182
        if [ "$2" = "long" ]; then              # Long format
183
            egrep -B 3 -A $TC "^$startdate .* snort.*: ={79}" $SYSLOG | \
184
                grep snort.*:
185
        elif [ "$2" = "opt" ]; then             # OPTimize format
186
           # Just show stuff useful for optimizing Snort
187
            egrep -B 3 -A $TC "^$startdate .* snort.*: ={79}" $SYSLOG | \
188
                egrep "snort.*: Snort analyzed |snort.*: dropping|emory .aults:"
189
        else                                    # Default format
190
            egrep -B 3 -A $TC "^$startdate .* snort.*: ={79}" $SYSLOG | \
191
                grep snort.*: | cut -d: -f4-
192
        fi
193
        ;;
194
  *)
195
        echo "Usage: $0 {start|stop|reload|restart|condrestart|status|stats (long|opt)}"
196
        exit 2
197
esac
198
 
199
exit 0