Skip to content

Commit 2c37aa9

Browse files
committed
1 parent 95e483b commit 2c37aa9

3 files changed

Lines changed: 75 additions & 6 deletions

File tree

lib/Virtualmin/Config/Plugin/Fail2ban.pm

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sub actions {
3131
$log->info("Cannot configure Fail2ban module as Firewall module is not installed");
3232
$self->done(2);
3333
}
34-
print "XXXXXX\n\n";
34+
3535
$self->spin();
3636
eval {
3737
if (has_command('fail2ban-server')) {
@@ -43,6 +43,11 @@ print "XXXXXX\n\n";
4343
create_fail2ban_jail($self);
4444
create_fail2ban_firewalld();
4545

46+
# Setup custom Usermin jail
47+
if (foreign_installed('usermin')) {
48+
create_fail2ban_usermin_jail();
49+
}
50+
4651
# Switch backend to use systemd to avoid failure on
4752
# fail2ban starting when actual log file is missing
4853
# e.g.: Failed during configuration: Have not found
@@ -120,6 +125,10 @@ my $mini_stack =
120125
my $proftpd_block = $mini_stack ? '' :
121126
"[proftpd]\n" .
122127
"enabled = true\nport = ftp,ftp-data,ftps,ftps-data,2222$proftpd_jail_extra\n\n";
128+
my $usermin_block = foreign_installed('usermin') && -d '/etc/fail2ban/filter.d'
129+
? "\n\n[usermin-auth]\nenabled = true\njournalmatch = ".
130+
"_SYSTEMD_UNIT=usermin.service"
131+
: '';
123132

124133
open(my $JAIL_LOCAL, '>', '/etc/fail2ban/jail.local');
125134
print $JAIL_LOCAL <<EOF;
@@ -137,7 +146,7 @@ enabled = true
137146
138147
[webmin-auth]
139148
enabled = true
140-
journalmatch = _SYSTEMD_UNIT=webmin.service
149+
journalmatch = _SYSTEMD_UNIT=webmin.service${usermin_block}
141150
142151
EOF
143152

@@ -160,4 +169,29 @@ EOF
160169
} # XXX iptables-multiport is default on CentOS, double check others.
161170
}
162171

172+
# Custom jail for Usermin, to protect against brute-force attacks on the login
173+
# page
174+
sub create_fail2ban_usermin_jail {
175+
return if (!-d '/etc/fail2ban/filter.d');
176+
open(my $USERMIN_JAIL, '>', '/etc/fail2ban/filter.d/usermin-auth.conf');
177+
print $USERMIN_JAIL <<'EOF';
178+
# Fail2Ban filter for usermin
179+
# created by Virtualmin installer
180+
181+
[INCLUDES]
182+
183+
before = common.conf
184+
185+
[Definition]
186+
187+
_daemon = usermin
188+
189+
failregex = ^%(__prefix_line)sNon-existent login as .+ from <HOST>\s*$
190+
^%(__prefix_line)sInvalid login as .+ from <HOST>\s*$
191+
192+
ignoreregex =
193+
EOF
194+
close $USERMIN_JAIL;
195+
}
196+
163197
1;

lib/Virtualmin/Config/Plugin/Fail2banFirewalld.pm

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ sub actions {
6262
create_fail2ban_jail($self);
6363
create_fail2ban_firewalld();
6464

65-
# Switch backend to use systemd to avoid failure on
66-
# fail2ban starting when actual log file is missing
67-
# e.g.: Failed during configuration: Have not found any log file for [name] jail
65+
# Setup custom Usermin jail
66+
if (foreign_installed('usermin')) {
67+
create_fail2ban_usermin_jail();
68+
}
69+
70+
# Switch backend to use systemd to avoid failure on fail2ban starting when
71+
# actual log file is missing e.g.: Failed during configuration: Have not
72+
# found any log file for [name] jail
6873
&foreign_require('fail2ban');
6974
my $jfile = "$fail2ban::config{'config_dir'}/jail.conf";
7075
my @jconf = &fail2ban::parse_config_file($jfile);
@@ -138,6 +143,10 @@ my $mini_stack =
138143
my $proftpd_block = $mini_stack ? '' :
139144
"[proftpd]\n" .
140145
"enabled = true\nport = ftp,ftp-data,ftps,ftps-data,2222$proftpd_jail_extra\n\n";
146+
my $usermin_block = foreign_installed('usermin') && -d '/etc/fail2ban/filter.d'
147+
? "\n\n[usermin-auth]\nenabled = true\njournalmatch = ".
148+
"_SYSTEMD_UNIT=usermin.service"
149+
: '';
141150

142151
open(my $JAIL_LOCAL, '>', '/etc/fail2ban/jail.local');
143152
print $JAIL_LOCAL <<EOF;
@@ -155,7 +164,7 @@ enabled = true
155164
156165
[webmin-auth]
157166
enabled = true
158-
journalmatch = _SYSTEMD_UNIT=webmin.service
167+
journalmatch = _SYSTEMD_UNIT=webmin.service${usermin_block}
159168
160169
EOF
161170

@@ -178,4 +187,29 @@ EOF
178187
}
179188
}
180189

190+
# Custom jail for Usermin, to protect against brute-force attacks on the login
191+
# page
192+
sub create_fail2ban_usermin_jail {
193+
return if (!-d '/etc/fail2ban/filter.d');
194+
open(my $USERMIN_JAIL, '>', '/etc/fail2ban/filter.d/usermin-auth.conf');
195+
print $USERMIN_JAIL <<'EOF';
196+
# Fail2Ban filter for usermin
197+
# created by Virtualmin installer
198+
199+
[INCLUDES]
200+
201+
before = common.conf
202+
203+
[Definition]
204+
205+
_daemon = usermin
206+
207+
failregex = ^%(__prefix_line)sNon-existent login as .+ from <HOST>\s*$
208+
^%(__prefix_line)sInvalid login as .+ from <HOST>\s*$
209+
210+
ignoreregex =
211+
EOF
212+
close $USERMIN_JAIL;
213+
}
214+
181215
1;

lib/Virtualmin/Config/Plugin/Usermin.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ sub actions {
4646
usermin::get_usermin_miniserv_config(\%uminiserv);
4747
$uminiserv{'preroot'} = "authentic-theme";
4848
$uminiserv{'ssl'} = "1";
49+
$uminiserv{'syslog'} = "1";
4950
$uminiserv{'ssl_cipher_list'} = $webmin::strong_ssl_ciphers;
5051
$uminiserv{'domainuser'} = 1;
5152
$uminiserv{'domainstrip'} = 1;

0 commit comments

Comments
 (0)