centos - firewalld で ICMP タイムスタンプとタイムスタンプ応答をブロックする

firewalld には、直接使用できる事前定義された ICMP タイプのデフォルト セットが付属しています。

# firewall-cmd --get-icmptypes
destination-unreachable echo-reply echo-request parameter-problem redirect router-advertisement router-solicitation source-quench time-exceeded timestamp-reply timestamp-request

ただし、parser( /usr/lib/python2.7/site-packages/firewall/core/io/icmptype.py) はこれらの型に限定されず、次のように拡張できます。

まず、man iptables-extensions(8) セクション icmp に従います。

icmp (IPv4 固有) この拡張機能は、「--protocol icmp」が指定されている場合に使用できます。次のオプションが提供されます。

  [!] --icmp-type {
    
    type[/code]|typename}
          This allows specification of the ICMP type, which can be a numeric ICMP type, type/code pair, or one of the ICMP type names shown by the command
           iptables -p icmp -h

icmp6 (IPv6 固有) この拡張機能は、--protocol ipv6-icmp' または --protocol icmpv6' が指定されている場合に使用できます。次のオプションが提供されます。

  [!] --icmpv6-type type[/code]|typename
          This allows specification of the ICMPv6 type, which can be a numeric ICMPv6 type, type and code, or one of the ICMPv6 type names shown by the command
           ip6tables -p ipv6-icmp -h

あなたが参照している 2 つのタイプは IPv4 固有であるため、次を使用して iptables によって認識される適切な名前を見つける必要があります。

# iptables -p icmp -h | grep timestamp
timestamp-request
timestamp-reply

ここで、firewalld パッケージの内容を確認すると、事前定義された ICMP タイプが保存されている場所がわかります。

# rpm -ql firewalld | grep icmptype
/etc/firewalld/icmptypes
/usr/lib/firewalld/icmptypes/destination-unreachable.xml
/usr/lib/firewalld/icmptypes/echo-reply.xml
/usr/lib/firewalld/icmptypes/echo-request.xml
/usr/lib/firewalld/icmptypes/parameter-problem.xml
/usr/lib/firewalld/icmptypes/redirect.xml
/usr/lib/firewalld/icmptypes/router-advertisement.xml
/usr/lib/firewalld/icmptypes/router-solicitation.xml
/usr/lib/firewalld/icmptypes/source-quench.xml
/usr/lib/firewalld/icmptypes/time-exceeded.xml
/usr/lib/firewalld/xmlschema/icmptype.xsd
/usr/share/man/man5/firewalld.icmptype.5.gz

上記で参照したパーサーを確認すると、iptables と通信するときに XML ファイル名を ICMP タイプとして使用していることがわかります。そのため、使用する ICMP タイプに対して、使用する ICMP タイプを使用して 2 つの新しいファイルを作成する必要があります。上で見つかりました。ユーザーが作成した ICMP タイプは /etc/firewalld/icmptypes に保存する必要があります。

# cat timestamp-request.xml
<?xml version="1.0" encoding="utf-8"?>
<icmptype>
  <short>Timestamp Request</short>
  <description>This message is used for time synchronization.</description>
  <destination ipv4="yes"/>
  <destination ipv6="no"/>
</icmptype>
# cat timestamp-reply.xml
<?xml version="1.0" encoding="utf-8"?>
<icmptype>
  <short>Timestamp Reply</short>
  <description>This message is used to reply to a timestamp message.</description>
  <destination ipv4="yes"/>
  <destination ipv6="no"/>
</icmptype>

最終的には次のようになります。

# ll -Z /etc/firewalld/icmptypes
-rw-r--r--. root root system_u:object_r:firewalld_etc_rw_t:s0 timestamp-reply.xml
-rw-r--r--. root root system_u:object_r:firewalld_etc_rw_t:s0 timestamp-request.xml

提供された XSD を使用してそれらを検証します。

# xmllint --schema /usr/lib/firewalld/xmlschema/icmptype.xsd timestamp-request.xml
timestamp-request.xml validates
# xmllint --noout --schema /usr/lib/firewalld/xmlschema/icmptype.xsd timestamp-reply.xml

timestamp-reply.xml は
ファイアウォールのリロードを検証します。

# firewall-cmd --reload

最後にそれらを追加します。

# firewall-cmd --add-icmp-block=timestamp-request
# firewall-cmd --add-icmp-block=timestamp-reply

# firewall-cmd --list-icmp-blocks

timestamp-reply timestamp-request
iptables でルールを直接調べて、追加されているかどうかを確認できます。

iptables -nvL | grep icmp
0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0
0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
0     0 REJECT     all  --  *      virbr0  0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable
0     0 REJECT     all  --  virbr0 *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable
0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0
0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited
0     0 REJECT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 13 reject-with icmp-host-prohibited
0     0 REJECT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 14 reject-with icmp-host-prohibited
0     0 REJECT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 13 reject-with icmp-host-prohibited
0     0 REJECT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 14 reject-with icmp-host-prohibited

タイプ 13 および 14 は、新しく追加された ICMP タイプです。

参考として、firewalld.icmptypes(5) マンページを参照してください。

これらの ICMP タイプはすでにアップストリームに含まれています。

おすすめ

転載: blog.csdn.net/lizhihua0625/article/details/124299192