41
41
#define DETECT_CLASSCONFIG_REGEX "^\\s*config\\s*classification\\s*:\\s*([a-zA-Z][a-zA-Z0-9-_]*)\\s*,\\s*(.+)\\s*,\\s*(\\d+)\\s*$"
43
43
/* Default path for the classification.config file */
44
#define SC_CLASS_CONF_DEF_CONF_FILEPATH "classification.config"
44
#define SC_CLASS_CONF_DEF_CONF_FILEPATH CONFIG_DIR "/classification.config"
46
46
/* Holds a pointer to the default path for the classification.config file */
47
47
static const char *default_file_path = SC_CLASS_CONF_DEF_CONF_FILEPATH;
153
160
* \brief Releases resources used by the Classification Config API.
155
static void SCClassConfDeInitContext(DetectEngineCtx *de_ctx)
162
static void SCClassConfDeInitLocalResources(DetectEngineCtx *de_ctx)
159
166
default_file_path = SC_CLASS_CONF_DEF_CONF_FILEPATH;
172
if (regex_study != NULL) {
173
pcre_free(regex_study);
181
* \brief Releases resources used by the Classification Config API.
183
void SCClassConfDeInitContext(DetectEngineCtx *de_ctx)
185
if (de_ctx->class_conf_ht != NULL)
186
HashTableFree(de_ctx->class_conf_ht);
188
de_ctx->class_conf_ht = NULL;
486
515
void SCClassConfLoadClassficationConfigFile(DetectEngineCtx *de_ctx)
488
if (SCClassConfInitContext(de_ctx) == -1) {
489
SCLogDebug("Error initializing classification config API");
517
if (SCClassConfInitContextAndLocalResources(de_ctx) == -1) {
518
SCLogInfo("Please check the \"classification-file\" option in your suricata.yaml file");
493
522
SCClassConfParseFile(de_ctx);
494
SCClassConfDeInitContext(de_ctx);
523
SCClassConfDeInitLocalResources(de_ctx);
529
* \brief Gets the classtype from the corresponding hash table stored
530
* in the Detection Engine Context's class conf ht, given the
533
* \param ct_name Pointer to the classtype name that has to be looked up.
534
* \param de_ctx Pointer to the Detection Engine Context.
536
* \retval lookup_ct_info Pointer to the SCClassConfClasstype instance from
537
* the hash table on success; NULL on failure.
539
SCClassConfClasstype *SCClassConfGetClasstype(const char *ct_name,
540
DetectEngineCtx *de_ctx)
542
SCClassConfClasstype *ct_info = SCClassConfAllocClasstype(0, ct_name, NULL,
546
SCClassConfClasstype *lookup_ct_info = HashTableLookup(de_ctx->class_conf_ht,
549
SCClassConfDeAllocClasstype(ct_info);
550
return lookup_ct_info;
500
553
/*----------------------------------Unittests---------------------------------*/
684
736
result = (de_ctx->class_conf_ht->count == 3);
686
ct = SCClassConfAllocClasstype(0, "unknown", NULL, 0);
687
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) != NULL);
688
SCClassConfDeAllocClasstype(ct);
690
ct = SCClassConfAllocClasstype(0, "unKnoWn", NULL, 0);
691
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) != NULL);
692
SCClassConfDeAllocClasstype(ct);
694
ct = SCClassConfAllocClasstype(0, "bamboo", NULL, 0);
695
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) == NULL);
696
SCClassConfDeAllocClasstype(ct);
698
ct = SCClassConfAllocClasstype(0, "bad-unknown", NULL, 0);
699
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) != NULL);
700
SCClassConfDeAllocClasstype(ct);
702
ct = SCClassConfAllocClasstype(0, "BAD-UNKnOWN", NULL, 0);
703
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) != NULL);
704
SCClassConfDeAllocClasstype(ct);
706
ct = SCClassConfAllocClasstype(0, "bed-unknown", NULL, 0);
707
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) == NULL);
708
SCClassConfDeAllocClasstype(ct);
738
result &= (SCClassConfGetClasstype("unknown", de_ctx) != NULL);
739
result &= (SCClassConfGetClasstype("unKnoWn", de_ctx) != NULL);
740
result &= (SCClassConfGetClasstype("bamboo", de_ctx) == NULL);
741
result &= (SCClassConfGetClasstype("bad-unknown", de_ctx) != NULL);
742
result &= (SCClassConfGetClasstype("BAD-UNKnOWN", de_ctx) != NULL);
743
result &= (SCClassConfGetClasstype("bed-unknown", de_ctx) == NULL);
710
745
DetectEngineCtxFree(de_ctx);
736
770
result = (de_ctx->class_conf_ht->count == 0);
738
ct = SCClassConfAllocClasstype(0, "unknown", NULL, 0);
739
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) == NULL);
740
SCClassConfDeAllocClasstype(ct);
742
ct = SCClassConfAllocClasstype(0, "unKnoWn", NULL, 0);
743
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) == NULL);
744
SCClassConfDeAllocClasstype(ct);
746
ct = SCClassConfAllocClasstype(0, "bamboo", NULL, 0);
747
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) == NULL);
748
SCClassConfDeAllocClasstype(ct);
750
ct = SCClassConfAllocClasstype(0, "bad-unknown", NULL, 0);
751
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) == NULL);
752
SCClassConfDeAllocClasstype(ct);
754
ct = SCClassConfAllocClasstype(0, "BAD-UNKnOWN", NULL, 0);
755
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) == NULL);
756
SCClassConfDeAllocClasstype(ct);
758
ct = SCClassConfAllocClasstype(0, "bed-unknown", NULL, 0);
759
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) == NULL);
760
SCClassConfDeAllocClasstype(ct);
772
result &= (SCClassConfGetClasstype("unknown", de_ctx) == NULL);
773
result &= (SCClassConfGetClasstype("unKnoWn", de_ctx) == NULL);
774
result &= (SCClassConfGetClasstype("bamboo", de_ctx) == NULL);
775
result &= (SCClassConfGetClasstype("bad-unknown", de_ctx) == NULL);
776
result &= (SCClassConfGetClasstype("BAD-UNKnOWN", de_ctx) == NULL);
777
result &= (SCClassConfGetClasstype("bed-unknown", de_ctx) == NULL);
762
779
DetectEngineCtxFree(de_ctx);
787
803
result = (de_ctx->class_conf_ht->count == 3);
789
ct = SCClassConfAllocClasstype(0, "unknown", NULL, 0);
790
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) == NULL);
791
SCClassConfDeAllocClasstype(ct);
793
ct = SCClassConfAllocClasstype(0, "not-suspicious", NULL, 0);
794
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) != NULL);
795
SCClassConfDeAllocClasstype(ct);
797
ct = SCClassConfAllocClasstype(0, "bamboola1", NULL, 0);
798
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) != NULL);
799
SCClassConfDeAllocClasstype(ct);
801
ct = SCClassConfAllocClasstype(0, "bamboola1", NULL, 0);
802
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) != NULL);
803
SCClassConfDeAllocClasstype(ct);
805
ct = SCClassConfAllocClasstype(0, "BAMBOolA1", NULL, 0);
806
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) != NULL);
807
SCClassConfDeAllocClasstype(ct);
809
ct = SCClassConfAllocClasstype(0, "unkNOwn", NULL, 0);
810
result &= (HashTableLookup(de_ctx->class_conf_ht, ct, 0) == NULL);
811
SCClassConfDeAllocClasstype(ct);
805
result &= (SCClassConfGetClasstype("unknown", de_ctx) == NULL);
806
result &= (SCClassConfGetClasstype("not-suspicious", de_ctx) != NULL);
807
result &= (SCClassConfGetClasstype("bamboola1", de_ctx) != NULL);
808
result &= (SCClassConfGetClasstype("bamboola1", de_ctx) != NULL);
809
result &= (SCClassConfGetClasstype("BAMBOolA1", de_ctx) != NULL);
810
result &= (SCClassConfGetClasstype("unkNOwn", de_ctx) == NULL);
813
812
DetectEngineCtxFree(de_ctx);