Implemented CIP I/O (UDP version of the CIP protocol), Common Industrial protocol

This commit is contained in:
Luca Deri
2024-01-29 13:28:41 +01:00
parent 6c08601c3d
commit 47f72443fa
80 changed files with 164 additions and 81 deletions
+1
View File
@@ -724,6 +724,7 @@ void init_yojimbo_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_
void init_stomp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
void init_radmin_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
void init_raft_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
void init_cip_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id);
#endif
+1
View File
@@ -421,6 +421,7 @@ typedef enum {
NDPI_PROTOCOL_STOMP = 390,
NDPI_PROTOCOL_RADMIN = 391,
NDPI_PROTOCOL_RAFT = 392,
NDPI_PROTOCOL_CIP = 393,
#ifdef CUSTOM_NDPI_PROTOCOLS
#include "../../../nDPI-custom/custom_ndpi_protocol_ids.h"
+12 -5
View File
@@ -2139,16 +2139,16 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 5050, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_defaults(ndpi_str, 1 /* cleartext */, 1 /* app proto */, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_MONERO,
"Monero", NDPI_PROTOCOL_CATEGORY_CRYPTO_CURRENCY,
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 0, 0, 0, 0, 0) /* UDP */);
"Monero", NDPI_PROTOCOL_CATEGORY_CRYPTO_CURRENCY,
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_DCERPC,
"DCERPC", NDPI_PROTOCOL_CATEGORY_RPC,
ndpi_build_default_ports(ports_a, 135, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 135, 0, 0, 0, 0) /* UDP */);
ndpi_set_proto_subprotocols(ndpi_str, NDPI_PROTOCOL_DCERPC,
NDPI_PROTOCOL_PROFINET_IO,
NDPI_PROTOCOL_MATCHED_BY_CONTENT,
NDPI_PROTOCOL_MATCHED_BY_CONTENT,
NDPI_PROTOCOL_NO_MORE_SUBPROTOCOLS);
ndpi_set_proto_defaults(ndpi_str, 1 /* cleartext */, 0 /* nw proto */, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_PROFINET_IO,
"PROFINET_IO", NDPI_PROTOCOL_CATEGORY_IOT_SCADA,
@@ -2222,6 +2222,10 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp
"Raft", NDPI_PROTOCOL_CATEGORY_NETWORK,
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_CIP,
"CIP", NDPI_PROTOCOL_CATEGORY_IOT_SCADA,
ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0) /* TCP */,
ndpi_build_default_ports(ports_b, 2222, 0, 0, 0, 0) /* UDP */);
#ifdef CUSTOM_NDPI_PROTOCOLS
#include "../../../nDPI-custom/custom_ndpi_main.c"
@@ -5801,7 +5805,7 @@ static int ndpi_callback_init(struct ndpi_detection_module_struct *ndpi_str) {
/* Protobuf */
init_protobuf_dissector(ndpi_str, &a);
/* ETHEREUM */
/* ETHEREUM */
init_ethereum_dissector(ndpi_str, &a);
/* Precision Time Protocol v2 */
@@ -5891,6 +5895,9 @@ static int ndpi_callback_init(struct ndpi_detection_module_struct *ndpi_str) {
/* Raft */
init_raft_dissector(ndpi_str, &a);
/* CIP (Common Industrial Protocol) */
init_cip_dissector(ndpi_str, &a);
#ifdef CUSTOM_NDPI_PROTOCOLS
#include "../../../nDPI-custom/custom_ndpi_main_init.c"
#endif
+73
View File
@@ -0,0 +1,73 @@
/*
* cip.c
*
* Copyright (C) 2018-24 - ntop.org
*
* 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/>.
*
*/
/* https://en.wikipedia.org/wiki/Common_Industrial_Protocol */
#include "ndpi_protocol_ids.h"
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_CIP
#define CIP_IO_PORT 2222
#include "ndpi_api.h"
#include "ndpi_private.h"
static void ndpi_search_cip(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet;
NDPI_LOG_DBG(ndpi_struct, "search cip\n");
if(packet->udp
&& (ntohs(packet->udp->source) == CIP_IO_PORT) && (ntohs(packet->udp->dest) == CIP_IO_PORT)
&& (packet->payload_packet_len >= 12)
&& (packet->payload_packet_len < 64)
&& (packet->payload[1] == 0x0)
) {
u_int8_t num_items = packet->payload[0], offset = 2;
while((num_items > 0) && (packet->payload_packet_len > (offset + 4))) {
// u_int16_t type_id = *((u_int16_t*)&packet->payload[offset]);
u_int16_t lenght = (packet->payload[offset+3] << 8) + packet->payload[offset+2];
offset += 4 + lenght;
}
if(offset == packet->payload_packet_len) {
NDPI_LOG_INFO(ndpi_struct,"found cip\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_CIP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
}
} else {
/* TODO add TCP dissection */
}
NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
}
void init_cip_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id) {
ndpi_set_bitmask_protocol_detection("CIP", ndpi_struct, *id,
NDPI_PROTOCOL_CIP,
ndpi_search_cip,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);
*id += 1;
}