suricata
detect-fast-pattern.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2021 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
22  *
23  * Implements the fast_pattern keyword
24  */
25 
26 #include "suricata-common.h"
27 #include "detect.h"
28 #include "flow.h"
29 #include "detect-content.h"
30 #include "detect-parse.h"
31 #include "detect-engine.h"
32 #include "detect-engine-mpm.h"
33 #include "detect-engine-build.h"
34 #include "detect-fast-pattern.h"
35 
36 #include "util-error.h"
37 #include "util-byte.h"
38 #include "util-debug.h"
39 #include "util-unittest.h"
40 #include "util-unittest-helper.h"
41 
42 #define PARSE_REGEX "^(\\s*only\\s*)|\\s*([0-9]+)\\s*,\\s*([0-9]+)\\s*$"
43 
44 static DetectParseRegex parse_regex;
45 
46 static int DetectFastPatternSetup(DetectEngineCtx *, Signature *, const char *);
47 #ifdef UNITTESTS
48 static void DetectFastPatternRegisterTests(void);
49 #endif
50 
51 /* holds the list of sm match lists that need to be searched for a keyword
52  * that has fp support */
53 static SCFPSupportSMList *g_fp_support_smlist_list = NULL;
54 
55 /**
56  * \brief Checks if a particular buffer is in the list
57  * of lists that need to be searched for a keyword that has fp support.
58  *
59  * \param list_id The list id.
60  *
61  * \retval 1 If supported.
62  * \retval 0 If not.
63  */
65  const int list_id)
66 {
67  if (de_ctx->fp_support_smlist_list == NULL) {
68  return 0;
69  }
70 
71  if (list_id == DETECT_SM_LIST_PMATCH)
72  return 1;
73 
75 }
76 
77 static void Add(SCFPSupportSMList **list, const int list_id, const int priority)
78 {
79  SCFPSupportSMList *ip = NULL;
80  /* insertion point - ip */
81  for (SCFPSupportSMList *tmp = *list; tmp != NULL; tmp = tmp->next) {
82  if (list_id == tmp->list_id) {
83  SCLogDebug("SM list already registered.");
84  return;
85  }
86 
87  /* We need a strict check to be sure that the current list
88  * was not already registered
89  * and other lists with the same priority hide it.
90  */
91  if (priority < tmp->priority)
92  break;
93 
94  ip = tmp;
95  }
96 
97  if (*list == NULL) {
98  SCFPSupportSMList *new = SCCalloc(1, sizeof(SCFPSupportSMList));
99  if (unlikely(new == NULL))
100  exit(EXIT_FAILURE);
101  new->list_id = list_id;
102  new->priority = priority;
103 
104  *list = new;
105  return;
106  }
107 
108  SCFPSupportSMList *new = SCCalloc(1, sizeof(SCFPSupportSMList));
109  if (unlikely(new == NULL))
110  exit(EXIT_FAILURE);
111  new->list_id = list_id;
112  new->priority = priority;
113  if (ip == NULL) {
114  new->next = *list;
115  *list = new;
116  } else {
117  new->next = ip->next;
118  ip->next = new;
119  }
120 }
121 
122 /**
123  * \brief Lets one add a sm list id to be searched for potential fp supported
124  * keywords later.
125  *
126  * \param list_id SM list id.
127  * \param priority Priority for this list.
128  */
129 void SupportFastPatternForSigMatchList(int list_id, int priority)
130 {
131  Add(&g_fp_support_smlist_list, list_id, priority);
132 }
133 
135 {
136  Add(&de_ctx->fp_support_smlist_list, list_id, priority);
137 }
138 
139 /**
140  * \brief Registers the keywords(SMs) that should be given fp support.
141  */
143 {
145 
146  /* other types are handled by DetectMpmAppLayerRegister() */
147 }
148 
150 {
151  SCFPSupportSMList *last = NULL;
152  for (SCFPSupportSMList *tmp = g_fp_support_smlist_list; tmp != NULL; tmp = tmp->next) {
153  SCFPSupportSMList *n = SCCalloc(1, sizeof(*n));
154  if (n == NULL) {
155  FatalError("out of memory: %s", strerror(errno));
156  }
157  n->list_id = tmp->list_id;
158  n->priority = tmp->priority;
159 
160  // append
161  if (de_ctx->fp_support_smlist_list == NULL) {
162  last = de_ctx->fp_support_smlist_list = n;
163  } else {
164  BUG_ON(last == NULL);
165  last->next = n;
166  last = n;
167  }
168  }
169 }
170 
172 {
173  for (SCFPSupportSMList *tmp = de_ctx->fp_support_smlist_list; tmp != NULL;) {
174  SCFPSupportSMList *next = tmp->next;
175  SCFree(tmp);
176  tmp = next;
177  }
179 }
180 
181 /**
182  * \brief Registration function for fast_pattern keyword
183  */
185 {
186  sigmatch_table[DETECT_FAST_PATTERN].name = "fast_pattern";
187  sigmatch_table[DETECT_FAST_PATTERN].desc = "force using preceding content in the multi pattern matcher";
188  sigmatch_table[DETECT_FAST_PATTERN].url = "/rules/prefilter-keywords.html#fast-pattern";
190  sigmatch_table[DETECT_FAST_PATTERN].Setup = DetectFastPatternSetup;
192 #ifdef UNITTESTS
193  sigmatch_table[DETECT_FAST_PATTERN].RegisterTests = DetectFastPatternRegisterTests;
194 #endif
196 
197  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
198 }
199 
200 /**
201  * \brief Configures the previous content context for a fast_pattern modifier
202  * keyword used in the rule.
203  *
204  * \param de_ctx Pointer to the Detection Engine Context.
205  * \param s Pointer to the Signature to which the current keyword belongs.
206  * \param arg May hold an argument
207  *
208  * \retval 0 On success.
209  * \retval -1 On failure.
210  */
211 static int DetectFastPatternSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
212 {
213  int res = 0;
214  size_t pcre2len;
215  char arg_substr[128] = "";
216  DetectContentData *cd = NULL;
217  pcre2_match_data *match = NULL;
218 
221  if (pm1 == NULL && pm2 == NULL) {
222  SCLogError("fast_pattern found inside "
223  "the rule, without a content context. Please use a "
224  "content based keyword before using fast_pattern");
225  return -1;
226  }
227 
228  SigMatch *pm = NULL;
229  if (pm1 && pm2) {
230  if (pm1->idx > pm2->idx)
231  pm = pm1;
232  else
233  pm = pm2;
234  } else if (pm1 && !pm2) {
235  pm = pm1;
236  } else {
237  pm = pm2;
238  }
239 
240  if (s->flags & SIG_FLAG_TXBOTHDIR && s->init_data->curbuf != NULL) {
243  SCLogError("fast_pattern cannot be used on to_client keyword for "
244  "transactional rule with a streaming buffer to server %u",
245  s->id);
246  goto error;
247  }
249  }
250  }
251 
252  cd = (DetectContentData *)pm->ctx;
253  if ((cd->flags & DETECT_CONTENT_NEGATED) &&
254  ((cd->flags & DETECT_CONTENT_DISTANCE) ||
255  (cd->flags & DETECT_CONTENT_WITHIN) ||
256  (cd->flags & DETECT_CONTENT_OFFSET) ||
257  (cd->flags & DETECT_CONTENT_DEPTH))) {
258 
259  /* we can't have any of these if we are having "only" */
260  SCLogError("fast_pattern; cannot be "
261  "used with negated content, along with relative modifiers");
262  goto error;
263  }
264 
265  if (arg == NULL|| strcmp(arg, "") == 0) {
267  SCLogError("can't use multiple fast_pattern "
268  "options for the same content");
269  goto error;
270  }
271  else { /*allow only one content to have fast_pattern modifier*/
272  for (uint32_t list_id = 0; list_id < DETECT_SM_LIST_MAX; list_id++) {
273  SigMatch *sm = NULL;
274  for (sm = s->init_data->smlists[list_id]; sm != NULL; sm = sm->next) {
275  if (sm->type == DETECT_CONTENT) {
276  DetectContentData *tmp_cd = (DetectContentData *)sm->ctx;
277  if (tmp_cd->flags & DETECT_CONTENT_FAST_PATTERN) {
278  SCLogError("fast_pattern "
279  "can be used on only one content in a rule");
280  goto error;
281  }
282  }
283  }
284  }
285  }
287  SCLogError("fast_pattern cannot be used with base64_data");
288  goto error;
289  }
291  return 0;
292  }
293 
294  /* Execute the regex and populate args with captures. */
295  int ret = DetectParsePcreExec(&parse_regex, &match, arg, 0, 0);
296  /* fast pattern only */
297  if (ret == 2) {
298  if ((cd->flags & DETECT_CONTENT_NEGATED) ||
299  (cd->flags & DETECT_CONTENT_DISTANCE) ||
300  (cd->flags & DETECT_CONTENT_WITHIN) ||
301  (cd->flags & DETECT_CONTENT_OFFSET) ||
302  (cd->flags & DETECT_CONTENT_DEPTH)) {
303 
304  /* we can't have any of these if we are having "only" */
305  SCLogError("fast_pattern: only; cannot be "
306  "used with negated content or with any of the relative "
307  "modifiers like distance, within, offset, depth");
308  goto error;
309  }
311 
312  /* fast pattern chop */
313  } else if (ret == 4) {
314  pcre2len = sizeof(arg_substr);
315  res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)arg_substr, &pcre2len);
316  if (res < 0) {
317  SCLogError("pcre2_substring_copy_bynumber failed "
318  "for fast_pattern offset");
319  goto error;
320  }
321  uint16_t offset;
322  if (StringParseUint16(&offset, 10, 0,
323  (const char *)arg_substr) < 0) {
324  SCLogError("Invalid fast pattern offset:"
325  " \"%s\"",
326  arg_substr);
327  goto error;
328  }
329 
330  pcre2len = sizeof(arg_substr);
331  res = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)arg_substr, &pcre2len);
332  if (res < 0) {
333  SCLogError("pcre2_substring_copy_bynumber failed "
334  "for fast_pattern offset");
335  goto error;
336  }
337  uint16_t length;
338  if (StringParseUint16(&length, 10, 0,
339  (const char *)arg_substr) < 0) {
340  SCLogError("Invalid value for fast "
341  "pattern: \"%s\"",
342  arg_substr);
343  goto error;
344  }
345 
346  // Avoiding integer overflow
347  if (offset > (65535 - length)) {
348  SCLogError("Fast pattern (length + offset) "
349  "exceeds limit pattern length limit");
350  goto error;
351  }
352 
353  if (offset + length > cd->content_len) {
354  SCLogError("Fast pattern (length + "
355  "offset (%u)) exceeds pattern length (%u)",
356  offset + length, cd->content_len);
357  goto error;
358  }
359 
360  cd->fp_chop_offset = offset;
361  cd->fp_chop_len = length;
363 
364  } else {
365  SCLogError("parse error, ret %" PRId32 ", string %s", ret, arg);
366  goto error;
367  }
368 
370 
371  pcre2_match_data_free(match);
372  return 0;
373 
374  error:
375  if (match) {
376  pcre2_match_data_free(match);
377  }
378  return -1;
379 }
380 
381 /*----------------------------------Unittests---------------------------------*/
382 
383 #ifdef UNITTESTS
384 #include "detect-engine-alert.h"
385 static SigMatch *GetMatches(Signature *s, const int list)
386 {
387  SigMatch *sm = DetectBufferGetFirstSigMatch(s, list);
388  if (sm == NULL && list < DETECT_SM_LIST_MAX) {
389  sm = s->init_data->smlists[list];
390  }
391  return sm;
392 }
393 
394 static int DetectFastPatternStickySingle(const char *sticky, const int list)
395 {
398  char string[1024];
399  snprintf(string, sizeof(string),
400  "alert tcp any any -> any any "
401  "(%s%scontent:\"one\"; fast_pattern; sid:1;)",
402  sticky ? sticky : "", sticky ? "; " : " ");
403  Signature *s = DetectEngineAppendSig(de_ctx, string);
404  FAIL_IF_NULL(s);
405  SigMatch *sm = GetMatches(s, list);
406  FAIL_IF_NULL(sm);
412  PASS;
413 }
414 
415 static int DetectFastPatternModifierSingle(const char *sticky, const int list)
416 {
419  char string[1024];
420  snprintf(string, sizeof(string),
421  "alert tcp any any -> any any "
422  "(content:\"one\"; %s%sfast_pattern; sid:1;)",
423  sticky ? sticky : "", sticky ? "; " : " ");
424  Signature *s = DetectEngineAppendSig(de_ctx, string);
425  FAIL_IF_NULL(s);
426  SigMatch *sm = GetMatches(s, list);
427  FAIL_IF_NULL(sm);
433  PASS;
434 }
435 
436 static int DetectFastPatternStickySingleNoFP(const char *sticky, const int list)
437 {
440  char string[1024];
441  snprintf(string, sizeof(string),
442  "alert tcp any any -> any any "
443  "(%s%scontent:\"one\"; sid:1;)",
444  sticky ? sticky : "", sticky ? "; " : " ");
445  Signature *s = DetectEngineAppendSig(de_ctx, string);
446  FAIL_IF_NULL(s);
447  SigMatch *sm = GetMatches(s, list);
448  FAIL_IF_NULL(sm);
454  PASS;
455 }
456 
457 static int DetectFastPatternModifierSingleNoFP(const char *sticky, const int list)
458 {
461  char string[1024];
462  snprintf(string, sizeof(string),
463  "alert tcp any any -> any any "
464  "(content:\"one\"; %s%ssid:1;)",
465  sticky ? sticky : "", sticky ? "; " : " ");
466  Signature *s = DetectEngineAppendSig(de_ctx, string);
467  FAIL_IF_NULL(s);
468  SigMatch *sm = GetMatches(s, list);
469  FAIL_IF_NULL(sm);
475  PASS;
476 }
477 
478 static int DetectFastPatternStickySingleBadArg(const char *sticky)
479 {
482  char string[1024];
483  /* bogus argument to fast_pattern */
484  snprintf(string, sizeof(string),
485  "alert tcp any any -> any any "
486  "(%s%scontent:\"one\"; fast_pattern:boo; sid:1;)",
487  sticky ? sticky : "", sticky ? "; " : " ");
488  Signature *s = DetectEngineAppendSig(de_ctx, string);
489  FAIL_IF_NOT_NULL(s);
490  /* fast_pattern only with distance */
491  snprintf(string, sizeof(string),
492  "alert tcp any any -> any any "
493  "(%s%scontent:\"one\"; fast_pattern:only; content:\"two\"; distance:10; sid:1;)",
494  sticky ? sticky : "", sticky ? "; " : " ");
495  s = DetectEngineAppendSig(de_ctx, string);
496  FAIL_IF_NOT_NULL(s);
497  /* fast_pattern only with distance */
498  snprintf(string, sizeof(string),
499  "alert tcp any any -> any any "
500  "(%s%scontent:\"one\"; content:\"two\"; fast_pattern:only; distance:10; sid:1;)",
501  sticky ? sticky : "", sticky ? "; " : " ");
502  s = DetectEngineAppendSig(de_ctx, string);
503  FAIL_IF_NOT_NULL(s);
504  /* fast_pattern only with distance */
505  snprintf(string, sizeof(string),
506  "alert tcp any any -> any any "
507  "(%s%scontent:\"one\"; content:\"two\"; distance:10; fast_pattern:only; sid:1;)",
508  sticky ? sticky : "", sticky ? "; " : " ");
509  s = DetectEngineAppendSig(de_ctx, string);
510  FAIL_IF_NOT_NULL(s);
511  /* fast_pattern chop with invalid values */
512  snprintf(string, sizeof(string),
513  "alert tcp any any -> any any "
514  "(%s%scontent:\"one\"; fast_pattern:5,6; sid:1;)",
515  sticky ? sticky : "", sticky ? "; " : " ");
516  s = DetectEngineAppendSig(de_ctx, string);
517  FAIL_IF_NOT_NULL(s);
519  PASS;
520 }
521 
522 static int DetectFastPatternModifierBadRules(const char *sticky)
523 {
526  char string[1024];
527  /* bogus argument to fast_pattern */
528  snprintf(string, sizeof(string),
529  "alert tcp any any -> any any "
530  "(content:\"one\"; %s%sfast_pattern:boo; sid:1;)",
531  sticky ? sticky : "", sticky ? "; " : " ");
532  Signature *s = DetectEngineAppendSig(de_ctx, string);
533  FAIL_IF_NOT_NULL(s);
534  /* fast_pattern only with distance */
535  snprintf(string, sizeof(string),
536  "alert tcp any any -> any any "
537  "(content:\"one\"; %s%sfast_pattern:only; content:\"two\"; %s%sdistance:10; sid:1;)",
538  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
539  s = DetectEngineAppendSig(de_ctx, string);
540  FAIL_IF_NOT_NULL(s);
541 #if 0 // TODO bug?
542  /* fast_pattern only with distance */
543  snprintf(string, sizeof(string), "alert tcp any any -> any any "
544  "(content:\"one\"; %s%s content:\"two\"; %s%sdistance:10; fast_pattern:only; sid:1;)",
545  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
546  s = DetectEngineAppendSig(de_ctx, string);
547  FAIL_IF_NOT_NULL(s);
548 #endif
549  /* fast_pattern only with within */
550  snprintf(string, sizeof(string),
551  "alert tcp any any -> any any "
552  "(content:\"one\"; %s%sfast_pattern:only; content:\"two\"; %s%swithin:10; sid:1;)",
553  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
554  s = DetectEngineAppendSig(de_ctx, string);
555  FAIL_IF_NOT_NULL(s);
556  /* fast_pattern only with within */
557  snprintf(string, sizeof(string),
558  "alert tcp any any -> any any "
559  "(content:\"one\"; %s%s content:\"two\"; %s%swithin:10; fast_pattern:only; sid:1;)",
560  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
561  s = DetectEngineAppendSig(de_ctx, string);
562  FAIL_IF_NOT_NULL(s);
563  /* fast_pattern only with offset */
564  snprintf(string, sizeof(string),
565  "alert tcp any any -> any any "
566  "(content:\"one\"; %s%sfast_pattern:only; offset:10; sid:1;)",
567  sticky ? sticky : "", sticky ? "; " : " ");
568  s = DetectEngineAppendSig(de_ctx, string);
569  FAIL_IF_NOT_NULL(s);
570  /* fast_pattern only with offset */
571  snprintf(string, sizeof(string),
572  "alert tcp any any -> any any "
573  "(content:\"one\"; %s%s offset:10; fast_pattern:only; sid:1;)",
574  sticky ? sticky : "", sticky ? "; " : " ");
575  s = DetectEngineAppendSig(de_ctx, string);
576  FAIL_IF_NOT_NULL(s);
577  /* fast_pattern only with depth */
578  snprintf(string, sizeof(string),
579  "alert tcp any any -> any any "
580  "(content:\"one\"; %s%sfast_pattern:only; depth:10; sid:1;)",
581  sticky ? sticky : "", sticky ? "; " : " ");
582  s = DetectEngineAppendSig(de_ctx, string);
583  FAIL_IF_NOT_NULL(s);
584  /* fast_pattern only with depth */
585  snprintf(string, sizeof(string),
586  "alert tcp any any -> any any "
587  "(content:\"one\"; %s%s depth:10; fast_pattern:only; sid:1;)",
588  sticky ? sticky : "", sticky ? "; " : " ");
589  s = DetectEngineAppendSig(de_ctx, string);
590  FAIL_IF_NOT_NULL(s);
591  /* fast_pattern only negate */
592  snprintf(string, sizeof(string),
593  "alert tcp any any -> any any "
594  "(content:\"one\"; %s%s content:!\"two\"; %s%sfast_pattern:only; sid:1;)",
595  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
596  s = DetectEngineAppendSig(de_ctx, string);
597  FAIL_IF_NOT_NULL(s);
598  /* fast_pattern chop with invalid values */
599  snprintf(string, sizeof(string),
600  "alert tcp any any -> any any "
601  "(content:\"one\"; %s%sfast_pattern:5,6; sid:1;)",
602  sticky ? sticky : "", sticky ? "; " : " ");
603  s = DetectEngineAppendSig(de_ctx, string);
604  FAIL_IF_NOT_NULL(s);
605  /* fast_pattern chop with invalid values */
606  snprintf(string, sizeof(string),
607  "alert tcp any any -> any any "
608  "(content:\"one\"; %s%sfast_pattern:65977,2; sid:1;)",
609  sticky ? sticky : "", sticky ? "; " : " ");
610  s = DetectEngineAppendSig(de_ctx, string);
611  FAIL_IF_NOT_NULL(s);
612  /* fast_pattern chop with invalid values */
613  snprintf(string, sizeof(string),
614  "alert tcp any any -> any any "
615  "(content:\"one\"; %s%sfast_pattern:2,65977; sid:1;)",
616  sticky ? sticky : "", sticky ? "; " : " ");
617  s = DetectEngineAppendSig(de_ctx, string);
618  FAIL_IF_NOT_NULL(s);
619  /* fast_pattern chop with invalid values */
620  snprintf(string, sizeof(string),
621  "alert tcp any any -> any any "
622  "(content:\"one\"; %s%sfast_pattern:2,65534; sid:1;)",
623  sticky ? sticky : "", sticky ? "; " : " ");
624  s = DetectEngineAppendSig(de_ctx, string);
625  FAIL_IF_NOT_NULL(s);
626  /* fast_pattern chop with invalid values */
627  snprintf(string, sizeof(string),
628  "alert tcp any any -> any any "
629  "(content:\"one\"; %s%sfast_pattern:65534,2; sid:1;)",
630  sticky ? sticky : "", sticky ? "; " : " ");
631  s = DetectEngineAppendSig(de_ctx, string);
632  FAIL_IF_NOT_NULL(s);
633  /* negated fast_pattern with distance */
634  snprintf(string, sizeof(string),
635  "alert tcp any any -> any any "
636  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%sdistance:10; sid:1;)",
637  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
638  s = DetectEngineAppendSig(de_ctx, string);
639  FAIL_IF_NOT_NULL(s);
640  /* negated fast_pattern with within */
641  snprintf(string, sizeof(string),
642  "alert tcp any any -> any any "
643  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%swithin:10; sid:1;)",
644  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
645  s = DetectEngineAppendSig(de_ctx, string);
646  FAIL_IF_NOT_NULL(s);
647  /* negated fast_pattern with depth */
648  snprintf(string, sizeof(string),
649  "alert tcp any any -> any any "
650  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%sdepth:10; sid:1;)",
651  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
652  s = DetectEngineAppendSig(de_ctx, string);
653  FAIL_IF_NOT_NULL(s);
654  /* negated fast_pattern with offset */
655  snprintf(string, sizeof(string),
656  "alert tcp any any -> any any "
657  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%soffset:10; sid:1;)",
658  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
659  s = DetectEngineAppendSig(de_ctx, string);
660  FAIL_IF_NOT_NULL(s);
662  PASS;
663 }
664 
665 static int DetectFastPatternStickySingleFPOnly(const char *sticky, const int list)
666 {
669  char string[1024];
670  snprintf(string, sizeof(string),
671  "alert tcp any any -> any any "
672  "(%s%scontent:\"one\"; fast_pattern:only; sid:1;)",
673  sticky ? sticky : "", sticky ? "; " : " ");
674  Signature *s = DetectEngineAppendSig(de_ctx, string);
675  FAIL_IF_NULL(s);
676  SigMatch *sm = GetMatches(s, list);
677  FAIL_IF_NULL(sm);
684  PASS;
685 }
686 
687 static int DetectFastPatternModifierFPOnly(const char *sticky, const int list)
688 {
691  char string[1024];
692  snprintf(string, sizeof(string),
693  "alert tcp any any -> any any "
694  "(content:\"one\"; %s%sfast_pattern:only; sid:1;)",
695  sticky ? sticky : "", sticky ? "; " : " ");
696  Signature *s = DetectEngineAppendSig(de_ctx, string);
697  FAIL_IF_NULL(s);
698  SigMatch *sm = GetMatches(s, list);
699  FAIL_IF_NULL(sm);
705 
706  snprintf(string, sizeof(string),
707  "alert tcp any any -> any any "
708  "(content:\"one\"; %s%scontent:\"two\"; %s%sfast_pattern:only; sid:2;)",
709  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
710  s = DetectEngineAppendSig(de_ctx, string);
711  FAIL_IF_NULL(s);
712  sm = GetMatches(s, list);
713  FAIL_IF_NULL(sm);
714  FAIL_IF_NULL(sm->next);
716  cd = (DetectContentData *)sm->ctx;
718  FAIL_IF_NOT(
720  sm = sm->next;
722  cd = (DetectContentData *)sm->ctx;
726 
727  snprintf(string, sizeof(string),
728  "alert tcp any any -> any any "
729  "(content:\"one\"; %s%scontent:\"two\"; distance:10; %s%scontent:\"three\"; "
730  "%s%sfast_pattern:only; sid:3;)",
731  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
732  sticky ? sticky : "", sticky ? "; " : " ");
733  s = DetectEngineAppendSig(de_ctx, string);
734  FAIL_IF_NULL(s);
735  sm = GetMatches(s, list);
736  FAIL_IF_NULL(sm);
737  FAIL_IF_NULL(sm->next);
739  cd = (DetectContentData *)sm->ctx;
741  FAIL_IF_NOT(
743  sm = sm->next;
744  FAIL_IF_NULL(sm->next);
746  cd = (DetectContentData *)sm->ctx;
748  FAIL_IF_NOT(
750  sm = sm->next;
751  FAIL_IF_NOT_NULL(sm->next);
753  cd = (DetectContentData *)sm->ctx;
757 
758  snprintf(string, sizeof(string),
759  "alert tcp any any -> any any "
760  "(content:\"one\"; %s%scontent:\"two\"; within:10; %s%scontent:\"three\"; "
761  "%s%sfast_pattern:only; sid:4;)",
762  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
763  sticky ? sticky : "", sticky ? "; " : " ");
764  s = DetectEngineAppendSig(de_ctx, string);
765  FAIL_IF_NULL(s);
766  sm = GetMatches(s, list);
767  FAIL_IF_NULL(sm);
768  FAIL_IF_NULL(sm->next);
770  cd = (DetectContentData *)sm->ctx;
772  FAIL_IF_NOT(
774  sm = sm->next;
775  FAIL_IF_NULL(sm->next);
777  cd = (DetectContentData *)sm->ctx;
779  FAIL_IF_NOT(
781  sm = sm->next;
782  FAIL_IF_NOT_NULL(sm->next);
784  cd = (DetectContentData *)sm->ctx;
788 
789  snprintf(string, sizeof(string),
790  "alert tcp any any -> any any "
791  "(content:\"one\"; %s%scontent:\"two\"; offset:10; %s%scontent:\"three\"; "
792  "%s%sfast_pattern:only; sid:5;)",
793  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
794  sticky ? sticky : "", sticky ? "; " : " ");
795  s = DetectEngineAppendSig(de_ctx, string);
796  FAIL_IF_NULL(s);
797  sm = GetMatches(s, list);
798  FAIL_IF_NULL(sm);
799  FAIL_IF_NULL(sm->next);
801  cd = (DetectContentData *)sm->ctx;
803  FAIL_IF_NOT(
805  sm = sm->next;
806  FAIL_IF_NULL(sm->next);
808  cd = (DetectContentData *)sm->ctx;
810  FAIL_IF_NOT(
812  sm = sm->next;
813  FAIL_IF_NOT_NULL(sm->next);
815  cd = (DetectContentData *)sm->ctx;
819 
820  snprintf(string, sizeof(string),
821  "alert tcp any any -> any any "
822  "(content:\"one\"; %s%scontent:\"two\"; depth:10; %s%scontent:\"three\"; "
823  "%s%sfast_pattern:only; sid:6;)",
824  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
825  sticky ? sticky : "", sticky ? "; " : " ");
826  s = DetectEngineAppendSig(de_ctx, string);
827  FAIL_IF_NULL(s);
828  sm = GetMatches(s, list);
829  FAIL_IF_NULL(sm);
830  FAIL_IF_NULL(sm->next);
832  cd = (DetectContentData *)sm->ctx;
834  FAIL_IF_NOT(
836  sm = sm->next;
837  FAIL_IF_NULL(sm->next);
839  cd = (DetectContentData *)sm->ctx;
841  FAIL_IF_NOT(
843  sm = sm->next;
844  FAIL_IF_NOT_NULL(sm->next);
846  cd = (DetectContentData *)sm->ctx;
850 
851  snprintf(string, sizeof(string),
852  "alert tcp any any -> any any "
853  "(content:!\"one\"; %s%sfast_pattern; content:\"two\"; depth:10; %s%ssid:7;)",
854  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
855  s = DetectEngineAppendSig(de_ctx, string);
856  FAIL_IF_NULL(s);
857  sm = GetMatches(s, list);
858  FAIL_IF_NULL(sm);
859  FAIL_IF_NULL(sm->next);
861  cd = (DetectContentData *)sm->ctx;
866  sm = sm->next;
867  FAIL_IF_NOT_NULL(sm->next);
869  cd = (DetectContentData *)sm->ctx;
871  FAIL_IF_NOT(
873 
875  PASS;
876 }
877 
878 static int DetectFastPatternStickyFPChop(const char *sticky, const int list)
879 {
882  char string[1024];
883  snprintf(string, sizeof(string),
884  "alert tcp any any -> any any "
885  "(%s%scontent:\"onetwothree\"; fast_pattern:3,4; sid:1;)",
886  sticky ? sticky : "", sticky ? "; " : " ");
887  Signature *s = DetectEngineAppendSig(de_ctx, string);
888  FAIL_IF_NULL(s);
889  SigMatch *sm = GetMatches(s, list);
890  FAIL_IF_NULL(sm);
897  FAIL_IF_NOT(cd->fp_chop_offset == 3);
898  FAIL_IF_NOT(cd->fp_chop_len == 4);
899 
900  snprintf(string, sizeof(string),
901  "alert tcp any any -> any any "
902  "(%s%scontent:\"onetwothree\"; fast_pattern:3,4; content:\"xyz\"; distance:10; sid:2;)",
903  sticky ? sticky : "", sticky ? "; " : " ");
904  s = DetectEngineAppendSig(de_ctx, string);
905  FAIL_IF_NULL(s);
906  sm = GetMatches(s, list);
907  FAIL_IF_NULL(sm);
909  cd = (DetectContentData *)sm->ctx;
914  FAIL_IF_NOT(cd->fp_chop_offset == 3);
915  FAIL_IF_NOT(cd->fp_chop_len == 4);
916 
918  PASS;
919 }
920 
921 static int DetectFastPatternModifierFPChop(const char *sticky, const int list)
922 {
925  char string[1024];
926  snprintf(string, sizeof(string),
927  "alert tcp any any -> any any "
928  "(content:\"onetwothree\"; %s%sfast_pattern:3,4; sid:1;)",
929  sticky ? sticky : "", sticky ? "; " : " ");
930  Signature *s = DetectEngineAppendSig(de_ctx, string);
931  FAIL_IF_NULL(s);
932  SigMatch *sm = GetMatches(s, list);
933  FAIL_IF_NULL(sm);
940  FAIL_IF_NOT(cd->fp_chop_offset == 3);
941  FAIL_IF_NOT(cd->fp_chop_len == 4);
942 
943  snprintf(string, sizeof(string),
944  "alert tcp any any -> any any "
945  "(content:!\"onetwothree\"; %s%sfast_pattern:3,4; sid:2;)",
946  sticky ? sticky : "", sticky ? "; " : " ");
947  s = DetectEngineAppendSig(de_ctx, string);
948  FAIL_IF_NULL(s);
949  sm = GetMatches(s, list);
950  FAIL_IF_NULL(sm);
952  cd = (DetectContentData *)sm->ctx;
959  FAIL_IF_NOT(cd->fp_chop_offset == 3);
960  FAIL_IF_NOT(cd->fp_chop_len == 4);
961 
963  PASS;
964 }
965 
966 /**
967  * \test Checks if a fast_pattern is registered in a Signature
968  */
969 static int DetectFastPatternTest01(void)
970 {
971  FAIL_IF_NOT(DetectFastPatternStickySingle(NULL, DETECT_SM_LIST_PMATCH));
972  FAIL_IF_NOT(DetectFastPatternModifierSingle(NULL, DETECT_SM_LIST_PMATCH));
973  FAIL_IF_NOT(DetectFastPatternStickySingleNoFP(NULL, DETECT_SM_LIST_PMATCH));
974  FAIL_IF_NOT(DetectFastPatternModifierSingleNoFP(NULL, DETECT_SM_LIST_PMATCH));
975  FAIL_IF_NOT(DetectFastPatternStickySingleBadArg(NULL));
976  FAIL_IF_NOT(DetectFastPatternModifierBadRules(NULL));
977  FAIL_IF_NOT(DetectFastPatternStickySingleFPOnly(NULL, DETECT_SM_LIST_PMATCH));
978  FAIL_IF_NOT(DetectFastPatternModifierFPOnly(NULL, DETECT_SM_LIST_PMATCH));
979  FAIL_IF_NOT(DetectFastPatternStickyFPChop(NULL, DETECT_SM_LIST_PMATCH));
980  FAIL_IF_NOT(DetectFastPatternModifierFPChop(NULL, DETECT_SM_LIST_PMATCH));
981 
982  struct {
983  const char *buffer_name;
984  const char *sb_name;
985  const char *mod_name;
986  } keywords[] = {
987  { "file_data", "file.data", NULL },
988  { "http_uri", "http.uri", "http_uri" },
989  { "http_raw_uri", "http.uri.raw", "http_raw_uri" },
990  { "http_user_agent", "http.user_agent", "http_user_agent" },
991  { "http_header", "http.header", "http_header" },
992  // http_raw_header requires sigs to have a direction
993  //{ "http_raw_header", "http.header.raw", "http_raw_header" },
994  { "http_method", "http.method", "http_method" },
995  { "http_cookie", "http.cookie", "http_cookie" },
996  { "http_host", "http.host", "http_host" },
997  { "http_raw_host", "http.host.raw", "http_raw_host" },
998  { "http_stat_code", "http.stat_code", "http_stat_code" },
999  { "http_stat_msg", "http.stat_msg", "http_stat_msg" },
1000  { "http_client_body", "http.request_body", "http_client_body" },
1001  { NULL, NULL, NULL },
1002  };
1003 
1004  for (int i = 0; keywords[i].buffer_name != NULL; i++) {
1005  const int list_id = DetectBufferTypeGetByName(keywords[i].buffer_name);
1006  FAIL_IF(list_id == -1);
1007 
1008  const char *k = keywords[i].sb_name;
1009  if (k) {
1010  FAIL_IF_NOT(DetectFastPatternStickySingle(k, list_id));
1011  FAIL_IF_NOT(DetectFastPatternStickySingleNoFP(k, list_id));
1012  FAIL_IF_NOT(DetectFastPatternStickySingleBadArg(k));
1013  FAIL_IF_NOT(DetectFastPatternStickySingleFPOnly(k, list_id));
1014  FAIL_IF_NOT(DetectFastPatternStickyFPChop(k, list_id));
1015  }
1016  k = keywords[i].mod_name;
1017  if (k) {
1018  FAIL_IF_NOT(DetectFastPatternModifierSingle(k, list_id));
1019  FAIL_IF_NOT(DetectFastPatternModifierSingleNoFP(k, list_id));
1020  FAIL_IF_NOT(DetectFastPatternModifierBadRules(k));
1021  FAIL_IF_NOT(DetectFastPatternModifierFPOnly(k, list_id));
1022  FAIL_IF_NOT(DetectFastPatternModifierFPChop(k, list_id));
1023  }
1024  }
1025 
1026  PASS;
1027 }
1028 
1029 /**
1030  * \test Checks to make sure that other sigs work that should when fast_pattern is inspecting on the
1031  * same payload
1032  *
1033  */
1034 static int DetectFastPatternTest14(void)
1035 {
1036  uint8_t *buf = (uint8_t *)"Dummy is our name. Oh yes. From right here "
1037  "right now, all the way to hangover. right. strings5_imp now here "
1038  "comes our dark knight strings_string5. Yes here is our dark knight";
1039  uint16_t buflen = strlen((char *)buf);
1040  ThreadVars th_v;
1041  DetectEngineThreadCtx *det_ctx = NULL;
1042 
1043  memset(&th_v, 0, sizeof(th_v));
1044  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
1045  FAIL_IF_NULL(p);
1046 
1049  de_ctx->flags |= DE_QUIET;
1050 
1052 
1054  "alert tcp any any -> any any "
1055  "(msg:\"fast_pattern test\"; content:\"strings_string5\"; content:\"knight\"; "
1056  "fast_pattern; sid:1;)");
1057  FAIL_IF_NULL(s);
1058 
1060  "alert tcp any any -> any any "
1061  "(msg:\"test different content\"; content:\"Dummy is our name\"; sid:2;)");
1062  FAIL_IF_NULL(s);
1063 
1065  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1066 
1067  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1070 
1071  UTHFreePackets(&p, 1);
1072  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1074  FlowShutdown();
1075  PASS;
1076 }
1077 
1078 /**
1079  * Unittest to check
1080  * - if we assign different content_ids to duplicate patterns, but one of the
1081  * patterns has a fast_pattern chop set.
1082  * - if 2 unique patterns get unique ids.
1083  * - if 2 duplicate patterns, with no chop set get unique ids.
1084  */
1085 static int DetectFastPatternTest671(void)
1086 {
1089  de_ctx->flags |= DE_QUIET;
1090 
1091  Signature *s[6];
1092  s[0] = DetectEngineAppendSig(
1093  de_ctx, "alert tcp any any -> any any (content:\"onetwothreefour\"; sid:1;)");
1094  FAIL_IF_NULL(s[0]);
1095  s[1] = DetectEngineAppendSig(
1096  de_ctx, "alert tcp any any -> any any (content:\"onetwothreefour\"; sid:2;)");
1097  FAIL_IF_NULL(s[1]);
1098  s[2] = DetectEngineAppendSig(
1099  de_ctx, "alert tcp any any -> any any (content:\"uniquepattern\"; sid:3;)");
1100  FAIL_IF_NULL(s[2]);
1102  "alert tcp any any -> any any (content:\"onetwothreefour\"; fast_pattern:3,5; sid:4;)");
1103  FAIL_IF_NULL(s[3]);
1104  s[4] = DetectEngineAppendSig(
1105  de_ctx, "alert tcp any any -> any any (content:\"twoth\"; sid:5;)");
1106  FAIL_IF_NULL(s[4]);
1108  "alert tcp any any -> any any (content:\"onetwothreefour\"; fast_pattern:0,15; "
1109  "sid:6;)");
1110  FAIL_IF_NULL(s[5]);
1111 
1113 
1115  DetectContentData *cd = (DetectContentData *)smd->ctx;
1116  FAIL_IF(cd->id != 0);
1117 
1118  smd = s[1]->sm_arrays[DETECT_SM_LIST_PMATCH];
1119  cd = (DetectContentData *)smd->ctx;
1120  FAIL_IF(cd->id != 0);
1121 
1122  smd = s[2]->sm_arrays[DETECT_SM_LIST_PMATCH];
1123  cd = (DetectContentData *)smd->ctx;
1124  FAIL_IF(cd->id != 2);
1125 
1126  smd = s[3]->sm_arrays[DETECT_SM_LIST_PMATCH];
1127  cd = (DetectContentData *)smd->ctx;
1128  FAIL_IF(cd->id != 1);
1129 
1130  smd = s[4]->sm_arrays[DETECT_SM_LIST_PMATCH];
1131  cd = (DetectContentData *)smd->ctx;
1132  FAIL_IF(cd->id != 1);
1133 
1134  smd = s[5]->sm_arrays[DETECT_SM_LIST_PMATCH];
1135  cd = (DetectContentData *)smd->ctx;
1136  FAIL_IF(cd->id != 0);
1137 
1139  PASS;
1140 }
1141 
1142 static int DetectFastPatternPrefilter(void)
1143 {
1146  const char *string = "alert tcp any any -> any any "
1147  "(content:\"one\"; prefilter; sid:1;)";
1148  Signature *s = DetectEngineAppendSig(de_ctx, string);
1149  FAIL_IF_NULL(s);
1151  FAIL_IF_NULL(sm);
1157  PASS;
1158 }
1159 
1160 static void DetectFastPatternRegisterTests(void)
1161 {
1162  UtRegisterTest("DetectFastPatternTest01", DetectFastPatternTest01);
1163  UtRegisterTest("DetectFastPatternTest14", DetectFastPatternTest14);
1164  /* Unittest to check
1165  * - if we assign different content_ids to duplicate patterns, but one of the
1166  * patterns has a fast_pattern chop set.
1167  * - if 2 unique patterns get unique ids.
1168  * - if 2 duplicate patterns, with no chop set get unique ids.
1169  */
1170  UtRegisterTest("DetectFastPatternTest671", DetectFastPatternTest671);
1171 
1172  UtRegisterTest("DetectFastPatternPrefilter", DetectFastPatternPrefilter);
1173 }
1174 #endif
util-byte.h
SCFPSupportSMList_
Definition: detect.h:789
SigTableElmt_::url
const char * url
Definition: detect.h:1339
detect-content.h
detect-engine.h
DetectBufferGetFirstSigMatch
SigMatch * DetectBufferGetFirstSigMatch(const Signature *s, const uint32_t buf_id)
Definition: detect-engine.c:1355
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:118
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
DETECT_CONTENT_FAST_PATTERN_CHOP
#define DETECT_CONTENT_FAST_PATTERN_CHOP
Definition: detect-content.h:36
SignatureInitData_::smlists
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
Definition: detect.h:605
DetectContentData_::fp_chop_len
uint16_t fp_chop_len
Definition: detect-content.h:98
SigTableElmt_::desc
const char * desc
Definition: detect.h:1338
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:153
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1326
SCFPSupportSMList_::next
struct SCFPSupportSMList_ * next
Definition: detect.h:792
DetectParseRegex
Definition: detect-parse.h:62
SCFPSupportSMList_::list_id
int list_id
Definition: detect.h:790
SigTableElmt_::name
const char * name
Definition: detect.h:1336
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:71
Signature_::alproto
AppProto alproto
Definition: detect.h:633
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
SIG_FLAG_INIT_TXDIR_FAST_TOCLIENT
#define SIG_FLAG_INIT_TXDIR_FAST_TOCLIENT
Definition: detect.h:305
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
PacketAlertCheck
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
Definition: detect-engine-alert.c:141
DETECT_FAST_PATTERN
@ DETECT_FAST_PATTERN
Definition: detect-engine-register.h:82
SigMatchData_::ctx
SigMatchCtx * ctx
Definition: detect.h:370
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1330
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:870
StringParseUint16
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:337
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2763
SupportFastPatternForSigMatchTypes
void SupportFastPatternForSigMatchTypes(void)
Registers the keywords(SMs) that should be given fp support.
Definition: detect-fast-pattern.c:142
SIG_FLAG_TXBOTHDIR
#define SIG_FLAG_TXBOTHDIR
Definition: detect.h:249
DE_QUIET
#define DE_QUIET
Definition: detect.h:332
UTHBuildPacket
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.
Definition: util-unittest-helper.c:359
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1981
Signature_::sm_arrays
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
Definition: detect.h:682
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:571
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:2901
DetectContentData_
Definition: detect-content.h:93
DetectContentData_::fp_chop_offset
uint16_t fp_chop_offset
Definition: detect-content.h:100
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:2847
SigMatchData_
Data needed for Match()
Definition: detect.h:367
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1321
DetectEngineRegisterFastPatternForId
void DetectEngineRegisterFastPatternForId(DetectEngineCtx *de_ctx, int list_id, int priority)
Definition: detect-fast-pattern.c:134
PARSE_REGEX
#define PARSE_REGEX
Definition: detect-fast-pattern.c:42
util-unittest.h
util-unittest-helper.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:82
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1123
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:518
FAIL_IF_NOT_NULL
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
Definition: util-unittest.h:96
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
util-error.h
DETECT_CONTENT_DISTANCE
#define DETECT_CONTENT_DISTANCE
Definition: detect-content.h:30
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:18
DetectEngineThreadCtx_
Definition: detect.h:1126
DetectGetLastSMFromMpmLists
SigMatch * DetectGetLastSMFromMpmLists(const DetectEngineCtx *de_ctx, const Signature *s)
get the last SigMatch from lists that support MPM.
Definition: detect-parse.c:595
DETECT_SM_LIST_BASE64_DATA
@ DETECT_SM_LIST_BASE64_DATA
Definition: detect.h:123
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:3027
DETECT_CONTENT_DEPTH
#define DETECT_CONTENT_DEPTH
Definition: detect-content.h:33
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
Definition: detect-engine.c:3496
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:362
DETECT_CONTENT_IS_SINGLE
#define DETECT_CONTENT_IS_SINGLE(c)
Definition: detect-content.h:68
DETECT_CONTENT_NEGATED
#define DETECT_CONTENT_NEGATED
Definition: detect-content.h:40
DetectContentData_::id
PatIntId id
Definition: detect-content.h:105
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:361
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:309
DetectBufferToClient
bool DetectBufferToClient(const DetectEngineCtx *de_ctx, int buf_id, AppProto alproto)
Definition: detect-engine-mpm.c:1075
Signature_::flags
uint32_t flags
Definition: detect.h:629
DetectEngineInitializeFastPatternList
void DetectEngineInitializeFastPatternList(DetectEngineCtx *de_ctx)
Definition: detect-fast-pattern.c:149
Packet_
Definition: decode.h:476
detect-engine-build.h
detect-engine-alert.h
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:104
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:698
FastPatternSupportEnabledForSigMatchList
int FastPatternSupportEnabledForSigMatchList(const DetectEngineCtx *de_ctx, const int list_id)
Checks if a particular buffer is in the list of lists that need to be searched for a keyword that has...
Definition: detect-fast-pattern.c:64
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1304
SCFPSupportSMList_::priority
int priority
Definition: detect.h:791
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2113
DetectEngineBufferTypeSupportsMpmGetById
bool DetectEngineBufferTypeSupportsMpmGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1299
detect-fast-pattern.h
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
suricata-common.h
SigMatch_::idx
uint16_t idx
Definition: detect.h:360
SigMatch_::type
uint16_t type
Definition: detect.h:359
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:665
SupportFastPatternForSigMatchList
void SupportFastPatternForSigMatchList(int list_id, int priority)
Lets one add a sm list id to be searched for potential fp supported keywords later.
Definition: detect-fast-pattern.c:129
SignatureInitData_::curbuf
SignatureInitDataBuffer * curbuf
Definition: detect.h:613
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
Definition: detect-engine.c:3723
FatalError
#define FatalError(...)
Definition: util-debug.h:502
SIGMATCH_OPTIONAL_OPT
#define SIGMATCH_OPTIONAL_OPT
Definition: detect.h:1529
DetectEngineFreeFastPatternList
void DetectEngineFreeFastPatternList(DetectEngineCtx *de_ctx)
Definition: detect-fast-pattern.c:171
SIG_FLAG_INIT_TXDIR_STREAMING_TOSERVER
#define SIG_FLAG_INIT_TXDIR_STREAMING_TOSERVER
Definition: detect.h:303
HtpBodyChunk_::next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:184
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
SigMatchListSMBelongsTo
int SigMatchListSMBelongsTo(const Signature *s, const SigMatch *key_sm)
Definition: detect-parse.c:831
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Signature_::id
uint32_t id
Definition: detect.h:664
DETECT_CONTENT_OFFSET
#define DETECT_CONTENT_OFFSET
Definition: detect-content.h:32
DETECT_CONTENT_FAST_PATTERN_ONLY
#define DETECT_CONTENT_FAST_PATTERN_ONLY
Definition: detect-content.h:35
detect-parse.h
SignatureInitDataBuffer_::id
uint32_t id
Definition: detect.h:539
Signature_
Signature container.
Definition: detect.h:628
SigMatch_
a single match condition for a signature
Definition: detect.h:358
DETECT_SM_LIST_MAX
@ DETECT_SM_LIST_MAX
Definition: detect.h:134
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2724
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:43
DetectFastPatternRegister
void DetectFastPatternRegister(void)
Registration function for fast_pattern keyword.
Definition: detect-fast-pattern.c:184
DetectContentData_::content_len
uint16_t content_len
Definition: detect-content.h:95
DetectGetLastSMFromLists
SigMatch * DetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
Definition: detect-parse.c:632
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:872
flow.h
DETECT_CONTENT_FAST_PATTERN
#define DETECT_CONTENT_FAST_PATTERN
Definition: detect-content.h:34
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
DetectEngineCtx_::fp_support_smlist_list
SCFPSupportSMList * fp_support_smlist_list
Definition: detect.h:1048
DETECT_CONTENT_WITHIN
#define DETECT_CONTENT_WITHIN
Definition: detect-content.h:31
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1328
UTHFreePackets
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:450