denyhost防止SSH暴力破解、機器掃描、密碼猜測

 DenyHostsPython語言寫的一個程序,它會分析sshd的日誌文件,當發現重 復的***時就會記錄IP/etc/hosts.deny文件,從而達到自動屏IP的功能。

DenyHosts官方網站爲:http://denyhosts.sourceforge.net

 

以下是安裝記錄(以CentOS 4.3, DenyHosts 2.5 爲例)

 

安裝

 

# cd /usr/local/src 

# wget http://mesh.dl.sourceforge.net/sourceforge/denyhosts/DenyHosts-2.5.tar.gz

# tar -zxvf DenyHosts-2.5.tar.gz

 

# cd DenyHosts-2.5

# python setup.py install

 

默認是安裝到/usr/share/denyhosts目錄的。

 

# cd /usr/share/denyhosts/

 

# cp denyhosts.cfg-dist denyhosts.cfg

 

# vi denyhosts.cfg

 

根據自己需要進行相應的配置(解釋見下文件的配置文件)

設置啓動腳本

 

# cp daemon-control-dist daemon-control 

# chown root daemon-control 

# chmod 700 daemon-control

完了之後執行 daemon-contron start就可以了。

# ./daemon-control start

如果要使DenyHosts每 次重起後自動啓動還需做如下設置:

# cd /etc/init.d

# ln -s /usr/share/denyhosts/daemon-control denyhosts

# chkconfig --add denyhosts 

# chkconfig --level 2345 denyhosts on

或者修改/etc/rc.local文件:

# vi /etc/rc.local

加入下面這條命令:

/usr/share/denyhosts/daemon-control start

 

 DenyHosts配置文件:

 vi /usr/share/denyhosts/denyhosts.cfg

 SECURE_LOG = /var/log/secure

 #ssh 日誌文件,它是根據這個文件來判斷的。

 HOSTS_DENY = /etc/hosts.deny

 #控制用戶登陸的文件

 PURGE_DENY = 5m

 #過多久後清除已經禁止的

 BLOCK_SERVICE  = sshd

 #禁止的服務名

 DENY_THRESHOLD_INVALID = 1

 #允許無效用戶失敗的次數

 DENY_THRESHOLD_VALID = 10

 #允許普通用戶登陸失敗的次數

 DENY_THRESHOLD_ROOT = 5

 #允許root登陸失敗的次數

 HOSTNAME_LOOKUP=NO

 #是否做域名反解

 ADMIN_EMAIL =

 #管理員郵件地址,它會給管理員發郵件

 DAEMON_LOG = /var/log/denyhosts#自己的日誌文件

 然後就可以啓動了:

 service denyhost start

 可以看看/etc/hosts.deny內是 否有禁止的IP,有的話說明已經成功了。

 如果出現:./daemon-control start配置

 starting DenyHosts:    /usr/bin/env python /usr/bin/denyhosts.py --daemon --config=/usr/share/denyhosts/denyhosts.cfg

 Can't read: /private/var/log/system.log

 [Errno 2] No such file or directory: '/private/var/log/system.log'

 Error deleting DenyHosts lock file: /var/lock/subsys/denyhosts

 [Errno 2] No such file or directory: '/var/lock/subsys/denyhosts'

 修改一下 denyhosts.cfg文件(24-25),把25行用#註釋掉就可以了。

 24# Mac OS X (v10.3 or earlier):

 25 SECURE_LOG=/private/var/log/system.log

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章