| 您的位置:首页 > 文档 > 编程技术 > |
文章分类热门文章 |
让别人ping不到你,你却可以ping到别人!创建:2005-10-28 00:00:00 作者:Unlinux 来自: http://www.Unlinux.com 听到otto老大说‘可以一次增加3分’,我就......嘿嘿...... 当然,这个程序其实很简单,希望高手们能把自己的心得体会给我们分享分享。 看这个程序你需要一点儿TCP/IP底层的知识,可以用作学习LKM编程的入门测试程序。 这个程序最开始是我在学习绿盟的文章时写的: http://magazine.nsfocus.com/detail.asp?id=636 看完这篇文章,我就写了一个自己的小防火墙。我在内核版本为 2.2.14 和 2.4.2 上可以成功编译运行。这个程序的主要作用是:阻挡别人ping你的IP包,你ping别人的IP包却可以通过。这样别人就无法ping到你,你却可以ping到别人! 我想基本上内核为 2.2.x 和 2.4.x 的都可以兼容。 如下: /* * File : li_filter.c writen by kunlong * Kernel : 2.2.16 or 2.2.14 or 2.4.2 * Complie : gcc -O3 -c li_filter.c * Usage : insmod li_filter.o -f * Date : 2001-06-28 */ #ifndef __KERNEL__ #define __KERNEL__ #endif #ifndef MODULE #define MODULE #endif #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/version.h> #include <linux/netdevice.h> #include <linux/if_ether.h> #include <linux/if_packet.h> #include <linux/skbuff.h> #include <linux/ip.h> #include <linux/icmp.h> #include <linux/in.h> #ifndef KERNEL_VERSION #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) #endif #if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,0) #include <asm/uaccess.h> #endif static struct device * filter_dev = NULL; static char * dev = NULL; /* 定义insmod命令行参数 */ #if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,0) MODULE_PARM( dev, "s" ); #endif int filter_rcv ( struct sk_buff * skb, struct device * dv, struct packet_type * pt ) { /* 注意pkt_type是什么 */ if ( ( skb->pkt_type == PACKET_HOST ) && ( skb->protocol == __constant_htons( ETH_P_IP) ) ) { if ( ( skb->nh.iph->version == 4 ) && ( skb->nh.iph->protocol == IPPROTO_ICMP ) ) /* 不考虑ipv6 */ { skb->h.raw = skb->nh.raw + ( skb->nh.iph->ihl << 2 ); if ( skb->h.icmph->type == 8 ) { unsigned char *saddr = &(skb->nh.iph->saddr); printk("<1>--- ping from: %d.%d.%d.%d ---n", *saddr,*(saddr+1),*(saddr+2),*(saddr+3)); skb->h.icmph->checksum += 1; // Change the checksum, then this IP packet will be Ignored. } } } kfree_skb( skb ); return( 0 ); } /* end of filter_rcv */ static struct packet_type filter_packet_type = { __constant_htons( ETH_P_ALL ), /* 此时可以接收到来自lo的回送报文,比如本机发送出去的 */ NULL, /* All devices */ filter_rcv, NULL, /* 如果是2.4内核,这里可以考虑设置成非零,但是filter_rcv需要改变 */ NULL, }; int init_module ( void ) /* 模块初始化 */ { if ( dev != NULL ) { filter_dev = dev_get( dev ); if ( filter_dev != NULL ) { filter_packet_type.dev = filter_dev; } } dev_add_pack( &filter_packet_type ); EXPORT_NO_SYMBOLS; return( 0 ); } /* end of init_module */ void cleanup_module ( void ) /* 模块卸载 */ { dev_remove_pack( &filter_packet_type ); return; } /* end of cleanup_module */ 嘿嘿,怎么样,还可以吧?...... ......哎哟......谁?!下次上网不许带臭鸡蛋...... ......哎哟............哎哟......西红柿也不行...... 转载自:http://www.unlinux.com/doc/program/20051106/7993.html 【评论】 【加入收藏夹】 【大 中 小】 【打印】 【关闭】 ※ 相关链接 无相关信息 |