Fail2Ban is a brilliant piece of IDS (Intrusion Detection Software) that I've got a crush on.
I've developed a couple "jails" -- rules for banning IP addresses.
First, a couple thoughts, tricks, and tips:
Then refer to them like this:
NOTE the %(...)s do NOT forget trailing "s"!
NOTE the %(...)s do NOT forget trailing "s"!
I've had emails saying Fail2ban had banned an IP, but testing showed it didn't. WTF?!? This is important that this works!
When you run a new jail, or start one, also run:
sudo iptables -n --list
and watch for a "chain" for each of your jails, and, make sure each chain has a reference, like this:
If there are 0 (zero) references, then reload the chain's jail like this:
(substituting name of your jail with no references).
What happens is, sometimes the INPUT chain doesn't refer any packets to the fail2ban chain(s), so you'll get an email saying a ban has happened, but it hasn't taken effect, and leaves cryptic messages in /var/log/fail2ban.log.
Good luck with your fail2ban installation!
Attachment | Size |
---|---|
![]() | 1.96 KB |
![]() | 665 bytes |
Comments
Ron
Sat, 2011/11/26 - 03:04
Permalink
Fail2ban jail for phpMyAdmin
If you don't run a web-based front end for MySQL admin, such as phpMyAdmin, then you should ban anyone trying to access it.
Here's the Jail, in my /etc/fail2ban/jail.local:
enabled = true
port = http,https
filter = apache-phpmyadmin
logpath = /usr/local/apache*/logs/error*
maxretry = 1
findtime = %(one_week)s
bantime = %(one_week)s
## I've appended a SECOND action, below, which sends email notice
## of ban action (the "%(action_mwl)s" part...
action = iptables-multiport[name=apache-phpmyadmin,
port="http,https", protocol=tcp] %(action_mwl)s
And, its filter, called /etc/fail2ban/filters.d/apache-phpmyadmin.local (updated and attached below):
# Option: failregex] File does not exist: .*(phpmyadmin|phpMyAdmin).*] .*mysql-?admin.*] .*(websql|sqlweb).*] .*SSLMySQLAdmin.*] .*mysql/scripts/setup.php.*] .*myadmin/scripts/setup.php.*] .*(pma|mysql|SQL)$] .*appConf.htm$] .*cpanelmysql.*] .*sqlmanager.*] .*roundcube.*
# Notes.: Regexp to catch Apache PHP MySQL Admin on
## servers not running it.
# Values: TEXT
failregex = client
client
client
client
client
client
client
client
client
client
client
ignoreregex =
Note that I've also included a "roundcube" mail server/interface block on the last line...
R o n
- - -
Vancouver
Ron
Sun, 2011/11/27 - 03:39
Permalink
Jail for bad robots
This one is for robots or bad-guys that read /robots.txt but either do not honour it, or use it to look for sensitive data.
First, I put an entry in my /robots.txt like this:
Then, made a jail like this:
## Disallow: /verboten4bots,
## then anyone accessing verboten4bots is a
## bad bot or malicious:
## (c) Ronald Barnes 2011.11.26
##
[apache-verboten4bots]
enabled = true
port = http,https
filter = apache-verboten4bots
logpath = /usr/local/apache*/logs/error*
maxretry = 1
findtime = %(one_week)s
bantime = 300
action = iptables-multiport[name=apache-verboten4bots,
port="http,https", protocol=tcp] %(action_mwl)s
Finally, a filter like this:
#
##
## Put a dummy entry into /robots.txt saying:
## Disallow: /verboten4bots,
## then anyone accessing verboten4bots is
## a bad bot or malicious:
##
## (c) Ronald Barnes 2011.11.26
##
#
#
[Definition]
# Option: failregex
# Notes.: Put a dummy entry into /robots.txt saying:
## Disallow: /verboten4bots,
## then anyone accessing verboten4bots is
## a bad bot or malicious:
# Values: TEXT
#
failregex = client] .*verboten4bots.*] .*Verboten4bots.*] .*Verboten4Bots.*
client
client
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
R o n
- - -
Vancouver
Add new comment