|
|
|
@ -24,11 +24,13 @@
|
|
|
|
|
//#include "util-mpm.h"
|
|
|
|
|
#include "util-error.h"
|
|
|
|
|
#include "util-hash.h"
|
|
|
|
|
#include "util-byte.h"
|
|
|
|
|
#include "util-debug.h"
|
|
|
|
|
|
|
|
|
|
#include "util-var-name.h"
|
|
|
|
|
#include "tm-modules.h"
|
|
|
|
|
|
|
|
|
|
static uint8_t DetectEngineCtxLoadConf(DetectEngineCtx *);
|
|
|
|
|
DetectEngineCtx *DetectEngineCtxInit(void) {
|
|
|
|
|
DetectEngineCtx *de_ctx;
|
|
|
|
|
|
|
|
|
@ -44,6 +46,7 @@ DetectEngineCtx *DetectEngineCtxInit(void) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
de_ctx->mpm_matcher = PatternMatchDefaultMatcher();
|
|
|
|
|
DetectEngineCtxLoadConf(de_ctx);
|
|
|
|
|
|
|
|
|
|
SigGroupHeadHashInit(de_ctx);
|
|
|
|
|
SigGroupHeadMpmHashInit(de_ctx);
|
|
|
|
@ -90,6 +93,299 @@ void DetectEngineCtxFree(DetectEngineCtx *de_ctx) {
|
|
|
|
|
//DetectPortPrintMemory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \brief Function that load DetectEngineCtx config for grouping sigs
|
|
|
|
|
* used by the engine
|
|
|
|
|
* \retval 0 if no config provided, 1 if config was provided
|
|
|
|
|
* and loaded successfuly
|
|
|
|
|
*/
|
|
|
|
|
static uint8_t DetectEngineCtxLoadConf(DetectEngineCtx *de_ctx) {
|
|
|
|
|
uint8_t profile = ENGINE_PROFILE_UNKNOWN;
|
|
|
|
|
char *de_ctx_profile = NULL;
|
|
|
|
|
|
|
|
|
|
const char *max_uniq_toclient_src_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_toclient_dst_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_toclient_sp_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_toclient_dp_groups_str = NULL;
|
|
|
|
|
|
|
|
|
|
const char *max_uniq_toserver_src_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_toserver_dst_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_toserver_sp_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_toserver_dp_groups_str = NULL;
|
|
|
|
|
|
|
|
|
|
const char *max_uniq_small_toclient_src_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_small_toclient_dst_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_small_toclient_sp_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_small_toclient_dp_groups_str = NULL;
|
|
|
|
|
|
|
|
|
|
const char *max_uniq_small_toserver_src_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_small_toserver_dst_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_small_toserver_sp_groups_str = NULL;
|
|
|
|
|
const char *max_uniq_small_toserver_dp_groups_str = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConfNode *de_ctx_custom = ConfGetNode("detect-engine");
|
|
|
|
|
ConfNode *opt = NULL;
|
|
|
|
|
|
|
|
|
|
if (de_ctx_custom != NULL) {
|
|
|
|
|
TAILQ_FOREACH(opt, &de_ctx_custom->head, next) {
|
|
|
|
|
if (strncmp(opt->val, "profile", 3) == 0) {
|
|
|
|
|
de_ctx_profile = opt->head.tqh_first->val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (de_ctx_profile != NULL) {
|
|
|
|
|
if (strncmp(de_ctx_profile, "low", 3) == 0) {
|
|
|
|
|
profile = ENGINE_PROFILE_LOW;
|
|
|
|
|
} else if (strncmp(de_ctx_profile, "medium", 6) == 0) {
|
|
|
|
|
profile = ENGINE_PROFILE_MEDIUM;
|
|
|
|
|
} else if (strncmp(de_ctx_profile, "high", 4) == 0) {
|
|
|
|
|
profile = ENGINE_PROFILE_HIGH;
|
|
|
|
|
} else if (strncmp(de_ctx_profile, "custom", 4) == 0) {
|
|
|
|
|
profile = ENGINE_PROFILE_CUSTOM;
|
|
|
|
|
}
|
|
|
|
|
SCLogInfo("Profile for detection engine groups is \"%s\"", de_ctx_profile);
|
|
|
|
|
} else {
|
|
|
|
|
SCLogInfo("Profile for detection engine groups not provided "
|
|
|
|
|
"at suricata.yaml. Using default (\"medium\").");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opt = NULL;
|
|
|
|
|
switch (profile) {
|
|
|
|
|
case ENGINE_PROFILE_LOW:
|
|
|
|
|
de_ctx->max_uniq_toclient_src_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toclient_dst_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toclient_sp_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toclient_dp_groups = 3;
|
|
|
|
|
de_ctx->max_uniq_toserver_src_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toserver_dst_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toserver_sp_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toserver_dp_groups = 3;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_src_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_dst_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_sp_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_dp_groups = 3;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_src_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_dst_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_sp_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_dp_groups = 3;
|
|
|
|
|
break;
|
|
|
|
|
case ENGINE_PROFILE_HIGH:
|
|
|
|
|
de_ctx->max_uniq_toclient_src_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_toclient_dst_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_toclient_sp_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_toclient_dp_groups = 10;
|
|
|
|
|
de_ctx->max_uniq_toserver_src_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_toserver_dst_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_toserver_sp_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_toserver_dp_groups = 30;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_src_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_dst_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_sp_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_dp_groups = 10;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_src_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_dst_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_sp_groups = 5;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_dp_groups = 10;
|
|
|
|
|
break;
|
|
|
|
|
case ENGINE_PROFILE_CUSTOM:
|
|
|
|
|
TAILQ_FOREACH(opt, &de_ctx_custom->head, next) {
|
|
|
|
|
if (strncmp(opt->val, "custom-values", 3) == 0) {
|
|
|
|
|
max_uniq_toclient_src_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "toclient_src_groups");
|
|
|
|
|
max_uniq_toclient_dst_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "toclient_dst_groups");
|
|
|
|
|
max_uniq_toclient_sp_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "toclient_sp_groups");
|
|
|
|
|
max_uniq_toclient_dp_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "toclient_dp_groups");
|
|
|
|
|
max_uniq_toserver_src_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "toserver_src_groups");
|
|
|
|
|
max_uniq_toserver_dst_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "toserver_dst_groups");
|
|
|
|
|
max_uniq_toserver_sp_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "toserver_sp_groups");
|
|
|
|
|
max_uniq_toserver_dp_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "toserver_dp_groups");
|
|
|
|
|
max_uniq_small_toclient_src_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "small_toclient_src_groups");
|
|
|
|
|
max_uniq_small_toclient_dst_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "small_toclient_dst_groups");
|
|
|
|
|
max_uniq_small_toclient_sp_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "small_toclient_sp_groups");
|
|
|
|
|
max_uniq_small_toclient_dp_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "small_toclient_dp_groups");
|
|
|
|
|
max_uniq_small_toserver_src_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "small_toserver_src_groups");
|
|
|
|
|
max_uniq_small_toserver_dst_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "small_toserver_dst_groups");
|
|
|
|
|
max_uniq_small_toserver_sp_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "small_toserver_sp_groups");
|
|
|
|
|
max_uniq_small_toserver_dp_groups_str = ConfNodeLookupChildValue
|
|
|
|
|
(opt->head.tqh_first, "small_toserver_dp_groups");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_toclient_src_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_toclient_src_groups, 10,
|
|
|
|
|
strlen(max_uniq_toclient_src_groups_str),
|
|
|
|
|
(const char *)max_uniq_toclient_src_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_toclient_src_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_toclient_src_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_toclient_dst_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_toclient_dst_groups, 10,
|
|
|
|
|
strlen(max_uniq_toclient_dst_groups_str),
|
|
|
|
|
(const char *)max_uniq_toclient_dst_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_toclient_dst_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_toclient_dst_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_toclient_sp_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_toclient_sp_groups, 10,
|
|
|
|
|
strlen(max_uniq_toclient_sp_groups_str),
|
|
|
|
|
(const char *)max_uniq_toclient_sp_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_toclient_sp_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_toclient_sp_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_toclient_dp_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_toclient_dp_groups, 10,
|
|
|
|
|
strlen(max_uniq_toclient_dp_groups_str),
|
|
|
|
|
(const char *)max_uniq_toclient_dp_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_toclient_dp_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_toclient_dp_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_toserver_src_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_toserver_src_groups, 10,
|
|
|
|
|
strlen(max_uniq_toserver_src_groups_str),
|
|
|
|
|
(const char *)max_uniq_toserver_src_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_toserver_src_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_toserver_src_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_toserver_dst_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_toserver_dst_groups, 10,
|
|
|
|
|
strlen(max_uniq_toserver_dst_groups_str),
|
|
|
|
|
(const char *)max_uniq_toserver_dst_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_toserver_dst_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_toserver_dst_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_toserver_sp_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_toserver_sp_groups, 10,
|
|
|
|
|
strlen(max_uniq_toserver_sp_groups_str),
|
|
|
|
|
(const char *)max_uniq_toserver_sp_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_toserver_sp_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_toserver_sp_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_toserver_dp_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_toserver_dp_groups, 10,
|
|
|
|
|
strlen(max_uniq_toserver_dp_groups_str),
|
|
|
|
|
(const char *)max_uniq_toserver_dp_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_toserver_dp_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_toserver_dp_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_small_toclient_src_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_small_toclient_src_groups, 10,
|
|
|
|
|
strlen(max_uniq_small_toclient_src_groups_str),
|
|
|
|
|
(const char *)max_uniq_small_toclient_src_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_small_toclient_src_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_small_toclient_src_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_small_toclient_dst_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_small_toclient_dst_groups, 10,
|
|
|
|
|
strlen(max_uniq_small_toclient_dst_groups_str),
|
|
|
|
|
(const char *)max_uniq_small_toclient_dst_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_small_toclient_dst_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_small_toclient_dst_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_small_toclient_sp_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_small_toclient_sp_groups, 10,
|
|
|
|
|
strlen(max_uniq_small_toclient_sp_groups_str),
|
|
|
|
|
(const char *)max_uniq_small_toclient_sp_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_small_toclient_sp_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_small_toclient_sp_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_small_toclient_dp_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_small_toclient_dp_groups, 10,
|
|
|
|
|
strlen(max_uniq_small_toclient_dp_groups_str),
|
|
|
|
|
(const char *)max_uniq_small_toclient_dp_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_small_toclient_dp_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_small_toclient_dp_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_small_toserver_src_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_small_toserver_src_groups, 10,
|
|
|
|
|
strlen(max_uniq_small_toserver_src_groups_str),
|
|
|
|
|
(const char *)max_uniq_small_toserver_src_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_small_toserver_src_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_small_toserver_src_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_small_toserver_dst_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_small_toserver_dst_groups, 10,
|
|
|
|
|
strlen(max_uniq_small_toserver_dst_groups_str),
|
|
|
|
|
(const char *)max_uniq_small_toserver_dst_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_small_toserver_dst_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_small_toserver_dst_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_small_toserver_sp_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_small_toserver_sp_groups, 10,
|
|
|
|
|
strlen(max_uniq_small_toserver_sp_groups_str),
|
|
|
|
|
(const char *)max_uniq_small_toserver_sp_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_small_toserver_sp_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_small_toserver_sp_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
if (max_uniq_small_toserver_dp_groups_str != NULL) {
|
|
|
|
|
if (ByteExtractStringUint16(&de_ctx->max_uniq_small_toserver_dp_groups, 10,
|
|
|
|
|
strlen(max_uniq_small_toserver_dp_groups_str),
|
|
|
|
|
(const char *)max_uniq_small_toserver_dp_groups_str) <= 0)
|
|
|
|
|
de_ctx->max_uniq_small_toserver_dp_groups = 2;
|
|
|
|
|
} else {
|
|
|
|
|
de_ctx->max_uniq_small_toserver_dp_groups = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
/* Default (or no config provided) is profile medium */
|
|
|
|
|
case ENGINE_PROFILE_MEDIUM:
|
|
|
|
|
case ENGINE_PROFILE_UNKNOWN:
|
|
|
|
|
default:
|
|
|
|
|
de_ctx->max_uniq_toclient_src_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toclient_dst_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toclient_sp_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toclient_dp_groups = 3;
|
|
|
|
|
|
|
|
|
|
de_ctx->max_uniq_toserver_src_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toserver_dst_groups = 4;
|
|
|
|
|
de_ctx->max_uniq_toserver_sp_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_toserver_dp_groups = 25;
|
|
|
|
|
|
|
|
|
|
de_ctx->max_uniq_small_toclient_src_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_dst_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_sp_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toclient_dp_groups = 2;
|
|
|
|
|
|
|
|
|
|
de_ctx->max_uniq_small_toserver_src_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_dst_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_sp_groups = 2;
|
|
|
|
|
de_ctx->max_uniq_small_toserver_dp_groups = 8;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (profile == ENGINE_PROFILE_UNKNOWN)
|
|
|
|
|
return 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* getting & (re)setting the internal sig i
|
|
|
|
|
*/
|
|
|
|
|