|
|
|
|
@ -62,16 +62,31 @@ extern int run_mode;
|
|
|
|
|
static int DetectReplaceSetup(DetectEngineCtx *, Signature *, const char *);
|
|
|
|
|
void DetectReplaceRegisterTests(void);
|
|
|
|
|
|
|
|
|
|
static int DetectReplacePostMatch(ThreadVars *tv,
|
|
|
|
|
DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
Packet *p, const Signature *s, const SigMatchCtx *ctx);
|
|
|
|
|
|
|
|
|
|
void DetectReplaceRegister (void)
|
|
|
|
|
{
|
|
|
|
|
sigmatch_table[DETECT_REPLACE].name = "replace";
|
|
|
|
|
sigmatch_table[DETECT_REPLACE].Match = NULL;
|
|
|
|
|
sigmatch_table[DETECT_REPLACE].Match = DetectReplacePostMatch;
|
|
|
|
|
sigmatch_table[DETECT_REPLACE].Setup = DetectReplaceSetup;
|
|
|
|
|
sigmatch_table[DETECT_REPLACE].Free = NULL;
|
|
|
|
|
sigmatch_table[DETECT_REPLACE].RegisterTests = DetectReplaceRegisterTests;
|
|
|
|
|
sigmatch_table[DETECT_REPLACE].flags = (SIGMATCH_QUOTES_MANDATORY|SIGMATCH_HANDLE_NEGATION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int DetectReplacePostMatch(ThreadVars *tv,
|
|
|
|
|
DetectEngineThreadCtx *det_ctx,
|
|
|
|
|
Packet *p, const Signature *s, const SigMatchCtx *ctx)
|
|
|
|
|
{
|
|
|
|
|
if (det_ctx->replist) {
|
|
|
|
|
DetectReplaceExecuteInternal(p, det_ctx->replist);
|
|
|
|
|
det_ctx->replist = NULL;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int DetectReplaceSetup(DetectEngineCtx *de_ctx, Signature *s, const char *replacestr)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *content = NULL;
|
|
|
|
|
@ -139,7 +154,17 @@ int DetectReplaceSetup(DetectEngineCtx *de_ctx, Signature *s, const char *replac
|
|
|
|
|
*/
|
|
|
|
|
s->flags |= SIG_FLAG_REQUIRE_PACKET;
|
|
|
|
|
SCFree(content);
|
|
|
|
|
content = NULL;
|
|
|
|
|
|
|
|
|
|
SigMatch *sm = SigMatchAlloc();
|
|
|
|
|
if (unlikely(sm == NULL)) {
|
|
|
|
|
SCFree(ud->replace);
|
|
|
|
|
ud->replace = NULL;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
sm->type = DETECT_REPLACE;
|
|
|
|
|
sm->ctx = NULL;
|
|
|
|
|
SigMatchAppendSMToList(s, sm, DETECT_SM_LIST_POSTMATCH);
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
|