bounty还有2天到期。回答此问题可获得+100声望奖励。goodman希望引起更多关注这个问题。
我正试图在我的Linux机器上实现一个过滤不同层协议的迷你防火墙。到目前为止,我已经成功地使用Netfilter将数据包过滤到TCP层。然而,我现在正在尝试过滤应用程序协议(深度数据包检测),我面临着问题。
我尝试使用Netfilter来解析TCP/UDP有效载荷,但我无法获得数据包的内容,它总是将有效载荷显示为0,但在Wireshark中我可以看到一些数据。我想在数据包进入应用层之前对其进行过滤。
除了Netfilter之外,在Linux中是否还有其他方法可以用来过滤应用程序协议?
我试图获取HTTP数据的程序:Unable to parse HTTP packet using netfilter hooks in kernel module
2条答案
按热度按时间9cbw7uwe1#
我使用C语言中的
libpcap
来测试和编写这段代码,以捕获和过滤HTTP数据包。在Linux(Ubuntu 20.04)首先安装libpcap:
下面是一个例子:
注:
我勾选
ifconfig -a
,把wlp5s0,你可以添加eth0或其他。nzk0hqpo2#
我发现Wireshark能够解码HTTP数据包,这解释了为什么我可以在Wireshark中查看HTTP内容,但在我的程序中无法查看。因此,我将尝试从我的程序中解码HTTP,并更新代码以打印HTTP数据。
程序输出
wireshark日志: