This commit is contained in:
Luca Deri
2022-04-01 19:07:00 +02:00
parent 6eb5bd88a7
commit 32a7d42469
+28 -36
View File
@@ -1209,9 +1209,6 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
char buf[32], buf1[64]; char buf[32], buf1[64];
char buf_ver[16]; char buf_ver[16];
u_int i; u_int i;
#ifdef HAVE_LIBJSON_C
json_object *jObj;
#endif
if(csv_fp != NULL) { if(csv_fp != NULL) {
float data_ratio = ndpi_data_ratio(flow->src2dst_bytes, flow->dst2src_bytes); float data_ratio = ndpi_data_ratio(flow->src2dst_bytes, flow->dst2src_bytes);
@@ -1310,11 +1307,11 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
if(csv_fp) if(csv_fp)
fprintf(csv_fp, "\n"); fprintf(csv_fp, "\n");
return; // return;
}
} }
if(csv_fp || !json_flag || (verbose > 1)) { if(csv_fp || !json_flag || (verbose > 1)) {
#if 1 #if 1
fprintf(out, "\t%u", id); fprintf(out, "\t%u", id);
#else #else
@@ -1333,7 +1330,6 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
if(flow->vlan_id > 0) fprintf(out, "[VLAN: %u]", flow->vlan_id); if(flow->vlan_id > 0) fprintf(out, "[VLAN: %u]", flow->vlan_id);
if(enable_payload_analyzer) fprintf(out, "[flowId: %u]", flow->flow_id); if(enable_payload_analyzer) fprintf(out, "[flowId: %u]", flow->flow_id);
}
if(enable_flow_stats) { if(enable_flow_stats) {
/* Print entropy values for monitored flows. */ /* Print entropy values for monitored flows. */
@@ -1355,7 +1351,8 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
flow->detected_protocol, buf1, sizeof(buf1))); flow->detected_protocol, buf1, sizeof(buf1)));
fprintf(out, "[%s]", fprintf(out, "[%s]",
ndpi_is_encrypted_proto(ndpi_thread_info[thread_id].workflow->ndpi_struct, flow->detected_protocol) ? "Encrypted" : "ClearText"); ndpi_is_encrypted_proto(ndpi_thread_info[thread_id].workflow->ndpi_struct,
flow->detected_protocol) ? "Encrypted" : "ClearText");
fprintf(out, "[Confidence: %s]", ndpi_confidence_get_name(flow->confidence)); fprintf(out, "[Confidence: %s]", ndpi_confidence_get_name(flow->confidence));
@@ -1442,7 +1439,8 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
fprintf(out, "[Risk Score: %u]", ndpi_risk2score(flow->risk, &cli_score, &srv_score)); fprintf(out, "[Risk Score: %u]", ndpi_risk2score(flow->risk, &cli_score, &srv_score));
} }
if(flow->ssh_tls.ssl_version != 0) fprintf(out, "[%s]", ndpi_ssl_version2str(buf_ver, sizeof(buf_ver), flow->ssh_tls.ssl_version, &known_tls)); if(flow->ssh_tls.ssl_version != 0) fprintf(out, "[%s]", ndpi_ssl_version2str(buf_ver, sizeof(buf_ver),
flow->ssh_tls.ssl_version, &known_tls));
if(flow->ssh_tls.client_hassh[0] != '\0') fprintf(out, "[HASSH-C: %s]", flow->ssh_tls.client_hassh); if(flow->ssh_tls.client_hassh[0] != '\0') fprintf(out, "[HASSH-C: %s]", flow->ssh_tls.client_hassh);
@@ -1495,14 +1493,28 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
} }
if(flow->ssh_tls.server_cipher != '\0') fprintf(out, "[Cipher: %s]", ndpi_cipher2str(flow->ssh_tls.server_cipher)); if(flow->ssh_tls.server_cipher != '\0') fprintf(out, "[Cipher: %s]", ndpi_cipher2str(flow->ssh_tls.server_cipher));
if(flow->bittorent_hash[0] != '\0') fprintf(out, "[BT Hash: %s]", flow->bittorent_hash); if(flow->bittorent_hash != '\0') fprintf(out, "[BT Hash: %s]", flow->bittorent_hash);
if(flow->dhcp_fingerprint[0] != '\0') fprintf(out, "[DHCP Fingerprint: %s]", flow->dhcp_fingerprint); if(flow->dhcp_fingerprint != '\0') fprintf(out, "[DHCP Fingerprint: %s]", flow->dhcp_fingerprint);
if(flow->dhcp_class_ident) fprintf(out, "[DHCP Class Ident: %s]",
flow->dhcp_class_ident);
if(flow->has_human_readeable_strings) fprintf(out, "[PLAIN TEXT (%s)]", flow->human_readeable_string_buffer); if(flow->has_human_readeable_strings) fprintf(out, "[PLAIN TEXT (%s)]",
flow->human_readeable_string_buffer);
#ifdef DIRECTION_BINS
print_bin(out, "Plen c2s", &flow->payload_len_bin_src2dst);
print_bin(out, "Plen s2c", &flow->payload_len_bin_dst2src);
#else
print_bin(out, "Plen Bins", &flow->payload_len_bin);
#endif
fprintf(out, "\n"); fprintf(out, "\n");
} else { }
#ifdef HAVE_LIBJSON_C #ifdef HAVE_LIBJSON_C
if(json_flag) {
json_object *jObj;
jObj = json_object_new_object(); jObj = json_object_new_object();
json_object_object_add(jObj,"protocol",json_object_new_string(ipProto2Name(flow->protocol))); json_object_object_add(jObj,"protocol",json_object_new_string(ipProto2Name(flow->protocol)));
@@ -1545,26 +1557,6 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
if(flow->ssh_tls.ja3_server[0] != '\0') if(flow->ssh_tls.ja3_server[0] != '\0')
json_object_object_add(jObj,"ja3s",json_object_new_string(flow->ssh_tls.ja3_server)); json_object_object_add(jObj,"ja3s",json_object_new_string(flow->ssh_tls.ja3_server));
if(flow->ssh_tls.server_cipher != '\0') fprintf(out, "[Cipher: %s]",
ndpi_cipher2str(flow->ssh_tls.server_cipher));
if(flow->bittorent_hash) fprintf(out, "[BT Hash: %s]",
flow->bittorent_hash);
if(flow->dhcp_fingerprint) fprintf(out, "[DHCP Fingerprint: %s]",
flow->dhcp_fingerprint);
if(flow->dhcp_class_ident) fprintf(out, "[DHCP Class Ident: %s]",
flow->dhcp_class_ident);
if(flow->has_human_readeable_strings) fprintf(out, "[PLAIN TEXT (%s)]",
flow->human_readeable_string_buffer);
#ifdef DIRECTION_BINS
print_bin(out, "Plen c2s", &flow->payload_len_bin_src2dst);
print_bin(out, "Plen s2c", &flow->payload_len_bin_dst2src);
#else
print_bin(out, "Plen Bins", &flow->payload_len_bin);
#endif
if(flow->ssh_tls.client_hassh[0] != '\0') if(flow->ssh_tls.client_hassh[0] != '\0')
json_object_object_add(sjObj, "client", json_object_new_string(flow->ssh_tls.client_hassh)); json_object_object_add(sjObj, "client", json_object_new_string(flow->ssh_tls.client_hassh));
@@ -1578,8 +1570,8 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
json_object_array_add(jArray_known_flows,jObj); json_object_array_add(jArray_known_flows,jObj);
else if(json_flag == 2) else if(json_flag == 2)
json_object_array_add(jArray_unknown_flows,jObj); json_object_array_add(jArray_unknown_flows,jObj);
#endif
} }
#endif
} }
/* ********************************** */ /* ********************************** */
@@ -3298,6 +3290,7 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
if(cumulative_stats.total_wire_bytes == 0) if(cumulative_stats.total_wire_bytes == 0)
goto free_stats; goto free_stats;
if(!json_flag) {
if(!quiet_mode) { if(!quiet_mode) {
printf("\nnDPI Memory statistics:\n"); printf("\nnDPI Memory statistics:\n");
printf("\tnDPI Memory (once): %-13s\n", formatBytes(ndpi_get_ndpi_detection_module_size(), buf, sizeof(buf))); printf("\tnDPI Memory (once): %-13s\n", formatBytes(ndpi_get_ndpi_detection_module_size(), buf, sizeof(buf)));
@@ -3307,7 +3300,6 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
printf("\tSetup Time: %lu msec\n", (unsigned long)(setup_time_usec/1000)); printf("\tSetup Time: %lu msec\n", (unsigned long)(setup_time_usec/1000));
printf("\tPacket Processing Time: %lu msec\n", (unsigned long)(processing_time_usec/1000)); printf("\tPacket Processing Time: %lu msec\n", (unsigned long)(processing_time_usec/1000));
if(!json_flag) {
printf("\nTraffic statistics:\n"); printf("\nTraffic statistics:\n");
printf("\tEthernet bytes: %-13llu (includes ethernet CRC/IFC/trailer)\n", printf("\tEthernet bytes: %-13llu (includes ethernet CRC/IFC/trailer)\n",
(long long unsigned int)cumulative_stats.total_wire_bytes); (long long unsigned int)cumulative_stats.total_wire_bytes);
@@ -3426,6 +3418,7 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
fprintf(results_file, "\n"); fprintf(results_file, "\n");
} }
}
if(json_flag) { if(json_flag) {
#ifdef HAVE_LIBJSON_C #ifdef HAVE_LIBJSON_C
@@ -3522,7 +3515,7 @@ static void printResults(u_int64_t processing_time_usec, u_int64_t setup_time_us
printRiskStats(); printRiskStats();
printFlowsStats(); printFlowsStats();
if(json_flag != 0) { if(json_flag) {
#ifdef HAVE_LIBJSON_C #ifdef HAVE_LIBJSON_C
json_object_object_add(jObj_main,"detected.protos",jArray_detProto); json_object_object_add(jObj_main,"detected.protos",jArray_detProto);
json_object_object_add(jObj_main,"known.flows",jArray_known_flows); json_object_object_add(jObj_main,"known.flows",jArray_known_flows);
@@ -3607,7 +3600,6 @@ free_stats:
dstStats = NULL; dstStats = NULL;
} }
} }
}
/** /**
* @brief Force a pcap_dispatch() or pcap_loop() call to return * @brief Force a pcap_dispatch() or pcap_loop() call to return