Improved logic for checking invalid DNS queries

This commit is contained in:
Luca Deri
2024-06-23 22:27:19 +02:00
parent aa1d7247d1
commit e92568e4bb
+23 -10
View File
@@ -768,17 +768,30 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
if (hostname_is_valid == 0) if (hostname_is_valid == 0)
ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, "Invalid chars detected in domain name"); ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, "Invalid chars detected in domain name");
dot = strchr(_hostname, '.'); /* Ignore reverse DNS queries */
if(dot) { if(strstr(_hostname, ".in-addr.") == NULL) {
uintptr_t first_element_len = dot - _hostname; dot = strchr(_hostname, '.');
if(dot) {
uintptr_t first_element_len = dot - _hostname;
if((first_element_len > 48) && (!is_mdns)) { if((first_element_len > 48) && (!is_mdns)) {
/* /*
The lenght of the first element in the query is very long The lenght of the first element in the query is very long
and this might be an issue or indicate an exfiltration and this might be an issue or indicate an exfiltration
*/ */
ndpi_set_risk(flow, NDPI_DNS_SUSPICIOUS_TRAFFIC, "Long DNS host name"); if(ends_with(ndpi_struct, _hostname, "multi.surbl.org")
|| ends_with(ndpi_struct, _hostname, "spamhaus.org")
|| ends_with(ndpi_struct, _hostname, "rackcdn.com")
|| ends_with(ndpi_struct, _hostname, "akamaiedge.net")
|| ends_with(ndpi_struct, _hostname, "mx-verification.google.com")
|| ends_with(ndpi_struct, _hostname, "amazonaws.com")
)
; /* Check common domain exceptions [TODO: if the list grows too much use a different datastructure] */
else
ndpi_set_risk(flow, NDPI_DNS_SUSPICIOUS_TRAFFIC, "Long DNS host name");
}
} }
} }
@@ -790,7 +803,7 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
flow->host_server_name, flow->host_server_name,
strlen(flow->host_server_name), strlen(flow->host_server_name),
&ret_match, &ret_match,
NDPI_PROTOCOL_DNS); NDPI_PROTOCOL_DNS);
if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN) if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN)