/etc/hosts.allow & /etc/hosts.deny

 

一.

 

 

二、hosts.allow和hosts.deny支持哪些服务

2.1 hosts.allow和hosts.deny支持哪些服务

hosts.allow和hosts.deny规则的执行者为TCP wrappers,对应守护进程为tcpd;而tcpd执行依赖于程序使用了libwrap库。

也就是说:hosts.allow和hosts.deny支持且只支持使用了libwrap库的服务。

 

2.2 查看程序是否使用libwarp

方法一、查看hosts_access字段串

查看应用程序是否支持 wrapper,可以使用 strings 程序然后 grep 字符串 hosts_access:

strings /usr/sbin/sshd | grep hosts_access

方法二、使用ldd

ldd /usr/sbin/sshd | grep libwrap

查测发现使用xinetd的都可以、sshd可以、vsftpd可以,httpd不可以,weblogic等java程序就不要想了。

 

三:

 

 

#!/bin/env

cat /var/log/secure|awk '/Invalid/{print $NF} /Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2":"$1}' > blacklist

for line in `cat blacklist`;do
        ip=`echo $line|cut -d: -f1`
        num=`echo $line|cut -d: -f2`

        if [ "$num" -gt 5 ];then
                grep $ip /etc/hosts.deny &> /dev/null
                if [ $? -gt 0 ];then
                        echo sshd:$ip:$num:deny >> hosts.deny
                fi
        fi
done

把Failed 和Invalid超过5次的写到/etc/hosts.deny中

 

/etc/hosts.allow

sshd:192.168.0.0/255.255.0.0:allow # 允许内网连接
all:116.236.134.26:allow # 允许公网地址连接
all:10.8.0.0/255.255.255.0:allow # 允许openvpn转换后的地址连接
sendmail:all:allow

/etc/hosts.deny

all:all:deny
sshd:all:deny

 

posted @ 2020-10-15 16:33  ascertain  阅读(1403)  评论(0编辑  收藏  举报