Changeset 427

Show
Ignore:
Timestamp:
03/25/06 23:18:56 (3 years ago)
Author:
common
Message:

shellcode-signatures
- formatting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/modules/shellcode-signatures/sch_namespace_xor.cpp

    r426 r427  
    2626 *******************************************************************************/ 
    2727 
    28  /* $Id$ */ 
     28/* $Id$ */ 
    2929 
    3030#include "sch_namespace_xor.hpp" 
     
    3939 
    4040#ifdef STDTAGS  
    41 #undef STDTAGS  
     41       #undef STDTAGS  
    4242#endif 
    4343#define STDTAGS l_sc | l_hlr 
     
    5252 
    5353        m_Shellcode = sc; 
    54          
     54 
    5555} 
    5656 
     
    6969                                m_ShellcodeHandlerName.c_str(), pcreEerror, pcreErrorPos); 
    7070                return false; 
    71         }else 
     71        } else 
    7272        { 
    7373                logInfo("%s loaded ...\n",m_ShellcodeHandlerName.c_str()); 
     
    9595 
    9696// data before xor 
    97         const char  *preMatch  =       NULL; 
    98         uint32_t       preSize         =       0; 
     97        const char  *preMatch   =   NULL; 
     98        uint32_t    preSize     =   0; 
    9999 
    100100 
    101101// data before xor 
    102         const char  *decoderMatch=     NULL; 
    103         uint32_t       decoderSize     =       0; 
     102        const char  *decoderMatch= NULL; 
     103        uint32_t    decoderSize =   0; 
    104104 
    105105 
    106106 
    107107// key 
    108         const char  *keyMatch  =       NULL; 
    109         char           byteKey         =       0; 
    110         uint32_t       intKey          =       0; 
    111         uint32_t       keySize         =       0; 
     108        const char  *keyMatch   =   NULL; 
     109        char        byteKey     =   0; 
     110        uint32_t    intKey      =   0; 
     111        uint32_t    keySize     =   0; 
    112112 
    113113 
    114114// 'data to xor' size 
    115         const char  *sizeMatch =       NULL; 
    116         uint32_t       codeSize        =       0; 
     115        const char  *sizeMatch  =   NULL; 
     116        uint32_t    codeSize    =   0; 
    117117 
    118118 
    119119// data after xor 
    120         const char  *postMatch =       NULL; 
    121         uint32_t       postSize        =       0; 
     120        const char  *postMatch  =   NULL; 
     121        uint32_t    postSize    =   0; 
    122122 
    123123 
     
    133133                        int matchSize = pcre_get_substring((char *) shellcode, (int *)ovec, (int)matchCount, i, &match); 
    134134 
    135                         switch (m_Shellcode->map[i]
     135                        switch ( m_Shellcode->map[i]
    136136                        { 
    137  
     137                         
    138138                        case sc_pre: 
    139139                                preMatch = match; 
     
    144144                                decoderMatch = match; 
    145145                                decoderSize = matchSize; 
    146                 break; 
     146                               break; 
    147147 
    148148 
    149149                        case sc_size: 
    150150                                sizeMatch = match; 
    151                 switch ( matchSize ) 
     151                               switch ( matchSize ) 
    152152                                { 
    153153                                case 4: 
     
    162162                                        break; 
    163163                                } 
    164                 break; 
     164                               break; 
    165165 
    166166 
     
    177177                                        break; 
    178178                                } 
    179                 break; 
     179                               break; 
    180180 
    181181                        case sc_key: 
     
    193193 
    194194                                } 
    195                 break; 
     195                               break; 
    196196 
    197197                        case sc_post: 
     
    209209                memcpy(decodedMessage, postMatch, postSize); 
    210210 
    211                 switch (keySize
     211                switch ( keySize
    212212                { 
    213213                case 1: 
    214                         if( codeSize > postSize ) 
     214                        if ( codeSize > postSize ) 
    215215                                logWarn("codeSize (%i) > postSize (%i), maybe broken xor?\n",codeSize,postSize); 
    216216 
    217                         for( uint32_t j = 0; j < codeSize && j < postSize; j++ ) 
     217                        for ( uint32_t j = 0; j < codeSize && j < postSize; j++ ) 
    218218                                decodedMessage[j] ^= byteKey; 
    219219                        break; 
    220220 
    221221                case 4: 
    222                         if( codeSize*4 > postSize ) 
     222                        if ( codeSize*4 > postSize ) 
    223223                                logWarn("codeSize*4 (%i) > postSize (%i), maybe broken xor?\n",codeSize*4,postSize); 
    224224 
    225                         for( uint32_t j = 0; j < codeSize && (j+1)*4 < postSize; j++ ) 
     225                        for ( uint32_t j = 0; j < codeSize && (j+1)*4 < postSize; j++ ) 
    226226                                *(uint32_t *)(decodedMessage+(j*4) ) ^= intKey; 
    227227                        break; 
     
    234234 
    235235                // the pre section 
    236                 memcpy(newshellcode                                                    ,preMatch               ,preSize); 
     236                memcpy(newshellcode                         ,preMatch       ,preSize); 
    237237 
    238238                // the xor as 0x90  
    239                 memset(newshellcode+preSize                                    ,0x90                   ,decoderSize); 
     239                memset(newshellcode+preSize                 ,0x90           ,decoderSize); 
    240240 
    241241                // the xor decoded data 
    242                 memcpy(newshellcode+preSize+decoderSize                ,decodedMessage ,postSize); 
     242                memcpy(newshellcode+preSize+decoderSize     ,decodedMessage ,postSize); 
    243243 
    244244                Message *newMessage = new Message((char *)newshellcode, len, (*msg)->getLocalPort(), (*msg)->getRemotePort(), 
    245                           (*msg)->getLocalHost(), (*msg)->getRemoteHost(), (*msg)->getResponder(), (*msg)->getSocket()); 
     245                                                                                 (*msg)->getLocalHost(), (*msg)->getRemoteHost(), (*msg)->getResponder(), (*msg)->getSocket()); 
    246246 
    247247                delete *msg;