快速业务通道

fail2ban封IP之Http

作者 佚名技术 来源 Linux系统 浏览 发布时间 2012-04-17

环境介绍:http是一个tomcat 的js程序 ,设置的路径为/opt/tomcat5/logs/localhost_access_log.txt
OS:centos 5.3 fail2ban版本:fail2ban-0.8.2-3.el5.rf.noarch.rpm
官方网站:http://www.fail2ban.org/wiki/index.php/Main_Page

背景:及时发现别人的恶意请求并禁止

步骤:

1.安装fail2ban
这里我走了弯路,下源码包安装报错,大家可以这个网址下载:http://packages.sw.be/fail2ban/

  1. #rpm -ivh fail2ban-0.8.23.el5.rf.noarch.rpm

2.配置fail2ban的自定义过滤规则
分析/opt/tomcat5/logs/localhost_access_log.txt 日志的恶意请求如下 :

  1. 192.168.32.41 - - [10/Sep/2010:18:11:27 0800] "GET 12345678.txt HTTP/1.1" 404 1063
  2. 192.168.32.41 - - [10/Sep/2010:18:11:27 0800] "GET 12345678.txt HTTP/1.1" 404 1063
  3. 192.168.32.41 - - [10/Sep/2010:18:11:29 0800] "GET 12345678.txt HTTP/1.1" 404 1063
  4. 192.168.32.41 - - [10/Sep/2010:18:11:29 0800] "GET 12345678.txt HTTP/1.1" 404 1063
  5. 192.168.32.41 - - [10/Sep/2010:18:11:29 0800] "GET 12345678.txt HTTP/1.1" 404 1063
  6. 192.168.32.41 - - [10/Sep/2010:18:11:29 0800] "GET 12345678.txt HTTP/1.1" 404 1063

从攻击行为特征来看, 这是短时间连续导致服务器发送HTTP 404文件未找到错误码, 下面是用于发现上述攻击的fail2ban filter规则,
在/etc/fail2ban/filter.d/目录下建立tomcat.conf文件保存下面的内容:

  1. [Definition]
  2. failregex = <HOST> -.*- .*HTTP/1.* 404 .*$
  3. ignoreregex =

3.测试fail2ban的过滤规则

  1. # fail2ban-regex /opt/tomcat5/logs/localhost_access_log.txt /etc/fail2ban/filter.d/tomcat.conf

结果如下:

  1. Running tests
  2. =============
  3. Use regex file : /etc/fail2ban/filter.d/tomcat.conf
  4. Use log file : /opt/tomcat5/logs/localhost_access_log.txt
  5. Results
  6. =======
  7. Failregex
  8. |- Regular expressions:
  9. | [1] -.*- .*HTTP/1.* 404 .*$
  10. |
  11. `- Number of matches:
  12. [1] 13 match(es)
  13. Ignoreregex
  14. |- Regular expressions:
  15. |
  16. `- Number of matches:
  17. Summary
  18. =======
  19. Addresses found:
  20. [1]
  21. 192.168.32.41 (Fri Sep 10 18:10:59 2010)
  22. 192.168.32.41 (Fri Sep 10 18:11:27 2010)
  23. 192.168.32.41 (Fri Sep 10 18:11:27 2010)
  24. 192.168.32.41 (Fri Sep 10 18:11:29 2010)
  25. 192.168.32.41 (Fri Sep 10 18:11:29 2010)
  26. 192.168.32.41 (Fri Sep 10 18:11:29 2010)
  27. 192.168.32.41 (Fri Sep 10 18:11:29 2010)
  28. 192.168.32.41 (Fri Sep 10 18:11:30 2010)
  29. 192.168.32.41 (Fri Sep 10 18:11:30 2010)
  30. 192.168.32.41 (Fri Sep 10 18:27:44 2010)
  31. 192.168.32.41 (Fri Sep 10 18:27:47 2010)
  32. 192.168.32.41 (Fri Sep 10 18:27:50 2010)
  33. 192.168.32.41 (Fri Sep 10 18:27:53 2010)
  34. Date template hits:
  35. 0 hit(s): Month Day Hour:Minute:Second
  36. 0 hit(s): Weekday Month Day Hour:Minute:Second Year
  37. 0 hit(s): Weekday Month Day Hour:Minute:Second
  38. 0 hit(s): Year/Month/Day Hour:Minute:Second
  39. 130 hit(s): Day/Month/Year:Hour:Minute:Second
  40. 0 hit(s): Year-Month-Day Hour:Minute:Second
  41. 0 hit(s): Day-Month-Year Hour:Minute:Second[.Millisecond]
  42. 0 hit(s): TAI64N
  43. 0 hit(s): Epoch
  44. Success, the total number of match is 13
  45. However, look at the above section ''Running tests'' which could contain important
  46. information.

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号