iptable规则在有效负载中丢弃具有特定子字符串的数据包

Kaz*_*oom 5 linux iptables linux-kernel

我试图编写规则来丢弃任何数据包,无论它是传出,传入还是被转发,它在TCP或UDP有效载荷中都有一个特定的子字符串.

我怎么想这样做?

And*_*mar 11

你需要一个使用Netfilter" String match support " 编译的内核.

然后你可以

iptables -A INPUT -m string --algo bm --string "test" -j DROP
iptables -A OUTPUT -m string --algo bm --string "test" -j DROP
iptables -A FORWARD -m string --algo bm --string "test" -j DROP
Run Code Online (Sandbox Code Playgroud)

检查结果

iptables -L
Run Code Online (Sandbox Code Playgroud)