JA3 format cleanup

This commit is contained in:
Luca Deri
2019-07-13 19:32:51 +02:00
parent af2dc0860c
commit 7b16c68e92
+56 -76
View File
@@ -2159,6 +2159,16 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
if((verbose == 1) || (verbose == 2)) {
FILE *out = results_file ? results_file : stdout;
u_int32_t total_flows = 0;
ndpi_host_ja3_fingerprints *ja3ByHostsHashT = NULL; //outer hash table
ndpi_ja3_fingerprints_host *hostByJA3C_ht = NULL; //for client
ndpi_ja3_fingerprints_host *hostByJA3S_ht = NULL; //for server
int i;
ndpi_host_ja3_fingerprints *ja3ByHost_element = NULL;
ndpi_ja3_info *info_of_element = NULL;
ndpi_host_ja3_fingerprints *tmp = NULL;
ndpi_ja3_info *tmp2 = NULL;
unsigned int num_ja3_client;
unsigned int num_ja3_server;
for(thread_id = 0; thread_id < num_threads; thread_id++)
total_flows += ndpi_thread_info[thread_id].workflow->num_allocated_flows;
@@ -2176,13 +2186,6 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
ndpi_twalk(ndpi_thread_info[thread_id].workflow->ndpi_flows_root[i], node_print_known_proto_walker, &thread_id);
}
//
ndpi_host_ja3_fingerprints *ja3ByHostsHashT = NULL; //outer hash table
ndpi_ja3_fingerprints_host *hostByJA3C_ht = NULL; //for client
ndpi_ja3_fingerprints_host *hostByJA3S_ht = NULL; //for server
int i = 0;
for(i = 0; i < num_flows; i++){
ndpi_host_ja3_fingerprints *ja3ByHostFound = NULL;
ndpi_ja3_fingerprints_host *hostByJA3Found = NULL;
@@ -2312,50 +2315,46 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
}
}
//pointers for the hash table's iteration
ndpi_host_ja3_fingerprints *ja3ByHost_element = NULL;
ndpi_ja3_info *info_of_element = NULL;
ndpi_host_ja3_fingerprints *tmp = NULL;
ndpi_ja3_info *tmp2 = NULL;
unsigned int num_ja3_client;
unsigned int num_ja3_server;
if(ja3ByHostsHashT) {
ndpi_ja3_fingerprints_host *hostByJA3Element = NULL;
ndpi_ja3_fingerprints_host *tmp3 = NULL;
ndpi_ip_dns *innerHashEl = NULL;
ndpi_ip_dns *tmp4 = NULL;
if(verbose == 1) {
//for each host the number of flow with a ja3 fingerprint is printed
int i = 1;
ndpi_host_ja3_fingerprints *ja3ByHost_element;
printf("Number of flow with JA3 for each host: \n");
/* for each host the number of flow with a ja3 fingerprint is printed */
i = 1;
printf("JA3 Host Stats: \n");
printf("\t\t IP %-24s \t %-10s \n", "Address", "# JA3C");
for(ja3ByHost_element = ja3ByHostsHashT; ja3ByHost_element != NULL; ja3ByHost_element = ja3ByHost_element->hh.next) {
num_ja3_client = HASH_COUNT(ja3ByHost_element->host_client_info_hasht);
num_ja3_server = HASH_COUNT(ja3ByHost_element->host_server_info_hasht);
if(num_ja3_client > 0) {
printf("\t%d\t IP %-42s \t %-10d JA3C\n",
printf("\t%d\t %-24s \t %-7d\n",
i,
ja3ByHost_element->ip_string,
num_ja3_client
);
i++;
}
else if(num_ja3_server > 0){
printf("\t%d\t IP %-42s \t %-10d JA3S %s\n",
i,
ja3ByHost_element->ip_string,
num_ja3_server,
ja3ByHost_element->dns_name
);
i++;
}
}
} else if(verbose == 2) {
int i = 1;
int againstRepeat;
ndpi_ja3_fingerprints_host *hostByJA3Element = NULL;
ndpi_ja3_fingerprints_host *tmp3 = NULL;
ndpi_ip_dns *innerHashEl = NULL;
ndpi_ip_dns *tmp4 = NULL;
//for each host it is printted the JA3C and JA3S, along the server name (if any)
//and the security status
//first all clients, then all servers
printf("JA3C & JA3S for each host: \n");
printf("JA3C/JA3S Host Stats: \n");
printf("\t%-7s %-24s %-34s %s\n", "", "IP", "JA3C", "JA3S");
//reminder
//ja3ByHostsHashT: hash table <ip, (ja3, ht_client, ht_server)>
@@ -2367,8 +2366,7 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
againstRepeat = 0;
if(num_ja3_client > 0) {
HASH_ITER(hh, ja3ByHost_element->host_client_info_hasht, info_of_element, tmp2) {
if(againstRepeat == 0){
printf("\t%-15d %-42s JA3C %s %s\n",
printf("\t%-7d %-24s %s %s\n",
i,
ja3ByHost_element->ip_string,
info_of_element->ja3,
@@ -2376,65 +2374,48 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
);
againstRepeat = 1;
i++;
}
else{
printf("\t%58s JA3C %s %s\n",
"",
info_of_element->ja3,
print_cipher(info_of_element->unsafe_cipher)
);
}
}
}
againstRepeat = 0;
if(num_ja3_server > 0) {
HASH_ITER(hh, ja3ByHost_element->host_server_info_hasht, info_of_element, tmp2) {
if(againstRepeat == 0){
printf("\t%-15d %-42s JA3S %s %-10s %s\n",
printf("\t%-7d %-24s %-34s %s %s %s%s%s\n",
i,
ja3ByHost_element->ip_string,
info_of_element->ja3,
print_cipher(info_of_element->unsafe_cipher),
ja3ByHost_element->dns_name
);
againstRepeat = 1;
i++;
}else{
printf("\t%58s JA3S %s %-10s %s\n",
"",
info_of_element->ja3,
print_cipher(info_of_element->unsafe_cipher),
ja3ByHost_element->dns_name
ja3ByHost_element->dns_name[0] ? "[" : "",
ja3ByHost_element->dns_name,
ja3ByHost_element->dns_name[0] ? "]" : ""
);
i++;
}
}
}
}
ndpi_ja3_fingerprints_host *hostByJA3Element = NULL;
ndpi_ja3_fingerprints_host *tmp3 = NULL;
ndpi_ip_dns *innerHashEl = NULL;
ndpi_ip_dns *tmp4 = NULL;
i = 1;
printf("\nHost IP for each JA3:\n");
printf("\nIP/JA3 Distribution:\n");
printf("%-15s %-39s %-26s\n", "", "JA3", "IP");
HASH_ITER(hh, hostByJA3C_ht, hostByJA3Element, tmp3) {
againstRepeat = 0;
HASH_ITER(hh, hostByJA3Element->ipToDNS_ht, innerHashEl, tmp4) {
if(againstRepeat == 0) {
printf("\t%-15d JA3C %s",
printf("\t%-7d JA3C %s",
i,
hostByJA3Element->ja3
);
printf("\t IP %-42s %s\n",
printf(" %-15s %s\n",
innerHashEl->ip_string,
print_cipher(hostByJA3Element->unsafe_cipher)
);
againstRepeat = 1;
i++;
} else {
printf("\t%51s", "");
printf("\t IP %-42s %s\n",
printf("\t%45s", "");
printf(" %-15s %s\n",
innerHashEl->ip_string,
print_cipher(hostByJA3Element->unsafe_cipher)
);
@@ -2445,28 +2426,31 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
againstRepeat = 0;
HASH_ITER(hh, hostByJA3Element->ipToDNS_ht, innerHashEl, tmp4) {
if(againstRepeat == 0) {
printf("\t%-15d JA3S %s",
printf("\t%-7d JA3S %s",
i,
hostByJA3Element->ja3
);
printf("\t IP %-42s %-10s %s\n",
printf(" %-15s %-10s %s%s%s\n",
innerHashEl->ip_string,
print_cipher(hostByJA3Element->unsafe_cipher),
innerHashEl->dns_name
innerHashEl->dns_name[0] ? "[" : "",
innerHashEl->dns_name,
innerHashEl->dns_name[0] ? "]" : ""
);
againstRepeat = 1;
i++;
}else{
printf("\t%51s", "");
printf("\t IP %-42s %-10s %s\n",
printf("\t%45s", "");
printf(" %-15s %-10s %s%s%s\n",
innerHashEl->ip_string,
print_cipher(hostByJA3Element->unsafe_cipher),
innerHashEl->dns_name
innerHashEl->dns_name[0] ? "[" : "",
innerHashEl->dns_name,
innerHashEl->dns_name[0] ? "]" : ""
);
}
}
}
}
printf("\n\n");
@@ -2484,11 +2468,6 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
free(ja3ByHost_element);
}
ndpi_ja3_fingerprints_host *hostByJA3Element = NULL;
ndpi_ja3_fingerprints_host *tmp3 = NULL;
ndpi_ip_dns *innerHashEl = NULL;
ndpi_ip_dns *tmp4 = NULL;
HASH_ITER(hh, hostByJA3C_ht, hostByJA3Element, tmp3) {
HASH_ITER(hh, hostByJA3C_ht->ipToDNS_ht, innerHashEl, tmp4) {
HASH_DEL(hostByJA3Element->ipToDNS_ht, innerHashEl);
@@ -2506,6 +2485,7 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
HASH_DEL(hostByJA3S_ht, hostByJA3Element);
free(hostByJA3Element);
}
}
qsort(all_flows, num_flows, sizeof(struct flow_info), cmpFlows);