爆破だサービスdeny sshログインドキュメントの拒否

6264 ワード

最近50回の失敗したログイン記録を調べて、どれらのIPが暴力的にsshにログインしようとしていることを発見することができます
実際にアクセスしたファイル/var/log/btmp.このログファイルはバイナリファイルであり、直接アクセスできず、lastbコマンドでのみアクセスでき、変更できないが、削除でき、対応するレコードの削除に達する.
[root@sz-nginx02 ~]# lastb -n 50
help     ssh:notty    218.17.149.227   Sun Jan 24 16:28 - 16:28  (00:00)    
hdfs     ssh:notty    218.17.149.227   Sun Jan 24 15:16 - 15:16  (00:00)    
michael  ssh:notty    59-120-151-118.h Sun Jan 24 15:03 - 15:03  (00:00)    
mfs      ssh:notty    59-120-151-118.h Sun Jan 24 14:20 - 14:20  (00:00)    
hadoop   ssh:notty    218.17.149.227   Sun Jan 24 14:03 - 14:03  (00:00)    
media    ssh:notty    59-120-151-118.h Sun Jan 24 13:40 - 13:40  (00:00)    
guest    ssh:notty    218.17.149.227   Sun Jan 24 12:50 - 12:50  (00:00)    
a        ssh:notty    ec2-54-165-101-6 Sun Jan 24 11:57 - 11:57  (00:00)    
grayson  ssh:notty    218.17.149.227   Sun Jan 24 11:37 - 11:37  (00:00)    
admin    ssh:notty    212-83-174-199.r Sun Jan 24 11:06 - 11:06  (00:00)    
ubnt     ssh:notty    212-83-174-199.r Sun Jan 24 11:06 - 11:06  (00:00)    
。。。。

Last最近のsshログインレコードの表示
実際のアクセスファイル/var/log/wtmp、バイナリファイル、直接catなどのアクセスはできず、lastコマンドでのみアクセスできます.変更はできませんが、削除してsshログインレコードをすべて消去できます.
[root@mop-general log]# last -20
root     pts/0        122.9.2.2        Wed Sep  7 18:42 - 18:43  (00:00)    
root     pts/4        180.190.112.198  Wed Sep  7 16:06   still logged in   
root     pts/3        180.191.152.214  Wed Sep  7 15:58 - 18:10  (02:12)    
root     pts/1        180.191.96.24    Wed Sep  7 15:35 - 18:01  (02:26)    
root     pts/0        180.191.100.87   Wed Sep  7 14:37 - 17:16  (02:38)    
root     pts/2        180.191.100.87   Wed Sep  7 11:42 - 17:16  (05:34)    
root     pts/0        49.144.88.139    Tue Sep  6 15:56 - 13:38  (21:42)    
root     pts/1        49.144.88.139    Tue Sep  6 14:39 - 13:38  (22:59)    
root     pts/0        49.144.124.87    Tue Sep  6 10:59 - 15:04  (04:04)    
root     pts/3        49.144.64.155    Mon Sep  5 16:32 - 11:25  (18:53)    
root     pts/2        49.144.64.155    Mon Sep  5 16:32 - 11:25  (18:53)    
root     pts/0        49.144.64.155    Mon Sep  5 14:51 - 18:39  (03:47)    
root     pts/1        49.144.64.155    Mon Sep  5 11:02 - 18:39  (07:37)    
root     pts/0        49.144.64.155    Sun Sep  4 14:41 - 11:15  (20:33)    
root     pts/0        45.116.146.134   Fri Aug 26 18:21 - 18:21  (00:00)    
root     pts/0        45.116.146.134   Fri Aug 26 18:21 - 18:21  (00:00)    
root     pts/0        45.116.146.134   Fri Aug 26 18:21 - 18:21  (00:00)    
root     pts/0        45.116.146.134   Fri Aug 26 18:21 - 18:21  (00:00)    
root     pts/0        45.116.146.134   Fri Aug 26 18:21 - 18:21  (00:00)    
root     pts/0        45.116.146.134   Fri Aug 26 18:21 - 18:21  (00:00)

セキュリティログ/var/log/secureは、ログインの成功と失敗の詳細を記録し、lastとlastbは情報の統合を表示し、直接アクセスを表示することができます.
tail -100 /var/log/secure
Jan 24 14:41:41 sz-nginx02 sshd[5497]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:41:42 sz-nginx02 sshd[5499]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:41:43 sz-nginx02 sshd[5501]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:41:44 sz-nginx02 sshd[5503]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:41:45 sz-nginx02 sshd[5505]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:41:46 sz-nginx02 sshd[5507]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:41:46 sz-nginx02 sshd[5509]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:41:47 sz-nginx02 sshd[5511]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:42:39 sz-nginx02 sshd[5513]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:42:40 sz-nginx02 sshd[5515]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:43:20 sz-nginx02 sshd[5517]: fatal: Read from socket failed: Connection reset by peer [preauth]
Jan 24 14:43:21 sz-nginx02 sshd[5519]: fatal: Read from socket failed: Connection reset by peer [preauth]
。。。。

ssh爆破防止***方式:
(1)鍵の作成,ssh-keygen
(2)DenyHostサービスを利用して,暴力sshを試みるipを制限する.デフォルトでは連続的なログイン試行に5回失敗し、/etc/hostsにIPを追加する.denyファイルは、ipログインを制限します.DenyHostはpythonが書いたプログラムで、sshdのログファイルを分析し、重複する***を発見すると/etc/hostsにIPを記録します.denyファイルは、IPを自動的に遮断する機能を備えています.
denyhostサービスインストール
(1)yumソース取付
yum -y install denyhosts.noarch
(2)コンパイルインストール
公式サイト:http://nchc.dl.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz
解凍、コンパイルインストール
DenyHostsプロファイル解析:vi/etc/denyhosts.conf
SECURE_LOG = /var/log/secure
#ssh     ,   redhat     /var/log/secure      。
#Mandrake、FreeBSD    /var/log/auth.log    , SUSE   /var/log/messages    。                 。
HOSTS_DENY = /etc/hosts.deny
#         
PURGE_DENY = 30m
#           ,        

#            'm' = minutes
#            'h' = hours
#            'd' = days
#            'w' = weeks
#            'y' = years

BLOCK_SERVICE = sshd
#      ,  DenyHost     SSH  ,    SMTP  。
DENY_THRESHOLD_INVALID = 1
#           
DENY_THRESHOLD_VALID = 5
#             
DENY_THRESHOLD_ROOT = 3
#  root       
HOSTNAME_LOOKUP=NO
#       
ADMIN_EMAIL = 
#       ,         
DAEMON_LOG = /var/log/denyhosts
#DenyHosts         

IPレコードへのsshログインが拒否されました
[root@fortress02-new ~]# cat /etc/hosts.deny
# hosts.denyThis file contains access rules which are used to
#deny connections to network services that either use
#the tcp_wrappers library or that have been
#started through a tcp_wrappers-enabled xinetd.
#
#The rules in this file can also be set up in
#/etc/hosts.allow with a 'deny' option instead.
#
#See 'man 5 hosts_options' and 'man 5 hosts_access'
#for information on rule syntax.
#See 'man tcpd' for information on tcp_wrappers
#
# DenyHosts: Wed Aug 17 14:51:21 2016 | sshd: 104.227.138.234
sshd: 104.227.138.234
# DenyHosts: Wed Aug 17 14:51:21 2016 | sshd: 61.161.250.27
sshd: 61.161.250.27
。。。。。。

転載先:https://blog.51cto.com/jschu/1738038