http://www.fail2ban.org/wiki/index.php/MANUAL_0_8
vsftp就象ssh一樣的問題,大量的"黑客"來測試我的伺服器的安全,太謝他們了,為了提高一下他們入侵的難度,找了個小軟體來防暴力入侵.我測試了他的ftp入侵防護。蠻不錯的,ssh就不測試了,以前介紹過的那個軟體很好用.
fail2ban的安裝
Centos5上面安裝很容易.yum安裝就可以了,當然前提是安裝了我講的那個Centos的擴充包.
#yum install fail2ban
也可以到他們的官方網站看看
http://www.fail2ban.org/wiki/index.php/Main_Page
fail2ban 可以阻擋的暴力入侵服務很多如apache,postfix,exim,named,qmail,sasl,ssh,webmin,wuftpd,大多了.
在 filter.d 目錄可以看到所有的部分
#ls -l /etc/fail2ban/filter.d/
total 80
-rw-r--r-- 1 root root 704 Feb 28 05:44 apache-auth.conf
-rw-r--r-- 1 root root 2396 Mar 6 06:37 apache-badbots.conf
-rw-r--r-- 1 root root 650 Mar 5 06:41 apache-noscript.conf
-rw-r--r-- 1 root root 444 Mar 6 06:37 apache-overflows.conf
-rw-r--r-- 1 root root 1036 Mar 1 02:35 common.conf
-rw-r--r-- 1 root root 609 Feb 28 05:44 courierlogin.conf
-rw-r--r-- 1 root root 584 Feb 28 05:44 couriersmtp.conf
-rw-r--r-- 1 root root 606 Feb 28 05:44 exim.conf
-rw-r--r-- 1 root root 887 Feb 28 05:44 named-refused.conf
-rw-r--r-- 1 root root 584 Feb 28 05:44 postfix.conf
-rw-r--r-- 1 root root 875 Mar 6 05:53 proftpd.conf
-rw-r--r-- 1 root root 794 Feb 28 05:44 pure-ftpd.conf
-rw-r--r-- 1 root root 599 Feb 28 05:44 qmail.conf
-rw-r--r-- 1 root root 643 Feb 28 05:44 sasl.conf
-rw-r--r-- 1 root root 1379 Mar 6 05:47 sshd.conf
-rw-r--r-- 1 root root 620 Feb 28 05:44 sshd-ddos.conf
-rw-r--r-- 1 root root 758 May 7 11:27 vsftpd.conf
-rw-r--r-- 1 root root 820 Feb 28 05:44 webmin-auth.conf
-rw-r--r-- 1 root root 308 Feb 28 05:44 wuftpd.conf
-rw-r--r-- 1 root root 841 Mar 6 06:37 xinetd-fail.conf
fail2ban的配置
在fail2ban安裝好後.主要的設定檔案是/etc/fail2ban/jail.conf和fail2ban.conf.fail2ban.conf.對不過我們用預設的值就好了.
好了,我們平時的設定啦,他設定太容易了,修改設定檔jail可以控制上面的所有的服務.
# vim /etc/fail2ban/jail.conf
[DEFAULT]
#全局設定
# 不列入的 IP 範圍,如果有二組以上以空白做為間隔 192.168.250.0/24
ignoreip = 127.0.0.1
# 設定 IP 被封鎖的時間(秒),如果值為 -1,代表永遠封鎖
bantime = 600
# 設定在多少時間内達到 maxretry 的次數就封鎖
findtime = 600
# 允許嘗試的次數
maxretry = 3
#分類設定
#針對sshd暴力入侵防護
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp]
mail-whois[name=SSH, dest=root]
logpath = /var/log/secure
# 如果有個别的次數設定就設在這裡
maxretry = 5
#針對vsftpd暴力入侵防護
[vsftpd-iptables]
filter = vsftpd
action = iptables[name=VSFTPD, port=ftp, protocol=tcp]
sendmail-whois[name=VSFTPD, [email protected]]
bantime = 1800
建議設定成maxretry為 3 表示3次錯誤就封鎖,另外logpath(Centos5和Rhel5中)要改成/var/log/secure.
然後我們設定啟動服務:
#chkconfig --level 2345 fail2ban on
#service fail2ban start
fail2ban測試和檢視
過濾檢查文法測試指令,你可以用這個指令看看哦。
#fail2ban-regex /var/log/secure /etc/fail2ban/filter.d/vsftpd.conf
安裝完fail2ban後.運作iptables的指令,會看到多了如下的iptables 的規則
#iptables -L -nv
Chain INPUT (policy ACCEPT 231M packets, 51G bytes)
pkts bytes target prot opt in out source destination
97 5294 fail2ban-VSFTPD tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:21
Chain fail2ban-VSFTPD (1 references)
20 998 DROP all -- * * 220.249.41.163 0.0.0.0/0
77 4296 RETURN all -- * * 0.0.0.0/0 0.0.0.0/0
當然,fail2ban本身還提供一個指令來查
#fail2ban-client status vsftpd-iptables
Status for the jail: vsftpd-iptables
|- filter
| |- File list: /var/log/secure
| |- Currently failed: 0
| `- Total failed: 6
`- action
|- Currently banned: 1
| `- IP list: 220.249.41.163
`- Total banned: 1
注:如果重起iptables 記的一定還要重起fail2ban,不然他就不能生效,fail2ban的過濾表是在iptables 啟動後在加入的.