Changeset 1440

Show
Ignore:
Timestamp:
11/20/07 17:58:04 (9 months ago)
Author:
till
Message:

honeytrap
- Fix: improper logging of IP address pairs

Files:

Legend:

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

    r1425 r1440  
     1Version 1.0.1 
     2- Fix: Improper logging of IP address pairs 
    13Version 1.0.0 
    24- Improved configure script 
  • honeytrap/trunk/src/dynsrv.c

    r1361 r1440  
    6565        int                     status; 
    6666#endif 
    67         socklen_t               client_addr_len; 
    68         struct sockaddr_in      client_addr, server_addr; 
     67        socklen_t               cliaddr_len, srvaddr_len; 
     68        struct sockaddr_in      cliaddr, srvaddr; 
    6969        struct timeval          c_timeout; 
    7070        struct hostent          *proxy_addr; 
     
    105105                if (proto == TCP) { 
    106106                        logmsg(LOG_DEBUG, 1, "Requesting tcp socket.\n"); 
    107                         if ((listen_fd = get_boundsock(&server_addr, port_l, SOCK_STREAM)) == -1) 
     107                        if ((listen_fd = get_boundsock(&srvaddr, port_l, SOCK_STREAM)) == -1) 
    108108                                exit(EXIT_SUCCESS); 
    109109                        if (port_flags_tcp[htons(port_l)]) 
     
    111111                } else if (proto == UDP) { 
    112112                        logmsg(LOG_DEBUG, 1, "Requesting udp socket.\n"); 
    113                         if ((listen_fd = get_boundsock(&server_addr, port_l, SOCK_DGRAM)) == -1) 
     113                        if ((listen_fd = get_boundsock(&srvaddr, port_l, SOCK_DGRAM)) == -1) 
    114114                                exit(EXIT_SUCCESS); 
    115115                        if (port_flags_udp[htons(port_l)]) 
     
    192192                                if (FD_ISSET(sigpipe[0], &rfds) && (check_sigpipe() == -1)) exit(EXIT_FAILURE); 
    193193                                if (FD_ISSET(listen_fd, &rfds)) { 
    194                                         if ((ip_l_str = strdup(inet_ntoa(ip_l))) == NULL) { 
    195                                                 logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %m.\n"); 
    196                                                 exit(EXIT_FAILURE); 
    197                                         } 
    198                                         if ((ip_r_str = strdup(inet_ntoa(ip_r))) == NULL) { 
    199                                                 logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %m.\n"); 
    200                                                 exit(EXIT_FAILURE); 
    201                                         } 
    202                                         logmsg(LOG_INFO, 1, "   %s  Handling %s connection request from %s:%d to %s:%d.\n", 
    203                                                 portstr, PROTO(proto), ip_r_str, ntohs(port_r), ip_l_str, ntohs(port_l)); 
    204                                         free(ip_r_str); 
    205                                         free(ip_l_str); 
    206  
    207                                         /* initialize attack record */ 
    208                                         if ((attack = new_attack(ip_l, ip_r, ntohs(port_l), 0, proto)) == NULL) { 
    209                                                 logmsg(LOG_ERR, 1, "Error - Could not initialize attack record.\n"); 
    210                                                 free(attack); 
    211                                                 exit(EXIT_FAILURE); 
    212                                         } 
    213194 
    214195 
    215196                                        /* accept connection depending on protocol */ 
    216                                         bzero(&client_addr, sizeof(client_addr)); 
    217                                         client_addr_len = sizeof(client_addr); 
     197                                        bzero(&cliaddr, sizeof(cliaddr)); 
     198                                        cliaddr_len = sizeof(cliaddr); 
    218199                                        established = 0; 
    219200 
     
    222203                                                /* accept tcp connection request */ 
    223204                                                if ((connection_fd = accept(listen_fd, (struct sockaddr *) 
    224                                                                             &client_addr, &client_addr_len)) < 0) { 
     205                                                                            &cliaddr, &cliaddr_len)) < 0) { 
    225206                                                        if (errno == EINTR) 
    226207                                                                break; 
     
    238219                                        case UDP: 
    239220                                                connection_fd = dup(listen_fd); 
    240                                                 client_addr.sin_family = AF_INET; 
    241                                                 client_addr.sin_addr = ip_r; 
    242                                                 client_addr.sin_port = port_r; 
     221                                                cliaddr.sin_family = AF_INET; 
     222                                                cliaddr.sin_addr = ip_r; 
     223                                                cliaddr.sin_port = port_r; 
    243224 
    244225                                                /* connecting our udp socket enables us to use read() and write() */ 
    245226                                                if (connect 
    246                                                     (connection_fd, (struct sockaddr *) &client_addr, 
    247                                                      client_addr_len) < 0) { 
     227                                                    (connection_fd, (struct sockaddr *) &cliaddr, 
     228                                                     cliaddr_len) < 0) { 
    248229                                                        if (errno == EINTR) 
    249230                                                                break; 
     
    260241                                                /* update remote endpoint information for attack structure */ 
    261242                                                if (getpeername 
    262                                                     (connection_fd, (struct sockaddr *) &client_addr, 
    263                                                      &client_addr_len) < 0) { 
     243                                                    (connection_fd, (struct sockaddr *) &cliaddr, 
     244                                                     &cliaddr_len) < 0) { 
    264245                                                        if (errno == EINTR) 
    265246                                                                break; 
     
    282263                                         
    283264 
     265                                        /* get remote socket endpoint info */ 
     266                                        cliaddr_len = sizeof(cliaddr); 
     267                                        if (getpeername(connection_fd, (struct sockaddr *) &cliaddr, (socklen_t *) &cliaddr_len) != 0) { 
     268                                                logmsg(LOG_ERR, 1, "Error - Could not get client info from socket: %s.\n", strerror(errno)); 
     269                                                exit(1); 
     270                                        } 
     271                                        if ((ip_r_str = strdup(inet_ntoa(cliaddr.sin_addr))) == NULL) { 
     272                                                logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %m.\n"); 
     273                                                exit(EXIT_FAILURE); 
     274                                        } 
     275 
     276                                        /* get local socket endpoint info */ 
     277                                        srvaddr_len = sizeof(srvaddr); 
     278                                        if (getsockname(connection_fd, (struct sockaddr *) &srvaddr, (socklen_t *) &srvaddr_len) != 0) { 
     279                                                logmsg(LOG_ERR, 1, "Error - Could not get client info from socket: %s.\n", strerror(errno)); 
     280                                                exit(1); 
     281                                        } 
     282                                        srvaddr.sin_addr = ip_l; 
     283                                        if ((ip_l_str = strdup(inet_ntoa(srvaddr.sin_addr))) == NULL) { 
     284                                                logmsg(LOG_ERR, 1, "Error - Unable to allocate memory: %m.\n"); 
     285                                                exit(EXIT_FAILURE); 
     286                                        } 
     287 
     288                                        logmsg(LOG_NOTICE, 1, "   %s  Handling %s connection request from %s:%d to %s:%d.\n", 
     289                                                portstr, PROTO(proto), ip_r_str, ntohs(cliaddr.sin_port), ip_l_str, ntohs(srvaddr.sin_port)); 
     290                                        free(ip_r_str); 
     291                                        free(ip_l_str); 
     292 
     293                                        /* initialize attack record */ 
     294                                        if ((attack = new_attack(cliaddr.sin_addr, srvaddr.sin_addr, ntohs(srvaddr.sin_port), 0, proto)) == NULL) { 
     295                                                logmsg(LOG_ERR, 1, "Error - Could not initialize attack record.\n"); 
     296                                                free(attack); 
     297                                                exit(EXIT_FAILURE); 
     298                                        } 
     299                                        attack->a_conn.r_port = ntohs(cliaddr.sin_port); 
     300 
     301 
    284302                                        /* incoming connection accepted, select port mode */ 
    285                                         logmsg(LOG_NOTICE, 1, "   %s  Connection from %s:%u accepted.\n", 
    286                                                portstr, inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); 
    287                                         attack->a_conn.r_port = ntohs(client_addr.sin_port); 
    288  
    289303                                        if (port_mode & PORTCONF_NORMAL) { 
    290304                                                /* handle connection in normal mode if this port configured to be handled 'normal' */ 
     
    372386                                                               "   %s  Handling connection from %s:%u in proxy mode.\n", 
    373387                                                               portstr, 
    374                                                                inet_ntoa(client_addr.sin_addr), 
    375                                                                ntohs(client_addr.sin_port)); 
     388                                                               inet_ntoa(cliaddr.sin_addr), 
     389                                                               ntohs(cliaddr.sin_port)); 
    376390                                                        handle_connection_proxied(connection_fd, 
    377391                                                                                  PORTCONF_PROXY, 
    378392                                                                                  proxy_sock_fd, (uint16_t) 
    379393                                                                                  ntohs(port_l), 
    380                                                                                   client_addr.sin_port, 
    381                                                                                   client_addr.sin_addr, 
     394                                                                                  cliaddr.sin_port, 
     395                                                                                  cliaddr.sin_addr, 
    382396                                                                                  proto, 
    383397                                                                                  m_read_timeout, 
     
    387401                                                               "   %s  Handling connection from %s:%u in mirror mode.\n", 
    388402                                                               portstr, 
    389                                                                inet_ntoa(client_addr.sin_addr), 
    390                                                                ntohs(client_addr.sin_port)); 
     403                                                               inet_ntoa(cliaddr.sin_addr), 
     404                                                               ntohs(cliaddr.sin_port)); 
    391405                                                        handle_connection_proxied(connection_fd, 
    392406                                                                                  PORTCONF_MIRROR, 
    393407                                                                                  mirror_sock_fd, (uint16_t) 
    394408                                                                                  ntohs(port_l), 
    395                                                                                   client_addr.sin_port, 
    396                                                                                   client_addr.sin_addr, 
     409                                                                                  cliaddr.sin_port, 
     410                                                                                  cliaddr.sin_addr, 
    397411                                                                                  proto, 
    398412                                                                                  m_read_timeout, 
     
    402416                                                               "   %s  Handling connection from %s:%u in normal mode.\n", 
    403417                                                               portstr, 
    404                                                                inet_ntoa(client_addr.sin_addr), 
    405                                                                ntohs(client_addr.sin_port)); 
     418                                                               inet_ntoa(cliaddr.sin_addr), 
     419                                                               ntohs(cliaddr.sin_port)); 
    406420                                                        handle_connection_normal(connection_fd, (uint16_t) 
    407421                                                                                 ntohs(port_l), proto,