使用fail2ban防止暴力破解ssh及vsftpd密码,fail2banvsftpdfail2ban支持


此文介绍一个linux下通过监控日志防止密码被暴力破解的软件-fail2ban。fail2ban支持常用的服务,如sshd,apache, qmail,proftpd, sasl, asterisk等的密码验证保护,当发现暴力破解的迹像时,可以通过iptables, tcp-wrapper, shorewall等方式阻止此IP的访问。

python安装

安装fail2ban需要Python >= 2.4,可以直接执行python查询版本号,但fail2ban 2.4有一个bug,所以还是推荐安装2.5以上的python。


python安装方法:

1

2

3

4

5

6

7

8

cd/tmp

wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tgz

tarxzf Python-2.7.3.tgz

cdPython-2.7.3

./configure

make&&makeinstall

rm-rf/usr/bin/python

ln-s/tmp/Python-2.7.3/python/usr/bin/

fail2ban安装

1

2

3

4

5

6

7

cd/tmp

wget https://github.com/downloads/fail2ban/fail2ban/fail2ban_0.8.6.orig.tar.gz

tarxzf fail2ban_0.8.6.orig.tar.gz

cdfail2ban-fail2ban-a20d1f8/

./setup.pyinstall

cpfiles/redhat-initd/etc/init.d/fail2ban

chmod755/etc/init.d/fail2ban

配置fail2ban日志轮循:

1

vi/etc/logrotate.d/fail2ban

写入:

1

2

3

4

5

6

7

8

9

/var/log/fail2ban.log {

weekly

rotate 7

missingok

compress

postrotate

/etc/init.d/fail2banrestart 1>/dev/null||true

endscript

}

fail2ban使用方法

配置文件:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

/etc/fail2ban/

├── action.d

│ ├── dummy.conf

│ ├── hostsdeny.conf

│ ├── iptables.conf

│ ├── mail-whois.conf

│ ├── mail.conf

│ └── shorewall.conf

├── fail2ban.conf

├── fail2ban.local

├── filter.d

│ ├── apache-auth.conf

│ ├── apache-noscript.conf

│ ├── couriersmtp.conf

│ ├── postfix.conf

│ ├── proftpd.conf

│ ├── qmail.conf

│ ├── sasl.conf

│ ├── sshd.conf

│ └── vsftpd.conf

├── jail.conf

└── jail.local

目录action.d下的文件指定满足条件时执行的一些动作,比如使用iptables禁止ip访问。


目录filter.d下的文件定义匹配日志的正则表达式。


fail2ban.conf文件是配置fail2ban-server程序启动的一些参数


jail.conf文件包含filter及action的指定。


每个conf文件可被local文件覆盖,conf文件第一个被读取,接着是读取local文件,所以local文件中定义的参数会覆盖conf中的参数。所以我们不需要添加所有的内容到local文件,只需要添加conf文件中你想覆盖的部分参数就好。

防ssh及vsftpd暴力破解实例

建立/etc/fail2ban/jail.local文件,在文件中加入:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

[vsftpd-iptables]

enabled =true

filter = vsftpd

action = iptables[name=VSFTPD, port=ftp, protocol=tcp]

sendmail-whois[name=VSFTPD, dest=you@mail.com]

logpath =/var/log/secure

maxretry = 3

[ssh-iptables]

enabled =true

filter = sshd

action = iptables[name=SSH, port=ssh, protocol=tcp]

sendmail-whois[name=SSH, dest=you@example.com, sender=fail2ban@example.com]

logpath =/var/log/secure.log

maxretry = 5

enabled:可选值false,true


filter:指定/etc/fail2ban/filter.d/目录下的正则文件,如filter = sshd则是指定/etc/fail2ban/filter.d/sshd.conf。


action:指定执行的动作,具体动作文件在/etc/fail2ban/action.d目录下。


logpath:指定监控日志的路径。


maxretry:执行action匹配的次数。


接着执行:

1

2

service iptables start

service fail2ban start

问题解决

1、WARNING: Unable to find a corresponding IP address for xxx


http://www.centos.bz/2012/05/warning-unable-to-find-a-corresponding-ip-address-for/


参考:http://www.fail2ban.org/wiki/index.php/MANUAL_0_8

相关内容

    暂无相关文章