您的位置:首页 > 大数据 > 人工智能

利用fail2ban阻止ssh暴力破解密码

2010-05-18 12:40 288 查看

连接上互联网的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


启动fail2ban

Fail2ban-client start

关闭fail2ban

Fail2ban-client stop


 fail2ban-client status

 

查看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***,配置文件中还有其他的服务配置,等有时间了我慢慢的贴上来!

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: