STUN, Hangout, Duo dissection improvements

This commit is contained in:
Luca Deri
2019-07-21 08:17:28 +02:00
parent e2d2ca5fe0
commit 72b05fed75
2 changed files with 36 additions and 18 deletions
+7 -1
View File
@@ -4088,8 +4088,14 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
if(ret.master_protocol == NDPI_PROTOCOL_STUN) { if(ret.master_protocol == NDPI_PROTOCOL_STUN) {
if(ret.app_protocol == NDPI_PROTOCOL_FACEBOOK) if(ret.app_protocol == NDPI_PROTOCOL_FACEBOOK)
ret.app_protocol = NDPI_PROTOCOL_MESSENGER; ret.app_protocol = NDPI_PROTOCOL_MESSENGER;
else if(ret.app_protocol == NDPI_PROTOCOL_GOOGLE) else if(ret.app_protocol == NDPI_PROTOCOL_GOOGLE) {
/*
As Google has recently introduced Duo,
we need to distinguish between it and hangout
thing that should be handled by the STUN dissector
*/
ret.app_protocol = NDPI_PROTOCOL_HANGOUT; ret.app_protocol = NDPI_PROTOCOL_HANGOUT;
}
} }
if(enable_guess if(enable_guess
+26 -14
View File
@@ -63,12 +63,12 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
*is_whatsapp = 0, *is_messenger = 0, *is_duo = 0; *is_whatsapp = 0, *is_messenger = 0, *is_duo = 0;
flow->protos.stun_ssl.stun.num_processed_pkts++;
if(payload_length < sizeof(struct stun_packet_header)) { if(payload_length < sizeof(struct stun_packet_header)) {
/* This looks like an invlid packet */
if(flow->protos.stun_ssl.stun.num_udp_pkts > 0) { if(flow->protos.stun_ssl.stun.num_udp_pkts > 0) {
*is_whatsapp = 1; *is_whatsapp = 1;
return NDPI_IS_STUN; /* This is WhatsApp Voice */ return(NDPI_IS_STUN); /* This is WhatsApp Voice */
} else } else
return(NDPI_IS_NOT_STUN); return(NDPI_IS_NOT_STUN);
} }
@@ -81,8 +81,18 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
msg_type = ntohs(h->msg_type) /* & 0x3EEF */, msg_len = ntohs(h->msg_len); msg_type = ntohs(h->msg_type) /* & 0x3EEF */, msg_len = ntohs(h->msg_len);
if(msg_type == 0x01 /* Binding Request */) /* https://www.iana.org/assignments/stun-parameters/stun-parameters.xhtml */
if(msg_type > 0x000C)
return(NDPI_IS_NOT_STUN);
if(msg_type == 0x01 /* Binding Request */) {
flow->protos.stun_ssl.stun.num_binding_requests++; flow->protos.stun_ssl.stun.num_binding_requests++;
if((msg_len == 0) && (flow->guessed_host_protocol_id == NDPI_PROTOCOL_GOOGLE)) {
flow->guessed_host_protocol_id = NDPI_PROTOCOL_GOOGLE_DUO;
}
}
flow->protos.stun_ssl.stun.num_udp_pkts++;
/* /*
printf("[msg_type: %04X][payload_length: %u][num_binding_request: %u]\n", printf("[msg_type: %04X][payload_length: %u][num_binding_request: %u]\n",
@@ -93,17 +103,18 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
&& (payload_length < 512) && (payload_length < 512)
&& ((msg_len+20) <= payload_length)) /* WhatsApp Voice */) { && ((msg_len+20) <= payload_length)) /* WhatsApp Voice */) {
*is_whatsapp = 1; *is_whatsapp = 1;
return NDPI_IS_STUN; /* This is WhatsApp Voice */ return(NDPI_IS_STUN); /* This is WhatsApp Voice */
} else if((payload[0] == 0x90) } else if((payload[0] == 0x90)
&& (((msg_len+11) == payload_length) /* WhatsApp Video */ && (((msg_len+11) == payload_length) /* WhatsApp Video */
|| (flow->protos.stun_ssl.stun.num_binding_requests >= 4))) { || (flow->protos.stun_ssl.stun.num_binding_requests >= 4))) {
*is_whatsapp = 2; *is_whatsapp = 2;
return NDPI_IS_STUN; /* This is WhatsApp Video */ return(NDPI_IS_STUN); /* This is WhatsApp Video */
} }
if((payload[0] != 0x80) && ((msg_len+20) > payload_length)) { if((payload[0] != 0x80) && ((msg_len+20) > payload_length))
return(NDPI_IS_NOT_STUN); return(NDPI_IS_NOT_STUN);
} else
flow->guessed_protocol_id = NDPI_PROTOCOL_STUN;
if(payload_length == (msg_len+20)) { if(payload_length == (msg_len+20)) {
if(msg_type <= 0x000b) /* http://www.3cx.com/blog/voip-howto/stun-details/ */ { if(msg_type <= 0x000b) /* http://www.3cx.com/blog/voip-howto/stun-details/ */ {
@@ -199,19 +210,19 @@ 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) {
*is_whatsapp = 1; *is_whatsapp = 1;
return NDPI_IS_STUN; /* This is WhatsApp */ return(NDPI_IS_STUN); /* This is WhatsApp */
} }
} }
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)) {
*is_whatsapp = 1; *is_whatsapp = 1;
return NDPI_IS_STUN; /* This is WhatsApp Voice */ return(NDPI_IS_STUN); /* This is WhatsApp Voice */
} else } else
return NDPI_IS_NOT_STUN; return(NDPI_IS_NOT_STUN);
udp_stun_found: udp_stun_found:
if(can_this_be_whatsapp_voice) { if(can_this_be_whatsapp_voice) {
flow->protos.stun_ssl.stun.num_udp_pkts++; flow->protos.stun_ssl.stun.num_processed_pkts++;
return((flow->protos.stun_ssl.stun.num_udp_pkts < MAX_NUM_STUN_PKTS) ? NDPI_IS_NOT_STUN : NDPI_IS_STUN); return((flow->protos.stun_ssl.stun.num_udp_pkts < MAX_NUM_STUN_PKTS) ? NDPI_IS_NOT_STUN : NDPI_IS_STUN);
} else { } else {
@@ -220,7 +231,6 @@ static ndpi_int_stun_t ndpi_int_check_stun(struct ndpi_detection_module_struct *
like GoogleHangout that might be candidates, thus we set the like GoogleHangout that might be candidates, thus we set the
guessed protocol to STUN guessed protocol to STUN
*/ */
flow->guessed_protocol_id = NDPI_PROTOCOL_STUN;
return(NDPI_IS_NOT_STUN); return(NDPI_IS_NOT_STUN);
} }
} }
@@ -268,6 +278,7 @@ void ndpi_search_stun(struct ndpi_detection_module_struct *ndpi_struct, struct n
} }
} }
/* UDP */
if(ndpi_int_check_stun(ndpi_struct, flow, packet->payload, if(ndpi_int_check_stun(ndpi_struct, flow, packet->payload,
packet->payload_packet_len, packet->payload_packet_len,
&is_whatsapp, &is_messenger, &is_duo) == NDPI_IS_STUN) { &is_whatsapp, &is_messenger, &is_duo) == NDPI_IS_STUN) {
@@ -288,7 +299,8 @@ void ndpi_search_stun(struct ndpi_detection_module_struct *ndpi_struct, struct n
} else { } else {
NDPI_LOG_INFO(ndpi_struct, "found UDP stun\n"); NDPI_LOG_INFO(ndpi_struct, "found UDP stun\n");
ndpi_int_stun_add_connection(ndpi_struct, ndpi_int_stun_add_connection(ndpi_struct,
is_whatsapp ? (is_whatsapp == 1 ? NDPI_PROTOCOL_WHATSAPP_VOICE : NDPI_PROTOCOL_WHATSAPP_VIDEO) : NDPI_PROTOCOL_STUN, is_whatsapp ? (is_whatsapp == 1 ? NDPI_PROTOCOL_WHATSAPP_VOICE : NDPI_PROTOCOL_WHATSAPP_VIDEO)
: NDPI_PROTOCOL_STUN,
flow); flow);
} }