Guys,
I've configured Dag's fail2ban package on my centos 5.3 servers.
The default configuration out of the boxe catches some errors, however some it doesn't catch, which are fixable, but I'm sure there are even more that I'm not aware of or not thought about.
The purpose of this post is to concentrate on sshd rules
The out of the box regex rules from /etc/fail2ban/filter.d/sshd.conf looks like this
failregex = (?:error: PAM: )?Authentication failure for .* from <HOST>\s*$
Failed [-/\w]+ for .* from <HOST>(?: port \d*)?(?: ssh\d*)?\s*$
ROOT LOGIN REFUSED.* FROM <HOST>\s*$
[iI](?:llegal|nvalid) user .* from <HOST>\s*$
Invalid user .* from <HOST>\s*$
User .+ from <HOST> not allowed because not listed in AllowUsers\s*$
User .+ from <HOST> not allowed because none of user's groups are listed in AllowGroups\s*$
Address <HOST> .* POSSIBLE BREAK-IN ATTEMPT\s*$
authentication failure; logname=\S* uid=\S* euid=\S* tty=\S* ruser=\S* rhost=<HOST>(?:\s+user=.*)?\s*$
running
fail2ban-regex /var/log/secure /etc/fail2ban/filter.d/sshd.conf
I get the following results
Failregex
|- Regular expressions:
| [1] (?:error: PAM: )?Authentication failure for .* from <HOST>\s*$
| [2] Failed [-/\w]+ for .* from <HOST>(?: port \d*)?(?: ssh\d*)?\s*$
| [3] ROOT LOGIN REFUSED.* FROM <HOST>\s*$
| [4] [iI](?:llegal|nvalid) user .* from <HOST>\s*$
| [5] Invalid user .* from <HOST>\s*$
| [6] User .+ from <HOST> not allowed because not listed in AllowUsers\s*$
| [7] User .+ from <HOST> not allowed because none of user's groups are listed in AllowGroups\s*$
| [8] Address <HOST> .* POSSIBLE BREAK-IN ATTEMPT!\s*$
| [9] authentication failure; logname=\S* uid=\S* euid=\S* tty=\S* ruser=\S* rhost=<HOST>(?:\s+user=.*)?\s*$
|
`- Number of matches:
[1] 0 match(es)
[2] 0 match(es)
[3] 0 match(es)
[4] 4545 match(es)
[5] 4545 match(es)
[6] 0 match(es)
[7] 0 match(es)
[8] 0 match(es)
[9] 0 match(es)
which is great, as you can see rule 4/5 catches the users brute force you can see in the log
Mar 8 14:07:02 bender sshd[21575]: Invalid user oracle1 from 205.237.202.133
Mar 8 14:07:03 bender sshd[21576]: input_userauth_request: invalid user oracle1
Mar 8 14:07:03 bender sshd[21576]: Received disconnect from 205.237.202.133: 11: Bye Bye
Mar 8 14:07:03 bender sshd[21577]: Invalid user grace from 205.237.202.133
Mar 8 14:07:03 bender sshd[21578]: Invalid user grace from 205.237.202.133
However it doesn't find
Mar 10 07:43:59 bender sshd[14659]: reverse mapping checking getaddrinfo for 221-135-54-97.sify.net failed - POSSIBLE BREAK-IN ATTEMPT!
which is because the regex pattern doesn't pickup ATTEMPT!, it picks up ATTEMPT.
Adjusting the rule
Address <HOST> .* POSSIBLE BREAK-IN ATTEMPT\s*$
to
Address <HOST> .* POSSIBLE BREAK-IN ATTEMPT!\s*$
should resolve this
which we can see by re-running the fail2ban-regex test
Results
=======
Failregex
|- Regular expressions:
| [1] (?:error: PAM: )?Authentication failure for .* from <HOST>\s*$
| [2] Failed [-/\w]+ for .* from <HOST>(?: port \d*)?(?: ssh\d*)?\s*$
| [3] ROOT LOGIN REFUSED.* FROM <HOST>\s*$
| [4] [iI](?:llegal|nvalid) user .* from <HOST>\s*$
| [5] Invalid user .* from <HOST>\s*$
| [6] User .+ from <HOST> not allowed because not listed in AllowUsers\s*$
| [7] User .+ from <HOST> not allowed because none of user's groups are listed in AllowGroups\s*$
| [8] Address <HOST> .* POSSIBLE BREAK-IN ATTEMPT!\s*$
| [9] authentication failure; logname=\S* uid=\S* euid=\S* tty=\S* ruser=\S* rhost=<HOST>(?:\s+user=.*)?\s*$
|
`- Number of matches:
[1] 0 match(es)
[2] 0 match(es)
[3] 0 match(es)
[4] 4545 match(es)
[5] 4545 match(es)
[6] 0 match(es)
[7] 0 match(es)
[8] 1 match(es)
[9] 0 match(es)
does catch it.
The questions are
1.) are there any more rules that should be added from experience
2.) is there a better way to design these rules.