42 #define DETECT_CLASSCONFIG_REGEX "^\\s*config\\s*classification\\s*:\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s*,\\s*(.+)\\s*,\\s*(\\d+)\\s*$"
45 #if defined OS_WIN32 || defined __CYGWIN__
46 #define SC_CLASS_CONF_DEF_CONF_FILEPATH CONFIG_DIR "\\\\classification.config"
48 #define SC_CLASS_CONF_DEF_CONF_FILEPATH CONFIG_DIR "/classification.config"
53 void *data2, uint16_t datalen2);
58 const char *classtype,
const char *classtype_desc,
int priority);
70 PCRE2_UCHAR errbuffer[256];
71 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
128 const char *filename = SCClassConfGetConfFilename(
de_ctx);
129 if ( (fd = fopen(filename,
"r")) == NULL) {
134 SCLogWarning(
"could not open: \"%s\": %s", filename, strerror(errno));
154 const char *log_filename = NULL;
157 char config_value[256];
158 snprintf(config_value,
sizeof(config_value),
163 if (
ConfGet(config_value, &log_filename) != 1) {
164 if (
ConfGet(
"classification-file", &log_filename) != 1) {
169 if (
ConfGet(
"classification-file", &log_filename) != 1) {
180 static void SCClassConfDeInitLocalResources(FILE *fd)
203 static char *SCClassConfStringToLowercase(
const char *
str)
205 char *new_str = NULL;
206 char *temp_str = NULL;
214 while (*temp_str !=
'\0') {
215 *temp_str =
u8_tolower((
unsigned char)*temp_str);
237 char ct_priority_str[16];
238 uint32_t ct_priority = 0;
239 uint16_t ct_id = index;
250 "classification.config file %s: \"%s\"",
251 SCClassConfGetConfFilename(
de_ctx), rawstr);
255 size_t copylen =
sizeof(ct_name);
257 ret = pcre2_substring_copy_bynumber(
260 SCLogInfo(
"pcre2_substring_copy_bynumber() failed");
265 copylen =
sizeof(ct_desc);
266 ret = pcre2_substring_copy_bynumber(
269 SCLogInfo(
"pcre2_substring_copy_bynumber() failed");
274 copylen =
sizeof(ct_priority_str);
275 ret = pcre2_substring_copy_bynumber(
278 SCLogInfo(
"pcre2_substring_copy_bynumber() failed");
286 ct_new = SCClassConfAllocClasstype(ct_id, ct_name, ct_desc, ct_priority);
293 if (ct_lookup == NULL) {
297 SCLogDebug(
"Duplicate classtype found inside classification.config");
321 static int SCClassConfIsLineBlankOrComment(
char *line)
323 while (*line !=
'\0') {
329 if (!isspace((
unsigned char)*line))
351 while (fgets(line,
sizeof(line), fd) != NULL) {
352 if (SCClassConfIsLineBlankOrComment(line))
364 SCLogInfo(
"tenant id %d: Added \"%d\" classification types from the classification file",
367 SCLogInfo(
"Added \"%d\" classification types from the classification file",
387 const char *classtype,
388 const char *classtype_desc,
393 if (classtype == NULL)
399 if ((ct->
classtype = SCClassConfStringToLowercase(classtype)) == NULL) {
400 SCClassConfDeAllocClasstype(ct);
404 if (classtype_desc != NULL &&
408 SCClassConfDeAllocClasstype(ct);
455 for (i = 0; i <
len; i++)
477 void *data2, uint16_t datalen2)
484 if (ct1 == NULL || ct2 == NULL)
494 SCLogDebug(
"Match found inside Classification-Config hash function");
509 SCClassConfDeAllocClasstype(ch);
526 fd = SCClassConfInitContextAndLocalResources(
de_ctx, fd);
533 SCLogError(
"please check the \"classification-file\" "
534 "option in your suricata.yaml file");
539 if (!SCClassConfParseFile(
de_ctx, fd)) {
540 SCLogWarning(
"Error loading classification configuration from %s",
541 SCClassConfGetConfFilename(
de_ctx));
545 SCClassConfDeInitLocalResources(fd);
564 char name[strlen(ct_name) + 1];
566 for (s = 0; s < strlen(ct_name); s++)
567 name[s] =
u8_tolower((
unsigned char)ct_name[s]);
573 return lookup_ct_info;
590 "config classification: nothing-wrong,Nothing Wrong With Us,3\n"
591 "config classification: unknown,Unknown are we,3\n"
592 "config classification: bad-unknown,We think it's bad, 2\n";
594 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
596 SCLogDebug(
"Error with SCFmemopen() called by Classification Config test code");
610 "config classification: not-suspicious,Not Suspicious Traffic,3\n"
611 "onfig classification: unknown,Unknown Traffic,3\n"
612 "config classification: _badunknown,Potentially Bad Traffic, 2\n"
613 "config classification: bamboola1,Unknown Traffic,3\n"
614 "config classification: misc-activity,Misc activity,-1\n"
615 "config classification: policy-violation,Potential Corporate "
616 "config classification: bamboola,Unknown Traffic,3\n";
618 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
620 SCLogDebug(
"Error with SCFmemopen() called by Classification Config test code");
634 "conig classification: not-suspicious,Not Suspicious Traffic,3\n"
635 "onfig classification: unknown,Unknown Traffic,3\n"
636 "config classification: _badunknown,Potentially Bad Traffic, 2\n"
637 "config classification: misc-activity,Misc activity,-1\n";
639 FILE *fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
641 SCLogDebug(
"Error with SCFmemopen() called by Classification Config test code");
650 static int SCClassConfTest01(
void)
676 static int SCClassConfTest02(
void)
701 static int SCClassConfTest03(
void)
719 static int SCClassConfTest04(
void)
752 static int SCClassConfTest05(
void)