|
|
|
@ -518,488 +518,6 @@ int DetectFastPatternTest04(void)
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Checks that a fast_pattern is used in the mpm phase.
|
|
|
|
|
*/
|
|
|
|
|
int DetectFastPatternTest05(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *buf = (uint8_t *) "Oh strin1. But what "
|
|
|
|
|
"strin2. This is strings3. We strins_str4. we "
|
|
|
|
|
"have strins_string5";
|
|
|
|
|
uint16_t buflen = strlen((char *)buf);
|
|
|
|
|
Packet *p = NULL;
|
|
|
|
|
ThreadVars th_v;
|
|
|
|
|
DetectEngineThreadCtx *det_ctx = NULL;
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
memset(&th_v, 0, sizeof(th_v));
|
|
|
|
|
|
|
|
|
|
p = UTHBuildPacket(buf,buflen,IPPROTO_TCP);
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
|
|
|
|
|
if (de_ctx == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
de_ctx->flags |= DE_QUIET;
|
|
|
|
|
|
|
|
|
|
de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
|
|
|
|
|
"(msg:\"fast_pattern test\"; content:\"string1\"; "
|
|
|
|
|
"content:\"string2\"; content:\"strings3\"; fast_pattern; "
|
|
|
|
|
"content:\"strings_str4\"; content:\"strings_string5\"; "
|
|
|
|
|
"sid:1;)");
|
|
|
|
|
if (de_ctx->sig_list == NULL) {
|
|
|
|
|
printf("sig parse failed: ");
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SigGroupBuild(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
|
|
|
|
|
|
|
|
|
|
/* start the search phase */
|
|
|
|
|
det_ctx->sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p);
|
|
|
|
|
if (PacketPatternSearchWithStreamCtx(det_ctx, p) != 0)
|
|
|
|
|
result = 1;
|
|
|
|
|
|
|
|
|
|
SigGroupCleanup(de_ctx);
|
|
|
|
|
SigCleanSignatures(de_ctx);
|
|
|
|
|
|
|
|
|
|
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
UTHFreePackets(&p, 1);
|
|
|
|
|
DetectEngineCtxFree(de_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Checks that a fast_pattern is used in the mpm phase.
|
|
|
|
|
*/
|
|
|
|
|
int DetectFastPatternTest06(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *buf = (uint8_t *) "Oh this is a string1. But what is this with "
|
|
|
|
|
"string2. This is strings3. We have strings_str4. We also have "
|
|
|
|
|
"strings_string5";
|
|
|
|
|
uint16_t buflen = strlen((char *)buf);
|
|
|
|
|
Packet *p = NULL;
|
|
|
|
|
ThreadVars th_v;
|
|
|
|
|
DetectEngineThreadCtx *det_ctx = NULL;
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
memset(&th_v, 0, sizeof(th_v));
|
|
|
|
|
p = UTHBuildPacket(buf,buflen,IPPROTO_TCP);
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
|
|
|
|
|
if (de_ctx == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
de_ctx->flags |= DE_QUIET;
|
|
|
|
|
|
|
|
|
|
de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
|
|
|
|
|
"(msg:\"fast_pattern test\"; content:\"string1\"; "
|
|
|
|
|
"content:\"string2\"; content:\"strings3\"; fast_pattern; "
|
|
|
|
|
"content:\"strings_str4\"; content:\"strings_string5\"; "
|
|
|
|
|
"sid:1;)");
|
|
|
|
|
if (de_ctx->sig_list == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
SigGroupBuild(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
|
|
|
|
|
|
|
|
|
|
/* start the search phase */
|
|
|
|
|
det_ctx->sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p);
|
|
|
|
|
if (PacketPatternSearchWithStreamCtx(det_ctx, p) != 0)
|
|
|
|
|
result = 1;
|
|
|
|
|
|
|
|
|
|
SigGroupCleanup(de_ctx);
|
|
|
|
|
SigCleanSignatures(de_ctx);
|
|
|
|
|
|
|
|
|
|
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
UTHFreePackets(&p, 1);
|
|
|
|
|
DetectEngineCtxFree(de_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Checks that a fast_pattern is used in the mpm phase, when the payload
|
|
|
|
|
* doesn't contain the fast_pattern string within it.
|
|
|
|
|
*/
|
|
|
|
|
int DetectFastPatternTest07(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *buf = (uint8_t *) "Dummy is our name. Oh yes. From right here "
|
|
|
|
|
"right now, all the way to hangover. right. now here comes our "
|
|
|
|
|
"dark knight strings_string5. Yes here is our dark knight";
|
|
|
|
|
uint16_t buflen = strlen((char *)buf);
|
|
|
|
|
Packet *p = NULL;
|
|
|
|
|
ThreadVars th_v;
|
|
|
|
|
DetectEngineThreadCtx *det_ctx = NULL;
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
memset(&th_v, 0, sizeof(th_v));
|
|
|
|
|
p = UTHBuildPacket(buf,buflen,IPPROTO_TCP);
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
|
|
|
|
|
if (de_ctx == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
de_ctx->flags |= DE_QUIET;
|
|
|
|
|
|
|
|
|
|
de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
|
|
|
|
|
"(msg:\"fast_pattern test\"; content:\"string1\"; "
|
|
|
|
|
"content:\"string2\"; content:\"strings3\"; fast_pattern; "
|
|
|
|
|
"content:\"strings_str4\"; content:\"strings_string5\"; "
|
|
|
|
|
"sid:1;)");
|
|
|
|
|
if (de_ctx->sig_list == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
SigGroupBuild(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
|
|
|
|
|
|
|
|
|
|
/* start the search phase */
|
|
|
|
|
det_ctx->sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p);
|
|
|
|
|
if (PacketPatternSearchWithStreamCtx(det_ctx, p) == 0)
|
|
|
|
|
result = 1;
|
|
|
|
|
|
|
|
|
|
SigGroupCleanup(de_ctx);
|
|
|
|
|
SigCleanSignatures(de_ctx);
|
|
|
|
|
|
|
|
|
|
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
UTHFreePackets(&p, 1);
|
|
|
|
|
DetectEngineCtxFree(de_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Checks that a fast_pattern is used in the mpm phase and that we get
|
|
|
|
|
* exactly 1 match for the mpm phase.
|
|
|
|
|
*/
|
|
|
|
|
int DetectFastPatternTest08(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *buf = (uint8_t *) "Dummy is our name. Oh yes. From right here "
|
|
|
|
|
"right now, all the way to hangover. right. now here comes our "
|
|
|
|
|
"dark knight strings3. Yes here is our dark knight";
|
|
|
|
|
uint16_t buflen = strlen((char *)buf);
|
|
|
|
|
Packet *p = NULL;
|
|
|
|
|
ThreadVars th_v;
|
|
|
|
|
DetectEngineThreadCtx *det_ctx = NULL;
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
memset(&th_v, 0, sizeof(th_v));
|
|
|
|
|
p = UTHBuildPacket(buf,buflen,IPPROTO_TCP);
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
|
|
|
|
|
if (de_ctx == NULL) {
|
|
|
|
|
printf("de_ctx init: ");
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
de_ctx->flags |= DE_QUIET;
|
|
|
|
|
|
|
|
|
|
de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
|
|
|
|
|
"(msg:\"fast_pattern test\"; content:\"string1\"; "
|
|
|
|
|
"content:\"string2\"; content:\"strings3\"; fast_pattern; "
|
|
|
|
|
"content:\"strings_str4\"; content:\"strings_string5\"; "
|
|
|
|
|
"sid:1;)");
|
|
|
|
|
if (de_ctx->sig_list == NULL) {
|
|
|
|
|
printf("sig parse failed: ");
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SigGroupBuild(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
|
|
|
|
|
|
|
|
|
|
/* start the search phase */
|
|
|
|
|
det_ctx->sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p);
|
|
|
|
|
uint32_t r = PacketPatternSearchWithStreamCtx(det_ctx, p);
|
|
|
|
|
if (r != 1) {
|
|
|
|
|
printf("expected 1, got %"PRIu32": ", r);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = 1;
|
|
|
|
|
end:
|
|
|
|
|
UTHFreePackets(&p, 1);
|
|
|
|
|
SigGroupCleanup(de_ctx);
|
|
|
|
|
SigCleanSignatures(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
|
|
|
|
|
DetectEngineCtxFree(de_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* \test Checks that a fast_pattern is used in the mpm phase, when the payload
|
|
|
|
|
* doesn't contain the fast_pattern string within it.
|
|
|
|
|
*/
|
|
|
|
|
int DetectFastPatternTest09(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *buf = (uint8_t *) "Dummy is our name. Oh yes. From right here "
|
|
|
|
|
"right now, all the way to hangover. right. no_strings4 _imp now here "
|
|
|
|
|
"comes our dark knight strings3. Yes here is our dark knight";
|
|
|
|
|
uint16_t buflen = strlen((char *)buf);
|
|
|
|
|
Packet *p = NULL;
|
|
|
|
|
ThreadVars th_v;
|
|
|
|
|
DetectEngineThreadCtx *det_ctx = NULL;
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
memset(&th_v, 0, sizeof(th_v));
|
|
|
|
|
p = UTHBuildPacket(buf,buflen,IPPROTO_TCP);
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
|
|
|
|
|
if (de_ctx == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
de_ctx->flags |= DE_QUIET;
|
|
|
|
|
|
|
|
|
|
de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
|
|
|
|
|
"(msg:\"fast_pattern test\"; content:\"string1\"; "
|
|
|
|
|
"content:\"string2\"; content:\"strings3\"; "
|
|
|
|
|
"content:\"strings4_imp\"; fast_pattern; "
|
|
|
|
|
"content:\"strings_string5\"; sid:1;)");
|
|
|
|
|
if (de_ctx->sig_list == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
SigGroupBuild(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
|
|
|
|
|
|
|
|
|
|
/* start the search phase */
|
|
|
|
|
det_ctx->sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p);
|
|
|
|
|
if (PacketPatternSearchWithStreamCtx(det_ctx, p) == 0)
|
|
|
|
|
result = 1;
|
|
|
|
|
|
|
|
|
|
SigGroupCleanup(de_ctx);
|
|
|
|
|
SigCleanSignatures(de_ctx);
|
|
|
|
|
|
|
|
|
|
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
UTHFreePackets(&p, 1);
|
|
|
|
|
DetectEngineCtxFree(de_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Checks that a the SigInit chooses the fast_pattern with better pattern
|
|
|
|
|
* strength, when we have multiple fast_patterns in the Signature. Also
|
|
|
|
|
* checks that we get a match for the fast_pattern from the mpm phase.
|
|
|
|
|
*/
|
|
|
|
|
int DetectFastPatternTest10(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *buf = (uint8_t *) "Dummy is our name. Oh yes. From right here "
|
|
|
|
|
"right now, all the way to hangover. right. strings4_imp now here "
|
|
|
|
|
"comes our dark knight strings5. Yes here is our dark knight";
|
|
|
|
|
uint16_t buflen = strlen((char *)buf);
|
|
|
|
|
Packet *p = NULL;
|
|
|
|
|
ThreadVars th_v;
|
|
|
|
|
DetectEngineThreadCtx *det_ctx = NULL;
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
memset(&th_v, 0, sizeof(th_v));
|
|
|
|
|
p = UTHBuildPacket(buf,buflen,IPPROTO_TCP);
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
|
|
|
|
|
if (de_ctx == NULL) {
|
|
|
|
|
printf("de_ctx init: ");
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
de_ctx->flags |= DE_QUIET;
|
|
|
|
|
|
|
|
|
|
de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
|
|
|
|
|
"(msg:\"fast_pattern test\"; content:\"string1\"; "
|
|
|
|
|
"content:\"string2\"; content:\"strings3\"; "
|
|
|
|
|
"content:\"strings4_imp\"; fast_pattern; "
|
|
|
|
|
"content:\"strings_string5\"; sid:1;)");
|
|
|
|
|
if (de_ctx->sig_list == NULL) {
|
|
|
|
|
printf("sig parse failed: ");
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SigGroupBuild(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
|
|
|
|
|
|
|
|
|
|
/* start the search phase */
|
|
|
|
|
det_ctx->sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p);
|
|
|
|
|
uint32_t r = PacketPatternSearchWithStreamCtx(det_ctx, p);
|
|
|
|
|
if (r != 1) {
|
|
|
|
|
printf("expected 1, got %"PRIu32": ", r);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = 1;
|
|
|
|
|
end:
|
|
|
|
|
UTHFreePackets(&p, 1);
|
|
|
|
|
SigGroupCleanup(de_ctx);
|
|
|
|
|
SigCleanSignatures(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
|
|
|
|
|
DetectEngineCtxFree(de_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Checks that a the SigInit chooses the fast_pattern with better pattern
|
|
|
|
|
* strength, when we have multiple fast_patterns in the Signature. Also
|
|
|
|
|
* checks that we get no matches for the fast_pattern from the mpm phase.
|
|
|
|
|
*/
|
|
|
|
|
int DetectFastPatternTest11(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *buf = (uint8_t *) "Dummy is our name. Oh yes. From right here "
|
|
|
|
|
"right now, all the way to hangover. right. strings5_imp now here "
|
|
|
|
|
"comes our dark knight strings5. Yes here is our dark knight";
|
|
|
|
|
uint16_t buflen = strlen((char *)buf);
|
|
|
|
|
Packet *p = NULL;
|
|
|
|
|
ThreadVars th_v;
|
|
|
|
|
DetectEngineThreadCtx *det_ctx = NULL;
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
memset(&th_v, 0, sizeof(th_v));
|
|
|
|
|
p = UTHBuildPacket(buf,buflen,IPPROTO_TCP);
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
|
|
|
|
|
if (de_ctx == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
de_ctx->flags |= DE_QUIET;
|
|
|
|
|
|
|
|
|
|
de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
|
|
|
|
|
"(msg:\"fast_pattern test\"; content:\"string1\"; "
|
|
|
|
|
"content:\"string2\"; content:\"strings3\"; "
|
|
|
|
|
"content:\"strings4_imp\"; fast_pattern; "
|
|
|
|
|
"content:\"strings_string5\"; sid:1;)");
|
|
|
|
|
if (de_ctx->sig_list == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
SigGroupBuild(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
|
|
|
|
|
|
|
|
|
|
/* start the search phase */
|
|
|
|
|
det_ctx->sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p);
|
|
|
|
|
if (PacketPatternSearchWithStreamCtx(det_ctx, p) == 0)
|
|
|
|
|
result = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
UTHFreePackets(&p, 1);
|
|
|
|
|
if (de_ctx != NULL) {
|
|
|
|
|
SigGroupCleanup(de_ctx);
|
|
|
|
|
SigCleanSignatures(de_ctx);
|
|
|
|
|
if (det_ctx != NULL)
|
|
|
|
|
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
|
|
|
|
|
DetectEngineCtxFree(de_ctx);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Checks that we don't get a match for the mpm phase.
|
|
|
|
|
*/
|
|
|
|
|
int DetectFastPatternTest12(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *buf = (uint8_t *) "Dummy is our name. Oh yes. From right here "
|
|
|
|
|
"right now, all the way to hangover. right. strings5_imp now here "
|
|
|
|
|
"comes our dark knight strings5. Yes here is our dark knight";
|
|
|
|
|
uint16_t buflen = strlen((char *)buf);
|
|
|
|
|
Packet *p = NULL;
|
|
|
|
|
ThreadVars th_v;
|
|
|
|
|
DetectEngineThreadCtx *det_ctx = NULL;
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
memset(&th_v, 0, sizeof(th_v));
|
|
|
|
|
p = UTHBuildPacket(buf,buflen,IPPROTO_TCP);
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
|
|
|
|
|
if (de_ctx == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
de_ctx->flags |= DE_QUIET;
|
|
|
|
|
|
|
|
|
|
de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
|
|
|
|
|
"(msg:\"fast_pattern test\"; content:\"string1\"; "
|
|
|
|
|
"content:\"string2\"; content:\"strings3\"; "
|
|
|
|
|
"content:\"strings4_imp\"; "
|
|
|
|
|
"content:\"strings_string5\"; sid:1;)");
|
|
|
|
|
if (de_ctx->sig_list == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
SigGroupBuild(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
|
|
|
|
|
|
|
|
|
|
/* start the search phase */
|
|
|
|
|
det_ctx->sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p);
|
|
|
|
|
if (PacketPatternSearchWithStreamCtx(det_ctx, p) == 0)
|
|
|
|
|
result = 1;
|
|
|
|
|
|
|
|
|
|
SigGroupCleanup(de_ctx);
|
|
|
|
|
SigCleanSignatures(de_ctx);
|
|
|
|
|
|
|
|
|
|
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
UTHFreePackets(&p, 1);
|
|
|
|
|
DetectEngineCtxFree(de_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Checks that a the SigInit chooses the fast_pattern with a better
|
|
|
|
|
* strength from the available patterns, when we don't specify a
|
|
|
|
|
* fast_pattern. We also check that we get a match from the mpm
|
|
|
|
|
* phase.
|
|
|
|
|
*/
|
|
|
|
|
int DetectFastPatternTest13(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *buf = (uint8_t *) "Dummy is our name. Oh yes. From right here "
|
|
|
|
|
"right now, all the way to hangover. right. strings5_imp now here "
|
|
|
|
|
"comes our dark knight strings_string5. Yes here is our dark knight";
|
|
|
|
|
uint16_t buflen = strlen((char *)buf);
|
|
|
|
|
Packet *p = NULL;
|
|
|
|
|
ThreadVars th_v;
|
|
|
|
|
DetectEngineThreadCtx *det_ctx = NULL;
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
memset(&th_v, 0, sizeof(th_v));
|
|
|
|
|
p = UTHBuildPacket(buf,buflen,IPPROTO_TCP);
|
|
|
|
|
|
|
|
|
|
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
|
|
|
|
|
if (de_ctx == NULL) {
|
|
|
|
|
printf("de_ctx init: ");
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
de_ctx->flags |= DE_QUIET;
|
|
|
|
|
|
|
|
|
|
de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
|
|
|
|
|
"(msg:\"fast_pattern test\"; content:\"string1\"; "
|
|
|
|
|
"content:\"string2\"; content:\"strings3\"; "
|
|
|
|
|
"content:\"strings4_imp\"; "
|
|
|
|
|
"content:\"strings_string5\"; sid:1;)");
|
|
|
|
|
if (de_ctx->sig_list == NULL) {
|
|
|
|
|
printf("sig parse failed: ");
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SigGroupBuild(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
|
|
|
|
|
|
|
|
|
|
/* start the search phase */
|
|
|
|
|
det_ctx->sgh = SigMatchSignaturesGetSgh(de_ctx, det_ctx, p);
|
|
|
|
|
uint32_t r = PacketPatternSearchWithStreamCtx(det_ctx, p);
|
|
|
|
|
if (r != 1) {
|
|
|
|
|
printf("expected 1 result, got %"PRIu32": ", r);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = 1;
|
|
|
|
|
end:
|
|
|
|
|
UTHFreePackets(&p, 1);
|
|
|
|
|
SigGroupCleanup(de_ctx);
|
|
|
|
|
SigCleanSignatures(de_ctx);
|
|
|
|
|
DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
|
|
|
|
|
DetectEngineCtxFree(de_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \test Checks to make sure that other sigs work that should when fast_pattern is inspecting on the same payload
|
|
|
|
|
*
|
|
|
|
@ -19430,15 +18948,6 @@ void DetectFastPatternRegisterTests(void)
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest02", DetectFastPatternTest02);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest03", DetectFastPatternTest03);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest04", DetectFastPatternTest04);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest05", DetectFastPatternTest05);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest06", DetectFastPatternTest06);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest07", DetectFastPatternTest07);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest08", DetectFastPatternTest08);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest09", DetectFastPatternTest09);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest10", DetectFastPatternTest10);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest11", DetectFastPatternTest11);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest12", DetectFastPatternTest12);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest13", DetectFastPatternTest13);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest14", DetectFastPatternTest14);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest15", DetectFastPatternTest15);
|
|
|
|
|
UtRegisterTest("DetectFastPatternTest16", DetectFastPatternTest16);
|
|
|
|
|