iptables 和 libpcap
我已设置规则来丢弃具有匹配字符串的 udp/tcp 数据包。 然而,我的程序使用 libpcap 捕获数据包,仍然能够看到这个数据包。
为什么是这个/,在 libpcap 看到数据包之前丢弃数据包的 iptable 规则应该是什么?
无论如何,也许除了 iptables 规则之外,是否有在 libpcap/tcpdump 看到此数据包之前丢弃该数据包?
i have rule set up to drop udp/tcp packets with matching strings. however, my program which captures packet using libpcap, is still able to see this packet.
Why is this/, what should be the iptable rules to drop packets before it is seen by libpcap?
Is there anyway,perhaps other than iptables rules, to drop this packet before it is seen by libpcap/tcpdump?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,libpcap 可以看到所有数据包。。
它们在被网络过滤器处理之前被捕获。
Yes, libpcap sees all the packets..
They are being captured before being processed by the netfilter.
您是否尝试更改您使用的 netfilter 挂钩的优先级? 如果您尝试以最高优先级挂钩传入数据包,它将在数据包套接字内核代码之前获取数据包,这就是 libpcap 用于捕获数据包的方式。
* 我假设您使用的是 Linux *
编辑:
Libpcap 使用不同的方式来捕获数据包 - 根据操作系统。 在 Linux 上,它使用数据包套接字,该套接字是使用 netfilter 框架在内核代码中实现的。
Did you try to change the priority of the netfilter hook you use? if you try hooking with the highest priority for incoming packets, it will get the packet before the packet socket kernel code, which is the way libpcap uses to capture packets.
* I assume you are using linux *
EDIT:
Libpcap uses different ways to capture packets - according to the OS. on linux it uses packet socket which is implemented in kernel code using the netfilter framework.
libpcap 无法在 netfilter 之前看到数据包,netfilter 是一个内核模块,它会在所有数据包到达用户模式之前对其进行处理,它甚至可以在内核看到数据包之前看到数据包。
您能解释一下吗?
libpcap 也有可能在 netfilter 上设置挂钩,覆盖 iptables 中的挂钩。 真正的问题是,查看 netfilter 上设置的钩子绝非易事,而且只能在内核模式下完成。 研究 libpcap 如何获取数据包。
Theres no way for libpcap to see the packets before netfilter, netfilter is a kernel module, and processes all packets before they hit user mode, it can even see the packets before the kernel sees it.
Could you explain further explain ?
Its possible that libpcap is also setting hooks on netfilter that overwrite the one in iptables. The real issue is that looking and what hooks are set on netfilter is far from trivial, and can only be done in kernel mode. Investigate how libpcap gets the packets.