Changeset 422

Show
Ignore:
Timestamp:
03/25/06 20:32:38 (3 years ago)
Author:
dp
Message:

shellcode-signatures:

  • add the shellcode-interface
  • provide Makefile.parser for manual parser rebuildung
  • add flex/bison stuff to Makefile.am
  • should work now
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/modules/shellcode-signatures/Makefile.am

    r419 r422  
    1212 
    1313 
    14 BUILD_SOURCES = parser.c 
    15  
    1614shellcodesignatures_la_SOURCES = shellcode-signatures.sc  
    17 shellcodesignatures_la_SOURCES += parser.y 
     15shellcodesignatures_la_SOURCES += y.tab.c lex.yy.c 
    1816shellcodesignatures_la_SOURCES += shellcode-signatures.cpp shellcode-signatures.hpp  
    1917 
     
    2220shellcodesignatures_la_LDFLAGS = -module -no-undefined -avoid-version 
    2321 
    24 CLEANFILES = parser.c 
  • nepenthes/trunk/modules/shellcode-signatures/parser.l

    r419 r422  
    22%{ 
    33#include <string.h> 
    4 #include "parser.h" 
     4#include "y.tab.h" 
    55 
    66inline void string_reset(); 
  • nepenthes/trunk/modules/shellcode-signatures/parser.y

    r419 r422  
    11/* $Id$ */ 
    22%{ 
    3    #include "parser-shared.h" 
    4  
    5 struct shellcode *shellcodes = NULL; 
    6  
     3        #define _GNU_SOURCE 
     4        #include <string.h> 
     5        #include <stdio.h> 
     6        #include <memory.h> 
     7         
     8        #include "parser.h" 
     9 
     10        inline void string_reset(); 
     11        inline char *string_get_buffer(); 
     12        inline int string_get_len(); 
    713 
    814        extern char *yytext; 
    9  
     15        extern FILE *yyin; 
     16 
     17        static struct shellcode *shellcodes = NULL; 
    1018        extern int line_number; 
    1119 
     20        static struct shellcode *init_shellcode(); 
     21        static char *get_namespace_by_numeric(int num); 
     22        static char *get_mapping_by_numeric(int num); 
    1223         
    1324%} 
     
    4455 
    4556                printf("\tname               %s\n", shellcodes->name); 
    46                 printf("\tnamespace          %s (%d) \n", get_namespace_by_numeric(shellcodes->sc_namespace), shellcodes->sc_namespace); 
     57                printf("\tnamespace          %s (%d) \n", get_namespace_by_numeric(shellcodes->nspace), shellcodes->nspace); 
    4758//              printf("\tpattern            %s\n", shellcodes->pattern); 
    4859                printf("\tmap-size           %d\n", shellcodes->map_items); 
     
    7283        : SC_XOR 
    7384        { 
    74                 shellcodes->sc_namespace = sc_xor; 
     85                shellcodes->nspace = sc_xor; 
    7586        } 
    7687        | 
    7788        SC_LINKXOR 
    7889        { 
    79                 shellcodes->sc_namespace = sc_linkxor; 
     90                shellcodes->nspace = sc_linkxor; 
    8091        } 
    8192        | 
    8293        SC_KONSTANZXOR 
    8394        { 
    84                 shellcodes->sc_namespace = sc_konstanzxor; 
     95                shellcodes->nspace = sc_konstanzxor; 
    8596        } 
    8697        | 
    8798        SC_LEIMBACHXOR 
    8899        { 
    89                 shellcodes->sc_namespace = sc_leimbachxor; 
     100                shellcodes->nspace = sc_leimbachxor; 
    90101        } 
    91102        | 
    92103        SC_BIND_SHELL 
    93104        { 
    94                 shellcodes->sc_namespace = sc_bindshell; 
     105                shellcodes->nspace = sc_bindshell; 
    95106        } 
    96107        | 
    97108        SC_CONNECTBACK_SHELL 
    98109        { 
    99                 shellcodes->sc_namespace = sc_connectbackshell; 
     110                shellcodes->nspace = sc_connectbackshell; 
    100111        } 
    101112        | 
    102113        SC_CONNECTBACK_FILETRANSFER 
    103114        { 
    104                  shellcodes->sc_namespace = sc_connectbackfiletransfer; 
     115                 shellcodes->nspace = sc_connectbackfiletransfer; 
    105116        } 
    106117        | 
    107118        SC_EXECUTE 
    108119        { 
    109                 shellcodes->sc_namespace = sc_execute; 
     120                shellcodes->nspace = sc_execute; 
    110121        } 
    111122        | 
    112123        SC_DOWNLOAD 
    113124        { 
    114                 shellcodes->sc_namespace = sc_download; 
     125                shellcodes->nspace = sc_download; 
    115126        } 
    116127        | 
    117128        SC_URL 
    118129        { 
    119                 shellcodes->sc_namespace = sc_url; 
     130                shellcodes->nspace = sc_url; 
    120131        } 
    121132        | 
    122133        SC_CONNECTBACK_LINK_FILETRANSFER 
    123134        { 
    124                 shellcodes->sc_namespace = sc_link; 
     135                shellcodes->nspace = sc_link; 
    125136        } 
    126137        |  
    127138        SC_BIND_LINK_FILETRANSFER 
    128139        { 
    129                 shellcodes->sc_namespace = sc_blink; 
     140                shellcodes->nspace = sc_blink; 
    130141        } 
    131142        ; 
     
    226237 
    227238 
    228         char *get_namespace_by_numeric(int num) 
     239        static char *get_namespace_by_numeric(int num) 
    229240        { 
    230241         
     
    251262        } 
    252263 
    253         char *get_mapping_by_numeric(int num) 
     264        static char *get_mapping_by_numeric(int num) 
    254265        { 
    255266                static char *mapmapping[]= 
     
    271282                 
    272283 
    273       int yyerror(char* s) { 
    274             printf(" %s at '%s' on line %d\n", s, yytext, line_number );return 0; 
    275       } 
    276  
    277  
    278       int yywrap(){ return 1; } 
    279 /* 
    280       int main(int argc, char** argv){ 
    281                   init_shellcode(); 
    282             yyparse(); 
    283       } 
    284  
    285 */ 
     284        int yyerror(char* s) 
     285        { 
     286                printf(" %s at '%s' on line %d\n", s, yytext, line_number ); 
     287                return 0; 
     288        } 
     289 
     290 
     291        int yywrap() 
     292        { 
     293                return 1; 
     294        } 
     295 
     296        struct shellcode *sc_parse_file(const char *filename) 
     297        { 
     298                init_shellcode(); 
     299                 
     300                yyin = fopen(filename, "r"); 
     301                 
     302                if( yyin == NULL ) 
     303                        return NULL; 
     304 
     305                yyparse(); 
     306                fclose(yyin); 
     307                 
     308                return shellcodes; 
     309        } 
     310         
     311        char *sc_get_error() 
     312        { 
     313                return "no idea"; 
     314        } 
  • nepenthes/trunk/modules/shellcode-signatures/sch_namespace_xor.hpp

    r419 r422  
    3434#include <pcre.h> 
    3535#include "ShellcodeHandler.hpp" 
    36 #include "parser-shared.h
     36#include "parser.hpp
    3737 
    3838namespace nepenthes