除了上面所说的以外,还可以通过检查iptables规则来推断将要记录的内容。具体来说,可以像这样过滤正在记录的匹配规则sudo iptables -L | grep -i "log"
:
ufw-before-logging-input all -- anywhere anywhere
ufw-after-logging-input all -- anywhere anywhere
ufw-before-logging-forward all -- anywhere anywhere
ufw-after-logging-forward all -- anywhere anywhere
ufw-before-logging-output all -- anywhere anywhere
ufw-after-logging-output all -- anywhere anywhere
Chain ufw-after-logging-forward (1 references)
LOG all -- anywhere anywhere limit: avg 3/min burst 10 LOG level warning prefix "[UFW BLOCK] "
Chain ufw-after-logging-input (1 references)
LOG all -- anywhere anywhere limit: avg 3/min burst 10 LOG level warning prefix "[UFW ALLOW] "
Chain ufw-after-logging-output (1 references)
LOG all -- anywhere anywhere limit: avg 3/min burst 10 LOG level warning prefix "[UFW ALLOW] "
ufw-logging-deny all -- anywhere anywhere ctstate INVALID
Chain ufw-before-logging-forward (1 references)
LOG all -- anywhere anywhere ctstate NEW limit: avg 3/min burst 10 LOG level warning prefix "[UFW AUDIT] "
Chain ufw-before-logging-input (1 references)
LOG all -- anywhere anywhere ctstate NEW limit: avg 3/min burst 10 LOG level warning prefix "[UFW AUDIT] "
Chain ufw-before-logging-output (1 references)
LOG all -- anywhere anywhere ctstate NEW limit: avg 3/min burst 10 LOG level warning prefix "[UFW AUDIT] "
Chain ufw-logging-allow (0 references)
LOG all -- anywhere anywhere limit: avg 3/min burst 10 LOG level warning prefix "[UFW ALLOW] "
Chain ufw-logging-deny (2 references)
LOG all -- anywhere anywhere ctstate INVALID limit: avg 3/min burst 10 LOG level warning prefix "[UFW AUDIT INVALID] "
LOG all -- anywhere anywhere limit: avg 3/min burst 10 LOG level warning prefix "[UFW BLOCK] "
ufw-logging-deny all -- anywhere anywhere limit: avg 3/min burst 10
LOG all -- anywhere anywhere limit: avg 3/min burst 5 LOG level warning prefix "[UFW LIMIT BLOCK] "
Chain ufw-user-logging-forward (0 references)
Chain ufw-user-logging-input (0 references)
Chain ufw-user-logging-output (1 references)
这些大部分是默认规则。检查上面的输出会显示ufw-before-*
生成[UFW AUDIT ..]日志的链。
我不是iptables的专家,UFW手册对此没有很大帮助,但据我所知,与此链匹配的规则位于/etc/ufw/before.rules中。
例如,以下各行允许进行环回连接,这可能会触发日志中的最后两行示例(以[UFW AUDIT] IN = lo开头的行)
# rules.before
# ....
# allow all on loopback
-A ufw-before-input -i lo -j ACCEPT
-A ufw-before-output -o lo -j ACCEPT
# ....
就我而言,我在端口5353上收到了许多已记录的LLMNR数据包:
Mar 17 21:02:21 pc kernel: [133419.183616] [UFW AUDIT] IN=wlp2s0 OUT= MAC= SRC=192.168.1.2 DST=224.0.0.251 LEN=146 TOS=0x00 PREC=0x00 TTL=255 ID=22456 DF PROTO=UDP SPT=5353 DPT=5353 LEN=126
我认为是由以下原因引起的rules.before
:
# allow MULTICAST mDNS for service discovery (be sure the MULTICAST line above
# is uncommented)
-A ufw-before-input -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT
停用这些功能的一种方法是执行以下操作:
sudo ufw deny 5353