Changeset 1561

Show
Ignore:
Timestamp:
02/19/08 22:20:23 (6 months ago)
Author:
till
Message:

honeytrap
- hash(pss+nonce) Nebula submission authentication

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeytrap/trunk/src/modules/htm_submitNebula.c

    r1557 r1561  
    3636#include <plughook.h> 
    3737#include <readconf.h> 
     38#include <sha512.h> 
    3839#include <sock.h> 
    3940#include <tcpip.h> 
     
    4243#include "htm_submitNebula.h" 
    4344 
     45 
    4446const char module_name[]="submitNebula"; 
    45 const char module_version[]="0.1.0"; 
     47const char module_version[]="0.1.1"; 
    4648 
    4749static const char *config_keywords[] = { 
     
    119121        struct hostent          *host; 
    120122        u_char                  *cbuf, response[9]; 
    121         u_int32_t               cbuf_len
     123        u_int32_t               cbuf_len, rand_no
    122124        struct sockaddr_in      sock; 
    123125        int                     sock_fd; 
    124         u_char                 secret_len
     126        char                   *sha512sum
    125127 
    126128        cbuf_len        = 0; 
     
    162164                inet_ntoa(*(struct in_addr*)host->h_addr), nebula_port); 
    163165 
    164         // send secret length 
    165         secret_len = strlen(nebula_secret); 
    166         if (write(sock_fd, &secret_len, 1) == -1) { 
    167                 logmsg(LOG_ERR, 1, "SubmitNebula Error - Writing to socket failed: %m.\n"); 
    168                 close(sock_fd); 
    169                 return(-1); 
    170         } 
    171  
    172         // send secret 
    173         if (write(sock_fd, nebula_secret, secret_len) == -1) { 
     166 
     167 
     168        // get random number 
     169        srand(time(0)); 
     170        rand_no = (u_int32_t) (RAND_MAX * (rand() / (RAND_MAX + 1.0))); 
     171 
     172        // hash secret with random number 
     173        if ((cbuf = malloc(strlen(nebula_secret)+4)) == NULL) { 
     174                logmsg(LOG_ERR, 1, "SubmitNebula Error - Unable to allocate memory: %m.\n"); 
     175                close(sock_fd); 
     176                return(-1); 
     177        } 
     178        memcpy(cbuf, nebula_secret, strlen(nebula_secret)); 
     179        memcpy(cbuf+strlen(nebula_secret), &rand_no, 4); 
     180        if ((sha512sum = mem_sha512sum(cbuf, strlen(nebula_secret)+4)) == NULL) { 
     181                logmsg(LOG_ERR, 1, "SubmitNebula Error - Unable to hash secret.\n"); 
     182                close(sock_fd); 
     183                return(-1); 
     184        } 
     185 
     186        // send random number 
     187        if (write(sock_fd, &rand_no, 4) == -1) { 
     188                logmsg(LOG_ERR, 1, "SubmitNebula Error - Writing to socket failed: %m.\n"); 
     189                close(sock_fd); 
     190                return(-1); 
     191        } 
     192 
     193        // send hashed secret 
     194        if (write(sock_fd, sha512sum, 128) == -1) { 
    174195                logmsg(LOG_ERR, 1, "SubmitNebula Error - Writing to socket failed: %m.\n"); 
    175196                close(sock_fd); 
     
    185206 
    186207 
    187         if (!read_line(sock_fd, (char *) response, 9, 10)) { 
     208        if (!read_line(sock_fd, (char *) &response, 9, 10)) { 
    188209                logmsg(LOG_WARN, 1, "SubmitNebula Warning - Nebula server did not respond within 10 seconds, skipping submission.\n"); 
    189210                close(sock_fd); 
     
    195216                return(0); 
    196217        } 
    197         else if (strncmp((char *) response, "UNKNOWN", 5) != 0) { 
     218        if (strncmp((char *) response, "UNKNOWN", 7)) { 
    198219                logmsg(LOG_WARN, 1, "SubmitNebula - Nebula server returned an invalid response, skipping submission.\n"); 
    199220                close(sock_fd);