<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[用fail2ban阻止SSH和VSFTP暴力破解密码]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[服务器技术]]></category>
<pubDate>Sat, 01 Jan 2011 04:32:16 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	一、下载安装<br/>#wget <a href="http://cdnetworks-kr-2.dl.sourceforge.net/project/fail2ban/fail2ban-stable/fail2ban-0.8.4/fail2ban-0.8.4.tar.bz2" target="_blank">http://cdnetworks-kr-2.dl.sourceforge.net/project/fail2ban/fail2ban-stable/fail2ban-0.8.4/fail2ban-0.8.4.tar.bz2</a><br/><br/>#tar xvfj fail2ban-0.8.4.tar.bz2<br/>#cd fail2ban-0.8.4<br/>#python setup.py install<br/>#cd files<br/># cp ./redhat-initd /etc/init.d/fail2ban<br/># chkconfig –add fail2ban<br/>#service fail2ban start<br/><br/>注意：如果重起iptables 记的一定还要重起fail2ban，不然他就不能生效，fail2ban的过滤表是在iptables 启动后在加入的。<br/><br/>二、配置<br/>1、fail2ban本身配置<br/>默认fail2ban.conf里面就三个参数，而且都有注释。<br/>#默认日志的级别<br/>loglevel = 3<br/>#日志的存放路径<br/>logtarget = /var/log/fail2ban.log<br/>#socket的位置<br/>socket = /tmp/fail2ban.sock<br/><br/>2、fail2ban防护配置<br/>全局设置<br/># vi /etc/fail2ban/jail.conf<br/># 忽悠 IP范围 如果有二组以上用空白做为间隔<br/>ignoreip = 127.0.0.1<br/># 设定 IP 被封锁的时间(秒)，如果值为 -1，代表永远封锁<br/>bantime = 86400<br/># 设定在多少时间内达到 maxretry 的次数就封锁<br/>findtime = 600<br/># 设定在多少时间内达到 maxretry 的次数就封锁<br/>maxretry = 3<br/># 允许尝试的次数<br/><br/>分类设置<br/>#针对sshd暴力入侵防护<br/><br/>[ssh-iptables]<br/><br/>enabled = true<br/>filter = sshd<br/>action = iptables[name=SSH, port=ssh, protocol=tcp]<br/>sendmail-whois[name=SSH, dest=you@mail.com, sender=fail2ban@mail.com]<br/>logpath = /var/log/secure<br/># 如果有个别的次数设定就设在这里<br/>maxretry = 3<br/><br/>#针对vsftpd暴力入侵防护<br/><br/>[vsftpd-iptables]<br/><br/>enabled = true<br/>filter = vsftpd<br/>action = iptables[name=VSFTPD, port=ftp, protocol=tcp]<br/>sendmail-whois[name=VSFTPD, dest=you@mail.com]<br/>logpath = /var/log/secure<br/>maxretry = 3<br/><br/>建议设置成maxretry为 3 表示3次错误就封锁，另外logpath(Centos5和Rhel5中)要改成/var/log/secure。<br/><br/>然后我们设置启动服务：<br/>#chkconfig –level 345 fail2ban on<br/>#service fail2ban start<br/><br/>三、测试：<br/>查看iptables 的规则多出了 iptables-ssh的规则<br/><br/>iptables -L<br/>Chain INPUT (policy ACCEPT)<br/>target prot opt source destination<br/>fail2ban-SSH tcp — anywhere anywhere tcp dpt:ssh<br/>fail2ban-SSH tcp — anywhere anywhere tcp dpt:ssh<br/><br/>Chain fail2ban-SSH (2 references)<br/>target prot opt source destination<br/>Drop all — 122.102.64.54 anywhere<br/><br/># 这有一个被阻止的IP 拒绝时间根据在你的配置文件设置时间有关 我设置的是一天<br/>RETURN all — anywhere anywhere<br/><br/>++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br/>在其他的机器上ssh 192.168.1.2<br/>连续三次输错密码<br/><br/>使用命令fail2ban-client status ssh-iptables<br/>查看阻止状态<br/><br/>或者<br/><br/>fail2ban-client status<br/>Status<br/>&#124;- Number of jail: 1<br/>`- Jail list: ssh-iptables<br/><br/>测试结果：<br/>#fail2ban-client status ssh-iptables<br/>Status for the jail: ssh-iptables<br/>&#124;- filter<br/>&#124; &#124;- File list: /var/log/secure<br/>&#124; &#124;- Currently failed: 0<br/>&#124; `- Total failed: 3<br/>`- action<br/>&#124;- Currently banned: 1<br/>&#124; `- IP list: 192.168.1.1<br/>`- Total banned: 1<br/><br/>++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br/><br/>我们在来看看fail2ban的日志记录<br/><br/>2010-05-17 16:57:23,964 fail2ban.actions: WARNING [ssh-iptables] Ban 192.168.1.1<br/>2010-05-17 21:35:00,449 fail2ban.actions: WARNING [ssh-iptables] Ban 218.108.85.244<br/>2010-05-18 03:56:34,986 fail2ban.actions: WARNING [ssh-iptables] Ban 59.39.66.30<br/><br/>记录了被阻止的IP，成功阻止了ssh 密码猜测<br/><br/>这里只是只介绍了保护SSH和VPSFTP方法，配置文件中还有其他的服务配置，有时间了大家可以自己研究一下。<br/><br/><br/>Tags - <a href="http://www.dzhope.com/tags/fail2ban/" rel="tag">fail2ban</a> , <a href="http://www.dzhope.com/tags/ssh/" rel="tag">ssh</a> , <a href="http://www.dzhope.com/tags/vsftp/" rel="tag">vsftp</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] 用fail2ban阻止SSH和VSFTP暴力破解密码]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>