Added -a <num> to ndpiReader for generating OPNsense configuration

See https://github.com/ntop/opnsense
This commit is contained in:
Luca Deri
2021-10-04 22:34:49 +02:00
parent fd0e65cb57
commit bb7aff6526
4 changed files with 139 additions and 67 deletions
+11 -2
View File
@@ -459,7 +459,8 @@ static void help(u_int long_help) {
"[-f <filter>][-s <duration>][-m <duration>][-b <num bin clusters>]\n" "[-f <filter>][-s <duration>][-m <duration>][-b <num bin clusters>]\n"
" [-p <protos>][-l <loops> [-q][-d][-J][-h][-D][-e <len>][-t][-v <level>]\n" " [-p <protos>][-l <loops> [-q][-d][-J][-h][-D][-e <len>][-t][-v <level>]\n"
" [-n <threads>][-w <file>][-c <file>][-C <file>][-j <file>][-x <file>]\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\n" " [-r <file>][-j <file>][-S <file>][-T <num>][-U <num>] [-x <domain>][-z]\n"
" [-a <mode>]\n\n"
"Usage:\n" "Usage:\n"
" -i <file.pcap|device> | Specify a pcap file/playlist to read packets from or a\n" " -i <file.pcap|device> | Specify a pcap file/playlist to read packets from or a\n"
" | device for live capture (comma-separated list)\n" " | device for live capture (comma-separated list)\n"
@@ -474,6 +475,10 @@ static void help(u_int long_help) {
#ifdef linux #ifdef linux
" -g <id:id...> | Thread affinity mask (one core id per thread)\n" " -g <id:id...> | Thread affinity mask (one core id per thread)\n"
#endif #endif
" -a <mode> | Generates option values for GUIs\n"
" | 0 - List known protocols\n"
" | 1 - List known categories\n"
" | 2 - List known risks\n"
" -d | Disable protocol guess and use only DPI\n" " -d | Disable protocol guess and use only DPI\n"
" -e <len> | Min human readeable string match len. Default %u\n" " -e <len> | Min human readeable string match len. Default %u\n"
" -q | Quiet mode\n" " -q | Quiet mode\n"
@@ -806,13 +811,17 @@ static void parseOptions(int argc, char **argv) {
} }
#endif #endif
while((opt = getopt_long(argc, argv, "b:e:c:C:dDf:g:i:Ij:S:hp: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:b:e:c:C:dDf:g:i:Ij:S:hp:pP:l:r:s:tu:v:V:n:Jrp:x:w:zq0123:456:7:89:m:T:U:",
longopts, &option_idx)) != EOF) { longopts, &option_idx)) != EOF) {
#ifdef DEBUG_TRACE #ifdef DEBUG_TRACE
if(trace) fprintf(trace, " #### Handling option -%c [%s] #### \n", opt, optarg ? optarg : ""); if(trace) fprintf(trace, " #### Handling option -%c [%s] #### \n", opt, optarg ? optarg : "");
#endif #endif
switch (opt) { switch (opt) {
case 'a':
ndpi_generate_options(atoi(optarg));
break;
case 'b': case 'b':
if((num_bin_clusters = atoi(optarg)) > 32) if((num_bin_clusters = atoi(optarg)) > 32)
num_bin_clusters = 32; num_bin_clusters = 32;
+7
View File
@@ -682,6 +682,13 @@ extern "C" {
*/ */
void ndpi_dump_protocols(struct ndpi_detection_module_struct *mod); void ndpi_dump_protocols(struct ndpi_detection_module_struct *mod);
/**
* Generate Options list used in OPNsense firewall plugin
*
* @par opt = The Option list to generate
*/
void ndpi_generate_options(u_int opt);
/** /**
* Write the list of the scores and their associated risks * Write the list of the scores and their associated risks
* *
+56
View File
@@ -6749,6 +6749,62 @@ void ndpi_dump_protocols(struct ndpi_detection_module_struct *ndpi_str) {
ndpi_category_get_name(ndpi_str, ndpi_str->proto_defaults[i].protoCategory)); ndpi_category_get_name(ndpi_str, ndpi_str->proto_defaults[i].protoCategory));
} }
/* ********************************** */
/* Helper function used to generate Options fields in OPNsense */
void ndpi_generate_options(u_int opt) {
struct ndpi_detection_module_struct *ndpi_str;
NDPI_PROTOCOL_BITMASK all;
u_int i;
ndpi_str = ndpi_init_detection_module(ndpi_no_prefs);
NDPI_BITMASK_SET_ALL(all);
ndpi_set_protocol_detection_bitmask2(ndpi_str, &all);
switch(opt) {
case 0: /* List known protocols */
{
for(i = 1 /* Skip unknown */; i < ndpi_str->ndpi_num_supported_protocols; i++) {
printf(" <Option%d value=\"%u\">%s</Option%d>\n",
i, i, ndpi_str->proto_defaults[i].protoName, i);
}
}
break;
case 1: /* List known categories */
{
for(i = 1 /* Skip Unknown */; i < NDPI_PROTOCOL_NUM_CATEGORIES; i++) {
const char *name = ndpi_category_get_name(ndpi_str, i);
if((name != NULL) && (name[0] != '\0')) {
printf(" <Option%d value=\"%u\">%s</Option%d>\n",
i, i, name, i);
}
}
}
break;
case 2: /* List known risks */
{
for(i = 1 /* Skip no risk */; i < NDPI_MAX_RISK; i++) {
ndpi_risk_enum r = (ndpi_risk_enum)i;
printf(" <Option%d value=\"%u\">%s</Option%d>\n",
i, i, ndpi_risk2str(r), i);
}
}
break;
default:
printf("WARNING: option -a out of range\n");
break;
}
exit(0);
}
/* ****************************************************** */ /* ****************************************************** */
void ndpi_dump_risks_score() { void ndpi_dump_risks_score() {
+1 -1
View File
@@ -933,7 +933,7 @@ static uint8_t *decrypt_initial_packet(struct ndpi_detection_module_struct *ndpi
uint8_t first_byte; uint8_t first_byte;
uint32_t pkn32, pn_offset, pkn_len, offset; uint32_t pkn32, pn_offset, pkn_len, offset;
quic_ciphers ciphers; /* Client initial ciphers */ quic_ciphers ciphers; /* Client initial ciphers */
quic_decrypt_result_t decryption = {0}; quic_decrypt_result_t decryption = { 0, 0};
uint8_t client_secret[HASH_SHA2_256_LENGTH]; uint8_t client_secret[HASH_SHA2_256_LENGTH];
memset(&ciphers, '\0', sizeof(ciphers)); memset(&ciphers, '\0', sizeof(ciphers));