Changeset 144 for trunk

Show
Ignore:
Timestamp:
12/21/10 16:01:36 (12 years ago)
Author:
andreu
Message:

DoS detection - detection in core (todo: email notification with renetcolSEC module)

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/dataFlowSet.c

    r127 r144  
    5858  int j = 0; 
    5959  int pos = 0; 
     60        int jdos = 0; 
     61        int posdos = 0; 
    6062  unsigned char buffer1;   
    6163  unsigned char buffer2[2]; 
     
    7577#endif 
    7678  struct AggCache agCache; 
     79        struct DoSCache dosCache; 
    7780  int bool = 0; /* in IPV4 Agg mode enabled, we need to now if it's an IPv4 */ 
    7881  int isIPv6 = 0; 
     
    330333                agCache.bytes = *((unsigned long*)&buffer4); 
    331334                if ( 
    332                     ((unsigned long)((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue) + ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)*10/100)) 
     335                    ((unsigned long)((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue) + ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)/5)) 
    333336                     >= (*((unsigned long*)&buffer4))) 
    334337                    && 
    335                     ( (unsigned long)((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue) - ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)*10/100)) 
     338                    ( (unsigned long)((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue) - ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)/5)) 
    336339                      <= (*((unsigned long*)&buffer4)) ) 
    337340                    ) 
     
    339342                    ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1; 
    340343                  } 
    341               } 
     344                                } 
    342345#if defined(IPV4AGGIDR) || defined(IPV4AGGIDSNMP) 
    343346              if (pftmp->fieldType==10){ 
     
    369372              } 
    370373#endif 
     374              if (pftmp->fieldType==1){ 
     375                      dosCache.bytes = *((unsigned long*)&buffer4); 
     376                                        dosCache.sampling = *myPtrs->currentRouterPtr->sampled; 
     377              } 
     378              if (pftmp->fieldType==2){ 
     379                      dosCache.pkts = *((unsigned long*)&buffer4); 
     380                                } 
    371381              break; 
    372382            case 16: 
     
    633643          } 
    634644#endif 
     645                if (pftmp->fieldType==1){ 
     646            dosCache.bytes = *((unsigned long*)&buffer4); 
     647                        dosCache.sampling = *myPtrs->currentRouterPtr->sampled; 
     648          }  
     649                if (pftmp->fieldType==2){ 
     650            dosCache.pkts = *((unsigned long*)&buffer4); 
     651          } 
    635652          break; 
    636653        case 16: 
     
    14261443        } 
    14271444        isMplsFlow = 0; 
     1445 
     1446        /* DoS DETECTION */ 
     1447        if ( ( dosCache.packets*dosCache.sampling > MAX_PKTS_DOS )   
     1448                  && ((dosCache.packets)/(dosCache.bytes) < RATIO_DOS ) ) { 
     1449                                jdos = 0; 
     1450        posdos = 69*MAX_RULES_PER_FIELD+jdos; 
     1451        while ( ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+jdos))) != NULL ) { 
     1452                                        ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+posdos)))->check = 1; 
     1453                                        jdos++; 
     1454                                } 
     1455        } 
     1456 
    14281457        /*  
    14291458         * 
     
    14651494                                                   &tmp->sourceId,  
    14661495                                                   sizeof(unsigned long)  
    1467                                                    ),  
    1468                                            &tmp->templateFlowSetId,  
    1469                                            sizeof(tmp->templateFlowSetId)  
    1470                                            ),  
    1471                                    myPtrs->ptr_buffer+secondOffset,  
     1496                                                   ), 
     1497                                           &tmp->templateFlowSetId, 
     1498                                           sizeof(tmp->templateFlowSetId) 
     1499                                           ), 
     1500                                   myPtrs->ptr_buffer+secondOffset, 
    14721501                                   flow_size 
    14731502                                   );  
  • trunk/src/dataFlowSet.h

    r127 r144  
    9595}; 
    9696 
     97struct DoSCache { 
     98  unsigned long bytes; 
     99        unsigned long pkts; 
     100        unsigned long sampling; 
     101} 
    97102 
    98103short  
  • trunk/src/renetcolParam.h

    r128 r144  
    7373#define MAX_IPV6_PREFIX 500 
    7474#define MAX_IPV6_SUBNET 100 
     75 
     76#define MAX_PKTS_DOS 30000      /* dos threshold */ 
     77#define RATIO_DOS 200   /* packets average size */ 
     78#define RATIO_FIELD 69  /* field 69 is a "reserved" field who is not used actualy. */ 
    7579 
    7680/*  
  • trunk/src/renetcolSender.c

    r127 r144  
    252252      close (listenSock); 
    253253      todo(clientSock, remoteHost); 
    254       if (!(pidFile = fopen("/tmp/pidrenetcol.tmp", "r"))) { 
    255         syslog (LOG_ERR, "error during /tmp/pidrenetcol.tmp opening : %s\n", 
     254      if (!(pidFile = fopen("/var/run/renetcol.pid", "r"))) { 
     255        syslog (LOG_ERR, "error during /var/run/renetcol.pid opening : %s\n", 
    256256                strerror(errno)); 
    257257        exit(1); 
     
    404404      buffer4[3]= *(myText+i); i++; 
    405405      renetcolPID = *((pid_t *)&buffer4); 
    406       if (!(pidFile = fopen("/tmp/pidrenetcol.tmp", "w"))) { 
    407         syslog (LOG_ERR, "error during /tmp/pidrenetcol.tmp opening : %s\n", 
     406      if (!(pidFile = fopen("/var/run/renetcol.pid", "w"))) { 
     407        syslog (LOG_ERR, "error during /var/run/renetcol.pid opening : %s\n", 
    408408                strerror(errno)); 
    409409        exit(1); 
  • trunk/web/inf/thks.php

    r141 r144  
    33print " <div id=\"contenu\"> <p> Thanks to : \n"; 
    44print "<ul>"; 
     5print "<li> Dany Vandromme (director of RENATER) and Franck SIMON (RENATER CTO 2007-2009). </li>"; 
    56print "<li> CERT RENATER (for his daily usage of renetcolGUI)</li>"; 
    67print "<li> Anthony Fisson (for the syslog section and many discussions about parallel computing options)</li>";