Skip to content

Commit

Permalink
TLS: add basic, basic, detection of Encrypted ClientHello (#2053)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanNardi authored Jul 21, 2023
1 parent fa0bd51 commit c85f2fb
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions example/ndpiReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,10 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
ndpi_cipher2str(flow->ssh_tls.encrypted_sni.cipher_suite, unknown_cipher));
}

if(flow->ssh_tls.encrypted_ch.version != 0) {
fprintf(out, "[ECH: version 0x%x]", flow->ssh_tls.encrypted_ch.version);
}

if(flow->ssh_tls.sha1_cert_fingerprint_set) {
fprintf(out, "[Certificate SHA-1: ");
for(i=0; i<20; i++)
Expand Down
2 changes: 2 additions & 0 deletions example/reader_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,8 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
flow->ssh_tls.encrypted_sni.cipher_suite = flow->ndpi_flow->protos.tls_quic.encrypted_sni.cipher_suite;
}

flow->ssh_tls.encrypted_ch.version = flow->ndpi_flow->protos.tls_quic.encrypted_ch.version;

if(flow->ndpi_flow->protos.tls_quic.tls_supported_versions) {
if((flow->ssh_tls.tls_supported_versions = ndpi_strdup(flow->ndpi_flow->protos.tls_quic.tls_supported_versions)) != NULL)
correct_csv_data_field(flow->ssh_tls.tls_supported_versions);
Expand Down
4 changes: 4 additions & 0 deletions example/reader_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ typedef struct ndpi_flow_info {
char *esni;
} encrypted_sni;

struct {
u_int16_t version;
} encrypted_ch;

time_t notBefore, notAfter;
u_int16_t server_cipher;
ndpi_cipher_weakness client_unsafe_cipher, server_unsafe_cipher;
Expand Down
5 changes: 5 additions & 0 deletions src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,11 @@ struct ndpi_flow_struct {
u_int16_t cipher_suite;
char *esni;
} encrypted_sni;

struct {
u_int16_t version;
} encrypted_ch;

ndpi_cipher_weakness server_unsafe_cipher;
} tls_quic; /* Used also by DTLS and POPS/IMAPS/SMTPS/FTPS */

Expand Down
11 changes: 10 additions & 1 deletion src/lib/protocols/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,9 @@ static void checkExtensions(struct ndpi_detection_module_struct *ndpi_struct,
/* Groups */
1035, 10794, 16696, 23130, 31354, 35466, 51914,
/* Ciphers */
102, 129, 52243, 52244, 57363, 65279, 65413
102, 129, 52243, 52244, 57363, 65279, 65413,
/* ECH */
65037
};
size_t const allowed_non_iana_extensions_size = sizeof(allowed_non_iana_extensions) /
sizeof(allowed_non_iana_extensions[0]);
Expand Down Expand Up @@ -2537,6 +2539,13 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
}
}
}
} else if(extension_id == 65037 /* ECH: latest drafts */) {
#ifdef DEBUG_TLS
printf("Client TLS: ECH version 0x%x\n", extension_id;
#endif
/* Beginning with draft-08, the version is the same as the code point
for the "encrypted_client_hello" extension. */
flow->protos.tls_quic.encrypted_ch.version = extension_id;
} else if(extension_id == 65445 || /* QUIC transport parameters (drafts version) */
extension_id == 57) { /* QUIC transport parameters (final version) */
u_int16_t s_offset = offset+extension_offset;
Expand Down
Binary file added tests/cfgs/default/pcap/tls_ech.pcapng
Binary file not shown.
30 changes: 30 additions & 0 deletions tests/cfgs/default/result/tls_ech.pcapng.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Guessed flow protos: 0

DPI Packets (TCP): 6 (6.00 pkts/flow)
Confidence DPI : 1 (flows)
Num dissector calls: 1 (1.00 diss/flow)
LRU cache ookla: 0/0/0 (insert/search/found)
LRU cache bittorrent: 0/0/0 (insert/search/found)
LRU cache zoom: 0/0/0 (insert/search/found)
LRU cache stun: 0/0/0 (insert/search/found)
LRU cache tls_cert: 0/0/0 (insert/search/found)
LRU cache mining: 0/0/0 (insert/search/found)
LRU cache msteams: 0/0/0 (insert/search/found)
LRU cache stun_zoom: 0/0/0 (insert/search/found)
Automa host: 1/1 (search/found)
Automa domain: 1/0 (search/found)
Automa tls cert: 0/0 (search/found)
Automa risk mask: 0/0 (search/found)
Automa common alpns: 2/2 (search/found)
Patricia risk mask: 0/0 (search/found)
Patricia risk: 0/0 (search/found)
Patricia protocols: 0/0 (search/found)

Cloudflare 10 4226 1

JA3 Host Stats:
IP Address # JA3C
1 2001:b07:a3d:c112:ce16:b409:3d0a:9177 1


1 TCP [2001:b07:a3d:c112:ce16:b409:3d0a:9177]:47460 <-> [2606:4700::6812:1e4e]:443 [proto: 91.220/TLS.Cloudflare][IP: 0/Unknown][Encrypted][Confidence: DPI][DPI packets: 6][cat: Web/5][6 pkts/1172 bytes <-> 4 pkts/3054 bytes][Goodput ratio: 55/88][0.07 sec][Hostname/SNI: performance.radar.cloudflare.com][(Advertised) ALPNs: h2;http/1.1][TLS Supported Versions: GREASE;TLSv1.3;TLSv1.2][bytes ratio: -0.445 (Download)][IAT c2s/s2c min/avg/max/stddev: 0/3 13/5 49/7 18/2][Pkt Len c2s/s2c min/avg/max/stddev: 86/86 195/764 670/2260 213/890][TLSv1.3][JA3C: 6820f114cf3b0809ffdcb30cb277848a][JA3S: eb1d94daa7e0344597e756a1fb6e7054][ECH: version 0xfe0d][Chrome][Cipher: TLS_AES_128_GCM_SHA256][Plen Bins: 0,0,25,0,0,0,0,0,0,0,0,0,0,0,0,0,25,0,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25]

0 comments on commit c85f2fb

Please sign in to comment.