教你如何配置fail2ban对Apache服务器进行安全防护的方法


当前第2页 返回上一页

要在基于红帽的系统中启用预定义的监狱,如下创建/etc/fail2ban/jail.local。

1

$ sudo vi /etc/fail2ban/jail.local

代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

# 检测密码认证失败

    [apache]

    enabled  = true

    port     = http,https

    filter   = apache-auth

    logpath  = /var/log/httpd/*error_log

    maxretry = 6

    # 检测抓取邮件地址的爬虫

    [apache-badbots]

    enabled  = true

    port     = http,https

    filter   = apache-badbots

    logpath  = /var/log/httpd/*access_log

    bantime  = 172800

    maxretry = 1

    # 检测漏洞和 PHP 脆弱性扫描

    [apache-noscript]

    enabled  = true

    port     = http,https

    filter   = apache-noscript

    logpath  = /var/log/httpd/*error_log

    maxretry = 6

    # 检测 Apache 溢出攻击

    [apache-overflows]

    enabled  = true

    port     = http,https

    filter   = apache-overflows

    logpath  = /var/log/httpd/*error_log

    maxretry = 2

    # 检测在服务器寻找主目录的尝试

    [apache-nohome]

    enabled  = true

    port     = http,https

    filter   = apache-nohome

    logpath  = /var/log/httpd/*error_log

    maxretry = 2

    # 检测执行不存在的脚本的企图

    # 这些都是流行的网站服务程序

    # 如:webmail, phpMyAdmin,WordPress

    port     = http,https

    filter   = apache-botsearch

    logpath  = /var/log/httpd/*error_log

    maxretry = 2

注意这些监狱文件默认的操作是iptables-multiport(定义在/etc/fail2ban/jail.conf中[DEFAULT]字段下的“banaction”中)。这个措施使用iptable的多端口模块禁止一个IP地址。

启用监狱后,你必须重启fail2ban来加载监狱。

在 Fedora 或者 CentOS/RHEL 7中:

1

$ sudo systemctl restart fail2ban

在 CentOS/RHEL 6中:

1

$ sudo service fail2ban restart

检查和管理fail2ban禁止状态

监狱一旦激活后,你可以用fail2ban的客户端命令行工具来监测当前的禁止状态。

查看激活的监狱列表:

1

$ sudo fail2ban-client status

查看特定监狱的状态(包含禁止的IP列表):

1

$ sudo fail2ban-client status [监狱名]

201561195749494.jpg (800×298)

你也可以手动禁止或者解禁IP地址:

要用制定监狱禁止IP:

1

$ sudo fail2ban-client set [name-of-jail] banip [ip-address]

要解禁指定监狱屏蔽的IP:

1

$ sudo fail2ban-client set [name-of-jail] unbanip [ip-address]

总结

本篇教程解释了fail2ban监狱如何工作以及如何使用内置的监狱来保护Apache服务器。依赖于你的环境以及要保护的web服务器类型,你或许要调整已有的监狱或者编写自定义监狱和日志过滤器。查看outfail2ban的官方Github页面来获取最新的监狱和过滤器示例。

以上就是教你如何配置fail2ban对Apache服务器进行安全防护的方法的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

apache怎么设置环境变量

apache怎么卸载

apache atlas是什么意思

apache基金会毕业是什么意思

apache组织为什么这么厉害

apache怎么安装

apache怎么修改端口号

apache 403 forbidden怎么解决

apache不解析php怎么办

apache tomcat是什么意思

更多相关阅读请进入《fail2ban》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...