Disable -Wno-unused-parameter -Wno-unused-function. (#2358)

* unused parameters and functions pollute the code and decrease readability

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni
2024-04-03 14:10:21 +02:00
committed by GitHub
parent b5e8bc2214
commit 41eef9246c
63 changed files with 568 additions and 605 deletions
+1 -3
View File
@@ -218,9 +218,7 @@ AS_IF([test "x${enable_tls_sigs}" = "xyes"],[
HANDLE_TLS_SIGS="" HANDLE_TLS_SIGS=""
]) ])
NDPI_CFLAGS="-W -Wall -Wno-unused-parameter -Wno-unused-function -Wno-address-of-packed-member ${NDPI_CFLAGS} -Wno-attributes" NDPI_CFLAGS="-W -Wall -Wno-address-of-packed-member ${NDPI_CFLAGS}"
#Workaround for RoaringBitmap with gcc-7
NDPI_CFLAGS="-Wno-attributes ${NDPI_CFLAGS}"
AS_IF([test "${with_lto_and_gold_linker+set}" = set], [ AS_IF([test "${with_lto_and_gold_linker+set}" = set], [
NDPI_CFLAGS="${NDPI_CFLAGS} -flto -fuse-ld=gold -Wno-unused-command-line-argument" NDPI_CFLAGS="${NDPI_CFLAGS} -flto -fuse-ld=gold -Wno-unused-command-line-argument"
+20 -40
View File
@@ -390,7 +390,7 @@ void ndpiCheckHostStringMatch(char *testChar) {
testChar, match.protocol_id, match.protocol_breed, testChar, match.protocol_id, match.protocol_breed,
match.protocol_category, match.protocol_category,
appBufStr, appBufStr,
ndpi_get_proto_breed_name( ndpi_str, match.protocol_breed ), ndpi_get_proto_breed_name( match.protocol_breed ),
ndpi_category_get_name( ndpi_str, match.protocol_category)); ndpi_category_get_name( ndpi_str, match.protocol_category));
} else } else
printf("Match NOT Found for string: %s\n\n", testChar ); printf("Match NOT Found for string: %s\n\n", testChar );
@@ -958,27 +958,6 @@ void printCSVHeader() {
fprintf(csv_fp, "\n"); fprintf(csv_fp, "\n");
} }
static int parse_two_unsigned_integer(char *param, u_int32_t *num1, u_int32_t *num2)
{
char *saveptr, *tmp_str, *num1_str, *num2_str;
tmp_str = ndpi_strdup(param);
if(tmp_str) {
num1_str = strtok_r(tmp_str, ":", &saveptr);
if(num1_str) {
num2_str = strtok_r(NULL, ":", &saveptr);
if(num2_str) {
*num1 = atoi(num1_str);
*num2 = atoi(num2_str);
ndpi_free(tmp_str);
return 0;
}
}
}
ndpi_free(tmp_str);
return -1;
}
static int parse_three_strings(char *param, char **s1, char **s2, char **s3) static int parse_three_strings(char *param, char **s1, char **s2, char **s3)
{ {
char *saveptr, *tmp_str, *s1_str, *s2_str = NULL, *s3_str; char *saveptr, *tmp_str, *s1_str, *s2_str = NULL, *s3_str;
@@ -1602,8 +1581,7 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
); );
fprintf(csv_fp, "%s,", fprintf(csv_fp, "%s,",
ndpi_protocol2id(ndpi_thread_info[thread_id].workflow->ndpi_struct, ndpi_protocol2id(flow->detected_protocol, buf, sizeof(buf)));
flow->detected_protocol, buf, sizeof(buf)));
fprintf(csv_fp, "%s,%s,%s,", fprintf(csv_fp, "%s,%s,%s,",
ndpi_protocol2name(ndpi_thread_info[thread_id].workflow->ndpi_struct, ndpi_protocol2name(ndpi_thread_info[thread_id].workflow->ndpi_struct,
@@ -1732,8 +1710,7 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
fprintf(out, "%s:", ndpi_tunnel2str(flow->tunnel_type)); fprintf(out, "%s:", ndpi_tunnel2str(flow->tunnel_type));
fprintf(out, "%s/%s][IP: %u/%s]", fprintf(out, "%s/%s][IP: %u/%s]",
ndpi_protocol2id(ndpi_thread_info[thread_id].workflow->ndpi_struct, ndpi_protocol2id(flow->detected_protocol, buf, sizeof(buf)),
flow->detected_protocol, buf, sizeof(buf)),
ndpi_protocol2name(ndpi_thread_info[thread_id].workflow->ndpi_struct, ndpi_protocol2name(ndpi_thread_info[thread_id].workflow->ndpi_struct,
flow->detected_protocol, buf1, sizeof(buf1)), flow->detected_protocol, buf1, sizeof(buf1)),
flow->detected_protocol.protocol_by_ip, flow->detected_protocol.protocol_by_ip,
@@ -2072,8 +2049,7 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
} }
} }
static void printFlowSerialized(u_int16_t thread_id, static void printFlowSerialized(struct ndpi_flow_info *flow)
struct ndpi_flow_info *flow)
{ {
char *json_str = NULL; char *json_str = NULL;
u_int32_t json_str_len = 0; u_int32_t json_str_len = 0;
@@ -2208,6 +2184,8 @@ static void node_print_unknown_proto_walker(const void *node,
struct ndpi_flow_info *flow = *(struct ndpi_flow_info**)node; struct ndpi_flow_info *flow = *(struct ndpi_flow_info**)node;
u_int16_t thread_id = *((u_int16_t*)user_data); u_int16_t thread_id = *((u_int16_t*)user_data);
(void)depth;
if((flow->detected_protocol.master_protocol != NDPI_PROTOCOL_UNKNOWN) if((flow->detected_protocol.master_protocol != NDPI_PROTOCOL_UNKNOWN)
|| (flow->detected_protocol.app_protocol != NDPI_PROTOCOL_UNKNOWN)) || (flow->detected_protocol.app_protocol != NDPI_PROTOCOL_UNKNOWN))
return; return;
@@ -2229,6 +2207,8 @@ static void node_print_known_proto_walker(const void *node,
struct ndpi_flow_info *flow = *(struct ndpi_flow_info**)node; struct ndpi_flow_info *flow = *(struct ndpi_flow_info**)node;
u_int16_t thread_id = *((u_int16_t*)user_data); u_int16_t thread_id = *((u_int16_t*)user_data);
(void)depth;
if((flow->detected_protocol.master_protocol == NDPI_PROTOCOL_UNKNOWN) if((flow->detected_protocol.master_protocol == NDPI_PROTOCOL_UNKNOWN)
&& (flow->detected_protocol.app_protocol == NDPI_PROTOCOL_UNKNOWN)) && (flow->detected_protocol.app_protocol == NDPI_PROTOCOL_UNKNOWN))
return; return;
@@ -2249,6 +2229,8 @@ static void node_proto_guess_walker(const void *node, ndpi_VISIT which, int dept
struct ndpi_flow_info *flow = *(struct ndpi_flow_info **) node; struct ndpi_flow_info *flow = *(struct ndpi_flow_info **) node;
u_int16_t thread_id = *((u_int16_t *) user_data), proto; u_int16_t thread_id = *((u_int16_t *) user_data), proto;
(void)depth;
if(flow == NULL) return; if(flow == NULL) return;
if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */ if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
@@ -2475,15 +2457,6 @@ static int acceptable(u_int32_t num_pkts) {
/* *********************************************** */ /* *********************************************** */
static int receivers_sort(void *_a, void *_b) {
struct receiver *a = (struct receiver *)_a;
struct receiver *b = (struct receiver *)_b;
return(b->num_pkts - a->num_pkts);
}
/* *********************************************** */
static int receivers_sort_asc(void *_a, void *_b) { static int receivers_sort_asc(void *_a, void *_b) {
struct receiver *a = (struct receiver *)_a; struct receiver *a = (struct receiver *)_a;
struct receiver *b = (struct receiver *)_b; struct receiver *b = (struct receiver *)_b;
@@ -2649,6 +2622,8 @@ static void port_stats_walker(const void *node, ndpi_VISIT which, int depth, voi
u_int16_t sport, dport; u_int16_t sport, dport;
char proto[16]; char proto[16];
(void)depth;
sport = ntohs(flow->src_port), dport = ntohs(flow->dst_port); sport = ntohs(flow->src_port), dport = ntohs(flow->dst_port);
/* get app level protocol */ /* get app level protocol */
@@ -3070,6 +3045,9 @@ void printPortStats(struct port_stats *stats) {
static void node_flow_risk_walker(const void *node, ndpi_VISIT which, int depth, void *user_data) { static void node_flow_risk_walker(const void *node, ndpi_VISIT which, int depth, void *user_data) {
struct ndpi_flow_info *f = *(struct ndpi_flow_info**)node; struct ndpi_flow_info *f = *(struct ndpi_flow_info**)node;
(void)depth;
(void)user_data;
if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */ if((which == ndpi_preorder) || (which == ndpi_leaf)) { /* Avoid walking the same node multiple times */
if(f->risk) { if(f->risk) {
u_int j; u_int j;
@@ -3802,7 +3780,7 @@ static void printFlowsStats() {
for(i=0; i<num_flows; i++) for(i=0; i<num_flows; i++)
{ {
printFlowSerialized(all_flows[i].thread_id, all_flows[i].flow); printFlowSerialized(all_flows[i].flow);
} }
} }
@@ -4242,7 +4220,7 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
if(breed_stats_pkts[i] > 0) { if(breed_stats_pkts[i] > 0) {
printf("\t%-20s packets: %-13llu bytes: %-13llu " printf("\t%-20s packets: %-13llu bytes: %-13llu "
"flows: %-13llu\n", "flows: %-13llu\n",
ndpi_get_proto_breed_name(ndpi_thread_info[0].workflow->ndpi_struct, i), ndpi_get_proto_breed_name(i),
breed_stats_pkts[i], breed_stats_bytes[i], breed_stats_flows[i]); breed_stats_pkts[i], breed_stats_bytes[i], breed_stats_flows[i]);
} }
} }
@@ -4252,7 +4230,7 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
for(i=0; i < NUM_BREEDS; i++) { for(i=0; i < NUM_BREEDS; i++) {
if(breed_stats_pkts[i] > 0) { if(breed_stats_pkts[i] > 0) {
fprintf(results_file, "%-20s %13llu %-13llu %-13llu\n", fprintf(results_file, "%-20s %13llu %-13llu %-13llu\n",
ndpi_get_proto_breed_name(ndpi_thread_info[0].workflow->ndpi_struct, i), ndpi_get_proto_breed_name(i),
breed_stats_pkts[i], breed_stats_bytes[i], breed_stats_flows[i]); breed_stats_pkts[i], breed_stats_bytes[i], breed_stats_flows[i]);
} }
} }
@@ -4322,6 +4300,8 @@ void sigproc(int sig) {
static int called = 0; static int called = 0;
int thread_id; int thread_id;
(void)sig;
if(called) return; else called = 1; if(called) return; else called = 1;
shutdown_app = 1; shutdown_app = 1;
+1 -2
View File
@@ -900,8 +900,7 @@ static void ndpi_process_packet(uint8_t * const args,
ip != NULL ? (uint8_t *)ip : (uint8_t *)ip6, ip != NULL ? (uint8_t *)ip : (uint8_t *)ip6,
ip_size, time_ms, NULL); ip_size, time_ms, NULL);
if (ndpi_is_protocol_detected(workflow->ndpi_struct, if (ndpi_is_protocol_detected(flow_to_process->detected_l7_protocol) != 0 &&
flow_to_process->detected_l7_protocol) != 0 &&
flow_to_process->detection_completed == 0) flow_to_process->detection_completed == 0)
{ {
if (flow_to_process->detected_l7_protocol.master_protocol != NDPI_PROTOCOL_UNKNOWN || if (flow_to_process->detected_l7_protocol.master_protocol != NDPI_PROTOCOL_UNKNOWN ||
+7 -12
View File
@@ -114,7 +114,6 @@ u_int16_t max_pattern_len = 8;
/* *********************************************************** */ /* *********************************************************** */
int ndpi_analyze_payload(struct ndpi_flow_info *flow, int ndpi_analyze_payload(struct ndpi_flow_info *flow,
u_int8_t src_to_dst_direction,
u_int8_t *payload, u_int8_t *payload,
u_int16_t payload_len, u_int16_t payload_len,
u_int32_t packet_id) { u_int32_t packet_id) {
@@ -194,7 +193,6 @@ int ndpi_analyze_payload(struct ndpi_flow_info *flow,
/* *********************************************************** */ /* *********************************************************** */
void ndpi_payload_analyzer(struct ndpi_flow_info *flow, void ndpi_payload_analyzer(struct ndpi_flow_info *flow,
u_int8_t src_to_dst_direction,
u_int8_t *payload, u_int16_t payload_len, u_int8_t *payload, u_int16_t payload_len,
u_int32_t packet_id) { u_int32_t packet_id) {
u_int16_t i, j; u_int16_t i, j;
@@ -215,7 +213,7 @@ void ndpi_payload_analyzer(struct ndpi_flow_info *flow,
for(i=0; i<scan_len; i++) { for(i=0; i<scan_len; i++) {
for(j=min_pattern_len; j <= max_pattern_len; j++) { for(j=min_pattern_len; j <= max_pattern_len; j++) {
if((i+j) < payload_len) { if((i+j) < payload_len) {
if(ndpi_analyze_payload(flow, src_to_dst_direction, &payload[i], j, packet_id) == -1) { if(ndpi_analyze_payload(flow, &payload[i], j, packet_id) == -1) {
LOG(NDPI_LOG_ERROR, "Error ndpi_analyze_payload (allocation failure)\n"); LOG(NDPI_LOG_ERROR, "Error ndpi_analyze_payload (allocation failure)\n");
} }
} }
@@ -687,7 +685,6 @@ static struct ndpi_flow_info *get_ndpi_flow_info(struct ndpi_workflow * workflow
ndpi_packet_tunnel tunnel_type, ndpi_packet_tunnel tunnel_type,
const struct ndpi_iphdr *iph, const struct ndpi_iphdr *iph,
const struct ndpi_ipv6hdr *iph6, const struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
u_int16_t ipsize, u_int16_t ipsize,
u_int16_t l4_packet_len, u_int16_t l4_packet_len,
u_int16_t l4_offset, u_int16_t l4_offset,
@@ -973,7 +970,6 @@ static struct ndpi_flow_info *get_ndpi_flow_info6(struct ndpi_workflow * workflo
u_int16_t vlan_id, u_int16_t vlan_id,
ndpi_packet_tunnel tunnel_type, ndpi_packet_tunnel tunnel_type,
const struct ndpi_ipv6hdr *iph6, const struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
u_int16_t ipsize, u_int16_t ipsize,
struct ndpi_tcphdr **tcph, struct ndpi_tcphdr **tcph,
struct ndpi_udphdr **udph, struct ndpi_udphdr **udph,
@@ -1002,7 +998,7 @@ static struct ndpi_flow_info *get_ndpi_flow_info6(struct ndpi_workflow * workflo
iph.protocol = l4proto; iph.protocol = l4proto;
return(get_ndpi_flow_info(workflow, 6, vlan_id, tunnel_type, return(get_ndpi_flow_info(workflow, 6, vlan_id, tunnel_type,
&iph, iph6, ip_offset, ipsize, &iph, iph6, ipsize,
ip_len, l4ptr - (const u_int8_t *)iph6, ip_len, l4ptr - (const u_int8_t *)iph6,
tcph, udph, sport, dport, tcph, udph, sport, dport,
proto, payload, proto, payload,
@@ -1430,7 +1426,6 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
ndpi_packet_tunnel tunnel_type, ndpi_packet_tunnel tunnel_type,
const struct ndpi_iphdr *iph, const struct ndpi_iphdr *iph,
struct ndpi_ipv6hdr *iph6, struct ndpi_ipv6hdr *iph6,
u_int16_t ip_offset,
u_int16_t ipsize, u_int16_t rawsize, u_int16_t ipsize, u_int16_t rawsize,
const struct pcap_pkthdr *header, const struct pcap_pkthdr *header,
const u_char *packet, const u_char *packet,
@@ -1453,7 +1448,7 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
if(iph) if(iph)
flow = get_ndpi_flow_info(workflow, IPVERSION, vlan_id, flow = get_ndpi_flow_info(workflow, IPVERSION, vlan_id,
tunnel_type, iph, NULL, tunnel_type, iph, NULL,
ip_offset, ipsize, ipsize,
ntohs(iph->tot_len) ? (ntohs(iph->tot_len) - (iph->ihl * 4)) : ipsize - (iph->ihl * 4) /* TSO */, ntohs(iph->tot_len) ? (ntohs(iph->tot_len) - (iph->ihl * 4)) : ipsize - (iph->ihl * 4) /* TSO */,
iph->ihl * 4, iph->ihl * 4,
&tcph, &udph, &sport, &dport, &tcph, &udph, &sport, &dport,
@@ -1461,7 +1456,7 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
&payload, &payload_len, &src_to_dst_direction, when); &payload, &payload_len, &src_to_dst_direction, when);
else else
flow = get_ndpi_flow_info6(workflow, vlan_id, flow = get_ndpi_flow_info6(workflow, vlan_id,
tunnel_type, iph6, ip_offset, ipsize, tunnel_type, iph6, ipsize,
&tcph, &udph, &sport, &dport, &tcph, &udph, &sport, &dport,
&proto, &proto,
&payload, &payload_len, &src_to_dst_direction, when); &payload, &payload_len, &src_to_dst_direction, when);
@@ -1554,7 +1549,7 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
#endif #endif
if(enable_payload_analyzer && (payload_len > 0)) if(enable_payload_analyzer && (payload_len > 0))
ndpi_payload_analyzer(flow, src_to_dst_direction, ndpi_payload_analyzer(flow,
payload, payload_len, payload, payload_len,
workflow->stats.ip_packet_count); workflow->stats.ip_packet_count);
@@ -1613,7 +1608,7 @@ static struct ndpi_proto packet_processing(struct ndpi_workflow * workflow,
} }
if((!skip) && ((flow->src2dst_packets+flow->dst2src_packets) < 100)) { if((!skip) && ((flow->src2dst_packets+flow->dst2src_packets) < 100)) {
if(ndpi_has_human_readeable_string(workflow->ndpi_struct, (char*)packet, header->caplen, if(ndpi_has_human_readeable_string((char*)packet, header->caplen,
human_readeable_string_len, human_readeable_string_len,
flow->human_readeable_string_buffer, flow->human_readeable_string_buffer,
sizeof(flow->human_readeable_string_buffer)) == 1) sizeof(flow->human_readeable_string_buffer)) == 1)
@@ -2369,7 +2364,7 @@ struct ndpi_proto ndpi_workflow_process_packet(struct ndpi_workflow * workflow,
/* process the packet */ /* process the packet */
return(packet_processing(workflow, time_ms, vlan_id, tunnel_type, iph, iph6, return(packet_processing(workflow, time_ms, vlan_id, tunnel_type, iph, iph6,
ip_offset, header->caplen - ip_offset, header->caplen - ip_offset,
header->caplen, header, packet, header->ts, header->caplen, header, packet, header->ts,
flow_risk)); flow_risk));
} }
+11 -11
View File
@@ -462,7 +462,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
ndpi_map_ndpi_id_to_user_proto_id(ndpi_info_mod, pid); ndpi_map_ndpi_id_to_user_proto_id(ndpi_info_mod, pid);
ndpi_set_proto_breed(ndpi_info_mod, pid, NDPI_PROTOCOL_SAFE); ndpi_set_proto_breed(ndpi_info_mod, pid, NDPI_PROTOCOL_SAFE);
ndpi_set_proto_category(ndpi_info_mod, pid, NDPI_PROTOCOL_CATEGORY_MEDIA); ndpi_set_proto_category(ndpi_info_mod, pid, NDPI_PROTOCOL_CATEGORY_MEDIA);
ndpi_is_subprotocol_informative(ndpi_info_mod, pid); ndpi_is_subprotocol_informative(pid);
ndpi_get_proto_breed(ndpi_info_mod, pid); ndpi_get_proto_breed(ndpi_info_mod, pid);
ndpi_port_range d_port[MAX_DEFAULT_PORTS] = {}; ndpi_port_range d_port[MAX_DEFAULT_PORTS] = {};
@@ -538,31 +538,31 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
ndpi_detection_process_packet(ndpi_info_mod, &flow, pkt.data(), pkt.size(), 0, &input_info); ndpi_detection_process_packet(ndpi_info_mod, &flow, pkt.data(), pkt.size(), 0, &input_info);
p = ndpi_detection_giveup(ndpi_info_mod, &flow, &protocol_was_guessed); p = ndpi_detection_giveup(ndpi_info_mod, &flow, &protocol_was_guessed);
assert(p.master_protocol == ndpi_get_flow_masterprotocol(ndpi_info_mod, &flow)); assert(p.master_protocol == ndpi_get_flow_masterprotocol(&flow));
assert(p.app_protocol == ndpi_get_flow_appprotocol(ndpi_info_mod, &flow)); assert(p.app_protocol == ndpi_get_flow_appprotocol(&flow));
assert(p.category == ndpi_get_flow_category(ndpi_info_mod, &flow)); assert(p.category == ndpi_get_flow_category(&flow));
ndpi_get_lower_proto(p); ndpi_get_lower_proto(p);
ndpi_get_upper_proto(p); ndpi_get_upper_proto(p);
ndpi_get_flow_error_code(&flow); ndpi_get_flow_error_code(&flow);
ndpi_get_flow_risk_info(&flow, out, sizeof(out), 1); ndpi_get_flow_risk_info(&flow, out, sizeof(out), 1);
ndpi_get_flow_ndpi_proto(ndpi_info_mod, &flow, &p2); ndpi_get_flow_ndpi_proto(&flow, &p2);
ndpi_is_proto(p, NDPI_PROTOCOL_TLS); ndpi_is_proto(p, NDPI_PROTOCOL_TLS);
ndpi_http_method2str(flow.http.method); ndpi_http_method2str(flow.http.method);
ndpi_get_l4_proto_name(ndpi_get_l4_proto_info(ndpi_info_mod, p.app_protocol)); ndpi_get_l4_proto_name(ndpi_get_l4_proto_info(ndpi_info_mod, p.app_protocol));
ndpi_is_subprotocol_informative(ndpi_info_mod, p.app_protocol); ndpi_is_subprotocol_informative(p.app_protocol);
ndpi_get_http_method(ndpi_info_mod, bool_value ? &flow : NULL); ndpi_get_http_method(bool_value ? &flow : NULL);
ndpi_get_http_url(ndpi_info_mod, &flow); ndpi_get_http_url(&flow);
ndpi_get_http_content_type(ndpi_info_mod, &flow); ndpi_get_http_content_type(&flow);
ndpi_get_flow_name(bool_value ? &flow : NULL); ndpi_get_flow_name(bool_value ? &flow : NULL);
/* ndpi_guess_undetected_protocol() is a "strange" function. Try fuzzing it, here */ /* ndpi_guess_undetected_protocol() is a "strange" function. Try fuzzing it, here */
if(!ndpi_is_protocol_detected(ndpi_info_mod, p)) { if(!ndpi_is_protocol_detected(p)) {
ndpi_guess_undetected_protocol(ndpi_info_mod, bool_value ? &flow : NULL, ndpi_guess_undetected_protocol(ndpi_info_mod, bool_value ? &flow : NULL,
flow.l4_proto); flow.l4_proto);
if(!flow.is_ipv6) { if(!flow.is_ipv6) {
/* Another "strange" function (ipv4 only): fuzz it here, for lack of a better alternative */ /* Another "strange" function (ipv4 only): fuzz it here, for lack of a better alternative */
ndpi_find_ipv4_category_userdata(ndpi_info_mod, flow.c_address.v4); ndpi_find_ipv4_category_userdata(ndpi_info_mod, flow.c_address.v4);
ndpi_search_tcp_or_udp_raw(ndpi_info_mod, NULL, 0, ntohl(flow.c_address.v4), ntohl(flow.s_address.v4)); ndpi_search_tcp_or_udp_raw(ndpi_info_mod, NULL, ntohl(flow.c_address.v4), ntohl(flow.s_address.v4));
ndpi_guess_undetected_protocol_v4(ndpi_info_mod, bool_value ? &flow : NULL, ndpi_guess_undetected_protocol_v4(ndpi_info_mod, bool_value ? &flow : NULL,
flow.l4_proto, flow.l4_proto,
+1
View File
@@ -7,6 +7,7 @@
#include "fuzzer/FuzzedDataProvider.h" #include "fuzzer/FuzzedDataProvider.h"
extern "C" void cleanup_func(ndpi_str_hash *h) { extern "C" void cleanup_func(ndpi_str_hash *h) {
(void)h;
/* Nothing to do */ /* Nothing to do */
return; return;
} }
+3
View File
@@ -22,6 +22,9 @@ static void __free(void * const node)
} }
static void __walk(const void *a, ndpi_VISIT which, int depth, void *user_data) static void __walk(const void *a, ndpi_VISIT which, int depth, void *user_data)
{ {
(void)which;
(void)depth;
assert(user_data == NULL && a); assert(user_data == NULL && a);
} }
+14 -35
View File
@@ -359,49 +359,41 @@ extern "C" {
* Get the main protocol of the passed flows for the detected module * Get the main protocol of the passed flows for the detected module
* *
* *
* @par ndpi_struct = the detection module
* @par flow = the flow given for the detection module * @par flow = the flow given for the detection module
* @return the ID of the master protocol detected * @return the ID of the master protocol detected
* *
*/ */
u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_flow_struct *flow);
struct ndpi_flow_struct *flow);
/** /**
* Get the app protocol of the passed flows for the detected module * Get the app protocol of the passed flows for the detected module
* *
* *
* @par ndpi_struct = the detection module
* @par flow = the flow given for the detection module * @par flow = the flow given for the detection module
* @return the ID of the app protocol detected * @return the ID of the app protocol detected
* *
*/ */
u_int16_t ndpi_get_flow_appprotocol(struct ndpi_detection_module_struct *ndpi_str, u_int16_t ndpi_get_flow_appprotocol(struct ndpi_flow_struct *flow);
struct ndpi_flow_struct *flow);
/** /**
* Get the category of the passed flows for the detected module * Get the category of the passed flows for the detected module
* *
* *
* @par ndpi_struct = the detection module
* @par flow = the flow given for the detection module * @par flow = the flow given for the detection module
* @return the ID of the category * @return the ID of the category
* *
*/ */
ndpi_protocol_category_t ndpi_get_flow_category(struct ndpi_detection_module_struct *ndpi_str, ndpi_protocol_category_t ndpi_get_flow_category(struct ndpi_flow_struct *flow);
struct ndpi_flow_struct *flow);
/** /**
* Get the ndpi protocol data of the passed flows for the detected module * Get the ndpi protocol data of the passed flows for the detected module
* *
* *
* @par ndpi_struct = the detection module
* @par flow = the flow given for the detection module * @par flow = the flow given for the detection module
* @par ndpi_proto = the output struct where to store the requested information * @par ndpi_proto = the output struct where to store the requested information
* *
*/ */
void ndpi_get_flow_ndpi_proto(struct ndpi_detection_module_struct *ndpi_str, void ndpi_get_flow_ndpi_proto(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
struct ndpi_proto * ndpi_proto); struct ndpi_proto * ndpi_proto);
/** /**
@@ -551,15 +543,13 @@ extern "C" {
* Same as ndpi_protocol2name() with the difference that the numeric protocol * Same as ndpi_protocol2name() with the difference that the numeric protocol
* name is returned * name is returned
* *
* @par ndpi_mod = the detection module
* @par proto = the struct ndpi_protocol contain the protocols name * @par proto = the struct ndpi_protocol contain the protocols name
* @par buf = the buffer to write the name of the protocols * @par buf = the buffer to write the name of the protocols
* @par buf_len = the length of the buffer * @par buf_len = the length of the buffer
* @return the buffer contains the master_protocol and protocol name * @return the buffer contains the master_protocol and protocol name
* *
*/ */
char* ndpi_protocol2id(struct ndpi_detection_module_struct *ndpi_mod, char* ndpi_protocol2id(ndpi_protocol proto, char *buf, u_int buf_len);
ndpi_protocol proto, char *buf, u_int buf_len);
/** /**
* Find out if a given category is custom/user-defined * Find out if a given category is custom/user-defined
@@ -596,13 +586,11 @@ extern "C" {
* Check if subprotocols of the specified master protocol are just * Check if subprotocols of the specified master protocol are just
* informative (and not real) * informative (and not real)
* *
* @par mod = the detection module
* @par protoId = the (master) protocol identifier to query * @par protoId = the (master) protocol identifier to query
* @return 1 = the subprotocol is informative, 0 otherwise. * @return 1 = the subprotocol is informative, 0 otherwise.
* *
*/ */
u_int8_t ndpi_is_subprotocol_informative(struct ndpi_detection_module_struct *ndpi_mod, u_int8_t ndpi_is_subprotocol_informative(u_int16_t protoId);
u_int16_t protoId);
/** /**
* Set hostname-based protocol * Set hostname-based protocol
@@ -690,8 +678,7 @@ extern "C" {
* @return the string name of the breed ID * @return the string name of the breed ID
* *
*/ */
char* ndpi_get_proto_breed_name(struct ndpi_detection_module_struct *ndpi_struct, char* ndpi_get_proto_breed_name(ndpi_protocol_breed_t breed_id);
ndpi_protocol_breed_t breed_id);
/** /**
* Return the ID of the protocol * Return the ID of the protocol
@@ -880,35 +867,29 @@ extern "C" {
/** /**
* Retrieve information for HTTP flows * Retrieve information for HTTP flows
* *
* @par ndpi_mod = the detection module
* @par flow = the detected flow * @par flow = the detected flow
* @return the HTTP method information about the flow * @return the HTTP method information about the flow
* *
*/ */
ndpi_http_method ndpi_get_http_method(struct ndpi_detection_module_struct *ndpi_mod, ndpi_http_method ndpi_get_http_method(struct ndpi_flow_struct *flow);
struct ndpi_flow_struct *flow);
/** /**
* Get the HTTP url * Get the HTTP url
* *
* @par ndpi_mod = the detection module
* @par flow = the detected flow * @par flow = the detected flow
* @return the HTTP method information about the flow * @return the HTTP method information about the flow
* *
*/ */
char* ndpi_get_http_url(struct ndpi_detection_module_struct *ndpi_mod, char* ndpi_get_http_url(struct ndpi_flow_struct *flow);
struct ndpi_flow_struct *flow);
/** /**
* Get the HTTP content-type * Get the HTTP content-type
* *
* @par ndpi_mod = the detection module
* @par flow = the detected flow * @par flow = the detected flow
* @return the HTTP method information about the flow * @return the HTTP method information about the flow
* *
*/ */
char* ndpi_get_http_content_type(struct ndpi_detection_module_struct *ndpi_mod, char* ndpi_get_http_content_type(struct ndpi_flow_struct *flow);
struct ndpi_flow_struct *flow);
/* NDPI_PROTOCOL_TOR */ /* NDPI_PROTOCOL_TOR */
/** /**
@@ -1102,15 +1083,14 @@ extern "C" {
int ndpi_flowv6_flow_hash(u_int8_t l4_proto, struct ndpi_in6_addr *src_ip, struct ndpi_in6_addr *dst_ip, int ndpi_flowv6_flow_hash(u_int8_t l4_proto, struct ndpi_in6_addr *src_ip, struct ndpi_in6_addr *dst_ip,
u_int16_t src_port, u_int16_t dst_port, u_int8_t icmp_type, u_int8_t icmp_code, u_int16_t src_port, u_int16_t dst_port, u_int8_t icmp_type, u_int8_t icmp_code,
u_char *hash_buf, u_int8_t hash_buf_len); u_char *hash_buf, u_int8_t hash_buf_len);
u_int8_t ndpi_extra_dissection_possible(struct ndpi_detection_module_struct *ndpi_struct, u_int8_t ndpi_extra_dissection_possible(struct ndpi_detection_module_struct *ndpi_str,
struct ndpi_flow_struct *flow); struct ndpi_flow_struct *flow);
u_int8_t ndpi_is_safe_ssl_cipher(u_int32_t cipher); u_int8_t ndpi_is_safe_ssl_cipher(u_int32_t cipher);
const char* ndpi_cipher2str(u_int32_t cipher, char unknown_cipher[8]); const char* ndpi_cipher2str(u_int32_t cipher, char unknown_cipher[8]);
const char* ndpi_tunnel2str(ndpi_packet_tunnel tt); const char* ndpi_tunnel2str(ndpi_packet_tunnel tt);
u_int16_t ndpi_guess_host_protocol_id(struct ndpi_detection_module_struct *ndpi_struct, u_int16_t ndpi_guess_host_protocol_id(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow); struct ndpi_flow_struct *flow);
int ndpi_has_human_readeable_string(struct ndpi_detection_module_struct *ndpi_struct, int ndpi_has_human_readeable_string(char *buffer, u_int buffer_size,
char *buffer, u_int buffer_size,
u_int8_t min_string_match_len, /* Will return 0 if no string > min_string_match_len have been found */ u_int8_t min_string_match_len, /* Will return 0 if no string > min_string_match_len have been found */
char *outbuf, u_int outbuf_len); char *outbuf, u_int outbuf_len);
/* Return a flow info string (summarized). Does only work for DNS/HTTP/TLS/QUIC. */ /* Return a flow info string (summarized). Does only work for DNS/HTTP/TLS/QUIC. */
@@ -1788,8 +1768,7 @@ extern "C" {
ndpi_risk_enum ndpi_validate_url(char *url); ndpi_risk_enum ndpi_validate_url(char *url);
u_int8_t ndpi_is_protocol_detected(struct ndpi_detection_module_struct *ndpi_str, u_int8_t ndpi_is_protocol_detected(ndpi_protocol proto);
ndpi_protocol proto);
void ndpi_serialize_risk(ndpi_serializer *serializer, ndpi_risk risk); void ndpi_serialize_risk(ndpi_serializer *serializer, ndpi_risk risk);
void ndpi_serialize_risk_score(ndpi_serializer *serializer, ndpi_risk_enum risk); void ndpi_serialize_risk_score(ndpi_serializer *serializer, ndpi_risk_enum risk);
void ndpi_serialize_confidence(ndpi_serializer *serializer, ndpi_confidence_t confidence); void ndpi_serialize_confidence(ndpi_serializer *serializer, ndpi_confidence_t confidence);
+3 -6
View File
@@ -106,13 +106,10 @@ extern "C" {
ndpi_protocol_category_t protoCategory, ndpi_protocol_category_t protoCategory,
ndpi_port_range *tcpDefPorts, ndpi_port_range *tcpDefPorts,
ndpi_port_range *udpDefPorts); ndpi_port_range *udpDefPorts);
void ndpi_set_risk(struct ndpi_detection_module_struct *ndpi_str, void ndpi_set_risk(struct ndpi_flow_struct *flow, ndpi_risk_enum r,
struct ndpi_flow_struct *flow, ndpi_risk_enum r,
char *risk_message); char *risk_message);
void ndpi_unset_risk(struct ndpi_detection_module_struct *ndpi_str, void ndpi_unset_risk(struct ndpi_flow_struct *flow, ndpi_risk_enum r);
struct ndpi_flow_struct *flow, ndpi_risk_enum r); int ndpi_isset_risk(struct ndpi_flow_struct *flow, ndpi_risk_enum r);
int ndpi_isset_risk(struct ndpi_detection_module_struct *ndpi_str,
struct ndpi_flow_struct *flow, ndpi_risk_enum r);
int ndpi_is_printable_buffer(u_int8_t const * const buf, size_t len); int ndpi_is_printable_buffer(u_int8_t const * const buf, size_t len);
int ndpi_normalize_printable_string(char * const str, size_t len); int ndpi_normalize_printable_string(char * const str, size_t len);
int ndpi_is_valid_hostname(char * const str, size_t len); int ndpi_is_valid_hostname(char * const str, size_t len);
+14 -19
View File
@@ -469,21 +469,21 @@ struct ndpi_detection_module_struct {
#else /* not defined NDPI_ENABLE_DEBUG_MESSAGES */ #else /* not defined NDPI_ENABLE_DEBUG_MESSAGES */
# ifdef WIN32 # ifdef WIN32
# define NDPI_LOG(...) {} # define NDPI_LOG(mod, ...) { (void)mod; }
# define NDPI_LOG_ERR(...) {} # define NDPI_LOG_ERR(mod, ...) { (void)mod; }
# define NDPI_LOG_INFO(...) {} # define NDPI_LOG_INFO(mod, ...) { (void)mod; }
# define NDPI_LOG_DBG(...) {} # define NDPI_LOG_DBG(mod, ...) { (void)mod; }
# define NDPI_LOG_DBG2(...) {} # define NDPI_LOG_DBG2(mod, ...) { (void)mod; }
# else # else
# define NDPI_LOG(proto, mod, log_level, args...) { /* printf(args); */ } # define NDPI_LOG(proto, mod, log_level, args...) { /* printf(args); */ }
# ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION # ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
# define NDPI_LOG_ERR(mod, args...) { printf(args); } # define NDPI_LOG_ERR(mod, args...) { (void)mod; printf(args); }
# else # else
# define NDPI_LOG_ERR(mod, args...) { /* printf(args); */ } # define NDPI_LOG_ERR(mod, args...) { (void)mod; /* printf(args); */ }
# endif # endif
# define NDPI_LOG_INFO(mod, args...) { /* printf(args); */ } # define NDPI_LOG_INFO(mod, args...) { (void)mod; /* printf(args); */ }
# define NDPI_LOG_DBG(mod, args...) { /* printf(args); */ } # define NDPI_LOG_DBG(mod, args...) { (void)mod; /* printf(args); */ }
# define NDPI_LOG_DBG2(mod, args...) { /* printf(args); */ } # define NDPI_LOG_DBG2(mod, args...) { (void)mod; /* printf(args); */ }
# endif # endif
#endif /* NDPI_ENABLE_DEBUG_MESSAGES */ #endif /* NDPI_ENABLE_DEBUG_MESSAGES */
@@ -558,16 +558,14 @@ void ndpi_set_detected_protocol(struct ndpi_detection_module_struct *ndpi_struct
u_int16_t lower_detected_protocol, u_int16_t lower_detected_protocol,
ndpi_confidence_t confidence); ndpi_confidence_t confidence);
void reset_detected_protocol(struct ndpi_detection_module_struct *ndpi_struct, void reset_detected_protocol(struct ndpi_flow_struct *flow);
struct ndpi_flow_struct *flow);
void ndpi_set_detected_protocol_keeping_master(struct ndpi_detection_module_struct *ndpi_str, void ndpi_set_detected_protocol_keeping_master(struct ndpi_detection_module_struct *ndpi_str,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow,
u_int16_t detected_protocol, u_int16_t detected_protocol,
ndpi_confidence_t confidence); ndpi_confidence_t confidence);
void change_category(struct ndpi_detection_module_struct *ndpi_struct, void change_category(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
ndpi_protocol_category_t protocol_category); ndpi_protocol_category_t protocol_category);
@@ -576,8 +574,7 @@ char *ndpi_user_agent_set(struct ndpi_flow_struct *flow, const u_int8_t *value,
void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struct, void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow); struct ndpi_flow_struct *flow);
void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_struct, void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_struct);
struct ndpi_flow_struct *flow);
void load_common_alpns(struct ndpi_detection_module_struct *ndpi_str); void load_common_alpns(struct ndpi_detection_module_struct *ndpi_str);
u_int8_t is_a_common_alpn(struct ndpi_detection_module_struct *ndpi_str, u_int8_t is_a_common_alpn(struct ndpi_detection_module_struct *ndpi_str,
@@ -593,7 +590,6 @@ u_int8_t ends_with(struct ndpi_detection_module_struct *ndpi_struct,
u_int ndpi_search_tcp_or_udp_raw(struct ndpi_detection_module_struct *ndpi_struct, u_int ndpi_search_tcp_or_udp_raw(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow,
u_int8_t protocol,
u_int32_t saddr, u_int32_t daddr); u_int32_t saddr, u_int32_t daddr);
u_int32_t ip_port_hash_funct(u_int32_t ip, u_int16_t port); u_int32_t ip_port_hash_funct(u_int32_t ip, u_int16_t port);
@@ -655,8 +651,7 @@ const uint8_t *get_crypto_data(struct ndpi_detection_module_struct *ndpi_struct,
/* RTP */ /* RTP */
int is_valid_rtp_payload_type(uint8_t type); int is_valid_rtp_payload_type(uint8_t type);
int is_rtp_or_rtcp(struct ndpi_detection_module_struct *ndpi_struct, int is_rtp_or_rtcp(struct ndpi_detection_module_struct *ndpi_struct);
struct ndpi_flow_struct *flow);
u_int8_t rtp_get_stream_type(u_int8_t payloadType, ndpi_multimedia_flow_type *s_type); u_int8_t rtp_get_stream_type(u_int8_t payloadType, ndpi_multimedia_flow_type *s_type);
/* Bittorrent */ /* Bittorrent */
+4 -1
View File
@@ -18,6 +18,9 @@ ifneq ($(OS),Windows_NT)
CFLAGS += -fPIC -DPIC CFLAGS += -fPIC -DPIC
endif endif
CFLAGS += -I. -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION @NDPI_CFLAGS@ @GPROF_CFLAGS@ @CUSTOM_NDPI@ @ADDITIONAL_INCS@ CFLAGS += -I. -I../include -Ithird_party/include -DNDPI_LIB_COMPILATION @NDPI_CFLAGS@ @GPROF_CFLAGS@ @CUSTOM_NDPI@ @ADDITIONAL_INCS@
CFLAGS_third_party/src/gcrypt_light.c := -Wno-unused-parameter
CFLAGS_third_party/src/ahocorasick.c := -Wno-unused-function -Wno-unused-parameter
CFLAGS_third_party/src/roaring.c := -Wno-unused-function -Wno-attributes
LDFLAGS += @NDPI_LDFLAGS@ LDFLAGS += @NDPI_LDFLAGS@
LIBS = @ADDITIONAL_LIBS@ @LIBS@ @GPROF_LIBS@ LIBS = @ADDITIONAL_LIBS@ @LIBS@ @GPROF_LIBS@
@@ -66,7 +69,7 @@ $(NDPI_LIB_SHARED): $(OBJECTS)
ln -fs $(NDPI_LIB_SHARED) $(NDPI_LIB_SHARED_BASE).$(NDPI_VERSION_MAJOR) ln -fs $(NDPI_LIB_SHARED) $(NDPI_LIB_SHARED_BASE).$(NDPI_VERSION_MAJOR)
%.o: %.c $(HEADERS) Makefile %.o: %.c $(HEADERS) Makefile
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_$<) -c $< -o $@
clean: clean:
/bin/rm -f $(NDPI_LIB_STATIC) $(OBJECTS) *.o *.so *.lo libndpi.so* /bin/rm -f $(NDPI_LIB_STATIC) $(OBJECTS) *.o *.so *.lo libndpi.so*
+16
View File
@@ -60,6 +60,9 @@ int ndpi_load_geoip(struct ndpi_detection_module_struct *ndpi_str,
return(0); return(0);
#else #else
(void)ndpi_str;
(void)ip_city_data;
(void)ip_as_data;
return(-3); return(-3);
#endif #endif
} }
@@ -73,6 +76,8 @@ void ndpi_free_geoip(struct ndpi_detection_module_struct *ndpi_str) {
ndpi_free(ndpi_str->mmdb_city); ndpi_free(ndpi_str->mmdb_city);
ndpi_free(ndpi_str->mmdb_as); ndpi_free(ndpi_str->mmdb_as);
#else
(void)ndpi_str;
#endif #endif
} }
@@ -103,6 +108,10 @@ int ndpi_get_geoip_asn(struct ndpi_detection_module_struct *ndpi_str, char *ip,
return(0); return(0);
} }
#else
(void)ndpi_str;
(void)ip;
(void)asn;
#endif #endif
return(-2); return(-2);
@@ -158,6 +167,13 @@ int ndpi_get_geoip_country_continent(struct ndpi_detection_module_struct *ndpi_s
return(0); return(0);
} }
#else
(void)ndpi_str;
(void)ip;
(void)country_code;
(void)country_code_len;
(void)continent;
(void)continent_len;
#endif #endif
return(-2); return(-2);
+171 -134
View File
@@ -216,7 +216,7 @@ static int addDefaultPort(struct ndpi_detection_module_struct *ndpi_str,
const char *_func, int _line); const char *_func, int _line);
static void ndpi_reset_packet_line_info(struct ndpi_packet_struct *packet); static void ndpi_reset_packet_line_info(struct ndpi_packet_struct *packet);
static void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, static void ndpi_int_change_protocol(struct ndpi_flow_struct *flow,
u_int16_t upper_detected_protocol, u_int16_t lower_detected_protocol, u_int16_t upper_detected_protocol, u_int16_t lower_detected_protocol,
ndpi_confidence_t confidence); ndpi_confidence_t confidence);
@@ -448,7 +448,7 @@ void ndpi_set_proto_category(struct ndpi_detection_module_struct *ndpi_str, u_in
- HTTP/SSL are NOT informative as SSL.Facebook (likely) means that this is - HTTP/SSL are NOT informative as SSL.Facebook (likely) means that this is
SSL (HTTPS) traffic containg Facebook traffic. SSL (HTTPS) traffic containg Facebook traffic.
*/ */
u_int8_t ndpi_is_subprotocol_informative(struct ndpi_detection_module_struct *ndpi_str, u_int16_t protoId) { u_int8_t ndpi_is_subprotocol_informative(u_int16_t protoId) {
if(!ndpi_is_valid_protoId(protoId)) if(!ndpi_is_valid_protoId(protoId))
return(0); return(0);
@@ -471,6 +471,11 @@ void ndpi_exclude_protocol(struct ndpi_detection_module_struct *ndpi_str, struct
(*(ndpi_str->ndpi_debug_printf))(protocol_id, ndpi_str, NDPI_LOG_DEBUG, _file, _func, _line, "exclude %s\n", (*(ndpi_str->ndpi_debug_printf))(protocol_id, ndpi_str, NDPI_LOG_DEBUG, _file, _func, _line, "exclude %s\n",
ndpi_get_proto_name(ndpi_str, protocol_id)); ndpi_get_proto_name(ndpi_str, protocol_id));
} }
#else
(void)ndpi_str;
(void)_file;
(void)_func;
(void)_line;
#endif #endif
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, protocol_id); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, protocol_id);
} }
@@ -625,6 +630,9 @@ static int addDefaultPort(struct ndpi_detection_module_struct *ndpi_str,
default_ports_tree_node_t **root, default_ports_tree_node_t **root,
const char *_func, const char *_func,
int _line) { int _line) {
(void)_func;
(void)_line;
u_int32_t port; u_int32_t port;
for(port = range->port_low; port <= range->port_high; port++) { for(port = range->port_low; port <= range->port_high; port++) {
@@ -2779,8 +2787,7 @@ int ndpi_load_ipv4_ptree(struct ndpi_detection_module_struct *ndpi_str,
/* ******************************************* */ /* ******************************************* */
static void ndpi_init_ptree_ipv4(struct ndpi_detection_module_struct *ndpi_str, static void ndpi_init_ptree_ipv4(void *ptree, ndpi_network host_list[]) {
void *ptree, ndpi_network host_list[]) {
int i; int i;
for(i = 0; host_list[i].network != 0x0; i++) { for(i = 0; host_list[i].network != 0x0; i++) {
@@ -3016,6 +3023,10 @@ void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *
} else { } else {
printf("Proto: %u, %s", proto, str); printf("Proto: %u, %s", proto, str);
} }
#else
(void)file_name;
(void)func_name;
(void)line_number;
#endif #endif
} }
@@ -3027,6 +3038,9 @@ void set_ndpi_debug_function(struct ndpi_detection_module_struct *ndpi_str, ndpi
#ifdef NDPI_ENABLE_DEBUG_MESSAGES #ifdef NDPI_ENABLE_DEBUG_MESSAGES
if(ndpi_str) if(ndpi_str)
ndpi_str->ndpi_debug_printf = ndpi_debug_printf; ndpi_str->ndpi_debug_printf = ndpi_debug_printf;
#else
(void)ndpi_str;
(void)ndpi_debug_printf;
#endif #endif
} }
@@ -3246,7 +3260,7 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(struct ndpi_glob
ndpi_exit_detection_module(ndpi_str); ndpi_exit_detection_module(ndpi_str);
return NULL; return NULL;
} }
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, host_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, host_protocol_list);
ndpi_str->ip_risk_mask_ptree = ndpi_patricia_new(32 /* IPv4 */); ndpi_str->ip_risk_mask_ptree = ndpi_patricia_new(32 /* IPv4 */);
@@ -3454,199 +3468,199 @@ int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str)
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_AMAZON_AWS)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_AMAZON_AWS)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_amazon_aws_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_amazon_aws_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_amazon_aws_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_amazon_aws_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_MICROSOFT_AZURE)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_MICROSOFT_AZURE)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_microsoft_azure_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_microsoft_azure_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_microsoft_azure_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_microsoft_azure_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_CACHEFLY)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_CACHEFLY)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_cachefly_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_cachefly_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_cachefly_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_cachefly_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_CLOUDFLARE)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_CLOUDFLARE)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_cloudflare_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_cloudflare_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_cloudflare_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_cloudflare_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_GOOGLE)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_GOOGLE)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_google_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_google_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_google_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_google_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_GOOGLE_CLOUD)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_GOOGLE_CLOUD)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_google_cloud_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_google_cloud_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_google_cloud_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_google_cloud_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_MICROSOFT_365)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_MICROSOFT_365)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_microsoft_365_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_microsoft_365_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_microsoft_365_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_microsoft_365_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_MS_ONE_DRIVE)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_MS_ONE_DRIVE)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_ms_one_drive_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_ms_one_drive_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_ms_one_drive_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_ms_one_drive_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_MS_OUTLOOK)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_MS_OUTLOOK)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_ms_outlook_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_ms_outlook_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_ms_outlook_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_ms_outlook_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_SKYPE_TEAMS)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_SKYPE_TEAMS)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_skype_teams_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_skype_teams_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_skype_teams_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_skype_teams_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_PROTONVPN)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_PROTONVPN)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_protonvpn_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_protonvpn_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_protonvpn_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_protonvpn_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TOR)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TOR)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_tor_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_tor_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_tor_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_tor_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_WHATSAPP)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_WHATSAPP)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_whatsapp_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_whatsapp_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_whatsapp_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_whatsapp_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_ETHEREUM)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_ETHEREUM)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_ethereum_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_ethereum_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_ethereum_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_ethereum_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_ZOOM)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_ZOOM)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_zoom_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_zoom_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_zoom_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_zoom_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_MULLVAD)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_MULLVAD)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_mullvad_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_mullvad_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_mullvad_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_mullvad_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TELEGRAM)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TELEGRAM)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_telegram_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_telegram_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_telegram_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_telegram_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_APPLE)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_APPLE)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_apple_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_apple_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_apple_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_apple_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TWITTER)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TWITTER)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_twitter_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_twitter_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_twitter_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_twitter_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_NETFLIX)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_NETFLIX)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_netflix_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_netflix_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_netflix_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_netflix_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_WEBEX)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_WEBEX)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_webex_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_webex_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_webex_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_webex_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TEAMVIEWER)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TEAMVIEWER)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_teamviewer_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_teamviewer_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_teamviewer_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_teamviewer_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_FACEBOOK)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_FACEBOOK)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_facebook_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_facebook_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_facebook_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_facebook_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TENCENT)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TENCENT)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_tencent_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_tencent_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_tencent_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_tencent_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_OPENDNS)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_OPENDNS)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_opendns_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_opendns_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_opendns_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_opendns_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_DROPBOX)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_DROPBOX)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_dropbox_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_dropbox_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_dropbox_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_dropbox_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_STARCRAFT)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_STARCRAFT)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_starcraft_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_starcraft_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_starcraft_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_starcraft_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_UBUNTUONE)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_UBUNTUONE)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_ubuntuone_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_ubuntuone_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_ubuntuone_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_ubuntuone_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TWITCH)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_TWITCH)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_twitch_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_twitch_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_twitch_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_twitch_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_HOTSPOT_SHIELD)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_HOTSPOT_SHIELD)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_hotspot_shield_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_hotspot_shield_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_hotspot_shield_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_hotspot_shield_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_GITHUB)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_GITHUB)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_github_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_github_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_github_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_github_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_STEAM)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_STEAM)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_steam_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_steam_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_steam_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_steam_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_BLOOMBERG)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_BLOOMBERG)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_bloomberg_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_bloomberg_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_bloomberg_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_bloomberg_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_EDGECAST)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_EDGECAST)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_edgecast_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_edgecast_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_edgecast_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_edgecast_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_GOTO)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_GOTO)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_goto_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_goto_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_goto_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_goto_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_RIOTGAMES)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_RIOTGAMES)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_riotgames_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_riotgames_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_riotgames_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_riotgames_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_THREEMA)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_THREEMA)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_threema_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_threema_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_threema_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_threema_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_ALIBABA)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_ALIBABA)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_alibaba_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_alibaba_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_alibaba_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_alibaba_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_AVAST)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_AVAST)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_avast_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_avast_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_avast_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_avast_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_DISCORD)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_DISCORD)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_discord_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_discord_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_discord_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_discord_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_LINE)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_LINE)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_line_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_line_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_line_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_line_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_VK)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_VK)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_vk_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_vk_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_vk_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_vk_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_YANDEX)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_YANDEX)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_yandex_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_yandex_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_yandex_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_yandex_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_YANDEX_CLOUD)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_YANDEX_CLOUD)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_yandex_cloud_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_yandex_cloud_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_yandex_cloud_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_yandex_cloud_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_DISNEYPLUS)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_DISNEYPLUS)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_disneyplus_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_disneyplus_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_disneyplus_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_disneyplus_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_HULU)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_HULU)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_hulu_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_hulu_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_hulu_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_hulu_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_EPICGAMES)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_EPICGAMES)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_epicgames_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_epicgames_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_epicgames_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_epicgames_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_NVIDIA)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_NVIDIA)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_nvidia_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_nvidia_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_nvidia_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_nvidia_protocol_list_6);
} }
if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_ROBLOX)) { if(is_ip_list_enabled(ndpi_str, NDPI_PROTOCOL_ROBLOX)) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->protocols_ptree, ndpi_protocol_roblox_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->protocols_ptree, ndpi_protocol_roblox_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_roblox_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->protocols_ptree6, ndpi_protocol_roblox_protocol_list_6);
} }
@@ -3658,15 +3672,15 @@ int ndpi_finalize_initialization(struct ndpi_detection_module_struct *ndpi_str)
} }
if(ndpi_str->cfg.risk_anonymous_subscriber_list_icloudprivaterelay_enabled) { if(ndpi_str->cfg.risk_anonymous_subscriber_list_icloudprivaterelay_enabled) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->ip_risk_ptree, ndpi_anonymous_subscriber_icloud_private_relay_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->ip_risk_ptree, ndpi_anonymous_subscriber_icloud_private_relay_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->ip_risk_ptree6, ndpi_anonymous_subscriber_icloud_private_relay_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->ip_risk_ptree6, ndpi_anonymous_subscriber_icloud_private_relay_protocol_list_6);
} }
if(ndpi_str->cfg.risk_anonymous_subscriber_list_protonvpn_enabled) { if(ndpi_str->cfg.risk_anonymous_subscriber_list_protonvpn_enabled) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->ip_risk_ptree, ndpi_anonymous_subscriber_protonvpn_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->ip_risk_ptree, ndpi_anonymous_subscriber_protonvpn_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->ip_risk_ptree6, ndpi_anonymous_subscriber_protonvpn_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->ip_risk_ptree6, ndpi_anonymous_subscriber_protonvpn_protocol_list_6);
} }
if(ndpi_str->cfg.risk_crawler_bot_list_enabled) { if(ndpi_str->cfg.risk_crawler_bot_list_enabled) {
ndpi_init_ptree_ipv4(ndpi_str, ndpi_str->ip_risk_ptree, ndpi_http_crawler_bot_protocol_list); ndpi_init_ptree_ipv4(ndpi_str->ip_risk_ptree, ndpi_http_crawler_bot_protocol_list);
ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->ip_risk_ptree6, ndpi_http_crawler_bot_protocol_list_6); ndpi_init_ptree_ipv6(ndpi_str, ndpi_str->ip_risk_ptree6, ndpi_http_crawler_bot_protocol_list_6);
} }
} }
@@ -4326,7 +4340,7 @@ static u_int16_t guess_protocol_id(struct ndpi_detection_module_struct *ndpi_str
/* Run some basic consistency tests */ /* Run some basic consistency tests */
if(packet->payload_packet_len < sizeof(struct ndpi_icmphdr)) { if(packet->payload_packet_len < sizeof(struct ndpi_icmphdr)) {
ndpi_set_risk(ndpi_str, flow, NDPI_MALFORMED_PACKET, NULL); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, NULL);
} else { } else {
u_int8_t icmp_type = (u_int8_t)packet->payload[0]; u_int8_t icmp_type = (u_int8_t)packet->payload[0];
u_int8_t icmp_code = (u_int8_t)packet->payload[1]; u_int8_t icmp_code = (u_int8_t)packet->payload[1];
@@ -4334,7 +4348,7 @@ static u_int16_t guess_protocol_id(struct ndpi_detection_module_struct *ndpi_str
/* https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml */ /* https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml */
if(((icmp_type >= 44) && (icmp_type <= 252)) if(((icmp_type >= 44) && (icmp_type <= 252))
|| (icmp_code > 15)) || (icmp_code > 15))
ndpi_set_risk(ndpi_str, flow, NDPI_MALFORMED_PACKET, NULL); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, NULL);
if(packet->payload_packet_len > sizeof(struct ndpi_icmphdr)) { if(packet->payload_packet_len > sizeof(struct ndpi_icmphdr)) {
flow->entropy = ndpi_entropy(packet->payload + sizeof(struct ndpi_icmphdr), flow->entropy = ndpi_entropy(packet->payload + sizeof(struct ndpi_icmphdr),
@@ -4344,12 +4358,12 @@ static u_int16_t guess_protocol_id(struct ndpi_detection_module_struct *ndpi_str
char str[32]; char str[32];
snprintf(str, sizeof(str), "Entropy %.2f", flow->entropy); snprintf(str, sizeof(str), "Entropy %.2f", flow->entropy);
ndpi_set_risk(ndpi_str, flow, NDPI_SUSPICIOUS_ENTROPY, str); ndpi_set_risk(flow, NDPI_SUSPICIOUS_ENTROPY, str);
} }
u_int16_t chksm = icmp4_checksum(packet->payload, packet->payload_packet_len); u_int16_t chksm = icmp4_checksum(packet->payload, packet->payload_packet_len);
if(chksm) { if(chksm) {
ndpi_set_risk(ndpi_str, flow, NDPI_MALFORMED_PACKET, NULL); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, NULL);
} }
} }
} }
@@ -4370,7 +4384,7 @@ static u_int16_t guess_protocol_id(struct ndpi_detection_module_struct *ndpi_str
/* Run some basic consistency tests */ /* Run some basic consistency tests */
if(packet->payload_packet_len < sizeof(struct ndpi_icmp6hdr)) if(packet->payload_packet_len < sizeof(struct ndpi_icmp6hdr))
ndpi_set_risk(ndpi_str, flow, NDPI_MALFORMED_PACKET, NULL); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, NULL);
else { else {
u_int8_t icmp6_type = (u_int8_t)packet->payload[0]; u_int8_t icmp6_type = (u_int8_t)packet->payload[0];
u_int8_t icmp6_code = (u_int8_t)packet->payload[1]; u_int8_t icmp6_code = (u_int8_t)packet->payload[1];
@@ -4378,7 +4392,7 @@ static u_int16_t guess_protocol_id(struct ndpi_detection_module_struct *ndpi_str
/* https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol_for_IPv6 */ /* https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol_for_IPv6 */
if(((icmp6_type >= 5) && (icmp6_type <= 127)) if(((icmp6_type >= 5) && (icmp6_type <= 127))
|| ((icmp6_code >= 156) && (icmp6_type != 255))) || ((icmp6_code >= 156) && (icmp6_type != 255)))
ndpi_set_risk(ndpi_str, flow, NDPI_MALFORMED_PACKET, NULL); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, NULL);
} }
} }
return(NDPI_PROTOCOL_IP_ICMPV6); return(NDPI_PROTOCOL_IP_ICMPV6);
@@ -4928,6 +4942,8 @@ int load_category_file_fd(struct ndpi_detection_module_struct *ndpi_str,
unsigned int failed_lines = 0; unsigned int failed_lines = 0;
unsigned int lines_read = 0; unsigned int lines_read = 0;
(void)lines_read;
if(!ndpi_str || !fd || !ndpi_str->protocols_ptree) if(!ndpi_str || !fd || !ndpi_str->protocols_ptree)
return(0); return(0);
@@ -5386,6 +5402,7 @@ void ndpi_set_bitmask_protocol_detection(char *label, struct ndpi_detection_modu
struct ndpi_flow_struct *flow), struct ndpi_flow_struct *flow),
const NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_bitmask, const NDPI_SELECTION_BITMASK_PROTOCOL_SIZE ndpi_selection_bitmask,
u_int8_t b_save_bitmask_unknow, u_int8_t b_add_detection_bitmask) { u_int8_t b_save_bitmask_unknow, u_int8_t b_add_detection_bitmask) {
(void)label;
/* /*
Compare specify protocol bitmask with main detection bitmask Compare specify protocol bitmask with main detection bitmask
*/ */
@@ -6882,9 +6899,9 @@ static void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_s
u_int8_t flags = ((u_int8_t*)tcph)[13]; u_int8_t flags = ((u_int8_t*)tcph)[13];
if(flags == 0) if(flags == 0)
ndpi_set_risk(ndpi_str, flow, NDPI_TCP_ISSUES, "TCP NULL scan"); ndpi_set_risk(flow, NDPI_TCP_ISSUES, "TCP NULL scan");
else if(flags == (TH_FIN | TH_PUSH | TH_URG)) else if(flags == (TH_FIN | TH_PUSH | TH_URG))
ndpi_set_risk(ndpi_str, flow, NDPI_TCP_ISSUES, "TCP XMAS scan"); ndpi_set_risk(flow, NDPI_TCP_ISSUES, "TCP XMAS scan");
if(ndpi_str->cfg.direction_detect_enabled && if(ndpi_str->cfg.direction_detect_enabled &&
(tcph->source != tcph->dest)) (tcph->source != tcph->dest))
@@ -6892,7 +6909,7 @@ static void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_s
if(packet->packet_direction == 0 /* cli -> srv */) { if(packet->packet_direction == 0 /* cli -> srv */) {
if(flags == TH_FIN) if(flags == TH_FIN)
ndpi_set_risk(ndpi_str, flow, NDPI_TCP_ISSUES, "TCP FIN scan"); ndpi_set_risk(flow, NDPI_TCP_ISSUES, "TCP FIN scan");
flow->l4.tcp.cli2srv_tcp_flags |= flags; flow->l4.tcp.cli2srv_tcp_flags |= flags;
} else } else
@@ -7062,11 +7079,11 @@ static void ndpi_connection_tracking(struct ndpi_detection_module_struct *ndpi_s
; /* multicast or broadcast */ ; /* multicast or broadcast */
else { else {
if(flow->packet_direction_complete_counter[flow->client_packet_direction] == 0) if(flow->packet_direction_complete_counter[flow->client_packet_direction] == 0)
ndpi_set_risk(ndpi_str, flow, NDPI_UNIDIRECTIONAL_TRAFFIC, "No client to server traffic"); /* Should never happen */ ndpi_set_risk(flow, NDPI_UNIDIRECTIONAL_TRAFFIC, "No client to server traffic"); /* Should never happen */
else if(flow->packet_direction_complete_counter[!flow->client_packet_direction] == 0) else if(flow->packet_direction_complete_counter[!flow->client_packet_direction] == 0)
ndpi_set_risk(ndpi_str, flow, NDPI_UNIDIRECTIONAL_TRAFFIC, "No server to client traffic"); ndpi_set_risk(flow, NDPI_UNIDIRECTIONAL_TRAFFIC, "No server to client traffic");
else { else {
ndpi_unset_risk(ndpi_str, flow, NDPI_UNIDIRECTIONAL_TRAFFIC); /* Clear bit */ ndpi_unset_risk(flow, NDPI_UNIDIRECTIONAL_TRAFFIC); /* Clear bit */
} }
} }
} }
@@ -7301,7 +7318,7 @@ static void ndpi_reconcile_msteams_udp(struct ndpi_detection_module_struct *ndpi
u_int8_t d_match = ((dport >= 3478) && (dport <= 3481)) ? 1 : 0; u_int8_t d_match = ((dport >= 3478) && (dport <= 3481)) ? 1 : 0;
if(s_match || d_match) { if(s_match || d_match) {
ndpi_int_change_protocol(ndpi_str, flow, ndpi_int_change_protocol(flow,
NDPI_PROTOCOL_SKYPE_TEAMS, master, NDPI_PROTOCOL_SKYPE_TEAMS, master,
/* Keep the same confidence */ /* Keep the same confidence */
flow->confidence); flow->confidence);
@@ -7319,8 +7336,7 @@ static void ndpi_reconcile_msteams_udp(struct ndpi_detection_module_struct *ndpi
/* ********************************************************************************* */ /* ********************************************************************************* */
static int ndpi_reconcile_msteams_call_udp_port(struct ndpi_detection_module_struct *ndpi_str, static int ndpi_reconcile_msteams_call_udp_port(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
u_int16_t sport, u_int16_t dport) { u_int16_t sport, u_int16_t dport) {
/* /*
@@ -7347,15 +7363,14 @@ static int ndpi_reconcile_msteams_call_udp_port(struct ndpi_detection_module_str
/* ********************************************************************************* */ /* ********************************************************************************* */
static void ndpi_reconcile_msteams_call_udp(struct ndpi_detection_module_struct *ndpi_str, static void ndpi_reconcile_msteams_call_udp(struct ndpi_flow_struct *flow) {
struct ndpi_flow_struct *flow) {
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_SKYPE_TEAMS_CALL) { if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_SKYPE_TEAMS_CALL) {
if(flow->l4_proto == IPPROTO_UDP) { if(flow->l4_proto == IPPROTO_UDP) {
u_int16_t sport = ntohs(flow->c_port); u_int16_t sport = ntohs(flow->c_port);
u_int16_t dport = ntohs(flow->s_port); u_int16_t dport = ntohs(flow->s_port);
if(ndpi_reconcile_msteams_call_udp_port(ndpi_str, flow, sport, dport) == 0) if(ndpi_reconcile_msteams_call_udp_port(flow, sport, dport) == 0)
ndpi_reconcile_msteams_call_udp_port(ndpi_str, flow, dport, sport); ndpi_reconcile_msteams_call_udp_port(flow, dport, sport);
} }
} }
} }
@@ -7408,13 +7423,13 @@ static void ndpi_reconcile_protocols(struct ndpi_detection_module_struct *ndpi_s
case NDPI_PROTOCOL_RTP: case NDPI_PROTOCOL_RTP:
case NDPI_PROTOCOL_COLLECTD: case NDPI_PROTOCOL_COLLECTD:
/* Remove NDPI_UNIDIRECTIONAL_TRAFFIC from unidirectional protocols */ /* Remove NDPI_UNIDIRECTIONAL_TRAFFIC from unidirectional protocols */
ndpi_unset_risk(ndpi_str, flow, NDPI_UNIDIRECTIONAL_TRAFFIC); ndpi_unset_risk(flow, NDPI_UNIDIRECTIONAL_TRAFFIC);
break; break;
case NDPI_PROTOCOL_SYSLOG: case NDPI_PROTOCOL_SYSLOG:
case NDPI_PROTOCOL_MDNS: case NDPI_PROTOCOL_MDNS:
if(flow->l4_proto == IPPROTO_UDP) if(flow->l4_proto == IPPROTO_UDP)
ndpi_unset_risk(ndpi_str, flow, NDPI_UNIDIRECTIONAL_TRAFFIC); ndpi_unset_risk(flow, NDPI_UNIDIRECTIONAL_TRAFFIC);
break; break;
case NDPI_PROTOCOL_TLS: case NDPI_PROTOCOL_TLS:
@@ -7432,12 +7447,12 @@ static void ndpi_reconcile_protocols(struct ndpi_detection_module_struct *ndpi_s
make_msteams_key(flow, 1 /* client */), make_msteams_key(flow, 1 /* client */),
&dummy, 0 /* Don't remove it as it can be used for other connections */, &dummy, 0 /* Don't remove it as it can be used for other connections */,
ndpi_get_current_time(flow))) { ndpi_get_current_time(flow))) {
ndpi_int_change_protocol(ndpi_str, flow, ndpi_int_change_protocol(flow,
NDPI_PROTOCOL_SKYPE_TEAMS, NDPI_PROTOCOL_TLS, NDPI_PROTOCOL_SKYPE_TEAMS, NDPI_PROTOCOL_TLS,
NDPI_CONFIDENCE_DPI_PARTIAL); NDPI_CONFIDENCE_DPI_PARTIAL);
} }
} else if(flow->guessed_protocol_id_by_ip == NDPI_PROTOCOL_TELEGRAM) { } else if(flow->guessed_protocol_id_by_ip == NDPI_PROTOCOL_TELEGRAM) {
ndpi_int_change_protocol(ndpi_str, flow, ndpi_int_change_protocol(flow,
flow->guessed_protocol_id_by_ip, flow->detected_protocol_stack[0], flow->guessed_protocol_id_by_ip, flow->detected_protocol_stack[0],
NDPI_CONFIDENCE_DPI_PARTIAL); NDPI_CONFIDENCE_DPI_PARTIAL);
} }
@@ -7461,16 +7476,16 @@ static void ndpi_reconcile_protocols(struct ndpi_detection_module_struct *ndpi_s
} }
} }
ndpi_reconcile_msteams_call_udp(ndpi_str, flow); ndpi_reconcile_msteams_call_udp(flow);
break; break;
case NDPI_PROTOCOL_RDP: case NDPI_PROTOCOL_RDP:
ndpi_set_risk(ndpi_str, flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found RDP"); /* Remote assistance */ ndpi_set_risk(flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found RDP"); /* Remote assistance */
break; break;
case NDPI_PROTOCOL_ANYDESK: case NDPI_PROTOCOL_ANYDESK:
if(flow->l4_proto == IPPROTO_TCP) /* TCP only */ if(flow->l4_proto == IPPROTO_TCP) /* TCP only */
ndpi_set_risk(ndpi_str, flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found AnyDesk"); /* Remote assistance */ ndpi_set_risk(flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found AnyDesk"); /* Remote assistance */
break; break;
/* Generic container for microsoft subprotocols */ /* Generic container for microsoft subprotocols */
@@ -7480,7 +7495,7 @@ static void ndpi_reconcile_protocols(struct ndpi_detection_module_struct *ndpi_s
case NDPI_PROTOCOL_MS_ONE_DRIVE: case NDPI_PROTOCOL_MS_ONE_DRIVE:
case NDPI_PROTOCOL_MS_OUTLOOK: case NDPI_PROTOCOL_MS_OUTLOOK:
case NDPI_PROTOCOL_SKYPE_TEAMS: case NDPI_PROTOCOL_SKYPE_TEAMS:
ndpi_int_change_protocol(ndpi_str, flow, ndpi_int_change_protocol(flow,
flow->guessed_protocol_id_by_ip, flow->detected_protocol_stack[1], flow->guessed_protocol_id_by_ip, flow->detected_protocol_stack[1],
NDPI_CONFIDENCE_DPI_PARTIAL); NDPI_CONFIDENCE_DPI_PARTIAL);
break; break;
@@ -7491,7 +7506,7 @@ static void ndpi_reconcile_protocols(struct ndpi_detection_module_struct *ndpi_s
case NDPI_PROTOCOL_GOOGLE: case NDPI_PROTOCOL_GOOGLE:
switch(flow->guessed_protocol_id_by_ip) { switch(flow->guessed_protocol_id_by_ip) {
case NDPI_PROTOCOL_GOOGLE_CLOUD: case NDPI_PROTOCOL_GOOGLE_CLOUD:
ndpi_int_change_protocol(ndpi_str, flow, ndpi_int_change_protocol(flow,
flow->guessed_protocol_id_by_ip, flow->detected_protocol_stack[1], flow->guessed_protocol_id_by_ip, flow->detected_protocol_stack[1],
NDPI_CONFIDENCE_DPI_PARTIAL); NDPI_CONFIDENCE_DPI_PARTIAL);
@@ -7510,7 +7525,7 @@ static void ndpi_reconcile_protocols(struct ndpi_detection_module_struct *ndpi_s
case NDPI_PROTOCOL_UNSAFE: case NDPI_PROTOCOL_UNSAFE:
case NDPI_PROTOCOL_POTENTIALLY_DANGEROUS: case NDPI_PROTOCOL_POTENTIALLY_DANGEROUS:
case NDPI_PROTOCOL_DANGEROUS: case NDPI_PROTOCOL_DANGEROUS:
ndpi_set_risk(ndpi_str, flow, NDPI_UNSAFE_PROTOCOL, NULL); ndpi_set_risk(flow, NDPI_UNSAFE_PROTOCOL, NULL);
break; break;
default: default:
/* Nothing to do */ /* Nothing to do */
@@ -7635,22 +7650,21 @@ static void ndpi_add_connection_as_zoom(struct ndpi_detection_module_struct *ndp
As these conditions won't happen with nDPI protocol-detected protocols As these conditions won't happen with nDPI protocol-detected protocols
it is not necessary to call this function elsewhere it is not necessary to call this function elsewhere
*/ */
static void ndpi_check_tcp_flags(struct ndpi_detection_module_struct *ndpi_str, static void ndpi_check_tcp_flags(struct ndpi_flow_struct *flow) {
struct ndpi_flow_struct *flow) {
// printf("[TOTAL] %u / %u [tot: %u]\n", flow->packet_direction_complete_counter[0], flow->packet_direction_complete_counter[1], flow->all_packets_counter); // printf("[TOTAL] %u / %u [tot: %u]\n", flow->packet_direction_complete_counter[0], flow->packet_direction_complete_counter[1], flow->all_packets_counter);
if((flow->l4.tcp.cli2srv_tcp_flags & TH_SYN) if((flow->l4.tcp.cli2srv_tcp_flags & TH_SYN)
&& (flow->l4.tcp.srv2cli_tcp_flags & TH_RST) && (flow->l4.tcp.srv2cli_tcp_flags & TH_RST)
&& (flow->packet_counter == 0 /* Ignore connections terminated by RST but that exchanged data (3WH + RST) */) && (flow->packet_counter == 0 /* Ignore connections terminated by RST but that exchanged data (3WH + RST) */)
) )
ndpi_set_risk(ndpi_str, flow, NDPI_TCP_ISSUES, "Connection refused (server)"); ndpi_set_risk(flow, NDPI_TCP_ISSUES, "Connection refused (server)");
else if((flow->l4.tcp.cli2srv_tcp_flags & TH_SYN) else if((flow->l4.tcp.cli2srv_tcp_flags & TH_SYN)
&& (flow->l4.tcp.cli2srv_tcp_flags & TH_RST) && (flow->l4.tcp.cli2srv_tcp_flags & TH_RST)
&& (flow->packet_counter == 0 /* Ignore connections terminated by RST but that exchanged data (3WH + RST) */) && (flow->packet_counter == 0 /* Ignore connections terminated by RST but that exchanged data (3WH + RST) */)
) )
ndpi_set_risk(ndpi_str, flow, NDPI_TCP_ISSUES, "Connection refused (client)"); ndpi_set_risk(flow, NDPI_TCP_ISSUES, "Connection refused (client)");
else if((flow->l4.tcp.srv2cli_tcp_flags & TH_RST) && (flow->packet_direction_complete_counter[1 /* server -> client */] == 1)) else if((flow->l4.tcp.srv2cli_tcp_flags & TH_RST) && (flow->packet_direction_complete_counter[1 /* server -> client */] == 1))
ndpi_set_risk(ndpi_str, flow, NDPI_TCP_ISSUES, "TCP probing attempt"); ndpi_set_risk(flow, NDPI_TCP_ISSUES, "TCP probing attempt");
} }
/* ********************************************************************************* */ /* ********************************************************************************* */
@@ -7668,7 +7682,7 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
return(ret); return(ret);
if(flow->l4_proto == IPPROTO_TCP) if(flow->l4_proto == IPPROTO_TCP)
ndpi_check_tcp_flags(ndpi_str, flow); ndpi_check_tcp_flags(flow);
/* Init defaults */ /* Init defaults */
ret.master_protocol = flow->detected_protocol_stack[1], ret.app_protocol = flow->detected_protocol_stack[0]; ret.master_protocol = flow->detected_protocol_stack[1], ret.app_protocol = flow->detected_protocol_stack[0];
@@ -7723,7 +7737,7 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
/* TODO: not sure about the best "order" among fully encrypted logic, classification by-port and classification by-ip...*/ /* TODO: not sure about the best "order" among fully encrypted logic, classification by-port and classification by-ip...*/
if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN && if(ret.app_protocol == NDPI_PROTOCOL_UNKNOWN &&
flow->first_pkt_fully_encrypted == 1) { flow->first_pkt_fully_encrypted == 1) {
ndpi_set_risk(ndpi_str, flow, NDPI_FULLY_ENCRYPTED, NULL); ndpi_set_risk(flow, NDPI_FULLY_ENCRYPTED, NULL);
} }
/* Classification by-port */ /* Classification by-port */
@@ -8031,7 +8045,7 @@ int ndpi_fill_ip_protocol_category(struct ndpi_detection_module_struct *ndpi_str
ret->custom_category_userdata = node->custom_user_data; ret->custom_category_userdata = node->custom_user_data;
if((ret->category == CUSTOM_CATEGORY_MALWARE) && (match_client == false)) { if((ret->category == CUSTOM_CATEGORY_MALWARE) && (match_client == false)) {
ndpi_set_risk(ndpi_str, flow, NDPI_MALWARE_HOST_CONTACTED, "Client contacted malware host"); ndpi_set_risk(flow, NDPI_MALWARE_HOST_CONTACTED, "Client contacted malware host");
} }
return(1); return(1);
@@ -8077,7 +8091,7 @@ int ndpi_fill_ip6_protocol_category(struct ndpi_detection_module_struct *ndpi_st
ret->custom_category_userdata = node->custom_user_data; ret->custom_category_userdata = node->custom_user_data;
if((ret->category == CUSTOM_CATEGORY_MALWARE) && (match_client == false)) { if((ret->category == CUSTOM_CATEGORY_MALWARE) && (match_client == false)) {
ndpi_set_risk(ndpi_str, flow, NDPI_MALWARE_HOST_CONTACTED, "Client contacted malware host"); ndpi_set_risk(flow, NDPI_MALWARE_HOST_CONTACTED, "Client contacted malware host");
} }
return(1); return(1);
@@ -8145,9 +8159,7 @@ static int ndpi_is_ntop_protocol(ndpi_protocol *ret) {
/* ********************************************************************************* */ /* ********************************************************************************* */
static int ndpi_check_protocol_port_mismatch_exceptions(struct ndpi_detection_module_struct *ndpi_str, static int ndpi_check_protocol_port_mismatch_exceptions(default_ports_tree_node_t *expected_proto,
struct ndpi_flow_struct *flow,
default_ports_tree_node_t *expected_proto,
ndpi_protocol *returned_proto) { ndpi_protocol *returned_proto) {
/* /*
For TLS (and other protocols) it is not simple to guess the exact protocol so before For TLS (and other protocols) it is not simple to guess the exact protocol so before
@@ -8416,7 +8428,7 @@ static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detectio
) { ) {
// printf("******** %u / %u\n", found->proto->protoId, ret.master_protocol); // printf("******** %u / %u\n", found->proto->protoId, ret.master_protocol);
if(!ndpi_check_protocol_port_mismatch_exceptions(ndpi_str, flow, found, &ret)) { if(!ndpi_check_protocol_port_mismatch_exceptions(found, &ret)) {
/* /*
Before triggering the alert we need to make some extra checks Before triggering the alert we need to make some extra checks
- the protocol found is not running on the port we have found - the protocol found is not running on the port we have found
@@ -8454,7 +8466,7 @@ static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detectio
} }
str[offset] = '\0'; str[offset] = '\0';
ndpi_set_risk(ndpi_str, flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT, str); ndpi_set_risk(flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT, str);
} }
} }
} }
@@ -8486,7 +8498,7 @@ static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detectio
if((r == NULL) if((r == NULL)
|| ((r->proto->protoId != ret.app_protocol) && (r->proto->protoId != ret.master_protocol))) || ((r->proto->protoId != ret.app_protocol) && (r->proto->protoId != ret.master_protocol)))
ndpi_set_risk(ndpi_str, flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT,NULL); ndpi_set_risk(flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT,NULL);
} }
} }
@@ -8516,7 +8528,7 @@ static ndpi_protocol ndpi_internal_detection_process_packet(struct ndpi_detectio
} }
if(net_risk != NDPI_NO_RISK) if(net_risk != NDPI_NO_RISK)
ndpi_set_risk(ndpi_str, flow, net_risk, NULL); ndpi_set_risk(flow, net_risk, NULL);
flow->tree_risk_checked = 1; flow->tree_risk_checked = 1;
} }
@@ -8715,7 +8727,7 @@ struct header_line {
struct ndpi_int_one_line_struct *line; struct ndpi_int_one_line_struct *line;
}; };
static void parse_single_packet_line(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow) static void parse_single_packet_line(struct ndpi_detection_module_struct *ndpi_str)
{ {
struct ndpi_packet_struct *packet = &ndpi_str->packet; struct ndpi_packet_struct *packet = &ndpi_str->packet;
struct ndpi_int_one_line_struct *line; struct ndpi_int_one_line_struct *line;
@@ -8886,7 +8898,7 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_str,
packet->line[packet->parsed_lines].len = packet->line[packet->parsed_lines].len =
(u_int16_t)(((size_t) &packet->payload[a]) - ((size_t) packet->line[packet->parsed_lines].ptr)); (u_int16_t)(((size_t) &packet->payload[a]) - ((size_t) packet->line[packet->parsed_lines].ptr));
parse_single_packet_line(ndpi_str, flow); parse_single_packet_line(ndpi_str);
if(packet->line[packet->parsed_lines].len == 0) { if(packet->line[packet->parsed_lines].len == 0) {
packet->empty_line_position = a; packet->empty_line_position = a;
@@ -8909,14 +8921,14 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_str,
(u_int16_t)(((size_t) &packet->payload[packet->payload_packet_len]) - (u_int16_t)(((size_t) &packet->payload[packet->payload_packet_len]) -
((size_t) packet->line[packet->parsed_lines].ptr)); ((size_t) packet->line[packet->parsed_lines].ptr));
parse_single_packet_line(ndpi_str, flow); parse_single_packet_line(ndpi_str);
packet->parsed_lines++; packet->parsed_lines++;
} }
} }
/* ********************************************************************************* */ /* ********************************************************************************* */
void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow) { void ndpi_parse_packet_line_info_any(struct ndpi_detection_module_struct *ndpi_str) {
struct ndpi_packet_struct *packet = &ndpi_str->packet; struct ndpi_packet_struct *packet = &ndpi_str->packet;
u_int32_t a; u_int32_t a;
u_int16_t end = packet->payload_packet_len; u_int16_t end = packet->payload_packet_len;
@@ -8986,14 +8998,14 @@ void ndpi_set_detected_protocol(struct ndpi_detection_module_struct *ndpi_str, s
ndpi_confidence_t confidence) { ndpi_confidence_t confidence) {
ndpi_protocol ret; ndpi_protocol ret;
ndpi_int_change_protocol(ndpi_str, flow, upper_detected_protocol, lower_detected_protocol, confidence); ndpi_int_change_protocol(flow, upper_detected_protocol, lower_detected_protocol, confidence);
ret.master_protocol = flow->detected_protocol_stack[1], ret.app_protocol = flow->detected_protocol_stack[0]; ret.master_protocol = flow->detected_protocol_stack[1], ret.app_protocol = flow->detected_protocol_stack[0];
ndpi_reconcile_protocols(ndpi_str, flow, &ret); ndpi_reconcile_protocols(ndpi_str, flow, &ret);
} }
/* ********************************************************************************* */ /* ********************************************************************************* */
void reset_detected_protocol(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow) { void reset_detected_protocol(struct ndpi_flow_struct *flow) {
flow->detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN; flow->detected_protocol_stack[1] = NDPI_PROTOCOL_UNKNOWN;
flow->detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN; flow->detected_protocol_stack[0] = NDPI_PROTOCOL_UNKNOWN;
flow->confidence = NDPI_CONFIDENCE_UNKNOWN; flow->confidence = NDPI_CONFIDENCE_UNKNOWN;
@@ -9001,36 +9013,36 @@ void reset_detected_protocol(struct ndpi_detection_module_struct *ndpi_str, stru
/* ********************************************************************************* */ /* ********************************************************************************* */
u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow) { u_int16_t ndpi_get_flow_masterprotocol(struct ndpi_flow_struct *flow) {
return(flow->detected_protocol_stack[1]); return(flow->detected_protocol_stack[1]);
} }
/* ********************************************************************************* */ /* ********************************************************************************* */
u_int16_t ndpi_get_flow_appprotocol(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow) { u_int16_t ndpi_get_flow_appprotocol(struct ndpi_flow_struct *flow) {
return(flow->detected_protocol_stack[0]); return(flow->detected_protocol_stack[0]);
} }
/* ********************************************************************************* */ /* ********************************************************************************* */
ndpi_protocol_category_t ndpi_get_flow_category(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow) ndpi_protocol_category_t ndpi_get_flow_category(struct ndpi_flow_struct *flow)
{ {
return(flow->category); return(flow->category);
} }
/* ********************************************************************************* */ /* ********************************************************************************* */
void ndpi_get_flow_ndpi_proto(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, void ndpi_get_flow_ndpi_proto(struct ndpi_flow_struct *flow,
struct ndpi_proto * ndpi_proto) struct ndpi_proto * ndpi_proto)
{ {
ndpi_proto->master_protocol = ndpi_get_flow_masterprotocol(ndpi_str, flow); ndpi_proto->master_protocol = ndpi_get_flow_masterprotocol(flow);
ndpi_proto->app_protocol = ndpi_get_flow_appprotocol(ndpi_str, flow); ndpi_proto->app_protocol = ndpi_get_flow_appprotocol(flow);
ndpi_proto->category = ndpi_get_flow_category(ndpi_str, flow); ndpi_proto->category = ndpi_get_flow_category(flow);
} }
/* ********************************************************************************* */ /* ********************************************************************************* */
static void ndpi_int_change_flow_protocol(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, static void ndpi_int_change_flow_protocol(struct ndpi_flow_struct *flow,
u_int16_t upper_detected_protocol, u_int16_t lower_detected_protocol, u_int16_t upper_detected_protocol, u_int16_t lower_detected_protocol,
ndpi_confidence_t confidence) { ndpi_confidence_t confidence) {
flow->detected_protocol_stack[0] = upper_detected_protocol, flow->detected_protocol_stack[0] = upper_detected_protocol,
@@ -9045,7 +9057,7 @@ static void ndpi_int_change_flow_protocol(struct ndpi_detection_module_struct *n
* what it does is: * what it does is:
* 1.update the flow protocol stack with the new protocol * 1.update the flow protocol stack with the new protocol
*/ */
static void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, static void ndpi_int_change_protocol(struct ndpi_flow_struct *flow,
u_int16_t upper_detected_protocol, u_int16_t lower_detected_protocol, u_int16_t upper_detected_protocol, u_int16_t lower_detected_protocol,
ndpi_confidence_t confidence) { ndpi_confidence_t confidence) {
if((upper_detected_protocol == NDPI_PROTOCOL_UNKNOWN) && (lower_detected_protocol != NDPI_PROTOCOL_UNKNOWN)) if((upper_detected_protocol == NDPI_PROTOCOL_UNKNOWN) && (lower_detected_protocol != NDPI_PROTOCOL_UNKNOWN))
@@ -9054,12 +9066,12 @@ static void ndpi_int_change_protocol(struct ndpi_detection_module_struct *ndpi_s
if(upper_detected_protocol == lower_detected_protocol) if(upper_detected_protocol == lower_detected_protocol)
lower_detected_protocol = NDPI_PROTOCOL_UNKNOWN; lower_detected_protocol = NDPI_PROTOCOL_UNKNOWN;
ndpi_int_change_flow_protocol(ndpi_str, flow, upper_detected_protocol, lower_detected_protocol, confidence); ndpi_int_change_flow_protocol(flow, upper_detected_protocol, lower_detected_protocol, confidence);
} }
/* ********************************************************************************* */ /* ********************************************************************************* */
void change_category(struct ndpi_detection_module_struct *ndpi_str, struct ndpi_flow_struct *flow, void change_category(struct ndpi_flow_struct *flow,
ndpi_protocol_category_t protocol_category) { ndpi_protocol_category_t protocol_category) {
flow->category = protocol_category; flow->category = protocol_category;
} }
@@ -9195,7 +9207,7 @@ ndpi_protocol ndpi_guess_undetected_protocol_v4(struct ndpi_detection_module_str
if((proto == IPPROTO_TCP) || (proto == IPPROTO_UDP)) { if((proto == IPPROTO_TCP) || (proto == IPPROTO_UDP)) {
if(shost && dhost) if(shost && dhost)
rc = ndpi_search_tcp_or_udp_raw(ndpi_str, flow, proto, shost, dhost); rc = ndpi_search_tcp_or_udp_raw(ndpi_str, flow, shost, dhost);
else else
rc = NDPI_PROTOCOL_UNKNOWN; rc = NDPI_PROTOCOL_UNKNOWN;
@@ -9233,8 +9245,7 @@ ndpi_protocol ndpi_guess_undetected_protocol(struct ndpi_detection_module_struct
/* ****************************************************** */ /* ****************************************************** */
char *ndpi_protocol2id(struct ndpi_detection_module_struct *ndpi_str, char *ndpi_protocol2id(ndpi_protocol proto, char *buf, u_int buf_len) {
ndpi_protocol proto, char *buf, u_int buf_len) {
if((proto.master_protocol != NDPI_PROTOCOL_UNKNOWN) && (proto.master_protocol != proto.app_protocol)) { if((proto.master_protocol != NDPI_PROTOCOL_UNKNOWN) && (proto.master_protocol != proto.app_protocol)) {
if(proto.app_protocol != NDPI_PROTOCOL_UNKNOWN) if(proto.app_protocol != NDPI_PROTOCOL_UNKNOWN)
ndpi_snprintf(buf, buf_len, "%u.%u", proto.master_protocol, proto.app_protocol); ndpi_snprintf(buf, buf_len, "%u.%u", proto.master_protocol, proto.app_protocol);
@@ -9464,8 +9475,7 @@ ndpi_protocol_breed_t ndpi_get_proto_breed(struct ndpi_detection_module_struct *
/* ****************************************************** */ /* ****************************************************** */
char *ndpi_get_proto_breed_name(struct ndpi_detection_module_struct *ndpi_str, char *ndpi_get_proto_breed_name(ndpi_protocol_breed_t breed_id) {
ndpi_protocol_breed_t breed_id) {
switch(breed_id) { switch(breed_id) {
case NDPI_PROTOCOL_SAFE: case NDPI_PROTOCOL_SAFE:
return("Safe"); return("Safe");
@@ -9533,7 +9543,7 @@ void ndpi_dump_protocols(struct ndpi_detection_module_struct *ndpi_str, FILE *du
ndpi_str->proto_defaults[i].protoName, ndpi_str->proto_defaults[i].protoName,
ndpi_get_l4_proto_name(ndpi_get_l4_proto_info(ndpi_str, i)), ndpi_get_l4_proto_name(ndpi_get_l4_proto_info(ndpi_str, i)),
ndpi_str->proto_defaults[i].isAppProtocol ? "" : "X", ndpi_str->proto_defaults[i].isAppProtocol ? "" : "X",
ndpi_get_proto_breed_name(ndpi_str, ndpi_str->proto_defaults[i].protoBreed), ndpi_get_proto_breed_name(ndpi_str->proto_defaults[i].protoBreed),
ndpi_category_get_name(ndpi_str, ndpi_str->proto_defaults[i].protoCategory)); ndpi_category_get_name(ndpi_str, ndpi_str->proto_defaults[i].protoCategory));
} }
@@ -9790,7 +9800,7 @@ void ndpi_check_subprotocol_risk(struct ndpi_detection_module_struct *ndpi_str,
switch(subprotocol_id) { switch(subprotocol_id) {
case NDPI_PROTOCOL_ANYDESK: case NDPI_PROTOCOL_ANYDESK:
ndpi_set_risk(ndpi_str, flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found AnyDesk"); /* Remote assistance */ ndpi_set_risk(flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found AnyDesk"); /* Remote assistance */
break; break;
} }
} }
@@ -9831,7 +9841,7 @@ u_int16_t ndpi_match_host_subprotocol(struct ndpi_detection_module_struct *ndpi_
char str[64] = { '\0' }; char str[64] = { '\0' };
strncpy(str, string_to_match, ndpi_min(string_to_match_len, sizeof(str)-1)); strncpy(str, string_to_match, ndpi_min(string_to_match_len, sizeof(str)-1));
ndpi_set_risk(ndpi_str, flow, NDPI_RISKY_DOMAIN, str); ndpi_set_risk(flow, NDPI_RISKY_DOMAIN, str);
} }
} }
@@ -9840,7 +9850,7 @@ u_int16_t ndpi_match_host_subprotocol(struct ndpi_detection_module_struct *ndpi_
char str[64] = { '\0' }; char str[64] = { '\0' };
strncpy(str, string_to_match, ndpi_min(string_to_match_len, sizeof(str)-1)); strncpy(str, string_to_match, ndpi_min(string_to_match_len, sizeof(str)-1));
ndpi_set_risk(ndpi_str, flow, NDPI_PUNYCODE_IDN, str); ndpi_set_risk(flow, NDPI_PUNYCODE_IDN, str);
} }
return(rc); return(rc);
@@ -9868,7 +9878,7 @@ int ndpi_match_hostname_protocol(struct ndpi_detection_module_struct *ndpi_struc
if(subproto != NDPI_PROTOCOL_UNKNOWN) { if(subproto != NDPI_PROTOCOL_UNKNOWN) {
ndpi_set_detected_protocol(ndpi_struct, flow, subproto, master_protocol, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, subproto, master_protocol, NDPI_CONFIDENCE_DPI);
if(!category_depends_on_master(master_protocol)) if(!category_depends_on_master(master_protocol))
change_category(ndpi_struct, flow, ret_match.protocol_category); change_category(flow, ret_match.protocol_category);
if(subproto == NDPI_PROTOCOL_OOKLA) { if(subproto == NDPI_PROTOCOL_OOKLA) {
ookla_add_to_cache(ndpi_struct, flow); ookla_add_to_cache(ndpi_struct, flow);
@@ -10031,6 +10041,8 @@ static void __lru_cache_lock(struct ndpi_lru_cache *c)
if(c->shared) { if(c->shared) {
pthread_mutex_lock(&c->mutex); pthread_mutex_lock(&c->mutex);
} }
#else
(void)c;
#endif #endif
} }
@@ -10040,6 +10052,8 @@ static void __lru_cache_unlock(struct ndpi_lru_cache *c)
if(c->shared) { if(c->shared) {
pthread_mutex_unlock(&c->mutex); pthread_mutex_unlock(&c->mutex);
} }
#else
(void)c;
#endif #endif
} }
@@ -10153,7 +10167,7 @@ int ndpi_get_lru_cache_stats(struct ndpi_global_context *g_ctx,
1 - Additional dissection is possible 1 - Additional dissection is possible
*/ */
u_int8_t ndpi_extra_dissection_possible(struct ndpi_detection_module_struct *ndpi_str, u_int8_t ndpi_extra_dissection_possible(struct ndpi_detection_module_struct *ndpi_str,
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
NDPI_LOG_DBG2(ndpi_str, "Protos (%u.%u): %d\n", NDPI_LOG_DBG2(ndpi_str, "Protos (%u.%u): %d\n",
flow->detected_protocol_stack[0], flow->detected_protocol_stack[0],
flow->detected_protocol_stack[1], flow->detected_protocol_stack[1],
@@ -10346,7 +10360,6 @@ u_int8_t ends_with(struct ndpi_detection_module_struct *ndpi_struct,
u_int8_t ends_len = strlen(ends); u_int8_t ends_len = strlen(ends);
u_int8_t rc; u_int8_t rc;
if(str_len < ends_len) return(0); if(str_len < ends_len) return(0);
rc = (strncmp(&str[str_len-ends_len], ends, ends_len) != 0) ? 0 : 1; rc = (strncmp(&str[str_len-ends_len], ends, ends_len) != 0) ? 0 : 1;
@@ -10398,7 +10411,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
if(rc) { if(rc) {
if(flow) if(flow)
ndpi_set_risk(ndpi_str, flow, NDPI_SUSPICIOUS_DGA_DOMAIN, name); ndpi_set_risk(flow, NDPI_SUSPICIOUS_DGA_DOMAIN, name);
} }
return(rc); return(rc);
@@ -10545,7 +10558,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|| ((max_domain_element_len >= 19 /* word too long. Example bbcbedxhgjmdobdprmen.com */) && ((num_char_repetitions > 1) || (num_digits > 1))) || ((max_domain_element_len >= 19 /* word too long. Example bbcbedxhgjmdobdprmen.com */) && ((num_char_repetitions > 1) || (num_digits > 1)))
) { ) {
if(flow) { if(flow) {
ndpi_set_risk(ndpi_str, flow, NDPI_SUSPICIOUS_DGA_DOMAIN, name); ndpi_set_risk(flow, NDPI_SUSPICIOUS_DGA_DOMAIN, name);
} }
NDPI_LOG_DBG2(ndpi_str, "[DGA] Found!"); NDPI_LOG_DBG2(ndpi_str, "[DGA] Found!");
@@ -10699,7 +10712,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
NDPI_LOG_DBG2(ndpi_str, "[DGA] Result: %u\n", rc); NDPI_LOG_DBG2(ndpi_str, "[DGA] Result: %u\n", rc);
if(rc && flow) if(rc && flow)
ndpi_set_risk(ndpi_str, flow, NDPI_SUSPICIOUS_DGA_DOMAIN, name); ndpi_set_risk(flow, NDPI_SUSPICIOUS_DGA_DOMAIN, name);
return(rc); return(rc);
} }
@@ -10852,6 +10865,11 @@ static ndpi_cfg_error _set_param_enable_disable(struct ndpi_detection_module_str
const char *proto) { const char *proto) {
int *variable = (int *)_variable; int *variable = (int *)_variable;
(void)ndpi_str;
(void)min_value;
(void)max_value;
(void)proto;
if(strcmp(value, "1") == 0 || if(strcmp(value, "1") == 0 ||
strcmp(value, "enable") == 0) { strcmp(value, "enable") == 0) {
*variable = 1; *variable = 1;
@@ -10877,6 +10895,9 @@ static ndpi_cfg_error _set_param_int(struct ndpi_detection_module_struct *ndpi_s
const char *errstrp; const char *errstrp;
long val; long val;
(void)ndpi_str;
(void)proto;
val = ndpi_strtonum(value, LONG_MIN, LONG_MAX, &errstrp, 0); val = ndpi_strtonum(value, LONG_MIN, LONG_MAX, &errstrp, 0);
if(errstrp) { if(errstrp) {
return NDPI_CFG_INVALID_PARAM; return NDPI_CFG_INVALID_PARAM;
@@ -10898,6 +10919,8 @@ static ndpi_cfg_error _set_param_int(struct ndpi_detection_module_struct *ndpi_s
static char *_get_param_int(void *_variable, const char *proto, char *buf, int buf_len) { static char *_get_param_int(void *_variable, const char *proto, char *buf, int buf_len) {
int *variable = (int *)_variable; int *variable = (int *)_variable;
(void)proto;
snprintf(buf, buf_len, "%d", *variable); snprintf(buf, buf_len, "%d", *variable);
buf[buf_len - 1] = '\0'; buf[buf_len - 1] = '\0';
return buf; return buf;
@@ -10908,6 +10931,8 @@ static char *_get_param_int(void *_variable, const char *proto, char *buf, int b
static char *_get_param_string(void *_variable, const char *proto, char *buf, int buf_len) { static char *_get_param_string(void *_variable, const char *proto, char *buf, int buf_len) {
char *variable = (char *)_variable; char *variable = (char *)_variable;
(void)proto;
snprintf(buf, buf_len, "%s", variable); snprintf(buf, buf_len, "%s", variable);
buf[buf_len - 1] = '\0'; buf[buf_len - 1] = '\0';
return buf; return buf;
@@ -10921,6 +10946,11 @@ static ndpi_cfg_error _set_param_filename(struct ndpi_detection_module_struct *n
const char *proto) { const char *proto) {
char *variable = (char *)_variable; char *variable = (char *)_variable;
(void)ndpi_str;
(void)min_value;
(void)max_value;
(void)proto;
if(value == NULL) { /* Valid value */ if(value == NULL) { /* Valid value */
variable[0] = '\0'; variable[0] = '\0';
return NDPI_CFG_OK; return NDPI_CFG_OK;
@@ -10985,6 +11015,10 @@ static ndpi_cfg_error _set_param_protocol_enable_disable(struct ndpi_detection_m
NDPI_PROTOCOL_BITMASK *bitmask = (NDPI_PROTOCOL_BITMASK *)_variable; NDPI_PROTOCOL_BITMASK *bitmask = (NDPI_PROTOCOL_BITMASK *)_variable;
u_int16_t proto_id; u_int16_t proto_id;
(void)ndpi_str;
(void)min_value;
(void)max_value;
if(strcmp(proto, "any") == 0 || if(strcmp(proto, "any") == 0 ||
strcmp(proto, "all") == 0 || strcmp(proto, "all") == 0 ||
strcmp(proto, "$PROTO_NAME_OR_ID") == 0) { strcmp(proto, "$PROTO_NAME_OR_ID") == 0) {
@@ -11023,6 +11057,9 @@ static int clbk_only_with_global_ctx(struct ndpi_detection_module_struct *ndpi_s
{ {
int *variable = (int *)_variable; int *variable = (int *)_variable;
(void)proto;
(void)param;
/* Integer set > 0 only if there is a global context */ /* Integer set > 0 only if there is a global context */
if(*variable > 0 && !ndpi_str->g_ctx) { if(*variable > 0 && !ndpi_str->g_ctx) {
*variable = 0; *variable = 0;
+2
View File
@@ -505,11 +505,13 @@ static inline void ndpi_serialize_single_float(ndpi_private_serializer *serializ
/* ********************************** */ /* ********************************** */
/* TODO: fix portability across platforms */ /* TODO: fix portability across platforms */
#if 0
static inline void ndpi_serialize_single_double(ndpi_private_serializer *serializer, static inline void ndpi_serialize_single_double(ndpi_private_serializer *serializer,
double s) { double s) {
memcpy(&serializer->buffer.data[serializer->status.buffer.size_used], &s, sizeof(s)); memcpy(&serializer->buffer.data[serializer->status.buffer.size_used], &s, sizeof(s));
serializer->status.buffer.size_used += sizeof(double); serializer->status.buffer.size_used += sizeof(double);
} }
#endif
/* ********************************** */ /* ********************************** */
+11 -17
View File
@@ -718,8 +718,7 @@ static inline int ndpi_is_valid_char(char c) {
/* ******************************************************************** */ /* ******************************************************************** */
static int ndpi_find_non_eng_bigrams(struct ndpi_detection_module_struct *ndpi_struct, static int ndpi_find_non_eng_bigrams(char *str) {
char *str) {
char s[3]; char s[3];
if((ndpi_isdigit(str[0]) && ndpi_isdigit(str[1])) if((ndpi_isdigit(str[0]) && ndpi_isdigit(str[1]))
@@ -737,8 +736,7 @@ static int ndpi_find_non_eng_bigrams(struct ndpi_detection_module_struct *ndpi_s
/* #define PRINT_STRINGS 1 */ /* #define PRINT_STRINGS 1 */
int ndpi_has_human_readeable_string(struct ndpi_detection_module_struct *ndpi_struct, int ndpi_has_human_readeable_string(char *buffer, u_int buffer_size,
char *buffer, u_int buffer_size,
u_int8_t min_string_match_len, u_int8_t min_string_match_len,
char *outbuf, u_int outbuf_len) { char *outbuf, u_int outbuf_len) {
u_int ret = 0, i, do_cr = 0, len = 0, o_idx = 0, being_o_idx = 0; u_int ret = 0, i, do_cr = 0, len = 0, o_idx = 0, being_o_idx = 0;
@@ -752,7 +750,7 @@ int ndpi_has_human_readeable_string(struct ndpi_detection_module_struct *ndpi_st
for(i=0; i<buffer_size-2; i++) { for(i=0; i<buffer_size-2; i++) {
if(ndpi_is_valid_char(buffer[i]) if(ndpi_is_valid_char(buffer[i])
&& ndpi_is_valid_char(buffer[i+1]) && ndpi_is_valid_char(buffer[i+1])
&& ndpi_find_non_eng_bigrams(ndpi_struct, &buffer[i])) { && ndpi_find_non_eng_bigrams(&buffer[i])) {
#ifdef PRINT_STRINGS #ifdef PRINT_STRINGS
printf("%c%c", buffer[i], buffer[i+1]); printf("%c%c", buffer[i], buffer[i+1]);
#endif #endif
@@ -1130,7 +1128,7 @@ void ndpi_serialize_proto(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_serialize_risk(serializer, risk); ndpi_serialize_risk(serializer, risk);
ndpi_serialize_confidence(serializer, confidence); ndpi_serialize_confidence(serializer, confidence);
ndpi_serialize_string_string(serializer, "proto", ndpi_protocol2name(ndpi_struct, l7_protocol, buf, sizeof(buf))); ndpi_serialize_string_string(serializer, "proto", ndpi_protocol2name(ndpi_struct, l7_protocol, buf, sizeof(buf)));
ndpi_serialize_string_string(serializer, "proto_id", ndpi_protocol2id(ndpi_struct, l7_protocol, buf, sizeof(buf))); ndpi_serialize_string_string(serializer, "proto_id", ndpi_protocol2id(l7_protocol, buf, sizeof(buf)));
ndpi_serialize_string_string(serializer, "proto_by_ip", ndpi_get_proto_name(ndpi_struct, ndpi_serialize_string_string(serializer, "proto_by_ip", ndpi_get_proto_name(ndpi_struct,
l7_protocol.protocol_by_ip)); l7_protocol.protocol_by_ip));
ndpi_serialize_string_uint32(serializer, "proto_by_ip_id", l7_protocol.protocol_by_ip); ndpi_serialize_string_uint32(serializer, "proto_by_ip_id", l7_protocol.protocol_by_ip);
@@ -1138,7 +1136,7 @@ void ndpi_serialize_proto(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_protocol_breed_t breed = ndpi_protocol_breed_t breed =
ndpi_get_proto_breed(ndpi_struct, ndpi_get_proto_breed(ndpi_struct,
(l7_protocol.app_protocol != NDPI_PROTOCOL_UNKNOWN ? l7_protocol.app_protocol : l7_protocol.master_protocol)); (l7_protocol.app_protocol != NDPI_PROTOCOL_UNKNOWN ? l7_protocol.app_protocol : l7_protocol.master_protocol));
ndpi_serialize_string_string(serializer, "breed", ndpi_get_proto_breed_name(ndpi_struct, breed)); ndpi_serialize_string_string(serializer, "breed", ndpi_get_proto_breed_name(breed));
if(l7_protocol.category != NDPI_PROTOCOL_CATEGORY_UNSPECIFIED) if(l7_protocol.category != NDPI_PROTOCOL_CATEGORY_UNSPECIFIED)
{ {
ndpi_serialize_string_uint32(serializer, "category_id", l7_protocol.category); ndpi_serialize_string_uint32(serializer, "category_id", l7_protocol.category);
@@ -1883,8 +1881,7 @@ ndpi_risk_enum ndpi_validate_url(char *url) {
/* ******************************************************************** */ /* ******************************************************************** */
u_int8_t ndpi_is_protocol_detected(struct ndpi_detection_module_struct *ndpi_str, u_int8_t ndpi_is_protocol_detected(ndpi_protocol proto) {
ndpi_protocol proto) {
if((proto.master_protocol != NDPI_PROTOCOL_UNKNOWN) if((proto.master_protocol != NDPI_PROTOCOL_UNKNOWN)
|| (proto.app_protocol != NDPI_PROTOCOL_UNKNOWN) || (proto.app_protocol != NDPI_PROTOCOL_UNKNOWN)
|| (proto.category != NDPI_PROTOCOL_CATEGORY_UNSPECIFIED)) || (proto.category != NDPI_PROTOCOL_CATEGORY_UNSPECIFIED))
@@ -2500,13 +2497,12 @@ void ndpi_handle_risk_exceptions(struct ndpi_detection_module_struct *ndpi_str,
/* ******************************************************************** */ /* ******************************************************************** */
void ndpi_set_risk(struct ndpi_detection_module_struct *ndpi_str, void ndpi_set_risk(struct ndpi_flow_struct *flow, ndpi_risk_enum r,
struct ndpi_flow_struct *flow, ndpi_risk_enum r,
char *risk_message) { char *risk_message) {
if(!flow) return; if(!flow) return;
/* Check if the risk is not yet set */ /* Check if the risk is not yet set */
if(!ndpi_isset_risk(ndpi_str, flow, r)) { if(!ndpi_isset_risk(flow, r)) {
ndpi_risk v = 1ull << r; ndpi_risk v = 1ull << r;
/* In case there is an exception set, take it into account */ /* In case there is an exception set, take it into account */
@@ -2557,9 +2553,8 @@ void ndpi_set_risk(struct ndpi_detection_module_struct *ndpi_str,
/* ******************************************************************** */ /* ******************************************************************** */
void ndpi_unset_risk(struct ndpi_detection_module_struct *ndpi_str, void ndpi_unset_risk(struct ndpi_flow_struct *flow, ndpi_risk_enum r) {
struct ndpi_flow_struct *flow, ndpi_risk_enum r) { if(ndpi_isset_risk(flow, r)) {
if(ndpi_isset_risk(ndpi_str, flow, r)) {
u_int8_t i, j; u_int8_t i, j;
ndpi_risk v = 1ull << r; ndpi_risk v = 1ull << r;
@@ -2584,8 +2579,7 @@ void ndpi_unset_risk(struct ndpi_detection_module_struct *ndpi_str,
/* ******************************************************************** */ /* ******************************************************************** */
int ndpi_isset_risk(struct ndpi_detection_module_struct *ndpi_str, int ndpi_isset_risk(struct ndpi_flow_struct *flow, ndpi_risk_enum r) {
struct ndpi_flow_struct *flow, ndpi_risk_enum r) {
ndpi_risk v = 1ull << r; ndpi_risk v = 1ull << r;
return(((flow->risk & v) == v) ? 1 : 0); return(((flow->risk & v) == v) ? 1 : 0);
+4 -5
View File
@@ -509,8 +509,7 @@ static u_int8_t is_port(u_int16_t a, u_int16_t b, u_int16_t what) {
/* ************************************* */ /* ************************************* */
static void ndpi_skip_bittorrent(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_skip_bittorrent(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet) {
if(search_into_bittorrent_cache(ndpi_struct, flow)) if(search_into_bittorrent_cache(ndpi_struct, flow))
ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 0, NDPI_CONFIDENCE_DPI_CACHE); ndpi_add_connection_as_bittorrent(ndpi_struct, flow, -1, 0, NDPI_CONFIDENCE_DPI_CACHE);
else else
@@ -553,7 +552,7 @@ static void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_str
if((ntohs(packet->udp->source) < 1024) if((ntohs(packet->udp->source) < 1024)
|| (ntohs(packet->udp->dest) < 1024) /* High ports only */) { || (ntohs(packet->udp->dest) < 1024) /* High ports only */) {
ndpi_skip_bittorrent(ndpi_struct, flow, packet); ndpi_skip_bittorrent(ndpi_struct, flow);
return; return;
} }
@@ -639,12 +638,12 @@ static void ndpi_search_bittorrent(struct ndpi_detection_module_struct *ndpi_str
return; return;
} }
ndpi_skip_bittorrent(ndpi_struct, flow, packet); ndpi_skip_bittorrent(ndpi_struct, flow);
} }
} }
if(flow->packet_counter > 8) { if(flow->packet_counter > 8) {
ndpi_skip_bittorrent(ndpi_struct, flow, packet); ndpi_skip_bittorrent(ndpi_struct, flow);
} }
} }
+2 -3
View File
@@ -6,8 +6,7 @@
#include "ndpi_private.h" #include "ndpi_private.h"
static void ndpi_int_bjnp_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_bjnp_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow) {
u_int8_t due_to_correlation) {
ndpi_set_detected_protocol(ndpi_struct, flow, ndpi_set_detected_protocol(ndpi_struct, flow,
NDPI_PROTOCOL_BJNP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); NDPI_PROTOCOL_BJNP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
} }
@@ -25,7 +24,7 @@ static void ndpi_check_bjnp(struct ndpi_detection_module_struct *ndpi_struct, st
|| (memcmp((const char *)packet->payload, "MFNP", 4) == 0) || (memcmp((const char *)packet->payload, "MFNP", 4) == 0)
) { ) {
NDPI_LOG_INFO(ndpi_struct, "found bjnp\n"); NDPI_LOG_INFO(ndpi_struct, "found bjnp\n");
ndpi_int_bjnp_add_connection(ndpi_struct, flow, 0); ndpi_int_bjnp_add_connection(ndpi_struct, flow);
return; return;
} }
} }
+3 -3
View File
@@ -154,7 +154,7 @@ static void print_safe_str(char *msg,bt_parse_data_cb_t *cbd) {
#define STREQ(a,b) !strcmp(a,b) #define STREQ(a,b) !strcmp(a,b)
void cb_data(bt_parse_data_cb_t *cbd,int *ret) { void cb_data(bt_parse_data_cb_t *cbd) {
struct bt_parse_protocol *p = &(cbd->p); struct bt_parse_protocol *p = &(cbd->p);
const u_int8_t *s; const u_int8_t *s;
const char *ss; const char *ss;
@@ -432,7 +432,7 @@ const u_int8_t *bt_decode(const u_int8_t *b, size_t *l, int *ret, bt_parse_data_
do { do {
b = bt_decode(b,l,ret,cbd); b = bt_decode(b,l,ret,cbd);
if(*ret < 0 || *l == 0) goto bad_data; if(*ret < 0 || *l == 0) goto bad_data;
cb_data(cbd,ret); cb_data(cbd);
if(*ret < 0) goto bad_data; if(*ret < 0) goto bad_data;
cbd->t = 0; cbd->t = 0;
} while (*b != 'e' && *l != 0); } while (*b != 'e' && *l != 0);
@@ -455,7 +455,7 @@ const u_int8_t *bt_decode(const u_int8_t *b, size_t *l, int *ret, bt_parse_data_
} }
b = bt_decode(b,l,ret,cbd); b = bt_decode(b,l,ret,cbd);
if(*ret < 0 || *l == 0) goto bad_data; if(*ret < 0 || *l == 0) goto bad_data;
cb_data(cbd,ret); cb_data(cbd);
if(*ret < 0) goto bad_data; if(*ret < 0) goto bad_data;
cbd->t = 0; cbd->t = 0;
*ls = 0; *ls = 0;
+1 -1
View File
@@ -67,7 +67,7 @@ static void ndpi_search_can(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_int_can_add_connection(ndpi_struct, flow); ndpi_int_can_add_connection(ndpi_struct, flow);
if (can_header->version != 0x01) { if (can_header->version != 0x01) {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Invalid CAN Header"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Invalid CAN Header");
} }
} }
+6 -9
View File
@@ -103,14 +103,13 @@ static int ndpi_int_collectd_check_type(u_int16_t block_type)
static int ndpi_int_collectd_dissect_hostname(struct ndpi_flow_struct * const flow, static int ndpi_int_collectd_dissect_hostname(struct ndpi_flow_struct * const flow,
struct ndpi_packet_struct const * const packet, struct ndpi_packet_struct const * const packet,
u_int16_t block_offset, u_int16_t block_length) u_int16_t block_length)
{ {
return (ndpi_hostname_sni_set(flow, &packet->payload[4], block_length, NDPI_HOSTNAME_NORM_ALL) == NULL); return (ndpi_hostname_sni_set(flow, &packet->payload[4], block_length, NDPI_HOSTNAME_NORM_ALL) == NULL);
} }
static int ndpi_int_collectd_dissect_username(struct ndpi_flow_struct * const flow, static int ndpi_int_collectd_dissect_username(struct ndpi_flow_struct * const flow,
struct ndpi_packet_struct const * const packet, struct ndpi_packet_struct const * const packet)
u_int16_t block_offset)
{ {
u_int16_t username_length = ntohs(get_u_int16_t(packet->payload, 4)); u_int16_t username_length = ntohs(get_u_int16_t(packet->payload, 4));
@@ -134,7 +133,7 @@ static void ndpi_search_collectd(struct ndpi_detection_module_struct *ndpi_struc
struct ndpi_packet_struct const * const packet = &ndpi_struct->packet; struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
u_int16_t num_blocks; u_int16_t num_blocks;
u_int16_t block_offset = 0, block_type, block_length; u_int16_t block_offset = 0, block_type, block_length;
u_int16_t hostname_offset, hostname_length = 0; u_int16_t hostname_length = 0;
NDPI_LOG_DBG(ndpi_struct, "search collectd\n"); NDPI_LOG_DBG(ndpi_struct, "search collectd\n");
@@ -158,7 +157,6 @@ static void ndpi_search_collectd(struct ndpi_detection_module_struct *ndpi_struc
* Dissect the hostname later, when we are sure that it is * Dissect the hostname later, when we are sure that it is
* the collectd protocol. * the collectd protocol.
*/ */
hostname_offset = block_offset;
if(block_length > 4) if(block_length > 4)
hostname_length = block_length - 4; /* Ignore type and length fields */ hostname_length = block_length - 4; /* Ignore type and length fields */
} else if (block_type == COLELCTD_TYPE_ENCR_AES256) { } else if (block_type == COLELCTD_TYPE_ENCR_AES256) {
@@ -169,7 +167,7 @@ static void ndpi_search_collectd(struct ndpi_detection_module_struct *ndpi_struc
*/ */
if (block_length != packet->payload_packet_len || if (block_length != packet->payload_packet_len ||
block_length < COLLECTD_ENCR_AES256_MIN_BLOCK_SIZE || block_length < COLLECTD_ENCR_AES256_MIN_BLOCK_SIZE ||
ndpi_int_collectd_dissect_username(flow, packet, block_offset) != 0) ndpi_int_collectd_dissect_username(flow, packet) != 0)
{ {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
} else { } else {
@@ -187,10 +185,9 @@ static void ndpi_search_collectd(struct ndpi_detection_module_struct *ndpi_struc
} }
if (hostname_length > 0 && if (hostname_length > 0 &&
ndpi_int_collectd_dissect_hostname(flow, packet, hostname_offset, ndpi_int_collectd_dissect_hostname(flow, packet, hostname_length) != 0)
hostname_length) != 0)
{ {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Invalid collectd Header"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Invalid collectd Header");
} }
ndpi_int_collectd_add_connection(ndpi_struct, flow); ndpi_int_collectd_add_connection(ndpi_struct, flow);
+3 -3
View File
@@ -35,7 +35,7 @@ static void ndpi_int_dcerpc_add_connection(struct ndpi_detection_module_struct
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DCERPC, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DCERPC, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
} }
static bool is_connection_oriented_dcerpc(struct ndpi_packet_struct *packet, struct ndpi_flow_struct *flow) static bool is_connection_oriented_dcerpc(struct ndpi_packet_struct *packet)
{ {
if((packet->tcp != NULL) if((packet->tcp != NULL)
&& (packet->payload_packet_len >= 64) && (packet->payload_packet_len >= 64)
@@ -48,7 +48,7 @@ static bool is_connection_oriented_dcerpc(struct ndpi_packet_struct *packet, str
return false; return false;
} }
static bool is_connectionless_dcerpc(struct ndpi_packet_struct *packet, struct ndpi_flow_struct *flow) static bool is_connectionless_dcerpc(struct ndpi_packet_struct *packet)
{ {
u_int16_t fragment_len; u_int16_t fragment_len;
@@ -83,7 +83,7 @@ static void ndpi_search_dcerpc(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
NDPI_LOG_DBG(ndpi_struct, "search DCERPC\n"); NDPI_LOG_DBG(ndpi_struct, "search DCERPC\n");
if (is_connection_oriented_dcerpc(packet, flow) || is_connectionless_dcerpc(packet, flow)) { if (is_connection_oriented_dcerpc(packet) || is_connectionless_dcerpc(packet)) {
NDPI_LOG_INFO(ndpi_struct, "found DCERPC\n"); NDPI_LOG_INFO(ndpi_struct, "found DCERPC\n");
ndpi_int_dcerpc_add_connection(ndpi_struct, flow); ndpi_int_dcerpc_add_connection(ndpi_struct, flow);
return; return;
+14 -15
View File
@@ -44,8 +44,7 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct,
/* *********************************************** */ /* *********************************************** */
static void ndpi_check_dns_type(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_check_dns_type(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
u_int16_t dns_type) { u_int16_t dns_type) {
/* https://en.wikipedia.org/wiki/List_of_DNS_record_types */ /* https://en.wikipedia.org/wiki/List_of_DNS_record_types */
@@ -93,7 +92,7 @@ static void ndpi_check_dns_type(struct ndpi_detection_module_struct *ndpi_struct
case 106: case 106:
case 107: case 107:
case 259: case 259:
ndpi_set_risk(ndpi_struct, flow, NDPI_DNS_SUSPICIOUS_TRAFFIC, "Obsolete DNS record type"); ndpi_set_risk(flow, NDPI_DNS_SUSPICIOUS_TRAFFIC, "Obsolete DNS record type");
break; break;
} }
} }
@@ -321,7 +320,7 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
x++; x++;
} }
} else { } else {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Invalid DNS Header"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Invalid DNS Header");
return(1 /* invalid */); return(1 /* invalid */);
} }
} else { } else {
@@ -351,10 +350,10 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
snprintf(str, sizeof(str), "DNS Error Code %s", snprintf(str, sizeof(str), "DNS Error Code %s",
dns_error_code2string(flow->protos.dns.reply_code, buf, sizeof(buf))); dns_error_code2string(flow->protos.dns.reply_code, buf, sizeof(buf)));
ndpi_set_risk(ndpi_struct, flow, NDPI_ERROR_CODE_DETECTED, str); ndpi_set_risk(flow, NDPI_ERROR_CODE_DETECTED, str);
} else { } else {
if(ndpi_isset_risk(ndpi_struct, flow, NDPI_SUSPICIOUS_DGA_DOMAIN)) { if(ndpi_isset_risk(flow, NDPI_SUSPICIOUS_DGA_DOMAIN)) {
ndpi_set_risk(ndpi_struct, flow, NDPI_RISKY_DOMAIN, "DGA Name Query with no Error Code"); ndpi_set_risk(flow, NDPI_RISKY_DOMAIN, "DGA Name Query with no Error Code");
} }
} }
@@ -431,7 +430,7 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
rsp_ttl = ntohl(*((u_int32_t*)&packet->payload[x+2])); rsp_ttl = ntohl(*((u_int32_t*)&packet->payload[x+2]));
if(rsp_ttl == 0) if(rsp_ttl == 0)
ndpi_set_risk(ndpi_struct, flow, NDPI_MINOR_ISSUES, "DNS Record with zero TTL"); ndpi_set_risk(flow, NDPI_MINOR_ISSUES, "DNS Record with zero TTL");
#ifdef DNS_DEBUG #ifdef DNS_DEBUG
printf("[DNS] TTL = %u\n", rsp_ttl); printf("[DNS] TTL = %u\n", rsp_ttl);
@@ -439,7 +438,7 @@ static int search_valid_dns(struct ndpi_detection_module_struct *ndpi_struct,
#endif #endif
if(found == 0) { if(found == 0) {
ndpi_check_dns_type(ndpi_struct, flow, rsp_type); ndpi_check_dns_type(flow, rsp_type);
flow->protos.dns.rsp_type = rsp_type; flow->protos.dns.rsp_type = rsp_type;
} }
@@ -755,7 +754,7 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
#ifdef DNS_DEBUG #ifdef DNS_DEBUG
printf("[DNS] Invalid query len [%u >= %u]\n", i+4, packet->payload_packet_len); printf("[DNS] Invalid query len [%u >= %u]\n", i+4, packet->payload_packet_len);
#endif #endif
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Invalid DNS Query Lenght"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Invalid DNS Query Lenght");
break; break;
} else { } else {
idx = i+5, num_queries++; idx = i+5, num_queries++;
@@ -767,7 +766,7 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
ndpi_hostname_sni_set(flow, (const u_int8_t *)_hostname, len, is_mdns ? NDPI_HOSTNAME_NORM_LC : NDPI_HOSTNAME_NORM_ALL); ndpi_hostname_sni_set(flow, (const u_int8_t *)_hostname, len, is_mdns ? NDPI_HOSTNAME_NORM_LC : NDPI_HOSTNAME_NORM_ALL);
if (hostname_is_valid == 0) if (hostname_is_valid == 0)
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, NULL); ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, NULL);
dot = strchr(_hostname, '.'); dot = strchr(_hostname, '.');
if(dot) { if(dot) {
@@ -779,7 +778,7 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
and this might be an issue or indicate an exfiltration and this might be an issue or indicate an exfiltration
*/ */
ndpi_set_risk(ndpi_struct, flow, NDPI_DNS_SUSPICIOUS_TRAFFIC, "Long DNS host name"); ndpi_set_risk(flow, NDPI_DNS_SUSPICIOUS_TRAFFIC, "Long DNS host name");
} }
} }
@@ -867,7 +866,7 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
char str[48]; char str[48];
snprintf(str, sizeof(str), "%u Bytes DNS Packet", packet->payload_packet_len); snprintf(str, sizeof(str), "%u Bytes DNS Packet", packet->payload_packet_len);
ndpi_set_risk(ndpi_struct, flow, NDPI_DNS_LARGE_PACKET, str); ndpi_set_risk(flow, NDPI_DNS_LARGE_PACKET, str);
} }
if(packet->iph != NULL) { if(packet->iph != NULL) {
@@ -877,14 +876,14 @@ static void ndpi_search_dns(struct ndpi_detection_module_struct *ndpi_struct, st
/* 0: fragmented; 1: not fragmented */ /* 0: fragmented; 1: not fragmented */
if((flags & 0x20) if((flags & 0x20)
|| (iph_is_valid_and_not_fragmented(packet->iph, packet->l3_packet_len) == 0)) { || (iph_is_valid_and_not_fragmented(packet->iph, packet->l3_packet_len) == 0)) {
ndpi_set_risk(ndpi_struct, flow, NDPI_DNS_FRAGMENTED, NULL); ndpi_set_risk(flow, NDPI_DNS_FRAGMENTED, NULL);
} }
} else if(packet->iphv6 != NULL) { } else if(packet->iphv6 != NULL) {
/* IPv6 */ /* IPv6 */
const struct ndpi_ip6_hdrctl *ip6_hdr = &packet->iphv6->ip6_hdr; const struct ndpi_ip6_hdrctl *ip6_hdr = &packet->iphv6->ip6_hdr;
if(ip6_hdr->ip6_un1_nxt == 0x2C /* Next Header: Fragment Header for IPv6 (44) */) { if(ip6_hdr->ip6_un1_nxt == 0x2C /* Next Header: Fragment Header for IPv6 (44) */) {
ndpi_set_risk(ndpi_struct, flow, NDPI_DNS_FRAGMENTED, NULL); ndpi_set_risk(flow, NDPI_DNS_FRAGMENTED, NULL);
} }
} }
} }
+3 -4
View File
@@ -32,8 +32,7 @@
#define DB_LSP_PORT 17500 #define DB_LSP_PORT 17500
static void ndpi_int_dropbox_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_dropbox_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow) {
u_int8_t due_to_correlation) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DROPBOX, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_DROPBOX, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
} }
@@ -49,7 +48,7 @@ static void ndpi_check_dropbox(struct ndpi_detection_module_struct *ndpi_struct,
if(payload_len > 10) { if(payload_len > 10) {
if(ndpi_strnstr((const char *)packet->payload, "\"host_int\"", payload_len) != NULL) { if(ndpi_strnstr((const char *)packet->payload, "\"host_int\"", payload_len) != NULL) {
NDPI_LOG_INFO(ndpi_struct, "found dropbox\n"); NDPI_LOG_INFO(ndpi_struct, "found dropbox\n");
ndpi_int_dropbox_add_connection(ndpi_struct, flow, 0); ndpi_int_dropbox_add_connection(ndpi_struct, flow);
return; return;
} }
} }
@@ -57,7 +56,7 @@ static void ndpi_check_dropbox(struct ndpi_detection_module_struct *ndpi_struct,
if(payload_len > 10) { if(payload_len > 10) {
if(ndpi_strnstr((const char *)packet->payload, "Bus17Cmd", payload_len) != NULL) { if(ndpi_strnstr((const char *)packet->payload, "Bus17Cmd", payload_len) != NULL) {
NDPI_LOG_INFO(ndpi_struct, "found dropbox\n"); NDPI_LOG_INFO(ndpi_struct, "found dropbox\n");
ndpi_int_dropbox_add_connection(ndpi_struct, flow, 0); ndpi_int_dropbox_add_connection(ndpi_struct, flow);
return; return;
} }
} }
+3 -3
View File
@@ -204,7 +204,7 @@ static void ndpi_search_fastcgi(struct ndpi_detection_module_struct *ndpi_struct
if (fcgi_parse_params(flow, packet) != 0) if (fcgi_parse_params(flow, packet) != 0)
{ {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Invalid FastCGI PARAMS header"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Invalid FastCGI PARAMS header");
ndpi_int_fastcgi_add_connection(ndpi_struct, flow, NULL); ndpi_int_fastcgi_add_connection(ndpi_struct, flow, NULL);
} else { } else {
ndpi_match_host_subprotocol(ndpi_struct, flow, ndpi_match_host_subprotocol(ndpi_struct, flow,
@@ -218,10 +218,10 @@ static void ndpi_search_fastcgi(struct ndpi_detection_module_struct *ndpi_struct
char str[128]; char str[128];
snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name); snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name);
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, str); ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, str);
/* This looks like an attack */ /* This looks like an attack */
ndpi_set_risk(ndpi_struct, flow, NDPI_POSSIBLE_EXPLOIT, NULL); ndpi_set_risk(flow, NDPI_POSSIBLE_EXPLOIT, NULL);
} }
ndpi_int_fastcgi_add_connection(ndpi_struct, flow, &ret_match); ndpi_int_fastcgi_add_connection(ndpi_struct, flow, &ret_match);
} }
+6 -8
View File
@@ -42,8 +42,7 @@ static void ndpi_int_ftp_control_add_connection(struct ndpi_detection_module_str
/* *************************************************************** */ /* *************************************************************** */
static int ndpi_ftp_control_check_request(struct ndpi_detection_module_struct *ndpi_struct, static int ndpi_ftp_control_check_request(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
const u_int8_t *payload, const u_int8_t *payload,
size_t payload_len) { size_t payload_len) {
#ifdef FTP_DEBUG #ifdef FTP_DEBUG
@@ -59,7 +58,7 @@ static int ndpi_ftp_control_check_request(struct ndpi_detection_module_struct *n
snprintf(buf, sizeof(buf), "Found FTP username (%s)", snprintf(buf, sizeof(buf), "Found FTP username (%s)",
flow->l4.tcp.ftp_imap_pop_smtp.username); flow->l4.tcp.ftp_imap_pop_smtp.username);
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, buf); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, buf);
return 1; return 1;
} }
@@ -555,8 +554,7 @@ static int ndpi_ftp_control_check_request(struct ndpi_detection_module_struct *n
/* *************************************************************** */ /* *************************************************************** */
static int ndpi_ftp_control_check_response(struct ndpi_flow_struct *flow, static int ndpi_ftp_control_check_response(struct ndpi_flow_struct *flow,
const u_int8_t *payload, const u_int8_t *payload) {
size_t payload_len) {
#ifdef FTP_DEBUG #ifdef FTP_DEBUG
printf("%s() [%.*s]\n", __FUNCTION__, (int)payload_len, payload); printf("%s() [%.*s]\n", __FUNCTION__, (int)payload_len, payload);
#endif #endif
@@ -604,8 +602,8 @@ static void ndpi_check_ftp_control(struct ndpi_detection_module_struct *ndpi_str
if(flow->ftp_control_stage == 0) { if(flow->ftp_control_stage == 0) {
NDPI_LOG_DBG2(ndpi_struct, "FTP_CONTROL stage 0: \n"); NDPI_LOG_DBG2(ndpi_struct, "FTP_CONTROL stage 0: \n");
if((payload_len > 0) && ndpi_ftp_control_check_request(ndpi_struct, if((payload_len > 0) && ndpi_ftp_control_check_request(flow,
flow, packet->payload, payload_len)) { packet->payload, payload_len)) {
NDPI_LOG_DBG2(ndpi_struct, NDPI_LOG_DBG2(ndpi_struct,
"Possible FTP_CONTROL request detected, we will look further for the response..\n"); "Possible FTP_CONTROL request detected, we will look further for the response..\n");
@@ -627,7 +625,7 @@ static void ndpi_check_ftp_control(struct ndpi_detection_module_struct *ndpi_str
} }
/* This is a packet in another direction. Check if we find the proper response. */ /* This is a packet in another direction. Check if we find the proper response. */
if((payload_len > 0) && ndpi_ftp_control_check_response(flow, packet->payload, payload_len)) { if((payload_len > 0) && ndpi_ftp_control_check_response(flow, packet->payload)) {
NDPI_LOG_INFO(ndpi_struct, "found FTP_CONTROL\n"); NDPI_LOG_INFO(ndpi_struct, "found FTP_CONTROL\n");
#ifdef FTP_DEBUG #ifdef FTP_DEBUG
+6 -6
View File
@@ -34,7 +34,7 @@ static void ndpi_int_ftp_data_add_connection(struct ndpi_detection_module_struct
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_FTP_DATA, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_FTP_DATA, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
} }
static int ndpi_match_ftp_data_port(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static int ndpi_match_ftp_data_port(struct ndpi_detection_module_struct *ndpi_struct) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
/* Check connection over TCP */ /* Check connection over TCP */
@@ -46,7 +46,7 @@ static int ndpi_match_ftp_data_port(struct ndpi_detection_module_struct *ndpi_st
return 0; return 0;
} }
static int ndpi_match_ftp_data_directory(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static int ndpi_match_ftp_data_directory(struct ndpi_detection_module_struct *ndpi_struct) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
@@ -70,7 +70,7 @@ static int ndpi_match_ftp_data_directory(struct ndpi_detection_module_struct *nd
return 0; return 0;
} }
static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) { static int ndpi_match_file_header(struct ndpi_detection_module_struct *ndpi_struct) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int32_t payload_len = packet->payload_packet_len; u_int32_t payload_len = packet->payload_packet_len;
@@ -235,9 +235,9 @@ static void ndpi_check_ftp_data(struct ndpi_detection_module_struct *ndpi_struct
*/ */
if(ndpi_seen_flow_beginning(flow)) { if(ndpi_seen_flow_beginning(flow)) {
if((packet->payload_packet_len > 0) if((packet->payload_packet_len > 0)
&& (ndpi_match_file_header(ndpi_struct, flow) && (ndpi_match_file_header(ndpi_struct)
|| ndpi_match_ftp_data_directory(ndpi_struct, flow) || ndpi_match_ftp_data_directory(ndpi_struct)
|| ndpi_match_ftp_data_port(ndpi_struct, flow) || ndpi_match_ftp_data_port(ndpi_struct)
) )
) { ) {
NDPI_LOG_INFO(ndpi_struct, "found FTP_DATA request\n"); NDPI_LOG_INFO(ndpi_struct, "found FTP_DATA request\n");
+74 -84
View File
@@ -68,7 +68,7 @@ static void ndpi_set_binary_application_transfer(struct ndpi_detection_module_st
) )
; ;
else else
ndpi_set_risk(ndpi_struct, flow, NDPI_BINARY_APPLICATION_TRANSFER, msg); ndpi_set_risk(flow, NDPI_BINARY_APPLICATION_TRANSFER, msg);
} }
/* *********************************************** */ /* *********************************************** */
@@ -160,7 +160,7 @@ static void ndpi_http_check_human_redeable_content(struct ndpi_detection_module_
snprintf(str, sizeof(str), "Susp content %02X%02X%02X%02X", snprintf(str, sizeof(str), "Susp content %02X%02X%02X%02X",
content[0], content[1], content[2], content[3]); content[0], content[1], content[2], content[3]);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_CONTENT, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_CONTENT, str);
} }
} }
} }
@@ -198,7 +198,7 @@ static void ndpi_validate_http_content(struct ndpi_detection_module_struct *ndpi
/* Final checks */ /* Final checks */
if(ndpi_isset_risk(ndpi_struct, flow, NDPI_BINARY_APPLICATION_TRANSFER) if(ndpi_isset_risk(flow, NDPI_BINARY_APPLICATION_TRANSFER)
&& flow->http.user_agent && flow->http.content_type) { && flow->http.user_agent && flow->http.content_type) {
if(((strncmp((const char *)flow->http.user_agent, "Java/", 5) == 0)) if(((strncmp((const char *)flow->http.user_agent, "Java/", 5) == 0))
&& &&
@@ -209,7 +209,7 @@ static void ndpi_validate_http_content(struct ndpi_detection_module_struct *ndpi
https://corelight.com/blog/detecting-log4j-exploits-via-zeek-when-java-downloads-java https://corelight.com/blog/detecting-log4j-exploits-via-zeek-when-java-downloads-java
*/ */
ndpi_set_risk(ndpi_struct, flow, NDPI_POSSIBLE_EXPLOIT, "Suspicious Log4J"); ndpi_set_risk(flow, NDPI_POSSIBLE_EXPLOIT, "Suspicious Log4J");
} }
} }
@@ -217,7 +217,7 @@ static void ndpi_validate_http_content(struct ndpi_detection_module_struct *ndpi
} }
if((flow->http.user_agent == NULL) || (flow->http.user_agent[0] == '\0')) if((flow->http.user_agent == NULL) || (flow->http.user_agent[0] == '\0'))
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, "Empty or missing User-Agent"); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, "Empty or missing User-Agent");
} }
/* *********************************************** */ /* *********************************************** */
@@ -391,8 +391,7 @@ static void ndpi_int_http_add_connection(struct ndpi_detection_module_struct *nd
/* ************************************************************* */ /* ************************************************************* */
static void setHttpUserAgent(struct ndpi_detection_module_struct *ndpi_struct, static void setHttpUserAgent(struct ndpi_flow_struct *flow, char *ua) {
struct ndpi_flow_struct *flow, char *ua) {
if( !strcmp(ua, "Windows NT 5.0")) ua = "Windows 2000"; if( !strcmp(ua, "Windows NT 5.0")) ua = "Windows 2000";
else if(!strcmp(ua, "Windows NT 5.1")) ua = "Windows XP"; else if(!strcmp(ua, "Windows NT 5.1")) ua = "Windows XP";
else if(!strcmp(ua, "Windows NT 5.2")) ua = "Windows Server 2003"; else if(!strcmp(ua, "Windows NT 5.2")) ua = "Windows Server 2003";
@@ -427,7 +426,7 @@ static void ndpi_http_parse_subprotocol(struct ndpi_detection_module_struct *ndp
if(packet->server_line.len > 7 && if(packet->server_line.len > 7 &&
strncmp((const char *)packet->server_line.ptr, "ntopng ", 7) == 0) { strncmp((const char *)packet->server_line.ptr, "ntopng ", 7) == 0) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NTOP, NDPI_PROTOCOL_HTTP, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NTOP, NDPI_PROTOCOL_HTTP, NDPI_CONFIDENCE_DPI);
ndpi_unset_risk(ndpi_struct, flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT); ndpi_unset_risk(flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT);
} }
/* Matching on Content-Type. /* Matching on Content-Type.
@@ -529,7 +528,7 @@ static void ndpi_http_parse_subprotocol(struct ndpi_detection_module_struct *ndp
(strstr(flow->http.url, "delivery.mp.microsoft.com/") || (strstr(flow->http.url, "delivery.mp.microsoft.com/") ||
strstr(flow->http.url, "download.windowsupdate.com/")) && strstr(flow->http.url, "download.windowsupdate.com/")) &&
strstr(flow->http.user_agent, "Microsoft-Delivery-Optimization/") && strstr(flow->http.user_agent, "Microsoft-Delivery-Optimization/") &&
ndpi_isset_risk(ndpi_struct, flow, NDPI_NUMERIC_IP_HOST)) { ndpi_isset_risk(flow, NDPI_NUMERIC_IP_HOST)) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_WINDOWS_UPDATE, master_protocol, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_WINDOWS_UPDATE, master_protocol, NDPI_CONFIDENCE_DPI);
} }
@@ -560,8 +559,7 @@ static void ndpi_http_parse_subprotocol(struct ndpi_detection_module_struct *ndp
/* ************************************************************* */ /* ************************************************************* */
static void ndpi_check_user_agent(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_check_user_agent(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
char const *ua, size_t ua_len) { char const *ua, size_t ua_len) {
char *double_slash; char *double_slash;
@@ -595,7 +593,7 @@ static void ndpi_check_user_agent(struct ndpi_detection_module_struct *ndpi_stru
char str[64]; char str[64];
snprintf(str, sizeof(str), "UA %s", ua); snprintf(str, sizeof(str), "UA %s", ua);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, str);
} }
} }
} }
@@ -606,7 +604,7 @@ static void ndpi_check_user_agent(struct ndpi_detection_module_struct *ndpi_stru
char str[64]; char str[64];
snprintf(str, sizeof(str), "UA %s", ua); snprintf(str, sizeof(str), "UA %s", ua);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, str);
} }
if((double_slash = strstr(ua, "://")) != NULL) { if((double_slash = strstr(ua, "://")) != NULL) {
@@ -616,14 +614,14 @@ static void ndpi_check_user_agent(struct ndpi_detection_module_struct *ndpi_stru
char str[64]; char str[64];
snprintf(str, sizeof(str), "UA %s", ua); snprintf(str, sizeof(str), "UA %s", ua);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, str);
} }
} }
} }
/* no else */ /* no else */
if(!strncmp(ua, "jndi:ldap://", 12)) /* Log4J */ { if(!strncmp(ua, "jndi:ldap://", 12)) /* Log4J */ {
ndpi_set_risk(ndpi_struct, flow, NDPI_POSSIBLE_EXPLOIT, "Suspicious Log4J"); ndpi_set_risk(flow, NDPI_POSSIBLE_EXPLOIT, "Suspicious Log4J");
} else if( } else if(
(ua_len < 4) /* Too short */ (ua_len < 4) /* Too short */
|| (ua_len > 256) /* Too long */ || (ua_len > 256) /* Too long */
@@ -631,7 +629,7 @@ static void ndpi_check_user_agent(struct ndpi_detection_module_struct *ndpi_stru
|| strchr(ua, '{') || strchr(ua, '{')
|| strchr(ua, '}') || strchr(ua, '}')
) { ) {
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, "Suspicious Log4J"); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, "Suspicious Log4J");
} }
/* /*
@@ -648,7 +646,7 @@ static void ndpi_check_user_agent(struct ndpi_detection_module_struct *ndpi_stru
snprintf(str, sizeof(str), "UA %s", ua); snprintf(str, sizeof(str), "UA %s", ua);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_CRAWLER_BOT, str); ndpi_set_risk(flow, NDPI_HTTP_CRAWLER_BOT, str);
} }
} }
@@ -710,15 +708,15 @@ void http_process_user_agent(struct ndpi_detection_module_struct *ndpi_struct,
} }
if(token) if(token)
setHttpUserAgent(ndpi_struct, flow, token); setHttpUserAgent(flow, token);
} }
} }
} }
} }
if(ndpi_user_agent_set(flow, ua_ptr, ua_ptr_len) != NULL) { if(ndpi_user_agent_set(flow, ua_ptr, ua_ptr_len) != NULL) {
ndpi_unset_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT); ndpi_unset_risk(flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT);
ndpi_check_user_agent(ndpi_struct, flow, flow->http.user_agent, ua_ptr_len); ndpi_check_user_agent(flow, flow->http.user_agent, ua_ptr_len);
} else { } else {
NDPI_LOG_DBG2(ndpi_struct, "Could not set HTTP user agent (already set?)\n"); NDPI_LOG_DBG2(ndpi_struct, "Could not set HTTP user agent (already set?)\n");
} }
@@ -729,8 +727,7 @@ void http_process_user_agent(struct ndpi_detection_module_struct *ndpi_struct,
/* ************************************************************* */ /* ************************************************************* */
static void ndpi_check_numeric_ip(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_check_numeric_ip(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
char *ip, u_int ip_len) { char *ip, u_int ip_len) {
char buf[22], *double_dot; char buf[22], *double_dot;
struct in_addr ip_addr; struct in_addr ip_addr;
@@ -746,21 +743,20 @@ static void ndpi_check_numeric_ip(struct ndpi_detection_module_struct *ndpi_stru
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found host %s", buf); snprintf(str, sizeof(str), "Found host %s", buf);
ndpi_set_risk(ndpi_struct, flow, NDPI_NUMERIC_IP_HOST, str); ndpi_set_risk(flow, NDPI_NUMERIC_IP_HOST, str);
} }
} }
/* ************************************************************* */ /* ************************************************************* */
static void ndpi_check_http_url(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_check_http_url(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
char *url) { char *url) {
if(strstr(url, "<php>") != NULL /* PHP code in the URL */) if(strstr(url, "<php>") != NULL /* PHP code in the URL */)
ndpi_set_risk(ndpi_struct, flow, NDPI_URL_POSSIBLE_RCE_INJECTION, "PHP code in URL"); ndpi_set_risk(flow, NDPI_URL_POSSIBLE_RCE_INJECTION, "PHP code in URL");
else if(strncmp(url, "/shell?", 7) == 0) else if(strncmp(url, "/shell?", 7) == 0)
ndpi_set_risk(ndpi_struct, flow, NDPI_URL_POSSIBLE_RCE_INJECTION, "Possible WebShell detected"); ndpi_set_risk(flow, NDPI_URL_POSSIBLE_RCE_INJECTION, "Possible WebShell detected");
else if(strncmp(url, "/.", 2) == 0) else if(strncmp(url, "/.", 2) == 0)
ndpi_set_risk(ndpi_struct, flow, NDPI_POSSIBLE_EXPLOIT, "URL starting with dot"); ndpi_set_risk(flow, NDPI_POSSIBLE_EXPLOIT, "URL starting with dot");
} }
/* ************************************************************* */ /* ************************************************************* */
@@ -768,8 +764,7 @@ static void ndpi_check_http_url(struct ndpi_detection_module_struct *ndpi_struct
#define MIN_APACHE_VERSION 2004000 /* 2.4.X [https://endoflife.date/apache] */ #define MIN_APACHE_VERSION 2004000 /* 2.4.X [https://endoflife.date/apache] */
#define MIN_NGINX_VERSION 1022000 /* 1.22.0 [https://endoflife.date/nginx] */ #define MIN_NGINX_VERSION 1022000 /* 1.22.0 [https://endoflife.date/nginx] */
static void ndpi_check_http_server(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_check_http_server(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
const char *server, u_int server_len) { const char *server, u_int server_len) {
if(server[0] != '\0') { if(server[0] != '\0') {
if(server_len > 7) { if(server_len > 7) {
@@ -790,10 +785,10 @@ static void ndpi_check_http_server(struct ndpi_detection_module_struct *ndpi_str
if((off == 7) && (version < MIN_APACHE_VERSION)) { if((off == 7) && (version < MIN_APACHE_VERSION)) {
snprintf(msg, sizeof(msg), "Obsolete Apache server %s", buf); snprintf(msg, sizeof(msg), "Obsolete Apache server %s", buf);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_OBSOLETE_SERVER, msg); ndpi_set_risk(flow, NDPI_HTTP_OBSOLETE_SERVER, msg);
} else if((off == 6) && (version < MIN_NGINX_VERSION)) { } else if((off == 6) && (version < MIN_NGINX_VERSION)) {
snprintf(msg, sizeof(msg), "Obsolete nginx server %s", buf); snprintf(msg, sizeof(msg), "Obsolete nginx server %s", buf);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_OBSOLETE_SERVER, msg); ndpi_set_risk(flow, NDPI_HTTP_OBSOLETE_SERVER, msg);
} }
} }
} }
@@ -801,7 +796,7 @@ static void ndpi_check_http_server(struct ndpi_detection_module_struct *ndpi_str
/* Check server content */ /* Check server content */
for(i=0; i<server_len; i++) { for(i=0; i<server_len; i++) {
if(!ndpi_isprint(server[i])) { if(!ndpi_isprint(server[i])) {
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, "Suspicious Agent"); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, "Suspicious Agent");
break; break;
} }
} }
@@ -828,7 +823,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
if(ndpi_isdigit(packet->host_line.ptr[0]) if(ndpi_isdigit(packet->host_line.ptr[0])
&& (packet->host_line.len < 21)) && (packet->host_line.len < 21))
ndpi_check_numeric_ip(ndpi_struct, flow, (char*)packet->host_line.ptr, packet->host_line.len); ndpi_check_numeric_ip(flow, (char*)packet->host_line.ptr, packet->host_line.len);
flow->http.url = ndpi_malloc(len); flow->http.url = ndpi_malloc(len);
if(flow->http.url) { if(flow->http.url) {
@@ -859,7 +854,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
flow->http.url[offset] = '\0'; flow->http.url[offset] = '\0';
} }
ndpi_check_http_url(ndpi_struct, flow, &flow->http.url[host_end]); ndpi_check_http_url(flow, &flow->http.url[host_end]);
} }
} }
@@ -868,7 +863,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
(u_int16_t)packet->http_method.len); (u_int16_t)packet->http_method.len);
if(packet->server_line.ptr != NULL) if(packet->server_line.ptr != NULL)
ndpi_check_http_server(ndpi_struct, flow, (const char *)packet->server_line.ptr, packet->server_line.len); ndpi_check_http_server(flow, (const char *)packet->server_line.ptr, packet->server_line.len);
if(packet->user_agent_line.ptr != NULL) { if(packet->user_agent_line.ptr != NULL) {
http_process_user_agent(ndpi_struct, flow, packet->user_agent_line.ptr, packet->user_agent_line.len); http_process_user_agent(ndpi_struct, flow, packet->user_agent_line.ptr, packet->user_agent_line.len);
@@ -905,7 +900,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
"Basic", packet->authorization_line.len) "Basic", packet->authorization_line.len)
|| ndpi_strncasestr((const char*)packet->authorization_line.ptr, || ndpi_strncasestr((const char*)packet->authorization_line.ptr,
"Digest", packet->authorization_line.len)) { "Digest", packet->authorization_line.len)) {
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS,
"Found credentials in HTTP Auth Line"); "Found credentials in HTTP Auth Line");
} }
} }
@@ -963,10 +958,10 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
char str[128]; char str[128];
snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name); snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name);
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, str); ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, str);
/* This looks like an attack */ /* This looks like an attack */
ndpi_set_risk(ndpi_struct, flow, NDPI_POSSIBLE_EXPLOIT, NULL); ndpi_set_risk(flow, NDPI_POSSIBLE_EXPLOIT, NULL);
} }
double_col = strchr((char*)flow->host_server_name, ':'); double_col = strchr((char*)flow->host_server_name, ':');
@@ -980,7 +975,7 @@ static void check_content_type_and_change_protocol(struct ndpi_detection_module_
snprintf(msg, sizeof(msg), "Expected %s, found %s", snprintf(msg, sizeof(msg), "Expected %s, found %s",
ndpi_intoav4(ntohl(ndpi_struct->packet.iph->daddr), buf, sizeof(buf)), flow->host_server_name); ndpi_intoav4(ntohl(ndpi_struct->packet.iph->daddr), buf, sizeof(buf)), flow->host_server_name);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, msg); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, msg);
} }
} }
} }
@@ -1038,7 +1033,7 @@ static struct l_string {
}; };
static const char *http_fs = "CDGHOPR"; static const char *http_fs = "CDGHOPR";
static u_int16_t http_request_url_offset(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static u_int16_t http_request_url_offset(struct ndpi_detection_module_struct *ndpi_struct)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
unsigned int i; unsigned int i;
@@ -1117,7 +1112,7 @@ static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_str
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr); snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, str);
return; return;
} }
break; break;
@@ -1126,7 +1121,7 @@ static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_str
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr); snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, str);
return; return;
} }
break; break;
@@ -1135,7 +1130,7 @@ static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_str
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr); snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, str);
return; return;
} }
break; break;
@@ -1144,7 +1139,7 @@ static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_str
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr); snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, str);
return; return;
} }
break; break;
@@ -1153,7 +1148,7 @@ static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_str
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr); snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, str);
return; return;
} }
break; break;
@@ -1162,7 +1157,7 @@ static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_str
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr); snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, str);
return; return;
} }
break; break;
@@ -1171,7 +1166,7 @@ static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_str
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr); snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, str);
return; return;
} }
break; break;
@@ -1180,7 +1175,7 @@ static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_str
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr); snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, str);
return; return;
} }
break; break;
@@ -1189,7 +1184,7 @@ static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_str
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr); snprintf(str, sizeof(str), "Found %.*s", packet->line[i].len, packet->line[i].ptr);
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER, str); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER, str);
return; return;
} }
@@ -1219,7 +1214,7 @@ static void parse_response_code(struct ndpi_detection_module_struct *ndpi_struct
if(flow->http.response_status_code >= 400) { if(flow->http.response_status_code >= 400) {
snprintf(ec, sizeof(ec), "HTTP Error Code %u", flow->http.response_status_code); snprintf(ec, sizeof(ec), "HTTP Error Code %u", flow->http.response_status_code);
ndpi_set_risk(ndpi_struct, flow, NDPI_ERROR_CODE_DETECTED, ec); ndpi_set_risk(flow, NDPI_ERROR_CODE_DETECTED, ec);
if(flow->http.url != NULL) { if(flow->http.url != NULL) {
/* Let's check for Wordpress */ /* Let's check for Wordpress */
@@ -1230,19 +1225,18 @@ static void parse_response_code(struct ndpi_detection_module_struct *ndpi_struct
|| ((flow->http.method == NDPI_HTTP_METHOD_GET) && (strncmp(slash, "/wp-content/uploads/", 20) == 0)) || ((flow->http.method == NDPI_HTTP_METHOD_GET) && (strncmp(slash, "/wp-content/uploads/", 20) == 0))
)) { )) {
/* Example of popular exploits https://www.wordfence.com/blog/2022/05/millions-of-attacks-target-tatsu-builder-plugin/ */ /* Example of popular exploits https://www.wordfence.com/blog/2022/05/millions-of-attacks-target-tatsu-builder-plugin/ */
ndpi_set_risk(ndpi_struct, flow, NDPI_POSSIBLE_EXPLOIT, "Possible Wordpress Exploit"); ndpi_set_risk(flow, NDPI_POSSIBLE_EXPLOIT, "Possible Wordpress Exploit");
} }
} }
} }
} }
} }
static int is_request(struct ndpi_detection_module_struct *ndpi_struct, static int is_request(struct ndpi_detection_module_struct *ndpi_struct) {
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int16_t filename_start; u_int16_t filename_start;
filename_start = http_request_url_offset(ndpi_struct, flow); filename_start = http_request_url_offset(ndpi_struct);
/* This check is required as RTSP is pretty similiar to HTTP */ /* This check is required as RTSP is pretty similiar to HTTP */
if(filename_start > 0 && if(filename_start > 0 &&
strncasecmp((const char *)packet->payload + filename_start, strncasecmp((const char *)packet->payload + filename_start,
@@ -1251,8 +1245,7 @@ static int is_request(struct ndpi_detection_module_struct *ndpi_struct,
return filename_start; return filename_start;
} }
static int is_response(struct ndpi_detection_module_struct *ndpi_struct, static int is_response(struct ndpi_detection_module_struct *ndpi_struct) {
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
if(packet->payload_packet_len >= 7 && if(packet->payload_packet_len >= 7 &&
strncasecmp((const char *)packet->payload, "HTTP/1.", 7) == 0) strncasecmp((const char *)packet->payload, "HTTP/1.", 7) == 0)
@@ -1309,7 +1302,7 @@ static void process_request(struct ndpi_detection_module_struct *ndpi_struct,
if(flow->http.user_agent == NULL || if(flow->http.user_agent == NULL ||
flow->http.user_agent[0] == '\0') { flow->http.user_agent[0] == '\0') {
ndpi_set_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, "Empty or missing User-Agent"); ndpi_set_risk(flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT, "Empty or missing User-Agent");
} }
} }
@@ -1324,7 +1317,7 @@ static void process_response(struct ndpi_detection_module_struct *ndpi_struct,
} }
static void reset(struct ndpi_detection_module_struct *ndpi_struct, static void reset(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
NDPI_LOG_DBG2(ndpi_struct, "Reset status and risks\n"); NDPI_LOG_DBG2(ndpi_struct, "Reset status and risks\n");
@@ -1371,19 +1364,19 @@ static void reset(struct ndpi_detection_module_struct *ndpi_struct,
/* Reset flow risks. We should reset only those risks triggered by /* Reset flow risks. We should reset only those risks triggered by
the previous HTTP response... */ the previous HTTP response... */
/* TODO */ /* TODO */
ndpi_unset_risk(ndpi_struct, flow, NDPI_BINARY_APPLICATION_TRANSFER); ndpi_unset_risk(flow, NDPI_BINARY_APPLICATION_TRANSFER);
ndpi_unset_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_CONTENT); ndpi_unset_risk(flow, NDPI_HTTP_SUSPICIOUS_CONTENT);
ndpi_unset_risk(ndpi_struct, flow, NDPI_POSSIBLE_EXPLOIT); ndpi_unset_risk(flow, NDPI_POSSIBLE_EXPLOIT);
ndpi_unset_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT); ndpi_unset_risk(flow, NDPI_HTTP_SUSPICIOUS_USER_AGENT);
ndpi_unset_risk(ndpi_struct, flow, NDPI_HTTP_CRAWLER_BOT); ndpi_unset_risk(flow, NDPI_HTTP_CRAWLER_BOT);
ndpi_unset_risk(ndpi_struct, flow, NDPI_NUMERIC_IP_HOST); ndpi_unset_risk(flow, NDPI_NUMERIC_IP_HOST);
ndpi_unset_risk(ndpi_struct, flow, NDPI_URL_POSSIBLE_RCE_INJECTION); ndpi_unset_risk(flow, NDPI_URL_POSSIBLE_RCE_INJECTION);
ndpi_unset_risk(ndpi_struct, flow, NDPI_HTTP_OBSOLETE_SERVER); ndpi_unset_risk(flow, NDPI_HTTP_OBSOLETE_SERVER);
ndpi_unset_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS); ndpi_unset_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS);
ndpi_unset_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS); ndpi_unset_risk(flow, NDPI_INVALID_CHARACTERS);
ndpi_unset_risk(ndpi_struct, flow, NDPI_HTTP_SUSPICIOUS_HEADER); ndpi_unset_risk(flow, NDPI_HTTP_SUSPICIOUS_HEADER);
ndpi_unset_risk(ndpi_struct, flow, NDPI_ERROR_CODE_DETECTED); ndpi_unset_risk(flow, NDPI_ERROR_CODE_DETECTED);
ndpi_unset_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET); ndpi_unset_risk(flow, NDPI_MALFORMED_PACKET);
} }
static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct,
@@ -1393,13 +1386,13 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
NDPI_LOG_DBG(ndpi_struct, "http_stage %d dir %d req/res %d/%d\n", NDPI_LOG_DBG(ndpi_struct, "http_stage %d dir %d req/res %d/%d\n",
flow->l4.tcp.http_stage, packet->packet_direction, flow->l4.tcp.http_stage, packet->packet_direction,
is_request(ndpi_struct, flow), is_response(ndpi_struct, flow)); is_request(ndpi_struct), is_response(ndpi_struct));
if(flow->l4.tcp.http_stage == 0) { /* Start: waiting for (the beginning of) a request */ if(flow->l4.tcp.http_stage == 0) { /* Start: waiting for (the beginning of) a request */
filename_start = is_request(ndpi_struct, flow); filename_start = is_request(ndpi_struct);
if(filename_start == 0) { if(filename_start == 0) {
/* Flow starting with a response? */ /* Flow starting with a response? */
if(is_response(ndpi_struct, flow)) { if(is_response(ndpi_struct)) {
NDPI_LOG_DBG2(ndpi_struct, "Response where a request were expected\n"); NDPI_LOG_DBG2(ndpi_struct, "Response where a request were expected\n");
/* This is tricky. Two opposing goals: /* This is tricky. Two opposing goals:
1) We want to correctly match request with response!! -> Skip this response 1) We want to correctly match request with response!! -> Skip this response
@@ -1436,7 +1429,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
/* Another pkt from the same direction (probably another fragment of the request) /* Another pkt from the same direction (probably another fragment of the request)
Keep lookng for the response */ Keep lookng for the response */
NDPI_LOG_DBG2(ndpi_struct, "Another piece of request\n"); NDPI_LOG_DBG2(ndpi_struct, "Another piece of request\n");
filename_start = is_request(ndpi_struct, flow); filename_start = is_request(ndpi_struct);
if(filename_start > 0) { if(filename_start > 0) {
/* Probably a new, separated request (asymmetric flow or missing pkts?). /* Probably a new, separated request (asymmetric flow or missing pkts?).
What should we do? We definitely don't want to mix data from different What should we do? We definitely don't want to mix data from different
@@ -1452,7 +1445,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
check_content_type_and_change_protocol(ndpi_struct, flow); check_content_type_and_change_protocol(ndpi_struct, flow);
return; return;
} else if(is_response(ndpi_struct, flow)) { } else if(is_response(ndpi_struct)) {
NDPI_LOG_DBG2(ndpi_struct, "Response where expected\n"); NDPI_LOG_DBG2(ndpi_struct, "Response where expected\n");
process_response(ndpi_struct, flow); process_response(ndpi_struct, flow);
@@ -1469,7 +1462,7 @@ static void ndpi_check_http_tcp(struct ndpi_detection_module_struct *ndpi_struct
/* Another pkt from the same direction (probably another fragment of the response) /* Another pkt from the same direction (probably another fragment of the response)
Keep lookng for the request */ Keep lookng for the request */
NDPI_LOG_DBG2(ndpi_struct, "Another piece of response\n"); NDPI_LOG_DBG2(ndpi_struct, "Another piece of response\n");
if(is_response(ndpi_struct, flow)) { if(is_response(ndpi_struct)) {
/* See the comment above about how we handle consecutive requests/responses */ /* See the comment above about how we handle consecutive requests/responses */
if(flow->l4.tcp.http_asymmetric_stage < 2) if(flow->l4.tcp.http_asymmetric_stage < 2)
flow->l4.tcp.http_asymmetric_stage++; flow->l4.tcp.http_asymmetric_stage++;
@@ -1525,8 +1518,7 @@ static void ndpi_search_http_tcp(struct ndpi_detection_module_struct *ndpi_struc
/* ********************************* */ /* ********************************* */
ndpi_http_method ndpi_get_http_method(struct ndpi_detection_module_struct *ndpi_struct, ndpi_http_method ndpi_get_http_method(struct ndpi_flow_struct *flow) {
struct ndpi_flow_struct *flow) {
if(!flow) { if(!flow) {
return(NDPI_HTTP_METHOD_UNKNOWN); return(NDPI_HTTP_METHOD_UNKNOWN);
} else } else
@@ -1535,8 +1527,7 @@ ndpi_http_method ndpi_get_http_method(struct ndpi_detection_module_struct *ndpi_
/* ********************************* */ /* ********************************* */
char* ndpi_get_http_url(struct ndpi_detection_module_struct *ndpi_struct, char* ndpi_get_http_url(struct ndpi_flow_struct *flow) {
struct ndpi_flow_struct *flow) {
if((!flow) || (!flow->http.url)) if((!flow) || (!flow->http.url))
return(""); return("");
else else
@@ -1545,8 +1536,7 @@ char* ndpi_get_http_url(struct ndpi_detection_module_struct *ndpi_struct,
/* ********************************* */ /* ********************************* */
char* ndpi_get_http_content_type(struct ndpi_detection_module_struct *ndpi_struct, char* ndpi_get_http_content_type(struct ndpi_flow_struct *flow) {
struct ndpi_flow_struct *flow) {
if((!flow) || (!flow->http.content_type)) if((!flow) || (!flow->http.content_type))
return(""); return("");
else else
+1 -1
View File
@@ -44,7 +44,7 @@ static void ndpi_search_icecast_tcp(struct ndpi_detection_module_struct *ndpi_st
if((packet->payload_packet_len < 500 && if((packet->payload_packet_len < 500 &&
packet->payload_packet_len >= 7 && memcmp(packet->payload, "SOURCE ", 7) == 0) packet->payload_packet_len >= 7 && memcmp(packet->payload, "SOURCE ", 7) == 0)
|| flow->l4.tcp.icecast_stage) { || flow->l4.tcp.icecast_stage) {
ndpi_parse_packet_line_info_any(ndpi_struct, flow); ndpi_parse_packet_line_info_any(ndpi_struct);
NDPI_LOG_DBG2(ndpi_struct, "Icecast lines=%d\n", packet->parsed_lines); NDPI_LOG_DBG2(ndpi_struct, "Icecast lines=%d\n", packet->parsed_lines);
for (i = 0; i < packet->parsed_lines; i++) { for (i = 0; i < packet->parsed_lines; i++) {
if(packet->line[i].ptr != NULL && packet->line[i].len > 4 if(packet->line[i].ptr != NULL && packet->line[i].len > 4
+1 -1
View File
@@ -43,7 +43,7 @@ static void ndpi_int_ipsec_add_connection(struct ndpi_detection_module_struct *
return; return;
case ISAKMP_MALFORMED: case ISAKMP_MALFORMED:
NDPI_LOG_INFO(ndpi_struct, "found malformed ISAKMP (UDP)\n"); NDPI_LOG_INFO(ndpi_struct, "found malformed ISAKMP (UDP)\n");
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Invalid IPSec/ISAKMP Header"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Invalid IPSec/ISAKMP Header");
break; break;
case ISAKMP_V1: case ISAKMP_V1:
NDPI_LOG_INFO(ndpi_struct, "found ISAKMPv1 (UDP)\n"); NDPI_LOG_INFO(ndpi_struct, "found ISAKMPv1 (UDP)\n");
+10 -10
View File
@@ -35,7 +35,7 @@ static void ndpi_int_irc_add_connection(struct ndpi_detection_module_struct *ndp
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_IRC, NDPI_PROTOCOL_UNKNOWN, confidence); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_IRC, NDPI_PROTOCOL_UNKNOWN, confidence);
} }
static u_int8_t ndpi_check_for_NOTICE_or_PRIVMSG(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static u_int8_t ndpi_check_for_NOTICE_or_PRIVMSG(struct ndpi_detection_module_struct *ndpi_struct)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
@@ -60,7 +60,7 @@ static u_int8_t ndpi_check_for_NOTICE_or_PRIVMSG(struct ndpi_detection_module_st
} }
static u_int8_t ndpi_check_for_Nickname(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static u_int8_t ndpi_check_for_Nickname(struct ndpi_detection_module_struct *ndpi_struct)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int16_t i, packetl = packet->payload_packet_len; u_int16_t i, packetl = packet->payload_packet_len;
@@ -82,7 +82,7 @@ static u_int8_t ndpi_check_for_Nickname(struct ndpi_detection_module_struct *ndp
return 0; return 0;
} }
static u_int8_t ndpi_check_for_cmd(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) static u_int8_t ndpi_check_for_cmd(struct ndpi_detection_module_struct *ndpi_struct)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int16_t i; u_int16_t i;
@@ -369,7 +369,7 @@ static void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct
if (memcmp(packet->payload, ":", 1) == 0) { if (memcmp(packet->payload, ":", 1) == 0) {
if (packet->payload[packet->payload_packet_len - 2] != 0x0d if (packet->payload[packet->payload_packet_len - 2] != 0x0d
&& packet->payload[packet->payload_packet_len - 1] == 0x0a) { && packet->payload[packet->payload_packet_len - 1] == 0x0a) {
ndpi_parse_packet_line_info_any(ndpi_struct, flow); ndpi_parse_packet_line_info_any(ndpi_struct);
} else if (packet->payload[packet->payload_packet_len - 2] == 0x0d) { } else if (packet->payload[packet->payload_packet_len - 2] == 0x0d) {
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
} else { } else {
@@ -396,7 +396,7 @@ static void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct
if ((memcmp(packet->payload, "USER ", 5) == 0) if ((memcmp(packet->payload, "USER ", 5) == 0)
|| (memcmp(packet->payload, "NICK ", 5) == 0) || (memcmp(packet->payload, "NICK ", 5) == 0)
|| (memcmp(packet->payload, "PASS ", 5) == 0) || (memcmp(packet->payload, "PASS ", 5) == 0)
|| (memcmp(packet->payload, ":", 1) == 0 && ndpi_check_for_NOTICE_or_PRIVMSG(ndpi_struct, flow) != 0) || (memcmp(packet->payload, ":", 1) == 0 && ndpi_check_for_NOTICE_or_PRIVMSG(ndpi_struct) != 0)
|| (memcmp(packet->payload, "PONG ", 5) == 0) || (memcmp(packet->payload, "PONG ", 5) == 0)
|| (memcmp(packet->payload, "PING ", 5) == 0) || (memcmp(packet->payload, "PING ", 5) == 0)
|| (memcmp(packet->payload, "JOIN ", 5) == 0) || (memcmp(packet->payload, "JOIN ", 5) == 0)
@@ -414,7 +414,7 @@ static void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct
sp[0] = '\0'; sp[0] = '\0';
snprintf(msg, sizeof(msg), "Found IRC username (%s)", buf); snprintf(msg, sizeof(msg), "Found IRC username (%s)", buf);
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, msg); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, msg);
} }
NDPI_LOG_DBG2(ndpi_struct, NDPI_LOG_DBG2(ndpi_struct,
@@ -450,7 +450,7 @@ static void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct
} }
} else if (packet->payload[packet->payload_packet_len - 1] == 0x0a) { } else if (packet->payload[packet->payload_packet_len - 1] == 0x0a) {
ndpi_parse_packet_line_info_any(ndpi_struct, flow); ndpi_parse_packet_line_info_any(ndpi_struct);
if (packet->parsed_lines > 1) { if (packet->parsed_lines > 1) {
NDPI_LOG_DBG2(ndpi_struct, "packet contains more than one line"); NDPI_LOG_DBG2(ndpi_struct, "packet contains more than one line");
for (c = 1; c < packet->parsed_lines; c++) { for (c = 1; c < packet->parsed_lines; c++) {
@@ -504,10 +504,10 @@ static void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct
if ((flow->detected_protocol_stack[0] != NDPI_PROTOCOL_IRC) && (flow->l4.tcp.irc_stage == 1)) { if ((flow->detected_protocol_stack[0] != NDPI_PROTOCOL_IRC) && (flow->l4.tcp.irc_stage == 1)) {
if ((((packet->payload_packet_len - http_content_ptr_len) > 10) if ((((packet->payload_packet_len - http_content_ptr_len) > 10)
&& (memcmp(packet->payload + http_content_ptr_len, "interface=", 10) == 0) && (memcmp(packet->payload + http_content_ptr_len, "interface=", 10) == 0)
&& (ndpi_check_for_Nickname(ndpi_struct, flow) != 0)) && (ndpi_check_for_Nickname(ndpi_struct) != 0))
|| (((packet->payload_packet_len - http_content_ptr_len) > 5) || (((packet->payload_packet_len - http_content_ptr_len) > 5)
&& (memcmp(packet->payload + http_content_ptr_len, "item=", 5) == 0) && (memcmp(packet->payload + http_content_ptr_len, "item=", 5) == 0)
&& (ndpi_check_for_cmd(ndpi_struct, flow) != 0))) { && (ndpi_check_for_cmd(ndpi_struct) != 0))) {
NDPI_LOG_INFO(ndpi_struct, "found IRC: Nickname, cmd, one time"); NDPI_LOG_INFO(ndpi_struct, "found IRC: Nickname, cmd, one time");
ndpi_int_irc_add_connection(ndpi_struct, flow, NDPI_CONFIDENCE_DPI); ndpi_int_irc_add_connection(ndpi_struct, flow, NDPI_CONFIDENCE_DPI);
return; return;
@@ -523,7 +523,7 @@ static void ndpi_search_irc_tcp(struct ndpi_detection_module_struct *ndpi_struct
if (packet->payload[packet->payload_packet_len - 2] != 0x0d if (packet->payload[packet->payload_packet_len - 2] != 0x0d
&& packet->payload[packet->payload_packet_len - 1] == 0x0a) { && packet->payload[packet->payload_packet_len - 1] == 0x0a) {
NDPI_LOG_DBG2(ndpi_struct, "ndpi_parse_packet_line_info_any(ndpi_struct, flow);"); NDPI_LOG_DBG2(ndpi_struct, "ndpi_parse_packet_line_info_any(ndpi_struct, flow);");
ndpi_parse_packet_line_info_any(ndpi_struct, flow); ndpi_parse_packet_line_info_any(ndpi_struct);
} else if (packet->payload[packet->payload_packet_len - 2] == 0x0d) { } else if (packet->payload[packet->payload_packet_len - 2] == 0x0d) {
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
} else { } else {
+3 -4
View File
@@ -29,8 +29,7 @@
#define LISP_PORT1 4342 /* TCP and UDP */ #define LISP_PORT1 4342 /* TCP and UDP */
static void ndpi_int_lisp_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_lisp_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow)
u_int8_t due_to_correlation)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_LISP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_LISP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
@@ -47,7 +46,7 @@ static void ndpi_check_lisp(struct ndpi_detection_module_struct *ndpi_struct, st
if((packet->udp->source == lisp_port && packet->udp->dest == lisp_port) || if((packet->udp->source == lisp_port && packet->udp->dest == lisp_port) ||
(packet->udp->source == lisp_port1 && packet->udp->dest == lisp_port1)) { (packet->udp->source == lisp_port1 && packet->udp->dest == lisp_port1)) {
NDPI_LOG_INFO(ndpi_struct, "found lisp\n"); NDPI_LOG_INFO(ndpi_struct, "found lisp\n");
ndpi_int_lisp_add_connection(ndpi_struct, flow, 0); ndpi_int_lisp_add_connection(ndpi_struct, flow);
return; return;
} }
} else { } else {
@@ -63,7 +62,7 @@ static void ndpi_check_lisp(struct ndpi_detection_module_struct *ndpi_struct, st
packet->payload[packet->payload_packet_len - 3] == 0xAC && packet->payload[packet->payload_packet_len - 3] == 0xAC &&
packet->payload[packet->payload_packet_len - 4] == 0x9F) { packet->payload[packet->payload_packet_len - 4] == 0x9F) {
NDPI_LOG_INFO(ndpi_struct, "found lisp\n"); NDPI_LOG_INFO(ndpi_struct, "found lisp\n");
ndpi_int_lisp_add_connection(ndpi_struct, flow, 0); ndpi_int_lisp_add_connection(ndpi_struct, flow);
return; return;
} }
} }
+1 -1
View File
@@ -186,7 +186,7 @@ static void ndpi_search_mail_imap_tcp(struct ndpi_detection_module_struct *ndpi_
snprintf(buf, sizeof(buf), "Found IMAP username (%s)", snprintf(buf, sizeof(buf), "Found IMAP username (%s)",
flow->l4.tcp.ftp_imap_pop_smtp.username); flow->l4.tcp.ftp_imap_pop_smtp.username);
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, buf); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, buf);
pwd = strtok_r(NULL, " \"\r\n", &saveptr); pwd = strtok_r(NULL, " \"\r\n", &saveptr);
if(pwd) { if(pwd) {
+2 -2
View File
@@ -88,7 +88,7 @@ static int ndpi_int_mail_pop_check_for_client_commands(struct ndpi_detection_mod
snprintf(buf, sizeof(buf), "Found username (%s)", snprintf(buf, sizeof(buf), "Found username (%s)",
flow->l4.tcp.ftp_imap_pop_smtp.username); flow->l4.tcp.ftp_imap_pop_smtp.username);
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, buf); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, buf);
flow->l4.tcp.pop_command_bitmask |= POP_BIT_USER; flow->l4.tcp.pop_command_bitmask |= POP_BIT_USER;
return 1; return 1;
@@ -100,7 +100,7 @@ static int ndpi_int_mail_pop_check_for_client_commands(struct ndpi_detection_mod
sizeof(flow->l4.tcp.ftp_imap_pop_smtp.password), 5, sizeof(flow->l4.tcp.ftp_imap_pop_smtp.password), 5,
packet->payload, packet->payload_packet_len); packet->payload, packet->payload_packet_len);
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, "Found password"); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, "Found password");
flow->l4.tcp.pop_command_bitmask |= POP_BIT_PASS; flow->l4.tcp.pop_command_bitmask |= POP_BIT_PASS;
return 1; return 1;
} else if((packet->payload[0] == 'C' || packet->payload[0] == 'c') } else if((packet->payload[0] == 'C' || packet->payload[0] == 'c')
+5 -6
View File
@@ -66,8 +66,7 @@ static void smtpInitExtraPacketProcessing(struct ndpi_flow_struct *flow);
/* **************************************** */ /* **************************************** */
static void get_credentials_auth_plain(struct ndpi_detection_module_struct *ndpi_struct, static void get_credentials_auth_plain(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
const u_int8_t *line, u_int16_t line_len) const u_int8_t *line, u_int16_t line_len)
{ {
u_int8_t buf[255]; u_int8_t buf[255];
@@ -102,7 +101,7 @@ static void get_credentials_auth_plain(struct ndpi_detection_module_struct *ndpi
snprintf(buf, sizeof(buf), "Found username (%s)", snprintf(buf, sizeof(buf), "Found username (%s)",
flow->l4.tcp.ftp_imap_pop_smtp.username); flow->l4.tcp.ftp_imap_pop_smtp.username);
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, buf); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, buf);
if(1 + user_len + 1 < out_len) { if(1 + user_len + 1 < out_len) {
unsigned int pwd_len; unsigned int pwd_len;
@@ -222,7 +221,7 @@ static void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct *ndpi_
} else if(packet->line[a].ptr[5] == 'P' || packet->line[a].ptr[5] == 'p') { } else if(packet->line[a].ptr[5] == 'P' || packet->line[a].ptr[5] == 'p') {
flow->l4.tcp.smtp_command_bitmask |= SMTP_BIT_AUTH_PLAIN; flow->l4.tcp.smtp_command_bitmask |= SMTP_BIT_AUTH_PLAIN;
/* AUTH PLAIN: username and pwd here */ /* AUTH PLAIN: username and pwd here */
get_credentials_auth_plain(ndpi_struct, flow, get_credentials_auth_plain(flow,
packet->line[a].ptr, packet->line[a].len); packet->line[a].ptr, packet->line[a].len);
flow->l4.tcp.ftp_imap_pop_smtp.auth_done = 1; flow->l4.tcp.ftp_imap_pop_smtp.auth_done = 1;
} }
@@ -262,7 +261,7 @@ static void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct *ndpi_
snprintf(msg, sizeof(msg), "Found SMTP username (%s)", snprintf(msg, sizeof(msg), "Found SMTP username (%s)",
flow->l4.tcp.ftp_imap_pop_smtp.username); flow->l4.tcp.ftp_imap_pop_smtp.username);
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, msg); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, msg);
} else if(flow->l4.tcp.ftp_imap_pop_smtp.password[0] == '\0') { } else if(flow->l4.tcp.ftp_imap_pop_smtp.password[0] == '\0') {
/* Password */ /* Password */
u_int8_t buf[48]; u_int8_t buf[48];
@@ -287,7 +286,7 @@ static void ndpi_search_mail_smtp_tcp(struct ndpi_detection_module_struct *ndpi_
ndpi_free(out); ndpi_free(out);
} }
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, "Found password"); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, "Found password");
flow->l4.tcp.ftp_imap_pop_smtp.auth_done = 1; flow->l4.tcp.ftp_imap_pop_smtp.auth_done = 1;
} else { } else {
+2 -2
View File
@@ -64,7 +64,7 @@ static void ndpi_search_munin(struct ndpi_detection_module_struct *ndpi_struct,
if (packet->payload[packet->payload_packet_len - 1] != '\n') if (packet->payload[packet->payload_packet_len - 1] != '\n')
{ {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Missing Munin Hostname"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Missing Munin Hostname");
return; return;
} }
@@ -73,7 +73,7 @@ static void ndpi_search_munin(struct ndpi_detection_module_struct *ndpi_struct,
{ {
ndpi_hostname_sni_set(flow, packet->payload + NDPI_STATICSTRING_LEN(munin_prefix), host_len, NDPI_HOSTNAME_NORM_ALL); ndpi_hostname_sni_set(flow, packet->payload + NDPI_STATICSTRING_LEN(munin_prefix), host_len, NDPI_HOSTNAME_NORM_ALL);
} else { } else {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Missing Munin Hostname"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Missing Munin Hostname");
} }
} }
+4 -4
View File
@@ -122,7 +122,7 @@ static int ndpi_search_natpmp_extra(struct ndpi_detection_module_struct *ndpi_st
if (natpmp_is_valid(packet, &natpmp_type) == 0) if (natpmp_is_valid(packet, &natpmp_type) == 0)
{ {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Invalid NATPMP Header"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Invalid NATPMP Header");
return 0; return 0;
} }
@@ -136,7 +136,7 @@ static int ndpi_search_natpmp_extra(struct ndpi_detection_module_struct *ndpi_st
flow->protos.natpmp.external_port = ntohs(get_u_int16_t(packet->payload, 6)); flow->protos.natpmp.external_port = ntohs(get_u_int16_t(packet->payload, 6));
if (flow->protos.natpmp.internal_port == 0) if (flow->protos.natpmp.internal_port == 0)
{ {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Request Port Mapping: Internal port must not 0"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Request Port Mapping: Internal port must not 0");
} }
break; break;
case NATPMP_RESPONSE_ADDRESS: case NATPMP_RESPONSE_ADDRESS:
@@ -144,7 +144,7 @@ static int ndpi_search_natpmp_extra(struct ndpi_detection_module_struct *ndpi_st
flow->protos.natpmp.external_address.ipv4 = get_u_int32_t(packet->payload, 8); flow->protos.natpmp.external_address.ipv4 = get_u_int32_t(packet->payload, 8);
if (flow->protos.natpmp.result_code != 0 && flow->protos.natpmp.external_address.ipv4 != 0) if (flow->protos.natpmp.result_code != 0 && flow->protos.natpmp.external_address.ipv4 != 0)
{ {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Address Response: Result code indicates an error, but External IPv4 Address is set"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Address Response: Result code indicates an error, but External IPv4 Address is set");
} }
break; break;
case NATPMP_RESPONSE_UDP_MAPPING: case NATPMP_RESPONSE_UDP_MAPPING:
@@ -154,7 +154,7 @@ static int ndpi_search_natpmp_extra(struct ndpi_detection_module_struct *ndpi_st
flow->protos.natpmp.external_port = ntohs(get_u_int16_t(packet->payload, 10)); flow->protos.natpmp.external_port = ntohs(get_u_int16_t(packet->payload, 10));
if (flow->protos.natpmp.internal_port == 0 || flow->protos.natpmp.external_port == 0) if (flow->protos.natpmp.internal_port == 0 || flow->protos.natpmp.external_port == 0)
{ {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Port Mapping Response: Internal/External port must not 0"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Port Mapping Response: Internal/External port must not 0");
} }
break; break;
} }
+2 -3
View File
@@ -29,8 +29,7 @@
#include "ndpi_private.h" #include "ndpi_private.h"
static void ndpi_int_nintendo_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_nintendo_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow) {
u_int8_t due_to_correlation) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NINTENDO, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NINTENDO, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
} }
@@ -46,7 +45,7 @@ static void ndpi_search_nintendo(struct ndpi_detection_module_struct *ndpi_struc
if(memcmp(payload, nintendo_pattern, 5) == 0) { if(memcmp(payload, nintendo_pattern, 5) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found nintendo\n"); NDPI_LOG_INFO(ndpi_struct, "found nintendo\n");
ndpi_int_nintendo_add_connection(ndpi_struct, flow, 0); ndpi_int_nintendo_add_connection(ndpi_struct, flow);
return; return;
} }
} }
+1 -1
View File
@@ -35,7 +35,7 @@ static void ndpi_int_nomachine_add_connection(struct ndpi_detection_module_struc
NDPI_LOG_INFO(ndpi_struct, "found NoMachine\n"); NDPI_LOG_INFO(ndpi_struct, "found NoMachine\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NOMACHINE, ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_NOMACHINE,
NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
ndpi_set_risk(ndpi_struct, flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found NoMachine"); ndpi_set_risk(flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found NoMachine");
} }
static void ndpi_search_nomachine(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_search_nomachine(struct ndpi_detection_module_struct *ndpi_struct,
+19 -19
View File
@@ -643,7 +643,8 @@ static int quic_get_pn_cipher_algo(int cipher_algo, int *hp_cipher_mode)
* algorithm output. * algorithm output.
*/ */
static int quic_hp_cipher_prepare(struct ndpi_detection_module_struct *ndpi_struct, static int quic_hp_cipher_prepare(struct ndpi_detection_module_struct *ndpi_struct,
quic_hp_cipher *hp_cipher, int hash_algo, int cipher_algo, uint8_t *secret, u_int32_t version) quic_hp_cipher *hp_cipher, int hash_algo, int cipher_algo,
uint8_t *secret, u_int32_t version)
{ {
#if 0 #if 0
/* Clear previous state (if any). */ /* Clear previous state (if any). */
@@ -674,7 +675,8 @@ static int quic_hp_cipher_prepare(struct ndpi_detection_module_struct *ndpi_stru
return 1; return 1;
} }
static int quic_pp_cipher_prepare(struct ndpi_detection_module_struct *ndpi_struct, static int quic_pp_cipher_prepare(struct ndpi_detection_module_struct *ndpi_struct,
quic_pp_cipher *pp_cipher, int hash_algo, int cipher_algo, int cipher_mode, uint8_t *secret, u_int32_t version) quic_pp_cipher *pp_cipher, int hash_algo, int cipher_algo,
int cipher_mode, uint8_t *secret, u_int32_t version)
{ {
#if 0 #if 0
/* Clear previous state (if any). */ /* Clear previous state (if any). */
@@ -699,7 +701,8 @@ static int quic_pp_cipher_prepare(struct ndpi_detection_module_struct *ndpi_stru
return 1; return 1;
} }
static int quic_ciphers_prepare(struct ndpi_detection_module_struct *ndpi_struct, static int quic_ciphers_prepare(struct ndpi_detection_module_struct *ndpi_struct,
quic_ciphers *ciphers, int hash_algo, int cipher_algo, int cipher_mode, uint8_t *secret, u_int32_t version) quic_ciphers *ciphers, int hash_algo, int cipher_algo,
int cipher_mode, uint8_t *secret, u_int32_t version)
{ {
int ret; int ret;
@@ -981,7 +984,7 @@ static int quic_derive_initial_secrets(struct ndpi_detection_module_struct *ndpi
static uint8_t *decrypt_initial_packet(struct ndpi_detection_module_struct *ndpi_struct, static uint8_t *decrypt_initial_packet(struct ndpi_detection_module_struct *ndpi_struct,
const uint8_t *orig_dest_conn_id, uint8_t orig_dest_conn_id_len, const uint8_t *orig_dest_conn_id, uint8_t orig_dest_conn_id_len,
const uint8_t *dest_conn_id, uint8_t dest_conn_id_len, uint8_t dest_conn_id_len,
uint8_t source_conn_id_len, uint32_t version, uint8_t source_conn_id_len, uint32_t version,
uint32_t *clear_payload_len) uint32_t *clear_payload_len)
{ {
@@ -1049,8 +1052,7 @@ static uint8_t *decrypt_initial_packet(struct ndpi_detection_module_struct *ndpi
quic_ciphers_reset(&ciphers); quic_ciphers_reset(&ciphers);
return NULL; return NULL;
} }
quic_decrypt_message(ndpi_struct, quic_decrypt_message(ndpi_struct, &ciphers.pp_cipher, &packet->payload[0], pn_offset + payload_length,
&ciphers.pp_cipher, &packet->payload[0], pn_offset + payload_length,
offset, first_byte, pkn_len, packet_number, &decryption); offset, first_byte, pkn_len, packet_number, &decryption);
quic_ciphers_reset(&ciphers); quic_ciphers_reset(&ciphers);
@@ -1370,7 +1372,7 @@ static uint8_t *get_clear_payload(struct ndpi_detection_module_struct *ndpi_stru
clear_payload = decrypt_initial_packet(ndpi_struct, clear_payload = decrypt_initial_packet(ndpi_struct,
flow->l4.udp.quic_orig_dest_conn_id, flow->l4.udp.quic_orig_dest_conn_id,
flow->l4.udp.quic_orig_dest_conn_id_len, flow->l4.udp.quic_orig_dest_conn_id_len,
dest_conn_id, dest_conn_id_len, dest_conn_id_len,
source_conn_id_len, version, source_conn_id_len, version,
clear_payload_len); clear_payload_len);
} }
@@ -1470,10 +1472,10 @@ void process_chlo(struct ndpi_detection_module_struct *ndpi_struct,
char str[128]; char str[128];
snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name); snprintf(str, sizeof(str), "Invalid host %s", flow->host_server_name);
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, str); ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, str);
/* This looks like an attack */ /* This looks like an attack */
ndpi_set_risk(ndpi_struct, flow, NDPI_POSSIBLE_EXPLOIT, NULL); ndpi_set_risk(flow, NDPI_POSSIBLE_EXPLOIT, NULL);
} }
sni_found = 1; sni_found = 1;
@@ -1501,12 +1503,11 @@ void process_chlo(struct ndpi_detection_module_struct *ndpi_struct,
/* Add check for missing SNI */ /* Add check for missing SNI */
if(flow->host_server_name[0] == '\0') { if(flow->host_server_name[0] == '\0') {
/* This is a bit suspicious */ /* This is a bit suspicious */
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_MISSING_SNI, NULL); ndpi_set_risk(flow, NDPI_TLS_MISSING_SNI, NULL);
} }
} }
static int may_be_gquic_rej(struct ndpi_detection_module_struct *ndpi_struct, static int may_be_gquic_rej(struct ndpi_detection_module_struct *ndpi_struct)
struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
void *ptr; void *ptr;
@@ -1527,7 +1528,7 @@ static int may_be_gquic_rej(struct ndpi_detection_module_struct *ndpi_struct,
} }
static int may_be_0rtt(struct ndpi_detection_module_struct *ndpi_struct, static int may_be_0rtt(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, uint32_t *version) uint32_t *version)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int8_t first_byte; u_int8_t first_byte;
@@ -1683,7 +1684,7 @@ static int may_be_initial_pkt(struct ndpi_detection_module_struct *ndpi_struct,
/* ***************************************************************** */ /* ***************************************************************** */
static int eval_extra_processing(struct ndpi_detection_module_struct *ndpi_struct, static int eval_extra_processing(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) struct ndpi_flow_struct *flow)
{ {
u_int32_t version = flow->protos.tls_quic.quic_version; u_int32_t version = flow->protos.tls_quic.quic_version;
@@ -1783,8 +1784,7 @@ static int ndpi_search_quic_extra(struct ndpi_detection_module_struct *ndpi_stru
return 0; return 0;
} }
static int is_vn(struct ndpi_detection_module_struct *ndpi_struct, static int is_vn(struct ndpi_detection_module_struct *ndpi_struct)
struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int32_t version; u_int32_t version;
@@ -1845,7 +1845,7 @@ static int ndpi_search_quic_extra_vn(struct ndpi_detection_module_struct *ndpi_s
return 1; /* Keep going */ return 1; /* Keep going */
if(flow->l4.udp.quic_vn_pair == 0) { if(flow->l4.udp.quic_vn_pair == 0) {
if(is_vn(ndpi_struct, flow)) { if(is_vn(ndpi_struct)) {
NDPI_LOG_DBG(ndpi_struct, "Valid VN\n"); NDPI_LOG_DBG(ndpi_struct, "Valid VN\n");
flow->l4.udp.quic_vn_pair = 1; flow->l4.udp.quic_vn_pair = 1;
return 1; return 1;
@@ -1892,7 +1892,7 @@ static void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
is_initial_quic = may_be_initial_pkt(ndpi_struct, &version); is_initial_quic = may_be_initial_pkt(ndpi_struct, &version);
if(!is_initial_quic) { if(!is_initial_quic) {
if(!is_ch_reassembler_pending(flow)) { /* Better safe than sorry */ if(!is_ch_reassembler_pending(flow)) { /* Better safe than sorry */
ret = may_be_0rtt(ndpi_struct, flow, &version); ret = may_be_0rtt(ndpi_struct, &version);
if(ret == 1) { if(ret == 1) {
NDPI_LOG_DBG(ndpi_struct, "Found 0-RTT, keep looking for Initial\n"); NDPI_LOG_DBG(ndpi_struct, "Found 0-RTT, keep looking for Initial\n");
flow->l4.udp.quic_0rtt_found = 1; flow->l4.udp.quic_0rtt_found = 1;
@@ -1910,7 +1910,7 @@ static void ndpi_search_quic(struct ndpi_detection_module_struct *ndpi_struct,
flow->protos.tls_quic.quic_version = 0; /* unknown */ flow->protos.tls_quic.quic_version = 0; /* unknown */
return; return;
} }
ret = may_be_gquic_rej(ndpi_struct, flow); ret = may_be_gquic_rej(ndpi_struct);
if(ret == 1) { if(ret == 1) {
NDPI_LOG_INFO(ndpi_struct, "GQUIC REJ\n"); NDPI_LOG_INFO(ndpi_struct, "GQUIC REJ\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_QUIC, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_QUIC, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
+1 -1
View File
@@ -36,7 +36,7 @@ static void ndpi_int_radmin_add_connection(struct ndpi_detection_module_struct *
ndpi_set_detected_protocol(ndpi_struct, flow, ndpi_set_detected_protocol(ndpi_struct, flow,
NDPI_PROTOCOL_RADMIN, NDPI_PROTOCOL_UNKNOWN, NDPI_PROTOCOL_RADMIN, NDPI_PROTOCOL_UNKNOWN,
NDPI_CONFIDENCE_DPI); NDPI_CONFIDENCE_DPI);
ndpi_set_risk(ndpi_struct, flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found Radmin"); ndpi_set_risk(flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found Radmin");
} }
static void ndpi_search_radmin(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_search_radmin(struct ndpi_detection_module_struct *ndpi_struct,
+2 -3
View File
@@ -47,8 +47,7 @@ static size_t raknet_dissect_ip(struct ndpi_packet_struct * const packet, size_t
return (packet->payload[offset] == 0x04 ? 4 : 16); return (packet->payload[offset] == 0x04 ? 4 : 16);
} }
static int is_custom_version(struct ndpi_detection_module_struct *ndpi_struct, static int is_custom_version(struct ndpi_detection_module_struct *ndpi_struct)
struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
unsigned char magic[] = { 0x00, 0xFF, 0xFF, 0x00, 0xFE, 0xFE, 0xFE, 0xFE, unsigned char magic[] = { 0x00, 0xFF, 0xFF, 0x00, 0xFE, 0xFE, 0xFE, 0xFE,
@@ -104,7 +103,7 @@ static void ndpi_search_raknet(struct ndpi_detection_module_struct *ndpi_struct,
*/ */
if (flow->packet_counter == 1) if (flow->packet_counter == 1)
{ {
flow->l4.udp.raknet_custom = is_custom_version(ndpi_struct, flow); flow->l4.udp.raknet_custom = is_custom_version(ndpi_struct);
} }
if (packet->payload_packet_len < 7) if (packet->payload_packet_len < 7)
+1 -1
View File
@@ -36,7 +36,7 @@ static void ndpi_int_rdp_add_connection(struct ndpi_detection_module_struct *ndp
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
NDPI_LOG_INFO(ndpi_struct, "found RDP\n"); NDPI_LOG_INFO(ndpi_struct, "found RDP\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RDP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_RDP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
ndpi_set_risk(ndpi_struct, flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found RDP"); /* Remote assistance */ ndpi_set_risk(flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found RDP"); /* Remote assistance */
} }
static void ndpi_search_rdp(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_search_rdp(struct ndpi_detection_module_struct *ndpi_struct,
+1 -1
View File
@@ -139,7 +139,7 @@ static void ndpi_search_rsh(struct ndpi_detection_module_struct * ndpi_struct,
flow->protos.rsh.command) < 0) flow->protos.rsh.command) < 0)
str[0] = '\0'; str[0] = '\0';
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, str); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, str);
} }
return; return;
+2 -3
View File
@@ -84,8 +84,7 @@ static int is_valid_rtcp_payload_type(uint8_t type)
return (type >= 192 && type <= 213); return (type >= 192 && type <= 213);
} }
int is_rtp_or_rtcp(struct ndpi_detection_module_struct *ndpi_struct, int is_rtp_or_rtcp(struct ndpi_detection_module_struct *ndpi_struct)
struct ndpi_flow_struct *flow)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int8_t padding, csrc_count, ext_header; u_int8_t padding, csrc_count, ext_header;
@@ -170,7 +169,7 @@ static void ndpi_rtp_search(struct ndpi_detection_module_struct *ndpi_struct,
return; return;
} }
is_rtp = is_rtp_or_rtcp(ndpi_struct, flow); is_rtp = is_rtp_or_rtcp(ndpi_struct);
if(is_rtp == IS_RTP) { if(is_rtp == IS_RTP) {
if(flow->l4.udp.rtp_stage == 2) { if(flow->l4.udp.rtp_stage == 2) {
if(flow->l4.udp.line_pkts[0] >= 2 && flow->l4.udp.line_pkts[1] >= 2) { if(flow->l4.udp.line_pkts[0] >= 2 && flow->l4.udp.line_pkts[1] >= 2) {
+16 -17
View File
@@ -30,8 +30,7 @@
#include "ndpi_private.h" #include "ndpi_private.h"
static void ndpi_int_sip_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_sip_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow) {
u_int8_t due_to_correlation) {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SIP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SIP, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
} }
@@ -65,7 +64,7 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
&& (memcmp(&packet_payload[7], "SIP:", 4) == 0 || memcmp(&packet_payload[7], "sip:", 4) == 0)) { && (memcmp(&packet_payload[7], "SIP:", 4) == 0 || memcmp(&packet_payload[7], "sip:", 4) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found sip NOTIFY\n"); NDPI_LOG_INFO(ndpi_struct, "found sip NOTIFY\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -73,14 +72,14 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
&& (memcmp(&packet_payload[9], "SIP:", 4) == 0 || memcmp(&packet_payload[9], "sip:", 4) == 0)) { && (memcmp(&packet_payload[9], "SIP:", 4) == 0 || memcmp(&packet_payload[9], "sip:", 4) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found sip REGISTER\n"); NDPI_LOG_INFO(ndpi_struct, "found sip REGISTER\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
if((memcmp(packet_payload, "INVITE ", 7) == 0 || memcmp(packet_payload, "invite ", 7) == 0) if((memcmp(packet_payload, "INVITE ", 7) == 0 || memcmp(packet_payload, "invite ", 7) == 0)
&& (memcmp(&packet_payload[7], "SIP:", 4) == 0 || memcmp(&packet_payload[7], "sip:", 4) == 0)) { && (memcmp(&packet_payload[7], "SIP:", 4) == 0 || memcmp(&packet_payload[7], "sip:", 4) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found sip INVITE\n"); NDPI_LOG_INFO(ndpi_struct, "found sip INVITE\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -92,20 +91,20 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
/* /*
if(memcmp(packet_payload, "SIP/2.0 200 OK", 14) == 0 || memcmp(packet_payload, "sip/2.0 200 OK", 14) == 0) { if(memcmp(packet_payload, "SIP/2.0 200 OK", 14) == 0 || memcmp(packet_payload, "sip/2.0 200 OK", 14) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found sip SIP/2.0 0K\n"); NDPI_LOG_INFO(ndpi_struct, "found sip SIP/2.0 0K\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
*/ */
if(memcmp(packet_payload, "SIP/2.0 ", 8) == 0 || memcmp(packet_payload, "sip/2.0 ", 8) == 0) { if(memcmp(packet_payload, "SIP/2.0 ", 8) == 0 || memcmp(packet_payload, "sip/2.0 ", 8) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found sip SIP/2.0 *\n"); NDPI_LOG_INFO(ndpi_struct, "found sip SIP/2.0 *\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
if((memcmp(packet_payload, "BYE ", 4) == 0 || memcmp(packet_payload, "bye ", 4) == 0) if((memcmp(packet_payload, "BYE ", 4) == 0 || memcmp(packet_payload, "bye ", 4) == 0)
&& (memcmp(&packet_payload[4], "SIP:", 4) == 0 || memcmp(&packet_payload[4], "sip:", 4) == 0)) { && (memcmp(&packet_payload[4], "SIP:", 4) == 0 || memcmp(&packet_payload[4], "sip:", 4) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found sip BYE\n"); NDPI_LOG_INFO(ndpi_struct, "found sip BYE\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -113,7 +112,7 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
&& ((memcmp(&packet_payload[4], "SIP:", 4) == 0 || memcmp(&packet_payload[4], "sip:", 4) == 0) || && ((memcmp(&packet_payload[4], "SIP:", 4) == 0 || memcmp(&packet_payload[4], "sip:", 4) == 0) ||
(memcmp(&packet_payload[4], "TEL:", 4) == 0 || memcmp(&packet_payload[4], "tel:", 4) == 0))) { (memcmp(&packet_payload[4], "TEL:", 4) == 0 || memcmp(&packet_payload[4], "tel:", 4) == 0))) {
NDPI_LOG_INFO(ndpi_struct, "found sip ACK\n"); NDPI_LOG_INFO(ndpi_struct, "found sip ACK\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -121,21 +120,21 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
&& ((memcmp(&packet_payload[7], "SIP:", 4) == 0 || memcmp(&packet_payload[7], "sip:", 4) == 0) || && ((memcmp(&packet_payload[7], "SIP:", 4) == 0 || memcmp(&packet_payload[7], "sip:", 4) == 0) ||
(memcmp(&packet_payload[7], "TEL:", 4) == 0 || memcmp(&packet_payload[7], "tel:", 4) == 0))) { (memcmp(&packet_payload[7], "TEL:", 4) == 0 || memcmp(&packet_payload[7], "tel:", 4) == 0))) {
NDPI_LOG_INFO(ndpi_struct, "found sip CANCEL\n"); NDPI_LOG_INFO(ndpi_struct, "found sip CANCEL\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
if((memcmp(packet_payload, "PUBLISH ", 8) == 0 || memcmp(packet_payload, "publish ", 8) == 0) if((memcmp(packet_payload, "PUBLISH ", 8) == 0 || memcmp(packet_payload, "publish ", 8) == 0)
&& (memcmp(&packet_payload[8], "SIP:", 4) == 0 || memcmp(&packet_payload[8], "sip:", 4) == 0)) { && (memcmp(&packet_payload[8], "SIP:", 4) == 0 || memcmp(&packet_payload[8], "sip:", 4) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found sip PUBLISH\n"); NDPI_LOG_INFO(ndpi_struct, "found sip PUBLISH\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
if((memcmp(packet_payload, "SUBSCRIBE ", 10) == 0 || memcmp(packet_payload, "subscribe ", 10) == 0) if((memcmp(packet_payload, "SUBSCRIBE ", 10) == 0 || memcmp(packet_payload, "subscribe ", 10) == 0)
&& (memcmp(&packet_payload[10], "SIP:", 4) == 0 || memcmp(&packet_payload[10], "sip:", 4) == 0)) { && (memcmp(&packet_payload[10], "SIP:", 4) == 0 || memcmp(&packet_payload[10], "sip:", 4) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found sip SUBSCRIBE\n"); NDPI_LOG_INFO(ndpi_struct, "found sip SUBSCRIBE\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -143,7 +142,7 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
if((memcmp(packet_payload, "MESSAGE ", 8) == 0 || memcmp(packet_payload, "message ", 8) == 0) if((memcmp(packet_payload, "MESSAGE ", 8) == 0 || memcmp(packet_payload, "message ", 8) == 0)
&& (memcmp(&packet_payload[8], "SIP:", 4) == 0 || memcmp(&packet_payload[8], "sip:", 4) == 0)) { && (memcmp(&packet_payload[8], "SIP:", 4) == 0 || memcmp(&packet_payload[8], "sip:", 4) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found sip MESSAGE\n"); NDPI_LOG_INFO(ndpi_struct, "found sip MESSAGE\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
@@ -153,28 +152,28 @@ void ndpi_search_sip_handshake(struct ndpi_detection_module_struct
&& ((memcmp(&packet_payload[8], "SIP:", 4) == 0 || memcmp(&packet_payload[8], "sip:", 4) == 0) || && ((memcmp(&packet_payload[8], "SIP:", 4) == 0 || memcmp(&packet_payload[8], "sip:", 4) == 0) ||
(memcmp(&packet_payload[8], "TEL:", 4) == 0 || memcmp(&packet_payload[8], "tel:", 4) == 0))) { (memcmp(&packet_payload[8], "TEL:", 4) == 0 || memcmp(&packet_payload[8], "tel:", 4) == 0))) {
NDPI_LOG_INFO(ndpi_struct, "found sip OPTIONS\n"); NDPI_LOG_INFO(ndpi_struct, "found sip OPTIONS\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
if((memcmp(packet_payload, "REFER ", 6) == 0 || memcmp(packet_payload, "refer ", 6) == 0) if((memcmp(packet_payload, "REFER ", 6) == 0 || memcmp(packet_payload, "refer ", 6) == 0)
&& (memcmp(&packet_payload[6], "SIP:", 4) == 0 || memcmp(&packet_payload[6], "sip:", 4) == 0)) { && (memcmp(&packet_payload[6], "SIP:", 4) == 0 || memcmp(&packet_payload[6], "sip:", 4) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found sip REFER\n"); NDPI_LOG_INFO(ndpi_struct, "found sip REFER\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
if((memcmp(packet_payload, "PRACK ", 6) == 0 || memcmp(packet_payload, "prack ", 6) == 0) if((memcmp(packet_payload, "PRACK ", 6) == 0 || memcmp(packet_payload, "prack ", 6) == 0)
&& (memcmp(&packet_payload[6], "SIP:", 4) == 0 || memcmp(&packet_payload[6], "sip:", 4) == 0)) { && (memcmp(&packet_payload[6], "SIP:", 4) == 0 || memcmp(&packet_payload[6], "sip:", 4) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found sip PRACK\n"); NDPI_LOG_INFO(ndpi_struct, "found sip PRACK\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
if((memcmp(packet_payload, "INFO ", 5) == 0 || memcmp(packet_payload, "info ", 5) == 0) if((memcmp(packet_payload, "INFO ", 5) == 0 || memcmp(packet_payload, "info ", 5) == 0)
&& (memcmp(&packet_payload[5], "SIP:", 4) == 0 || memcmp(&packet_payload[5], "sip:", 4) == 0)) { && (memcmp(&packet_payload[5], "SIP:", 4) == 0 || memcmp(&packet_payload[5], "sip:", 4) == 0)) {
NDPI_LOG_INFO(ndpi_struct, "found sip INFO\n"); NDPI_LOG_INFO(ndpi_struct, "found sip INFO\n");
ndpi_int_sip_add_connection(ndpi_struct, flow, 0); ndpi_int_sip_add_connection(ndpi_struct, flow);
return; return;
} }
} }
+1 -1
View File
@@ -285,7 +285,7 @@ static void ndpi_dissect_slp_v2(struct ndpi_detection_module_struct *ndpi_struct
} }
} else if (url_entry_count_offset > 0 && packet->payload_packet_len > sizeof(*hdr) + url_entry_count_offset + 2) { } else if (url_entry_count_offset > 0 && packet->payload_packet_len > sizeof(*hdr) + url_entry_count_offset + 2) {
if (slp_dissect_url_entries(ndpi_struct, flow, sizeof(*hdr) + url_entry_count_offset) != 0) { if (slp_dissect_url_entries(ndpi_struct, flow, sizeof(*hdr) + url_entry_count_offset) != 0) {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Invalid URL entries"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Invalid URL entries");
} }
} else if (packet->payload_packet_len > sizeof(*hdr) + url_offset + 2) { } else if (packet->payload_packet_len > sizeof(*hdr) + url_offset + 2) {
url_length_or_count = ntohs(*(uint16_t *)&packet->payload[sizeof(*hdr) + url_offset]); // FID_SrvReg or FID_SrvDeReg url_length_or_count = ntohs(*(uint16_t *)&packet->payload[sizeof(*hdr) + url_offset]); // FID_SrvReg or FID_SrvDeReg
+1 -1
View File
@@ -52,7 +52,7 @@ static void ndpi_search_smb_tcp(struct ndpi_detection_module_struct *ndpi_struct
if(packet->payload[8] != 0x72) /* Skip Negotiate request */ { if(packet->payload[8] != 0x72) /* Skip Negotiate request */ {
NDPI_LOG_INFO(ndpi_struct, "found SMBv1\n"); NDPI_LOG_INFO(ndpi_struct, "found SMBv1\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SMBV1, NDPI_PROTOCOL_NETBIOS, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SMBV1, NDPI_PROTOCOL_NETBIOS, NDPI_CONFIDENCE_DPI);
ndpi_set_risk(ndpi_struct, flow, NDPI_SMB_INSECURE_VERSION, "Found SMBv1"); ndpi_set_risk(flow, NDPI_SMB_INSECURE_VERSION, "Found SMBv1");
} }
return; return;
} else if(memcmp(&packet->payload[4], smbv2, sizeof(smbv2)) == 0) { } else if(memcmp(&packet->payload[4], smbv2, sizeof(smbv2)) == 0) {
+1 -1
View File
@@ -129,7 +129,7 @@ static void ndpi_search_snmp(struct ndpi_detection_module_struct *ndpi_struct,
char str[64]; char str[64];
snprintf(str, sizeof(str), "SNMP Error %d", error_status); snprintf(str, sizeof(str), "SNMP Error %d", error_status);
ndpi_set_risk(ndpi_struct, flow, NDPI_ERROR_CODE_DETECTED, str); ndpi_set_risk(flow, NDPI_ERROR_CODE_DETECTED, str);
} }
} }
} }
+3 -4
View File
@@ -30,8 +30,7 @@
static void ndpi_int_spotify_add_connection(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_int_spotify_add_connection(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow)
u_int8_t due_to_correlation)
{ {
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SPOTIFY, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SPOTIFY, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
} }
@@ -50,7 +49,7 @@ static void ndpi_check_spotify(struct ndpi_detection_module_struct *ndpi_struct,
if(payload_len >= 7) { if(payload_len >= 7) {
if(memcmp(packet->payload, "SpotUdp", 7) == 0) { if(memcmp(packet->payload, "SpotUdp", 7) == 0) {
NDPI_LOG_INFO(ndpi_struct, "found spotify udp dissector\n"); NDPI_LOG_INFO(ndpi_struct, "found spotify udp dissector\n");
ndpi_int_spotify_add_connection(ndpi_struct, flow, 0); ndpi_int_spotify_add_connection(ndpi_struct, flow);
return; return;
} }
} }
@@ -62,7 +61,7 @@ static void ndpi_check_spotify(struct ndpi_detection_module_struct *ndpi_struct,
packet->payload[6] == 0x52 && (packet->payload[7] == 0x0e || packet->payload[7] == 0x0f) && packet->payload[6] == 0x52 && (packet->payload[7] == 0x0e || packet->payload[7] == 0x0f) &&
packet->payload[8] == 0x50 ) { packet->payload[8] == 0x50 ) {
NDPI_LOG_INFO(ndpi_struct, "found spotify tcp dissector\n"); NDPI_LOG_INFO(ndpi_struct, "found spotify tcp dissector\n");
ndpi_int_spotify_add_connection(ndpi_struct, flow, 0); ndpi_int_spotify_add_connection(ndpi_struct, flow);
} }
} }
+10 -13
View File
@@ -68,8 +68,7 @@ typedef struct {
/* ************************************************************************ */ /* ************************************************************************ */
static void ssh_analyze_signature_version(struct ndpi_detection_module_struct *ndpi_struct, static void ssh_analyze_signature_version(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
char *str_to_check, char *str_to_check,
u_int8_t is_client_signature) { u_int8_t is_client_signature) {
@@ -122,8 +121,7 @@ static void ssh_analyze_signature_version(struct ndpi_detection_module_struct *n
/* ************************************************************************ */ /* ************************************************************************ */
static void ssh_analyse_cipher(struct ndpi_detection_module_struct *ndpi_struct, static void ssh_analyse_cipher(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
char *ciphers, u_int cipher_len, char *ciphers, u_int cipher_len,
u_int8_t is_client_signature) { u_int8_t is_client_signature) {
@@ -179,7 +177,7 @@ static void ssh_analyse_cipher(struct ndpi_detection_module_struct *ndpi_struct,
char str[64]; char str[64];
snprintf(str, sizeof(str), "Found cipher %s", obsolete_ciphers[found_obsolete_cipher]); snprintf(str, sizeof(str), "Found cipher %s", obsolete_ciphers[found_obsolete_cipher]);
ndpi_set_risk(ndpi_struct, flow, ndpi_set_risk(flow,
(is_client_signature ? NDPI_SSH_OBSOLETE_CLIENT_VERSION_OR_CIPHER : NDPI_SSH_OBSOLETE_SERVER_VERSION_OR_CIPHER), (is_client_signature ? NDPI_SSH_OBSOLETE_CLIENT_VERSION_OR_CIPHER : NDPI_SSH_OBSOLETE_SERVER_VERSION_OR_CIPHER),
str); str);
} }
@@ -218,8 +216,7 @@ static void ndpi_int_ssh_add_connection(struct ndpi_detection_module_struct
/* ************************************************************************ */ /* ************************************************************************ */
static u_int16_t concat_hash_string(struct ndpi_detection_module_struct *ndpi_struct, static u_int16_t concat_hash_string(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
struct ndpi_packet_struct *packet, struct ndpi_packet_struct *packet,
char *buf, u_int8_t client_hash) { char *buf, u_int8_t client_hash) {
u_int32_t offset = 22, len, buf_out_len = 0, max_payload_len = packet->payload_packet_len-sizeof(u_int32_t); u_int32_t offset = 22, len, buf_out_len = 0, max_payload_len = packet->payload_packet_len-sizeof(u_int32_t);
@@ -262,7 +259,7 @@ static u_int16_t concat_hash_string(struct ndpi_detection_module_struct *ndpi_st
goto invalid_payload; goto invalid_payload;
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len); strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
ssh_analyse_cipher(ndpi_struct, flow, (char*)&packet->payload[offset], len, 1 /* client */); ssh_analyse_cipher(flow, (char*)&packet->payload[offset], len, 1 /* client */);
buf_out_len += len; buf_out_len += len;
buf[buf_out_len++] = ';'; buf[buf_out_len++] = ';';
} }
@@ -283,7 +280,7 @@ static u_int16_t concat_hash_string(struct ndpi_detection_module_struct *ndpi_st
goto invalid_payload; goto invalid_payload;
strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len); strncpy(&buf[buf_out_len], (const char *)&packet->payload[offset], len);
ssh_analyse_cipher(ndpi_struct, flow, (char*)&packet->payload[offset], len, 0 /* server */); ssh_analyse_cipher(flow, (char*)&packet->payload[offset], len, 0 /* server */);
buf_out_len += len; buf_out_len += len;
buf[buf_out_len++] = ';'; buf[buf_out_len++] = ';';
} }
@@ -417,7 +414,7 @@ static void ndpi_search_ssh_tcp(struct ndpi_detection_module_struct *ndpi_struct
flow->protos.ssh.client_signature[len] = '\0'; flow->protos.ssh.client_signature[len] = '\0';
ndpi_ssh_zap_cr(flow->protos.ssh.client_signature, len); ndpi_ssh_zap_cr(flow->protos.ssh.client_signature, len);
ssh_analyze_signature_version(ndpi_struct, flow, flow->protos.ssh.client_signature, 1); ssh_analyze_signature_version(flow, flow->protos.ssh.client_signature, 1);
#ifdef SSH_DEBUG #ifdef SSH_DEBUG
printf("[SSH] [client_signature: %s]\n", flow->protos.ssh.client_signature); printf("[SSH] [client_signature: %s]\n", flow->protos.ssh.client_signature);
@@ -437,7 +434,7 @@ static void ndpi_search_ssh_tcp(struct ndpi_detection_module_struct *ndpi_struct
flow->protos.ssh.server_signature[len] = '\0'; flow->protos.ssh.server_signature[len] = '\0';
ndpi_ssh_zap_cr(flow->protos.ssh.server_signature, len); ndpi_ssh_zap_cr(flow->protos.ssh.server_signature, len);
ssh_analyze_signature_version(ndpi_struct, flow, flow->protos.ssh.server_signature, 0); ssh_analyze_signature_version(flow, flow->protos.ssh.server_signature, 0);
#ifdef SSH_DEBUG #ifdef SSH_DEBUG
printf("[SSH] [server_signature: %s]\n", flow->protos.ssh.server_signature); printf("[SSH] [server_signature: %s]\n", flow->protos.ssh.server_signature);
@@ -469,7 +466,7 @@ static void ndpi_search_ssh_tcp(struct ndpi_detection_module_struct *ndpi_struct
if(packet->packet_direction == 0 /* client */) { if(packet->packet_direction == 0 /* client */) {
u_char fingerprint_client[16]; u_char fingerprint_client[16];
len = concat_hash_string(ndpi_struct, flow, packet, hassh_buf, 1 /* client */); len = concat_hash_string(flow, packet, hassh_buf, 1 /* client */);
ndpi_MD5Init(&ctx); ndpi_MD5Init(&ctx);
ndpi_MD5Update(&ctx, (const unsigned char *)hassh_buf, len); ndpi_MD5Update(&ctx, (const unsigned char *)hassh_buf, len);
@@ -491,7 +488,7 @@ static void ndpi_search_ssh_tcp(struct ndpi_detection_module_struct *ndpi_struct
} else { } else {
u_char fingerprint_server[16]; u_char fingerprint_server[16];
len = concat_hash_string(ndpi_struct, flow, packet, hassh_buf, 0 /* server */); len = concat_hash_string(flow, packet, hassh_buf, 0 /* server */);
ndpi_MD5Init(&ctx); ndpi_MD5Init(&ctx);
ndpi_MD5Update(&ctx, (const unsigned char *)hassh_buf, len); ndpi_MD5Update(&ctx, (const unsigned char *)hassh_buf, len);
+2 -2
View File
@@ -48,7 +48,7 @@ static u_int8_t sc2_match_logon_ip(struct ndpi_packet_struct* packet)
transfer generated by the user interaction with the client, e.g. chatting or looking at someone's transfer generated by the user interaction with the client, e.g. chatting or looking at someone's
match history. The current way to detect this is plain dumb packet matching. match history. The current way to detect this is plain dumb packet matching.
*/ */
static u_int8_t ndpi_check_starcraft_tcp(struct ndpi_detection_module_struct* ndpi_struct, struct ndpi_flow_struct* flow) static u_int8_t ndpi_check_starcraft_tcp(struct ndpi_detection_module_struct* ndpi_struct)
{ {
struct ndpi_packet_struct* packet = &ndpi_struct->packet; struct ndpi_packet_struct* packet = &ndpi_struct->packet;
@@ -132,7 +132,7 @@ static void ndpi_search_starcraft(struct ndpi_detection_module_struct* ndpi_stru
} }
} }
else if (packet->tcp != NULL) { else if (packet->tcp != NULL) {
result = ndpi_check_starcraft_tcp(ndpi_struct, flow); result = ndpi_check_starcraft_tcp(ndpi_struct);
if (result == 1) { if (result == 1) {
NDPI_LOG_INFO(ndpi_struct, "Found Starcraft 2 [Client, TCP]\n"); NDPI_LOG_INFO(ndpi_struct, "Found Starcraft 2 [Client, TCP]\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_STARCRAFT, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_STARCRAFT, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
+5 -6
View File
@@ -417,8 +417,7 @@ int is_stun(struct ndpi_detection_module_struct *ndpi_struct,
return 1; return 1;
} }
static int keep_extra_dissection(struct ndpi_detection_module_struct *ndpi_struct, static int keep_extra_dissection(struct ndpi_flow_struct *flow)
struct ndpi_flow_struct *flow)
{ {
if(flow->detected_protocol_stack[1] == NDPI_PROTOCOL_UNKNOWN /* No subclassification */) if(flow->detected_protocol_stack[1] == NDPI_PROTOCOL_UNKNOWN /* No subclassification */)
return 1; return 1;
@@ -518,10 +517,10 @@ static int stun_search_again(struct ndpi_detection_module_struct *ndpi_struct,
old_proto_stack[1] = flow->detected_protocol_stack[1]; old_proto_stack[1] = flow->detected_protocol_stack[1];
/* TODO: right way? It is a bit scary... do we need to reset something else too? */ /* TODO: right way? It is a bit scary... do we need to reset something else too? */
reset_detected_protocol(ndpi_struct, flow); reset_detected_protocol(flow);
/* We keep the category related to STUN traffic */ /* We keep the category related to STUN traffic */
/* STUN often triggers this risk; clear it. TODO: clear other risks? */ /* STUN often triggers this risk; clear it. TODO: clear other risks? */
ndpi_unset_risk(ndpi_struct, flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT); ndpi_unset_risk(flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT);
/* Give room for DTLS handshake, where we might have /* Give room for DTLS handshake, where we might have
retransmissions and fragments */ retransmissions and fragments */
@@ -589,7 +588,7 @@ static int stun_search_again(struct ndpi_detection_module_struct *ndpi_struct,
NDPI_LOG_DBG(ndpi_struct, "QUIC range. Unexpected\n"); NDPI_LOG_DBG(ndpi_struct, "QUIC range. Unexpected\n");
} else if(first_byte <= 191) { } else if(first_byte <= 191) {
rtp_rtcp = is_rtp_or_rtcp(ndpi_struct, flow); rtp_rtcp = is_rtp_or_rtcp(ndpi_struct);
if(rtp_rtcp == IS_RTP) { if(rtp_rtcp == IS_RTP) {
NDPI_LOG_DBG(ndpi_struct, "RTP (dir %d)\n", packet->packet_direction); NDPI_LOG_DBG(ndpi_struct, "RTP (dir %d)\n", packet->packet_direction);
NDPI_LOG_INFO(ndpi_struct, "Found RTP over STUN\n"); NDPI_LOG_INFO(ndpi_struct, "Found RTP over STUN\n");
@@ -621,7 +620,7 @@ static int stun_search_again(struct ndpi_detection_module_struct *ndpi_struct,
} else { } else {
NDPI_LOG_DBG(ndpi_struct, "QUIC range. Unexpected\n"); NDPI_LOG_DBG(ndpi_struct, "QUIC range. Unexpected\n");
} }
return keep_extra_dissection(ndpi_struct, flow); return keep_extra_dissection(flow);
} }
/* ************************************************************ */ /* ************************************************************ */
-2
View File
@@ -25,7 +25,6 @@
u_int ndpi_search_tcp_or_udp_raw(struct ndpi_detection_module_struct *ndpi_struct, u_int ndpi_search_tcp_or_udp_raw(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow, struct ndpi_flow_struct *flow,
u_int8_t protocol,
u_int32_t saddr, u_int32_t daddr) /* host endianess */ u_int32_t saddr, u_int32_t daddr) /* host endianess */
{ {
u_int16_t rc; u_int16_t rc;
@@ -56,7 +55,6 @@ void ndpi_search_tcp_or_udp(struct ndpi_detection_module_struct *ndpi_struct, st
if(packet->iph /* IPv4 Only: we need to support packet->iphv6 at some point */) { if(packet->iph /* IPv4 Only: we need to support packet->iphv6 at some point */) {
proto = ndpi_search_tcp_or_udp_raw(ndpi_struct, proto = ndpi_search_tcp_or_udp_raw(ndpi_struct,
flow, flow,
flow->l4_proto,
ntohl(packet->iph->saddr), ntohl(packet->iph->saddr),
ntohl(packet->iph->daddr)); ntohl(packet->iph->daddr));
+1 -1
View File
@@ -51,7 +51,7 @@ static void ndpi_search_teamview(struct ndpi_detection_module_struct *ndpi_struc
if (flow->teamviewer_stage == 4 || if (flow->teamviewer_stage == 4 ||
packet->udp->dest == ntohs(5938) || packet->udp->source == ntohs(5938)) { packet->udp->dest == ntohs(5938) || packet->udp->source == ntohs(5938)) {
ndpi_int_teamview_add_connection(ndpi_struct, flow); ndpi_int_teamview_add_connection(ndpi_struct, flow);
ndpi_set_risk(ndpi_struct, flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found TeamViewer"); /* Remote assistance (UDP only) */ ndpi_set_risk(flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found TeamViewer"); /* Remote assistance (UDP only) */
} }
return; return;
} }
+4 -5
View File
@@ -65,7 +65,7 @@ static int search_telnet_again(struct ndpi_detection_module_struct *ndpi_struct,
return(1); return(1);
flow->protos.telnet.password_detected = 1; flow->protos.telnet.password_detected = 1;
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, "Found password"); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, "Found password");
flow->protos.telnet.password[flow->protos.telnet.character_id] = '\0'; flow->protos.telnet.password[flow->protos.telnet.character_id] = '\0';
return(0); return(0);
} }
@@ -99,7 +99,7 @@ static int search_telnet_again(struct ndpi_detection_module_struct *ndpi_struct,
snprintf(buf, sizeof(buf), "Found Telnet username (%s)", snprintf(buf, sizeof(buf), "Found Telnet username (%s)",
flow->protos.telnet.username); flow->protos.telnet.username);
ndpi_set_risk(ndpi_struct, flow, NDPI_CLEAR_TEXT_CREDENTIALS, buf); ndpi_set_risk(flow, NDPI_CLEAR_TEXT_CREDENTIALS, buf);
return(1); return(1);
} }
@@ -146,8 +146,7 @@ __mingw_forceinline static
#else #else
__forceinline static __forceinline static
#endif #endif
u_int8_t search_iac(struct ndpi_detection_module_struct *ndpi_struct, u_int8_t search_iac(struct ndpi_detection_module_struct *ndpi_struct) {
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int16_t a; u_int16_t a;
@@ -189,7 +188,7 @@ static void ndpi_search_telnet_tcp(struct ndpi_detection_module_struct *ndpi_str
struct ndpi_flow_struct *flow) { struct ndpi_flow_struct *flow) {
NDPI_LOG_DBG(ndpi_struct, "search telnet\n"); NDPI_LOG_DBG(ndpi_struct, "search telnet\n");
if(search_iac(ndpi_struct, flow) == 1) { if(search_iac(ndpi_struct) == 1) {
if(flow->l4.tcp.telnet_stage == 2) { if(flow->l4.tcp.telnet_stage == 2) {
NDPI_LOG_INFO(ndpi_struct, "found telnet\n"); NDPI_LOG_INFO(ndpi_struct, "found telnet\n");
ndpi_int_telnet_add_connection(ndpi_struct, flow); ndpi_int_telnet_add_connection(ndpi_struct, flow);
+9 -11
View File
@@ -113,29 +113,27 @@ static int thrift_validate_type(uint8_t message_type)
return message_type < TMT_TYPE_MAX; return message_type < TMT_TYPE_MAX;
} }
static void thrift_set_method(struct ndpi_detection_module_struct *ndpi_struct, static void thrift_set_method(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
char const * const method, size_t method_length) char const * const method, size_t method_length)
{ {
if (thrift_validate_method(method, method_length) == 0) { if (thrift_validate_method(method, method_length) == 0) {
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, "Invalid method name"); ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, "Invalid method name");
flow->protos.thrift.method[0] = '\0'; flow->protos.thrift.method[0] = '\0';
} else { } else {
strncpy(flow->protos.thrift.method, method, ndpi_min(sizeof(flow->protos.thrift.method), method_length)); strncpy(flow->protos.thrift.method, method, ndpi_min(sizeof(flow->protos.thrift.method), method_length));
} }
} }
static void thrift_set_type(struct ndpi_detection_module_struct *ndpi_struct, static void thrift_set_type(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
uint8_t message_type) uint8_t message_type)
{ {
if (message_type == TMT_INVALID_TMESSAGE_TYPE) { if (message_type == TMT_INVALID_TMESSAGE_TYPE) {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Invalid message type"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Invalid message type");
} }
flow->protos.thrift.message_type = message_type; flow->protos.thrift.message_type = message_type;
if (message_type == TMT_EXCEPTION) { if (message_type == TMT_EXCEPTION) {
ndpi_set_risk(ndpi_struct, flow, NDPI_ERROR_CODE_DETECTED, "Apache Thrift Exception"); ndpi_set_risk(flow, NDPI_ERROR_CODE_DETECTED, "Apache Thrift Exception");
} }
} }
@@ -168,8 +166,8 @@ static void ndpi_dissect_strict_hdr(struct ndpi_detection_module_struct *ndpi_st
ndpi_int_thrift_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN); ndpi_int_thrift_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
thrift_set_method(ndpi_struct, flow, strict_hdr->method, method_length); thrift_set_method(flow, strict_hdr->method, method_length);
thrift_set_type(ndpi_struct, flow, strict_hdr->message_type); thrift_set_type(flow, strict_hdr->message_type);
} }
static void ndpi_dissect_compact_hdr(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_dissect_compact_hdr(struct ndpi_detection_module_struct *ndpi_struct,
@@ -200,8 +198,8 @@ static void ndpi_dissect_compact_hdr(struct ndpi_detection_module_struct *ndpi_s
ndpi_int_thrift_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN); ndpi_int_thrift_add_connection(ndpi_struct, flow, NDPI_PROTOCOL_UNKNOWN);
thrift_set_method(ndpi_struct, flow, compact_hdr->method, compact_hdr->method_length); thrift_set_method(flow, compact_hdr->method, compact_hdr->method_length);
thrift_set_type(ndpi_struct, flow, compact_hdr->message_type); thrift_set_type(flow, compact_hdr->message_type);
} }
static void ndpi_search_thrift_tcp_udp(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_search_thrift_tcp_udp(struct ndpi_detection_module_struct *ndpi_struct,
+2 -2
View File
@@ -55,7 +55,7 @@ static void dissect_tivoconnect_data(struct ndpi_detection_module_struct *ndpi_s
if (value == NULL) if (value == NULL)
{ {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, "Missing value type in TiViConnect beacon"); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, "Missing value type in TiViConnect beacon");
continue; continue;
} }
value++; value++;
@@ -108,7 +108,7 @@ static void dissect_tivoconnect_data(struct ndpi_detection_module_struct *ndpi_s
if ((size_t)(key - payload) != payload_len) if ((size_t)(key - payload) != payload_len)
{ {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, ndpi_set_risk(flow, NDPI_MALFORMED_PACKET,
"TiViConnect beacon malformed packet"); "TiViConnect beacon malformed packet");
} }
} }
+42 -46
View File
@@ -149,9 +149,7 @@ static u_int32_t __get_master(struct ndpi_detection_module_struct *ndpi_struct,
/* **************************************** */ /* **************************************** */
static int ndpi_search_tls_memory(struct ndpi_detection_module_struct *ndpi_struct, static int ndpi_search_tls_memory(const u_int8_t *payload,
struct ndpi_flow_struct *flow,
const u_int8_t *payload,
u_int16_t payload_len, u_int16_t payload_len,
u_int32_t seq, u_int32_t seq,
message_t *message) { message_t *message) {
@@ -354,7 +352,7 @@ static void checkTLSSubprotocol(struct ndpi_detection_module_struct *ndpi_struct
ndpi_set_detected_protocol(ndpi_struct, flow, cached_proto, __get_master(ndpi_struct, flow), NDPI_CONFIDENCE_DPI_CACHE); ndpi_set_detected_protocol(ndpi_struct, flow, cached_proto, __get_master(ndpi_struct, flow), NDPI_CONFIDENCE_DPI_CACHE);
flow->category = ndpi_get_proto_category(ndpi_struct, ret); flow->category = ndpi_get_proto_category(ndpi_struct, ret);
ndpi_check_subprotocol_risk(ndpi_struct, flow, cached_proto); ndpi_check_subprotocol_risk(ndpi_struct, flow, cached_proto);
ndpi_unset_risk(ndpi_struct, flow, NDPI_NUMERIC_IP_HOST); ndpi_unset_risk(flow, NDPI_NUMERIC_IP_HOST);
} }
} }
} }
@@ -450,7 +448,7 @@ void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct
char str[64]; char str[64];
snprintf(str, sizeof(str), "Invalid issuerDN %s", flow->protos.tls_quic.issuerDN); snprintf(str, sizeof(str), "Invalid issuerDN %s", flow->protos.tls_quic.issuerDN);
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, str); ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, str);
} }
} }
@@ -528,7 +526,7 @@ void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct
snprintf(str, sizeof(str), "TLS Cert lasts %u days", snprintf(str, sizeof(str), "TLS Cert lasts %u days",
(flow->protos.tls_quic.notAfter-flow->protos.tls_quic.notBefore) / 86400); (flow->protos.tls_quic.notAfter-flow->protos.tls_quic.notBefore) / 86400);
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_CERT_VALIDITY_TOO_LONG, str); /* Certificate validity longer than 13 months */ ndpi_set_risk(flow, NDPI_TLS_CERT_VALIDITY_TOO_LONG, str); /* Certificate validity longer than 13 months */
} }
if((time_sec < flow->protos.tls_quic.notBefore) || (time_sec > flow->protos.tls_quic.notAfter)) { if((time_sec < flow->protos.tls_quic.notBefore) || (time_sec > flow->protos.tls_quic.notAfter)) {
@@ -543,7 +541,7 @@ void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct
strftime(e, sizeof(e), "%d/%b/%Y %H:%M:%S", ndpi_gmtime_r(&theTime, &result)); strftime(e, sizeof(e), "%d/%b/%Y %H:%M:%S", ndpi_gmtime_r(&theTime, &result));
snprintf(str, sizeof(str), "%s - %s", b, e); snprintf(str, sizeof(str), "%s - %s", b, e);
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_CERTIFICATE_EXPIRED, str); /* Certificate expired */ ndpi_set_risk(flow, NDPI_TLS_CERTIFICATE_EXPIRED, str); /* Certificate expired */
} else if((time_sec > flow->protos.tls_quic.notBefore) } else if((time_sec > flow->protos.tls_quic.notBefore)
&& (time_sec > (flow->protos.tls_quic.notAfter - (ndpi_struct->cfg.tls_certificate_expire_in_x_days * 86400)))) { && (time_sec > (flow->protos.tls_quic.notAfter - (ndpi_struct->cfg.tls_certificate_expire_in_x_days * 86400)))) {
char str[96], b[32], e[32]; char str[96], b[32], e[32];
@@ -557,7 +555,7 @@ void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct
strftime(e, sizeof(e), "%d/%b/%Y %H:%M:%S", ndpi_gmtime_r(&theTime, &result)); strftime(e, sizeof(e), "%d/%b/%Y %H:%M:%S", ndpi_gmtime_r(&theTime, &result));
snprintf(str, sizeof(str), "%s - %s", b, e); snprintf(str, sizeof(str), "%s - %s", b, e);
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_CERTIFICATE_ABOUT_TO_EXPIRE, str); /* Certificate almost expired */ ndpi_set_risk(flow, NDPI_TLS_CERTIFICATE_ABOUT_TO_EXPIRE, str); /* Certificate almost expired */
} }
} }
} }
@@ -642,10 +640,10 @@ void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct
here that will create false positives here that will create false positives
*/ */
if(ndpi_normalize_printable_string(dNSName, dNSName_len) == 0) { if(ndpi_normalize_printable_string(dNSName, dNSName_len) == 0) {
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, dNSName); ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, dNSName);
/* This looks like an attack */ /* This looks like an attack */
ndpi_set_risk(ndpi_struct, flow, NDPI_POSSIBLE_EXPLOIT, NULL); ndpi_set_risk(flow, NDPI_POSSIBLE_EXPLOIT, NULL);
} }
if(matched_name == 0) { if(matched_name == 0) {
@@ -692,7 +690,7 @@ void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct
if(!flow->protos.tls_quic.subprotocol_detected) if(!flow->protos.tls_quic.subprotocol_detected)
if(ndpi_match_hostname_protocol(ndpi_struct, flow, __get_master(ndpi_struct, flow), dNSName, dNSName_len)) { if(ndpi_match_hostname_protocol(ndpi_struct, flow, __get_master(ndpi_struct, flow), dNSName, dNSName_len)) {
flow->protos.tls_quic.subprotocol_detected = 1; flow->protos.tls_quic.subprotocol_detected = 1;
ndpi_unset_risk(ndpi_struct, flow, NDPI_NUMERIC_IP_HOST); ndpi_unset_risk(flow, NDPI_NUMERIC_IP_HOST);
} }
i += len; i += len;
@@ -700,7 +698,7 @@ void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct
#if DEBUG_TLS #if DEBUG_TLS
printf("[TLS] Leftover %u bytes", packet->payload_packet_len - i); printf("[TLS] Leftover %u bytes", packet->payload_packet_len - i);
#endif #endif
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_SUSPICIOUS_EXTENSION, NULL); ndpi_set_risk(flow, NDPI_TLS_SUSPICIOUS_EXTENSION, NULL);
break; break;
} }
} else { } else {
@@ -712,7 +710,7 @@ void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct
char str[128]; char str[128];
snprintf(str, sizeof(str), "%s vs %s", flow->host_server_name, flow->protos.tls_quic.server_names); snprintf(str, sizeof(str), "%s vs %s", flow->host_server_name, flow->protos.tls_quic.server_names);
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_CERTIFICATE_MISMATCH, str); /* Certificate mismatch */ ndpi_set_risk(flow, NDPI_TLS_CERTIFICATE_MISMATCH, str); /* Certificate mismatch */
} }
} }
} }
@@ -737,7 +735,7 @@ void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct
ndpi_set_detected_protocol(ndpi_struct, flow, proto_id, __get_master(ndpi_struct, flow), NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, proto_id, __get_master(ndpi_struct, flow), NDPI_CONFIDENCE_DPI);
flow->category = ndpi_get_proto_category(ndpi_struct, ret); flow->category = ndpi_get_proto_category(ndpi_struct, ret);
ndpi_check_subprotocol_risk(ndpi_struct, flow, proto_id); ndpi_check_subprotocol_risk(ndpi_struct, flow, proto_id);
ndpi_unset_risk(ndpi_struct, flow, NDPI_NUMERIC_IP_HOST); ndpi_unset_risk(flow, NDPI_NUMERIC_IP_HOST);
if(ndpi_struct->tls_cert_cache) { if(ndpi_struct->tls_cert_cache) {
u_int64_t key = make_tls_cert_key(packet, 0 /* from the server */); u_int64_t key = make_tls_cert_key(packet, 0 /* from the server */);
@@ -754,7 +752,7 @@ void processCertificateElements(struct ndpi_detection_module_struct *ndpi_struct
if(ndpi_check_issuerdn_risk_exception(ndpi_struct, flow->protos.tls_quic.issuerDN)) if(ndpi_check_issuerdn_risk_exception(ndpi_struct, flow->protos.tls_quic.issuerDN))
return; /* This is a trusted DN */ return; /* This is a trusted DN */
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_SELFSIGNED_CERTIFICATE, flow->protos.tls_quic.subjectDN); ndpi_set_risk(flow, NDPI_TLS_SELFSIGNED_CERTIFICATE, flow->protos.tls_quic.subjectDN);
} }
#if DEBUG_TLS #if DEBUG_TLS
@@ -783,7 +781,7 @@ int processCertificate(struct ndpi_detection_module_struct *ndpi_struct,
if((packet->payload_packet_len != (length + 4 + (is_dtls ? 8 : 0))) || (packet->payload[1] != 0x0) || if((packet->payload_packet_len != (length + 4 + (is_dtls ? 8 : 0))) || (packet->payload[1] != 0x0) ||
certificates_offset >= packet->payload_packet_len) { certificates_offset >= packet->payload_packet_len) {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, NULL); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, NULL);
return(-1); /* Invalid length */ return(-1); /* Invalid length */
} }
@@ -792,7 +790,7 @@ int processCertificate(struct ndpi_detection_module_struct *ndpi_struct,
packet->payload[certificates_offset - 1]; packet->payload[certificates_offset - 1];
if((packet->payload[certificates_offset - 3] != 0x0) || ((certificates_length+3) != length)) { if((packet->payload[certificates_offset - 3] != 0x0) || ((certificates_length+3) != length)) {
ndpi_set_risk(ndpi_struct, flow, NDPI_MALFORMED_PACKET, NULL); ndpi_set_risk(flow, NDPI_MALFORMED_PACKET, NULL);
return(-2); /* Invalid length */ return(-2); /* Invalid length */
} }
@@ -869,7 +867,7 @@ int processCertificate(struct ndpi_detection_module_struct *ndpi_struct,
u_int16_t rc1 = ndpi_hash_find_entry(ndpi_struct->malicious_sha1_hashmap, sha1_str, sha1_siz * 2, NULL); u_int16_t rc1 = ndpi_hash_find_entry(ndpi_struct->malicious_sha1_hashmap, sha1_str, sha1_siz * 2, NULL);
if(rc1 == 0) if(rc1 == 0)
ndpi_set_risk(ndpi_struct, flow, NDPI_MALICIOUS_SHA1_CERTIFICATE, sha1_str); ndpi_set_risk(flow, NDPI_MALICIOUS_SHA1_CERTIFICATE, sha1_str);
} }
} }
@@ -987,7 +985,7 @@ static int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
} }
message = &flow->tls_quic.message[packet->packet_direction]; message = &flow->tls_quic.message[packet->packet_direction];
if(ndpi_search_tls_memory(ndpi_struct, flow, packet->payload, if(ndpi_search_tls_memory(packet->payload,
packet->payload_packet_len, ntohl(packet->tcp->seq), packet->payload_packet_len, ntohl(packet->tcp->seq),
message) == -1) message) == -1)
return 0; /* Error -> stop */ return 0; /* Error -> stop */
@@ -1058,7 +1056,7 @@ static int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
u_int8_t alert_level = message->buffer[5]; u_int8_t alert_level = message->buffer[5];
if(alert_level == 2 /* Warning (1), Fatal (2) */) if(alert_level == 2 /* Warning (1), Fatal (2) */)
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_FATAL_ALERT, NULL); ndpi_set_risk(flow, NDPI_TLS_FATAL_ALERT, NULL);
} }
u_int16_t const alert_len = ntohs(*(u_int16_t const *)&message->buffer[3]); u_int16_t const alert_len = ntohs(*(u_int16_t const *)&message->buffer[3]);
@@ -1176,7 +1174,7 @@ static int ndpi_search_tls_tcp(struct ndpi_detection_module_struct *ndpi_struct,
suited than NDPI_CONFIDENCE_DPI_CACHE */ suited than NDPI_CONFIDENCE_DPI_CACHE */
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_TLS, NDPI_CONFIDENCE_DPI_AGGRESSIVE); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_OOKLA, NDPI_PROTOCOL_TLS, NDPI_CONFIDENCE_DPI_AGGRESSIVE);
/* TLS over port 8080 usually triggers that risk; clear it */ /* TLS over port 8080 usually triggers that risk; clear it */
ndpi_unset_risk(ndpi_struct, flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT); ndpi_unset_risk(flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT);
flow->extra_packets_func = NULL; flow->extra_packets_func = NULL;
return(0); /* That's all */ return(0); /* That's all */
} else { } else {
@@ -1286,11 +1284,11 @@ static int ndpi_search_tls_udp(struct ndpi_detection_module_struct *ndpi_struct,
} }
if(handshake_frag_off == 0) { if(handshake_frag_off == 0) {
rc = ndpi_search_tls_memory(ndpi_struct, flow, &block[13], rc = ndpi_search_tls_memory(&block[13],
handshake_frag_len + 12, handshake_frag_len + 12,
handshake_frag_off, message); handshake_frag_off, message);
} else { } else {
rc = ndpi_search_tls_memory(ndpi_struct, flow, &block[13 + 12], rc = ndpi_search_tls_memory(&block[13 + 12],
handshake_frag_len, handshake_frag_len,
handshake_frag_off + 12, message); handshake_frag_off + 12, message);
} }
@@ -1472,7 +1470,7 @@ static void tlsCheckUncommonALPN(struct ndpi_detection_module_struct *ndpi_struc
str[str_len - 1] = '\0'; str[str_len - 1] = '\0';
} }
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_UNCOMMON_ALPN, str); ndpi_set_risk(flow, NDPI_TLS_UNCOMMON_ALPN, str);
break; break;
} }
@@ -1518,7 +1516,7 @@ static void checkExtensions(struct ndpi_detection_module_struct *ndpi_struct,
printf("[TLS] extension length exceeds remaining packet length: %u > %u.\n", printf("[TLS] extension length exceeds remaining packet length: %u > %u.\n",
extension_len, packet->payload_packet_len - extension_payload_offset); extension_len, packet->payload_packet_len - extension_payload_offset);
#endif #endif
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_SUSPICIOUS_EXTENSION, NULL); ndpi_set_risk(flow, NDPI_TLS_SUSPICIOUS_EXTENSION, NULL);
return; return;
} }
@@ -1560,7 +1558,7 @@ static void checkExtensions(struct ndpi_detection_module_struct *ndpi_struct,
#ifdef DEBUG_TLS #ifdef DEBUG_TLS
printf("[TLS] suspicious extension id: %u\n", extension_id); printf("[TLS] suspicious extension id: %u\n", extension_id);
#endif #endif
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_SUSPICIOUS_EXTENSION, str); ndpi_set_risk(flow, NDPI_TLS_SUSPICIOUS_EXTENSION, str);
return; return;
} }
} }
@@ -1577,7 +1575,7 @@ static void checkExtensions(struct ndpi_detection_module_struct *ndpi_struct,
#ifdef DEBUG_TLS #ifdef DEBUG_TLS
printf("[TLS] suspicious DTLS-only extension id: %u\n", extension_id); printf("[TLS] suspicious DTLS-only extension id: %u\n", extension_id);
#endif #endif
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_SUSPICIOUS_EXTENSION, str); ndpi_set_risk(flow, NDPI_TLS_SUSPICIOUS_EXTENSION, str);
return; return;
} }
} }
@@ -1601,8 +1599,7 @@ static int u_int16_t_cmpfunc(const void * a, const void * b) { return(*(u_int16_
/* **************************************** */ /* **************************************** */
static void ndpi_compute_ja4(struct ndpi_detection_module_struct *ndpi_struct, static void ndpi_compute_ja4(struct ndpi_flow_struct *flow,
struct ndpi_flow_struct *flow,
u_int32_t quic_version, u_int32_t quic_version,
union ja_info *ja) { union ja_info *ja) {
u_int8_t tmp_str[JA_STR_LEN]; u_int8_t tmp_str[JA_STR_LEN];
@@ -1680,7 +1677,7 @@ static void ndpi_compute_ja4(struct ndpi_detection_module_struct *ndpi_struct,
break; break;
} }
ja_str[3] = ndpi_isset_risk(ndpi_struct, flow, NDPI_NUMERIC_IP_HOST) ? 'i' : 'd', ja_str_len = 4; ja_str[3] = ndpi_isset_risk(flow, NDPI_NUMERIC_IP_HOST) ? 'i' : 'd', ja_str_len = 4;
/* JA4_a */ /* JA4_a */
rc = ndpi_snprintf(&ja_str[ja_str_len], ja_max_len - ja_str_len, "%02u%02u%c%c_", rc = ndpi_snprintf(&ja_str[ja_str_len], ja_max_len - ja_str_len, "%02u%02u%c%c_",
@@ -1827,7 +1824,7 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
char unknown_cipher[8]; char unknown_cipher[8];
snprintf(str, sizeof(str), "Cipher %s", ndpi_cipher2str(ja.server.cipher[0], unknown_cipher)); snprintf(str, sizeof(str), "Cipher %s", ndpi_cipher2str(ja.server.cipher[0], unknown_cipher));
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_WEAK_CIPHER, str); ndpi_set_risk(flow, NDPI_TLS_WEAK_CIPHER, str);
} }
flow->protos.tls_quic.server_cipher = ja.server.cipher[0]; flow->protos.tls_quic.server_cipher = ja.server.cipher[0];
@@ -1916,12 +1913,12 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
s_offset += alpn_len, alpn_str_len += alpn_len;; s_offset += alpn_len, alpn_str_len += alpn_len;;
} else { } else {
alpn_str[alpn_str_len] = '\0'; alpn_str[alpn_str_len] = '\0';
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_UNCOMMON_ALPN, alpn_str); ndpi_set_risk(flow, NDPI_TLS_UNCOMMON_ALPN, alpn_str);
break; break;
} }
} else { } else {
alpn_str[alpn_str_len] = '\0'; alpn_str[alpn_str_len] = '\0';
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_UNCOMMON_ALPN, alpn_str); ndpi_set_risk(flow, NDPI_TLS_UNCOMMON_ALPN, alpn_str);
break; break;
} }
} /* while */ } /* while */
@@ -1932,7 +1929,7 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
printf("Server TLS [ALPN: %s][len: %u]\n", alpn_str, alpn_str_len); printf("Server TLS [ALPN: %s][len: %u]\n", alpn_str, alpn_str_len);
#endif #endif
if(ndpi_normalize_printable_string(alpn_str, alpn_str_len) == 0) if(ndpi_normalize_printable_string(alpn_str, alpn_str_len) == 0)
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, alpn_str); ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, alpn_str);
if(flow->protos.tls_quic.negotiated_alpn == NULL) if(flow->protos.tls_quic.negotiated_alpn == NULL)
flow->protos.tls_quic.negotiated_alpn = ndpi_strdup(alpn_str); flow->protos.tls_quic.negotiated_alpn = ndpi_strdup(alpn_str);
@@ -2055,7 +2052,7 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
snprintf(str, sizeof(str), "%s", ndpi_ssl_version2str(buf, sizeof(buf), snprintf(str, sizeof(str), "%s", ndpi_ssl_version2str(buf, sizeof(buf),
flow->protos.tls_quic.ssl_version, flow->protos.tls_quic.ssl_version,
&unknown_tls_version)); &unknown_tls_version));
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_OBSOLETE_VERSION, str); ndpi_set_risk(flow, NDPI_TLS_OBSOLETE_VERSION, str);
} }
if((session_id_len+base_offset+3) > packet->payload_packet_len) if((session_id_len+base_offset+3) > packet->payload_packet_len)
@@ -2264,10 +2261,10 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
printf("[TLS] SNI: [%s]\n", sni); printf("[TLS] SNI: [%s]\n", sni);
#endif #endif
if(ndpi_is_valid_hostname((char *)&packet->payload[offset+extension_offset+5], len) == 0) { if(ndpi_is_valid_hostname((char *)&packet->payload[offset+extension_offset+5], len) == 0) {
ndpi_set_risk(ndpi_struct, flow, NDPI_INVALID_CHARACTERS, sni); ndpi_set_risk(flow, NDPI_INVALID_CHARACTERS, sni);
/* This looks like an attack */ /* This looks like an attack */
ndpi_set_risk(ndpi_struct, flow, NDPI_POSSIBLE_EXPLOIT, NULL); ndpi_set_risk(flow, NDPI_POSSIBLE_EXPLOIT, NULL);
} }
if(!is_quic) { if(!is_quic) {
@@ -2280,7 +2277,7 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
if((flow->protos.tls_quic.subprotocol_detected == 0) if((flow->protos.tls_quic.subprotocol_detected == 0)
&& (check_sni_is_numeric_ip(sni) == 1)) { && (check_sni_is_numeric_ip(sni) == 1)) {
ndpi_set_risk(ndpi_struct, flow, NDPI_NUMERIC_IP_HOST, sni); ndpi_set_risk(flow, NDPI_NUMERIC_IP_HOST, sni);
} }
if(ndpi_check_dga_name(ndpi_struct, flow, sni, 1, 0)) { if(ndpi_check_dga_name(ndpi_struct, flow, sni, 1, 0)) {
@@ -2733,8 +2730,7 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
#ifdef DEBUG_TLS #ifdef DEBUG_TLS
printf("UA [%.*s]\n", (int)param_len, &packet->payload[s_offset]); printf("UA [%.*s]\n", (int)param_len, &packet->payload[s_offset]);
#endif #endif
http_process_user_agent(ndpi_struct, flow, http_process_user_agent(ndpi_struct, flow, &packet->payload[s_offset], param_len);
&packet->payload[s_offset], param_len);
break; break;
} }
s_offset += param_len; s_offset += param_len;
@@ -2820,12 +2816,12 @@ compute_ja3c:
NULL); NULL);
if(rc1 == 0) if(rc1 == 0)
ndpi_set_risk(ndpi_struct, flow, NDPI_MALICIOUS_JA3, flow->protos.tls_quic.ja3_client); ndpi_set_risk(flow, NDPI_MALICIOUS_JA3, flow->protos.tls_quic.ja3_client);
} }
} }
if(ndpi_struct->cfg.tls_ja4c_fingerprint_enabled) { if(ndpi_struct->cfg.tls_ja4c_fingerprint_enabled) {
ndpi_compute_ja4(ndpi_struct, flow, quic_version, &ja); ndpi_compute_ja4(flow, quic_version, &ja);
} }
/* End JA3/JA4 */ /* End JA3/JA4 */
} }
@@ -2834,14 +2830,14 @@ compute_ja3c:
if((flow->protos.tls_quic.ssl_version >= 0x0303) /* >= TLSv1.2 */ if((flow->protos.tls_quic.ssl_version >= 0x0303) /* >= TLSv1.2 */
&& !(flow->stun.maybe_dtls == 1 && is_dtls && use_srtp) /* Webrtc traffic */ && !(flow->stun.maybe_dtls == 1 && is_dtls && use_srtp) /* Webrtc traffic */
&& (flow->protos.tls_quic.advertised_alpns == NULL) /* No ALPN */) { && (flow->protos.tls_quic.advertised_alpns == NULL) /* No ALPN */) {
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_NOT_CARRYING_HTTPS, "No ALPN"); ndpi_set_risk(flow, NDPI_TLS_NOT_CARRYING_HTTPS, "No ALPN");
} }
/* Suspicious Domain Fronting: /* Suspicious Domain Fronting:
https://github.com/SixGenInc/Noctilucent/blob/master/docs/ */ https://github.com/SixGenInc/Noctilucent/blob/master/docs/ */
if(flow->protos.tls_quic.encrypted_sni.esni && if(flow->protos.tls_quic.encrypted_sni.esni &&
flow->host_server_name[0] != '\0') { flow->host_server_name[0] != '\0') {
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_SUSPICIOUS_ESNI_USAGE, "Found ESNI w/o SNI"); ndpi_set_risk(flow, NDPI_TLS_SUSPICIOUS_ESNI_USAGE, "Found ESNI w/o SNI");
} }
/* Add check for missing SNI */ /* Add check for missing SNI */
@@ -2851,7 +2847,7 @@ compute_ja3c:
&& (flow->protos.tls_quic.encrypted_sni.esni == NULL) /* No ESNI */ && (flow->protos.tls_quic.encrypted_sni.esni == NULL) /* No ESNI */
) { ) {
/* This is a bit suspicious */ /* This is a bit suspicious */
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_MISSING_SNI, NULL); ndpi_set_risk(flow, NDPI_TLS_MISSING_SNI, NULL);
if(flow->protos.tls_quic.advertised_alpns != NULL) { if(flow->protos.tls_quic.advertised_alpns != NULL) {
char buf[256], *tmp, *item; char buf[256], *tmp, *item;
@@ -2863,7 +2859,7 @@ compute_ja3c:
while(item != NULL) { while(item != NULL) {
if(item[0] == 'h') { if(item[0] == 'h') {
/* Example 'h2' */ /* Example 'h2' */
ndpi_set_risk(ndpi_struct, flow, NDPI_TLS_ALPN_SNI_MISMATCH, NULL); ndpi_set_risk(flow, NDPI_TLS_ALPN_SNI_MISMATCH, NULL);
break; break;
} else } else
item = strtok_r(NULL, ",", &tmp); item = strtok_r(NULL, ",", &tmp);
+1 -1
View File
@@ -52,7 +52,7 @@ static void ndpi_search_vnc_tcp(struct ndpi_detection_module_struct *ndpi_struct
((memcmp(packet->payload, "RFB 004.", 7) == 0) && (packet->payload[11] == 0x0a)))) { ((memcmp(packet->payload, "RFB 004.", 7) == 0) && (packet->payload[11] == 0x0a)))) {
NDPI_LOG_INFO(ndpi_struct, "found vnc\n"); NDPI_LOG_INFO(ndpi_struct, "found vnc\n");
ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_VNC, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI); ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_VNC, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
ndpi_set_risk(ndpi_struct, flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found VNC"); /* Remote assistance */ ndpi_set_risk(flow, NDPI_DESKTOP_OR_FILE_SHARING_SESSION, "Found VNC"); /* Remote assistance */
return; return;
} }
} }
+1 -2
View File
@@ -35,7 +35,6 @@ static void ndpi_int_z3950_add_connection(struct ndpi_detection_module_struct *n
/* ***************************************************************** */ /* ***************************************************************** */
static int z3950_parse_sequences(struct ndpi_packet_struct const * const packet, static int z3950_parse_sequences(struct ndpi_packet_struct const * const packet,
struct ndpi_flow_struct *flow,
int max_sequences) { int max_sequences) {
size_t payload_offset = 2; size_t payload_offset = 2;
int cur_sequences = 0; int cur_sequences = 0;
@@ -92,7 +91,7 @@ static void ndpi_search_z3950(struct ndpi_detection_module_struct *ndpi_struct,
if(packet->tcp != NULL && packet->payload_packet_len >= 6 && if(packet->tcp != NULL && packet->payload_packet_len >= 6 &&
flow->packet_counter >= 1 && flow->packet_counter <= 8) { flow->packet_counter >= 1 && flow->packet_counter <= 8) {
int ret = z3950_parse_sequences(packet, flow, minimum_expected_sequences); int ret = z3950_parse_sequences(packet, minimum_expected_sequences);
if(ret < 0) { if(ret < 0) {
NDPI_EXCLUDE_PROTO(ndpi_struct, flow); NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
+2 -2
View File
@@ -34,7 +34,7 @@ __mingw_forceinline static
#else #else
__forceinline static __forceinline static
#endif #endif
u_int8_t ndpi_int_zattoo_user_agent_set(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow) u_int8_t ndpi_int_zattoo_user_agent_set(struct ndpi_detection_module_struct *ndpi_struct)
{ {
struct ndpi_packet_struct *packet = &ndpi_struct->packet; struct ndpi_packet_struct *packet = &ndpi_struct->packet;
@@ -90,7 +90,7 @@ static void ndpi_search_zattoo(struct ndpi_detection_module_struct *ndpi_struct,
* that might be changed later */ * that might be changed later */
ndpi_parse_packet_line_info(ndpi_struct, flow); ndpi_parse_packet_line_info(ndpi_struct, flow);
if(ndpi_int_zattoo_user_agent_set(ndpi_struct, flow)) { if(ndpi_int_zattoo_user_agent_set(ndpi_struct)) {
NDPI_LOG_INFO(ndpi_struct, "found zattoo. add connection over tcp with pattern GET / or POST /\n"); NDPI_LOG_INFO(ndpi_struct, "found zattoo. add connection over tcp with pattern GET / or POST /\n");
ZATTOO_DETECTED; ZATTOO_DETECTED;
+1
View File
@@ -51,6 +51,7 @@ static void ndpi_dbg_fn(u_int32_t protocol,
/* While this program always logs at NDPI_LOG_DEBUG_EXTRA level, the /* While this program always logs at NDPI_LOG_DEBUG_EXTRA level, the
initialization of the library may log at any level */ initialization of the library may log at any level */
(void)log_level;
(void)file; (void)file;
(void)func; (void)func;
(void)line; (void)line;
+3
View File
@@ -366,6 +366,9 @@ int main(int argc, char **argv) {
#ifndef WIN32 #ifndef WIN32
int c; int c;
#endif #endif
(void)argc;
(void)argv;
NDPI_PROTOCOL_BITMASK all; NDPI_PROTOCOL_BITMASK all;
if (ndpi_get_api_version() != NDPI_API_VERSION) { if (ndpi_get_api_version() != NDPI_API_VERSION) {