4.激活fail2ban的规则
从测试结果可以看出, 恶意攻击节点的IP地址和攻击时间都能够正确发现, 因此可以进一步修改fail2ban的配置文件激活上述规则.
下面是我的/etc/fail2ban/jail.local配置文件内容:
- [tomcat]
- enabled = true
- port = http,https
- filter = tomcat
- action = iptables[name=tomcat, port=8080, protocol=tcp]
- sendmail-whois[name=tomcat, dest=abc@mail.com]
- maxretry = 2
- logpath = /opt/tomcat5/logs/localhost_access_log.txt
- bantime = 1800
5.测试效果
生成2个错误的链接,查看fail2ban日志 如下:
- 2010-09-10 18:33:30,156 fail2ban.actions.action: INFO Set actionStart = printf %b "Subject: [Fail2Ban] : started
- From: Fail2Ban <>
- To: \n
- Hi,\n
- The jail has been started successfully.\n
- Regards,\n
- Fail2Ban" | /usr/sbin/sendmail -f
- 2010-09-10 18:33:30,157 fail2ban.actions.action: INFO Set actionUnban =
- 2010-09-10 18:33:30,158 fail2ban.actions.action: INFO Set actionCheck =
- 2010-09-10 18:33:31,546 fail2ban.actions: WARNING [tomcat] Ban 192.168.32.41
并查看管理员邮箱 ,已经收到邮件了,内容大概如下:
- Hi,
-
- The IP 192.168.32.41 has just been banned by Fail2Ban after
- 4 attempts against tomcat.
-
-
- Here are more information about 192.168.32.41:
-
- [Querying whois.arin.net]
- [whois.arin.net]
- #
- # Query terms are ambiguous. The query is assumed to be:
- # "n 192.168.32.41"
- #
- # Use "?" to get help.
6.写完收工.
上面只是根据我的需求,写的一点东西,其他很功能大家自己可以去研究 .
|