Improved detection as non DGA for hostnames belnging to a CDN (#2068)

This commit is contained in:
Luca Deri
2023-10-23 17:49:50 +02:00
parent a443bba0dd
commit 71d768d036
+6 -4
View File
@@ -9803,10 +9803,9 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
u_int i, j, max_tmp_len = sizeof(tmp)-1; u_int i, j, max_tmp_len = sizeof(tmp)-1;
len = ndpi_snprintf(tmp, max_tmp_len, "%s", name); len = ndpi_snprintf(tmp, max_tmp_len, "%s", name);
if(len < 0) { if(len < 0) {
NDPI_LOG_DBG2(ndpi_str, "[DGA] too short"); NDPI_LOG_DBG2(ndpi_str, "[DGA] too short");
return(0); return(0);
} else } else
tmp[(u_int)len < max_tmp_len ? (u_int)len : max_tmp_len] = '\0'; tmp[(u_int)len < max_tmp_len ? (u_int)len : max_tmp_len] = '\0';
@@ -9913,7 +9912,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
u_int max_num_consecutive_digits_first_word = 0, num_word = 0; u_int max_num_consecutive_digits_first_word = 0, num_word = 0;
for(word = strtok_r(tmp, ".", &tok_tmp); ; word = strtok_r(NULL, ".", &tok_tmp)) { for(word = strtok_r(tmp, ".", &tok_tmp); ; word = strtok_r(NULL, ".", &tok_tmp)) {
u_int num_consecutive_digits = 0; u_int num_consecutive_digits = 0, word_len;
if(!word) break; else num_word++; if(!word) break; else num_word++;
@@ -9922,7 +9921,10 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
if(num_words > 2) if(num_words > 2)
break; /* Stop after the 2nd word of the domain name */ break; /* Stop after the 2nd word of the domain name */
if(strlen(word) < 5) continue; if((word_len = strlen(word)) < 5) continue;
if((word_len < 10) && (ndpi_ends_with(ndpi_str, word, "cdn") /* Content Delivery Network ? */))
continue; /* Ignore names (not too long) that end with cdn [ ssl.p.jwpcdn.com or www.awxcdn.com ] */
NDPI_LOG_DBG2(ndpi_str, "[DGA] word(%s) [%s][len: %u]\n", word, name, (unsigned int)strlen(word)); NDPI_LOG_DBG2(ndpi_str, "[DGA] word(%s) [%s][len: %u]\n", word, name, (unsigned int)strlen(word));