Changeset 1249

Show
Ignore:
Timestamp:
05/02/07 21:50:56 (1 year ago)
Author:
till
Message:

make plugins optional in autotools build process

Files:

Legend:

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

    r1221 r1249  
    11Version 0.7.0 
    2 - Plugins can be priotizized 
     2- Plugins can be prioritized 
    33- PostgreSQL module for commits into mwcollect database 
    44- SHA512 hash support 
     
    66- Improved connection request handling in the nfq stream monitor 
    77- FTP download plugin is now source-based routing safe 
     8- Changed autotools process to make module builts optional 
    89Version 0.6.5 
    910- Introduced an nfnetlink_queue-based connection monitor 
  • honeytrap/trunk/INSTALL

    r1081 r1249  
    1010   The `configure' shell script must be told which connection monitor 
    1111should be used by honeytrap to monitor network interfaces for incoming 
    12 connection requests. Possible values are currently 
    13  
    14    --with-pcap-mon      monitoring with a PCAP-based sniffer 
     12connection requests. Currently the following options are possible: 
     13 
     14   --with-nfq-mon       monitoring via libnetfilter_queue 
     15                        (Linux only, recommended) 
    1516 
    1617   --with-ipq-mon       monitoring via netfilter/iptables ip_queue 
    1718                        (Linux only) 
     19 
     20   --with-pcap-mon      monitoring with a PCAP-based sniffer 
     21 
     22To build additional plugins use the --with-[pluginname] options. 
    1823 
    1924Please refer to the generic installation instructions below for further 
  • honeytrap/trunk/configure.in

    r1241 r1249  
    267267fi 
    268268 
     269#----------------------- network stream monitors --------------------------- 
    269270 
    270271AC_ARG_WITH(pcap-mon, 
     
    377378else with_ipfw_mon="no" 
    378379fi 
     380 
     381 
     382#----------------------- optional plugins --------------------------- 
     383 
     384 
     385AC_ARG_WITH(spamsum, 
     386        [  --with-spamsum           Perform SpamSum similarity analysis for recorded attacks]) 
     387AM_CONDITIONAL(BUILD_SPAMSUM_PLUGIN, test x$with_spamsum = xyes) 
     388if test "$with_spamsum" != "yes"; then 
     389        with_spamsum="no" 
     390fi 
     391 
     392 
     393 
     394AC_ARG_WITH(postgres, 
     395        [  --with-postgres          Store attack data in PostgreSQL database]) 
     396AM_CONDITIONAL(BUILD_POSTGRES_PLUGIN, test x$with_postgres = xyes) 
     397if test "$with_postgres" = "yes"; then 
     398  AC_ARG_WITH(libpq_includes, 
     399    [  --with-libpq-includes=DIR  libpq include directory], 
     400    [with_libpq_includes="$withval"],[with_libpq_includes=no]) 
     401 
     402  AC_ARG_WITH(libpq_libraries, 
     403    [  --with-libpq-libraries=DIR  libpq library directory], 
     404    [with_libpq_libraries="$withval"],[with_libpq_libraries=no]) 
     405 
     406  if test "$with_libpq_includes" != "no"; then 
     407    CPPFLAGS="${CPPFLAGS} -I${with_libpq_includes}" 
     408  fi 
     409  AC_CHECK_HEADER(postgresql/libpq-fe.h,,[AC_ERROR(libpq-fe.h not found.)]) 
     410 
     411  if test "$with_libpq_libraries" != "no"; then 
     412    LDFLAGS="${LDFLAGS}  -L${with_libpq_libraries}" 
     413  fi 
     414  LIPQ="" 
     415  AC_CHECK_LIB(pq, PQconnectdb,, LPQ="no") 
     416 
     417  if test "$LPQ" = "no"; then 
     418    echo 
     419    echo "   ERROR!  Libpq library/headers not found. Install it or use the" 
     420    echo "   --with-libpq-* options, if you have it installed in unusual place." 
     421    echo 
     422    exit 
     423  fi 
     424 
     425  AC_DEFINE([USE_POSTGRES_DB], [], [Define to store attacks in PostgreSQL database]) 
     426else with_postgres="no" 
     427fi 
     428 
     429#------------------------------------------------------------- 
     430 
     431 
    379432 
    380433default_directory="/usr /usr/local" 
     
    463516echo 
    464517echo "--- honeytrap configuration ---" 
    465 echo "Debugging options:             $enable_debug" 
    466 echo "Profiling options:             $enable_profile" 
    467 echo "Electric Fence:                $with_efence" 
     518echo "Debugging options:                  $enable_debug" 
     519echo "Profiling options:                  $enable_profile" 
     520echo "Electric Fence:                     $with_efence" 
    468521echo 
    469522echo "Connection monitor" 
    470 echo "  Linux ip_queue (ipq):        $with_ipq_mon" 
    471 echo "  Linux nfnetlink_queue (nfq): $with_nfq_mon" 
    472 echo "  FreeBSD ipfw (ipfw):         $with_ipfw_mon" 
    473 echo "  Libpcap (pcap):              $with_pcap_mon" 
     523echo "  Linux ip_queue (ipq):             $with_ipq_mon" 
     524echo "  Linux libnetfilter_queue (nfq):   $with_nfq_mon" 
     525echo "  FreeBSD ipfw (ipfw):              $with_ipfw_mon" 
     526echo "  Libpcap (pcap):                   $with_pcap_mon" 
     527echo 
     528echo "Optional plugins" 
     529echo "  PostgeSQL:                        $with_postgres" 
     530echo "  SpamSum:                          $with_spamsum" 
  • honeytrap/trunk/src/modules/Makefile.am

    r1226 r1249  
    99libdir=$(DESTDIR)/$(sysconfdir)/honeytrap/plugins 
    1010 
    11 lib_LTLIBRARIES = htm_aSaveFile.la htm_ftpDownload.la htm_tftpDownload.la htm_vncDownload.la htm_b64Decode.la htm_SpamSum.la htm_aSavePostgres.la 
     11lib_LTLIBRARIES = \ 
     12        htm_aSaveFile.la \ 
     13        htm_ftpDownload.la \ 
     14        htm_tftpDownload.la \ 
     15        htm_vncDownload.la \ 
     16        htm_b64Decode.la 
     17 
     18if BUILD_SPAMSUM_PLUGIN 
     19lib_LTLIBRARIES += htm_SpamSum.la 
     20endif 
     21 
     22if BUILD_POSTGRES_PLUGIN 
     23lib_LTLIBRARIES += htm_aSavePostgres.la 
     24endif 
    1225 
    1326htm_aSaveFile_la_SOURCES = htm_aSaveFile.c htm_aSaveFile.h 
     
    2639htm_b64Decode_la_LDFLAGS = -module -no-undefined -avoid-version 
    2740 
     41if BUILD_SPAMSUM_PLUGIN 
    2842htm_SpamSum_la_SOURCES = htm_SpamSum.c htm_SpamSum.h 
    2943htm_SpamSum_la_LDFLAGS = -module -no-undefined -avoid-version 
     44endif 
    3045 
     46if BUILD_POSTGRES_PLUGIN 
    3147htm_aSavePostgres_la_SOURCES = htm_aSavePostgres.c htm_aSavePostgres.h 
    3248htm_aSavePostgres_la_LDFLAGS = -module -no-undefined -avoid-version -lpq 
     49endif 
    3350 
    3451install-exec-am: 
    3552        $(mkinstalldirs) $(DESTDIR)/$(sysconfdir)/honeytrap/plugins 
    36         for module in `find .libs -name htm_*.so | grep -v SpamSum`; do \ 
     53        for module in `find .libs -name htm_*.so`; do \ 
    3754                [ -h $$module ] || $(INSTALL_DATA) "$$module" $(DESTDIR)/$(sysconfdir)/honeytrap/plugins/ ; \ 
    3855        done 
    39         for module in `find . -name htm_*.*a | grep -v SpamSum`; do \ 
     56        for module in `find . -name htm_*.*a`; do \ 
    4057                rm -f $(DESTDIR)/$(sysconfdir)/honeytrap/plugins/`basename "$$module"` ; \ 
    4158        done 
  • honeytrap/trunk/src/modules/htm_aSavePostgres.c

    r1248 r1249  
    1313 * 
    1414 * Description: 
    15  *   This honeytrap module submits a recorded attack to a PostgreSQL database. 
     15 *   This honeytrap module submits recorded attacks to a PostgreSQL database. 
    1616 *    
    1717 */ 
     18 
     19#ifdef USE_POSTGRES 
    1820 
    1921#include <stdio.h> 
     
    159161                /* check if sample already exists */ 
    160162                memset(query, 0, MAX_SQL_BUFFER + 1); 
    161                 if (snprintf(query, MAX_SQL_BUFFER, "SELECT malware.sensor_exists_sample('%s', '%s');",  
     163                if (snprintf(query, MAX_SQL_BUFFER, "SELECT mwcollect.sensor_exists_sample('%s', '%s');",  
    162164                        mem_sha512sum(attack->download->dl_payload.data, attack->download->dl_payload.size), 
    163165                        mem_md5sum(attack->download->dl_payload.data, attack->download->dl_payload.size)) >= MAX_SQL_BUFFER) { 
     
    177179                } else { 
    178180                        /* escape byte data to prevent sql injection */ 
     181logmsg(LOG_DEBUG, 1, "payload is %s.\n", attack->download->dl_payload.data); 
    179182                        if ((esc_bytea = PQescapeByteaConn(db_connection, attack->download->dl_payload.data, 
    180183                                                           attack->download->dl_payload.size, &length)) == NULL) { 
     
    185188                                return(-1); 
    186189                        } 
     190logmsg(LOG_DEBUG, 1, "esc_bytea is %s.\n", esc_bytea); 
    187191 
    188192                        if ((uri = build_uri(attack->download)) == NULL) { 
     
    198202                        } 
    199203                        memset(query, 0, MAX_SQL_BUFFER + 1); 
    200                         if (snprintf(query, MAX_SQL_BUFFER, "SELECT attacks.sensor_honeytrap_add_sample('%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s')", 
     204//                      if (snprintf(query, MAX_SQL_BUFFER, "SELECT attacks.sensor_honeytrap_add_sample('%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s')", 
     205logmsg(LOG_DEBUG, 1, "esc_bytea is %s.\n", esc_bytea); 
     206                        if (snprintf(query, MAX_SQL_BUFFER, "SELECT mwcollect.sensor_add_sample('%s', '%s', '%s', '%s', '%s', '%s')", 
     207                                mem_md5sum(attack->download->dl_payload.data, attack->download->dl_payload.size), 
    201208                                mem_sha512sum(attack->download->dl_payload.data, attack->download->dl_payload.size), 
    202                                 "honeytrap-default"
    203                                "dynamic-generic", 
    204                                uri
     209                                esc_bytea
     210//                             "honeytrap-default", 
     211//                             "dynamic-generic"
    205212                                inet_ntoa(*(struct in_addr*)&(attack->a_conn.l_addr)), 
    206213                                inet_ntoa(*(struct in_addr*)&(attack->a_conn.r_addr)), 
    207                                 attack->a_conn.l_port, 
    208                                 attack->download->r_port, 
    209                                 esc_bytea) >= MAX_SQL_BUFFER) { 
     214                                uri 
     215//                              attack->a_conn.l_port, 
     216//                              attack->download->r_port, 
     217                                ) >= MAX_SQL_BUFFER) { 
    210218                                logmsg(LOG_ERR, 1, "Postgres client error - Could not save malware: SQL query exceeds maximum size (increase MAX_SQL_BUFFER and recompile).\n"); 
    211219                                free(uri); 
     
    213221                                return(-1); 
    214222                        } 
     223logmsg(LOG_DEBUG, 1, "Postgres client - Query is: %s.\n", query); 
    215224                        free(uri); 
    216225 
    217226                        if (PQresultStatus(res = PQexec(db_connection, query)) != PGRES_TUPLES_OK) { 
    218227                                logmsg(LOG_ERR, 1, "Postgres client error - Malware submission failed: %s.\n", PQerrorMessage(db_connection)); 
     228                                logmsg(LOG_DEBUG, 1, "Postgres client - Query was: %s.\n", query); 
    219229                                PQclear(res); 
    220230                                db_disconnect(); 
     
    227237 
    228238                        /* get instance number for reference within attack_string record */ 
    229                         mw_inst = atoi(PQgetvalue(res, 0, PQfnumber(res, "sensor_honeytrap_add_sample"))); 
     239//                      mw_inst = atoi(PQgetvalue(res, 0, PQfnumber(res, "sensor_honeytrap_add_sample"))); 
     240                        mw_inst = atoi(PQgetvalue(res, 0, PQfnumber(res, "sensor_add_sample"))); 
    230241 
    231242                        PQclear(res);     
     
    334345        return(0); 
    335346} 
     347 
     348#endif 
  • honeytrap/trunk/src/modules/htm_aSavePostgres.h

    r1238 r1249  
    1111 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    1212 */ 
     13 
     14#ifdef USE_POSTGRES 
    1315 
    1416#ifndef __HT_MODULE_ASAVEPOSTGRES_H 
     
    3032 
    3133/* use static values for now. should be taken from configuration file */ 
    32 const char      *db_info = "port=5432 host=127.0.0.1 user=mwcollect password=mwcollect dbname=mwcollect"; 
     34const char      *db_info = "port=5432 host=127.0.0.1 user=mwcollect password=mwcollect dbname=mwcollect2"; 
    3335 
    3436void plugin_init(void); 
     
    4244 
    4345#endif 
     46 
     47#endif 
  • honeytrap/trunk/src/modules/htm_ftpDownload.c

    r1241 r1249  
    11/* htm_ftpDownload.c 
    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 
     
    227227 
    228228 
    229 int ftp_quit(int control_sock_fd, int data_sock_fd, int dumpfile_fd) { 
     229int ftp_quit(int control_sock_fd, int data_sock_fd) { 
    230230        char rline[MAX_LINE+1];         /* MAX_LINE plus one char for \0 */ 
    231231        int timeout = 60; 
     
    233233 
    234234        close(data_sock_fd); 
    235         close(dumpfile_fd); 
    236235 
    237236        logmsg(LOG_NOISY, 1, "FTP download - Sending 'QUIT'.\n"); 
     
    252251int get_ftp_resource(const char *user, const char* pass, struct in_addr *lhost, struct in_addr *rhost, const int port, const char *save_file, Attack *attack) { 
    253252        struct sockaddr_in control_socket, local_data_socket, remote_data_socket; 
    254         int control_sock_fd, data_sock_listen_fd, data_sock_fd, dumpfile_fd, 
     253        int control_sock_fd, data_sock_listen_fd, data_sock_fd, 
    255254            local_data_port, bytes_read, total_bytes, addr_len, select_return, timeout, retval; 
    256255        uint8_t ip_octet[4], *binary_stream; 
     
    269268        timeout = 60; 
    270269        data_sock_fd = -1; 
    271         dumpfile_fd = -1; 
    272270         
    273271        logmsg(LOG_NOTICE, 1, "FTP download - Requesting '%s' from %s:%u.\n", save_file, inet_ntoa(*rhost), port); 
     
    341339        /* wait for 200 */ 
    342340        while (strstr(rline, "200") != rline) { 
    343  
     341                /* read multi-line banner */ 
     342                while ((strlen(rline) > 3) && (rline[3] == '-')) {  
     343                        if (read_ftp_line(control_sock_fd, rline, timeout) <= 0) return(0); 
     344                } 
    344345                /* wait for 230 and send SYST and TYPE */ 
    345346                if(strstr(rline, "230") == rline) { 
     347 
    346348                        /* Send SYST and switch to binary mode */ 
    347349                        /* Some buggy servers cannot handle a TYPE after SYST, so check for return value */ 
     
    431433                sizeof(local_data_socket))) < 0) && (local_data_port < 65535)) { 
    432434                logmsg(LOG_DEBUG, 1, 
    433                         "FTP download - Port %d is already in use. Trying to bind on port %d.\n", 
     435                        "FTP download - Unable to bind port %d. Trying port %d.\n", 
    434436                        ntohs(local_data_socket.sin_port), ntohs(local_data_socket.sin_port)+1); 
    435437                /* check if integer was overflowed to 0 */ 
     
    451453                        strerror(errno)); 
    452454                close(data_sock_listen_fd); 
    453                 ftp_quit(control_sock_fd, data_sock_fd, dumpfile_fd); 
     455                ftp_quit(control_sock_fd, data_sock_fd); 
    454456                return(-1); 
    455457        } else logmsg(LOG_DEBUG, 1, "FTP download - Initialized FTP data channel on port %u/tcp.\n", 
     
    478480        if(strstr(rline, "4") == rline) { 
    479481                logmsg(LOG_WARN, 1, "FTP download - FTP error code received: %s", rline); 
    480                 ftp_quit(control_sock_fd, data_sock_fd, dumpfile_fd); 
     482                ftp_quit(control_sock_fd, data_sock_fd); 
    481483                return(-1); 
    482484        } 
     
    503505                if(strstr(rline, "4") == rline) { 
    504506                        logmsg(LOG_WARN, 1, "FTP download - FTP error code received: %s", rline); 
    505                         ftp_quit(control_sock_fd, data_sock_fd, dumpfile_fd); 
     507                        ftp_quit(control_sock_fd, data_sock_fd); 
    506508                        return(-1); 
    507509                } 
     
    521523                if (errno != EINTR) { 
    522524                        logmsg(LOG_ERR, 1, "FTP download error - Select on FTP data channel failed: %s.\n", strerror(errno)); 
    523                         ftp_quit(control_sock_fd, data_sock_fd, dumpfile_fd); 
     525                        ftp_quit(control_sock_fd, data_sock_fd); 
    524526                        return(-1); 
    525527                } 
     
    527529                logmsg(LOG_WARN, 1, "FTP download - Transfer timeout, no incoming data connection for %d seconds.\n", 
    528530                        timeout); 
    529                 ftp_quit(control_sock_fd, data_sock_fd, dumpfile_fd); 
     531                ftp_quit(control_sock_fd, data_sock_fd); 
    530532                return(-1); 
    531533        } else if (FD_ISSET(data_sock_listen_fd, &rfds)) {  
     
    533535                        logmsg(LOG_ERR, 1, "FTP download error - Unable to accept FTP data connection: %s\n", 
    534536                                strerror(errno)); 
    535                         ftp_quit(control_sock_fd, data_sock_fd, dumpfile_fd); 
     537                        ftp_quit(control_sock_fd, data_sock_fd); 
    536538                        return(-1); 
    537539                } else logmsg(LOG_DEBUG, 1, "FTP download - Incoming data connection from %s:%u.\n", 
     
    550552                if (errno != EINTR) { 
    551553                        logmsg(LOG_ERR, 1, "FTP download error - Select on FTP data channel failed: %s.\n", strerror(errno)); 
    552                         ftp_quit(control_sock_fd, data_sock_listen_fd, dumpfile_fd); 
     554                        ftp_quit(control_sock_fd, data_sock_listen_fd); 
    553555                        return(-1); 
    554556                } 
    555557        } else if (select_return == 0) { 
    556558                logmsg(LOG_WARN, 1, "FTP download - Transfer timeout, no data to read for 10 seconds.\n"); 
    557                 ftp_quit(control_sock_fd, data_sock_listen_fd, dumpfile_fd); 
    558                 return(-1); 
    559         } else if (FD_ISSET(data_sock_fd, &rfds)) {  
     559                ftp_quit(control_sock_fd, data_sock_listen_fd); 
     560                return(-1); 
     561        } else if (FD_ISSET(data_sock_fd, &rfds)) { 
    560562                logmsg(LOG_DEBUG, 1, "FTP download - Data available, retrieving file.\n"); 
    561563                /* receive file */ 
     
    566568                        total_bytes += bytes_read; 
    567569                } 
     570                if (bytes_read < 0) { 
     571                        logmsg(LOG_ERR, 1, "FTP download error - Unable to read from data channel: %s.\n", strerror(errno)); 
     572                        ftp_quit(control_sock_fd, data_sock_listen_fd); 
     573                        return(-1); 
     574                } 
    568575                logmsg(LOG_NOISY, 1, "FTP download - Successfully downloaded %s.\n", save_file); 
    569                 ftp_quit(control_sock_fd, data_sock_fd, dumpfile_fd); 
     576                ftp_quit(control_sock_fd, data_sock_fd); 
    570577 
    571578                /* add download to attack record */ 
    572                 if(total_bytes) { 
     579                if (total_bytes) { 
    573580                        logmsg(LOG_DEBUG, 1, "FTP download - Adding download to attack record.\n"); 
    574581                        add_download("ftp", 6, rhost->s_addr, port, user, pass, (const char *) save_file, binary_stream, total_bytes, attack); 
     
    583590        /* close open descriptors and return */ 
    584591        while((read_ftp_line(control_sock_fd, rline, 5) && strstr(rline, "226") != rline)); 
    585         ftp_quit(control_sock_fd, data_sock_fd, dumpfile_fd); 
     592        ftp_quit(control_sock_fd, data_sock_fd); 
    586593        return(0); 
    587594} 
  • honeytrap/trunk/src/modules/htm_ftpDownload.h

    r1238 r1249  
    11/* htm_ftpDownload.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 
     
    1919 
    2020const char module_name[]="htm_ftpDownload"; 
    21 const char module_version[]="0.4.0"; 
     21const char module_version[]="0.4.1"; 
    2222 
    2323void plugin_init(void); 
     
    2626int cmd_parse_for_ftp(Attack *attack); 
    2727int read_ftp_line(int control_sock_fd, char *rline, int timeout); 
    28 int ftp_quit(int control_sock_fd, int data_sock_fd, int dumpfile_fd); 
     28int ftp_quit(int control_sock_fd, int data_sock_fd); 
    2929int get_ftp_resource(const char *user, const char* pass, struct in_addr *lhost, struct in_addr *rhost, const int port, const char *save_file, Attack *attack); 
    3030int get_ftpcmd(char *attack_string, uint32_t string_size, struct in_addr lhost, Attack *attack);