首页 > 其他分享 >DenyHos黑白名单防ssh攻击

DenyHos黑白名单防ssh攻击

时间:2023-01-06 16:24:07浏览次数:73  
标签:lib 黑白 etc hosts ssh denyhosts DenyHos var usr

DenyHos黑白名单防ssh攻击

DenyHosts是Python语言写的一个程序,它会分析sshd的日志文件(/var/log/secure),当发现重 复的攻击时就会记录IP到/etc/hosts.deny文件,从而达到自动屏IP的功能。

官网下载DenyHosts

DenyHosts官网:http://denyhosts.sourceforge.net/

https://github.com/denyhosts/denyhosts

安装部署

yum安装

#yum install repe-release denyhosts -y

#systemctl enable --now denyhosts 

# cat /usr/lib/systemd/system/denyhosts.service 
[Unit]
Description=SSH log watcher
Before=sshd.service

[Service]
Type=forking
ExecStartPre=/bin/rm -f /var/run/denyhosts.pid
ExecStart=/usr/bin/denyhosts.py --daemon --config=/etc/denyhosts.conf
PIDFile=/var/run/denyhosts.pid

[Install]
WantedBy=multi-user.target
$systemctl enable denyhosts.service 

相关配置文件

$rpm -ql denyhosts
##  该目录中主要存放计划任务,日志压缩 以及 chkconfig 和 service 启动的文档
/etc/cron.d/denyhosts
/etc/denyhosts.conf
/etc/logrotate.d/denyhosts
/etc/rc.d/init.d/denyhosts
/etc/sysconfig/denyhosts
/usr/bin/denyhosts-control
/usr/bin/denyhosts.py

## 该目录中主要存放 denyhosts 所拒绝及允许的一些主机信息
/var/lib/denyhosts
/var/lib/denyhosts/allowed-hosts
/var/lib/denyhosts/allowed-warned-hosts
/var/lib/denyhosts/hosts
/var/lib/denyhosts/hosts-restricted
/var/lib/denyhosts/hosts-root
/var/lib/denyhosts/hosts-valid
/var/lib/denyhosts/offset
/var/lib/denyhosts/suspicious-logins
/var/lib/denyhosts/sync-hosts
/var/lib/denyhosts/users-hosts
/var/lib/denyhosts/users-invalid
/var/lib/denyhosts/users-valid
/var/log/denyhosts

黑白名单

]# cat /etc/hosts.allow
#
# hosts.allow    This file contains access rules which are used to
#        allow or deny connections to network services that
#        either use the tcp_wrappers library or that have been
#        started through a tcp_wrappers-enabled xinetd.
#
#        See 'man 5 hosts_options' and 'man 5 hosts_access'
#        for information on rule syntax.
#        See 'man tcpd' for information on tcp_wrappers
#
sshd:*.*.*.*   #表示允许所有


]# head -18  /etc/hosts.deny
#
# hosts.deny    This 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: Fri Jan  6 14:59:19 2023 | sshd: 200.148.153.172
sshd: 200.148.153.172
# DenyHosts: Fri Jan  6 14:59:19 2023 | sshd: 159.223.229.158
sshd: 159.223.229.158
# DenyHosts: Fri Jan  6 14:59:19 2023 | sshd: 41.79.235.36

编译安装

# wget http://imcat.in/down/DenyHosts-2.6.tar.gz
# du -sh DenyHosts-2.6.tar.gz
# tar xvf DenyHosts-2.6.tar.gz -C /usr/local/
# cd /usr/local/DenyHosts-2.6/
# python setup.py install


#cp /usr/share/denyhosts/denyhosts.cfg-dist /usr/share/denyhosts/denyhosts.cfg 

# egrep -v '^#|^$' /usr/share/denyhosts/denyhosts.cfg
       ############ THESE SETTINGS ARE REQUIRED ############
SECURE_LOG = /var/log/secure
HOSTS_DENY = /etc/hosts.deny
PURGE_DENY = 1h
BLOCK_SERVICE  = sshd
DENY_THRESHOLD_INVALID = 5
DENY_THRESHOLD_VALID = 10
DENY_THRESHOLD_ROOT = 1
DENY_THRESHOLD_RESTRICTED = 1
WORK_DIR = /usr/share/denyhosts/data
SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES
HOSTNAME_LOOKUP=YES
LOCK_FILE = /var/lock/subsys/denyhosts
       ############ THESE SETTINGS ARE OPTIONAL ############
ADMIN_EMAIL =
SMTP_HOST = localhost
SMTP_PORT = 25
SMTP_FROM = DenyHosts <nobody@localhost>
SMTP_SUBJECT = DenyHosts Report
AGE_RESET_VALID=5d
AGE_RESET_ROOT=25d
AGE_RESET_RESTRICTED=25d
AGE_RESET_INVALID=10d
   ######### THESE SETTINGS ARE SPECIFIC TO DAEMON MODE  ##########
DAEMON_LOG = /var/log/denyhosts

DAEMON_SLEEP = 30s
DAEMON_PURGE = 1h
   #########   THESE SETTINGS ARE SPECIFIC TO     ##########
   #########       DAEMON SYNCHRONIZATION         ##########


# cp /usr/share/denyhosts/daemon-control-dist /usr/share/denyhosts/daemon-control //启动文件
# chown root /usr/share/denyhosts/daemon-control
# chmod 754 /usr/share/denyhosts/daemon-control
# ln -s /usr/share/denyhosts/daemon-control /etc/init.d/denyhosts
# chkconfig --level 345 denyhosts on
# /sbin/service denyhosts restart
# /sbin/service denyhosts stop
# /sbin/service denyhosts status

 

 

 

 ####或开启启动方式

# vi /etc/rc.local
/usr/share/denyhosts/daemon-control start

 

 

标签:lib,黑白,etc,hosts,ssh,denyhosts,DenyHos,var,usr
From: https://www.cnblogs.com/weiweirui/p/17030811.html

相关文章

  • 利用host.deny和host.allow文件来允许指定IP来源登录ssh服务
    一、hosts.deny和hosts.allowhosts.deny和hosts.allow是成对出现的,当有一个主机想要访问我们的系统的时候,会经过黑白名单的确认,白名单的优先级高于黑名单,如果访问的ip出现......
  • 基于OpenCV DNN模块给黑白老照片上色(附Python/C++源码)
    导读本文给大家分享一个用OpenCVDNN模块给黑白老照片上色的实例,并给出Python和C++版本源码。 背景介绍    这个项目是基于在加利福尼亚大学,伯克利,RichardZhang,Phil......
  • 为什么彩色打印比黑白打印贵很多?
    如果你在小区或写字楼周边打印店打印过文件,你就会发现彩色打印比黑白打印的价格要贵很多,同样是使用A4纸进行打印,黑白打印单面要1元一张,而单面彩色打印价格大概是3元-5元一......
  • 转 Git配置SSH
    Git配置SSHhttp://t.csdn.cn/TT8QC林家小猪已于2022-05-2511:43:46修改26915收藏43分类专栏:软件安装文章标签:gitssh数据仓库版权华为云开发者联盟该内容已......
  • 1.树莓派设置root ssh登录
    设置root用户密码sudopasswdroot启动root账户sudopasswd--unlockroot设置ssh允许登录sudosed-i"s/^#PermitRootLogin.*/PermitRootLoginyes/g"/etc/ssh/ss......
  • Java个人博客系统ssh个人博客系统家乡特产家乡风景
    简介Java基于ssh开发的个人博客系统,主要有家乡特产文章,家乡风景,照片墙,留言等功能演示视频https://www.bilibili.com/video/BV1Yy4y1e7VR/?share_source=copy_web&vd_sou......
  • 转 Git配置SSH Keys步骤
    Git配置SSHKeys步骤 Git配置SSHKeys步骤使用教程1.若是首次安装使用git,先配置用户名称和邮箱(如果有就不需要配置)打开GitBash,输入gitconfig--globaluser.name......
  • Jenkins通过安装ssh插件实现构建后推送到其它服务器
    参考博客:https://www.cnblogs.com/zhchoutai/p/8869898.html一、PublishOverSSH 安装   因为我这里已经安装了PublishOverSSH 所以在installdeplugins中可......
  • 使用 K8S 部署 RSS 全套自托管解决方案- RssHub + Tiny Tiny Rss
    前言什么是RSS?RSS是一种描述和同步网站内容的格式,是使用最广泛的XML应用。RSS搭建了信息迅速传播的一个技术平台,使得每个人都成为潜在的信息提供者。发布一个RSS......
  • ssh免密登录问题
    执行ssh-copy-id遇到/usr/bin/ssh-copy-id:ERROR:@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ERROR:@WARNING:REMOTEHOSTIDENTIFICATIONHA......