版權聲明:原創做品,容許轉載,轉載時請務必以超連接形式標明文章
原始出處 、做者信息和本聲明。不然將追究法律責任。
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
|