Improved DGA detection skipping names containign at least 3 consecutive digits in the first word

This commit is contained in:
Luca Deri
2022-03-26 09:59:55 +01:00
parent aeb5f1f947
commit 856d7d2916
2 changed files with 28 additions and 4 deletions
+1
View File
@@ -3651,6 +3651,7 @@ static void dgaUnitTest() {
};
const char *non_dga[] = {
"100x100design.com",
"mz.gov.pl",
"zoomam104zc.zoom.us",
"5CI_DOMBIN",
+27 -4
View File
@@ -8101,8 +8101,12 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
tmp[j] = '\0';
len = j;
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)) {
if(!word) break;
u_int num_consecutive_digits = 0;
if(!word) break; else num_word++;
num_words++;
@@ -8114,7 +8118,16 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
trigram_char_skip = 0;
for(i = 0; word[i+1] != '\0'; i++) {
switch(word[i]) {
if(isdigit(word[i]))
num_consecutive_digits++;
else {
if((num_word == 1) && (num_consecutive_digits > max_num_consecutive_digits_first_word))
max_num_consecutive_digits_first_word = num_consecutive_digits;
num_consecutive_digits = 0;
}
switch(word[i]) {
case '-':
num_dash++;
/*
@@ -8133,7 +8146,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
case '.':
continue;
break;
break;
}
num_bigram_checks++;
@@ -8180,8 +8193,14 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
}
}
} /* for */
} /* for */
if((num_word == 1) && (num_consecutive_digits > max_num_consecutive_digits_first_word))
max_num_consecutive_digits_first_word = num_consecutive_digits;
} /* for */
if(ndpi_verbose_dga_detection)
printf("[NDPI] max_num_consecutive_digits_first_word=%u\n", max_num_consecutive_digits_first_word);
if(ndpi_verbose_dga_detection)
printf("[%s][num_found: %u][num_impossible: %u][num_digits: %u][num_bigram_checks: %u][num_vowels: %u/%u][num_trigram_vowels: %u][num_trigram_found: %u/%u][vowels: %u][rc: %u]\n",
name, num_found, num_impossible, num_digits, num_bigram_checks, num_vowels, len, num_trigram_vowels,
@@ -8212,6 +8231,10 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
if(num_dash > 2)
rc = 0;
/* Skip names whose first word item has at least 3 consecutive digits */
if(max_num_consecutive_digits_first_word > 2)
rc = 0;
if(ndpi_verbose_dga_detection) {
if(rc)
printf("DGA %s [num_found: %u][num_impossible: %u]\n",