|
60 | 60 | #define TH_PUSH 0x08
|
61 | 61 | #define TH_ACK 0x10
|
62 | 62 | #define TH_URG 0x20
|
| 63 | +#define TH_ECE 0x40 |
| 64 | +#define TH_CWR 0x80 |
63 | 65 | #endif
|
64 | 66 |
|
65 | 67 | #if defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__
|
@@ -4400,7 +4402,7 @@ void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_str) {
|
4400 | 4402 |
|
4401 | 4403 | if(ndpi_str->address_cache)
|
4402 | 4404 | ndpi_term_address_cache(ndpi_str->address_cache);
|
4403 |
| - |
| 4405 | + |
4404 | 4406 | ndpi_free(ndpi_str);
|
4405 | 4407 | }
|
4406 | 4408 |
|
@@ -4794,7 +4796,7 @@ static int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_str,
|
4794 | 4796 | def = NULL;
|
4795 | 4797 | else
|
4796 | 4798 | def = &ndpi_str->proto_defaults[subprotocol_id];
|
4797 |
| - |
| 4799 | + |
4798 | 4800 | if(def == NULL) {
|
4799 | 4801 | ndpi_port_range ports_a[MAX_DEFAULT_PORTS], ports_b[MAX_DEFAULT_PORTS];
|
4800 | 4802 | char *equal = strchr(proto, '=');
|
@@ -6724,6 +6726,9 @@ void ndpi_free_flow_data(struct ndpi_flow_struct* flow) {
|
6724 | 6726 | ndpi_free(flow->risk_infos[i].info);
|
6725 | 6727 | }
|
6726 | 6728 |
|
| 6729 | + if(flow->tcp.fingerprint) |
| 6730 | + ndpi_free(flow->tcp.fingerprint); |
| 6731 | + |
6727 | 6732 | if(flow->http.url)
|
6728 | 6733 | ndpi_free(flow->http.url);
|
6729 | 6734 |
|
@@ -6904,14 +6909,86 @@ static int ndpi_init_packet(struct ndpi_detection_module_struct *ndpi_str,
|
6904 | 6909 |
|
6905 | 6910 | /* TCP / UDP detection */
|
6906 | 6911 | if(l4protocol == IPPROTO_TCP) {
|
| 6912 | + u_int16_t header_len; |
| 6913 | + |
6907 | 6914 | if(l4_packet_len < 20 /* min size of tcp */)
|
6908 | 6915 | return(1);
|
6909 | 6916 |
|
6910 | 6917 | /* tcp */
|
6911 | 6918 | packet->tcp = (struct ndpi_tcphdr *) l4ptr;
|
6912 |
| - if(l4_packet_len >= packet->tcp->doff * 4) { |
6913 |
| - packet->payload_packet_len = l4_packet_len - packet->tcp->doff * 4; |
6914 |
| - packet->payload = ((u_int8_t *) packet->tcp) + (packet->tcp->doff * 4); |
| 6919 | + header_len = packet->tcp->doff * 4; |
| 6920 | + |
| 6921 | + if(l4_packet_len >= header_len) { |
| 6922 | + if(flow->tcp.fingerprint == NULL) { |
| 6923 | + u_int8_t *t = (u_int8_t*)packet->tcp; |
| 6924 | + u_int16_t flags = ntohs(*((u_int16_t*)&t[12])); |
| 6925 | + |
| 6926 | + if((flags & (TH_SYN | TH_ECE | TH_CWR)) == TH_SYN) { |
| 6927 | + u_int8_t *options = (u_int8_t*)(&t[sizeof(struct ndpi_tcphdr)]); |
| 6928 | + char fingerprint[128], options_fp[128]; |
| 6929 | + u_int8_t i, fp_idx = 0, options_fp_idx = 0; |
| 6930 | + u_int8_t options_len = header_len - sizeof(struct ndpi_tcphdr); |
| 6931 | + u_int16_t tcp_win = ntohs(packet->tcp->window); |
| 6932 | + u_int8_t ip_ttl; |
| 6933 | + u_int8_t sha_hash[NDPI_SHA256_BLOCK_SIZE]; |
| 6934 | + |
| 6935 | + if(packet->iph) |
| 6936 | + ip_ttl = packet->iph->ttl; |
| 6937 | + else |
| 6938 | + ip_ttl = packet->iphv6->ip6_hdr.ip6_un1_hlim; |
| 6939 | + |
| 6940 | + if(ip_ttl <= 32) ip_ttl = 32; |
| 6941 | + else if(ip_ttl <= 64) ip_ttl = 64; |
| 6942 | + else if(ip_ttl <= 128) ip_ttl = 128; |
| 6943 | + else if(ip_ttl <= 192) ip_ttl = 192; |
| 6944 | + else ip_ttl = 255; |
| 6945 | + |
| 6946 | + fp_idx = snprintf(fingerprint, sizeof(fingerprint), "%u_%u_", ip_ttl, tcp_win); |
| 6947 | + |
| 6948 | + for(i=0; i<options_len; ) { |
| 6949 | + u_int8_t kind = options[i]; |
| 6950 | + int rc; |
| 6951 | + |
| 6952 | + rc = snprintf(&options_fp[options_fp_idx], sizeof(options_fp)-options_fp_idx, "%02x", kind); |
| 6953 | + options_fp_idx += rc; |
| 6954 | + |
| 6955 | + if(kind == 0) /* EOF */ |
| 6956 | + break; |
| 6957 | + else if(kind == 1) /* NOP */ |
| 6958 | + i++; |
| 6959 | + else { |
| 6960 | + u_int8_t len = options[i+1]; |
| 6961 | + |
| 6962 | + if(len == 0) |
| 6963 | + break; |
| 6964 | + else if(kind == 8) { |
| 6965 | + /* Timestamp: ignore it */ |
| 6966 | + } else { |
| 6967 | + int j = i+2; |
| 6968 | + u_int8_t opt_len = len - 2; |
| 6969 | + |
| 6970 | + while(opt_len > 0) { |
| 6971 | + rc = snprintf(&options_fp[options_fp_idx], sizeof(options_fp)-options_fp_idx, "%02x", options[j]); |
| 6972 | + options_fp_idx += rc; |
| 6973 | + j++, opt_len--; |
| 6974 | + } |
| 6975 | + } |
| 6976 | + |
| 6977 | + i += len; |
| 6978 | + } |
| 6979 | + } /* for */ |
| 6980 | + |
| 6981 | + ndpi_sha256((const u_char*)options_fp, options_fp_idx, sha_hash); |
| 6982 | + snprintf(&fingerprint[fp_idx], sizeof(fingerprint)-fp_idx, "%02x%02x%02x%02x%02x%02x", |
| 6983 | + sha_hash[0], sha_hash[1], sha_hash[2], |
| 6984 | + sha_hash[3], sha_hash[4], sha_hash[5]); |
| 6985 | + |
| 6986 | + flow->tcp.fingerprint = ndpi_strdup(fingerprint); |
| 6987 | + } |
| 6988 | + } |
| 6989 | + |
| 6990 | + packet->payload_packet_len = l4_packet_len - header_len; |
| 6991 | + packet->payload = ((u_int8_t *) packet->tcp) + header_len; |
6915 | 6992 | } else {
|
6916 | 6993 | /* tcp header not complete */
|
6917 | 6994 | return(1);
|
@@ -7546,7 +7623,7 @@ static void ndpi_reconcile_msteams_udp(struct ndpi_detection_module_struct *ndpi
|
7546 | 7623 | struct ndpi_flow_struct *flow,
|
7547 | 7624 | u_int16_t master) {
|
7548 | 7625 | /* This function can NOT access &ndpi_str->packet since it is called also from ndpi_detection_giveup(), via ndpi_reconcile_protocols() */
|
7549 |
| - |
| 7626 | + |
7550 | 7627 | if(flow->l4_proto == IPPROTO_UDP) {
|
7551 | 7628 | u_int16_t sport = ntohs(flow->c_port);
|
7552 | 7629 | u_int16_t dport = ntohs(flow->s_port);
|
@@ -7694,7 +7771,7 @@ static void ndpi_reconcile_protocols(struct ndpi_detection_module_struct *ndpi_s
|
7694 | 7771 | NDPI_CONFIDENCE_DPI_PARTIAL);
|
7695 | 7772 | }
|
7696 | 7773 | break;
|
7697 |
| - |
| 7774 | + |
7698 | 7775 | case NDPI_PROTOCOL_SKYPE_TEAMS:
|
7699 | 7776 | case NDPI_PROTOCOL_SKYPE_TEAMS_CALL:
|
7700 | 7777 | if(flow->l4_proto == IPPROTO_UDP && ndpi_str->msteams_cache) {
|
@@ -9066,8 +9143,7 @@ struct header_line {
|
9066 | 9143 | struct ndpi_int_one_line_struct *line;
|
9067 | 9144 | };
|
9068 | 9145 |
|
9069 |
| -static void parse_single_packet_line(struct ndpi_detection_module_struct *ndpi_str) |
9070 |
| -{ |
| 9146 | +static void parse_single_packet_line(struct ndpi_detection_module_struct *ndpi_str) { |
9071 | 9147 | struct ndpi_packet_struct *packet = &ndpi_str->packet;
|
9072 | 9148 | struct ndpi_int_one_line_struct *line;
|
9073 | 9149 | size_t length;
|
@@ -11366,7 +11442,7 @@ static const struct cfg_param {
|
11366 | 11442 | { "tls", "subclassification", "enable", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(tls_subclassification_enabled), NULL },
|
11367 | 11443 |
|
11368 | 11444 | { "quic", "subclassification", "enable", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(quic_subclassification_enabled), NULL },
|
11369 |
| - |
| 11445 | + |
11370 | 11446 | { "smtp", "tls_dissection", "enable", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(smtp_opportunistic_tls_enabled), NULL },
|
11371 | 11447 |
|
11372 | 11448 | { "imap", "tls_dissection", "enable", NULL, NULL, CFG_PARAM_ENABLE_DISABLE, __OFF(imap_opportunistic_tls_enabled), NULL },
|
|
0 commit comments