From d2c0b9872d6f57e06a7171a2fcdbfb9b830d9fe9 Mon Sep 17 00:00:00 2001
From: Ravi Kerur <ravi.kerur@viasat.com>
Date: Wed, 25 Sep 2019 12:41:15 -0700
Subject: Initial Zoom detection based on IP and ports.

Following IP and ports are reported by Zoom support
to open up in firewall.

https://support.zoom.us/hc/en-us/articles/201362683-Network-Firewall-or-Proxy-Server-Settings-for-Zoom

Signed-off-by: Ravi Kerur <ravi.kerur@viasat.com>
---
 src/include/ndpi_protocol_ids.h  |   2 +-
 src/include/ndpi_protocols.h     |   1 +
 src/lib/ndpi_content_match.c.inc |  60 +++++++++++++++++-
 src/lib/ndpi_main.c              |   7 ++-
 src/lib/protocols/zoom.c         | 130 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 196 insertions(+), 4 deletions(-)
 create mode 100644 src/lib/protocols/zoom.c

(limited to 'src')

diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h
index c22c6f815..ac0ff42fc 100644
--- a/src/include/ndpi_protocol_ids.h
+++ b/src/include/ndpi_protocol_ids.h
@@ -223,7 +223,7 @@ typedef enum {
   NDPI_PROTOCOL_VEVO                  = 186,
   NDPI_PROTOCOL_PANDORA               = 187,
   NDPI_PROTOCOL_QUIC                  = 188, /* Andrea Buscarinu <andrea.buscarinu@gmail.com> - Michele Campus <michelecampus5@gmail.com> */
-  NDPI_PROTOCOL_FREE_189              = 189,
+  NDPI_PROTOCOL_ZOOM                  = 189, /* Zoom video conference. */
   NDPI_PROTOCOL_EAQ                   = 190,
   NDPI_PROTOCOL_OOKLA                 = 191,
   NDPI_PROTOCOL_AMQP                  = 192,
diff --git a/src/include/ndpi_protocols.h b/src/include/ndpi_protocols.h
index 5091b458d..f1dddd301 100644
--- a/src/include/ndpi_protocols.h
+++ b/src/include/ndpi_protocols.h
@@ -372,5 +372,6 @@ void init_modbus_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_i
 void init_line_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
 void init_wireguard_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
 void init_targus_getdata_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
+void init_zoom_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask);
 
 #endif /* __NDPI_PROTOCOLS_H__ */
diff --git a/src/lib/ndpi_content_match.c.inc b/src/lib/ndpi_content_match.c.inc
index 1693db9fd..fef2fd4e4 100644
--- a/src/lib/ndpi_content_match.c.inc
+++ b/src/lib/ndpi_content_match.c.inc
@@ -8220,6 +8220,62 @@ static ndpi_network host_protocol_list[] = {
   /* Line */
   { 0x7DD1FC00 /* 125.209.252.0/24 */, 24, NDPI_PROTOCOL_LINE },	
 
+  /* Zoom video conference app. */
+  { 0x03501480 /* 3.80.20.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x03787900 /* 3.120.121.0/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x03682280 /* 3.104.34.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x03D04800 /* 3.208.72.0/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x03D3F100 /* 3.211.241.0/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x04227D80 /* 4.34.125.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x04234080 /* 4.35.64.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x08058000 /* 8.5.128.0/23 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x0D340680 /* 13.52.6.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x0D349200 /* 13.52.146.0/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x0D726AA6 /* 13.114.106.166/32 */, 32, NDPI_PROTOCOL_ZOOM },
+  { 0x12CD5D80 /* 18.205.93.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x32EFCA00 /* 50.239.202.0/23 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x32EFCC00 /* 50.239.204.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0x343D6480 /* 52.61.100.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x34519780 /* 52.81.151.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x34C56115 /* 52.197.97.21/32 */, 32, NDPI_PROTOCOL_ZOOM },
+  { 0x34CA3EC0 /* 52.202.62.192/26 */, 26, NDPI_PROTOCOL_ZOOM },
+  { 0x34D7A800 /* 52.215.168.0/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x40454A00 /* 64.69.74.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0x407D3E00 /* 64.125.62.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0x40D39000 /* 64.211.144.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0x41279800 /* 65.39.152.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0x45AE3900 /* 69.174.57.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0x45AE6C00 /* 69.174.108.0/22 */, 22, NDPI_PROTOCOL_ZOOM },
+  { 0x634F1400 /* 99.79.20.0/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0x677AA600 /* 103.122.166.0/23 */, 23, NDPI_PROTOCOL_ZOOM },
+  { 0x6D5EA000 /* 109.94.160.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0x736E9AC0 /* 115.110.154.192/26 */, 26, NDPI_PROTOCOL_ZOOM },
+  { 0x737238C0 /* 115.114.56.192/26 */, 26, NDPI_PROTOCOL_ZOOM },
+  { 0x73727300 /* 115.114.115.0/26 */, 26, NDPI_PROTOCOL_ZOOM },
+  { 0x73728300 /* 115.114.131.0/26 */, 26, NDPI_PROTOCOL_ZOOM },
+  { 0x781D9400 /* 120.29.148.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0xA0013880 /* 160.1.56.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0xA1C78800 /* 161.199.136.0/22 */, 22, NDPI_PROTOCOL_ZOOM },
+  { 0xA20CE800 /* 162.12.232.0/22 */, 22, NDPI_PROTOCOL_ZOOM },
+  { 0xA2FF2400 /* 162.255.36.0/22 */, 22, NDPI_PROTOCOL_ZOOM },
+  { 0xA5FE5800 /* 165.254.88.0/23 */, 23, NDPI_PROTOCOL_ZOOM },
+  { 0xC0CC0C00 /* 192.204.12.0/22 */, 22, NDPI_PROTOCOL_ZOOM },
+  { 0xCAB1CF80 /* 202.177.207.128/27 */, 27, NDPI_PROTOCOL_ZOOM },
+  { 0xCAB1D560 /* 202.177.213.96/27 */, 27, NDPI_PROTOCOL_ZOOM },
+  { 0xCC506800 /* 204.80.104.0/21 */, 21, NDPI_PROTOCOL_ZOOM },
+  { 0xCC8D1C00 /* 204.141.28.0/22 */, 22, NDPI_PROTOCOL_ZOOM },
+  { 0xCFE28400 /* 207.226.132.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0xD109D300 /* 209.9.211.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0xD109D700 /* 209.9.215.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0xD2393700 /* 210.57.55.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0xD5139000 /* 213.19.144.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0xD5139900 /* 213.19.153.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0xD5F48C00 /* 213.244.140.0/24 */, 24, NDPI_PROTOCOL_ZOOM },
+  { 0xDD7A5840 /* 221.122.88.64/27 */, 27, NDPI_PROTOCOL_ZOOM },
+  { 0xDD7A5880 /* 221.122.88.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  { 0xDD7A5980 /* 221.122.89.128/25 */, 25, NDPI_PROTOCOL_ZOOM },
+  /* 2620:123:2000::/44 IPV6 */
+
   { 0x0, 0, 0 }
 };
 
@@ -8593,7 +8649,9 @@ ndpi_protocol_match host_match[] = {
   { "hotspotshield.com", NULL, "hotspotshield" TLD,                    "HotspotShield",    NDPI_PROTOCOL_HOTSPOT_SHIELD, NDPI_PROTOCOL_CATEGORY_VPN, NDPI_PROTOCOL_POTENTIALLY_DANGEROUS },
   { ".northghost.com", NULL, "\\.northghost" TLD,                      "HotspotShield",    NDPI_PROTOCOL_HOTSPOT_SHIELD, NDPI_PROTOCOL_CATEGORY_VPN, NDPI_PROTOCOL_POTENTIALLY_DANGEROUS },
 
-  { ".webex.com", NULL, "\\.webex" TLD,                                "Webex",            NDPI_PROTOCOL_WEBEX, NDPI_PROTOCOL_CATEGORY_VOIP, NDPI_PROTOCOL_ACCEPTABLE },
+  { ".webex.com",      NULL, "\\.webex" TLD,                           "Webex",            NDPI_PROTOCOL_WEBEX, NDPI_PROTOCOL_CATEGORY_VOIP, NDPI_PROTOCOL_ACCEPTABLE },
+  { ".zoom.us",        NULL, "\\.zoom" TLD,                            "Zoom",             NDPI_PROTOCOL_ZOOM,  NDPI_PROTOCOL_CATEGORY_VIDEO, NDPI_PROTOCOL_ACCEPTABLE },
+  { ".cloudfront.net", NULL, "\\.cloudfront" TLD,                      "Zoom",             NDPI_PROTOCOL_ZOOM, NDPI_PROTOCOL_CATEGORY_VIDEO, NDPI_PROTOCOL_ACCEPTABLE },
 
   { ".ocsdomain.com", NULL, "\\.ocsdomain" TLD,                        "OCS",              NDPI_PROTOCOL_OCS, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN },
   { "ocs.fr", NULL, "ocs" TLD,                                         "OCS",              NDPI_PROTOCOL_OCS, NDPI_PROTOCOL_CATEGORY_MEDIA, NDPI_PROTOCOL_FUN },
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index df40c5769..cd12ee6df 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -1249,9 +1249,9 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
 			    no_master, "PcAnywhere", NDPI_PROTOCOL_CATEGORY_REMOTE_ACCESS,
 			    ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
 			    ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
-    ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_FREE_189,
+    ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_ZOOM,
 			    0 /* can_have_a_subprotocol */, no_master,
-			    no_master, "Free189", NDPI_PROTOCOL_CATEGORY_VOIP,
+			    no_master, "Zoom", NDPI_PROTOCOL_CATEGORY_VIDEO,
 			    ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
 			    ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
     ndpi_set_proto_defaults(ndpi_mod, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_WHATSAPP_FILES,
@@ -3309,6 +3309,9 @@ void ndpi_set_protocol_detection_bitmask2(struct ndpi_detection_module_struct *n
   /* Targus Getdata */
   init_targus_getdata_dissector(ndpi_struct, &a, detection_bitmask);
 
+  /* ZOOM */
+  init_zoom_dissector(ndpi_struct, &a, detection_bitmask);
+
   /* ----------------------------------------------------------------- */
 
   ndpi_struct->callback_buffer_size = a;
diff --git a/src/lib/protocols/zoom.c b/src/lib/protocols/zoom.c
new file mode 100644
index 000000000..341fb1c0f
--- /dev/null
+++ b/src/lib/protocols/zoom.c
@@ -0,0 +1,130 @@
+/*
+ * zoom.c
+ *
+ * Copyright (C) 2018 by ntop.org
+ *
+ * This file is part of nDPI, an open source deep packet inspection
+ * library based on the OpenDPI and PACE technology by ipoque GmbH
+ *
+ * nDPI is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * nDPI is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "ndpi_protocol_ids.h"
+
+#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_ZOOM
+
+#include "ndpi_api.h"
+
+static u_int8_t is_zoom_tcp_port(struct ndpi_flow_struct *flow) {
+
+  struct ndpi_packet_struct *packet = &flow->packet;
+  u_int16_t dport = ntohs(packet->tcp->dest);
+
+  if((dport == 8801) || (dport == 8802) || (dport == 5090) || (dport == 5091)){
+    return 1;
+  }
+  return 0;
+}
+
+static u_int8_t is_zoom_udp_port(struct ndpi_flow_struct *flow) {
+
+  struct ndpi_packet_struct *packet = &flow->packet;
+  u_int16_t dport = ntohs(packet->tcp->dest);
+
+  if((dport == 3478) || (dport == 3479) || (dport == 5090) ||
+     (dport >= 8801 && dport <= 8810) || (dport >= 20000 && dport <= 64000)){
+    return 1;
+  }
+  return 0;
+}
+
+static u_int8_t zoom_ptree_match(struct ndpi_detection_module_struct *ndpi_struct, struct in_addr *pin) {
+  return((ndpi_network_ptree_match(ndpi_struct, pin) == NDPI_PROTOCOL_ZOOM) ? 1 : 0);
+}
+
+/* ******************************************* */
+
+static u_int8_t is_zoom_flow(struct ndpi_detection_module_struct *ndpi_struct,
+                             struct ndpi_flow_struct *flow) {
+  struct ndpi_packet_struct *packet = &flow->packet;
+
+  if(packet->iph) {
+    struct in_addr daddr;
+
+    daddr.s_addr = packet->iph->daddr;
+
+    if(zoom_ptree_match(ndpi_struct, &daddr)) {
+      return(1);
+    }
+  }
+
+  return(0);
+}
+
+static void ndpi_check_zoom(struct ndpi_detection_module_struct *ndpi_struct,
+				  struct ndpi_flow_struct *flow) {
+
+  struct ndpi_packet_struct *packet = &flow->packet;
+    
+  NDPI_LOG_DBG(ndpi_struct, "search Zoom video \n");
+
+  if(packet->tcp != NULL)
+    {
+      if (is_zoom_flow(ndpi_struct, flow) && is_zoom_tcp_port(flow)){
+        NDPI_LOG_INFO(ndpi_struct, "found zoom on tcp\n");
+
+        ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_ZOOM,
+                                   NDPI_PROTOCOL_UNKNOWN);
+        return;
+      }
+    }
+  else if(packet->udp != NULL)
+    {
+      if (is_zoom_flow(ndpi_struct, flow) && is_zoom_udp_port(flow)){
+        NDPI_LOG_INFO(ndpi_struct, "found zoom on udp\n");
+
+        ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_ZOOM,
+                                   NDPI_PROTOCOL_UNKNOWN);
+        return;
+      }
+    }
+  else
+    {
+      NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
+    }
+}
+
+void ndpi_search_zoom(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
+{
+  struct ndpi_packet_struct *packet = &flow->packet;
+
+  NDPI_LOG_DBG(ndpi_struct, "search zoom\n");
+
+  /* skip marked packets */
+  if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_ZOOM)
+    ndpi_check_zoom(ndpi_struct, flow);
+}
+
+
+void init_zoom_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
+{
+  ndpi_set_bitmask_protocol_detection("Zoom", ndpi_struct, detection_bitmask, *id,
+				      NDPI_PROTOCOL_ZOOM,
+				      ndpi_search_zoom,
+				      NDPI_SELECTION_BITMASK_PROTOCOL_TCP_OR_UDP_WITH_PAYLOAD,
+				      SAVE_DETECTION_BITMASK_AS_UNKNOWN,
+				      ADD_TO_DETECTION_BITMASK);
+  *id += 1;
+}
-- 
cgit v1.2.3