new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / debian / ossec-hids / var / ossec / active-response / bin / route-null.sh
1 #!/bin/sh
2 # Adds an IP to null route
3 # Requirements: ip route
4 # Expect: srcip
5 # Author: Ivan Lotina
6 # Modifyed script host-deny from Daniel B. Cid
7 # Last modified: Feb 16, 2007
8
9 ACTION=$1
10 USER=$2
11 IP=$3
12
13 LOCAL=`dirname $0`;
14 cd $LOCAL
15 cd ../
16 PWD=`pwd`
17 LOCK="${PWD}/host-deny-lock"
18 LOCK_PID="${PWD}/host-deny-lock/pid"
19
20 UNAME=`uname`
21
22 # Logging the call
23 echo "`date` $0 $1 $2 $3 $4 $5" >> ${PWD}/../logs/active-responses.log
24
25
26 # IP Address must be provided
27 if [ "x${IP}" = "x" ]; then
28    echo "$0: Missing argument <action> <user> (ip)" 
29    exit 1;
30 fi
31
32 # Match the loopback address to the version of the provided IP address
33 LOOPBACK=127.0.0.1
34 echo "${IP}" | grep "\:" > /dev/null 2>&1
35 if [ $? = 0 ]; then
36    LOOPBACK=::1
37 fi
38
39 # Adding the ip to null route
40 if [ "x${ACTION}" = "xadd" ]; then
41   if [ "X${UNAME}" = "XLinux" ]; then
42    route add ${IP} reject
43    exit 0;
44   fi
45
46   if [ "X${UNAME}" = "XFreeBSD" ]; then
47    route -q add ${IP} $LOOPBACK -blackhole
48    exit 0;
49   fi
50
51 # Deleting from null route
52 # be carefull not to remove your default route
53 elif [ "x${ACTION}" = "xdelete" ]; then   
54   if [ "X${UNAME}" = "XLinux" ]; then
55    route del ${IP} reject
56    exit 0;
57   fi
58
59   if [ "X${UNAME}" = "XFreeBSD" ]; then
60    route -q delete ${IP} $LOOPBACK -blackhole
61    exit 0;
62   fi
63
64 # Invalid action   
65 else
66    echo "$0: invalid action: ${ACTION}"
67 fi       
68
69 exit 1;