diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/ndpi_private.h | 2 | ||||
-rw-r--r-- | src/include/ndpi_protocol_ids.h | 2 | ||||
-rw-r--r-- | src/include/ndpi_typedefs.h | 3 | ||||
-rw-r--r-- | src/lib/ndpi_main.c | 8 | ||||
-rw-r--r-- | src/lib/protocols/redis_net.c | 94 | ||||
-rw-r--r-- | src/lib/protocols/resp.c | 81 |
6 files changed, 87 insertions, 103 deletions
diff --git a/src/include/ndpi_private.h b/src/include/ndpi_private.h index 8802421d6..ecb4dae04 100644 --- a/src/include/ndpi_private.h +++ b/src/include/ndpi_private.h @@ -565,7 +565,7 @@ void init_quake_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_in void init_quic_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); void init_radius_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); void init_rdp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); -void init_redis_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); +void init_resp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); void init_rsync_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); void init_rtcp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); void init_rtmp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id); diff --git a/src/include/ndpi_protocol_ids.h b/src/include/ndpi_protocol_ids.h index cd3729994..d614c5297 100644 --- a/src/include/ndpi_protocol_ids.h +++ b/src/include/ndpi_protocol_ids.h @@ -210,7 +210,7 @@ typedef enum { NDPI_PROTOCOL_EBAY = 179, NDPI_PROTOCOL_CNN = 180, NDPI_PROTOCOL_MEGACO = 181, - NDPI_PROTOCOL_REDIS = 182, + NDPI_PROTOCOL_RESP = 182, NDPI_PROTOCOL_PINTEREST = 183, NDPI_PROTOCOL_VHUA = 184, NDPI_PROTOCOL_TELEGRAM = 185, diff --git a/src/include/ndpi_typedefs.h b/src/include/ndpi_typedefs.h index 06adf1f55..72e2cd704 100644 --- a/src/include/ndpi_typedefs.h +++ b/src/include/ndpi_typedefs.h @@ -1413,9 +1413,6 @@ struct ndpi_flow_struct { ndpi_protocol_category_t category; - /* NDPI_PROTOCOL_REDIS */ - u_int8_t redis_s2d_first_char, redis_d2s_first_char; - /* Only packets with L5 data (ie no TCP SYN, pure ACKs, ...) */ u_int16_t packet_counter; // can be 0 - 65000 u_int16_t packet_direction_counter[2]; diff --git a/src/lib/ndpi_main.c b/src/lib/ndpi_main.c index df70e26ab..0ecf3b6a3 100644 --- a/src/lib/ndpi_main.c +++ b/src/lib/ndpi_main.c @@ -1682,8 +1682,8 @@ static void ndpi_init_protocol_defaults(struct ndpi_detection_module_struct *ndp "Megaco", NDPI_PROTOCOL_CATEGORY_VOIP, ndpi_build_default_ports(ports_a, 0, 0, 0, 0, 0), /* TCP */ ndpi_build_default_ports(ports_b, 2944, 0, 0, 0, 0)); /* UDP */ - ndpi_set_proto_defaults(ndpi_str, 1 /* cleartext */, 0 /* nw proto */, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_REDIS, - "Redis", NDPI_PROTOCOL_CATEGORY_DATABASE, + ndpi_set_proto_defaults(ndpi_str, 1 /* cleartext */, 0 /* nw proto */, NDPI_PROTOCOL_ACCEPTABLE, NDPI_PROTOCOL_RESP, + "RESP", NDPI_PROTOCOL_CATEGORY_DATABASE, ndpi_build_default_ports(ports_a, 6379, 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_ZMQ, @@ -5511,8 +5511,8 @@ static int ndpi_callback_init(struct ndpi_detection_module_struct *ndpi_str) { /* MEGACO */ init_megaco_dissector(ndpi_str, &a); - /* REDIS */ - init_redis_dissector(ndpi_str, &a); + /* RESP */ + init_resp_dissector(ndpi_str, &a); /* VHUA */ init_vhua_dissector(ndpi_str, &a); diff --git a/src/lib/protocols/redis_net.c b/src/lib/protocols/redis_net.c deleted file mode 100644 index a25d72f0c..000000000 --- a/src/lib/protocols/redis_net.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * redis.c - * - * Copyright (C) 2011-22 - 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/>. - * - */ - -#include "ndpi_protocol_ids.h" - -#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_REDIS - -#include "ndpi_api.h" -#include "ndpi_private.h" - - -static void ndpi_int_redis_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { - ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_REDIS, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); -} - - -static void ndpi_check_redis(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { - struct ndpi_packet_struct *packet = &ndpi_struct->packet; - - /* Break after 10 packets. */ - if(flow->packet_counter > 10) { - NDPI_EXCLUDE_PROTO(ndpi_struct, flow); - return; - } - - if(packet->packet_direction == 0) - flow->redis_s2d_first_char = packet->payload[0]; - else - flow->redis_d2s_first_char = packet->payload[0]; - - if((flow->redis_s2d_first_char != '\0') && (flow->redis_d2s_first_char != '\0')) { - /* - *1 - $4 - PING - +PONG - *3 - $3 - SET - $19 - dns.cache.127.0.0.1 - $9 - localhost - +OK - */ - - if(((flow->redis_s2d_first_char == '*') - && ((flow->redis_d2s_first_char == '+') || (flow->redis_d2s_first_char == ':'))) - || ((flow->redis_d2s_first_char == '*') - && ((flow->redis_s2d_first_char == '+') || (flow->redis_s2d_first_char == ':')))) { - NDPI_LOG_INFO(ndpi_struct, "Found Redis\n"); - ndpi_int_redis_add_connection(ndpi_struct, flow); - } else { - NDPI_EXCLUDE_PROTO(ndpi_struct, flow); - } - } else - return; /* Too early */ -} - -static void ndpi_search_redis(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { - NDPI_LOG_DBG(ndpi_struct, "search Redis\n"); - - ndpi_check_redis(ndpi_struct, flow); -} - - -void init_redis_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id) -{ - ndpi_set_bitmask_protocol_detection("Redis", ndpi_struct, *id, - NDPI_PROTOCOL_REDIS, - ndpi_search_redis, - NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, - SAVE_DETECTION_BITMASK_AS_UNKNOWN, - ADD_TO_DETECTION_BITMASK); - - *id += 1; -} diff --git a/src/lib/protocols/resp.c b/src/lib/protocols/resp.c new file mode 100644 index 000000000..330124bea --- /dev/null +++ b/src/lib/protocols/resp.c @@ -0,0 +1,81 @@ +/* + * resp.c + * + * Redis Serialization Protocol + * + * Copyright (C) 2024 - ntop.org + * Copyright (C) 2024 - V.G <jacendi@protonmail.com> + * + * 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_RESP + +#include "ndpi_api.h" +#include "ndpi_private.h" + +static void ndpi_search_resp(struct ndpi_detection_module_struct *ndpi_struct, + struct ndpi_flow_struct *flow) +{ + struct ndpi_packet_struct const * const packet = &ndpi_struct->packet; + + NDPI_LOG_DBG(ndpi_struct, "search RESP\n"); + + if (packet->payload_packet_len < 10) + goto exclude; + + switch(packet->payload[0]) + { + case '*': + case '$': + case '~': + break; + default: + goto exclude; + } + + u_int8_t offset = 1; + while (offset < 4 && packet->payload[offset] != '\r') + { + if (!ndpi_isdigit(packet->payload[offset])) + goto exclude; + offset++; + } + + if (memcmp(&packet->payload[offset], "\r\n", 2) == 0) { + NDPI_LOG_INFO(ndpi_struct, "found RESP\n"); + ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RESP, + NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); + } + +exclude: + NDPI_EXCLUDE_PROTO(ndpi_struct, flow); +} + +void init_resp_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id) +{ + ndpi_set_bitmask_protocol_detection("RESP", ndpi_struct, *id, + NDPI_PROTOCOL_RESP, + ndpi_search_resp, + NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION, + SAVE_DETECTION_BITMASK_AS_UNKNOWN, + ADD_TO_DETECTION_BITMASK); + *id += 1; +} |