Added -a <num> to ndpiReader for generating OPNsense configuration
See https://github.com/ntop/opnsense
This commit is contained in:
+11
-2
@@ -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;
|
||||||
|
|||||||
@@ -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
|
||||||
*
|
*
|
||||||
|
|||||||
+120
-64
@@ -67,7 +67,7 @@ static void (*_ndpi_free)(void *ptr);
|
|||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
|
|
||||||
static ndpi_risk_info ndpi_known_risks[] = {
|
static ndpi_risk_info ndpi_known_risks[] = {
|
||||||
{ NDPI_NO_RISK, NDPI_RISK_LOW, CLIENT_FAIR_RISK_PERCENTAGE },
|
{ NDPI_NO_RISK, NDPI_RISK_LOW, CLIENT_FAIR_RISK_PERCENTAGE },
|
||||||
{ NDPI_URL_POSSIBLE_XSS, NDPI_RISK_SEVERE, CLIENT_HIGH_RISK_PERCENTAGE },
|
{ NDPI_URL_POSSIBLE_XSS, NDPI_RISK_SEVERE, CLIENT_HIGH_RISK_PERCENTAGE },
|
||||||
{ NDPI_URL_POSSIBLE_SQL_INJECTION, NDPI_RISK_SEVERE, CLIENT_HIGH_RISK_PERCENTAGE },
|
{ NDPI_URL_POSSIBLE_SQL_INJECTION, NDPI_RISK_SEVERE, CLIENT_HIGH_RISK_PERCENTAGE },
|
||||||
{ NDPI_URL_POSSIBLE_RCE_INJECTION, NDPI_RISK_SEVERE, CLIENT_HIGH_RISK_PERCENTAGE },
|
{ NDPI_URL_POSSIBLE_RCE_INJECTION, NDPI_RISK_SEVERE, CLIENT_HIGH_RISK_PERCENTAGE },
|
||||||
@@ -433,7 +433,7 @@ void ndpi_set_proto_defaults(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
ndpi_str->proto_defaults[protoId].protoBreed = breed;
|
ndpi_str->proto_defaults[protoId].protoBreed = breed;
|
||||||
ndpi_str->proto_defaults[protoId].subprotocols = NULL;
|
ndpi_str->proto_defaults[protoId].subprotocols = NULL;
|
||||||
ndpi_str->proto_defaults[protoId].subprotocol_count = 0;
|
ndpi_str->proto_defaults[protoId].subprotocol_count = 0;
|
||||||
|
|
||||||
for(j = 0; j < MAX_DEFAULT_PORTS; j++) {
|
for(j = 0; j < MAX_DEFAULT_PORTS; j++) {
|
||||||
if(udpDefPorts[j].port_low != 0)
|
if(udpDefPorts[j].port_low != 0)
|
||||||
addDefaultPort(ndpi_str, &udpDefPorts[j], &ndpi_str->proto_defaults[protoId], 0, &ndpi_str->udpRoot,
|
addDefaultPort(ndpi_str, &udpDefPorts[j], &ndpi_str->proto_defaults[protoId], 0, &ndpi_str->udpRoot,
|
||||||
@@ -632,7 +632,7 @@ static int ndpi_string_to_automa(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
|
|
||||||
if(rc != ACERR_SUCCESS) {
|
if(rc != ACERR_SUCCESS) {
|
||||||
ndpi_free(value_dup);
|
ndpi_free(value_dup);
|
||||||
|
|
||||||
if(rc != ACERR_DUPLICATE_PATTERN)
|
if(rc != ACERR_DUPLICATE_PATTERN)
|
||||||
return (-2);
|
return (-2);
|
||||||
}
|
}
|
||||||
@@ -721,7 +721,7 @@ static int ndpi_xgrams_inited = 0;
|
|||||||
static unsigned int bigrams_bitmap[(XGRAMS_C*XGRAMS_C+31)/32];
|
static unsigned int bigrams_bitmap[(XGRAMS_C*XGRAMS_C+31)/32];
|
||||||
static unsigned int imposible_bigrams_bitmap[(XGRAMS_C*XGRAMS_C+31)/32];
|
static unsigned int imposible_bigrams_bitmap[(XGRAMS_C*XGRAMS_C+31)/32];
|
||||||
static unsigned int trigrams_bitmap[(XGRAMS_C*XGRAMS_C*XGRAMS_C+31)/32];
|
static unsigned int trigrams_bitmap[(XGRAMS_C*XGRAMS_C*XGRAMS_C+31)/32];
|
||||||
|
|
||||||
|
|
||||||
static void ndpi_xgrams_init(unsigned int *dst,size_t dn, const char **src,size_t sn, unsigned int l) {
|
static void ndpi_xgrams_init(unsigned int *dst,size_t dn, const char **src,size_t sn, unsigned int l) {
|
||||||
unsigned int i,j,c;
|
unsigned int i,j,c;
|
||||||
@@ -733,7 +733,7 @@ static void ndpi_xgrams_init(unsigned int *dst,size_t dn, const char **src,size_
|
|||||||
c += a - 'a';
|
c += a - 'a';
|
||||||
}
|
}
|
||||||
if(src[i][l]) { printf("%u: c[%d] != 0\n",i,l); abort(); }
|
if(src[i][l]) { printf("%u: c[%d] != 0\n",i,l); abort(); }
|
||||||
if((c >> 3) >= dn) abort();
|
if((c >> 3) >= dn) abort();
|
||||||
dst[c >> 5] |= 1u << (c & 0x1f);
|
dst[c >> 5] |= 1u << (c & 0x1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -757,7 +757,7 @@ static void init_string_based_protocols(struct ndpi_detection_module_struct *ndp
|
|||||||
/* Note: string_to_match is not malloc'ed here as ac_automata_release is
|
/* Note: string_to_match is not malloc'ed here as ac_automata_release is
|
||||||
* called with free_pattern = 0 */
|
* called with free_pattern = 0 */
|
||||||
ndpi_add_string_value_to_automa(ndpi_str->tls_cert_subject_automa.ac_automa,
|
ndpi_add_string_value_to_automa(ndpi_str->tls_cert_subject_automa.ac_automa,
|
||||||
tls_certificate_match[i].string_to_match,
|
tls_certificate_match[i].string_to_match,
|
||||||
tls_certificate_match[i].protocol_id);
|
tls_certificate_match[i].protocol_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1771,7 +1771,7 @@ static int ac_domain_match_handler(AC_MATCH_t *m, AC_TEXT_t *txt, AC_REP_t *matc
|
|||||||
AC_PATTERN_t *pattern = m->patterns;
|
AC_PATTERN_t *pattern = m->patterns;
|
||||||
int i,start,end = m->position;
|
int i,start,end = m->position;
|
||||||
|
|
||||||
for(i=0; i < m->match_num; i++,pattern++) {
|
for(i=0; i < m->match_num; i++,pattern++) {
|
||||||
/*
|
/*
|
||||||
* See ac_automata_exact_match()
|
* See ac_automata_exact_match()
|
||||||
* The bit is set if the pattern exactly matches AND
|
* The bit is set if the pattern exactly matches AND
|
||||||
@@ -1785,7 +1785,7 @@ static int ac_domain_match_handler(AC_MATCH_t *m, AC_TEXT_t *txt, AC_REP_t *matc
|
|||||||
MATCH_DEBUG_INFO("[NDPI] Searching: [to search: %.*s/%u][pattern: %s%.*s%s/%u l:%u] %d-%d\n",
|
MATCH_DEBUG_INFO("[NDPI] Searching: [to search: %.*s/%u][pattern: %s%.*s%s/%u l:%u] %d-%d\n",
|
||||||
txt->length, txt->astring,(unsigned int) txt->length,
|
txt->length, txt->astring,(unsigned int) txt->length,
|
||||||
m->patterns[0].rep.from_start ? "^":"",
|
m->patterns[0].rep.from_start ? "^":"",
|
||||||
(unsigned int) pattern->length, pattern->astring,
|
(unsigned int) pattern->length, pattern->astring,
|
||||||
m->patterns[0].rep.at_end ? "$":"", (unsigned int) pattern->length,m->patterns[0].rep.level,
|
m->patterns[0].rep.at_end ? "$":"", (unsigned int) pattern->length,m->patterns[0].rep.level,
|
||||||
start,end);
|
start,end);
|
||||||
|
|
||||||
@@ -2304,8 +2304,8 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
|
|||||||
#endif /* NDPI_ENABLE_DEBUG_MESSAGES */
|
#endif /* NDPI_ENABLE_DEBUG_MESSAGES */
|
||||||
|
|
||||||
if(prefs & ndpi_enable_ja3_plus)
|
if(prefs & ndpi_enable_ja3_plus)
|
||||||
ndpi_str->enable_ja3_plus = 1;
|
ndpi_str->enable_ja3_plus = 1;
|
||||||
|
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
if(!(prefs & ndpi_dont_init_libgcrypt)) {
|
if(!(prefs & ndpi_dont_init_libgcrypt)) {
|
||||||
if(!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) {
|
if(!gcry_control (GCRYCTL_INITIALIZATION_FINISHED_P)) {
|
||||||
@@ -2373,7 +2373,7 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
|
|||||||
ndpi_str->custom_categories.ipAddresses = ndpi_patricia_new(32 /* IPv4 */);
|
ndpi_str->custom_categories.ipAddresses = ndpi_patricia_new(32 /* IPv4 */);
|
||||||
ndpi_str->custom_categories.ipAddresses_shadow = ndpi_patricia_new(32 /* IPv4 */);
|
ndpi_str->custom_categories.ipAddresses_shadow = ndpi_patricia_new(32 /* IPv4 */);
|
||||||
|
|
||||||
if(ndpi_str->host_automa.ac_automa)
|
if(ndpi_str->host_automa.ac_automa)
|
||||||
ac_automata_feature(ndpi_str->host_automa.ac_automa,AC_FEATURE_LC);
|
ac_automata_feature(ndpi_str->host_automa.ac_automa,AC_FEATURE_LC);
|
||||||
|
|
||||||
if(ndpi_str->custom_categories.hostnames.ac_automa)
|
if(ndpi_str->custom_categories.hostnames.ac_automa)
|
||||||
@@ -2396,7 +2396,7 @@ struct ndpi_detection_module_struct *ndpi_init_detection_module(ndpi_init_prefs
|
|||||||
|
|
||||||
/* ahocorasick debug */
|
/* ahocorasick debug */
|
||||||
/* Needed ac_automata_enable_debug(1) for show debug */
|
/* Needed ac_automata_enable_debug(1) for show debug */
|
||||||
if(ndpi_str->host_automa.ac_automa)
|
if(ndpi_str->host_automa.ac_automa)
|
||||||
ac_automata_name(ndpi_str->host_automa.ac_automa,"host",AC_FEATURE_DEBUG);
|
ac_automata_name(ndpi_str->host_automa.ac_automa,"host",AC_FEATURE_DEBUG);
|
||||||
|
|
||||||
if(ndpi_str->custom_categories.hostnames.ac_automa)
|
if(ndpi_str->custom_categories.hostnames.ac_automa)
|
||||||
@@ -2554,7 +2554,7 @@ static int ndpi_match_string_common(AC_AUTOMATA_t *automa, char *string_to_match
|
|||||||
if(category)
|
if(category)
|
||||||
*category = rc ? match.category : 0;
|
*category = rc ? match.category : 0;
|
||||||
|
|
||||||
if(breed)
|
if(breed)
|
||||||
*breed = rc ? match.breed : 0;
|
*breed = rc ? match.breed : 0;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@@ -2702,7 +2702,7 @@ void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_str) {
|
|||||||
|
|
||||||
if(ndpi_str->ip_risk_mask_ptree)
|
if(ndpi_str->ip_risk_mask_ptree)
|
||||||
ndpi_patricia_destroy((ndpi_patricia_tree_t *) ndpi_str->ip_risk_mask_ptree, free_ptree_data);
|
ndpi_patricia_destroy((ndpi_patricia_tree_t *) ndpi_str->ip_risk_mask_ptree, free_ptree_data);
|
||||||
|
|
||||||
if(ndpi_str->udpRoot != NULL)
|
if(ndpi_str->udpRoot != NULL)
|
||||||
ndpi_tdestroy(ndpi_str->udpRoot, ndpi_free);
|
ndpi_tdestroy(ndpi_str->udpRoot, ndpi_free);
|
||||||
if(ndpi_str->tcpRoot != NULL)
|
if(ndpi_str->tcpRoot != NULL)
|
||||||
@@ -2743,7 +2743,7 @@ void ndpi_exit_detection_module(struct ndpi_detection_module_struct *ndpi_str) {
|
|||||||
|
|
||||||
if(ndpi_str->custom_categories.ipAddresses_shadow != NULL)
|
if(ndpi_str->custom_categories.ipAddresses_shadow != NULL)
|
||||||
ndpi_patricia_destroy((ndpi_patricia_tree_t *) ndpi_str->custom_categories.ipAddresses_shadow, free_ptree_data);
|
ndpi_patricia_destroy((ndpi_patricia_tree_t *) ndpi_str->custom_categories.ipAddresses_shadow, free_ptree_data);
|
||||||
|
|
||||||
if(ndpi_str->host_risk_mask_automa.ac_automa != NULL)
|
if(ndpi_str->host_risk_mask_automa.ac_automa != NULL)
|
||||||
ac_automata_release((AC_AUTOMATA_t *) ndpi_str->host_risk_mask_automa.ac_automa,
|
ac_automata_release((AC_AUTOMATA_t *) ndpi_str->host_risk_mask_automa.ac_automa,
|
||||||
1 /* free patterns strings memory */);
|
1 /* free patterns strings memory */);
|
||||||
@@ -2857,7 +2857,7 @@ u_int16_t ndpi_guess_protocol_id(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
if(((icmp_type >= 44) && (icmp_type <= 252))
|
if(((icmp_type >= 44) && (icmp_type <= 252))
|
||||||
|| (icmp_code > 15))
|
|| (icmp_code > 15))
|
||||||
ndpi_set_risk(ndpi_str, flow, NDPI_MALFORMED_PACKET);
|
ndpi_set_risk(ndpi_str, flow, NDPI_MALFORMED_PACKET);
|
||||||
|
|
||||||
if (flow->packet.payload_packet_len > sizeof(struct ndpi_icmphdr)) {
|
if (flow->packet.payload_packet_len > sizeof(struct ndpi_icmphdr)) {
|
||||||
flow->entropy = ndpi_entropy(flow->packet.payload + sizeof(struct ndpi_icmphdr),
|
flow->entropy = ndpi_entropy(flow->packet.payload + sizeof(struct ndpi_icmphdr),
|
||||||
flow->packet.payload_packet_len - sizeof(struct ndpi_icmphdr));
|
flow->packet.payload_packet_len - sizeof(struct ndpi_icmphdr));
|
||||||
@@ -2938,14 +2938,14 @@ char *strsep(char **sp, char *sep) {
|
|||||||
/* ******************************************************************** */
|
/* ******************************************************************** */
|
||||||
|
|
||||||
int ndpi_add_ip_risk_mask(struct ndpi_detection_module_struct *ndpi_str,
|
int ndpi_add_ip_risk_mask(struct ndpi_detection_module_struct *ndpi_str,
|
||||||
char *ip, ndpi_risk mask) {
|
char *ip, ndpi_risk mask) {
|
||||||
char *saveptr, *addr = strtok_r(ip, "/", &saveptr);
|
char *saveptr, *addr = strtok_r(ip, "/", &saveptr);
|
||||||
|
|
||||||
if(addr) {
|
if(addr) {
|
||||||
char *cidr = strtok_r(NULL, "\n", &saveptr);
|
char *cidr = strtok_r(NULL, "\n", &saveptr);
|
||||||
struct in_addr pin;
|
struct in_addr pin;
|
||||||
ndpi_patricia_node_t *node;
|
ndpi_patricia_node_t *node;
|
||||||
|
|
||||||
pin.s_addr = inet_addr(addr);
|
pin.s_addr = inet_addr(addr);
|
||||||
/* FIX: Add IPv6 support */
|
/* FIX: Add IPv6 support */
|
||||||
if((node = add_to_ptree(ndpi_str->ip_risk_mask_ptree, AF_INET,
|
if((node = add_to_ptree(ndpi_str->ip_risk_mask_ptree, AF_INET,
|
||||||
@@ -2976,16 +2976,16 @@ int ndpi_add_host_risk_mask(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
case '\'':
|
case '\'':
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
host = &host[1];
|
host = &host[1];
|
||||||
len = strlen(host);
|
len = strlen(host);
|
||||||
if(len > 0)
|
if(len > 0)
|
||||||
host[len-1] = '\0';
|
host[len-1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
host_dup = ndpi_strdup(host);
|
host_dup = ndpi_strdup(host);
|
||||||
if(!host_dup)
|
if(!host_dup)
|
||||||
return(-1);
|
return(-1);
|
||||||
@@ -3002,10 +3002,10 @@ int ndpi_add_host_risk_mask(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
ac_pattern.rep.dot = memchr(host,'.',len) != NULL;
|
ac_pattern.rep.dot = memchr(host,'.',len) != NULL;
|
||||||
|
|
||||||
rc = ac_automata_add(ndpi_str->host_risk_mask_automa.ac_automa, &ac_pattern);
|
rc = ac_automata_add(ndpi_str->host_risk_mask_automa.ac_automa, &ac_pattern);
|
||||||
|
|
||||||
if(rc != ACERR_SUCCESS) {
|
if(rc != ACERR_SUCCESS) {
|
||||||
ndpi_free(host_dup);
|
ndpi_free(host_dup);
|
||||||
|
|
||||||
if(rc != ACERR_DUPLICATE_PATTERN)
|
if(rc != ACERR_DUPLICATE_PATTERN)
|
||||||
return (-2);
|
return (-2);
|
||||||
}
|
}
|
||||||
@@ -3030,7 +3030,7 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_str, char *rule,
|
|||||||
|
|
||||||
if(!rule_type) {
|
if(!rule_type) {
|
||||||
NDPI_LOG_ERR(ndpi_str, "Invalid rule '%s'\n", rule);
|
NDPI_LOG_ERR(ndpi_str, "Invalid rule '%s'\n", rule);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
key = strtok(NULL, "=");
|
key = strtok(NULL, "=");
|
||||||
@@ -3040,7 +3040,7 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_str, char *rule,
|
|||||||
|
|
||||||
if(mask) {
|
if(mask) {
|
||||||
ndpi_risk risk_mask = (ndpi_risk)atoll(mask);
|
ndpi_risk risk_mask = (ndpi_risk)atoll(mask);
|
||||||
|
|
||||||
if(!strcmp(rule_type, "ip_risk_mask")) {
|
if(!strcmp(rule_type, "ip_risk_mask")) {
|
||||||
return(ndpi_add_ip_risk_mask(ndpi_str, key, risk_mask));
|
return(ndpi_add_ip_risk_mask(ndpi_str, key, risk_mask));
|
||||||
} else if(!strcmp(rule_type, "host_risk_mask")) {
|
} else if(!strcmp(rule_type, "host_risk_mask")) {
|
||||||
@@ -3048,7 +3048,7 @@ int ndpi_handle_rule(struct ndpi_detection_module_struct *ndpi_str, char *rule,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NDPI_LOG_ERR(ndpi_str, "Unknown rule '%s'\n", rule);
|
NDPI_LOG_ERR(ndpi_str, "Unknown rule '%s'\n", rule);
|
||||||
return(-1);
|
return(-1);
|
||||||
} else
|
} else
|
||||||
@@ -3226,7 +3226,7 @@ static int ndpi_load_risky_domain(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
if(!ndpi_str->risky_domain_automa.ac_automa)
|
if(!ndpi_str->risky_domain_automa.ac_automa)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return ndpi_string_to_automa(ndpi_str, (AC_AUTOMATA_t *)ndpi_str->risky_domain_automa.ac_automa,
|
return ndpi_string_to_automa(ndpi_str, (AC_AUTOMATA_t *)ndpi_str->risky_domain_automa.ac_automa,
|
||||||
domain_name, 1, 0, 0, 0, 1); /* domain, protocol, category, breed, level , at_end */
|
domain_name, 1, 0, 0, 0, 1); /* domain, protocol, category, breed, level , at_end */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4302,19 +4302,19 @@ void ndpi_free_flow_data(struct ndpi_flow_struct* flow) {
|
|||||||
flow_is_proto(flow, NDPI_PROTOCOL_MAIL_IMAPS)) {
|
flow_is_proto(flow, NDPI_PROTOCOL_MAIL_IMAPS)) {
|
||||||
if(flow->protos.tls_quic_stun.tls_quic.server_names)
|
if(flow->protos.tls_quic_stun.tls_quic.server_names)
|
||||||
ndpi_free(flow->protos.tls_quic_stun.tls_quic.server_names);
|
ndpi_free(flow->protos.tls_quic_stun.tls_quic.server_names);
|
||||||
|
|
||||||
if(flow->protos.tls_quic_stun.tls_quic.alpn)
|
if(flow->protos.tls_quic_stun.tls_quic.alpn)
|
||||||
ndpi_free(flow->protos.tls_quic_stun.tls_quic.alpn);
|
ndpi_free(flow->protos.tls_quic_stun.tls_quic.alpn);
|
||||||
|
|
||||||
if(flow->protos.tls_quic_stun.tls_quic.tls_supported_versions)
|
if(flow->protos.tls_quic_stun.tls_quic.tls_supported_versions)
|
||||||
ndpi_free(flow->protos.tls_quic_stun.tls_quic.tls_supported_versions);
|
ndpi_free(flow->protos.tls_quic_stun.tls_quic.tls_supported_versions);
|
||||||
|
|
||||||
if(flow->protos.tls_quic_stun.tls_quic.issuerDN)
|
if(flow->protos.tls_quic_stun.tls_quic.issuerDN)
|
||||||
ndpi_free(flow->protos.tls_quic_stun.tls_quic.issuerDN);
|
ndpi_free(flow->protos.tls_quic_stun.tls_quic.issuerDN);
|
||||||
|
|
||||||
if(flow->protos.tls_quic_stun.tls_quic.subjectDN)
|
if(flow->protos.tls_quic_stun.tls_quic.subjectDN)
|
||||||
ndpi_free(flow->protos.tls_quic_stun.tls_quic.subjectDN);
|
ndpi_free(flow->protos.tls_quic_stun.tls_quic.subjectDN);
|
||||||
|
|
||||||
if(flow->protos.tls_quic_stun.tls_quic.encrypted_sni.esni)
|
if(flow->protos.tls_quic_stun.tls_quic.encrypted_sni.esni)
|
||||||
ndpi_free(flow->protos.tls_quic_stun.tls_quic.encrypted_sni.esni);
|
ndpi_free(flow->protos.tls_quic_stun.tls_quic.encrypted_sni.esni);
|
||||||
}
|
}
|
||||||
@@ -4815,7 +4815,7 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
|
|||||||
if(ndpi_str->mining_cache && flow->packet.iph) {
|
if(ndpi_str->mining_cache && flow->packet.iph) {
|
||||||
u_int16_t cached_proto;
|
u_int16_t cached_proto;
|
||||||
u_int32_t key = flow->packet.iph->saddr + flow->packet.iph->daddr;
|
u_int32_t key = flow->packet.iph->saddr + flow->packet.iph->daddr;
|
||||||
|
|
||||||
if(ndpi_lru_find_cache(ndpi_str->mining_cache, key,
|
if(ndpi_lru_find_cache(ndpi_str->mining_cache, key,
|
||||||
&cached_proto, 0 /* Don't remove it as it can be used for other connections */)) {
|
&cached_proto, 0 /* Don't remove it as it can be used for other connections */)) {
|
||||||
ndpi_set_detected_protocol(ndpi_str, flow, cached_proto, NDPI_PROTOCOL_UNKNOWN);
|
ndpi_set_detected_protocol(ndpi_str, flow, cached_proto, NDPI_PROTOCOL_UNKNOWN);
|
||||||
@@ -4823,7 +4823,7 @@ ndpi_protocol ndpi_detection_giveup(struct ndpi_detection_module_struct *ndpi_st
|
|||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: add the remaining stage_XXXX protocols */
|
/* TODO: add the remaining stage_XXXX protocols */
|
||||||
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
|
if(flow->detected_protocol_stack[0] == NDPI_PROTOCOL_UNKNOWN) {
|
||||||
u_int16_t guessed_protocol_id = NDPI_PROTOCOL_UNKNOWN, guessed_host_protocol_id = NDPI_PROTOCOL_UNKNOWN;
|
u_int16_t guessed_protocol_id = NDPI_PROTOCOL_UNKNOWN, guessed_host_protocol_id = NDPI_PROTOCOL_UNKNOWN;
|
||||||
@@ -5224,7 +5224,7 @@ static void ndpi_reconcile_protocols(struct ndpi_detection_module_struct *ndpi_s
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// printf("====>> %u.%u [%u]\n", ret->master_protocol, ret->app_protocol, flow->detected_protocol_stack[0]);
|
// printf("====>> %u.%u [%u]\n", ret->master_protocol, ret->app_protocol, flow->detected_protocol_stack[0]);
|
||||||
|
|
||||||
switch(ret->app_protocol) {
|
switch(ret->app_protocol) {
|
||||||
/*
|
/*
|
||||||
Skype for a host doing MS Teams means MS Teams
|
Skype for a host doing MS Teams means MS Teams
|
||||||
@@ -5418,7 +5418,7 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
|
|
||||||
if(flow->num_processed_pkts > NDPI_MAX_NUM_PKTS_PER_FLOW_TO_DISSECT)
|
if(flow->num_processed_pkts > NDPI_MAX_NUM_PKTS_PER_FLOW_TO_DISSECT)
|
||||||
return(ret); /* Avoid spending too much time with this flow */
|
return(ret); /* Avoid spending too much time with this flow */
|
||||||
|
|
||||||
/* Init default */
|
/* Init default */
|
||||||
ret.master_protocol = flow->detected_protocol_stack[1],
|
ret.master_protocol = flow->detected_protocol_stack[1],
|
||||||
ret.app_protocol = flow->detected_protocol_stack[0];
|
ret.app_protocol = flow->detected_protocol_stack[0];
|
||||||
@@ -5536,7 +5536,7 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
ret.master_protocol = ret.app_protocol;
|
ret.master_protocol = ret.app_protocol;
|
||||||
ret.app_protocol = flow->guessed_host_protocol_id;
|
ret.app_protocol = flow->guessed_host_protocol_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((!flow->risk_checked)
|
if((!flow->risk_checked)
|
||||||
&& ((ret.master_protocol != NDPI_PROTOCOL_UNKNOWN) || (ret.app_protocol != NDPI_PROTOCOL_UNKNOWN))
|
&& ((ret.master_protocol != NDPI_PROTOCOL_UNKNOWN) || (ret.app_protocol != NDPI_PROTOCOL_UNKNOWN))
|
||||||
) {
|
) {
|
||||||
@@ -5574,11 +5574,11 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
if(default_ports[i] == dport) {
|
if(default_ports[i] == dport) {
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
if(!found)
|
if(!found)
|
||||||
ndpi_set_risk(ndpi_str, flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT);
|
ndpi_set_risk(ndpi_str, flow, NDPI_KNOWN_PROTOCOL_ON_NON_STANDARD_PORT);
|
||||||
}
|
}
|
||||||
} else if((!ndpi_is_ntop_protocol(&ret)) && default_ports && (default_ports[0] != 0)) {
|
} else if((!ndpi_is_ntop_protocol(&ret)) && default_ports && (default_ports[0] != 0)) {
|
||||||
u_int8_t found = 0, i, num_loops = 0;
|
u_int8_t found = 0, i, num_loops = 0;
|
||||||
@@ -5611,7 +5611,7 @@ ndpi_protocol ndpi_detection_process_packet(struct ndpi_detection_module_struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
ndpi_reconcile_protocols(ndpi_str, flow, &ret);
|
ndpi_reconcile_protocols(ndpi_str, flow, &ret);
|
||||||
|
|
||||||
if(num_calls == 0)
|
if(num_calls == 0)
|
||||||
flow->fail_with_unknown = 1;
|
flow->fail_with_unknown = 1;
|
||||||
|
|
||||||
@@ -5894,7 +5894,7 @@ void ndpi_parse_packet_line_info(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
|
|
||||||
packet->http_num_headers++;
|
packet->http_num_headers++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* "Content-Type:" header line in HTTP. */
|
/* "Content-Type:" header line in HTTP. */
|
||||||
if(packet->line[packet->parsed_lines].len > 14 &&
|
if(packet->line[packet->parsed_lines].len > 14 &&
|
||||||
(strncasecmp((const char *) packet->line[packet->parsed_lines].ptr, "Content-Type: ", 14) == 0 ||
|
(strncasecmp((const char *) packet->line[packet->parsed_lines].ptr, "Content-Type: ", 14) == 0 ||
|
||||||
@@ -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() {
|
||||||
@@ -6756,7 +6812,7 @@ void ndpi_dump_risks_score() {
|
|||||||
|
|
||||||
printf("%3s %-48s %-8s %s %-8s %-8s\n",
|
printf("%3s %-48s %-8s %s %-8s %-8s\n",
|
||||||
"Id", "Risk", "Severity", "Score", "CliScore", "SrvScore");
|
"Id", "Risk", "Severity", "Score", "CliScore", "SrvScore");
|
||||||
|
|
||||||
for(i = 1; i < NDPI_MAX_RISK; i++) {
|
for(i = 1; i < NDPI_MAX_RISK; i++) {
|
||||||
ndpi_risk_enum r = (ndpi_risk_enum)i;
|
ndpi_risk_enum r = (ndpi_risk_enum)i;
|
||||||
ndpi_risk risk = (uint64_t)2 << (r-1);
|
ndpi_risk risk = (uint64_t)2 << (r-1);
|
||||||
@@ -6918,7 +6974,7 @@ static u_int16_t ndpi_automa_match_string_subprotocol(struct ndpi_detection_modu
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ****************************************************** */
|
/* ****************************************************** */
|
||||||
|
|
||||||
void ndpi_check_subprotocol_risk(struct ndpi_detection_module_struct *ndpi_str,
|
void ndpi_check_subprotocol_risk(struct ndpi_detection_module_struct *ndpi_str,
|
||||||
struct ndpi_flow_struct *flow, u_int16_t subprotocol_id) {
|
struct ndpi_flow_struct *flow, u_int16_t subprotocol_id) {
|
||||||
switch(subprotocol_id) {
|
switch(subprotocol_id) {
|
||||||
@@ -7367,10 +7423,10 @@ int ndpi_ptree_match_addr(ndpi_ptree_t *tree,
|
|||||||
/* Based on djb2 hash - http://www.cse.yorku.ca/~oz/hash.html */
|
/* Based on djb2 hash - http://www.cse.yorku.ca/~oz/hash.html */
|
||||||
u_int32_t ndpi_quick_hash(unsigned char *str, u_int str_len) {
|
u_int32_t ndpi_quick_hash(unsigned char *str, u_int str_len) {
|
||||||
u_int32_t hash = 5381, i;
|
u_int32_t hash = 5381, i;
|
||||||
|
|
||||||
for(i=0; i<str_len; i++)
|
for(i=0; i<str_len; i++)
|
||||||
hash = ((hash << 5) + hash) + str[i]; /* hash * 33 + str[i] */
|
hash = ((hash << 5) + hash) + str[i]; /* hash * 33 + str[i] */
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7393,7 +7449,7 @@ static int enough(int a, int b) {
|
|||||||
if(a == 0) return(1);
|
if(a == 0) return(1);
|
||||||
|
|
||||||
if(b > (((a+1)*percentage)/100)) return(1);
|
if(b > (((a+1)*percentage)/100)) return(1);
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7450,15 +7506,15 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
if(ndpi_dga_function != NULL) {
|
if(ndpi_dga_function != NULL) {
|
||||||
/* A custom DGA function is defined */
|
/* A custom DGA function is defined */
|
||||||
int rc = ndpi_dga_function(name, is_hostname);
|
int rc = ndpi_dga_function(name, is_hostname);
|
||||||
|
|
||||||
if(rc) {
|
if(rc) {
|
||||||
if(flow) {
|
if(flow) {
|
||||||
ndpi_set_risk(ndpi_str, flow, NDPI_SUSPICIOUS_DGA_DOMAIN);
|
ndpi_set_risk(ndpi_str, flow, NDPI_SUSPICIOUS_DGA_DOMAIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(rc);
|
return(rc);
|
||||||
} else {
|
} else {
|
||||||
int len, rc = 0, trigram_char_skip = 0;
|
int len, rc = 0, trigram_char_skip = 0;
|
||||||
u_int8_t max_num_char_repetitions = 0, last_char = 0, num_char_repetitions = 0, num_dots = 0, num_trigram_dots = 0;
|
u_int8_t max_num_char_repetitions = 0, last_char = 0, num_char_repetitions = 0, num_dots = 0, num_trigram_dots = 0;
|
||||||
u_int8_t max_domain_element_len = 0, curr_domain_element_len = 0, first_element_is_numeric = 1;
|
u_int8_t max_domain_element_len = 0, curr_domain_element_len = 0, first_element_is_numeric = 1;
|
||||||
@@ -7473,13 +7529,13 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
|| (endsWith(name, ".home", 5))
|
|| (endsWith(name, ".home", 5))
|
||||||
)
|
)
|
||||||
return(0);
|
return(0);
|
||||||
|
|
||||||
if(flow && (flow->detected_protocol_stack[1] != NDPI_PROTOCOL_UNKNOWN))
|
if(flow && (flow->detected_protocol_stack[1] != NDPI_PROTOCOL_UNKNOWN))
|
||||||
return(0); /* Ignore DGA check for protocols already fully detected */
|
return(0); /* Ignore DGA check for protocols already fully detected */
|
||||||
|
|
||||||
if(strncmp(name, "www.", 4) == 0)
|
if(strncmp(name, "www.", 4) == 0)
|
||||||
name = &name[4];
|
name = &name[4];
|
||||||
|
|
||||||
if(ndpi_verbose_dga_detection)
|
if(ndpi_verbose_dga_detection)
|
||||||
printf("[DGA check] %s\n", name);
|
printf("[DGA check] %s\n", name);
|
||||||
|
|
||||||
@@ -7511,26 +7567,26 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
if(!isdigit(tmp[j]))
|
if(!isdigit(tmp[j]))
|
||||||
first_element_is_numeric = 0;
|
first_element_is_numeric = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ndpi_is_vowel(tmp[j]))
|
if(ndpi_is_vowel(tmp[j]))
|
||||||
num_vowels++;
|
num_vowels++;
|
||||||
|
|
||||||
if(last_char == tmp[j]) {
|
if(last_char == tmp[j]) {
|
||||||
if(++num_char_repetitions > max_num_char_repetitions)
|
if(++num_char_repetitions > max_num_char_repetitions)
|
||||||
max_num_char_repetitions = num_char_repetitions;
|
max_num_char_repetitions = num_char_repetitions;
|
||||||
} else
|
} else
|
||||||
num_char_repetitions = 1, last_char = tmp[j];
|
num_char_repetitions = 1, last_char = tmp[j];
|
||||||
|
|
||||||
if(isdigit(tmp[j])) {
|
if(isdigit(tmp[j])) {
|
||||||
num_digits++;
|
num_digits++;
|
||||||
|
|
||||||
if(((j+2)<(u_int)len) && isdigit(tmp[j+1]) && (tmp[j+2] == '.')) {
|
if(((j+2)<(u_int)len) && isdigit(tmp[j+1]) && (tmp[j+2] == '.')) {
|
||||||
/* Check if there are too many digits */
|
/* Check if there are too many digits */
|
||||||
if(num_digits < 4)
|
if(num_digits < 4)
|
||||||
return(0); /* Double digits */
|
return(0); /* Double digits */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(tmp[j]) {
|
switch(tmp[j]) {
|
||||||
case '.':
|
case '.':
|
||||||
case '-':
|
case '-':
|
||||||
@@ -7588,7 +7644,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
- https://www.akamai.com/uk/en/multimedia/documents/state-of-the-internet/ddos-reflection-netbios-name-server-rpc-portmap-sentinel-udp-threat-advisory.pdf
|
- https://www.akamai.com/uk/en/multimedia/documents/state-of-the-internet/ddos-reflection-netbios-name-server-rpc-portmap-sentinel-udp-threat-advisory.pdf
|
||||||
- http://ubiqx.org/cifs/NetBIOS.html
|
- http://ubiqx.org/cifs/NetBIOS.html
|
||||||
*/
|
*/
|
||||||
|| ((max_domain_element_len >= 19 /* word too long. Example bbcbedxhgjmdobdprmen.com */) && ((num_char_repetitions > 1) || (num_digits > 1)))
|
|| ((max_domain_element_len >= 19 /* word too long. Example bbcbedxhgjmdobdprmen.com */) && ((num_char_repetitions > 1) || (num_digits > 1)))
|
||||||
) {
|
) {
|
||||||
if(flow) {
|
if(flow) {
|
||||||
ndpi_set_risk(ndpi_str, flow, NDPI_SUSPICIOUS_DGA_DOMAIN);
|
ndpi_set_risk(ndpi_str, flow, NDPI_SUSPICIOUS_DGA_DOMAIN);
|
||||||
@@ -7614,7 +7670,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
printf("-> word(%s) [%s][len: %u]\n", word, name, (unsigned int)strlen(word));
|
printf("-> word(%s) [%s][len: %u]\n", word, name, (unsigned int)strlen(word));
|
||||||
|
|
||||||
trigram_char_skip = 0;
|
trigram_char_skip = 0;
|
||||||
|
|
||||||
for(i = 0; word[i+1] != '\0'; i++) {
|
for(i = 0; word[i+1] != '\0'; i++) {
|
||||||
switch(word[i]) {
|
switch(word[i]) {
|
||||||
case '-':
|
case '-':
|
||||||
@@ -7659,7 +7715,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
if((num_trigram_dots < 2) && (word[i+2] != '\0')) {
|
if((num_trigram_dots < 2) && (word[i+2] != '\0')) {
|
||||||
if(ndpi_verbose_dga_detection)
|
if(ndpi_verbose_dga_detection)
|
||||||
printf("***> %s [trigram_char_skip: %u]\n", &word[i], trigram_char_skip);
|
printf("***> %s [trigram_char_skip: %u]\n", &word[i], trigram_char_skip);
|
||||||
|
|
||||||
if(ndpi_is_trigram_char(word[i]) && ndpi_is_trigram_char(word[i+1]) && ndpi_is_trigram_char(word[i+2])) {
|
if(ndpi_is_trigram_char(word[i]) && ndpi_is_trigram_char(word[i+1]) && ndpi_is_trigram_char(word[i+2])) {
|
||||||
if(trigram_char_skip) {
|
if(trigram_char_skip) {
|
||||||
trigram_char_skip--;
|
trigram_char_skip--;
|
||||||
@@ -7670,14 +7726,14 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
num_trigram_found++, trigram_char_skip = 2 /* 1 char overlap */;
|
num_trigram_found++, trigram_char_skip = 2 /* 1 char overlap */;
|
||||||
else if(ndpi_verbose_dga_detection)
|
else if(ndpi_verbose_dga_detection)
|
||||||
printf("[NDPI] NO Trigram %c%c%c\n", word[i], word[i+1], word[i+2]);
|
printf("[NDPI] NO Trigram %c%c%c\n", word[i], word[i+1], word[i+2]);
|
||||||
|
|
||||||
/* Count vowels */
|
/* Count vowels */
|
||||||
num_trigram_vowels += ndpi_is_vowel(word[i]) + ndpi_is_vowel(word[i+1]) + ndpi_is_vowel(word[i+2]);
|
num_trigram_vowels += ndpi_is_vowel(word[i]) + ndpi_is_vowel(word[i+1]) + ndpi_is_vowel(word[i+2]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(word[i] == '.')
|
if(word[i] == '.')
|
||||||
num_trigram_dots++;
|
num_trigram_dots++;
|
||||||
|
|
||||||
trigram_char_skip = 0;
|
trigram_char_skip = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7695,7 +7751,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
else
|
else
|
||||||
rc = 1;
|
rc = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(num_bigram_checks
|
if(num_bigram_checks
|
||||||
&& (num_dots > 0)
|
&& (num_dots > 0)
|
||||||
&& ((num_found == 0) || ((num_digits > 5) && (num_words <= 3))
|
&& ((num_found == 0) || ((num_digits > 5) && (num_words <= 3))
|
||||||
@@ -7713,7 +7769,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
|
|
||||||
if(num_dash > 2)
|
if(num_dash > 2)
|
||||||
rc = 0;
|
rc = 0;
|
||||||
|
|
||||||
if(ndpi_verbose_dga_detection) {
|
if(ndpi_verbose_dga_detection) {
|
||||||
if(rc)
|
if(rc)
|
||||||
printf("DGA %s [num_found: %u][num_impossible: %u]\n",
|
printf("DGA %s [num_found: %u][num_impossible: %u]\n",
|
||||||
@@ -7730,7 +7786,7 @@ int ndpi_check_dga_name(struct ndpi_detection_module_struct *ndpi_str,
|
|||||||
return(rc);
|
return(rc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ******************************************************************** */
|
/* ******************************************************************** */
|
||||||
|
|
||||||
ndpi_risk_info* ndpi_risk2severity(ndpi_risk_enum risk) {
|
ndpi_risk_info* ndpi_risk2severity(ndpi_risk_enum risk) {
|
||||||
|
|||||||
@@ -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));
|
||||||
|
|||||||
Reference in New Issue
Block a user