Subversion Repositories ALCASAR

Rev

Rev 2864 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2864 Rev 2865
1
#!/bin/sh
1
#!/bin/sh
2
# $Id: fail2ban.sh 2864 2020-10-18 09:06:17Z rexy $
2
# $Id: fail2ban.sh 2865 2020-10-18 22:21:46Z 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
 
6
 
7
#########################################################
7
#########################################################
8
## Mise à jour de la configuration de jail de fail2ban ##
8
## Mise à jour de la configuration de jail de fail2ban ##
9
#########################################################
9
#########################################################
10
[ -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
11
cat << EOF > $JAIL_CONF
11
cat << EOF > $JAIL_CONF
12
 
12
 
13
# Fail2Ban configuration file
13
# Fail2Ban configuration file
14
#
14
#
15
# Author: Cyril Jaquier
15
# Author: Cyril Jaquier
16
# Adapted by ALCASAR team
16
# Adapted by ALCASAR team
17
 
17
 
18
 
18
 
19
# 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
20
# in each jail afterwards.
20
# in each jail afterwards.
21
 
-
 
22
[DEFAULT]
21
[DEFAULT]
23
 
-
 
24
# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
22
# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
25
# ban a host which matches an address in this list. Several addresses can be
23
# ban a host which matches an address in this list. Several addresses can be
26
# defined using space separator.
24
# defined using space separator.
27
ignoreip = 127.0.0.1/8
25
ignoreip = 127.0.0.1/8
28
 
-
 
29
# "bantime" is the number of seconds that a host is banned.
26
# "bantime" is the number of seconds that a host is banned.
30
bantime  = 180
27
bantime  = 180
31
 
28
 
32
# A host is banned if it has generated "maxretry" during the last "findtime" seconds.
29
# A host is banned if it has generated "maxretry" during the last "findtime" seconds.
33
# Un client est banni s'il génere "maxretry" requêtes pendant "findtime" (en secondes)
30
# Un client est banni s'il génere "maxretry" requêtes pendant "findtime" (en secondes)
34
# Pour ALCASAR : 5 requetes pour chaque filtres en 60 secondes
31
# Pour ALCASAR : 5 requetes pour chaque filtres en 60 secondes
35
findtime  = 60
32
findtime  = 60
36
 
33
 
37
# "maxretry" is the number of failures before a host get banned.
34
# "maxretry" is the number of failures before a host get banned.
38
maxretry = 5
35
maxretry = 5
39
 
36
 
40
# "backend" specifies the backend used to get files modification. Available
37
# "backend" specifies the backend used to get files modification. Available
41
# options are "gamin", "polling" and "auto". This option can be overridden in
38
# options are "gamin", "polling" and "auto". This option can be overridden in
42
# each jail too (use "gamin" for a jail and "polling" for another).
39
# each jail too (use "gamin" for a jail and "polling" for another).
43
#
40
#
44
# gamin:   requires Gamin (a file alteration monitor) to be installed. If Gamin
41
# gamin:   requires Gamin (a file alteration monitor) to be installed. If Gamin
45
#          is not installed, Fail2ban will use polling.
42
#          is not installed, Fail2ban will use polling.
46
# polling: uses a polling algorithm which does not require external libraries.
43
# polling: uses a polling algorithm which does not require external libraries.
47
# auto:    will choose Gamin if available and polling otherwise.
44
# auto:    will choose Gamin if available and polling otherwise.
48
backend = auto
45
backend = auto
49
 
46
 
50
# "usedns" specifies if jails should trust hostnames in logs,
47
# "usedns" specifies if jails should trust hostnames in logs,
51
# warn when DNS lookups are performed, or ignore all hostnames in logs
48
# warn when DNS lookups are performed, or ignore all hostnames in logs
52
#
49
#
53
# yes: if a hostname is encountered, a DNS lookup will be performed.
50
# yes: if a hostname is encountered, a DNS lookup will be performed.
54
# warn: if a hostname is encountered, a DNS lookup will be performed,
51
# warn: if a hostname is encountered, a DNS lookup will be performed,
55
# but it will be logged as a warning.
52
# but it will be logged as a warning.
56
# no: if a hostname is encountered, will not be used for banning,
53
# no: if a hostname is encountered, will not be used for banning,
57
# but it will be logged as info.
54
# but it will be logged as info.
58
usedns = warn
55
usedns = warn
59
 
56
 
60
# Bannissement sur tous les ports après 3 refus du serveur WEB (tentative d'accès sur des pages inexistentes)
57
# Bannissement sur tous les ports après 3 refus du serveur WEB (tentative d'accès sur des pages inexistentes)
61
[alcasar_mod-evasive]
58
[alcasar_mod-evasive]
62
#enabled = true
59
#enabled = true
63
enabled = false
60
enabled = false
64
backend = auto
61
backend = auto
65
filter = alcasar_mod-evasive
62
filter = alcasar_mod-evasive
66
action = iptables-allports[name=alcasar_mod-evasive]
63
action = iptables-allports[name=alcasar_mod-evasive]
67
logpath = /var/log/lighttpd/access.log
64
logpath = /var/log/lighttpd/access.log
68
maxretry = 3
65
maxretry = 3
69
 
66
 
70
# Bannissement sur tout les ports après 3 refus de SSH (tentative d'accès par brute-force)
67
# Bannissement sur tout les ports après 3 refus de SSH (tentative d'accès par brute-force)
71
[ssh-iptables]
68
[ssh-iptables]
72
enabled = true
69
enabled = true
73
#enabled  = false
70
#enabled  = false
74
filter   = sshd
71
filter   = sshd
75
action   = iptables-allports[name=SSH]
72
action   = iptables-allports[name=SSH]
76
logpath  = /var/log/auth.log
73
logpath  = /var/log/auth.log
77
maxretry = 3
74
maxretry = 3
78
 
75
 
79
# Bannissement sur tous les ports après 5 échecs de connexion sur le centre de contrôle (ACC)
76
# Bannissement sur tous les ports après 5 échecs de connexion sur le centre de contrôle (ACC)
80
[alcasar_acc]
77
[alcasar_acc]
81
enabled = true
78
enabled = true
82
#enabled = false
79
#enabled = false
83
backend = auto
80
backend = auto
84
filter = alcasar_acc
81
filter = alcasar_acc
85
action = iptables-allports[name=alcasar_acc]
82
action = iptables-allports[name=alcasar_acc]
86
logpath = /var/log/lighttpd/access.log
83
logpath = /var/log/lighttpd/access.log
87
maxretry = 5
84
maxretry = 5
88
 
85
 
89
# Bannissement sur tout les ports après 5 echecs de connexion pour un usager
86
# Bannissement sur tout les ports après 5 echecs de connexion pour un usager
90
[alcasar_intercept]
87
[alcasar_intercept]
91
enabled = true
88
enabled = true
92
#enabled = false
89
#enabled = false
93
backend = auto
90
backend = auto
94
filter = alcasar_intercept
91
filter = alcasar_intercept
95
action = iptables-allports[name=alcasar_intercept]
92
action = iptables-allports[name=alcasar_intercept]
96
logpath = /var/log/lighttpd/access.log
93
logpath = /var/log/lighttpd/access.log
97
maxretry = 5
94
maxretry = 5
98
 
95
 
99
# Bannissement sur tout les port après 5 échecs de changement de mot de passe
96
# Bannissement sur tout les port après 5 échecs de changement de mot de passe
100
# 5 POST pour changer le mot de passe que le POST soit ok ou non.
97
# 5 POST pour changer le mot de passe que le POST soit ok ou non.
101
[alcasar_change-pwd]
98
[alcasar_change-pwd]
102
enabled = true
99
enabled = true
103
#enabled = false
100
#enabled = false
104
backend = auto
101
backend = auto
105
filter = alcasar_change-pwd
102
filter = alcasar_change-pwd
106
action = iptables-allports[name=alcasar_change-pwd]
103
action = iptables-allports[name=alcasar_change-pwd]
107
logpath = /var/log/lighttpd/access.log
104
logpath = /var/log/lighttpd/access.log
108
maxretry = 5
105
maxretry = 5
109
 
106
 
110
EOF
107
EOF
111
 
108
 
112
##############################################
109
##############################################
113
## Mise en place des filtres spécifiques	##
110
## Mise en place des filtres spécifiques	##
114
## - Mod_evasive.conf						##
111
## - Mod_evasive.conf						##
115
## - acc-htdigest.conf						##
112
## - acc-htdigest.conf						##
116
## - intercept.conf							##
113
## - intercept.conf							##
117
## - change-pwd.conf						##
114
## - change-pwd.conf						##
118
##############################################
115
##############################################
119
 
116
 
120
######################
117
######################
121
## MOD-EVASIVE.CONF ##
118
## MOD-EVASIVE.CONF ##
122
######################
119
######################
123
cat << EOF > $DIR_FILTER/alcasar_mod-evasive.conf
120
cat << EOF > $DIR_FILTER/alcasar_mod-evasive.conf
124
# Fail2Ban configuration file
121
# Fail2Ban configuration file
125
#
122
#
126
# Author: Cyril Jaquier
123
# Author: Cyril Jaquier
127
# Adapted by ALCASAR team
124
# Adapted by ALCASAR team
128
 
125
 
129
[Definition]
126
[Definition]
130
 
-
 
131
# Option:  failregex
127
# Option:  failregex
132
# Notes.:  regex to match the password failure messages in the logfile. The
128
# Notes.:  regex to match the password failure messages in the logfile. The
133
#          host must be matched by a group named "host". The tag "<HOST>" can
129
#          host must be matched by a group named "host". The tag "<HOST>" can
134
#          be used for standard IP/hostname matching and is only an alias for
130
#          be used for standard IP/hostname matching and is only an alias for
135
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
131
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
136
# Values:  TEXT
132
# Values:  TEXT
137
#
-
 
138
failregex =  <HOST> .+\] "[^"]+" 403
133
failregex =  <HOST> .+\] "[^"]+" 403
139
 
-
 
140
# Option:  ignoreregex
134
# Option:  ignoreregex
141
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
135
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
142
# Values:  TEXT
-
 
143
#
-
 
144
ignoreregex = 
136
ignoreregex = 
145
EOF
137
EOF
146
 
138
 
147
#######################
139
#######################
148
## ACC-HTDIGEST.CONF ##
140
## ACC-HTDIGEST.CONF ##
149
#######################
141
#######################
150
cat << EOF > $DIR_FILTER/alcasar_acc.conf
142
cat << EOF > $DIR_FILTER/alcasar_acc.conf
151
# Fail2Ban configuration file
143
# Fail2Ban configuration file
152
#
144
#
153
# Author: Cyril Jaquier
145
# Author: Cyril Jaquier
154
# Adapted by ALCASAR team
146
# Adapted by ALCASAR team
155
 
147
 
156
[Definition]
148
[Definition]
157
 
-
 
158
# Option:  failregex
149
# Option:  failregex
159
# Notes.:  regex to match the password failure messages in the logfile. The
150
# Notes.:  regex to match the password failure messages in the logfile. The
160
#          host must be matched by a group named "host". The tag "<HOST>" can
151
#          host must be matched by a group named "host". The tag "<HOST>" can
161
#          be used for standard IP/hostname matching and is only an alias for
152
#          be used for standard IP/hostname matching and is only an alias for
162
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
153
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
163
# Values:  TEXT
154
# Values:  TEXT
164
#
-
 
165
failregex =  <HOST> .+\] "[^"]+" 401
155
failregex =  <HOST> .+\] "[^"]+" 401
166
 
-
 
167
#[[]auth_digest:error[]] [[]client <HOST>:[0-9]\{1,5\}[]]
-
 
168
 
-
 
169
# Option:  ignoreregex
156
# Option:  ignoreregex
170
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
157
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
171
# Values:  TEXT
-
 
172
#
-
 
173
ignoreregex = 
158
ignoreregex = 
174
EOF
159
EOF
175
 
160
 
176
####################
161
####################
177
## INTERCEPT.CONF ##
162
## INTERCEPT.CONF ##
178
####################
163
####################
179
cat << EOF > $DIR_FILTER/alcasar_intercept.conf
164
cat << EOF > $DIR_FILTER/alcasar_intercept.conf
180
# Fail2Ban configuration file
165
# Fail2Ban configuration file
181
#
166
#
182
# Author: Cyril Jaquier
167
# Author: Cyril Jaquier
183
# Adapted by ALCASAR team
168
# Adapted by ALCASAR team
184
 
169
 
185
[Definition]
170
[Definition]
186
 
-
 
187
# Option:  failregex
171
# Option:  failregex
188
# Notes.:  regex to match the password failure messages in the logfile. The
172
# Notes.:  regex to match the password failure messages in the logfile. The
189
#          host must be matched by a group named "host". The tag "<HOST>" can
173
#          host must be matched by a group named "host". The tag "<HOST>" can
190
#          be used for standard IP/hostname matching and is only an alias for
174
#          be used for standard IP/hostname matching and is only an alias for
191
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
175
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
192
# Values:  TEXT
176
# Values:  TEXT
193
#
-
 
194
failregex = <HOST> .* \"GET \/intercept\.php\?res=failed\&reason=reject
177
failregex = <HOST> .* \"GET \/intercept\.php\?res=failed\&reason=reject
195
 
-
 
196
# Option:  ignoreregex
178
# Option:  ignoreregex
197
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
179
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
198
# Values:  TEXT
-
 
199
#
-
 
200
ignoreregex = 
180
ignoreregex = 
201
EOF
181
EOF
202
 
182
 
203
#####################
183
#####################
204
## CHANGE-PWD.CONF ##
184
## CHANGE-PWD.CONF ##
205
#####################
185
#####################
206
cat << EOF > $DIR_FILTER/alcasar_change-pwd.conf
186
cat << EOF > $DIR_FILTER/alcasar_change-pwd.conf
207
 
187
 
208
# Fail2Ban configuration file
188
# Fail2Ban configuration file
209
#
189
#
210
# Author: Cyril Jaquier
190
# Author: Cyril Jaquier
211
# Adapted by ALCASAR team
191
# Adapted by ALCASAR team
212
 
192
 
213
[Definition]
193
[Definition]
214
 
-
 
215
# Option:  failregex
194
# Option:  failregex
216
# Notes.:  regex to match the password failure messages in the logfile. The
195
# Notes.:  regex to match the password failure messages in the logfile. The
217
#          host must be matched by a group named "host". The tag "<HOST>" can
196
#          host must be matched by a group named "host". The tag "<HOST>" can
218
#          be used for standard IP/hostname matching and is only an alias for
197
#          be used for standard IP/hostname matching and is only an alias for
219
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
198
#          (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
220
# Values:  TEXT
199
# Values:  TEXT
221
#
-
 
222
failregex = <HOST> .* \"POST \/password\.php
200
failregex = <HOST> .* \"POST \/password\.php
223
 
-
 
224
 
-
 
225
# Option:  ignoreregex
201
# Option:  ignoreregex
226
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
202
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
227
# Values:  TEXT
-
 
228
#
-
 
229
ignoreregex = 
203
ignoreregex = 
230
EOF
204
EOF
231
 
205