Changeset 1270

Show
Ignore:
Timestamp:
05/20/07 15:22:17 (1 year ago)
Author:
till
Message:

honeytrap 1.0.0 started

  • New configuration concept with hierarchically organized file format
  • New plugin: PostgreSQL module for commits into mwcollect database
  • New plugin: Saving attack data in files is performed by a module now
  • New plugin: x86 CPU emulation module for generic shellcode analysis

based on libemu by Markus and Paul (still PoC)

  • Improved connection request handling in the nfq stream monitor
  • Plugins can be prioritized
  • SHA512 hashing support
  • FTP download plugin is now source-based routing safe
  • Changed autotools process to make module builts optional
  • Performance improvements
Files:

Legend:

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

    r1253 r1270  
    1 Version 0.7.0 
     1Version 1.0.0 
     2- New configuration concept with hierarchically organized file format 
     3- New plugin: PostgreSQL module for commits into mwcollect database 
     4- New plugin: Saving attack data in files is performed by a module now 
     5- New plugin: x86 CPU emulation module for generic shellcode analysis 
     6              based on libemu by Markus and Paul 
     7- Improved connection request handling in the nfq stream monitor 
    28- Plugins can be prioritized 
    3 - x86 CPU emulation module for generic shellcode analysis 
    4   based on libemu by Markus and Paul 
    5 - PostgreSQL module for commits into mwcollect database 
    6 - SHA512 hash support 
    7 - Performance improvements 
    8 - Improved connection request handling in the nfq stream monitor 
     9- SHA512 hashing support 
    910- FTP download plugin is now source-based routing safe 
    1011- Changed autotools process to make module builts optional 
     12- Performance improvements 
    1113Version 0.6.5 
    1214- Introduced an nfnetlink_queue-based connection monitor 
  • honeytrap/trunk/README

    r1081 r1270  
    2222  future releases. 
    2323 
    24   Version 0.5.0 introduces the mirror mode (option '-m'). When run- 
    25   ning in this mode, whenever a connection request is handled, hon- 
    26   eytrap tries to establish a so called mirror connection  back  to 
    27   the  remote  host  requesting the same port. All data received on 
    28   one of the two connections is copied to the other one. Thus, hon- 
    29   eytrap is acting as a tcp proxy for a connection of a remote host 
    30   with itself. If no mirror connection can be  established,  honey- 
    31   trap falls back to normal mode. 
    32  
    33   A  plugin  interface  was  added in Version 0.6.0. Plugins can be 
    34   loaded as dynamic shared objects. Also, honeytrap can now be con- 
    35   figured  via a configuration file. The file is reprocessed when a 
    36   SIGHUP is received so changes can be  made  available  with  zero 
    37   downtime. 
    38  
    39   Version  0.6.2  comes  with  lots  of new features. Using the new 
    40   proxy mode, Connections can not only be mirrored back to the ini- 
    41   tiator,  but proxied to other systems and other ports. The appro- 
    42   priate mode can optionally be configured per TCP port. A new, li- 
    43   bipq-based  connection  monitor  was introduced (idea stolen from 
    44   the nepenthes honeytrap module). 
    45  
    4624INSTALLATION 
    4725 
     
    6543  early as possible. 
    6644 
    67 THANKS 
    68  
    69   Many thanks to Steve, Gary to help me debugging compile errors on 
    70   FreeBSD and OpenBSD and to lots of others who  helped  me  fixing 
    71   bugs. 
    72  
    7345CONTACT 
    7446 
  • honeytrap/trunk/configure.in

    r1253 r1270  
    11# $Id$  
    22AC_PREREQ(02.50) 
    3 AC_INIT([honeytrap], [0.6.5], [tillmann.werner@gmx.de]) 
     3AC_INIT([honeytrap], [1.0.0], [tillmann.werner@gmx.de]) 
    44AM_CONFIG_HEADER(config.h) 
    5 AM_INIT_AUTOMAKE(honeytrap,0.6.5
     5AM_INIT_AUTOMAKE(honeytrap,1.0.0
    66 
    77# Since we get -O2 from configure defaults, which doesn't work in 64bit 
  • honeytrap/trunk/etc/honeytrap.conf.dist

    r1124 r1270  
    1 # /etc/honeytrap/honeytrap.conf 
    2 
    3 # This is a sample honeytrap configuration file. 
    4 # However, the default values below should work in most installations. 
    5 
    6 # Copyright (C) 2006 Tillmann Werner <tillmann.werner@gmx.de> 
    7 
    8 
    9 # allowed keywords are: 
    10 
    11 # keyword       values          description 
    12 # ---------------------------------------------------------------------------------- 
    13 # pidfile       path            full pid file path (defaults to /var/run/honeytrap.pid if not given) 
    14 # logfile       path            full logfile path (defaults to /var/log/honeytrap.log if not given) 
    15 # user          username        user from /etc/passwd under which honeytrap should run 
    16 # group         groupname       group from /etc/group under which honeytrap should run 
    17 # promisc       -               tells honeytrap to sniff in promiscuous mode 
    18 # mirror        -               tells honeytrap to run in mirror mode 
    19 # response_dir  path            path to directory with default responses (defaults to /etc/honeytrap/responses) 
    20 # plugin_dir    path            path to directory with honeytrap plugins (defaults to /etc/honeytrap/plugins) 
    21 # attacks_dir   path            where to save attack strings (default is /var/spool/honeytrap) 
    22 # dlsave_dir    path            where to save downloaded files (default is /var/spool/honeytrap) 
    23 # read_limt     number          max. bytes to read from a socket - prevents honeytrap from memory exhaustion 
     1/*  
     2 * honeytrap 1.0 configuration file template -- please adjust 
     3 * (c) Tillmann Werner <tillmann.werner@gmx.de> 
     4*/ 
     5 
     6/* log to this file */ 
     7logfile         = "/opt/honeytrap/honeytrap.log" 
     8 
     9/* PID file */ 
     10pidfile         = "/var/run/honeytrap.pid" 
     11 
     12/* where to look for default responses 
     13   these are sent for connections handled in "normal mode" */ 
     14response_dir    = "/opt/honeytrap/etc/honeytrap/responses" 
     15 
     16/* where to look for plugins 
     17   need to be set before loading plugins */ 
     18plugin_dir      = "/opt/honeytrap/etc/honeytrap/plugins" 
     19 
     20/* run in mirror mode - mirror connections back to the initiator 
     21   use with caution! */ 
     22//mirror = "on" 
     23 
     24/* put network interface into promiscuous mode 
     25   (only availabel when compiled with --with-pcap-mon) */ 
     26//promisc = "on" 
     27 
     28/* the user and group under which honeytrap should run */ 
     29user    = "nobody" 
     30group   = "nogroup" 
     31 
     32/* include a file */ 
     33//include = "ports.conf" 
    2434 
    2535 
    26 pidfile = /var/run/honeytrap.pid 
    27 logfile = /etc/honeytrap/honeytrap.log 
     36/* ----- plugin stuff below ----- */ 
    2837 
    29 response_dir = /etc/honeytrap/responses 
    30 plugin_dir = /etc/honeytrap/plugins 
     38/* include a plugin via plugin-[ModuleName] = "" */ 
    3139 
    32 attacks_dir = /var/spool/honeytrap/attacks 
    33 dlsave_dir = /var/spool/honeytrap/downloads 
     40plugin-ftpDownload = "" 
     41plugin-tftpDownload = "" 
     42plugin-b64Decode = "" 
     43plugin-vncDownload = "" 
    3444 
    35 # max bytes to read from an attack connection (10MB = 10485760) 
    36 read_limit = 10485760 
     45/* store attacks on disk */ 
     46plugin-SaveFile = { 
     47        attacks_dir     = "/opt/honeytrap/attacks" 
     48        downloads_dir   = "/opt/honeytrap/downloads" 
     49
     50 
     51/* calculate locality sensitive hashes */ 
     52plugin-SpamSum = { 
     53        md5sum_sigfile  = "/opt/honeytrap/md5sum.sigs" 
     54        spamsum_sigfile = "/opt/honeytrap/spamsum.sigs" 
     55
     56 
     57/* store attacks in PostgeSQL database */ 
     58/* 
     59plugin-SavePostgres = { 
     60        db_host = "localhost" 
     61        db_name = "some_db" 
     62        db_user = "some_user" 
     63        db_pass = "some_pass" 
     64//      db_port = "some_port"   // if not set, use the default (5432/tcp) 
     65
     66*/ 
    3767 
    3868 
    39  
    40 # hash signature files for htm_SpamSum plugin 
    41 # you'll get errors if you define them and don't load this plugin 
    42 md5_sigfile 
    43 ss_sigfile 
    44  
    45  
    46 # run in mirror mode - mirror connections back to the initiator (use with caution!) 
    47 mirror 
    48  
    49 # put network interface into promiscuous mode - only available when using the pcap connection monitor 
    50 #promisc 
    51  
    52 # run as the following user and group 
    53 user    = nobody 
    54 group   = nogroup 
    55  
    56 # use this host (ip address) to listen for FTP data connections (you would need the htm_ftpDownload plugin version 3) 
    57 #ftp_host = example.com 
    58  
    59 #include explicit port configuration 
    60 #include = ./ports.conf 
     69/* ----- explicit port modes below ----- */ 
     70portconf = { 
     71        /* ignore these ports */ 
     72        ignore = { 
     73                protocol        = "tcp" 
     74                port            = "22" 
     75        } 
     76
  • honeytrap/trunk/etc/ports.conf.dist

    r1117 r1270  
    1 # honeytrap configuration file 
    2 # Explicit configuration for some tcp ports 
    3 
    4 # the syntax is 'port = portnum/protocol: mode[,host,port]' 
    5 # e.g. 'port = 80/tcp: mirror' 
    6 
    7 # protocol must either be tcp or udp 
    8 
    9 # possible values for mode are: 
    10 # ignore:       ignore connection requests on this port 
    11 # normal:       always handle connections on this port in normal mode 
    12 # mirror:       always handle connections on this port in mirror mode 
    13 # proxy:        always handle connections on this port in proxy mod 
    14 
    15 # 'proxy' takes the arguments 'host,port' where port is optional 
    16 # e.g. 'port = 80/tcp: proxy,example.com:8000 
    17 # if no port argument is given, the attacked port is used. 
    18 # the proxy destination port does not support protocol changes 
    19 
     1/*  
     2 * honeytrap 1.0 port configuration file template 
     3 * should be included in main configuration file 
     4 * (c) Tillmann Werner <tillmann.werner@gmx.de> 
     5*/ 
    206 
    21 #port = 21/tcp: normal 
    22 #port = 22/tcp: ignore 
    23 #port = 25/tcp: mirror 
    24 #port = 53/udp: ignore 
    25 #port = 80/tcp: proxy,example.com:8000 
     7portconf = { 
     8        /* ignore these ports */ 
     9        ignore = { 
     10                protocol        = "tcp" 
     11                port            = ["25", "1433"] 
     12        } 
     13        /* process ports in normal mode */ 
     14        normal = { 
     15                protocol        = ["tcp", "udp"] 
     16                port            = ["53"] 
     17        } 
     18        /* mirror ports back to the initiator */ 
     19        mirror = { 
     20                protocol        = ["tcp"] 
     21                port            = ["23"] 
     22        } 
     23        /* proxy ports to a target */ 
     24        proxy = { 
     25                /* names for proxy maps can be chosen from [a-zA-Z0-9-_] */ 
     26                proxy-http = { 
     27                        protocol        = ["tcp"] 
     28                        port            = ["80", "8080"] 
     29 
     30                        target_host     = "127.0.0.1" 
     31                        target_protocol = "tcp" 
     32                        target_port     = "8080" 
     33                } 
     34                proxy-tftp = { 
     35                        protocol        = ["udp"] 
     36                        port            = ["69"] 
     37 
     38                        target_host     = "tftp.localhost" 
     39                        target_protocol = "udp" 
     40                        target_port     = "69" 
     41                } 
     42        } 
     43
  • honeytrap/trunk/src/Makefile.am

    r1201 r1270  
    99                        signals.c signals.h \ 
    1010                        readconf.c readconf.h \ 
     11                        parseconf.c parseconf.h \ 
     12                        conftree.c conftree.h \ 
    1113                        plugin.c plugin.h \ 
    1214                        plughook.c plughook.h \ 
  • honeytrap/trunk/src/attack.h

    r1226 r1270  
    5050        u_char                  op_mode;        /* mode of operation (none, ignore, normal, proxy, mirror) */ 
    5151        uint16_t                dl_count;       /* number of downloads */ 
    52 //      struct s_download       download[];     /* array of download structs */ 
    5352        struct s_download       *download;      /* array of download structs */ 
    5453} Attack; 
  • honeytrap/trunk/src/conftree.c

    r1268 r1270  
    3131 
    3232 
     33void conftree_children_free(conf_node *tree) { 
     34        conf_node       *cur_node, *old_node; 
     35        list_entry      *val, *old_val; 
     36 
     37        if (!tree) return; 
     38 
     39        cur_node = tree->first_leaf; 
     40        while (cur_node) { 
     41                if (cur_node->first_leaf) conftree_children_free(cur_node->first_leaf); 
     42                free(cur_node->keyword); 
     43                val = cur_node->val; 
     44                while (val) { 
     45                        free(val->data); 
     46                        old_val = val; 
     47                        val = val->next; 
     48                        free(old_val); 
     49                } 
     50                old_node = cur_node; 
     51                cur_node = cur_node->next; 
     52                free(old_node); 
     53        } 
     54        return; 
     55} 
     56 
     57 
    3358void print_conftree(conf_node *tree, int depth) { 
    3459        int i; 
    35         conf_node *cur_node; 
     60        char c; 
     61        conf_node       *cur_node; 
     62        list_entry      *val; 
    3663 
    3764        cur_node = tree; 
     
    3966                if (cur_node->keyword) { 
    4067                        for (i=0; i<depth*2; i++) printf(" "); 
    41                         printf("%s\n", cur_node->keyword); 
     68                        printf("%s", cur_node->keyword); 
     69                        val = cur_node->val; 
     70                        while (val) { 
     71                                if (val->data) { 
     72                                        printf("\n\t\t\""); 
     73                                        for( i = 0; i < val->size; i++ ) 
     74                                                printf("%c", isprint(c = *((const char *)(val->data+i))) ? c : '.'); 
     75                                        printf("\""); 
     76                                } 
     77                                val = val->next; 
     78                        } 
     79                        printf("\n"); 
    4280                } 
    4381                print_conftree(cur_node->first_leaf, depth+1); 
     
    4583        } 
    4684        return; 
     85} 
     86 
     87 
     88list_entry *add_list_item(conf_node *node, const void *data, ssize_t size) { 
     89        list_entry      *new_entry; 
     90 
     91        if (!node) return(NULL); 
     92 
     93        /* find last list element */ 
     94        if (node->val) while (node->val->next) node->val = node->val->next; 
     95 
     96        /* create new element */ 
     97        if ((new_entry = malloc(sizeof(list_entry))) == NULL) { 
     98                logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
     99                return(NULL); 
     100        } 
     101        memset(new_entry, 0, sizeof(list_entry)); 
     102 
     103        /* copy data */ 
     104        if ((new_entry->data = malloc(size+1)) == NULL) { 
     105                logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
     106                return(NULL); 
     107        } 
     108        memset(new_entry->data, 0, size+1); 
     109        new_entry->size = size; 
     110        memcpy(new_entry->data, data, size); 
     111 
     112        /* attach new element to the list and return */ 
     113        if (node->val) node->val->next = new_entry; 
     114         else node->val = new_entry; 
     115 
     116        return(new_entry); 
     117} 
     118 
     119 
     120/* return first leaf node of subtree for given keyword */ 
     121conf_node *conf_subtree(conf_node *tree, const char *keyword) { 
     122        conf_node *subtree; 
     123 
     124        if ((subtree = check_keyword(tree, keyword)) == NULL) return(NULL); 
     125        return(subtree->first_leaf); 
    47126} 
    48127 
     
    52131conf_node *check_keyword(conf_node *tree, const char *keyword) { 
    53132        conf_node       *cur_node; 
    54         char            *key, *subkey; 
     133        char            **key, *subkey; 
     134 
     135        cur_node        = tree; 
     136        subkey          = NULL; 
    55137 
    56138        if (!tree) return(NULL); 
    57139        if (!keyword) { 
    58                 logmsg(LOG_WARN, 1, "Error - Unable to search tree: No keyword given.\n"); 
    59                 return(NULL); 
    60         } 
    61  
    62         cur_node        = tree; 
    63  
    64         if ((key = strdup(keyword)) ==  NULL) { 
    65                 logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    66                 return(NULL); 
    67         } 
    68  
    69         if ((subkey = strchr(key, '.')) != NULL) { 
    70                 subkey[0] = 0; 
    71                 subkey++; 
    72         } 
    73  
    74         /* depth first search in config tree */ 
    75         while(cur_node) { 
    76                 if (strncmp(cur_node->keyword, keyword, strlen(keyword)) == 0) { 
    77                         free(key); 
    78                         return(cur_node); 
    79                 } 
    80                 if (subkey) { 
    81                         if (strncmp(cur_node->keyword, key, strlen(key)) == 0) { 
    82                                 tree = cur_node->first_leaf; 
    83                                 while (tree) { 
    84                                         cur_node = check_keyword(tree, subkey); 
    85                                         if (cur_node) return(cur_node); 
    86                                         tree = tree->next; 
    87                                 } 
    88                                 break; 
    89                         } 
    90                 } 
    91                 cur_node = cur_node->next; 
     140                fprintf(stderr, "  Error - Unable to search tree: No keyword given.\n"); 
     141                return(NULL); 
     142        } 
     143 
     144 
     145        if (((key = (char **) malloc(sizeof(char *))) == NULL) || ((*key = strdup(keyword)) ==  NULL)) { 
     146                fprintf(stderr, "  Error - Unable to allocate memory: %s.\n", strerror(errno)); 
     147                return(NULL); 
     148        } 
     149 
     150        /* search in config tree */ 
     151        if ((subkey = strsep(key, ".")) == NULL) { 
     152                free(key); 
     153                return(NULL); 
     154        } 
     155        while (cur_node) { 
     156                /* compare current node's keyword with prefix */ 
     157                if (strncmp(cur_node->keyword, subkey, strlen(subkey)) == 0) { 
     158                        if ((subkey = strsep(key, ".")) == NULL) return(cur_node); 
     159                        cur_node = cur_node->first_leaf; 
     160                } else cur_node = cur_node->next; 
    92161        } 
    93162 
     
    99168/* insert new node into config tree and return a pointer to it 
    100169 * if *tree is NULL, it will be set to point to the root node */ 
    101 conf_node *add_keyword(conf_node **tree, const char *keyword) { 
     170conf_node *add_keyword(conf_node **tree, const char *keyword, const void *data, ssize_t size) { 
    102171        conf_node       *new_node, *cur_node; 
    103         char            *key, *subkey
     172        char            *key, *subkey, *list_item
    104173 
    105174        cur_node        = *tree; 
     
    107176        key             = NULL; 
    108177        subkey          = NULL; 
     178        list_item       = NULL; 
     179 
    109180 
    110181        if (!keyword) { 
     
    113184        } 
    114185 
    115         /* check whether the keyword or a prefix of it does already exist */ 
    116         if ((cur_node = check_keyword(*tree, keyword)) == NULL) { 
    117                 if ((key = strdup(keyword)) ==  NULL) { 
    118                         logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    119                         return(NULL); 
    120                 } 
     186        // check whether a prefix does already exist and if not, add it recursively 
     187        if ((key = strdup(keyword)) ==  NULL) { 
     188                logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
     189                return(NULL); 
     190        } 
     191 
     192        /* add recursively */ 
     193        if ((cur_node = check_keyword(*tree, key)) == NULL) { 
    121194                if ((subkey = strrchr(key, '.')) != NULL) { 
    122195                        subkey[0] = 0;          // zero-terminate first half 
    123196                        subkey++;               // pointer to second half 
    124                         cur_node = add_keyword(tree, key); 
    125                 } else subkey = key; 
    126         } else return(cur_node);                // node already exists 
    127  
    128  
    129         /* create new node and insert it into tree */ 
     197                        if (isdigit(subkey[0])) { 
     198                                if ((cur_node = check_keyword(*tree, key)) == NULL) 
     199                                        if ((cur_node = add_keyword(tree, key, NULL, 0)) == NULL) return(NULL); 
     200//printf(" -- got a list entry: %s:%s = %s\n", key, subkey, (char *) data); 
     201                                if (add_list_item(cur_node, data, size) == NULL) { 
     202                                        fprintf(stderr, "  Error - Unable to add list item for %s.\n", key); 
     203                                        return(NULL); 
     204                                } 
     205                                return(cur_node); 
     206                        } 
     207                        if ((cur_node = add_keyword(tree, key, NULL, 0)) == NULL) return(NULL); 
     208                } 
     209        } else return(cur_node); 
     210 
     211        // create new node and insert it into tree 
    130212        if ((new_node = malloc(sizeof(conf_node))) == NULL) { 
    131213                logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
     
    134216        } 
    135217        memset(new_node, 0, sizeof(conf_node)); 
    136         if ((new_node->keyword = strdup(subkey)) == NULL) { 
     218        // if keyword is a toplevel key, add it, else add subkey 
     219        if ((new_node->keyword = strdup(subkey ? subkey : key)) == NULL) { 
    137220                logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %s.\n", strerror(errno)); 
    138221                free(key); 
     
    140223        } 
    141224        free(key); 
     225 
     226        if (size) { 
     227//printf(" -- got single list entry: %s = %s\n", keyword, (char *) data); 
     228                if (add_list_item(new_node, data, size) == NULL) { 
     229                        fprintf(stderr, "  Error - Unable to add list item for %s.\n", keyword); 
     230                        return(NULL); 
     231                } 
     232        } 
    142233 
    143234        /* insert new node into tree */ 
     
    150241                } else cur_node->first_leaf = new_node; 
    151242        } else { 
    152                 /* it's the root node */ 
     243                /* it's a top level node */ 
    153244                if (!(*tree)) (*tree) = new_node; 
    154245                /* it's a root's neighbor */ 
     
    159250                } 
    160251        } 
     252        if (*tree == NULL) *tree = cur_node; 
    161253 
    162254        return(new_node); 
  • honeytrap/trunk/src/conftree.h

    r1268 r1270  
    1818 
    1919 
     20typedef struct list_entry { 
     21        ssize_t                 size; 
     22        void                    *data; 
     23        struct list_entry       *next; 
     24} list_entry; 
     25 
     26 
    2027typedef struct conf_node { 
    2128        char                    *keyword; 
     29        list_entry              *val; 
    2230        struct conf_node        *first_leaf; 
    2331        struct conf_node        *next; 
     
    2533 
    2634 
    27 conf_node *config_keywords_tree; 
     35conf_node *config_keywords_tree;        // tree for allowed keywords, initialized by core, extended by plugins 
     36conf_node *config_tree;                 // tree for actual configuration organized in a hierarchical manner 
    2837 
    2938 
     39void conftree_children_free(conf_node *tree); 
    3040void print_conftree(conf_node *tree, int depth); 
     41conf_node *conf_subtree(conf_node *tree, const char *keyword); 
    3142conf_node *check_keyword(conf_node *tree, const char *keyword); 
    32 conf_node *add_keyword(conf_node **tree, const char *keyword); 
     43conf_node *add_keyword(conf_node **tree, const char *keyword, const void *data, ssize_t size); 
    3344 
    3445#endif 
  • honeytrap/trunk/src/ctrl.c

    r1221 r1270  
    5353        fprintf(stdout, "\t-L:\tlogfile\n"); 
    5454        fprintf(stdout, "\t-P:\tpid file\n"); 
    55         exit(0); 
     55        exit(EXIT_SUCCESS); 
    5656} 
    5757 
     
    100100        if (logfile_fd == STDOUT_FILENO) { 
    101101                fprintf(stderr, "  Error - Logging to stdout is not possible while running in daemon mode.\n"); 
    102                 clean_exit(0); 
     102                clean_exit(EXIT_SUCCESS); 
    103103        } 
    104104 
     
    109109        if (getrlimit(RLIMIT_NOFILE, &rl) < 0) { 
    110110                fprintf(stderr, "  Error - Unable to daemonize: %s\n", strerror(errno)); 
    111                 exit(1); 
     111                exit(EXIT_FAILURE); 
    112112        } 
    113113 
     
    115115        if ((pid = fork()) < 0) { 
    116116                fprintf(stderr, "  Error - Unable to daemonize: %s\n", strerror(errno)); 
    117                 exit(1); 
    118         } else if (pid != 0) exit(0); 
     117                exit(EXIT_FAILURE); 
     118        } else if (pid != 0) exit(EXIT_SUCCESS); 
    119119                 
    120120        setsid(); 
     
    123123        if ((pid = fork()) < 0) { 
    124124                fprintf(stderr, "  Error - Unable to daemonize: %s\n", strerror(errno)); 
    125                 exit(1); 
     125                exit(EXIT_FAILURE); 
    126126        } else if (pid != 0) { 
    127127                DEBUG_FPRINTF(stdout, "  Successfully changed into daemon environment.\n"); 
    128128                fprintf(stdout, "\nhoneytrap v%s Copyright (C) 2005-2007 Tillmann Werner <tillmann.werner@gmx.de>\n", VERSION); 
    129129                fflush(stdout); 
    130                 exit(0); 
     130                exit(EXIT_SUCCESS); 
    131131        } 
    132132 
     
    137137        if (chdir("/") < 0) { 
    138138                fprintf(stderr, "  Error - Cannot change working directory: %s\n", strerror(errno)); 
    139                 exit(1); 
     139                exit(EXIT_FAILURE); 
    140140        } 
    141141 
     
    161161        if ((pidfile_fd = open(pidfile_name, O_EXCL | O_CREAT | O_NOCTTY | O_RDWR, 0640)) == -1) { 
    162162                logmsg(LOG_ERR, 1, "Error - Unable to open pid file: %s\n", strerror(errno)); 
    163                 exit(0); 
     163                exit(EXIT_SUCCESS); 
    164164        } 
    165165        if (lockf(pidfile_fd, F_TLOCK, 0) < 0) { 
    166166                logmsg(LOG_ERR, 1, "Error - Unable to lock pid file: %s\n", strerror(errno)); 
    167                 clean_exit(0); 
     167                clean_exit(EXIT_SUCCESS); 
    168168        } 
    169169 
  • honeytrap/trunk/src/dynsrv.c

    r1221 r1270  
    2626#include <string.h> 
    2727 
     28#include "readconf.h" 
    2829#include "ctrl.h" 
    2930#include "honeytrap.h" 
     
    6566#endif 
    6667    socklen_t client_addr_len; 
    67     struct sockaddr_in client_addr, server_addr; 
    68     struct timeval c_timeout; 
    69     struct s_proxy_dest *proxy_dst
    70     struct hostent *proxy_addr; 
    71     struct in_addr *p_addr
    72     fd_set rfds; 
    73     char *ip_l_str, *ip_r_str; 
    74     Attack *attack; 
    75     u_int8_t port_mode; 
     68    struct sockaddr_in client_addr, server_addr; 
     69    struct timeval     c_timeout; 
     70    struct hostent     *proxy_addr
     71    struct in_addr     *p_addr; 
     72    proxy_dest         *proxy_dst
     73    fd_set             rfds; 
     74    char               *ip_l_str, *ip_r_str; 
     75    Attack             *attack; 
     76    u_int8_t           port_mode; 
    7677 
    7778    proxy_addr          = NULL; 
     
    9394    if (!((proto == TCP) || (proto == UDP))) { 
    9495        logmsg(LOG_DEBUG, 1, "Unsupported protocol type.\n"); 
    95         exit(0)
     96        return
    9697    } 
    9798 
     
    106107        if (proto == TCP) { 
    107108                logmsg(LOG_DEBUG, 1, "Requesting tcp socket.\n"); 
    108                 if ((listen_fd = tcpsock(&server_addr, port_l)) < 0) exit(1); 
    109                 port_mode = port_flags[htons(port_l)].tcp
     109                if ((listen_fd = tcpsock(&server_addr, port_l)) < 0) exit(EXIT_FAILURE); 
     110                port_mode = port_flags_tcp[htons(port_l)] ? port_flags_tcp[htons(port_l)]->mode : 0
    110111        } else if (proto == UDP) { 
    111112                logmsg(LOG_DEBUG, 1, "Requesting udp socket.\n"); 
    112                 if ((listen_fd = udpsock(&server_addr, port_l)) < 0) exit(1); 
    113                 port_mode = port_flags[htons(port_l)].udp
     113                if ((listen_fd = udpsock(&server_addr, port_l)) < 0) exit(EXIT_FAILURE); 
     114                port_mode = port_flags_udp[htons(port_l)] ? port_flags_udp[htons(port_l)]->mode : 0
    114115        } else { 
    115116                logmsg(LOG_DEBUG, 1, "Unsupported protocol type.\n"); 
    116                 exit(0)
     117                return
    117118        } 
    118119 
     
    130131            logmsg(LOG_ERR, 1, "Error - Could not listen on socket: %s.\n", strerror(errno)); 
    131132            close(listen_fd); 
    132             exit(1); 
     133            exit(EXIT_FAILURE); 
    133134        } 
    134135        logmsg(LOG_DEBUG, 1, "Listening on port %u/%s.\n", ntohs(port_l), PROTO(proto)); 
     
    140141            logmsg(LOG_ERR, 1, "IPQ Error: %s.\n", ipq_errstr()); 
    141142            ipq_destroy_handle(h); 
    142             exit(1); 
     143            exit(EXIT_FAILURE); 
    143144        } 
    144145 
     
    173174                logmsg(LOG_ERR, 1, "   %u\t  Error - select() call failed: %s.\n", 
    174175                    (uint16_t) ntohs(port_l), strerror(errno)); 
    175                 exit(1); 
     176                exit(EXIT_FAILURE); 
    176177            case  0: 
    177178                /* timeout */ 
    178179                logmsg(LOG_NOISY, 1, "-> %u\t  No incoming connection for %u seconds - server terminated.\n", 
    179180                    (uint16_t) ntohs(port_l), conn_timeout); 
    180                 exit(0)
     181                return
    181182            default: 
    182183                if (FD_ISSET(listen_fd, &rfds)) { 
     
    188189                        logmsg(LOG_ERR, 1, "Error - Could not initialize attack record.\n"); 
    189190                        free(attack); 
    190                         exit(1); 
     191                        exit(EXIT_FAILURE); 
    191192                    } 
    192193                    if (port_mode & PORTCONF_NORMAL) { 
     
    198199                        /* get proxy server address for port */ 
    199200                        logmsg(LOG_DEBUG, 1, "   %u\t  Handling connection in proxy mode.\n", (uint16_t) ntohs(port_l)); 
    200                         proxy_dst = proxy_dest; 
    201                         while (proxy_dst) { 
    202                             if (proxy_dst->attack_port == ntohs(port_l)) break; 
    203                             proxy_dst = proxy_dst->next; 
     201 
     202                        if (proto == TCP) { 
     203                                if (port_flags_tcp[htons(port_l)]) proxy_dst = port_flags_tcp[htons(port_l)]->target; 
     204                        } else if (proto == UDP) { 
     205                                if (port_flags_udp[htons(port_l)]) proxy_dst = port_flags_udp[htons(port_l)]->target; 
    204206                        } 
    205                         if (proxy_dst->attack_port == ntohs(port_l)) { 
    206                                /* try to establish proxy connection to server */ 
    207                             if ((proxy_addr = gethostbyname(proxy_dst->d_addr)) == NULL) { 
    208                                 logmsg(LOG_ERR, 1, "   %u\t  Error - Unable to resolve proxy host %s.\n", 
    209                                     (uint16_t) ntohs(port_l), proxy_dst->d_addr); 
    210                                free(attack); 
    211                                 exit(0); 
    212                            
    213                             logmsg(LOG_DEBUG, 1, "== %u\t  Proxy hostname %s resolved to %s.\n", 
    214                                 (uint16_t) ntohs(port_l), proxy_dst->d_addr
    215                                 inet_ntoa(*(struct in_addr*)proxy_addr->h_addr_list[0])); 
    216  
    217  
    218                             logmsg(LOG_DEBUG, 1, "== %u\t  Requesting proxy connection to %s:%u.\n", 
    219                                (uint16_t) ntohs(port_l), 
    220                                inet_ntoa(*(struct in_addr*)proxy_addr->h_addr_list[0]), proxy_dst->d_port); 
     207 
     208                        /* try to establish proxy connection to server */ 
     209                       if ((proxy_addr = gethostbyname(proxy_dst->host)) == NULL) { 
     210                            logmsg(LOG_ERR, 1, "   %u\t  Error - Unable to resolve proxy host %s.\n", 
     211                                (uint16_t) ntohs(port_l), proxy_dst->host); 
     212                            free(attack); 
     213                            exit(EXIT_FAILURE); 
     214                       
     215                        logmsg(LOG_DEBUG, 1, "== %u\t  Proxy hostname %s resolved to %s.\n", 
     216                            (uint16_t) ntohs(port_l), proxy_dst->host
     217                            inet_ntoa(*(struct in_addr*)proxy_addr->h_addr_list[0])); 
     218 
     219 
     220                        logmsg(LOG_DEBUG, 1, "== %u\t  Requesting proxy connection to %s:%u.\n", 
     221                            (uint16_t) ntohs(port_l), 
     222                            inet_ntoa(*(struct in_addr*)proxy_addr->h_addr_list[0]), proxy_dst->port); 
    221223                            p_addr = (struct in_addr *) proxy_addr->h_addr_list[0]; 
    222                             if ((proxy_sock_fd = proxy_connect(PORTCONF_PROXY, *p_addr, 
    223                                 ntohs(port_l), proxy_dst->d_port, proto, attack)) == -1) { 
    224