在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

  • 1
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在 Windows 操作系统上,您可以通过以下步骤在防火墙过滤外来ICMP timestamp类型 13报文以及外出ICMP timestamp 回复报文: 1. 打开 Windows 防火墙设置。您可以通过按下 Win + R 键,在运行对话框中输入 "wf.msc" 并按下回车键来打开 Windows 防火墙高级安全设置。 2. 在 Windows 防火墙高级安全设置窗口中,选择 "入站规则" 选项。 3. 单击 "新建规则" 链接,以创建新的入站规则。 4. 在规则类型对话框中,选择 "自定义" 选项,并单击 "下一步"。 5. 在程序对话框中,选择 "所有程序" 或指定特定程序,取决于您是否要限制特定程序的 ICMP timestamp 报文。 6. 在协议和端口对话框中,选择 "ICMPv4" 或 "ICMPv6",具体取决于您要过滤ICMP 版本。 7. 在自定义服务对话框中,选择 "指定 ICMP 类型" 选项,并选择 "时间戳请求"(类型 13)。 8. 在操作对话框中,选择 "阻止连接" 选项,并单击 "下一步"。 9. 在配置文件对话框中,选择适用于您的网络配置的配置文件,并单击 "下一步"。 10. 在名称对话框中,为规则提供一个名称和(可选)描述,并单击 "完成" 完成规则的创建。 您可以按照相同的步骤创建一个出站规则来过滤外出ICMP timestamp 回复报文。只需在步骤 2 中选择 "出站规则" 选项,然后按照类似的步骤创建规则即可。 请注意,具体的步骤可能会因 Windows 版本而有所不同,上述步骤是基于 Windows 10 的。如果您使用的是其他版本的 Windows,可能会有一些细微差异。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

攻城狮白玉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值