论坛: 编程破解 标题: 中看不中用的firewall 复制本贴地址    
作者: cimsxiyang [cimsxiyang]    版主   登录
/*该程序没有什么实际价值,但是,用来学习还是可以的*/
这个程序的主要作用是:阻挡别人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 */ 


地主 发表时间: 04/15 20:27

回复: icesky [icesky]   论坛用户   登录
我有事!去我那!

B1层 发表时间: 04/15 20:33

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号