syn flood攻击算法的c语言实现

#ifndef   _KERNEL_  
  #define   _KENNEL_  
  #endif  
  #ifndef   MODULE  
  #define   MODULE  
  #endif  
  #include   <linux/module.h>  
  #include   <linux/skbuff.h>  
  #include   <linux/netdevice.h>  
  #include   <linux/config.h>  
  #include   <linux/ip.h>  
  #include   <linux/tcp.h>  
  #include   <linux/udp.h>  
  #include   <linux/netfilter_ipv4.h>  
  struct  
    {  
      struct   timeval   time;  
      __u8   nNUM;  
      u_int32   ipaddr;  
      u_int16   port;  
    }IP_FILTER_TAB[5000];  
  struct  
    {  
      struct   timeval   time;  
      u_int32   ipaddr;  
    }IP_OUT_TAB[100];  
   
  static   unsigned   int   my_firewall(unsigned   int   hooknum,struct   sk_buff   **   skb,const   struct   net_device   *in,const   struct   net_device   *out,int(*okfn)(struct   sk_buff   *))  
  {  
  struct   iphdr   *iph;  
  struct   tcphdr   *tcph;  
  struct   udphdr   *udph;  
  __u32   sip;  
  __u32   dip;  
  __u16   sport;  
  __u16   dport;  
  /*取出IP头,源IP地址,目的IP地址*/  
  iph=(*skb)->nh.iph;  
  sip=iph->saddr;  
  dip=iph->daddr;  
  /*如果是TCP协议*/  
  if(iph->protocol==6){  
        tcph=(struct   tcphdr*)((__u32   *)iph+iph->ihl);  
        sport=tcph->source;  
        dport=tcph->dest;  
        /*防止land攻击*/  
        if((tcph->syn)&&(sport==dport)&&(sip==dip)){  
        printk("maybe   land   attack/n");  
        /*抵御syn   flood攻击模块*/  
   
         
     
        }  
   
  }  
   
   
  }  
  static   struct   nf_hook_ops   iplimitfilter=  
  {  
      {NULL,NULL},  
        my_firewall,  
        PF_INET,  
        NF_IP_LOCAL_IN,  
        NF_IP_LOCAL_OUT,  
        NF_IP_PRI_FILTER-1  
  };  
  int   init_module(void)  
    {  
      return   nf_register_hook(&iplimitfilter);  
    }  
  void   cleanup_module(void)  
  {  
      nf_unregister_hook(&iplimitfilter);  
  }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值