Initial work towards detection via TLS of browser types
This commit is contained in:
@@ -1474,6 +1474,11 @@ static void printFlow(u_int16_t id, struct ndpi_flow_info *flow, u_int16_t threa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef EURISTICS_CODE
|
||||||
|
if(flow->ssh_tls.browser_euristics.is_safari_tls) fprintf(out, "[Safari]");
|
||||||
|
if(flow->ssh_tls.browser_euristics.is_firefox_tls) fprintf(out, "[Firefox]");
|
||||||
|
#endif
|
||||||
|
|
||||||
if(flow->ssh_tls.notBefore && flow->ssh_tls.notAfter) {
|
if(flow->ssh_tls.notBefore && flow->ssh_tls.notAfter) {
|
||||||
char notBefore[32], notAfter[32];
|
char notBefore[32], notAfter[32];
|
||||||
struct tm a, b;
|
struct tm a, b;
|
||||||
|
|||||||
@@ -1170,6 +1170,8 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
|
|||||||
flow->ssh_tls.sha1_cert_fingerprint_set = 1;
|
flow->ssh_tls.sha1_cert_fingerprint_set = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flow->ssh_tls.browser_euristics = flow->ndpi_flow->protos.tls_quic_stun.tls_quic.browser_euristics;
|
||||||
|
|
||||||
if(flow->ndpi_flow->protos.tls_quic_stun.tls_quic.alpn) {
|
if(flow->ndpi_flow->protos.tls_quic_stun.tls_quic.alpn) {
|
||||||
if((flow->ssh_tls.tls_alpn = ndpi_strdup(flow->ndpi_flow->protos.tls_quic_stun.tls_quic.alpn)) != NULL)
|
if((flow->ssh_tls.tls_alpn = ndpi_strdup(flow->ndpi_flow->protos.tls_quic_stun.tls_quic.alpn)) != NULL)
|
||||||
correct_csv_data_field(flow->ssh_tls.tls_alpn);
|
correct_csv_data_field(flow->ssh_tls.tls_alpn);
|
||||||
|
|||||||
@@ -211,10 +211,13 @@ typedef struct ndpi_flow_info {
|
|||||||
ja3_client[33], ja3_server[33],
|
ja3_client[33], ja3_server[33],
|
||||||
sha1_cert_fingerprint[20];
|
sha1_cert_fingerprint[20];
|
||||||
u_int8_t sha1_cert_fingerprint_set;
|
u_int8_t sha1_cert_fingerprint_set;
|
||||||
|
struct tls_euristics browser_euristics;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
u_int16_t cipher_suite;
|
u_int16_t cipher_suite;
|
||||||
char *esni;
|
char *esni;
|
||||||
} encrypted_sni;
|
} encrypted_sni;
|
||||||
|
|
||||||
time_t notBefore, notAfter;
|
time_t notBefore, notAfter;
|
||||||
u_int16_t server_cipher;
|
u_int16_t server_cipher;
|
||||||
ndpi_cipher_weakness client_unsafe_cipher, server_unsafe_cipher;
|
ndpi_cipher_weakness client_unsafe_cipher, server_unsafe_cipher;
|
||||||
|
|||||||
@@ -1211,6 +1211,14 @@ typedef enum {
|
|||||||
|
|
||||||
#define MAX_NUM_TLS_SIGNATURE_ALGORITHMS 16
|
#define MAX_NUM_TLS_SIGNATURE_ALGORITHMS 16
|
||||||
|
|
||||||
|
struct tls_euristics {
|
||||||
|
/*
|
||||||
|
TLS euristics for detecting browsers usage
|
||||||
|
NOTE: expect false positives
|
||||||
|
*/
|
||||||
|
u_int8_t is_safari_tls:1, is_firefox_tls:1, notused:6;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NOTE
|
NOTE
|
||||||
When the struct below is modified don't forget to update
|
When the struct below is modified don't forget to update
|
||||||
@@ -1322,8 +1330,15 @@ struct ndpi_flow_struct {
|
|||||||
u_int32_t notBefore, notAfter;
|
u_int32_t notBefore, notAfter;
|
||||||
char ja3_client[33], ja3_server[33];
|
char ja3_client[33], ja3_server[33];
|
||||||
u_int16_t server_cipher;
|
u_int16_t server_cipher;
|
||||||
|
u_int8_t sha1_certificate_fingerprint[20];
|
||||||
|
|
||||||
|
#ifdef TLS_HANDLE_SIGNATURE_ALGORITMS
|
||||||
|
/* Under #ifdef to save memory for those who do not need them */
|
||||||
|
u_int8_t num_tls_signature_algorithms;
|
||||||
u_int16_t client_signature_algorithms[MAX_NUM_TLS_SIGNATURE_ALGORITHMS];
|
u_int16_t client_signature_algorithms[MAX_NUM_TLS_SIGNATURE_ALGORITHMS];
|
||||||
u_int8_t num_tls_signature_algorithms, sha1_certificate_fingerprint[20];
|
#endif
|
||||||
|
|
||||||
|
struct tls_euristics browser_euristics;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
u_int16_t cipher_suite;
|
u_int16_t cipher_suite;
|
||||||
|
|||||||
+41
-7
@@ -1400,6 +1400,8 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if((cipher_offset+cipher_len) <= total_len) {
|
if((cipher_offset+cipher_len) <= total_len) {
|
||||||
|
u_int8_t safari_ciphers = 0;
|
||||||
|
|
||||||
for(i=0; i<cipher_len;) {
|
for(i=0; i<cipher_len;) {
|
||||||
u_int16_t *id = (u_int16_t*)&packet->payload[cipher_offset+i];
|
u_int16_t *id = (u_int16_t*)&packet->payload[cipher_offset+i];
|
||||||
|
|
||||||
@@ -1407,23 +1409,40 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
printf("Client TLS [cipher suite: %u/0x%04X] [%d/%u]\n", ntohs(*id), ntohs(*id), i, cipher_len);
|
printf("Client TLS [cipher suite: %u/0x%04X] [%d/%u]\n", ntohs(*id), ntohs(*id), i, cipher_len);
|
||||||
#endif
|
#endif
|
||||||
if((*id == 0) || (packet->payload[cipher_offset+i] != packet->payload[cipher_offset+i+1])) {
|
if((*id == 0) || (packet->payload[cipher_offset+i] != packet->payload[cipher_offset+i+1])) {
|
||||||
|
u_int16_t cipher_id = ntohs(*id);
|
||||||
/*
|
/*
|
||||||
Skip GREASE [https://tools.ietf.org/id/draft-ietf-tls-grease-01.html]
|
Skip GREASE [https://tools.ietf.org/id/draft-ietf-tls-grease-01.html]
|
||||||
https://engineering.salesforce.com/tls-fingerprinting-with-ja3-and-ja3s-247362855967
|
https://engineering.salesforce.com/tls-fingerprinting-with-ja3-and-ja3s-247362855967
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(ja3.client.num_cipher < MAX_NUM_JA3)
|
if(ja3.client.num_cipher < MAX_NUM_JA3)
|
||||||
ja3.client.cipher[ja3.client.num_cipher++] = ntohs(*id);
|
ja3.client.cipher[ja3.client.num_cipher++] = cipher_id;
|
||||||
else {
|
else {
|
||||||
invalid_ja3 = 1;
|
invalid_ja3 = 1;
|
||||||
#ifdef DEBUG_TLS
|
#ifdef DEBUG_TLS
|
||||||
printf("Client TLS Invalid cipher %u\n", ja3.client.num_cipher);
|
printf("Client TLS Invalid cipher %u\n", ja3.client.num_cipher);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch(cipher_id) {
|
||||||
|
case 0x00c008: /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */
|
||||||
|
case 0x00C023: /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 */
|
||||||
|
case 0x00C024: /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 */
|
||||||
|
case 0x00c012: /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */
|
||||||
|
case 0x00C027: /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */
|
||||||
|
case 0x00C028: /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */
|
||||||
|
case 0x00003C: /* TLS_RSA_WITH_AES_128_CBC_SHA256 */
|
||||||
|
case 0x00003D: /* TLS_RSA_WITH_AES_256_CBC_SHA256 */
|
||||||
|
safari_ciphers++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
} /* for */
|
||||||
|
|
||||||
|
if(safari_ciphers >= 6)
|
||||||
|
flow->protos.tls_quic_stun.tls_quic.browser_euristics.is_safari_tls = 1;
|
||||||
} else {
|
} else {
|
||||||
invalid_ja3 = 1;
|
invalid_ja3 = 1;
|
||||||
#ifdef DEBUG_TLS
|
#ifdef DEBUG_TLS
|
||||||
@@ -1622,17 +1641,32 @@ int processClientServerHello(struct ndpi_detection_module_struct *ndpi_struct,
|
|||||||
s_offset += 2;
|
s_offset += 2;
|
||||||
tot_signature_algorithms_len = ndpi_min((sizeof(ja3.client.signature_algorithms) / 2) - 1, tot_signature_algorithms_len);
|
tot_signature_algorithms_len = ndpi_min((sizeof(ja3.client.signature_algorithms) / 2) - 1, tot_signature_algorithms_len);
|
||||||
|
|
||||||
|
#ifdef TLS_HANDLE_SIGNATURE_ALGORITMS
|
||||||
|
flow->protos.tls_quic_stun.tls_quic.num_tls_signature_algorithms = ndpi_min(tot_signature_algorithms_len, MAX_NUM_TLS_SIGNATURE_ALGORITHMS);
|
||||||
|
|
||||||
|
memcpy(flow->protos.tls_quic_stun.tls_quic.client_signature_algorithms,
|
||||||
|
&packet->payload[s_offset], 2 /* 16 bit */*flow->protos.tls_quic_stun.tls_quic.num_tls_signature_algorithms);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
for(i=0; i<tot_signature_algorithms_len; i++) {
|
for(i=0; i<tot_signature_algorithms_len; i++) {
|
||||||
int rc = snprintf(&ja3.client.signature_algorithms[i*2], sizeof(ja3.client.signature_algorithms)-i*2, "%02X", packet->payload[s_offset+i]);
|
int rc = snprintf(&ja3.client.signature_algorithms[i*2], sizeof(ja3.client.signature_algorithms)-i*2, "%02X", packet->payload[s_offset+i]);
|
||||||
|
|
||||||
if(flow->protos.tls_quic_stun.tls_quic.num_tls_signature_algorithms < MAX_NUM_TLS_SIGNATURE_ALGORITHMS) {
|
|
||||||
if(flow->protos.tls_quic_stun.tls_quic.client_signature_algorithms[flow->protos.tls_quic_stun.tls_quic.num_tls_signature_algorithms])
|
|
||||||
flow->protos.tls_quic_stun.tls_quic.num_tls_signature_algorithms++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rc < 0) break;
|
if(rc < 0) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(i=0; i<tot_signature_algorithms_len; i+=2) {
|
||||||
|
u_int16_t cipher_id = (u_int16_t)ntohs(*((u_int16_t*)&packet->payload[s_offset+i]));
|
||||||
|
|
||||||
|
// printf("=>> %04X\n", cipher_id);
|
||||||
|
|
||||||
|
if(cipher_id == 0x0603 /* ECDSA_SECP521R1_SHA512 */) {
|
||||||
|
flow->protos.tls_quic_stun.tls_quic.browser_euristics.is_firefox_tls = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ja3.client.signature_algorithms[i*2] = '\0';
|
ja3.client.signature_algorithms[i*2] = '\0';
|
||||||
|
|
||||||
#ifdef DEBUG_TLS
|
#ifdef DEBUG_TLS
|
||||||
|
|||||||
Reference in New Issue
Block a user