如何停止发送 ICMP 时间戳回复和请求?

如何停止发送 ICMP 时间戳回复和请求?

哇,进步了!下面更新了!我一直在互联网上寻找这个问题的答案。我使用的是运行 Raspbian Debian 11 的 Raspberry Pi。问题似乎相当简单,只是阻止 ICMP 时间戳请求和回复,但经过数小时的网页浏览和尝试 3 种不同的解决方案后,它们都没有奏效。我试过:

  • 使用 ipchains,但现在已经过时了,所以我寻找如何使用 iptables 来代替。我发现本教程建议使用iptables -I INPUT -p icmp --icmp-type timestamp-request -j DROP,但会出现错误iptables v1.8.7 (nf_tables): unknown option "--icmp-type"
  • 显然 nftables 是 iptables 的更新版本,因此我尝试执行以下操作并使用:
nft add table ip filter # create table. I would have needed to enter this, but the table was already created so I didn't have to. 
nft add chain ip filter INPUT { type filter hook input priority 0 \; } # create chain
nft insert rule ip filter INPUT icmp type timestamp-request counter drop
nft insert rule ip filter INPUT icmp type timestamp-reply counter drop
sudo systemctl start nftables
sudo systemctl enable nftables
#backup your old /etc/nftables.conf file first before continuing
sudo nft list ruleset > /etc/nftables.conf

  • 我尝试将行添加net.ipv4.tcp_timestamps = 0到 /etc/sysctl.conf 中,因为我看到这里

我的完整 /etc/nftables.conf 如下所示:

#!/usr/sbin/nft -f
flush ruleset

table ip nat {
        chain POSTROUTING {
                type nat hook postrouting priority srcnat; policy accept;
                ip saddr 10.0.0.0/24 ip daddr != 10.0.0.0/24 counter packets 0 bytes 0 masquerade
                oifname "wlan0" counter packets 0 bytes 0 masquerade
        }
}
table ip filter {
        chain FORWARD {
                type filter hook forward priority filter; policy accept;
                iifname "wlan0" oifname "uap0" ct state related,established counter packets 0 bytes 0 accept
                iifname "uap0" oifname "wlan0" counter packets 0 bytes 0 accept
        }

        chain INPUT {
                type filter hook input priority filter; policy accept;
                icmp type timestamp-reply counter packets 0 bytes 0 drop
                icmp type timestamp-request counter packets 0 bytes 0 drop
        }
}

还是没运气。如何阻止或禁用我的系统回复时间戳?

编辑:为了测试 Pi 是否会响应时间戳请求,我运行nmap -v -v -v -PP 10.6.74.84,其中 10.6.74.84 是 Pi 的 IP,然后我在结果中查找“主机已启动,收到时间戳答复 ttl 63(0.0057 秒延迟)。”。

并且取得突破!/etc/nftables.conf 与上文相同,但运行sudo nft list ruleset会打印:

table ip nat {
        chain POSTROUTING {
                type nat hook postrouting priority srcnat; policy accept;
                ip saddr 10.0.0.0/24 ip daddr != 10.0.0.0/24 counter packets 0 bytes 0 masquerade
                oifname "wlan0" counter packets 0 bytes 0 masquerade
        }
}
table ip filter {
        chain FORWARD {
                type filter hook forward priority filter; policy accept;
                iifname "wlan0" oifname "uap0" ct state related,established counter packets 0 bytes 0 accept
                iifname "uap0" oifname "wlan0" counter packets 0 bytes 0 accept
        }

        chain INPUT {
                type filter hook input priority filter; policy accept;
        }
}

不一样!少了几行!所以规则集没有更新以匹配 .conf 文件中的最新版本,还是其他原因?打算做一些研究。

相关内容