new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / debian / ossec-hids / var / ossec / active-response / bin / ipfw_mac.sh
1 #!/bin/sh
2 # Adds an IP to the IPFW drop list.
3 # Only works with IPFW.
4 # Expect: srcip
5 # Author: Rafael Capovilla - under @ ( at ) underlinux.com.br
6 # Author: Daniel B. Cid - dcid @ ( at ) ossec.net
7 # Author: Charles W. Kefauver ckefauver @ ( at ) ibacom.es
8 #         changed for Mac OS X compatibility
9 # Last modified: August 14, 2006
10
11 UNAME=`uname`
12 IPFW="/sbin/ipfw"
13 ARG1=""
14 ARG2=""
15 ACTION=$1
16 USER=$2
17 IP=$3
18
19 # warning do NOT add leading 0 in SET_ID
20 SET_ID=2
21
22 LOCAL=`dirname $0`;
23 cd $LOCAL
24 cd ../
25 PWD=`pwd`
26 echo "`date` $0 $1 $2 $3 $4 $5" >> ${PWD}/../logs/active-responses.log
27
28
29 # Checking for an IP
30 if [ "x${IP}" = "x" ]; then
31    echo "$0: <action> <username> <ip>" 
32    exit 1;
33 fi
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 Darwin
43 if [ "X${UNAME}" = "XDarwin" ]; then
44    ls ${IPFW} >> /dev/null 2>&1
45    if [ $? != 0 ]; then
46        exit 0;
47    fi
48
49    
50    # Executing and exiting
51         if [ "x${ACTION}" = "xadd" ]; then
52            #${IPFW} set disable ${SET_ID}
53            ${IPFW} -q add set ${SET_ID} deny ip from ${IP} to any
54            ${IPFW} -q add set ${SET_ID} deny ip from any to ${IP}
55            ${IPFW} -q set enable ${SET_ID}
56            exit 0;
57         fi
58
59         if [ "x${ACTION}" = "xdelete" ]; then
60                 #${IPFW} -S show | grep "set ${SET_ID}" | grep "${IP}"  >/dev/null 2>&1
61                 #get list of ipfw rules ID to delete
62                 RULES_TO_DELETE=`${IPFW} -S show | grep "set ${SET_ID}" | grep "${IP}" | awk '{print $1}'`
63                 
64                 for RULE_ID in ${RULES_TO_DELETE}
65                 do
66                         ${IPFW} -q delete ${RULE_ID}
67                 done
68                 
69                 exit 0;
70         fi
71
72    exit 0;
73 fi
74
75
76 # Not Darwin
77 exit 1;
78