aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/include/ndpi_protocol_ids.h1
-rw-r--r--src/include/ndpi_protocols.h1
-rw-r--r--src/lib/ndpi_main.c7
-rw-r--r--src/lib/protocols/fins.c120
-rw-r--r--src/lib/protocols/rtp.c3
-rw-r--r--src/lib/protocols/skype.c3
6 files changed, 134 insertions, 1 deletions
diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h
index b87c0dbb8..8ef02e6f8 100644
--- a/src/include/ndpi_protocol_ids.h
+++ b/src/include/ndpi_protocol_ids.h
@@ -390,6 +390,7 @@ typedef enum {
NDPI_PROTOCOL_RTPS = 359,
NDPI_PROTOCOL_OPC_UA = 360,
NDPI_PROTOCOL_S7COMM_PLUS = 361,
+ NDPI_PROTOCOL_FINS = 362,
#ifdef CUSTOM_NDPI_PROTOCOLS
#include "../../../nDPI-custom/custom_ndpi_protocol_ids.h"
diff --git a/src/include/ndpi_protocols.h b/src/include/ndpi_protocols.h
index b003ca17b..fe14c0318 100644
--- a/src/include/ndpi_protocols.h
+++ b/src/include/ndpi_protocols.h
@@ -254,6 +254,7 @@ void init_ptpv2_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_in
void init_hart_ip_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
void init_rtps_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
void init_opc_ua_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
+void init_fins_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
/* ndpi_main.c */
extern u_int32_t ndpi_ip_port_hash_funct(u_int32_t ip, u_int16_t port);
diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c
index 1895cfda9..6d0d6399f 100644
--- a/src/lib/ndpi_main.c
+++ b/src/lib/ndpi_main.c
@@ -2146,6 +2146,10 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
"S7CommPlus", NDPI_PROTOCOL_CATEGORY_IOT_SCADA,
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_str, 1 /* cleartext */, 0 /* nw proto */, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_FINS,
+ "FINS", NDPI_PROTOCOL_CATEGORY_IOT_SCADA,
+ ndpi_build_default_ports(ports_a, 9600, 0, 0, 0, 0) /* TCP */,
+ ndpi_build_default_ports(ports_b, 9600, 0, 0, 0, 0) /* UDP */);
#ifdef CUSTOM_NDPI_PROTOCOLS
#include "../../../nDPI-custom/custom_ndpi_main.c"
@@ -5588,6 +5592,9 @@ static int ndpi_callback_init(struct ndpi_detection_module_struct *ndpi_str) {
/* OPC Unified Architecture */
init_opc_ua_dissector(ndpi_str, &a);
+ /* Factory Interface Network Service */
+ init_fins_dissector(ndpi_str, &a);
+
#ifdef CUSTOM_NDPI_PROTOCOLS
#include "../../../nDPI-custom/custom_ndpi_main_init.c"
#endif
diff --git a/src/lib/protocols/fins.c b/src/lib/protocols/fins.c
new file mode 100644
index 000000000..980697e33
--- /dev/null
+++ b/src/lib/protocols/fins.c
@@ -0,0 +1,120 @@
+/*
+ * fins.c
+ *
+ * Factory Interface Network Service
+ *
+ * Copyright (C) 2023 - ntop.org
+ * Copyright (C) V.G <jacendi@protonmail.com>
+ *
+ * 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_FINS
+
+#include "ndpi_api.h"
+#include "ndpi_private.h"
+
+struct fins_hdr {
+ u_int8_t icf; /* Information Control Field */
+ u_int8_t rsv; /* Reserved, must be set to 0 */
+ u_int8_t gct; /* Permissible number of gateways */
+ u_int8_t dna; /* Destination network address */
+ u_int8_t da1; /* Destination node address */
+ u_int8_t da2; /* Destination unit address */
+ u_int8_t sna; /* Source network address */
+ u_int8_t sa1; /* Source node address */
+ u_int8_t sa2; /* Source unit address */
+ u_int8_t sid; /* Service ID */
+};
+
+static void ndpi_int_fins_add_connection(struct ndpi_detection_module_struct * const ndpi_struct,
+ struct ndpi_flow_struct * const flow)
+{
+ ndpi_set_detected_protocol(ndpi_struct, flow,
+ NDPI_PROTOCOL_FINS,
+ NDPI_PROTOCOL_UNKNOWN,
+ NDPI_CONFIDENCE_DPI);
+}
+
+static void ndpi_search_fins(struct ndpi_detection_module_struct *ndpi_struct,
+ struct ndpi_flow_struct *flow)
+{
+ struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
+
+ /* FINS/TCP header is 20 bytes long, but it's usually followed
+ * by 10 byte FINS header and command data
+ */
+ if (packet->tcp != NULL && packet->payload_packet_len >= 20) {
+ /* The FINS/TCP header always contains the
+ * 4 byte ASCII magic value 'FINS'
+ */
+ if (memcmp(packet->payload, "FINS", 4) == 0) {
+ NDPI_LOG_INFO(ndpi_struct, "found FINS over TCP\n");
+ ndpi_int_fins_add_connection(ndpi_struct, flow);
+ return;
+ }
+ } else if ((packet->udp != NULL) &&
+ (packet->payload_packet_len > sizeof(struct fins_hdr)))
+ {
+ struct fins_hdr const * const fins = (struct fins_hdr *)packet->payload;
+
+ /* 0x80 - command, response required
+ * 0xC0 - response, response not required
+ * 0xC1 - response, response required
+ */
+ if ((fins->icf != 0x80) && (fins->icf != 0xC0) &&
+ (fins->icf != 0xC1))
+ {
+ goto not_fins;
+ }
+
+ if ((fins->dna > 0x7F) || (fins->sna > 0x7F)) {
+ goto not_fins;
+ }
+
+ if ((fins->da2 == 0x00) || (fins->da2 == 0xFE) ||
+ (fins->da2 == 0xE1) || ((fins->da2 >= 0x10) &&
+ (fins->da2 <= 0x1F)))
+ {
+ if ((fins->sa2 == 0x00) || (fins->sa2 == 0xFE) ||
+ (fins->sa2 == 0xE1) || ((fins->sa2 >= 0x10) &&
+ (fins->sa2 <= 0x1F)))
+ {
+ NDPI_LOG_INFO(ndpi_struct, "found FINS over UDP\n");
+ ndpi_int_fins_add_connection(ndpi_struct, flow);
+ return;
+ }
+ }
+ }
+
+not_fins:
+ NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
+}
+
+void init_fins_dissector(struct ndpi_detection_module_struct *ndpi_struct,
+ u_int32_t *id)
+{
+ ndpi_set_bitmask_protocol_detection("FINS", ndpi_struct, *id,
+ NDPI_PROTOCOL_FINS,
+ ndpi_search_fins,
+ NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
+ SAVE_DETECTION_BITMASK_AS_UNKNOWN,
+ ADD_TO_DETECTION_BITMASK
+ );
+
+ *id += 1;
+}
diff --git a/src/lib/protocols/rtp.c b/src/lib/protocols/rtp.c
index 078550c5b..7977f79a8 100644
--- a/src/lib/protocols/rtp.c
+++ b/src/lib/protocols/rtp.c
@@ -239,7 +239,8 @@ static void ndpi_rtp_search(struct ndpi_detection_module_struct *ndpi_struct,
NDPI_LOG_DBG(ndpi_struct, "search RTP\n");
if(d_port == 5355 || /* LLMNR_PORT */
- d_port == 5353 /* MDNS_PORT */) {
+ d_port == 5353 || /* MDNS_PORT */
+ d_port == 9600 /* FINS_PORT */) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
return;
}
diff --git a/src/lib/protocols/skype.c b/src/lib/protocols/skype.c
index e1a5583ff..5a506757f 100644
--- a/src/lib/protocols/skype.c
+++ b/src/lib/protocols/skype.c
@@ -64,6 +64,9 @@ static void ndpi_check_skype(struct ndpi_detection_module_struct *ndpi_struct, s
)
&& (packet->payload[0] != 0x30) /* Avoid invalid SNMP detection */
&& (packet->payload[0] != 0x00) /* Avoid invalid CAPWAP detection */
+ && (packet->payload[0] != 0x80) /* Avoid invalid FINS detection */
+ && (packet->payload[0] != 0xC0) /* Avoid invalid FINS detection */
+ && (packet->payload[0] != 0xC1) /* Avoid invalid FINS detection */
&& (packet->payload[2] == 0x02))) {
if(is_port(sport, dport, 8801)) {