52static void DetectUrilenRegisterTests (
void);
54static int g_http_uri_buffer_id = 0;
55static int g_http_raw_uri_buffer_id = 0;
86static DetectUrilenData *DetectUrilenParse (
const char *urilenstr)
88 return SCDetectUrilenParse(urilenstr);
104 DetectUrilenData *urilend = NULL;
109 urilend = DetectUrilenParse(urilenstr);
113 if (urilend->raw_buffer) {
115 g_http_raw_uri_buffer_id) == NULL) {
120 g_http_uri_buffer_id) == NULL) {
128 DetectUrilenFree(
de_ctx, urilend);
142 DetectUrilenData *urilend = (DetectUrilenData *)ptr;
143 SCDetectUrilenFree(urilend);
155 uint16_t high = UINT16_MAX;
162 DetectUrilenData *dd = (DetectUrilenData *)sm->ctx;
164 switch (dd->du16.mode) {
166 if (dd->du16.arg1 < UINT16_MAX) {
167 high = dd->du16.arg1 + 1;
173 high = dd->du16.arg1;
176 if (dd->du16.arg2 < UINT16_MAX) {
177 high = dd->du16.arg2 + 1;
192 if (!found || high == UINT16_MAX)
209 SCLogDebug(
"updated %u, content %u to have depth %u "
210 "because of urilen.",
233 *sigerror =
"depth or urilen smaller than content len";
235 "than content len %u",
254static int DetectUrilenParseTest01(
void)
257 DetectUrilenData *urilend = NULL;
259 urilend = DetectUrilenParse(
"10");
260 if (urilend != NULL) {
261 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_EQ &&
262 !urilend->raw_buffer)
265 DetectUrilenFree(NULL, urilend);
271static int DetectUrilenParseTest02(
void)
274 DetectUrilenData *urilend = NULL;
276 urilend = DetectUrilenParse(
" < 10 ");
277 if (urilend != NULL) {
278 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT &&
279 !urilend->raw_buffer)
282 DetectUrilenFree(NULL, urilend);
288static int DetectUrilenParseTest03(
void)
291 DetectUrilenData *urilend = NULL;
293 urilend = DetectUrilenParse(
" > 10 ");
294 if (urilend != NULL) {
295 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT &&
296 !urilend->raw_buffer)
299 DetectUrilenFree(NULL, urilend);
305static int DetectUrilenParseTest04(
void)
308 DetectUrilenData *urilend = NULL;
310 urilend = DetectUrilenParse(
" 5 <> 10 ");
311 if (urilend != NULL) {
312 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
316 DetectUrilenFree(NULL, urilend);
322static int DetectUrilenParseTest05(
void)
325 DetectUrilenData *urilend = NULL;
327 urilend = DetectUrilenParse(
"5<>10,norm");
328 if (urilend != NULL) {
329 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
333 DetectUrilenFree(NULL, urilend);
339static int DetectUrilenParseTest06(
void)
342 DetectUrilenData *urilend = NULL;
344 urilend = DetectUrilenParse(
"5<>10,raw");
345 if (urilend != NULL) {
346 if (urilend->du16.arg1 == 5 && urilend->du16.arg2 == 10 &&
350 DetectUrilenFree(NULL, urilend);
356static int DetectUrilenParseTest07(
void)
359 DetectUrilenData *urilend = NULL;
361 urilend = DetectUrilenParse(
">10, norm ");
362 if (urilend != NULL) {
363 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT &&
364 !urilend->raw_buffer)
367 DetectUrilenFree(NULL, urilend);
373static int DetectUrilenParseTest08(
void)
376 DetectUrilenData *urilend = NULL;
378 urilend = DetectUrilenParse(
"<10, norm ");
379 if (urilend != NULL) {
380 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT &&
381 !urilend->raw_buffer)
384 DetectUrilenFree(NULL, urilend);
390static int DetectUrilenParseTest09(
void)
393 DetectUrilenData *urilend = NULL;
395 urilend = DetectUrilenParse(
">10, raw ");
396 if (urilend != NULL) {
397 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_GT && urilend->raw_buffer)
400 DetectUrilenFree(NULL, urilend);
406static int DetectUrilenParseTest10(
void)
409 DetectUrilenData *urilend = NULL;
411 urilend = DetectUrilenParse(
"<10, raw ");
412 if (urilend != NULL) {
413 if (urilend->du16.arg1 == 10 && urilend->du16.mode ==
DETECT_UINT_LT && urilend->raw_buffer)
416 DetectUrilenFree(NULL, urilend);
428 DetectUrilenData **urilend,
const char *
str)
436 if (snprintf(fullstr, 1024,
"alert ip any any -> any any (msg:\"Urilen "
437 "test\"; urilen:%s; sid:1;)",
str) >= 1024) {
449 if ((*de_ctx)->sig_list == NULL) {
453 *sig = (*de_ctx)->sig_list;
455 *urilend = DetectUrilenParse(
str);
470static int DetectUrilenSetpTest01(
void)
473 DetectUrilenData *urilend = NULL;
478 res = DetectUrilenInitTest(&
de_ctx, &sig, &urilend,
"1 <> 2 ");
486 if (urilend != NULL) {
487 if (urilend->du16.arg1 == 1 && urilend->du16.arg2 == 2 &&
494 DetectUrilenFree(NULL, urilend);
503static int DetectUrilenSigTest01(
void)
507 uint8_t httpbuf1[] =
"POST /suricata HTTP/1.0\r\n"
508 "Host: foo.bar.tld\r\n"
510 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
518 memset(&th_v, 0,
sizeof(th_v));
519 memset(&f, 0,
sizeof(f));
520 memset(&ssn, 0,
sizeof(ssn));
526 f.
proto = IPPROTO_TCP;
545 "alert tcp any any -> any any "
546 "(msg:\"Testing urilen\"; "
547 "urilen: <5; sid:1;)");
553 "alert tcp any any -> any any "
554 "(msg:\"Testing http_method\"; "
555 "urilen: >5; sid:2;)");
566 SCLogDebug(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
571 if (htp_state == NULL) {
579 printf(
"sid 1 alerted, but should not have: \n");
583 printf(
"sid 2 did not alerted, but should have: \n");
605void DetectUrilenRegisterTests(
void)
607 UtRegisterTest(
"DetectUrilenParseTest01", DetectUrilenParseTest01);
608 UtRegisterTest(
"DetectUrilenParseTest02", DetectUrilenParseTest02);
609 UtRegisterTest(
"DetectUrilenParseTest03", DetectUrilenParseTest03);
610 UtRegisterTest(
"DetectUrilenParseTest04", DetectUrilenParseTest04);
611 UtRegisterTest(
"DetectUrilenParseTest05", DetectUrilenParseTest05);
612 UtRegisterTest(
"DetectUrilenParseTest06", DetectUrilenParseTest06);
613 UtRegisterTest(
"DetectUrilenParseTest07", DetectUrilenParseTest07);
614 UtRegisterTest(
"DetectUrilenParseTest08", DetectUrilenParseTest08);
615 UtRegisterTest(
"DetectUrilenParseTest09", DetectUrilenParseTest09);
616 UtRegisterTest(
"DetectUrilenParseTest10", DetectUrilenParseTest10);
AppLayerParserThreadCtx * AppLayerParserThreadCtxAlloc(void)
Gets a new app layer protocol's parser thread context.
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
Destroys the app layer parser thread context obtained using AppLayerParserThreadCtxAlloc().
int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alproto, uint8_t flags, const uint8_t *input, uint32_t input_len)
#define DETECT_CONTENT_DEPTH
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
void SigCleanSignatures(DetectEngineCtx *de_ctx)
int SigGroupCleanup(DetectEngineCtx *de_ctx)
DetectEngineCtx * DetectEngineCtxInit(void)
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Data structures and function prototypes for keeping state for the detection engine.
int DetectBufferTypeRegister(const char *name)
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
SigTableElmt * sigmatch_table
void DetectUrilenRegister(void)
Registration function for urilen: keyword.
bool DetectUrilenValidateContent(const Signature *s, const char **sigerror, const DetectBufferType *dbt)
void DetectUrilenApplyToContent(Signature *s, int list)
set prefilter dsize pair
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
#define FLOW_INITIALIZE(f)
#define FLOW_PKT_TOSERVER
#define FLOW_PKT_ESTABLISHED
AppLayerParserThreadCtx * alp_tctx
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
void StreamTcpFreeConfig(bool quiet)
void StreamTcpInitConfig(bool)
To initialize the stream global configuration data.
main detection engine ctx
AppProto alproto
application level protocol
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
a single match condition for a signature
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
void(* Free)(DetectEngineCtx *, void *)
void(* RegisterTests)(void)
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
SignatureInitDataBuffer * buffers
SignatureInitData * init_data
Per thread variable structure.
#define SCLogError(...)
Macro used to log ERROR messages.
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.
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.