-
Notifications
You must be signed in to change notification settings - Fork 9
/
check_apache_loaded_modules.sh
77 lines (72 loc) · 1.84 KB
/
check_apache_loaded_modules.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
#
# This script checks to see if Apache is running with modules not installed from a package.
# This might indicate a break-in.
#
# REQUIREMENTS
# This script requires apache and some common tools and is meant to be run on *nix-systems.
#
# COPYRIGHT
# Copyright 2013 - Kumina B.V./Tim Stoop ([email protected]), this script is licensed under the
# GNU GPL version 3 or higher.
#
if [ `/usr/bin/whoami` != 'root' ]; then
echo "You must be root to use this program..."
exit 3
fi
WARN_AT=0
CRIT_AT=0
while getopts w:c: name
do
case $name in
w)
WARN_AT="$OPTARG"
;;
c)
CRIT_AT="$OPTARG"
;;
*)
echo "usage: $0 [-w num_warning] [-c num_critical]\n" >&2
exit 1
esac
done
shift $(($OPTIND - 1))
STATE=4
CRIT_MODULES=''
WARN_MODULES=''
CRIT_NUM=0
WARN_NUM=0
LOADED_SHARED_MODULES=`/usr/sbin/apache2ctl -M 2>/dev/null | /usr/bin/awk '/\(shared\)/ { print $1 }'`
for module in $LOADED_SHARED_MODULES; do
if [ $STATE -eq 4 ]; then STATE=0; fi
ON_DISK=`/bin/grep $module /etc/apache2/mods-enabled/*.load | /usr/bin/awk '{ print $NF }'`
# Check whether we got a response
if [ "$ON_DISK" != "" ]; then
IN_PACKAGE=`/usr/bin/dpkg -S $ON_DISK`
if [ "$IN_PACKAGE" != "" ]; then
# All is fine
continue
else
CRIT_NUM=$(($CRIT_NUM+1))
if [ $STATE -lt 2 ] && [ $CRIT_NUM -gt $CRIT_AT ]; then STATE=2; fi
CRIT_MODULES="$CRIT_MODULES$ON_DISK;"
fi
else
WARN_NUM=$(($WARN_NUM+1))
if [ $STATE -lt 1 ] && [ $WARN_NUM -gt $WARN_AT ]; then STATE=1; fi
WARN_MODULES="$WARN_MODULES$module"
fi
done
if [ $STATE -eq 0 ]; then
echo 'APACHE OK, no unknown modules found'
exit 0
elif [ $STATE -eq 1 ]; then
echo "APACHE WARNING, following modules not found in config: $WARN_MODULES"
exit 1
elif [ $STATE -eq 2 ]; then
echo "APACHE CRITICAL, foreign module found: $CRIT_MODULES"
exit 2
else
echo "APACHE UNKNOWN, something went wrong"
exit 3
fi