Changeset 1408

Show
Ignore:
Timestamp:
10/08/07 20:41:00 (11 months ago)
Author:
till
Message:

honeytrap
- improved ip address validation

Files:

Legend:

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

    r1387 r1408  
    160160                        } 
    161161                        logmsg(LOG_DEBUG, 1, "FTP download - %s resolves to %s.\n", token.string, 
    162                                 inet_ntoa(*(struct in_addr*)host->h_addr_list[0])); 
    163  
    164                         if (!replace_private_ips && !valid_ipaddr((uint32_t) *(host->h_addr_list[0]))) { 
     162                                inet_ntoa(*(struct in_addr*)host->h_addr)); 
     163 
     164                        if (!replace_private_ips && !valid_ipaddr(*(struct in_addr*)host->h_addr)) { 
    165165                                logmsg(LOG_INFO, 1, "FTP download error - %s is not a valid ip address.\n", 
    166166                                        inet_ntoa(*(struct in_addr*)host->h_addr_list[0])); 
     
    337337 
    338338        /* replace private ip? */ 
    339         if (replace_private_ips && (private_ipaddr(rhost->s_addr) || !(valid_ipaddr(rhost->s_addr)))) { 
     339        if (replace_private_ips && (private_ipaddr(*rhost) || !(valid_ipaddr(*rhost)))) { 
    340340                logmsg(LOG_NOISY, 1, "FTP download - Replacing private/invalid server address with attacking IP address.\n"); 
    341341                rhost = (struct in_addr *) &attack->a_conn.r_addr; 
     
    500500                        inet_ntoa(*(struct in_addr*)data_host->h_addr_list[0])); 
    501501 
    502                 if (!valid_ipaddr((uint32_t) *(data_host->h_addr_list[0]))) { 
     502                if (!valid_ipaddr(*(struct in_addr*)data_host->h_addr)) { 
    503503                        logmsg(LOG_INFO, 1, "FTP download error - %s is not a valid ip address.\n", 
    504504                                inet_ntoa(*(struct in_addr*)data_host->h_addr_list[0])); 
  • honeytrap/trunk/src/modules/htm_tftpDownload.c

    r1356 r1408  
    113113                                inet_ntoa(*(struct in_addr*)host->h_addr_list[0])); 
    114114 
    115                         if (!replace_private_ips && !valid_ipaddr((uint32_t) *(host->h_addr_list[0]))) { 
     115                        if (!replace_private_ips && !valid_ipaddr(*(struct in_addr*)host->h_addr)) { 
    116116                                logmsg(LOG_INFO, 1, "TFTP download error - %s is not a valid ip address.\n", 
    117117                                        inet_ntoa(*(struct in_addr*)host->h_addr_list[0])); 
     
    174174 
    175175        /* replace private ip? */ 
    176         if (replace_private_ips && (private_ipaddr(host->s_addr) || !(valid_ipaddr(host->s_addr)))) { 
     176        if (replace_private_ips && (private_ipaddr(*host) || !(valid_ipaddr(*host)))) { 
    177177                logmsg(LOG_NOISY, 1, "TFTP download - Replacing private/invalid server address with attacking IP address.\n"); 
    178178                host = (struct in_addr *) &attack->a_conn.r_addr; 
  • honeytrap/trunk/src/util.c

    r1355 r1408  
    2929 
    3030/* check if 'address' is an ip address with a reasonable value */ 
    31 int valid_ipaddr(uint32_t address) { 
    32         return(address > 0xffffff ? 1 : 0); 
     31int valid_ipaddr(struct in_addr address) { 
     32        u_char octet[4]; 
     33 
     34        octet[0] = address.s_addr; 
     35        octet[1] = address.s_addr >> 8; 
     36        octet[2] = address.s_addr >> 16; 
     37        octet[3] = address.s_addr >> 24; 
     38 
     39        if (!octet[0] || !octet[3]) return(0); 
     40        if (address.s_addr == 0xffffffff) return(0); 
     41 
     42        return(1); 
    3343} 
    3444 
    3545 
    3646/* test if 'address' is a rfc1918 ip address */ 
    37 int private_ipaddr(uint32_t address) { 
     47int private_ipaddr(struct in_addr address) { 
    3848        int i; 
    3949 
    4050        for (i=0; i<(sizeof(priv_prefixes)/4); i++) 
    41                 if ((ntohl(address) & priv_prefixes[i]) == ntohl(address)) return(1); 
     51                if ((ntohl(address.s_addr) & priv_prefixes[i]) == ntohl(address.s_addr)) return(1); 
    4252 
    4353        return(0); 
  • honeytrap/trunk/src/util.h

    r1334 r1408  
    3030 
    3131 
    32 int valid_ipaddr(uint32_t address); 
    33 int private_ipaddr(uint32_t address); 
     32int valid_ipaddr(struct in_addr address); 
     33int private_ipaddr(struct in_addr address); 
    3434int read_line(int socket, char *line, ssize_t len, int timeout); 
    3535struct strtk extract_token(char *parse_string);