new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / debian / ossec-hids / var / ossec / active-response / bin / ipfw.sh
1 #!/bin/sh
2 # Adds an IP to the IPFW drop list.
3 # Only works with IPFW.
4 # We use TABLE 00001. If you use this table for anything else,
5 # please change it here.
6 # Expect: srcip
7 # Author: Rafael Capovilla - under @ ( at ) underlinux.com.br
8 # Author: Daniel B. Cid - dcid @ ( at ) ossec.net
9 # Last modified: May 07, 2006
10
11 UNAME=`uname`
12 IPFW="/sbin/ipfw"
13 ARG1=""
14 ARG2=""
15 ACTION=$1
16 USER=$2
17 IP=$3
18 TABLE_ID=00001
19
20 LOCAL=`dirname $0`;
21 cd $LOCAL
22 cd ../
23 PWD=`pwd`
24 echo "`date` $0 $1 $2 $3 $4 $5" >> ${PWD}/../logs/active-responses.log
25
26
27 # Checking for an IP
28 if [ "x${IP}" = "x" ]; then
29    echo "$0: <action> <username> <ip>" 
30    exit 1;
31 fi
32
33
34
35 # Blocking IP
36 if [ "x${ACTION}" != "xadd" -a "x${ACTION}" != "xdelete" ]; then
37    echo "$0: Invalid action: ${ACTION}"
38    exit 1;
39 fi
40
41
42 # We should run on FreeBSD
43 # We always use table 00001 and rule id 00001.
44 if [ "X${UNAME}" = "XFreeBSD" ]; then
45    ls ${IPFW} >> /dev/null 2>&1
46    if [ $? != 0 ]; then
47        exit 0;
48    fi
49
50    # Check if our table is set
51    ${IPFW} show | grep "^00001" | grep "table(1)" >/dev/null 2>&1
52    if [ ! $? = 0 ]; then
53         # We need to add the table
54         ${IPFW} -q 00001 add deny ip from table\(${TABLE_ID}\) to any
55         ${IPFW} -q 00001 add deny ip from any to table\(${TABLE_ID}\)
56    fi    
57    
58    
59    # Executing and exiting
60    ${IPFW} -q table ${TABLE_ID} ${ACTION} ${IP}
61
62    exit 0;
63 fi
64
65
66 # Not FreeBSD
67 exit 1;