andy_ker 2014-12-28 08:07 采纳率: 50%
浏览 4414
已采纳

netfilter钩子拦截数据包获取数据包源MAC地址

本人大学生,最近在研究arp防火墙,想实现主机拦截从本机出去发送的所有数据包,获取其源mac地址,以防止主机欺骗.在网上大量调研后采用了netfilter钩子来实现截获数据包,但是在加载内核模块时出现了问题.因为之前没有接触过网络和内核,只能在几天的时间里自学了一下.所以问题比较多.现在贴出我的程序和makefile文件请大神帮忙解答!!小弟感谢不尽,这次开发对我真的很重要哈,但毕竟本人能力有限,先谢谢大家了!

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

//static char *in_dev="eth0";
//MOUDLE_PARM(in_dev,"s");
static struct nf_hook_ops nfho;
//module_init(pack_init);

unsigned int hook_func(unsigned int hooknum,struct sk_buff **skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *))
{
// struct sk_buff *nskb;//mac地址通过网上给的方法无法获取,所以直接执行DROP
// struct ethhdr *eth;

// nskb=*skb;
// eth=(struct ethhdr*)(nskb->mac.raw);
// printk("src mac:");
// printk("%02x",eth_hdr->h_source);
// printk("\n");

// switch(mac)
// {
// case 111111111111 :
return NF_DROP;
// default:
// return NF_DROP;
// }
}

int init_hook(void)
{
nfho.hook=hook_func;
nfho.hooknum=NF_INET_POST_ROUTING;
nfho.pf=PF_INET;
nfho.priority=NF_IP_PRI_FIRST;
nf_register_hook(&nfho);
return 0;
}
void cleanup_module()
{
nf_unregister_hook(&nfho);
}

makefile:
obj-m :=hook.o

KERNELDIR :=/lib/modules/uname -r/build

PWD :=$(shell pwd)
default:

make -C ${KERNELDIR} M=${PWD} modules

clean:

rm -f .o *.ko *.mod.c *.mod.o modules. Module.*

现在有三个问题:
1、模块加载成功后没有实现DROP的效果,主机还是可以上网。
2、模块无法卸载。执行一次rmmod显示杀死成功,但是还是可以grep到。
3、网上的方法已经无法实现获取数据包源mac地址,因为后来内核中取消了ethhdr结构体。求解决办法。

  • 写回答

4条回答 默认 最新

  • threenewbee 2014-12-28 08:11
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器