在Linux防火墙上过滤外来的ICMP timestamp和禁止Traceroute探测

由于等保测评要求,最近需要协助加固Linux的云服务器,修复这两个漏洞,故查阅了相关资料,整理起来以便以后回看

环境:Centos6.9

ICMP timestamp 请求响应漏洞

解决方案:

  • 在您的防火墙上过滤外来的ICMP timestamp(类型13)报文以及外出的ICMP timestamp回复报文。

    具体解决方式就是禁用ICMP timestamp-request,编辑etc/sysconfig/iptables文件,在防火墙规则里面添加如下两条记录:

    [root@i-721DFB51 ~]# vim /etc/sysconfig/iptables
    
    # add the following two lines to limit icmp timestamp 20191029
     -A INPUT -p icmp -m icmp --icmp-type timestamp-request -j DROP
     -A INPUT -p icmp -m icmp --icmp-type timestamp-reply -j DROP
    

解决允许Traceroute探测

解决方案:

  • 添加相关规则

    [root@i-721DFB51 ~]# vim /etc/sysconfig/iptables

    # add the following two lines to ban Traceroute Detection
    -A INPUT -p icmp -m icmp --icmp-type time-exceeded -j DROP
    -A OUTPUT -p icmp -m icmp --icmp-type time-exceeded -j DROP
    
  • 重启iptables服务

    service iptables restart

  • 检查新添加的规则是否生效

    iptables -L -n

生效的话会显示添加下面几条规则,13,14是ICMP timestamp 请求响应漏洞的规则,11是解决允许Traceroute探测的

DROP       icmp --  0.0.0.0/0           0.0.0.0/0           icmp type 13
DROP       icmp --  0.0.0.0/0           0.0.0.0/0           icmp type 14
DROP       icmp --  0.0.0.0/0           0.0.0.0/0           icmp type 11

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
DROP       icmp --  0.0.0.0/0            0.0.0.0/0           icmp type 11 

除了上面的直接修改文件的方式,我们也可以直接使用iptable的命令进行修改规则,直接在终端命令行输入如下命令

iptables -A INPUT -p ICMP --icmp-type timestamp-request -j DROP
iptables -A INPUT -p ICMP --icmp-type timestamp-reply -j DROP
iptables -A INPUT -p ICMP --icmp-type time-exceeded -j DROP
iptables -A OUTPUT -p ICMP --icmp-type time-exceeded -j DROP

输入之后,执行iptables -L -n查看修改的规则情况。
不过注意,现在这只是临时生效,一旦你service iptables restart重启iptables服务,你就会发现,你设定的规则不见了。
如果你想跟上面修改文件的达到永久生效的效果,你只需要执行一句命令service iptables save对我们修改过的规则进行保存即可。

第二种方法我直接写了一个脚本来跑

#!/bin/bash
# 使用环境:Centos6.9
# 备份原来的防火墙规则
/bin/cp /etc/sysconfig/iptables /etc/sysconfig/iptables.bak
# ICMP timestamp 请求响应漏洞
iptables -A INPUT -p ICMP --icmp-type timestamp-request -j DROP
iptables -A INPUT -p ICMP --icmp-type timestamp-reply -j DROP
# 解决允许Traceroute探测
iptables -A INPUT -p ICMP --icmp-type time-exceeded -j DROP
iptables -A OUTPUT -p ICMP --icmp-type time-exceeded -j DROP
# 查看修改后的防火墙规则
iptables -L -n
# 查看是否符合预期,是的话输入yes保存,否则输入no回退到之前的防火墙规则
echo "Is the rules save? (yes/no)"
while true
do
    read option
    if [ $option == "yes" ];then
        service iptables save
        service iptables restart
        break
    elif [ $option == "no" ];then
        service iptables restart
        break
    else
        echo "Please input yes/no"
    fi
done
# 查看保存后的防火墙规则是否生效
iptables -L -n

环境:Centos7.5

由于不知道怎么使用firewall-cmd来修改规则,只能在centos7上重新安装iptables服务,并关闭firewalld服务

yum install iptables-services -y
systemctl mask firewalld.service
systemctl enable iptables.service
systemctl enable ip6tables.service

systemctl stop firewalld.service
systemctl start iptables.service
systemctl start ip6tables.service

安装完成之后就如上面一样修改/etc/sysconfig/iptables文件即可(这只是一个取巧的方法,欢迎大家批评指正)

参考链接

https://www.cnblogs.com/toughlife/p/5475256.html

https://www.cnblogs.com/liushui-sky/p/9442299.html

猜你喜欢

转载自blog.csdn.net/zhh763984017/article/details/102902499