Subversion Repositories ALCASAR

Rev

Rev 2837 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2837 Rev 2864
1
#!/bin/sh
1
#!/bin/sh
2
# $Id: fail2ban.sh 2837 2020-06-16 22:24:15Z rexy $
2
# $Id: fail2ban.sh 2864 2020-10-18 09:06:17Z rexy $
3
 
3
 
4
JAIL_CONF="/etc/fail2ban/jail.conf"
4
JAIL_CONF="/etc/fail2ban/jail.conf"
5
DIR_FILTER="/etc/fail2ban/filter.d/"
5
DIR_FILTER="/etc/fail2ban/filter.d/"
6
ACTION_ALLPORTS="/etc/fail2ban/action.d/iptables-allports.conf"
-
 
7
 
6
 
8
#########################################################
7
#########################################################
9
## Mise à jour de la configuration de jail de fail2ban ##
8
## Mise à jour de la configuration de jail de fail2ban ##
10
#########################################################
9
#########################################################
11
[ -f $JAIL_CONF ] && [ ! -e $JAIL_CONF.default ] && mv $JAIL_CONF $JAIL_CONF.default
10
[ -f $JAIL_CONF ] && [ ! -e $JAIL_CONF.default ] && mv $JAIL_CONF $JAIL_CONF.default
12
cat << EOF > $JAIL_CONF
11
cat << EOF > $JAIL_CONF
13
 
12
 
14
# Fail2Ban configuration file
13
# Fail2Ban configuration file
15
#
14
#
16
# Author: Cyril Jaquier
15
# Author: Cyril Jaquier
17
# Adapted by ALCASAR team
16
# Adapted by ALCASAR team
18
 
17
 
19
 
18
 
20
# The DEFAULT allows a global definition of the options. They can be overridden
19
# The DEFAULT allows a global definition of the options. They can be overridden
21
# in each jail afterwards.
20
# in each jail afterwards.
22
 
21
 
23
[DEFAULT]
22
[DEFAULT]
24
 
23
 
25
# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
24
# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
26
# ban a host which matches an address in this list. Several addresses can be
25
# ban a host which matches an address in this list. Several addresses can be
27
# defined using space separator.
26
# defined using space separator.
28
ignoreip = 127.0.0.1/8
27
ignoreip = 127.0.0.1/8
29
 
28
 
30
# "bantime" is the number of seconds that a host is banned.
29
# "bantime" is the number of seconds that a host is banned.
31
bantime  = 180
30
bantime  = 180
32
 
31
 
33
# A host is banned if it has generated "maxretry" during the last "findtime" seconds.
32
# A host is banned if it has generated "maxretry" during the last "findtime" seconds.
34
# Un client est banni s'il génere "maxretry" requêtes pendant "findtime" (en secondes)
33
# Un client est banni s'il génere "maxretry" requêtes pendant "findtime" (en secondes)
35
# Pour ALCASAR : 5 requetes pour chaque filtres en 60 secondes
34
# Pour ALCASAR : 5 requetes pour chaque filtres en 60 secondes
36
findtime  = 60
35
findtime  = 60
37
 
36
 
38
# "maxretry" is the number of failures before a host get banned.
37
# "maxretry" is the number of failures before a host get banned.
39
maxretry = 5
38
maxretry = 5
40
 
39
 
41
# "backend" specifies the backend used to get files modification. Available
40
# "backend" specifies the backend used to get files modification. Available
42
# options are "gamin", "polling" and "auto". This option can be overridden in
41
# options are "gamin", "polling" and "auto". This option can be overridden in
43
# each jail too (use "gamin" for a jail and "polling" for another).
42
# each jail too (use "gamin" for a jail and "polling" for another).
44
#
43
#
45
# gamin:   requires Gamin (a file alteration monitor) to be installed. If Gamin
44
# gamin:   requires Gamin (a file alteration monitor) to be installed. If Gamin
46
#          is not installed, Fail2ban will use polling.
45
#          is not installed, Fail2ban will use polling.
47
# polling: uses a polling algorithm which does not require external libraries.
46
# polling: uses a polling algorithm which does not require external libraries.
48
# auto:    will choose Gamin if available and polling otherwise.
47
# auto:    will choose Gamin if available and polling otherwise.
49
backend = auto
48
backend = auto
50
 
49
 
51
# "usedns" specifies if jails should trust hostnames in logs,
50
# "usedns" specifies if jails should trust hostnames in logs,
52
# warn when DNS lookups are performed, or ignore all hostnames in logs
51
# warn when DNS lookups are performed, or ignore all hostnames in logs
53
#
52
#
54
# yes: if a hostname is encountered, a DNS lookup will be performed.
53
# yes: if a hostname is encountered, a DNS lookup will be performed.
55
# warn: if a hostname is encountered, a DNS lookup will be performed,
54
# warn: if a hostname is encountered, a DNS lookup will be performed,
56
# but it will be logged as a warning.
55
# but it will be logged as a warning.
57
# no: if a hostname is encountered, will not be used for banning,
56
# no: if a hostname is encountered, will not be used for banning,
58
# but it will be logged as info.
57
# but it will be logged as info.
59
usedns = warn
58
usedns = warn
60
 
59
 
61
# Bannissement sur tous les ports après 3 refus du serveur WEB (tentative d'accès sur des pages inexistentes)
60
# Bannissement sur tous les ports après 3 refus du serveur WEB (tentative d'accès sur des pages inexistentes)
62
[alcasar_mod-evasive]
61
[alcasar_mod-evasive]
63
 
-
 
64
#enabled = true
62
#enabled = true
65
enabled = false
63
enabled = false
66
backend = auto
64
backend = auto
67
filter = alcasar_mod-evasive
65
filter = alcasar_mod-evasive
68
action = iptables-allports[name=alcasar_mod-evasive]
66
action = iptables-allports[name=alcasar_mod-evasive]
69
logpath = /var/log/lighttpd/access.log
67
logpath = /var/log/lighttpd/access.log
70
maxretry = 3
68
maxretry = 3
71
 
69
 
72
# Bannissement sur tout les ports après 3 refus de SSH (tentative d'accès par brute-force)
70
# Bannissement sur tout les ports après 3 refus de SSH (tentative d'accès par brute-force)
73
[ssh-iptables]
71
[ssh-iptables]
74
 
-
 
75
enabled = true
72
enabled = true
76
#enabled  = false
73
#enabled  = false
77
filter   = sshd
74
filter   = sshd
78
action   = iptables-allports[name=SSH]
75
action   = iptables-allports[name=SSH]
79
logpath  = /var/log/auth.log
76
logpath  = /var/log/auth.log
80
maxretry = 3
77
maxretry = 3
81
 
78
 
82
# Bannissement sur tous les ports après 5 échecs de connexion sur le centre de contrôle (ACC)
79
# Bannissement sur tous les ports après 5 échecs de connexion sur le centre de contrôle (ACC)
83
[alcasar_acc]
80
[alcasar_acc]
84
 
-
 
85
enabled = true
81
enabled = true
86
#enabled = false
82
#enabled = false
87
backend = auto
83
backend = auto
88
filter = alcasar_acc
84
filter = alcasar_acc
89
action = iptables-allports[name=alcasar_acc]
85
action = iptables-allports[name=alcasar_acc]
90
logpath = /var/log/lighttpd/access.log
86
logpath = /var/log/lighttpd/access.log
91
maxretry = 6
87
maxretry = 5
92
 
88
 
93
# Bannissement sur tout les ports après 5 echecs de connexion pour un usager
89
# Bannissement sur tout les ports après 5 echecs de connexion pour un usager
94
[alcasar_intercept]
90
[alcasar_intercept]
95
 
-
 
96
enabled = true
91
enabled = true
97
#enabled = false
92
#enabled = false
98
backend = auto
93
backend = auto
99
filter = alcasar_intercept
94
filter = alcasar_intercept
100
action = iptables-allports[name=alcasar_intercept]
95
action = iptables-allports[name=alcasar_intercept]
101
logpath = /var/log/lighttpd/access.log
96
logpath = /var/log/lighttpd/access.log
102
maxretry = 6
97
maxretry = 5
103
 
98
 
104
# Bannissement sur tout les port après 5 échecs de changement de mot de passe
99
# Bannissement sur tout les port après 5 échecs de changement de mot de passe
105
# 5 POST pour changer le mot de passe que le POST soit ok ou non.
100
# 5 POST pour changer le mot de passe que le POST soit ok ou non.
106
[alcasar_change-pwd]
101
[alcasar_change-pwd]
107
 
-
 
108
enabled = true
102
enabled = true
109
#enabled = false
103
#enabled = false
110
backend = auto
104
backend = auto
111
filter = alcasar_change-pwd
105
filter = alcasar_change-pwd
112
action = iptables-allports[name=alcasar_change-pwd]
106
action = iptables-allports[name=alcasar_change-pwd]
113
logpath = /var/log/lighttpd/access.log
107
logpath = /var/log/lighttpd/access.log
114
maxretry = 5
108
maxretry = 5
115
 
109
 
116
EOF
110
EOF
117
 
111
 
118
##################################################
112
##############################################
119
## Mise en place des filtres spécifiques	##
113
## Mise en place des filtres spécifiques	##
120
## - Mod_evasive.conf				##
114
## - Mod_evasive.conf						##
121
## - acc-htdigest.conf				##
115
## - acc-htdigest.conf						##
122
## - intercept.conf				##
116
## - intercept.conf							##
123
## - change-pwd.conf				##
117
## - change-pwd.conf						##
124
##################################################
118
##############################################
125
 
119
 
126
######################
120
######################
127
## MOD-EVASIVE.CONF ##
121
## MOD-EVASIVE.CONF ##
128
######################
122
######################
129
cat << EOF > $DIR_FILTER/alcasar_mod-evasive.conf
123
cat << EOF > $DIR_FILTER/alcasar_mod-evasive.conf
130
# Fail2Ban configuration file
124
# Fail2Ban configuration file
131
#
125
#
132
# Author: Cyril Jaquier
126
# Author: Cyril Jaquier
133
# Adapted by ALCASAR team
127
# Adapted by ALCASAR team
134
 
128
 
135
[Definition]
129
[Definition]
136
 
130
 
137
# Option:  failregex
131
# Option:  failregex
138
# Notes.:  regex to match the password failure messages in the logfile. The
132
# Notes.:  regex to match the password failure messages in the logfile. The
139
#          host must be matched by a group named "host". The tag "<HOST>" can
133
#          host must be matched by a group named "host". The tag "<HOST>" can
140
#          be used for standard IP/hostname matching and is only an alias for
134
#          be used for standard IP/hostname matching and is only an alias for
141
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
135
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
142
# Values:  TEXT
136
# Values:  TEXT
143
#
137
#
144
failregex =  <HOST> .+\] "[^"]+" 403
138
failregex =  <HOST> .+\] "[^"]+" 403
145
 
139
 
146
# Option:  ignoreregex
140
# Option:  ignoreregex
147
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
141
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
148
# Values:  TEXT
142
# Values:  TEXT
149
#
143
#
150
ignoreregex = 
144
ignoreregex = 
151
EOF
145
EOF
152
 
146
 
153
#######################
147
#######################
154
## ACC-HTDIGEST.CONF ##
148
## ACC-HTDIGEST.CONF ##
155
#######################
149
#######################
156
cat << EOF > $DIR_FILTER/alcasar_acc.conf
150
cat << EOF > $DIR_FILTER/alcasar_acc.conf
157
# Fail2Ban configuration file
151
# Fail2Ban configuration file
158
#
152
#
159
# Author: Cyril Jaquier
153
# Author: Cyril Jaquier
160
# Adapted by ALCASAR team
154
# Adapted by ALCASAR team
161
 
155
 
162
[Definition]
156
[Definition]
163
 
157
 
164
# Option:  failregex
158
# Option:  failregex
165
# Notes.:  regex to match the password failure messages in the logfile. The
159
# Notes.:  regex to match the password failure messages in the logfile. The
166
#          host must be matched by a group named "host". The tag "<HOST>" can
160
#          host must be matched by a group named "host". The tag "<HOST>" can
167
#          be used for standard IP/hostname matching and is only an alias for
161
#          be used for standard IP/hostname matching and is only an alias for
168
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
162
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
169
# Values:  TEXT
163
# Values:  TEXT
170
#
164
#
171
failregex =  <HOST> .+\] "[^"]+" 401
165
failregex =  <HOST> .+\] "[^"]+" 401
172
 
166
 
173
#[[]auth_digest:error[]] [[]client <HOST>:[0-9]\{1,5\}[]]
167
#[[]auth_digest:error[]] [[]client <HOST>:[0-9]\{1,5\}[]]
174
 
168
 
175
# Option:  ignoreregex
169
# Option:  ignoreregex
176
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
170
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
177
# Values:  TEXT
171
# Values:  TEXT
178
#
172
#
179
ignoreregex = 
173
ignoreregex = 
180
EOF
174
EOF
181
 
175
 
182
####################
176
####################
183
## INTERCEPT.CONF ##
177
## INTERCEPT.CONF ##
184
####################
178
####################
185
cat << EOF > $DIR_FILTER/alcasar_intercept.conf
179
cat << EOF > $DIR_FILTER/alcasar_intercept.conf
186
# Fail2Ban configuration file
180
# Fail2Ban configuration file
187
#
181
#
188
# Author: Cyril Jaquier
182
# Author: Cyril Jaquier
189
# Adapted by ALCASAR team
183
# Adapted by ALCASAR team
190
 
184
 
191
[Definition]
185
[Definition]
192
 
186
 
193
# Option:  failregex
187
# Option:  failregex
194
# Notes.:  regex to match the password failure messages in the logfile. The
188
# Notes.:  regex to match the password failure messages in the logfile. The
195
#          host must be matched by a group named "host". The tag "<HOST>" can
189
#          host must be matched by a group named "host". The tag "<HOST>" can
196
#          be used for standard IP/hostname matching and is only an alias for
190
#          be used for standard IP/hostname matching and is only an alias for
197
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
191
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
198
# Values:  TEXT
192
# Values:  TEXT
199
#
193
#
200
failregex = <HOST> .* \"GET \/intercept\.php\?res=failed\&reason=reject
194
failregex = <HOST> .* \"GET \/intercept\.php\?res=failed\&reason=reject
201
 
195
 
202
# Option:  ignoreregex
196
# Option:  ignoreregex
203
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
197
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
204
# Values:  TEXT
198
# Values:  TEXT
205
#
199
#
206
ignoreregex = 
200
ignoreregex = 
207
EOF
201
EOF
208
 
202
 
209
#####################
203
#####################
210
## CHANGE-PWD.CONF ##
204
## CHANGE-PWD.CONF ##
211
#####################
205
#####################
212
cat << EOF > $DIR_FILTER/alcasar_change-pwd.conf
206
cat << EOF > $DIR_FILTER/alcasar_change-pwd.conf
213
 
207
 
214
# Fail2Ban configuration file
208
# Fail2Ban configuration file
215
#
209
#
216
# Author: Cyril Jaquier
210
# Author: Cyril Jaquier
217
# Adapted by ALCASAR team
211
# Adapted by ALCASAR team
218
 
212
 
219
[Definition]
213
[Definition]
220
 
214
 
221
# Option:  failregex
215
# Option:  failregex
222
# Notes.:  regex to match the password failure messages in the logfile. The
216
# Notes.:  regex to match the password failure messages in the logfile. The
223
#          host must be matched by a group named "host". The tag "<HOST>" can
217
#          host must be matched by a group named "host". The tag "<HOST>" can
224
#          be used for standard IP/hostname matching and is only an alias for
218
#          be used for standard IP/hostname matching and is only an alias for
225
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
219
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
226
# Values:  TEXT
220
# Values:  TEXT
227
#
221
#
228
failregex = <HOST> .* \"POST \/password\.php
222
failregex = <HOST> .* \"POST \/password\.php
229
 
223
 
230
 
224
 
231
# Option:  ignoreregex
225
# Option:  ignoreregex
232
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
226
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
233
# Values:  TEXT
227
# Values:  TEXT
234
#
228
#
235
ignoreregex = 
229
ignoreregex = 
236
EOF
230
EOF
237
 
-
 
238
##############################################
-
 
239
##   Log sur ULOG quand iptables-allports   ##
-
 
240
##############################################
-
 
241
[ -f $ACTION_ALLPORTS ] && [ ! -e $ACTION_ALLPORTS.default ] && mv $ACTION_ALLPORTS $ACTION_ALLPORTS.default
-
 
242
cat << EOF > $ACTION_ALLPORTS
-
 
243
# Fail2Ban configuration file
-
 
244
#
-
 
245
# Author: Cyril Jaquier
-
 
246
# Modified: Yaroslav O. Halchenko <debian@onerussian.com>
-
 
247
# 			made active on all ports from original iptables.conf
-
 
248
# Adapted by ALCASAR team
-
 
249
 
-
 
250
[Definition]
-
 
251
 
-
 
252
# Option:  actionstart
-
 
253
# Notes.:  command executed once at the start of Fail2Ban.
-
 
254
# Values:  CMD
-
 
255
#
-
 
256
actionstart = iptables -N fail2ban-<name>
-
 
257
              iptables -A fail2ban-<name> -j RETURN
-
 
258
              iptables -I <chain> -p <protocol> -j fail2ban-<name>
-
 
259
 
-
 
260
# Option:  actionstop
-
 
261
# Notes.:  command executed once at the end of Fail2Ban
-
 
262
# Values:  CMD
-
 
263
#
-
 
264
actionstop = iptables -D <chain> -p <protocol> -j fail2ban-<name>
-
 
265
             iptables -F fail2ban-<name>
-
 
266
             iptables -X fail2ban-<name>
-
 
267
 
-
 
268
# Option:  actioncheck
-
 
269
# Notes.:  command executed once before each actionban command
-
 
270
# Values:  CMD
-
 
271
#
-
 
272
actioncheck = iptables -n -L <chain> | grep -q fail2ban-<name>
-
 
273
 
-
 
274
# Option:  actionban
-
 
275
# Notes.:  command executed when banning an IP. Take care that the
-
 
276
#          command is executed with Fail2Ban user rights.
-
 
277
# Tags:    <ip>  IP address
-
 
278
#          <failures>  number of failures
-
 
279
#          <time>  unix timestamp of the ban time
-
 
280
# Values:  CMD
-
 
281
 
-
 
282
actionban = iptables -I fail2ban-<name> 1 -s <ip> -j DROP
-
 
283
 
-
 
284
# Option:  actionunban
-
 
285
# Notes.:  command executed when unbanning an IP. Take care that the
-
 
286
#          command is executed with Fail2Ban user rights.
-
 
287
# Tags:    <ip>  IP address
-
 
288
#          <failures>  number of failures
-
 
289
#          <time>  unix timestamp of the ban time
-
 
290
# Values:  CMD
-
 
291
#
-
 
292
actionunban = iptables -D fail2ban-<name> -s <ip> -j DROP
-
 
293
 
-
 
294
[Init]
-
 
295
 
-
 
296
# Defaut name of the chain
-
 
297
#
-
 
298
name = default
-
 
299
 
-
 
300
# Option:  protocol
-
 
301
# Notes.:  internally used by config reader for interpolations.
-
 
302
# Values:  [ tcp | udp | icmp | all ] Default: tcp
-
 
303
#
-
 
304
protocol = tcp
-
 
305
 
-
 
306
# Option:  chain
-
 
307
# Notes    specifies the iptables chain to which the fail2ban rules should be
-
 
308
#          added
-
 
309
# Values:  STRING  Default: INPUT
-
 
310
chain = INPUT
-
 
311
 
-
 
312
EOF
-
 
313
 
231