Completed custom category implementation
This commit is contained in:
@@ -346,6 +346,7 @@ extern "C" {
|
||||
* @par ndpi_struct = the detection module
|
||||
* @par string_to_match = the string to match
|
||||
* @par string_to_match_len = the length of the string
|
||||
* @par ret_match = completed returned match information
|
||||
* @par is_host_match = value of the second field of struct ndpi_automa
|
||||
* @return the ID of the matched subprotocol
|
||||
*
|
||||
@@ -353,6 +354,7 @@ extern "C" {
|
||||
int ndpi_match_string_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
char *string_to_match,
|
||||
u_int string_to_match_len,
|
||||
ndpi_protocol_match_result *ret_match,
|
||||
u_int8_t is_host_match);
|
||||
/**
|
||||
* Check if the host passed match with a protocol
|
||||
@@ -361,6 +363,7 @@ extern "C" {
|
||||
* @par flow = the flow where match the host
|
||||
* @par string_to_match = the string to match
|
||||
* @par string_to_match_len = the length of the string
|
||||
* @par ret_match = completed returned match information
|
||||
* @par master_protocol_id = value of the ID associated to the master protocol detected
|
||||
* @return the ID of the matched subprotocol
|
||||
*
|
||||
@@ -369,6 +372,7 @@ extern "C" {
|
||||
struct ndpi_flow_struct *flow,
|
||||
char *string_to_match,
|
||||
u_int string_to_match_len,
|
||||
ndpi_protocol_match_result *ret_match,
|
||||
u_int16_t master_protocol_id);
|
||||
|
||||
|
||||
@@ -379,6 +383,7 @@ extern "C" {
|
||||
* @par flow = the flow where match the host
|
||||
* @par string_to_match = the string to match
|
||||
* @par string_to_match_len = the length of the string
|
||||
* @par ret_match = completed returned match information
|
||||
* @par master_protocol_id = value of the ID associated to the master protocol detected
|
||||
* @return the ID of the matched subprotocol
|
||||
*
|
||||
@@ -387,6 +392,7 @@ extern "C" {
|
||||
struct ndpi_flow_struct *flow,
|
||||
char *string_to_match,
|
||||
u_int string_to_match_len,
|
||||
ndpi_protocol_match_result *ret_match,
|
||||
u_int16_t master_protocol_id);
|
||||
/**
|
||||
* Exclude protocol from search
|
||||
|
||||
+41
-17
@@ -53,34 +53,55 @@ extern "C" {
|
||||
extern u_int8_t ndpi_ips_match(u_int32_t src, u_int32_t dst,
|
||||
u_int32_t net, u_int32_t num_bits);
|
||||
|
||||
u_int16_t ntohs_ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
|
||||
u_int16_t ntohs_ndpi_bytestream_to_number(const u_int8_t * str,
|
||||
u_int16_t max_chars_to_read,
|
||||
u_int16_t * bytes_read);
|
||||
|
||||
u_int32_t ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
|
||||
u_int64_t ndpi_bytestream_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
|
||||
u_int32_t ndpi_bytestream_dec_or_hex_to_number(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
|
||||
u_int64_t ndpi_bytestream_dec_or_hex_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
|
||||
u_int32_t ndpi_bytestream_to_ipv4(const u_int8_t * str, u_int16_t max_chars_to_read, u_int16_t * bytes_read);
|
||||
u_int32_t ndpi_bytestream_to_number(const u_int8_t * str, u_int16_t max_chars_to_read,
|
||||
u_int16_t * bytes_read);
|
||||
u_int64_t ndpi_bytestream_to_number64(const u_int8_t * str, u_int16_t max_chars_to_read,
|
||||
u_int16_t * bytes_read);
|
||||
u_int32_t ndpi_bytestream_dec_or_hex_to_number(const u_int8_t * str,
|
||||
u_int16_t max_chars_to_read,
|
||||
u_int16_t * bytes_read);
|
||||
u_int64_t ndpi_bytestream_dec_or_hex_to_number64(const u_int8_t * str,
|
||||
u_int16_t max_chars_to_read,
|
||||
u_int16_t * bytes_read);
|
||||
u_int32_t ndpi_bytestream_to_ipv4(const u_int8_t * str, u_int16_t max_chars_to_read,
|
||||
u_int16_t * bytes_read);
|
||||
|
||||
void ndpi_set_detected_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
u_int16_t upper_detected_protocol,
|
||||
u_int16_t lower_detected_protocol);
|
||||
|
||||
extern void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
extern void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow);
|
||||
extern void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow);
|
||||
extern void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow);
|
||||
|
||||
extern u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow, u_int16_t counter);
|
||||
extern u_int16_t ndpi_check_for_email_address(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow, u_int16_t counter);
|
||||
|
||||
extern void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow,
|
||||
extern void ndpi_int_change_packet_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
u_int16_t upper_detected_protocol,
|
||||
u_int16_t lower_detected_protocol);
|
||||
extern void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow,
|
||||
extern void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
u_int16_t upper_detected_protocol,
|
||||
u_int16_t lower_detected_protocol);
|
||||
extern void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod, ndpi_protocol_breed_t protoBreed, u_int16_t protoId,
|
||||
u_int16_t tcp_alias_protoId[2], u_int16_t udp_alias_protoId[2], char *protoName,
|
||||
extern void ndpi_int_change_category(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
ndpi_protocol_category_t protocol_category);
|
||||
|
||||
extern void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_mod,
|
||||
ndpi_protocol_breed_t protoBreed, u_int16_t protoId,
|
||||
u_int16_t tcp_alias_protoId[2],
|
||||
u_int16_t udp_alias_protoId[2], char *protoName,
|
||||
ndpi_protocol_category_t protoCategory,
|
||||
ndpi_port_range *tcpDefPorts, ndpi_port_range *udpDefPorts);
|
||||
ndpi_port_range *tcpDefPorts,
|
||||
ndpi_port_range *udpDefPorts);
|
||||
|
||||
extern void ndpi_int_reset_packet_protocol(struct ndpi_packet_struct *packet);
|
||||
extern void ndpi_int_reset_protocol(struct ndpi_flow_struct *flow);
|
||||
@@ -90,8 +111,10 @@ extern "C" {
|
||||
extern void ndpi_packet_src_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip);
|
||||
extern void ndpi_packet_dst_ip_get(const struct ndpi_packet_struct *packet, ndpi_ip_addr_t * ip);
|
||||
|
||||
extern char *ndpi_get_ip_string(struct ndpi_detection_module_struct *ndpi_struct, const ndpi_ip_addr_t * ip);
|
||||
extern char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_struct, const struct ndpi_packet_struct *packet);
|
||||
extern char *ndpi_get_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
const ndpi_ip_addr_t * ip);
|
||||
extern char *ndpi_get_packet_src_ip_string(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
const struct ndpi_packet_struct *packet);
|
||||
extern char* ndpi_get_proto_by_id(struct ndpi_detection_module_struct *ndpi_mod, u_int id);
|
||||
u_int16_t ndpi_get_proto_by_name(struct ndpi_detection_module_struct *ndpi_mod, const char *name);
|
||||
|
||||
@@ -102,7 +125,8 @@ extern "C" {
|
||||
extern u_int8_t ndpi_is_proto(ndpi_protocol p, u_int16_t proto);
|
||||
|
||||
extern u_int16_t ndpi_get_lower_proto(ndpi_protocol p);
|
||||
extern int ndpi_get_protocol_id_master_proto(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t protocol_id,
|
||||
extern int ndpi_get_protocol_id_master_proto(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
u_int16_t protocol_id,
|
||||
u_int16_t** tcp_master_proto,
|
||||
u_int16_t** udp_master_proto);
|
||||
#/* NDPI_PROTOCOL_NETBIOS */
|
||||
|
||||
@@ -1099,8 +1099,9 @@ struct ndpi_flow_struct {
|
||||
|
||||
/* protocols which have marked a connection as this connection cannot be protocol XXX, multiple u_int64_t */
|
||||
NDPI_PROTOCOL_BITMASK excluded_protocol_bitmask;
|
||||
|
||||
|
||||
ndpi_protocol_category_t category;
|
||||
|
||||
/* NDPI_PROTOCOL_REDIS */
|
||||
u_int8_t redis_s2d_first_char, redis_d2s_first_char;
|
||||
|
||||
@@ -1207,4 +1208,10 @@ typedef struct {
|
||||
u_int8_t value;
|
||||
} ndpi_network;
|
||||
|
||||
typedef struct {
|
||||
int protocol_id;
|
||||
ndpi_protocol_category_t protocol_category;
|
||||
ndpi_protocol_breed_t protocol_breed;
|
||||
} ndpi_protocol_match_result;
|
||||
|
||||
#endif /* __NDPI_TYPEDEFS_H__ */
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
# make -f Makefile.simple
|
||||
#
|
||||
CFLAGS += -fPIC -DPIC -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION -g
|
||||
RANLIB=ranlib
|
||||
RANLIB = ranlib
|
||||
|
||||
OBJECTS = $(patsubst protocols/%.c, protocols/%.o, $(wildcard protocols/*.c)) $(patsubst third_party/src/%.c, third_party/src/%.o, $(wildcard third_party/src/*.c)) ndpi_main.o
|
||||
HEADERS = $(wildcard ../include/*.h)
|
||||
|
||||
+75
-33
@@ -413,15 +413,13 @@ u_int32_t ndpi_detection_get_sizeof_ndpi_id_struct(void) { return sizeof(struct
|
||||
|
||||
/* *********************************************************************************** */
|
||||
|
||||
char * ndpi_get_proto_by_id(struct ndpi_detection_module_struct *ndpi_mod, u_int id)
|
||||
{
|
||||
char * ndpi_get_proto_by_id(struct ndpi_detection_module_struct *ndpi_mod, u_int id) {
|
||||
return((id >= ndpi_mod->ndpi_num_supported_protocols) ? NULL : ndpi_mod->proto_defaults[id].protoName);
|
||||
}
|
||||
|
||||
/* *********************************************************************************** */
|
||||
|
||||
u_int16_t ndpi_get_proto_by_name(struct ndpi_detection_module_struct *ndpi_mod, const char *name)
|
||||
{
|
||||
u_int16_t ndpi_get_proto_by_name(struct ndpi_detection_module_struct *ndpi_mod, const char *name) {
|
||||
u_int16_t i, num = ndpi_get_num_supported_protocols(ndpi_mod);
|
||||
|
||||
for(i = 0; i < num; i++)
|
||||
@@ -438,8 +436,7 @@ ndpi_port_range * ndpi_build_default_ports_range(ndpi_port_range *ports,
|
||||
u_int16_t portB_low, u_int16_t portB_high,
|
||||
u_int16_t portC_low, u_int16_t portC_high,
|
||||
u_int16_t portD_low, u_int16_t portD_high,
|
||||
u_int16_t portE_low, u_int16_t portE_high)
|
||||
{
|
||||
u_int16_t portE_low, u_int16_t portE_high) {
|
||||
int i = 0;
|
||||
|
||||
ports[i].port_low = portA_low, ports[i].port_high = portA_high; i++;
|
||||
@@ -458,8 +455,7 @@ ndpi_port_range * ndpi_build_default_ports(ndpi_port_range *ports,
|
||||
u_int16_t portB,
|
||||
u_int16_t portC,
|
||||
u_int16_t portD,
|
||||
u_int16_t portE)
|
||||
{
|
||||
u_int16_t portE) {
|
||||
int i = 0;
|
||||
|
||||
ports[i].port_low = portA, ports[i].port_high = portA; i++;
|
||||
@@ -753,8 +749,7 @@ static int ndpi_remove_host_url_subprotocol(struct ndpi_detection_module_struct
|
||||
/* ******************************************************************** */
|
||||
|
||||
void ndpi_init_protocol_match(struct ndpi_detection_module_struct *ndpi_mod,
|
||||
ndpi_protocol_match *match)
|
||||
{
|
||||
ndpi_protocol_match *match) {
|
||||
u_int16_t no_master[2] = { NDPI_PROTOCOL_NO_MASTER_PROTO, NDPI_PROTOCOL_NO_MASTER_PROTO };
|
||||
ndpi_port_range ports_a[MAX_DEFAULT_PORTS], ports_b[MAX_DEFAULT_PORTS];
|
||||
static u_int16_t generic_id = NDPI_LAST_IMPLEMENTED_PROTOCOL;
|
||||
@@ -2634,7 +2629,7 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_mod,
|
||||
else
|
||||
removeDefaultPort(&range, def, is_tcp ? &ndpi_mod->tcpRoot : &ndpi_mod->udpRoot);
|
||||
} else if(is_ip) {
|
||||
/* NDPI_PROTOCOL_TOR */
|
||||
/* NDPI_PROTOCOL_TOR */
|
||||
ndpi_add_host_ip_subprotocol(ndpi_mod, value, subprotocol_id);
|
||||
} else {
|
||||
if(do_add)
|
||||
@@ -4172,6 +4167,11 @@ int ndpi_enable_loaded_categories(struct ndpi_detection_module_struct *ndpi_str)
|
||||
void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
ndpi_protocol *ret) {
|
||||
if(flow->category != NDPI_PROTOCOL_CATEGORY_UNSPECIFIED) {
|
||||
ret->category = flow->category;
|
||||
return;
|
||||
}
|
||||
|
||||
if(ndpi_struct->custom_categories.categories_loaded) {
|
||||
if(flow->packet.iph) {
|
||||
prefix_t prefix;
|
||||
@@ -4189,7 +4189,7 @@ void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struc
|
||||
}
|
||||
|
||||
if(node) {
|
||||
ret->category = (ndpi_protocol_category_t)node->value.user_value;
|
||||
flow->category = ret->category = (ndpi_protocol_category_t)node->value.user_value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -4199,7 +4199,7 @@ void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struc
|
||||
int rc = ndpi_match_custom_category(ndpi_struct, (char *)flow->host_server_name, &id);
|
||||
|
||||
if(rc == 0) {
|
||||
ret->category = (ndpi_protocol_category_t)id;
|
||||
flow->category = ret->category = (ndpi_protocol_category_t)id;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -4209,13 +4209,13 @@ void ndpi_fill_protocol_category(struct ndpi_detection_module_struct *ndpi_struc
|
||||
int rc = ndpi_match_custom_category(ndpi_struct, (char *)flow->protos.stun_ssl.ssl.server_certificate, &id);
|
||||
|
||||
if(rc == 0) {
|
||||
ret->category = (ndpi_protocol_category_t)id;
|
||||
flow->category = ret->category = (ndpi_protocol_category_t)id;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret->category = ndpi_get_proto_category(ndpi_struct, *ret);
|
||||
flow->category = ret->category = ndpi_get_proto_category(ndpi_struct, *ret);
|
||||
}
|
||||
|
||||
/* ********************************************************************************* */
|
||||
@@ -4347,6 +4347,19 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
||||
if(flow->guessed_host_protocol_id >= (NDPI_MAX_SUPPORTED_PROTOCOLS-1)) {
|
||||
/* This is a custom protocol and it has priority over everything else */
|
||||
ret.master_protocol = NDPI_PROTOCOL_UNKNOWN, ret.app_protocol = flow->guessed_host_protocol_id;
|
||||
|
||||
if(flow->packet.tcp) {
|
||||
/* Minimal guess for HTTP/SSL-based protocols */
|
||||
switch(ntohs(flow->packet.tcp->dest)) {
|
||||
case 80:
|
||||
ret.master_protocol = NDPI_PROTOCOL_HTTP;
|
||||
break;
|
||||
case 443:
|
||||
ret.master_protocol = NDPI_PROTOCOL_SSL; /* QUIC could also match */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ndpi_check_flow_func(ndpi_struct, flow, &ndpi_selection_packet);
|
||||
ndpi_fill_protocol_category(ndpi_struct, flow, &ret);
|
||||
return(ret);
|
||||
@@ -4921,10 +4934,11 @@ void ndpi_debug_get_last_log_function_line(struct ndpi_detection_module_struct
|
||||
|
||||
/* ********************************************************************************* */
|
||||
|
||||
u_int8_t ndpi_detection_get_l4(const u_int8_t * l3, u_int16_t l3_len, const u_int8_t ** l4_return, u_int16_t * l4_len_return,
|
||||
u_int8_t * l4_protocol_return, u_int32_t flags)
|
||||
{
|
||||
return ndpi_detection_get_l4_internal(NULL, l3, l3_len, l4_return, l4_len_return, l4_protocol_return, flags);
|
||||
u_int8_t ndpi_detection_get_l4(const u_int8_t * l3, u_int16_t l3_len,
|
||||
const u_int8_t ** l4_return, u_int16_t * l4_len_return,
|
||||
u_int8_t * l4_protocol_return, u_int32_t flags) {
|
||||
return ndpi_detection_get_l4_internal(NULL, l3, l3_len,
|
||||
l4_return, l4_len_return, l4_protocol_return, flags);
|
||||
}
|
||||
|
||||
/* ********************************************************************************* */
|
||||
@@ -4932,8 +4946,7 @@ u_int8_t ndpi_detection_get_l4(const u_int8_t * l3, u_int16_t l3_len, const u_in
|
||||
void ndpi_set_detected_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
u_int16_t upper_detected_protocol,
|
||||
u_int16_t lower_detected_protocol)
|
||||
{
|
||||
u_int16_t lower_detected_protocol) {
|
||||
struct ndpi_id_struct *src = flow->src;
|
||||
struct ndpi_id_struct *dst = flow->dst;
|
||||
|
||||
@@ -4969,7 +4982,8 @@ void ndpi_int_change_flow_protocol(struct ndpi_detection_module_struct *ndpi_str
|
||||
u_int16_t lower_detected_protocol) {
|
||||
if(!flow) return;
|
||||
|
||||
flow->detected_protocol_stack[0] = upper_detected_protocol, flow->detected_protocol_stack[1] = lower_detected_protocol;
|
||||
flow->detected_protocol_stack[0] = upper_detected_protocol,
|
||||
flow->detected_protocol_stack[1] = lower_detected_protocol;
|
||||
}
|
||||
|
||||
/* ********************************************************************************* */
|
||||
@@ -5018,6 +5032,14 @@ void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
|
||||
/* ********************************************************************************* */
|
||||
|
||||
void ndpi_int_change_category(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
ndpi_protocol_category_t protocol_category) {
|
||||
flow->category = protocol_category;
|
||||
}
|
||||
|
||||
/* ********************************************************************************* */
|
||||
|
||||
/* change protocol only if guessing is active */
|
||||
/* void ndpi_guess_change_protocol(struct ndpi_detection_module_struct *ndpi_struct, */
|
||||
/* struct ndpi_flow_struct *flow) */
|
||||
@@ -5600,22 +5622,29 @@ int ndpi_match_prefix(const u_int8_t *payload, size_t payload_len,
|
||||
|
||||
int ndpi_match_string_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
char *string_to_match, u_int string_to_match_len,
|
||||
ndpi_protocol_match_result *ret_match,
|
||||
u_int8_t is_host_match) {
|
||||
AC_REP_t match = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED, NDPI_PROTOCOL_UNRATED };
|
||||
AC_TEXT_t ac_input_text;
|
||||
ndpi_automa *automa = is_host_match ? &ndpi_struct->host_automa : &ndpi_struct->content_automa;
|
||||
|
||||
if((automa->ac_automa == NULL) || (string_to_match_len == 0)) return(NDPI_PROTOCOL_UNKNOWN);
|
||||
ndpi_automa *automa = is_host_match ? &ndpi_struct->host_automa :
|
||||
&ndpi_struct->content_automa;
|
||||
AC_REP_t match = { NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_CATEGORY_UNSPECIFIED, NDPI_PROTOCOL_UNRATED };
|
||||
|
||||
if((automa->ac_automa == NULL) || (string_to_match_len == 0))
|
||||
return(NDPI_PROTOCOL_UNKNOWN);
|
||||
|
||||
if(!automa->ac_automa_finalized) {
|
||||
ac_automata_finalize((AC_AUTOMATA_t*)automa->ac_automa);
|
||||
automa->ac_automa_finalized = 1;
|
||||
}
|
||||
|
||||
|
||||
ac_input_text.astring = string_to_match, ac_input_text.length = string_to_match_len;
|
||||
ac_automata_search(((AC_AUTOMATA_t*)automa->ac_automa), &ac_input_text, &match);
|
||||
ac_automata_reset(((AC_AUTOMATA_t*)automa->ac_automa));
|
||||
|
||||
|
||||
ret_match->protocol_id = match.number,
|
||||
ret_match->protocol_category = match.category,
|
||||
ret_match->protocol_breed = match.breed;
|
||||
|
||||
return(match.number);
|
||||
}
|
||||
|
||||
@@ -5627,10 +5656,15 @@ static int ndpi_automa_match_string_subprotocol(struct ndpi_detection_module_str
|
||||
struct ndpi_flow_struct *flow,
|
||||
char *string_to_match, u_int string_to_match_len,
|
||||
u_int16_t master_protocol_id,
|
||||
ndpi_protocol_match_result *ret_match,
|
||||
u_int8_t is_host_match) {
|
||||
int matching_protocol_id = ndpi_match_string_subprotocol(ndpi_struct, string_to_match, string_to_match_len, is_host_match);
|
||||
int matching_protocol_id;
|
||||
struct ndpi_packet_struct *packet = &flow->packet;
|
||||
|
||||
matching_protocol_id = ndpi_match_string_subprotocol(ndpi_struct, string_to_match,
|
||||
string_to_match_len, ret_match,
|
||||
is_host_match);
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
char m[256];
|
||||
@@ -5650,8 +5684,9 @@ static int ndpi_automa_match_string_subprotocol(struct ndpi_detection_module_str
|
||||
packet->detected_protocol_stack[0] = matching_protocol_id;
|
||||
|
||||
flow->detected_protocol_stack[0] = packet->detected_protocol_stack[0],
|
||||
flow->detected_protocol_stack[1] = packet->detected_protocol_stack[1];
|
||||
|
||||
flow->detected_protocol_stack[1] = packet->detected_protocol_stack[1],
|
||||
flow->category = ret_match->protocol_category;
|
||||
|
||||
return(packet->detected_protocol_stack[0]);
|
||||
}
|
||||
|
||||
@@ -5679,10 +5714,15 @@ static int ndpi_automa_match_string_subprotocol(struct ndpi_detection_module_str
|
||||
struct ndpi_flow_struct *flow,
|
||||
char *string_to_match, u_int string_to_match_len,
|
||||
u_int16_t master_protocol_id,
|
||||
ndpi_automa_match_string_subprotocol *ret_match,
|
||||
u_int8_t is_host_match) {
|
||||
int rv = NDPI_PROTOCOL_UNKNOWN;
|
||||
struct hs *hs = (struct hs*)ndpi_struct->hyperscan;
|
||||
|
||||
/*
|
||||
TODO HYPERSCAN
|
||||
In case of match fill up ret_match and set flow protocol + category
|
||||
*/
|
||||
if(hs_scan(hs->database, string_to_match,
|
||||
string_to_match_len, 0, hs->scratch,
|
||||
hyperscanEventHandler, &rv) != HS_SUCCESS)
|
||||
@@ -5698,10 +5738,11 @@ static int ndpi_automa_match_string_subprotocol(struct ndpi_detection_module_str
|
||||
int ndpi_match_host_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
char *string_to_match, u_int string_to_match_len,
|
||||
ndpi_protocol_match_result *ret_match,
|
||||
u_int16_t master_protocol_id) {
|
||||
return(ndpi_automa_match_string_subprotocol(ndpi_struct,
|
||||
flow, string_to_match, string_to_match_len,
|
||||
master_protocol_id, 1));
|
||||
master_protocol_id, ret_match, 1));
|
||||
}
|
||||
|
||||
/* ****************************************************** */
|
||||
@@ -5709,10 +5750,11 @@ int ndpi_match_host_subprotocol(struct ndpi_detection_module_struct *ndpi_struct
|
||||
int ndpi_match_content_subprotocol(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
struct ndpi_flow_struct *flow,
|
||||
char *string_to_match, u_int string_to_match_len,
|
||||
ndpi_protocol_match_result *ret_match,
|
||||
u_int16_t master_protocol_id) {
|
||||
return(ndpi_automa_match_string_subprotocol(ndpi_struct, flow,
|
||||
string_to_match, string_to_match_len,
|
||||
master_protocol_id, 0));
|
||||
master_protocol_id, ret_match, 0));
|
||||
}
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
@@ -207,12 +207,16 @@ void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, struct nd
|
||||
flow->protos.dns.num_queries = (u_int8_t)dns_header.num_queries,
|
||||
flow->protos.dns.num_answers = (u_int8_t) (dns_header.num_answers + dns_header.authority_rrs + dns_header.additional_rrs);
|
||||
|
||||
if(j > 0)
|
||||
if(j > 0) {
|
||||
ndpi_protocol_match_result ret_match;
|
||||
|
||||
ndpi_match_host_subprotocol(ndpi_struct, flow,
|
||||
(char *)flow->host_server_name,
|
||||
strlen((const char*)flow->host_server_name),
|
||||
&ret_match,
|
||||
NDPI_PROTOCOL_DNS);
|
||||
|
||||
}
|
||||
|
||||
#ifdef DNS_DEBUG
|
||||
NDPI_LOG_DBG2(ndpi_struct, "[num_queries=%d][num_answers=%d][reply_code=%u][rsp_type=%u][host_server_name=%s]\n",
|
||||
flow->protos.dns.num_queries, flow->protos.dns.num_answers,
|
||||
|
||||
@@ -84,7 +84,8 @@ void ndpi_search_fbzero(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
&& (t->tag[2] == 'I') && (t->tag[3] == '\0')) {
|
||||
char *value = (char*)&packet->payload[data_offset + data_prev_offset];
|
||||
u_int tag_len = t->tag_offset_len-data_prev_offset, max_len;
|
||||
|
||||
ndpi_protocol_match_result ret_match;
|
||||
|
||||
max_len = ndpi_min(tag_len, sizeof(flow->host_server_name)-1);
|
||||
|
||||
strncpy((char*)flow->host_server_name, value, max_len);
|
||||
@@ -99,6 +100,7 @@ void ndpi_search_fbzero(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
|
||||
ndpi_match_host_subprotocol(ndpi_struct, flow, (char *)flow->host_server_name,
|
||||
strlen((const char *)flow->host_server_name),
|
||||
&ret_match,
|
||||
NDPI_PROTOCOL_FBZERO);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,8 @@ static void setHttpUserAgent(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
static void parseHttpSubprotocol(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) {
|
||||
if((flow->l4.tcp.http_stage == 0) || (flow->http.url && flow->http_detected)) {
|
||||
char *double_col = strchr((char*)flow->host_server_name, ':');
|
||||
|
||||
ndpi_protocol_match_result ret_match;
|
||||
|
||||
if(double_col) double_col[0] = '\0';
|
||||
|
||||
/**
|
||||
@@ -182,6 +183,7 @@ static void parseHttpSubprotocol(struct ndpi_detection_module_struct *ndpi_struc
|
||||
*/
|
||||
ndpi_match_host_subprotocol(ndpi_struct, flow, (char *)flow->host_server_name,
|
||||
strlen((const char *)flow->host_server_name),
|
||||
&ret_match,
|
||||
NDPI_PROTOCOL_HTTP);
|
||||
}
|
||||
}
|
||||
@@ -349,12 +351,16 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
|
||||
packet->host_line.len, packet->host_line.ptr);
|
||||
|
||||
/* call ndpi_match_host_subprotocol to see if there is a match with known-host HTTP subprotocol */
|
||||
if((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
|
||||
if((ndpi_struct->http_dont_dissect_response) || flow->http_detected) {
|
||||
ndpi_protocol_match_result ret_match;
|
||||
|
||||
ndpi_match_host_subprotocol(ndpi_struct, flow,
|
||||
(char*)packet->host_line.ptr,
|
||||
packet->host_line.len,
|
||||
&ret_match,
|
||||
NDPI_PROTOCOL_HTTP);
|
||||
|
||||
}
|
||||
|
||||
/* Copy result for nDPI apps */
|
||||
if(!ndpi_struct->disable_metadata_export) {
|
||||
len = ndpi_min(packet->host_line.len, sizeof(flow->host_server_name)-1);
|
||||
@@ -395,12 +401,16 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
|
||||
|
||||
if((flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN)
|
||||
&& ((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
|
||||
&& (packet->http_origin.len > 0))
|
||||
&& (packet->http_origin.len > 0)) {
|
||||
ndpi_protocol_match_result ret_match;
|
||||
|
||||
ndpi_match_host_subprotocol(ndpi_struct, flow,
|
||||
(char *)packet->http_origin.ptr,
|
||||
packet->http_origin.len,
|
||||
&ret_match,
|
||||
NDPI_PROTOCOL_HTTP);
|
||||
|
||||
}
|
||||
|
||||
if(flow->detected_protocol_stack[0] != NDPI_PROTOCOL_UNKNOWN) {
|
||||
if(packet->detected_protocol_stack[0] != NDPI_PROTOCOL_HTTP) {
|
||||
NDPI_LOG_INFO(ndpi_struct, "found HTTP/%s\n",
|
||||
@@ -440,10 +450,13 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
|
||||
NDPI_LOG_DBG2(ndpi_struct, "Content Type line found %.*s\n",
|
||||
packet->content_line.len, packet->content_line.ptr);
|
||||
|
||||
if((ndpi_struct->http_dont_dissect_response) || flow->http_detected)
|
||||
if((ndpi_struct->http_dont_dissect_response) || flow->http_detected) {
|
||||
ndpi_protocol_match_result ret_match;
|
||||
|
||||
ndpi_match_content_subprotocol(ndpi_struct, flow,
|
||||
(char*)packet->content_line.ptr, packet->content_line.len,
|
||||
NDPI_PROTOCOL_HTTP);
|
||||
&ret_match, NDPI_PROTOCOL_HTTP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
if((sni_offset+len) < udp_len) {
|
||||
if(!ndpi_struct->disable_metadata_export) {
|
||||
int max_len = sizeof(flow->host_server_name)-1, j = 0;
|
||||
ndpi_protocol_match_result ret_match;
|
||||
|
||||
if(len > max_len) len = max_len;
|
||||
|
||||
@@ -118,6 +119,7 @@ void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
|
||||
ndpi_match_host_subprotocol(ndpi_struct, flow,
|
||||
(char *)flow->host_server_name,
|
||||
strlen((const char*)flow->host_server_name),
|
||||
&ret_match,
|
||||
NDPI_PROTOCOL_QUIC);
|
||||
}
|
||||
}
|
||||
|
||||
+36
-31
@@ -327,13 +327,13 @@ int sslTryAndRetrieveServerCertificate(struct ndpi_detection_module_struct *ndpi
|
||||
}
|
||||
/* Client hello, Server Hello, and certificate packets probably all checked in this case */
|
||||
if ((packet->ssl_certificate_num_checks >= 3)
|
||||
&& (flow->l4.tcp.seen_syn)
|
||||
&& (flow->l4.tcp.seen_syn_ack)
|
||||
&& (flow->l4.tcp.seen_ack) /* We have seen the 3-way handshake */)
|
||||
{
|
||||
/* We're done processing extra packets since we've probably checked all possible cert packets */
|
||||
return 0;
|
||||
}
|
||||
&& (flow->l4.tcp.seen_syn)
|
||||
&& (flow->l4.tcp.seen_syn_ack)
|
||||
&& (flow->l4.tcp.seen_ack) /* We have seen the 3-way handshake */)
|
||||
{
|
||||
/* We're done processing extra packets since we've probably checked all possible cert packets */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* 1 means keep looking for more packets */
|
||||
return 1;
|
||||
@@ -368,22 +368,27 @@ int sslDetectProtocolFromCertificate(struct ndpi_detection_module_struct *ndpi_s
|
||||
#ifdef CERTIFICATE_DEBUG
|
||||
NDPI_LOG_DBG2(ndpi_struct, "***** [SSL] %s\n", certificate);
|
||||
#endif
|
||||
ndpi_protocol_match_result ret_match;
|
||||
u_int32_t subproto = ndpi_match_host_subprotocol(ndpi_struct, flow, certificate,
|
||||
strlen(certificate), NDPI_PROTOCOL_SSL);
|
||||
strlen(certificate),
|
||||
&ret_match,
|
||||
NDPI_PROTOCOL_SSL);
|
||||
|
||||
if(subproto != NDPI_PROTOCOL_UNKNOWN) {
|
||||
/* If we've detected the subprotocol from client certificate but haven't had a chance
|
||||
* to see the server certificate yet, set up extra packet processing to wait
|
||||
* a few more packets. */
|
||||
if((flow->protos.stun_ssl.ssl.client_certificate[0] != '\0') && (flow->protos.stun_ssl.ssl.server_certificate[0] == '\0')) {
|
||||
sslInitExtraPacketProcessing(0, flow);
|
||||
}
|
||||
ndpi_set_detected_protocol(ndpi_struct, flow, subproto,
|
||||
ndpi_ssl_refine_master_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SSL));
|
||||
return(rc); /* Fix courtesy of Gianluca Costa <g.costa@xplico.org> */
|
||||
}
|
||||
/* If we've detected the subprotocol from client certificate but haven't had a chance
|
||||
* to see the server certificate yet, set up extra packet processing to wait
|
||||
* a few more packets. */
|
||||
if((flow->protos.stun_ssl.ssl.client_certificate[0] != '\0') && (flow->protos.stun_ssl.ssl.server_certificate[0] == '\0')) {
|
||||
sslInitExtraPacketProcessing(0, flow);
|
||||
}
|
||||
|
||||
ndpi_set_detected_protocol(ndpi_struct, flow, subproto,
|
||||
ndpi_ssl_refine_master_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SSL));
|
||||
return(rc); /* Fix courtesy of Gianluca Costa <g.costa@xplico.org> */
|
||||
}
|
||||
|
||||
if(ndpi_is_ssl_tor(ndpi_struct, flow, certificate) != 0)
|
||||
return(rc);
|
||||
if(ndpi_is_ssl_tor(ndpi_struct, flow, certificate) != 0)
|
||||
return(rc);
|
||||
}
|
||||
|
||||
if(((packet->ssl_certificate_num_checks >= 2)
|
||||
@@ -394,9 +399,9 @@ int sslDetectProtocolFromCertificate(struct ndpi_detection_module_struct *ndpi_s
|
||||
/* || (flow->protos.stun_ssl.ssl.client_certificate[0] != '\0') */
|
||||
) {
|
||||
ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
@@ -480,7 +485,7 @@ static void ssl_mark_and_payload_search_for_other_protocols(struct
|
||||
ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL_NO_CERT);
|
||||
} else
|
||||
NDPI_LOG_INFO(ndpi_struct, "found ssl\n");
|
||||
ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL);
|
||||
ndpi_int_ssl_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_SSL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,16 +521,16 @@ static u_int8_t ndpi_search_sslv3_direction1(struct ndpi_detection_module_struct
|
||||
u_int32_t cert_start;
|
||||
|
||||
NDPI_LOG_DBG2(ndpi_struct,
|
||||
"maybe SSLv3 server hello split into smaller packets\n");
|
||||
"maybe SSLv3 server hello split into smaller packets\n");
|
||||
|
||||
/* lets hope at least the server hello and the start of the certificate block are in the first packet */
|
||||
cert_start = ntohs(get_u_int16_t(packet->payload, 7)) + 5 + 4;
|
||||
NDPI_LOG_DBG2(ndpi_struct, "suspected start of certificate: %u\n",
|
||||
cert_start);
|
||||
cert_start);
|
||||
|
||||
if(cert_start < packet->payload_packet_len && packet->payload[cert_start] == 0x0b) {
|
||||
NDPI_LOG_DBG2(ndpi_struct,
|
||||
"found 0x0b at suspected start of certificate block\n");
|
||||
"found 0x0b at suspected start of certificate block\n");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -536,16 +541,16 @@ static u_int8_t ndpi_search_sslv3_direction1(struct ndpi_detection_module_struct
|
||||
u_int32_t cert_start;
|
||||
|
||||
NDPI_LOG_DBG2(ndpi_struct,
|
||||
"maybe SSLv3 server hello split into smaller packets but with seperate record for the certificate\n");
|
||||
"maybe SSLv3 server hello split into smaller packets but with seperate record for the certificate\n");
|
||||
|
||||
/* lets hope at least the server hello record and the start of the certificate record are in the first packet */
|
||||
cert_start = ntohs(get_u_int16_t(packet->payload, 7)) + 5 + 5 + 4;
|
||||
NDPI_LOG_DBG2(ndpi_struct, "suspected start of certificate: %u\n",
|
||||
cert_start);
|
||||
cert_start);
|
||||
|
||||
if(cert_start < packet->payload_packet_len && packet->payload[cert_start] == 0x0b) {
|
||||
NDPI_LOG_DBG2(ndpi_struct,
|
||||
"found 0x0b at suspected start of certificate block\n");
|
||||
"found 0x0b at suspected start of certificate block\n");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
@@ -603,7 +608,7 @@ void ndpi_search_ssl_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
|
||||
* so go on checking for certificate patterns for a couple more packets
|
||||
*/
|
||||
NDPI_LOG_DBG2(ndpi_struct,
|
||||
"ssl flow but check another packet for patterns\n");
|
||||
"ssl flow but check another packet for patterns\n");
|
||||
ssl_mark_and_payload_search_for_other_protocols(ndpi_struct, flow);
|
||||
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_SSL) {
|
||||
/* still ssl so check another packet */
|
||||
@@ -685,7 +690,7 @@ void ndpi_search_ssl_tcp(struct ndpi_detection_module_struct *ndpi_struct, struc
|
||||
return;
|
||||
} else if(ret == 2) {
|
||||
NDPI_LOG_DBG2(ndpi_struct,
|
||||
"sslv3 server len match with split packet -> check some more packets for SSL patterns\n");
|
||||
"sslv3 server len match with split packet -> check some more packets for SSL patterns\n");
|
||||
ssl_mark_and_payload_search_for_other_protocols(ndpi_struct, flow);
|
||||
if(packet->detected_protocol_stack[0] == NDPI_PROTOCOL_SSL) {
|
||||
flow->l4.tcp.ssl_stage = 3;
|
||||
|
||||
Reference in New Issue
Block a user