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",
123 SCLogError(
"within argument \"%" PRIi32
"\" is "
124 "less than the content length \"%" PRIu32
"\" which is invalid, since "
125 "this will never match. Invalidating signature",
137 if (prev_pm == NULL) {
144 "has a fast_pattern:only; set. Can't "
145 "have relative keywords around a fast_pattern "
165 static int DetectWithinTestPacket01 (
void)
167 uint8_t *buf = (uint8_t *)
"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
168 "User-Agent: Wget/1.11.4"
170 "Host: www.google.com"
171 "Connection: Keep-Alive"
172 "Date: Mon, 04 Jan 2010 17:29:39 GMT";
173 uint16_t buflen = strlen((
char *)buf);
178 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with within "
179 "modifier\"; pcre:\"/AllWorkAndNoPlayMakesWillADullBoy/\";"
180 " content:\"HTTP\"; within:5; sid:49; rev:1;)";
189 static int DetectWithinTestPacket02 (
void)
191 uint8_t *buf = (uint8_t *)
"Zero Five Ten Fourteen";
192 uint16_t buflen = strlen((
char *)buf);
197 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with within "
198 "modifier\"; content:\"Five\"; content:\"Ten\"; within:3; distance:1; sid:1;)";
207 static int DetectWithinTestVarSetup(
void)
209 char sig[] =
"alert tcp any any -> any any ( "
210 "msg:\"test rule\"; "
213 "byte_extract:2,0,somevar,relative; "
229 void DetectWithinRegisterTests(
void)
231 UtRegisterTest(
"DetectWithinTestPacket01", DetectWithinTestPacket01);
232 UtRegisterTest(
"DetectWithinTestPacket02", DetectWithinTestPacket02);
233 UtRegisterTest(
"DetectWithinTestVarSetup", DetectWithinTestVarSetup);
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
SigTableElmt * sigmatch_table
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.
#define DETECT_CONTENT_VALUE_MAX
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.
int StringParseI32RangeCheck(int32_t *res, int base, size_t len, const char *str, int32_t min, int32_t max)
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.
#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)