- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在用 netfilter 的钩子(Hook)编写一些内核模块。钩子(Hook)函数:
uint main_hook(uint hooknum,
struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *) )
{
struct iphdr *ip;
struct udphdr *udp;
if (skb->protocol == htons(ETH_P_IP)){
ip = (struct iphdr *)skb->data;//skb_network_header(skb);
if (ip->version == 4 && ip->protocol == IPPROTO_UDP){
udp = (struct udphdr *)(skb->data + sizeof(struct iphdr));
printk("[udp-catch] packet from %d to %d\n", ntohs(udp->source), ntohs(udp->dest));
return NF_QUEUE;
}
}
return NF_ACCEPT;
}
我可以指定多个队列吗?如果没有,我怎样才能找到这个号码?
最佳答案
libnetfilter_queue 网页的函数文档:
创建队列时,num 的默认值为 0。
如果你有两个队列在同一台机器上运行,比如说一个发送IP数据包另一个接收,你需要创建两个不同编号的队列:
发送:
qh = nfq_create_queue(h, 0, &cb, NULL);
接收:
qh = nfq_create_queue(h, 1, &cb, NULL);
要正确过滤 IP 表,您应该指定 netfilter 队列号:
发件人:
sudo iptables -A OUTPUT -p all -d <dest ip> -j NFQUEUE --queue-num 0
接收者:
sudo iptables -A INPUT -p all -s <src ip> -d <dest ip> -j NFQUEUE --queue-num 1
您还可以查看 iptables 手册并搜索 NFQUEUE。
希望这能有所帮助。
关于c - netfilter 队列数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15389719/
如果传入数据包进入并在本地处理,是否有办法获得通知该事件? 我目前正在使用 NF_IP_LOCAL_IN Hook 。但看起来这会提供所有发往该接口(interface)的数据包。例如,假设 tcp
我目前正在尝试在用户空间中使用带有 libnetfilter_queue 的代码来修改在 iptables 的 NFQUEUE 目标中排队的数据包。但是,我不知道如何去做。 我已经将它设置为使用 NF
我正在构建一个简单的 Linux 防火墙,使用 netfilters 作为内核模块实现。我希望它能够进行深度数据包检查,为此我需要能够读取数据包的内容。我该如何继续这样做? 最佳答案 来自 netfi
在实现 netfiler Hook 时,我一直在尝试读取数据包内容。 我可以正确过滤 IP 字段或 TCP 字段,但是,出于好奇,我一直在尝试更进一步并显示应用程序级别有效负载的内容,但失败了。 我知
假设我从 Netfilter 拦截了一个数据包,随后返回 NF_STOLEN。在某些时候,我想将该数据包重新注入(inject)到它来自的 TCP 流中(在本例中)。我想从内核空间执行此操作。到目前为
我正在用 netfilter 的钩子(Hook)编写一些内核模块。钩子(Hook)函数: uint main_hook(uint hooknum, struct s
我正在编写一个内核模块,它需要在 IP 层进行一些数据包过滤工作。我需要做的是拦截所有 IP 数据包,并且在一些传出数据包上,我需要在发送它们之前将它们保留一小段时间(比如几十毫秒)进行分析。 我已经
任何人都可以指出一些将 xt_string 模块与 netfilter 结合使用的示例或提供示例。我想做的是编写 netfilter 模块,它将丢弃在 skb->data 字段中包含特定字符串的数据包
我想写一个Linux 2.6 netfilter module,可以检查传入的IP包信息,比如目标IP,源IP。之后将这些信息传递给 user space 应用程序,该应用程序(即 Socket 应用
我有一个基本代码。此代码丢弃并记录所有传入和传出的数据包。我想写一个 netfilter 内核模块来拦截数据包并将它们记录在内核日志中。它应该能够检测不同的(以 1 或 2 为例)基于 TCP 的侦察
我想在端口 80 上捕获所有要发送到转发地址的 tcp 数据包,并将它们传递给用户空间程序进行修改。我知道如何使用 IPtables 规则来做到这一点,例如 iptables -A FORWARD .
NF_INET_LOCAL_OUT 钩子(Hook)的 skb->sk 指向发送数据包的套接字的 struct sock。是否有一个钩子(Hook)为接收数据包的套接字设置了它?在 NF_INET_L
我正在研究内核模块中的 netfilter Hook 。我希望能够捕获由 scapy 创建的数据包。 钩子(Hook)以及通过 scapy 生成的数据包都在同一台物理主机上运行。似乎没有可用的 net
我希望能够在收到数据包时将其分成两个数据包(ip header 中的两个不同目的地)并将其传回 netfilter。如果有帮助,我正在使用 C++。 这有可能吗? 谢谢 最佳答案 我发现最好的方法是通
如何在内核模块中编译多个文件(文件调用其他文件中的函数)? 最佳答案 我将你的问题解释为,你想将多个编译单元链接到一个模块中? 在内核源代码中有很多这样的例子;它的一般要点是像这样编写 Makefil
我想把所有的流量封装在UDP中。我已经可以捕获它并转发了。但是现在我想做封装。对于此任务,我需要以原始形式获取完整数据包。但是我该怎么做呢?我的代码是 while ((rv = recv(fd, bu
谁能告诉我如何使用 Netfilter Hook 通过 linux 模块修改数据包数据? 谢谢! 最佳答案 不必编写自己的 netfilter 模块。您可以使用 iptables 中的 QUEUE 目
我在 Ubuntu 14.10 上使用 netfilter 队列。到目前为止一切正常,我看到了数据包并设置了判断,但我想更好地了解我从队列中读取的内容。 从此page开始. 这是有问题的代码: fd
我正在使用 Linux 4.13.x。我正在考虑在内核中发送数据包响应。 考虑在用户空间中运行的回显 TCP 或 UDP 服务器,还有另一个节点运行 TCP 或 UDP 客户端。客户端正在向服务器发送
请看代码片段 char ipAddr[] = {192, 168, 88, 2}; struct iphdr *ip_hdr = (struct iphdr*)(some_valid_eth_hdr_
我是一名优秀的程序员,十分优秀!