Go to the documentation of this file.
49 static void DetectWithinRegisterTests(
void);
73 const char *
str = withinstr;
78 SCLogError(
"within needs preceding content option");
85 SCLogError(
"can't use multiple withins for the same content.");
90 "keyword like within/distance with a absolute "
91 "relative keyword like depth/offset for the same "
97 "negated keyword set along with a fast_pattern");
102 "keyword set along with a fast_pattern:only;");
105 if (
str[0] !=
'-' && isalpha((
unsigned char)
str[0])) {
109 "seen in within - %s",
122 SCLogError(
"within argument \"%" PRIi32
"\" is "
123 "less than the content length \"%" PRIu32
"\" which is invalid, since "
124 "this will never match. Invalidating signature",
136 if (prev_pm == NULL) {
143 "has a fast_pattern:only; set. Can't "
144 "have relative keywords around a fast_pattern "
164 static int DetectWithinTestPacket01 (
void)
166 uint8_t *buf = (uint8_t *)
"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
167 "User-Agent: Wget/1.11.4"
169 "Host: www.google.com"
170 "Connection: Keep-Alive"
171 "Date: Mon, 04 Jan 2010 17:29:39 GMT";
172 uint16_t buflen = strlen((
char *)buf);
177 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with within "
178 "modifier\"; pcre:\"/AllWorkAndNoPlayMakesWillADullBoy/\";"
179 " content:\"HTTP\"; within:5; sid:49; rev:1;)";
188 static int DetectWithinTestPacket02 (
void)
190 uint8_t *buf = (uint8_t *)
"Zero Five Ten Fourteen";
191 uint16_t buflen = strlen((
char *)buf);
196 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with within "
197 "modifier\"; content:\"Five\"; content:\"Ten\"; within:3; distance:1; sid:1;)";
206 static int DetectWithinTestVarSetup(
void)
208 char sig[] =
"alert tcp any any -> any any ( "
209 "msg:\"test rule\"; "
212 "byte_extract:2,0,somevar,relative; "
228 void DetectWithinRegisterTests(
void)
230 UtRegisterTest(
"DetectWithinTestPacket01", DetectWithinTestPacket01);
231 UtRegisterTest(
"DetectWithinTestPacket02", DetectWithinTestPacket02);
232 UtRegisterTest(
"DetectWithinTestVarSetup", DetectWithinTestVarSetup);
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
main detection engine ctx
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
int UTHPacketMatchSig(Packet *p, const char *sig)
SigMatch * DetectGetLastSMByListPtr(const Signature *s, SigMatch *sm_list,...)
Returns the sm with the largest index (added last) from the list passed to us as a pointer.
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
int StringParseInt32(int32_t *res, int base, size_t len, const char *str)
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
uint8_t DetectByteIndexType
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define PASS
Pass the test.
void DetectWithinRegister(void)
#define DETECT_CONTENT_DEPTH
#define DETECT_CONTENT_NEGATED
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
#define DETECT_CONTENT_WITHIN_VAR
bool DetectByteRetrieveSMVar(const char *arg, const Signature *s, DetectByteIndexType *index)
Used to retrieve args from BM.
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
#define DETECT_CONTENT_WITHIN_NEXT
#define SCLogError(...)
Macro used to log ERROR messages.
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
#define DETECT_CONTENT_OFFSET
#define DETECT_CONTENT_FAST_PATTERN_ONLY
a single match condition for a signature
DetectEngineCtx * DetectEngineCtxInit(void)
#define DETECT_PCRE_RELATIVE_NEXT
SigMatch * DetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
#define DETECT_CONTENT_FAST_PATTERN
#define DETECT_CONTENT_WITHIN
void(* RegisterTests)(void)