-
Notifications
You must be signed in to change notification settings - Fork 3
/
A:apache2.sh
206 lines (185 loc) · 6.16 KB
/
A:apache2.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
echo
echo -e "\e[1;95m-------------------------[apache2 audit in progress]-------------------------"
installed=$(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed")
if [ $installed -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking apache2 installation\t\t\t\t\t\t\t$status"
if [ ! -f /etc/apache2/apache2.conf ];
then
status="\e[91m[ BAD ]"
echo -e "\e[39m[*] Checking if /etc/apache2/apache2.conf exists\t\t\t\t\t$status\e[39m"
else
signature=$(grep -cP '^ServerSignature\s+Off$' /etc/apache2/apache2.conf)
if [ $signature -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if apache2 version is hidden\t\t\t\t\t\t$status"
token=$(grep -cP '^ServerTokens\s+Prod$' /etc/apache2/apache2.conf)
if [ $token -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if ServerTokens has been set\t\t\t\t\t\t$status"
token=$(grep -cP '^FileETag\sNone$' /etc/apache2/apache2.conf)
if [ $token -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if ETags is disabled\t\t\t\t\t\t\t$status"
cipher=$(grep -cP "^Timeout 60$" /etc/apache2/apache2.conf)
if [ $cipher -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if DoS attacks Protection is enabled\t\t\t\t\t$status"
fi
indexmod=$(apache2ctl -M 2>/dev/null|grep -c autoindex)
if [ $indexmod -eq 1 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if autoindex module is disabled\t\t\t\t\t\t$status"
indexmod=$(cat /var/www/html/index.html|wc -w)
if [ $indexmod -ne 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if index.html is empty\t\t\t\t\t\t\t$status"
if [ ! -f /etc/apache2/apache2.conf ];
then
status="\e[91m[ BAD ]"
echo -e "\e[39m[*] Checking if /etc/apache2/conf-available/security.conf exists\t\t\t$status\e[39m"
else
rdir=$(grep -cPzo '<Directory\s+/>\nOptions\s+-Indexes\nAllowOverride\s+None\nOrder\s+Deny,Allow\nDeny\s+from\s+all\n</Directory>' /etc/apache2/conf-available/security.conf)
if [ $rdir -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if root directory is secured\t\t\t\t\t\t$status"
rdir=$(grep -cPzo '<Directory\s+/var/www/html>\nOptions\s+-Indexes\s+-Includes\nAllowOverride\s+None\nOrder\s+Allow,Deny\nAllow\s+from\s+All\n</Directory>\n' /etc/apache2/conf-available/security.conf)
if [ $rdir -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if html directory is secured\t\t\t\t\t\t$status"
cipher=$(grep -cP "^Header\sedit\sSet-Cookie\s\^\(\.\*\)\$\s\$1;HttpOnly;Secure$" /etc/apache2/conf-available/security.conf)
if [ $cipher -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if HttpOnly and Secure flags are enabled\t\t\t\t\t$status"
cipher=$(grep -cP '^Header\salways\sappend\sX-Frame-Options\sSAMEORIGIN$' /etc/apache2/conf-available/security.conf)
if [ $cipher -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if Clickjacking Attack Protection is enabled\t\t\t\t$status"
cipher=$(grep -cP '^Header\sset\sX-XSS-Protection\s"1;\smode=block"$' /etc/apache2/conf-available/security.conf)
if [ $cipher -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if XSS Protection is enabled\t\t\t\t\t\t$status"
cipher=$(grep -cP '^Header\salways\sset\sStrict-Transport-Security\s"max-age=31536000;\sincludeSubDomains"$' /etc/apache2/conf-available/security.conf)
if [ $cipher -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if Enforce secure connections is enabled\t\t\t\t\t$status"
cipher=$(grep -cP '^Header\sset\sX-Content-Type-Options:\s"nosniff"$' /etc/apache2/conf-available/security.conf)
if [ $cipher -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if MIME sniffing Protection is enabled\t\t\t\t\t$status"
cipher=$(grep -cP "^Header\sset\sContent-Security-Policy\s\"default-src\s'self';\"$" /etc/apache2/conf-available/security.conf)
if [ $cipher -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if Cross-site scripting and injections Protection is enabled\t\t$status"
fi
if [ ! -f /etc/apache2/mods-available/ssl.conf ];
then
status="\e[91m[ BAD ]"
echo -e "\e[39m[*] Checking if /etc/apache2/mods-available/ssl.conf exists\t\t\t\t$status\e[39m"
else
tls=$(grep -cP '^\s+SSLProtocol\s+\–ALL\s+\+TLSv1\s+\+TLSv1\.1\s+\+TLSv1\.2$' /etc/apache2/mods-available/ssl.conf)
if [ $tls -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if only TLS SSL Protocol is enabled\t\t\t\t\t$status"
cipher=$(grep -cP '^\s+SSLCipherSuite\s+HIGH\:\!MEDIUM\:\!aNULL\:\!MD5\:\!RC4$' /etc/apache2/mods-available/ssl.conf)
if [ $cipher -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if strong SSL Cipher Suites are enabled\t\t\t\t\t$status"
fi
indexmod=$(apache2ctl -M 2>/dev/null|grep -c headers)
if [ $indexmod -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if headers module is enabled\t\t\t\t\t\t$status"
echo -e "\033[0m"
echo [SUCCESS] apache2 audit ran by $USER on $(date -u) | tee -a /bin/lib/sh/MK3S/data/MK3S.log