Fixed false positive with STUN detection

This commit is contained in:
Luca Deri
2019-09-26 22:18:56 +02:00
parent 7de9fd7170
commit 194cdcf581
+26 -24
View File
@@ -157,9 +157,9 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
if(flow->protos.stun_ssl.stun.num_udp_pkts > 0) { if(flow->protos.stun_ssl.stun.num_udp_pkts > 0) {
flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
} else } else
return NDPI_IS_NOT_STUN; return(NDPI_IS_NOT_STUN);
} }
if((strncmp((const char*)payload, (const char*)"RSP/", 4) == 0) if((strncmp((const char*)payload, (const char*)"RSP/", 4) == 0)
@@ -168,8 +168,10 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
goto udp_stun_found; goto udp_stun_found;
} }
msg_type = ntohs(h->msg_type); msg_type = ntohs(h->msg_type), msg_len = ntohs(h->msg_len);
msg_len = ntohs(h->msg_len);
if(msg_type == 0)
return(NDPI_IS_NOT_STUN);
/* https://www.iana.org/assignments/stun-parameters/stun-parameters.xhtml */ /* https://www.iana.org/assignments/stun-parameters/stun-parameters.xhtml */
if ((msg_type & 0x3EEF) > 0x000B && msg_type != 0x0800) { if ((msg_type & 0x3EEF) > 0x000B && msg_type != 0x0800) {
@@ -195,12 +197,12 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
if (payload_length == total_len) { if (payload_length == total_len) {
/* This is DTLS and the only protocol we know behaves like this is signal */ /* This is DTLS and the only protocol we know behaves like this is signal */
flow->guessed_host_protocol_id = NDPI_PROTOCOL_SIGNAL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_SIGNAL;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
} }
} }
} }
return NDPI_IS_NOT_STUN; return(NDPI_IS_NOT_STUN);
} }
#if 0 #if 0
@@ -236,7 +238,7 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
#endif #endif
flow->guessed_host_protocol_id = proto; flow->guessed_host_protocol_id = proto;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
} else { } else {
#ifdef DEBUG_LRU #ifdef DEBUG_LRU
printf("[LRU] NOT FOUND %u\n", key); printf("[LRU] NOT FOUND %u\n", key);
@@ -258,7 +260,7 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
if (!msg_len) { if (!msg_len) {
/* flow->protos.stun_ssl.stun.num_udp_pkts++; */ /* flow->protos.stun_ssl.stun.num_udp_pkts++; */
return NDPI_IS_NOT_STUN; /* This to keep analyzing STUN instead of giving up */ return(NDPI_IS_NOT_STUN); /* This to keep analyzing STUN instead of giving up */
} }
} }
@@ -271,11 +273,11 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
if((payload[0] == 0x80 && payload_length < 512 && ((msg_len+20) <= payload_length))) { if((payload[0] == 0x80 && payload_length < 512 && ((msg_len+20) <= payload_length))) {
flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL;
return NDPI_IS_STUN; /* This is WhatsApp Call */ return(NDPI_IS_STUN); /* This is WhatsApp Call */
} else if((payload[0] == 0x90) && (((msg_len+11) == payload_length) || } else if((payload[0] == 0x90) && (((msg_len+11) == payload_length) ||
(flow->protos.stun_ssl.stun.num_binding_requests >= 4))) { (flow->protos.stun_ssl.stun.num_binding_requests >= 4))) {
flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL;
return NDPI_IS_STUN; /* This is WhatsApp Call */ return(NDPI_IS_STUN); /* This is WhatsApp Call */
} }
if (payload[0] != 0x80 && (msg_len + 20) > payload_length) if (payload[0] != 0x80 && (msg_len + 20) > payload_length)
@@ -322,7 +324,7 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
switch(attribute) { switch(attribute) {
case 0x0103: case 0x0103:
flow->guessed_host_protocol_id = NDPI_PROTOCOL_ZOOM; flow->guessed_host_protocol_id = NDPI_PROTOCOL_ZOOM;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
break; break;
case 0x4000: case 0x4000:
@@ -330,7 +332,7 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
case 0x4002: case 0x4002:
/* These are the only messages apparently whatsapp voice can use */ /* These are the only messages apparently whatsapp voice can use */
flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
break; break;
case 0x0014: /* Realm */ case 0x0014: /* Realm */
@@ -352,10 +354,10 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
if (strstr((char*) flow->host_server_name, "google.com") != NULL) { if (strstr((char*) flow->host_server_name, "google.com") != NULL) {
flow->guessed_host_protocol_id = NDPI_PROTOCOL_HANGOUT_DUO; flow->guessed_host_protocol_id = NDPI_PROTOCOL_HANGOUT_DUO;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
} else if (strstr((char*) flow->host_server_name, "whispersystems.org") != NULL) { } else if (strstr((char*) flow->host_server_name, "whispersystems.org") != NULL) {
flow->guessed_host_protocol_id = NDPI_PROTOCOL_SIGNAL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_SIGNAL;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
} }
} }
} }
@@ -365,14 +367,14 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
if (msg_type == 0x0001) { if (msg_type == 0x0001) {
if ((msg_len == 100) || (msg_len == 104)) { if ((msg_len == 100) || (msg_len == 104)) {
flow->guessed_host_protocol_id = NDPI_PROTOCOL_MESSENGER; flow->guessed_host_protocol_id = NDPI_PROTOCOL_MESSENGER;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
} else if(msg_len == 76) { } else if(msg_len == 76) {
#if 0 #if 0
if(1) { if(1) {
flow->guessed_host_protocol_id = NDPI_PROTOCOL_HANGOUT_DUO; flow->guessed_host_protocol_id = NDPI_PROTOCOL_HANGOUT_DUO;
return NDPI_IS_NOT_STUN; /* This case is found also with signal traffic */ return(NDPI_IS_NOT_STUN); /* This case is found also with signal traffic */
} else } else
return NDPI_IS_STUN; return(NDPI_IS_STUN);
#endif #endif
} }
} }
@@ -389,7 +391,7 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
printf("==> Skype found\n"); printf("==> Skype found\n");
#endif #endif
flow->guessed_host_protocol_id = NDPI_PROTOCOL_SKYPE_CALL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_SKYPE_CALL;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
} }
break; break;
@@ -410,7 +412,7 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
#endif #endif
flow->guessed_host_protocol_id = NDPI_PROTOCOL_SKYPE_CALL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_SKYPE_CALL;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
break; break;
case 0x8070: /* Implementation Version */ case 0x8070: /* Implementation Version */
@@ -422,13 +424,13 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
#endif #endif
flow->guessed_host_protocol_id = NDPI_PROTOCOL_SKYPE_CALL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_SKYPE_CALL;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
} }
break; break;
case 0xFF03: case 0xFF03:
flow->guessed_host_protocol_id = NDPI_PROTOCOL_HANGOUT_DUO; flow->guessed_host_protocol_id = NDPI_PROTOCOL_HANGOUT_DUO;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
break; break;
default: default:
@@ -444,15 +446,15 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
goto udp_stun_found; goto udp_stun_found;
} else if(msg_type == 0x0800) { } else if(msg_type == 0x0800) {
flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
} }
} }
if ((flow->protos.stun_ssl.stun.num_udp_pkts > 0) && (msg_type <= 0x00FF)) { if ((flow->protos.stun_ssl.stun.num_udp_pkts > 0) && (msg_type <= 0x00FF)) {
flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL; flow->guessed_host_protocol_id = NDPI_PROTOCOL_WHATSAPP_CALL;
return NDPI_IS_STUN; return(NDPI_IS_STUN);
} else } else
return NDPI_IS_NOT_STUN; return(NDPI_IS_NOT_STUN);
udp_stun_found: udp_stun_found:
flow->protos.stun_ssl.stun.num_processed_pkts++; flow->protos.stun_ssl.stun.num_processed_pkts++;