Added the ability to track the payload via -E and via the new option 'ndpi_track_flow_payload'
This commit is contained in:
+26
-9
@@ -96,6 +96,7 @@ u_int8_t verbose = 0, enable_flow_stats = 0;
|
||||
int nDPI_LogLevel = 0;
|
||||
char *_debug_protocols = NULL;
|
||||
static u_int8_t stats_flag = 0;
|
||||
ndpi_init_prefs init_prefs = ndpi_no_prefs;
|
||||
u_int8_t human_readeable_string_len = 5;
|
||||
u_int8_t max_num_udp_dissected_pkts = 24 /* 8 is enough for most protocols, Signal and SnapchatCall require more */, max_num_tcp_dissected_pkts = 80 /* due to telnet */;
|
||||
static u_int32_t pcap_analysis_duration = (u_int32_t)-1;
|
||||
@@ -120,7 +121,7 @@ static time_t capture_until = 0;
|
||||
static u_int32_t num_flows;
|
||||
static struct ndpi_detection_module_struct *ndpi_info_mod = NULL;
|
||||
|
||||
extern u_int8_t enable_doh_dot_detection, enable_ja3_plus;
|
||||
extern u_int8_t enable_doh_dot_detection;
|
||||
extern u_int32_t max_num_packets_per_flow, max_packet_payload_dissection, max_num_reported_top_payloads;
|
||||
extern u_int16_t min_pattern_len, max_pattern_len;
|
||||
extern void ndpi_self_check_host_match(); /* Self check function */
|
||||
@@ -310,7 +311,7 @@ void ndpiCheckHostStringMatch(char *testChar) {
|
||||
if(!testChar)
|
||||
return;
|
||||
|
||||
ndpi_str = ndpi_init_detection_module(enable_ja3_plus ? ndpi_enable_ja3_plus : ndpi_no_prefs);
|
||||
ndpi_str = ndpi_init_detection_module(init_prefs);
|
||||
ndpi_finalize_initialization(ndpi_str);
|
||||
|
||||
// Display ALL Host strings ie host_match[] ?
|
||||
@@ -440,7 +441,7 @@ static void help(u_int long_help) {
|
||||
"-i <file|device> "
|
||||
#endif
|
||||
"[-f <filter>][-s <duration>][-m <duration>][-b <num bin clusters>]\n"
|
||||
" [-p <protos>][-l <loops> [-q][-d][-J][-h][-H][-D][-e <len>][-t][-v <level>]\n"
|
||||
" [-p <protos>][-l <loops> [-q][-d][-J][-h][-H][-D][-e <len>][-E][-t][-v <level>]\n"
|
||||
" [-n <threads>][-w <file>][-c <file>][-C <file>][-j <file>][-x <file>]\n"
|
||||
" [-r <file>][-j <file>][-S <file>][-T <num>][-U <num>] [-x <domain>][-z]\n"
|
||||
" [-a <mode>]\n\n"
|
||||
@@ -467,6 +468,7 @@ static void help(u_int long_help) {
|
||||
" | 2 - List known risks\n"
|
||||
" -d | Disable protocol guess and use only DPI\n"
|
||||
" -e <len> | Min human readeable string match len. Default %u\n"
|
||||
" -E | Track flow payload\n"
|
||||
" -q | Quiet mode\n"
|
||||
" -F | Enable flow stats\n"
|
||||
" -t | Dissect GTP/TZSP tunnels\n"
|
||||
@@ -531,7 +533,7 @@ static void help(u_int long_help) {
|
||||
|
||||
NDPI_PROTOCOL_BITMASK all;
|
||||
|
||||
ndpi_info_mod = ndpi_init_detection_module(ndpi_no_prefs);
|
||||
ndpi_info_mod = ndpi_init_detection_module(init_prefs);
|
||||
printf("\n\nnDPI supported protocols:\n");
|
||||
printf("%3s %-22s %-10s %-8s %-12s %s\n",
|
||||
"Id", "Protocol", "Layer_4", "Nw_Proto", "Breed", "Category");
|
||||
@@ -659,7 +661,7 @@ void extcap_config() {
|
||||
ndpi_proto_defaults_t *proto_defaults;
|
||||
#endif
|
||||
|
||||
ndpi_info_mod = ndpi_init_detection_module(ndpi_no_prefs);
|
||||
ndpi_info_mod = ndpi_init_detection_module(init_prefs);
|
||||
#if 0
|
||||
ndpi_num_supported_protocols = ndpi_get_ndpi_num_supported_protocols(ndpi_info_mod);
|
||||
proto_defaults = ndpi_get_proto_defaults(ndpi_info_mod);
|
||||
@@ -806,7 +808,7 @@ static void parseOptions(int argc, char **argv) {
|
||||
}
|
||||
#endif
|
||||
|
||||
while((opt = getopt_long(argc, argv, "a:Ab:e:c:C:dDf:g:i:Ij:k:K:S:hHp:pP:l:r:s:tu:v:V:n:Jrp:x:w:zq0123:456:7:89:m:T:U:",
|
||||
while((opt = getopt_long(argc, argv, "a:Ab:e:Ec:C:dDf:g:i:Ij:k:K:S:hHp:pP:l:r:s:tu:v:V:n:Jrp:x:w:zq0123:456:7:89:m:T:U:",
|
||||
longopts, &option_idx)) != EOF) {
|
||||
#ifdef DEBUG_TRACE
|
||||
if(trace) fprintf(trace, " #### Handling option -%c [%s] #### \n", opt, optarg ? optarg : "");
|
||||
@@ -838,6 +840,10 @@ static void parseOptions(int argc, char **argv) {
|
||||
human_readeable_string_len = atoi(optarg);
|
||||
break;
|
||||
|
||||
case 'E':
|
||||
init_prefs |= ndpi_track_flow_payload;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
case '3':
|
||||
_pcap_file[0] = optarg;
|
||||
@@ -1053,7 +1059,7 @@ static void parseOptions(int argc, char **argv) {
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
enable_ja3_plus = 1;
|
||||
init_prefs |= ndpi_enable_ja3_plus;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -1678,6 +1684,17 @@ static void printFlow(u_int32_t id, struct ndpi_flow_info *flow, u_int16_t threa
|
||||
print_bin(out, "Plen Bins", &flow->payload_len_bin);
|
||||
#endif
|
||||
|
||||
if(flow->flow_payload && (flow->flow_payload_len > 0)) {
|
||||
u_int i;
|
||||
|
||||
printf("[Payload: ");
|
||||
|
||||
for(i=0; i<flow->flow_payload_len; i++)
|
||||
printf("%c", isspace(flow->flow_payload[i]) ? '.' : flow->flow_payload[i]);
|
||||
|
||||
printf("]");
|
||||
}
|
||||
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
}
|
||||
@@ -4336,7 +4353,7 @@ static void dgaUnitTest() {
|
||||
};
|
||||
int debug = 0, i;
|
||||
NDPI_PROTOCOL_BITMASK all;
|
||||
struct ndpi_detection_module_struct *ndpi_str = ndpi_init_detection_module(enable_ja3_plus ? ndpi_enable_ja3_plus : ndpi_no_prefs);
|
||||
struct ndpi_detection_module_struct *ndpi_str = ndpi_init_detection_module(init_prefs);
|
||||
|
||||
assert(ndpi_str != NULL);
|
||||
|
||||
@@ -5097,7 +5114,7 @@ void zscoreUnitTest() {
|
||||
ac_automata_enable_debug(1);
|
||||
parseOptions(argc, argv);
|
||||
|
||||
ndpi_info_mod = ndpi_init_detection_module(enable_ja3_plus ? ndpi_enable_ja3_plus : ndpi_no_prefs);
|
||||
ndpi_info_mod = ndpi_init_detection_module(init_prefs);
|
||||
|
||||
if(ndpi_info_mod == NULL) return -1;
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ extern u_int8_t max_num_udp_dissected_pkts /* 24 */, max_num_tcp_dissected_pkts
|
||||
static u_int32_t flow_id = 0;
|
||||
|
||||
u_int8_t enable_doh_dot_detection = 0;
|
||||
u_int8_t enable_ja3_plus = 0;
|
||||
extern ndpi_init_prefs init_prefs;
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
@@ -403,7 +403,7 @@ struct ndpi_workflow* ndpi_workflow_init(const struct ndpi_workflow_prefs * pref
|
||||
set_ndpi_flow_malloc(NULL), set_ndpi_flow_free(NULL);
|
||||
|
||||
/* TODO: just needed here to init ndpi ndpi_malloc wrapper */
|
||||
module = ndpi_init_detection_module(enable_ja3_plus ? ndpi_enable_ja3_plus : ndpi_no_prefs);
|
||||
module = ndpi_init_detection_module(init_prefs);
|
||||
|
||||
if(module == NULL) {
|
||||
LOG(NDPI_LOG_ERROR, "global structure initialization failed\n");
|
||||
@@ -537,7 +537,8 @@ void ndpi_flow_info_free_data(struct ndpi_flow_info *flow) {
|
||||
ndpi_free_bin(&flow->payload_len_bin);
|
||||
#endif
|
||||
|
||||
if(flow->risk_str) ndpi_free(flow->risk_str);
|
||||
if(flow->risk_str) ndpi_free(flow->risk_str);
|
||||
if(flow->flow_payload) ndpi_free(flow->flow_payload);
|
||||
}
|
||||
|
||||
/* ***************************************************** */
|
||||
@@ -1329,6 +1330,9 @@ void process_ndpi_collected_info(struct ndpi_workflow * workflow, struct ndpi_fl
|
||||
if(workflow->__flow_detected_callback != NULL)
|
||||
workflow->__flow_detected_callback(workflow, flow, workflow->__flow_detected_udata);
|
||||
}
|
||||
|
||||
flow->flow_payload = flow->ndpi_flow->flow_payload, flow->flow_payload_len = flow->ndpi_flow->flow_payload_len;
|
||||
flow->ndpi_flow->flow_payload = NULL; /* We'll free the memory */
|
||||
|
||||
ndpi_free_flow_info_half(flow);
|
||||
}
|
||||
|
||||
@@ -300,6 +300,10 @@ typedef struct ndpi_flow_info {
|
||||
#else
|
||||
struct ndpi_bin payload_len_bin;
|
||||
#endif
|
||||
|
||||
/* Flow payload */
|
||||
u_int16_t flow_payload_len;
|
||||
char *flow_payload;
|
||||
} ndpi_flow_info_t;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user