Changeset 1221

Show
Ignore:
Timestamp:
04/16/07 18:10:02 (1 year ago)
Author:
till
Message:

plugin priorities, small fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeytrap/trunk/ChangeLog

    r1201 r1221  
    11Version 0.7.0 
     2- Plugins can be priotizized 
    23- PostgreSQL module for commits into mwcollect database 
    34- SHA512 hash support 
  • honeytrap/trunk/src/attack.c

    r1201 r1221  
    101101        /* call plugins */ 
    102102        /* do calls even if no data received, i.e. to update connection statistics */ 
    103         plughook_process_attack(*a); 
     103        plughook_process_attack(funclist_attack_preproc, *a); 
     104        plughook_process_attack(funclist_attack_analyze, *a); 
     105        plughook_process_attack(funclist_attack_savedata, *a); 
     106        plughook_process_attack(funclist_attack_postproc, *a); 
    104107 
    105108        return(1); 
  • honeytrap/trunk/src/ctrl.c

    r1128 r1221  
    6666        unload_default_responses(); 
    6767 
     68        /* unloading plugins */ 
    6869        logmsg(LOG_DEBUG, 1, "Unloading plugins.\n"); 
    6970        unload_plugins(); 
  • honeytrap/trunk/src/dynsrv.c

    r1201 r1221  
    8787    proxy_sock_fd       = -1; 
    8888    proxy_this          = 0; 
    89     mirror_this         = 0
     89    mirror_this         = mirror_mode
    9090    established         = 0; 
    9191    port_mode           = PORTCONF_IGNORE; 
  • honeytrap/trunk/src/honeytrap.h

    r1128 r1221  
    2020#include <dlfcn.h> 
    2121 
    22 /* 
    23 #include "pcapmon.h" 
    24 #include "ipqmon.h" 
    25 */ 
    26  
    2722#if HAVE_CONFIG_H 
    2823# include <config.h> 
     
    3126 
    3227#define EXCL_FILE_RW    O_CREAT | O_NOCTTY | O_APPEND | O_WRONLY 
    33 #define DEBUG_FPRINTF if (log_level == LOG_DEBUG) fprintf 
    3428 
    3529#define PORTCONF_NONE   0 
     
    3832#define PORTCONF_MIRROR 4 
    3933#define PORTCONF_PROXY  8 
    40  
    41 #define TCP     6 
    42 #define UDP     17 
    4334 
    4435char *conffile_name, **arg_v; 
  • honeytrap/trunk/src/ip.h

    r1117 r1221  
    1313#ifndef __HONEYTRAP_IP_H 
    1414#define __HONEYTRAP_IP_H 1 
     15 
     16#include <netinet/in.h> 
    1517 
    1618 
  • honeytrap/trunk/src/logging.h

    r1201 r1221  
    11/* logging.h 
    2  * Copyright (C) 2005 Tillmann Werner <tillmann.werner@gmx.de> 
     2 * Copyright (C) 2005-2007 Tillmann Werner <tillmann.werner@gmx.de> 
    33 * 
    44 * This file is free software; as a special exception the author gives 
     
    1818#include <sys/types.h> 
    1919 
     20typedef enum { 
     21        OFF     = 0, 
     22        ERR     = 1, 
     23        WARN    = 2, 
     24        NOTICE  = 3, 
     25        INFO    = 4, 
     26        NOISY   = 5, 
     27        DEBUG   = 6, 
     28} s_log_level; 
     29 
     30s_log_level log_level; 
     31 
    2032#define LOG_OFF         0 
    2133#define LOG_ERR         1 
    2234#define LOG_WARN        2 
    23 #define LOG_NOTICE      3       /* default */ 
     35#define LOG_NOTICE      3       // default 
    2436#define LOG_INFO        4 
    2537#define LOG_NOISY       5 
    2638#define LOG_DEBUG       6 
    2739 
     40/* 
     41u_char log_level; 
     42*/ 
     43 
    2844#define LOGLINE_SIZE    256     /* truncates longer lines */ 
    2945 
    30 u_char log_level; 
     46#define DEBUG_FPRINTF   if (log_level == DEBUG) fprintf 
    3147 
    3248int logfile_fd; 
  • honeytrap/trunk/src/modules/htm_SpamSum.c

    r1201 r1221  
    5959 
    6060void plugin_unload(void) { 
    61         unhook(&pluginlist_process_attack, module_name, "calc_spamsum"); 
     61        unhook(PPRIO_POSTPROC, module_name, "calc_spamsum"); 
    6262        return; 
    6363} 
     
    6565void plugin_register_hooks(void) { 
    6666        DEBUG_FPRINTF(stdout, "    Plugin %s: Registering hooks.\n", module_name); 
    67         add_attack_func_to_list(module_name, "calc_spamsum", (void *) calc_spamsum); 
     67        add_attack_func_to_list(PPRIO_POSTPROC, module_name, "calc_spamsum", (void *) calc_spamsum); 
    6868 
    6969        return; 
  • honeytrap/trunk/src/modules/htm_aSaveFile.c

    r1125 r1221  
    2525#include <stdio.h> 
    2626 
     27#include <ip.h> 
    2728#include <logging.h> 
    2829#include <honeytrap.h> 
     
    3839 
    3940void plugin_unload(void) { 
    40         unhook(&pluginlist_process_attack, module_name, "save_to_file"); 
     41        unhook(PPRIO_SAVEDATA, module_name, "save_to_file"); 
    4142        return; 
    4243} 
     
    4445void plugin_register_hooks(void) { 
    4546        DEBUG_FPRINTF(stdout, "    Plugin %s: Registering hooks.\n", module_name); 
    46         add_attack_func_to_list(module_name, "save_to_file", (void *) save_to_file); 
     47        add_attack_func_to_list(PPRIO_SAVEDATA, module_name, "save_to_file", (void *) save_to_file); 
    4748 
    4849        return; 
  • honeytrap/trunk/src/modules/htm_aSavePostgres.c

    r1201 r1221  
    4545 
    4646void plugin_unload(void) { 
    47         unhook(&pluginlist_process_attack, module_name, "db_submit"); 
     47        unhook(PPRIO_SAVEDATA, module_name, "db_submit"); 
    4848        return; 
    4949} 
     
    5252void plugin_register_hooks(void) { 
    5353        DEBUG_FPRINTF(stdout, "    Plugin %s: Registering hooks.\n", module_name); 
    54         add_attack_func_to_list(module_name, "db_submit", (void *) db_submit); 
     54        add_attack_func_to_list(PPRIO_SAVEDATA, module_name, "db_submit", (void *) db_submit); 
    5555 
    5656        return; 
  • honeytrap/trunk/src/modules/htm_b64Decode.c

    r1125 r1221  
    4040 
    4141void plugin_unload(void) { 
    42         unhook(&pluginlist_process_attack, module_name, "b64_decode"); 
     42        unhook(PPRIO_PREPROC, module_name, "b64_decode"); 
    4343        return; 
    4444} 
     
    4646void plugin_register_hooks(void) { 
    4747        DEBUG_FPRINTF(stdout, "    Plugin %s: Registering hooks.\n", module_name); 
    48         add_attack_func_to_list(module_name, "b64_decode", (void *) b64_decode); 
     48        add_attack_func_to_list(PPRIO_PREPROC, module_name, "b64_decode", (void *) b64_decode); 
    4949 
    5050        return; 
     
    135135                        dec_attack.a_conn.payload.data = decoded->str; 
    136136                        dec_attack.a_conn.payload.size = decoded->len; 
    137                         plughook_process_attack(dec_attack); 
     137//                      plughook_process_attack(funclist_attack_preproc, dec_attack); 
     138                        plughook_process_attack(funclist_attack_analyze, dec_attack); 
     139                        plughook_process_attack(funclist_attack_savedata, dec_attack); 
     140                        plughook_process_attack(funclist_attack_postproc, dec_attack); 
    138141 
    139142 
  • honeytrap/trunk/src/modules/htm_ftpDownload.c

    r1201 r1221  
    4141 
    4242void plugin_unload(void) { 
    43         unhook(&pluginlist_process_attack, module_name, "cmd_parse_for_ftp"); 
     43        unhook(PPRIO_ANALYZE, module_name, "cmd_parse_for_ftp"); 
    4444        return; 
    4545} 
     
    4747void plugin_register_hooks(void) { 
    4848        DEBUG_FPRINTF(stdout, "    Plugin %s: Registering hooks.\n", module_name); 
    49         add_attack_func_to_list(module_name, "cmd_parse_for_ftp", (void *) cmd_parse_for_ftp); 
     49        add_attack_func_to_list(PPRIO_ANALYZE, module_name, "cmd_parse_for_ftp", (void *) cmd_parse_for_ftp); 
    5050 
    5151        return; 
  • honeytrap/trunk/src/modules/htm_tftpDownload.c

    r1201 r1221  
    4141 
    4242void plugin_unload(void) { 
    43         unhook(&pluginlist_process_attack, module_name, "cmd_parse_for_tftp"); 
     43        unhook(PPRIO_ANALYZE, module_name, "cmd_parse_for_tftp"); 
    4444        return; 
    4545} 
     
    4747void plugin_register_hooks(void) { 
    4848        DEBUG_FPRINTF(stdout, "    Plugin %s: Registering hooks.\n", module_name); 
    49         add_attack_func_to_list(module_name, "cmd_parse_for_tftp", (void *) cmd_parse_for_tftp); 
     49        add_attack_func_to_list(PPRIO_ANALYZE, module_name, "cmd_parse_for_tftp", (void *) cmd_parse_for_tftp); 
    5050 
    5151        return; 
  • honeytrap/trunk/src/modules/htm_vncDownload.c

    r1125 r1221  
    3434 
    3535void plugin_unload(void) { 
    36         unhook(&pluginlist_process_attack, module_name, "cmd_parse_for_vnc"); 
     36        unhook(PPRIO_ANALYZE, module_name, "cmd_parse_for_vnc"); 
    3737        return; 
    3838} 
     
    4040void plugin_register_hooks(void) { 
    4141        DEBUG_FPRINTF(stdout, "    Plugin %s: Registering hooks.\n", module_name); 
    42         add_attack_func_to_list(module_name, "cmd_parse_for_vnc", (void *) cmd_parse_for_vnc); 
     42        add_attack_func_to_list(PPRIO_ANALYZE, module_name, "cmd_parse_for_vnc", (void *) cmd_parse_for_vnc); 
    4343 
    4444        return; 
  • honeytrap/trunk/src/plughook.c

    r1106 r1221  
    2323 
    2424void init_plugin_hooks(void) { 
    25         pluginlist_unload_plugins       = NULL; 
    26         pluginlist_process_attack       = NULL; 
    27         return; 
    28 
    29  
    30  
    31 PlugFuncList *add_attack_func_to_list(const char *plugname, const char *funcname, int (*func)(Attack)) { 
     25        funclist_unload_plugins         = NULL; 
     26        funclist_attack_preproc         = NULL; 
     27        funclist_attack_analyze         = NULL; 
     28        funclist_attack_savedata        = NULL; 
     29        funclist_attack_postproc        = NULL; 
     30        return; 
     31
     32 
     33 
     34PlugFuncList *add_attack_func_to_list(const func_prio priority, const char *plugname, const char *funcname, int (*func)(Attack)) { 
    3235        PlugFuncList *func_tmp, *func_new; 
    3336 
    34         DEBUG_FPRINTF(stdout, "    Hooking plugin %s to 'process_attack'.\n", plugname); 
     37        func_tmp        = NULL; 
     38        func_new        = NULL; 
     39 
     40        DEBUG_FPRINTF(stdout, "    Hooking %s::%s() to 'process_attack' (priority: %d).\n", plugname, funcname, priority); 
    3541        if ((func_new = (PlugFuncList *) malloc(sizeof(PlugFuncList))) == NULL) { 
    3642                logmsg(LOG_ERR, 1, "    Error - Unable to allocate memory: %s\n", strerror(errno)); 
     
    4046 
    4147        /* attach new function to list */ 
    42         func_tmp = pluginlist_process_attack; 
     48        switch (priority) { 
     49        case PPRIO_PREPROC: 
     50                func_tmp        = funclist_attack_preproc; 
     51                break; 
     52        case PPRIO_ANALYZE: 
     53                func_tmp        = funclist_attack_analyze; 
     54                break; 
     55        case PPRIO_SAVEDATA: 
     56                func_tmp        = funclist_attack_savedata; 
     57                break; 
     58        case PPRIO_POSTPROC: 
     59                func_tmp        = funclist_attack_postproc; 
     60                break; 
     61        default: 
     62                fprintf(stderr, "    Error - Unknown plugin priority.\n"); 
     63                return(NULL); 
     64        } 
    4365        if (func_tmp) { 
    4466                while(func_tmp->next) func_tmp = func_tmp->next; 
    4567                func_tmp->next = func_new; 
    46         } else pluginlist_process_attack = func_new; 
     68        } else switch (priority) { 
     69        case PPRIO_PREPROC: 
     70                funclist_attack_preproc = func_new; 
     71                break; 
     72        case PPRIO_ANALYZE: 
     73                funclist_attack_analyze = func_new; 
     74                break; 
     75        case PPRIO_SAVEDATA: 
     76                funclist_attack_savedata = func_new; 
     77                break; 
     78        case PPRIO_POSTPROC: 
     79                funclist_attack_postproc = func_new; 
     80                break; 
     81        default: 
     82                fprintf(stderr, "    Error - Unknown plugin priority.\n"); 
     83                return(NULL); 
     84        } 
    4785 
    4886        func_new->func          = (void *)func; 
     
    5088        func_new->funcnam       = (char *)funcname; 
    5189 
    52         DEBUG_FPRINTF(stdout, "    %s::%s() hooked to 'process_attack'.\n", func_new->plugnam, func_new->funcnam); 
     90        DEBUG_FPRINTF(stdout, "    %s::%s() hooked to 'process_attack' (priority: %d).\n", func_new->plugnam, func_new->funcnam, priority); 
    5391        return(func_new); 
    5492} 
    5593 
    5694 
    57 void plughook_process_attack(Attack attack) { 
     95void plughook_process_attack(PlugFuncList *func_list, Attack attack) { 
    5896        PlugFuncList *func_tmp = NULL; 
    5997 
    6098        logmsg(LOG_DEBUG, 1, "Calling plugins for hook 'process_attack'.\n"); 
    6199 
    62         if (pluginlist_process_attack == NULL) { 
     100        if (func_list == NULL) { 
    63101                logmsg(LOG_DEBUG, 1, "No plugins registered for hook 'process_attack'.\n"); 
    64102                return; 
    65103        } 
    66104 
    67         func_tmp = pluginlist_process_attack
     105        func_tmp = func_list
    68106        while(func_tmp) { 
    69107                if (func_tmp->func) { 
     
    89127 
    90128        /* attach new function to list */ 
    91         func_tmp = pluginlist_unload_plugins; 
     129        func_tmp = funclist_unload_plugins; 
    92130        if (func_tmp) { 
    93131                while(func_tmp->next) func_tmp = func_tmp->next; 
    94132                func_tmp->next = func_new; 
    95         } else pluginlist_unload_plugins = func_new; 
     133        } else funclist_unload_plugins = func_new; 
    96134 
    97135        func_new->func          = (void *)func; 
     
    109147        logmsg(LOG_DEBUG, 1, "Calling plugins for hook 'unload_plugins'.\n"); 
    110148 
    111         if (pluginlist_process_attack == NULL) { 
     149/* 
     150        if (funclist_process_attack == NULL) { 
    112151                logmsg(LOG_DEBUG, 1, "No plugins registered for hook 'unload_plugins'.\n"); 
    113152                return; 
    114153        } 
    115  
    116         func_tmp = pluginlist_unload_plugins; 
     154*/ 
     155 
     156        func_tmp = funclist_unload_plugins; 
    117157        while(func_tmp) { 
    118158                if (func_tmp->func) { 
     
    130170 
    131171 
    132 void unhook(PlugFuncList **hook_func_list, const char *plugname, const char *funcname) { 
     172void unhook(const func_prio priority, const char *plugname, const char *funcname) { 
     173        switch (priority) { 
     174        case PPRIO_PREPROC: 
     175                unhook_from_list(&funclist_attack_preproc, plugname, funcname); 
     176                break; 
     177        case PPRIO_ANALYZE: 
     178                unhook_from_list(&funclist_attack_analyze, plugname, funcname); 
     179                break; 
     180        case PPRIO_SAVEDATA: 
     181                unhook_from_list(&funclist_attack_savedata, plugname, funcname); 
     182                break; 
     183        case PPRIO_POSTPROC: 
     184                unhook_from_list(&funclist_attack_postproc, plugname, funcname); 
     185                break; 
     186        default: 
     187                logmsg(LOG_ERR, 1, "Error - Unable to unhook %s::%s: Unsupported priority.\n", plugname, funcname); 
     188                return; 
     189        } 
     190        return; 
     191
     192 
     193 
     194void unhook_from_list(PlugFuncList **hook_func_list, const char *plugname, const char *funcname) { 
    133195        PlugFuncList *func_tmp, *func_del, *func_before_del; 
    134196 
  • honeytrap/trunk/src/plughook.h

    r1106 r1221  
    11/* plughook.h 
    2  * Copyright (C) 2006 Tillmann Werner <tillmann.werner@gmx.de> 
     2 * Copyright (C) 2006-2007 Tillmann Werner <tillmann.werner@gmx.de> 
    33 * 
    44 * This file is free software; as a special exception the author gives 
     
    1414#define __HONEYTRAP_PLUGHOOK_H 1 
    1515 
     16#include "plugin.h" 
    1617#include "attack.h" 
     18 
     19typedef enum { 
     20        PPRIO_PREPROC   = 0,    // attack preprocessing, e.g., decryption 
     21        PPRIO_ANALYZE   = 1,    // attack analysis, e.g., ftp command parsing 
     22        PPRIO_SAVEDATA  = 2,    // for data-saving plugins 
     23        PPRIO_POSTPROC  = 3,    // attack postprocessing, e.g., IDS signature generation or other time complex tasks 
     24} func_prio; 
    1725 
    1826typedef struct plugin_func_list { 
    1927        int (*func)(void *arg[]); 
     28        func_prio prio; 
    2029        char *plugnam; 
    2130        char *funcnam; 
     
    2433 
    2534 
    26 PlugFuncList *pluginlist_unload_plugins; 
    27 PlugFuncList *pluginlist_process_attack; 
     35PlugFuncList *funclist_unload_plugins; 
     36PlugFuncList *funclist_attack_preproc; 
     37PlugFuncList *funclist_attack_analyze; 
     38PlugFuncList *funclist_attack_savedata; 
     39PlugFuncList *funclist_attack_postproc; 
    2840 
    2941 
    30 PlugFuncList *add_attack_func_to_list(const char *plugname, const char *funcname, int (*func)(struct s_attack)); 
    31 void plughook_process_attack(struct s_attack attack); 
     42PlugFuncList *add_attack_func_to_list(const func_prio priority, const char *plugname, const char *funcname, int (*func)(struct s_attack)); 
     43void plughook_process_attack(PlugFuncList *func_list, Attack attack); 
    3244 
    3345PlugFuncList *add_unload_func_to_list(const char *plugname, const char *funcname, void (*func)(void)); 
     
    3547 
    3648void init_plugin_hooks(void); 
    37 void unhook(PlugFuncList **hook_func_list, const char *plugname, const char *funcname); 
     49void unhook(const func_prio priority, const char *plugname, const char *funcname); 
     50void unhook_from_list(PlugFuncList **hook_func_list, const char *plugname, const char *funcname); 
    3851 
    3952#endif 
  • honeytrap/trunk/src/plugin.c

    r1123 r1221  
    3333        DIR *plugindir; 
    3434 
    35         full_path = NULL; 
    36         plugin_list = NULL; 
     35        full_path      = NULL; 
     36        plugin_list    = NULL; 
    3737 
    3838        init_plugin_hooks(); 
  • honeytrap/trunk/src/plugin.h

    r1081 r1221  
    1414#define __HONEYTRAP_PLUGIN_H 1 
    1515 
    16  
    1716typedef struct plugin_struct { 
    1817        void *handle; 
     
    2524 
    2625char *plugin_error_str; 
     26 
    2727Plugin *plugin_list; 
    2828 
  • honeytrap/trunk/src/proxy.c

    r1126 r1221  
    2323#include "proxy.h" 
    2424#include "logging.h" 
     25#include "ip.h" 
    2526 
    2627int proxy_connect(u_char mode, struct in_addr ipaddr, uint16_t l_port, u_int16_t port, uint16_t proto, Attack *attack) {