Changeset 1625

Show
Ignore:
Timestamp:
05/28/08 21:32:07 (3 months ago)
Author:
till
Message:

honeytrap
- reworked NFQ stream monitor hooking to prevent unbinding errors
- hex2bin tool: Command line switch for byte order swapping added

Files:

Legend:

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

    r1567 r1625  
    44- Fix: Improper logging of IP address pairs 
    55- Nebula submission plugin 
     6- reworked NFQ stream monitor hooking to prevent unbinding errors 
     7- hex2bin tool: Command line switch for byte order swapping added 
    68Version 1.0.0 
    79- Improved configure script 
  • honeytrap/trunk/src/ctrl.c

    r1404 r1625  
    2323#include "honeytrap.h" 
    2424#include "logging.h" 
     25#include "nfqmon.h" 
    2526#include "pcapmon.h" 
    2627#include "plugin.h" 
     
    5960void clean_exit(int status) { 
    6061#ifdef USE_PCAP_MON 
    61         /* free bpf filter string */ 
     62        // free bpf filter string 
     63        logmsg(LOG_DEBUG, 1, "Freeing BPF filter string.\n"); 
    6264        free(bpf_filter_string); 
     65#endif 
     66#ifdef USE_NFQ_MON 
     67        // unhook from netfilter-queue 
     68        if (h) { 
     69                logmsg(LOG_DEBUG, 1, "Destroying NFQ handle.\n"); 
     70                if (qh && nfq_destroy_queue(qh) != 0) { 
     71                        logmsg(LOG_ERR, 1, "Error - Could not destroy NFQ handle: %m.\n"); 
     72                } 
     73 
     74                logmsg(LOG_DEBUG, 1, "Unhooking NFQ connection monitor.\n"); 
     75                if (nfq_close(h) != 0) { 
     76                        logmsg(LOG_ERR, 1, "Error - Could not close NFQ connection monitor: %m.\n"); 
     77                } 
     78        } 
    6379#endif 
    6480 
  • honeytrap/trunk/src/nfqmon.c

    r1361 r1625  
    144144 
    145145int start_nfq_mon(void) { 
    146         struct nfq_handle       *h; 
    147146        struct nfnl_handle      *nh; 
    148147        int                     nfq_fd, rv; 
     
    163162        } 
    164163 
    165         if (nfq_unbind_pf(h, AF_INET) < 0) { 
    166                 logmsg(LOG_ERR, 1, "Error - Could not unbind existing NFQ handle: %m.\n"); 
    167                 logmsg(LOG_ERR, 1, "Do you have root privileges?\n"); 
    168                 clean_exit(EXIT_FAILURE); 
    169         } 
     164        if (nfq_unbind_pf(h, AF_INET) < 0) 
     165                logmsg(LOG_WARN, 1, "Warning - Could not unbind existing NFQ handle: %m.\n"); 
    170166 
    171167        if (nfq_bind_pf(h, AF_INET) < 0) { 
    172168                logmsg(LOG_ERR, 1, "Error - Could not bind existing NFQ handle: %m.\n"); 
     169                logmsg(LOG_ERR, 1, "Do you have root privileges?\n"); 
     170 
     171                h = NULL; 
    173172                clean_exit(EXIT_FAILURE); 
    174173        } 
  • honeytrap/trunk/src/nfqmon.h

    r1131 r1625  
    2020 
    2121int id; 
     22struct nfq_handle *h; 
    2223struct nfq_q_handle *qh; 
    2324 
  • honeytrap/trunk/tools/hex2bin.c

    r1279 r1625  
    11/* hex2bin.c 
    2  * Copyright (C) 2006-2007 Tillmann Werner <tillmann.werner@gmx.de> 
     2 * Copyright (C) 2006-2008 Tillmann Werner <tillmann.werner@gmx.de> 
    33 * 
    44 * This file is free software; as a special exception the author gives 
     
    1818 */ 
    1919 
     20#include <errno.h> 
     21#include <stdio.h> 
    2022#include <stdlib.h> 
    21 #include <stdio.h> 
    2223#include <string.h> 
    23 #include <errno.h> 
     24#include <unistd.h> 
    2425 
    2526int main(int argc, char *argv[]) { 
    26         u_char chr; 
    27         int retval; 
     27        char option; 
     28        u_char buf[4]; 
     29        unsigned int chr[2]; 
     30        int swap, retval; 
    2831        FILE *file; 
    2932 
    30         if (argc < 2) { 
    31                 fprintf(stderr, "Error - No filename given.\n"); 
    32                 exit(1); 
     33        swap = 0; 
     34 
     35        // process args 
     36        while((option = getopt(argc, argv, "sh?")) > 0) { 
     37                switch(option) { 
     38                        case 's': 
     39                                swap = 1; 
     40                                break; 
     41                        case 'h': 
     42                        case '?': 
     43                        default: 
     44                                printf("Usage: %s [-s] file   (-s swaps byte order)\n", argv[0]); 
     45                                exit(EXIT_SUCCESS); 
     46                } 
    3347        } 
    3448 
    35         /* open file */ 
    36         if ((file = fopen(argv[1], "r")) == NULL) { 
     49        // open file 
     50        if (argc - optind < 1) { 
     51                fprintf(stderr, "Error - No filename given.\n"); 
     52                exit(EXIT_FAILURE); 
     53        } 
     54        if ((file = fopen(argv[optind++], "r")) == NULL) { 
    3755                fprintf(stderr, "Error - Unable to open file: %s.\n", strerror(errno)); 
    38                 exit(1); 
     56                exit(EXIT_FAILURE); 
    3957        } 
    4058 
     59        // process data 
    4160        errno = 0; 
    42         while((retval = fscanf(file, "%2x", &chr)) > 0) fprintf(stdout, "%c", chr); 
    43         if ((retval = EOF) && errno) fprintf(stderr, "Error - Unable to read from file: %s.\n", strerror(errno)); 
     61        for (;;) switch ((retval = fread(&buf, 2, 2, file))) { 
     62        case 0: 
     63                fclose(file); 
     64                if ((retval = EOF) && errno) { 
     65                        fprintf(stderr, "Error - Unable to read from file: %s.\n", strerror(errno)); 
     66                        exit(EXIT_FAILURE); 
     67                } 
     68                exit(EXIT_SUCCESS); 
     69        case 1: 
     70                sscanf((char *) buf, "%2x", &chr[0]); 
     71                fprintf(stdout, "%c", chr[0]); 
     72                break; 
     73        case 2: 
     74                sscanf((char *) buf, "%2x%2x", &chr[0], &chr[1]); 
     75                fprintf(stdout, "%c%c", swap ? chr[1] : chr[0], swap ? chr[0] : chr[1]); 
     76                break; 
     77        } 
    4478 
    45         fclose(file); 
    46         return(0); 
     79        exit(EXIT_SUCCESS); // never reached 
    4780}