版权声明:原创做品,容许转载,转载时请务必以超连接形式标明文章
原始出处 、做者信息和本声明。不然将追究法律责任。
http://1177696.blog.51cto.com/728703/317395
|
链接上互联网的linux主机难免有人探测你的ssh的密码
最近发现个人机器被来自各个国家的***不停测在暴力猜想密码,经不起这样的折腾!
后来发现了一款软件能够阻止这样的***,很奏效的!
下面是个人配置:
下载源码包安装 地址:http://www.fail2ban.org/wiki/index.php/Main_Page 上传到服务器上 安装 #tar xvfj fail2ban-0.8.4.tar.bz2 #cd fail2ban-0.8.4 #python setup.py install 安装完成后服务会自动设置成启动的
在以前须要将系统的IPTABLES启动
配置: # vi /etc/fail2ban/jail.conf # 忽悠 IP范围 若是有二组以上用空白作为间隔 ignoreip = 127.0.0.1 # 设定 IP 被封锁的时间(秒),若是值为 -1,表明永远封锁 bantime = 86400 # 设定在多少时间内达到 maxretry 的次数就封锁 findtime = 600 # 容许尝试的次数 maxretry = 3 [ssh-iptables] # 开启ssh阻止规则 enabled = true filter = sshd action = iptables[name=SSH, port=22, protocol=tcp] #不发送邮件 #sendmail-whois[name=SSH, dest=you@mail.com, sender=fail2ban@mail.com] #ssh 失败日志路径
logpath = /var/log/secure
启动fail2ban
service fail2ban start
查看iptables 的规则多出了 iptables-ssh的规则
iptables -L
Chain INPUT (policy ACCEPT) target prot opt source destination fail2ban-SSH tcp -- anywhere anywhere tcp dpt:ssh fail2ban-SSH tcp -- anywhere anywhere tcp dpt:ssh
Chain fail2ban-SSH (2 references)
target prot opt source destination DROP all -- 122.102.64.54 anywhere
# 这有一个被阻止的IP 拒绝时间根据在你的配置文件设置时间有关 我设置的是一天
RETURN all -- anywhere anywhere +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 在其余的机器上ssh 192.168.1.2 连续三次输错密码 使用命令fail2ban-client status ssh-iptables 查看阻止状态 或者 fail2ban-client status Status |- Number of jail: 1 `- Jail list: ssh-iptables 测试结果: #fail2ban-client status ssh-iptables Status for the jail: ssh-iptables |- filter | |- File list: /var/log/secure | |- Currently failed: 0 | `- Total failed: 3 `- action |- Currently banned: 1 | `- IP list: 192.168.1.1 `- Total banned: 1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
咱们在来看看fail2ban的日志记录
2010-05-17 16:57:23,964 fail2ban.actions: WARNING [ssh-iptables] Ban 192.168.1.1
2010-05-17 21:35:00,449 fail2ban.actions: WARNING [ssh-iptables] Ban 218.108.85.244 2010-05-18 03:56:34,986 fail2ban.actions: WARNING [ssh-iptables] Ban 59.39.66.30
记录了被阻止的IP
成功阻止了ssh 密码猜想
这只是阻止其中的一种ssh***,配置文件中还有其余的服务配置,等有时间了我慢慢的贴上来!
本文出自 “
影子骑士” 博客,请务必保留此出处
http://1177696.blog.51cto.com/728703/317395
|