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, (const char *)arg_substr) <= 0) {
323  SCLogError("Invalid fast pattern offset:"
324  " \"%s\"",
325  arg_substr);
326  goto error;
327  }
328 
329  pcre2len = sizeof(arg_substr);
330  res = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)arg_substr, &pcre2len);
331  if (res < 0) {
332  SCLogError("pcre2_substring_copy_bynumber failed "
333  "for fast_pattern offset");
334  goto error;
335  }
336  uint16_t length;
337  if (StringParseUint16(&length, 10, 0, (const char *)arg_substr) <= 0) {
338  SCLogError("Invalid value for fast "
339  "pattern: \"%s\"",
340  arg_substr);
341  goto error;
342  }
343 
344  // Avoiding integer overflow
345  if (offset > (65535 - length)) {
346  SCLogError("Fast pattern (length + offset) "
347  "exceeds limit pattern length limit");
348  goto error;
349  }
350 
351  if (offset + length > cd->content_len) {
352  SCLogError("Fast pattern (length + "
353  "offset (%u)) exceeds pattern length (%u)",
354  offset + length, cd->content_len);
355  goto error;
356  }
357 
358  cd->fp_chop_offset = offset;
359  cd->fp_chop_len = length;
361 
362  } else {
363  SCLogError("parse error, ret %" PRId32 ", string %s", ret, arg);
364  goto error;
365  }
366 
368 
369  pcre2_match_data_free(match);
370  return 0;
371 
372  error:
373  if (match) {
374  pcre2_match_data_free(match);
375  }
376  return -1;
377 }
378 
379 /*----------------------------------Unittests---------------------------------*/
380 
381 #ifdef UNITTESTS
382 #include "detect-engine-alert.h"
383 #include "detect-engine-buffer.h"
384 static SigMatch *GetMatches(Signature *s, const int list)
385 {
386  SigMatch *sm = DetectBufferGetFirstSigMatch(s, list);
387  if (sm == NULL && list < DETECT_SM_LIST_MAX) {
388  sm = s->init_data->smlists[list];
389  }
390  return sm;
391 }
392 
393 static int DetectFastPatternStickySingle(const char *sticky, const int list)
394 {
397  char string[1024];
398  snprintf(string, sizeof(string),
399  "alert tcp any any -> any any "
400  "(%s%scontent:\"one\"; fast_pattern; sid:1;)",
401  sticky ? sticky : "", sticky ? "; " : " ");
402  Signature *s = DetectEngineAppendSig(de_ctx, string);
403  FAIL_IF_NULL(s);
404  SigMatch *sm = GetMatches(s, list);
405  FAIL_IF_NULL(sm);
411  PASS;
412 }
413 
414 static int DetectFastPatternModifierSingle(const char *sticky, const int list)
415 {
418  char string[1024];
419  snprintf(string, sizeof(string),
420  "alert tcp any any -> any any "
421  "(content:\"one\"; %s%sfast_pattern; sid:1;)",
422  sticky ? sticky : "", sticky ? "; " : " ");
423  Signature *s = DetectEngineAppendSig(de_ctx, string);
424  FAIL_IF_NULL(s);
425  SigMatch *sm = GetMatches(s, list);
426  FAIL_IF_NULL(sm);
432  PASS;
433 }
434 
435 static int DetectFastPatternStickySingleNoFP(const char *sticky, const int list)
436 {
439  char string[1024];
440  snprintf(string, sizeof(string),
441  "alert tcp any any -> any any "
442  "(%s%scontent:\"one\"; sid:1;)",
443  sticky ? sticky : "", sticky ? "; " : " ");
444  Signature *s = DetectEngineAppendSig(de_ctx, string);
445  FAIL_IF_NULL(s);
446  SigMatch *sm = GetMatches(s, list);
447  FAIL_IF_NULL(sm);
453  PASS;
454 }
455 
456 static int DetectFastPatternModifierSingleNoFP(const char *sticky, const int list)
457 {
460  char string[1024];
461  snprintf(string, sizeof(string),
462  "alert tcp any any -> any any "
463  "(content:\"one\"; %s%ssid:1;)",
464  sticky ? sticky : "", sticky ? "; " : " ");
465  Signature *s = DetectEngineAppendSig(de_ctx, string);
466  FAIL_IF_NULL(s);
467  SigMatch *sm = GetMatches(s, list);
468  FAIL_IF_NULL(sm);
474  PASS;
475 }
476 
477 static int DetectFastPatternStickySingleBadArg(const char *sticky)
478 {
481  char string[1024];
482  /* bogus argument to fast_pattern */
483  snprintf(string, sizeof(string),
484  "alert tcp any any -> any any "
485  "(%s%scontent:\"one\"; fast_pattern:boo; sid:1;)",
486  sticky ? sticky : "", sticky ? "; " : " ");
487  Signature *s = DetectEngineAppendSig(de_ctx, string);
488  FAIL_IF_NOT_NULL(s);
489  /* fast_pattern only with distance */
490  snprintf(string, sizeof(string),
491  "alert tcp any any -> any any "
492  "(%s%scontent:\"one\"; fast_pattern:only; content:\"two\"; distance:10; sid:1;)",
493  sticky ? sticky : "", sticky ? "; " : " ");
494  s = DetectEngineAppendSig(de_ctx, string);
495  FAIL_IF_NOT_NULL(s);
496  /* fast_pattern only with distance */
497  snprintf(string, sizeof(string),
498  "alert tcp any any -> any any "
499  "(%s%scontent:\"one\"; content:\"two\"; fast_pattern:only; distance:10; sid:1;)",
500  sticky ? sticky : "", sticky ? "; " : " ");
501  s = DetectEngineAppendSig(de_ctx, string);
502  FAIL_IF_NOT_NULL(s);
503  /* fast_pattern only with distance */
504  snprintf(string, sizeof(string),
505  "alert tcp any any -> any any "
506  "(%s%scontent:\"one\"; content:\"two\"; distance:10; fast_pattern:only; sid:1;)",
507  sticky ? sticky : "", sticky ? "; " : " ");
508  s = DetectEngineAppendSig(de_ctx, string);
509  FAIL_IF_NOT_NULL(s);
510  /* fast_pattern chop with invalid values */
511  snprintf(string, sizeof(string),
512  "alert tcp any any -> any any "
513  "(%s%scontent:\"one\"; fast_pattern:5,6; sid:1;)",
514  sticky ? sticky : "", sticky ? "; " : " ");
515  s = DetectEngineAppendSig(de_ctx, string);
516  FAIL_IF_NOT_NULL(s);
518  PASS;
519 }
520 
521 static int DetectFastPatternModifierBadRules(const char *sticky)
522 {
525  char string[1024];
526  /* bogus argument to fast_pattern */
527  snprintf(string, sizeof(string),
528  "alert tcp any any -> any any "
529  "(content:\"one\"; %s%sfast_pattern:boo; sid:1;)",
530  sticky ? sticky : "", sticky ? "; " : " ");
531  Signature *s = DetectEngineAppendSig(de_ctx, string);
532  FAIL_IF_NOT_NULL(s);
533  /* fast_pattern only with distance */
534  snprintf(string, sizeof(string),
535  "alert tcp any any -> any any "
536  "(content:\"one\"; %s%sfast_pattern:only; content:\"two\"; %s%sdistance:10; sid:1;)",
537  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
538  s = DetectEngineAppendSig(de_ctx, string);
539  FAIL_IF_NOT_NULL(s);
540 #if 0 // TODO bug?
541  /* fast_pattern only with distance */
542  snprintf(string, sizeof(string), "alert tcp any any -> any any "
543  "(content:\"one\"; %s%s content:\"two\"; %s%sdistance:10; fast_pattern:only; sid:1;)",
544  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
545  s = DetectEngineAppendSig(de_ctx, string);
546  FAIL_IF_NOT_NULL(s);
547 #endif
548  /* fast_pattern only with within */
549  snprintf(string, sizeof(string),
550  "alert tcp any any -> any any "
551  "(content:\"one\"; %s%sfast_pattern:only; content:\"two\"; %s%swithin:10; sid:1;)",
552  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
553  s = DetectEngineAppendSig(de_ctx, string);
554  FAIL_IF_NOT_NULL(s);
555  /* fast_pattern only with within */
556  snprintf(string, sizeof(string),
557  "alert tcp any any -> any any "
558  "(content:\"one\"; %s%s content:\"two\"; %s%swithin:10; fast_pattern:only; sid:1;)",
559  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
560  s = DetectEngineAppendSig(de_ctx, string);
561  FAIL_IF_NOT_NULL(s);
562  /* fast_pattern only with offset */
563  snprintf(string, sizeof(string),
564  "alert tcp any any -> any any "
565  "(content:\"one\"; %s%sfast_pattern:only; offset:10; sid:1;)",
566  sticky ? sticky : "", sticky ? "; " : " ");
567  s = DetectEngineAppendSig(de_ctx, string);
568  FAIL_IF_NOT_NULL(s);
569  /* fast_pattern only with offset */
570  snprintf(string, sizeof(string),
571  "alert tcp any any -> any any "
572  "(content:\"one\"; %s%s offset:10; fast_pattern:only; sid:1;)",
573  sticky ? sticky : "", sticky ? "; " : " ");
574  s = DetectEngineAppendSig(de_ctx, string);
575  FAIL_IF_NOT_NULL(s);
576  /* fast_pattern only with depth */
577  snprintf(string, sizeof(string),
578  "alert tcp any any -> any any "
579  "(content:\"one\"; %s%sfast_pattern:only; depth:10; sid:1;)",
580  sticky ? sticky : "", sticky ? "; " : " ");
581  s = DetectEngineAppendSig(de_ctx, string);
582  FAIL_IF_NOT_NULL(s);
583  /* fast_pattern only with depth */
584  snprintf(string, sizeof(string),
585  "alert tcp any any -> any any "
586  "(content:\"one\"; %s%s depth:10; fast_pattern:only; sid:1;)",
587  sticky ? sticky : "", sticky ? "; " : " ");
588  s = DetectEngineAppendSig(de_ctx, string);
589  FAIL_IF_NOT_NULL(s);
590  /* fast_pattern only negate */
591  snprintf(string, sizeof(string),
592  "alert tcp any any -> any any "
593  "(content:\"one\"; %s%s content:!\"two\"; %s%sfast_pattern:only; sid:1;)",
594  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
595  s = DetectEngineAppendSig(de_ctx, string);
596  FAIL_IF_NOT_NULL(s);
597  /* fast_pattern chop with invalid values */
598  snprintf(string, sizeof(string),
599  "alert tcp any any -> any any "
600  "(content:\"one\"; %s%sfast_pattern:5,6; sid:1;)",
601  sticky ? sticky : "", sticky ? "; " : " ");
602  s = DetectEngineAppendSig(de_ctx, string);
603  FAIL_IF_NOT_NULL(s);
604  /* fast_pattern chop with invalid values */
605  snprintf(string, sizeof(string),
606  "alert tcp any any -> any any "
607  "(content:\"one\"; %s%sfast_pattern:65977,2; sid:1;)",
608  sticky ? sticky : "", sticky ? "; " : " ");
609  s = DetectEngineAppendSig(de_ctx, string);
610  FAIL_IF_NOT_NULL(s);
611  /* fast_pattern chop with invalid values */
612  snprintf(string, sizeof(string),
613  "alert tcp any any -> any any "
614  "(content:\"one\"; %s%sfast_pattern:2,65977; sid:1;)",
615  sticky ? sticky : "", sticky ? "; " : " ");
616  s = DetectEngineAppendSig(de_ctx, string);
617  FAIL_IF_NOT_NULL(s);
618  /* fast_pattern chop with invalid values */
619  snprintf(string, sizeof(string),
620  "alert tcp any any -> any any "
621  "(content:\"one\"; %s%sfast_pattern:2,65534; sid:1;)",
622  sticky ? sticky : "", sticky ? "; " : " ");
623  s = DetectEngineAppendSig(de_ctx, string);
624  FAIL_IF_NOT_NULL(s);
625  /* fast_pattern chop with invalid values */
626  snprintf(string, sizeof(string),
627  "alert tcp any any -> any any "
628  "(content:\"one\"; %s%sfast_pattern:65534,2; sid:1;)",
629  sticky ? sticky : "", sticky ? "; " : " ");
630  s = DetectEngineAppendSig(de_ctx, string);
631  FAIL_IF_NOT_NULL(s);
632  /* negated fast_pattern with distance */
633  snprintf(string, sizeof(string),
634  "alert tcp any any -> any any "
635  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%sdistance:10; sid:1;)",
636  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
637  s = DetectEngineAppendSig(de_ctx, string);
638  FAIL_IF_NOT_NULL(s);
639  /* negated fast_pattern with within */
640  snprintf(string, sizeof(string),
641  "alert tcp any any -> any any "
642  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%swithin:10; sid:1;)",
643  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
644  s = DetectEngineAppendSig(de_ctx, string);
645  FAIL_IF_NOT_NULL(s);
646  /* negated fast_pattern with depth */
647  snprintf(string, sizeof(string),
648  "alert tcp any any -> any any "
649  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%sdepth:10; sid:1;)",
650  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
651  s = DetectEngineAppendSig(de_ctx, string);
652  FAIL_IF_NOT_NULL(s);
653  /* negated fast_pattern with offset */
654  snprintf(string, sizeof(string),
655  "alert tcp any any -> any any "
656  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%soffset:10; sid:1;)",
657  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
658  s = DetectEngineAppendSig(de_ctx, string);
659  FAIL_IF_NOT_NULL(s);
661  PASS;
662 }
663 
664 static int DetectFastPatternStickySingleFPOnly(const char *sticky, const int list)
665 {
668  char string[1024];
669  snprintf(string, sizeof(string),
670  "alert tcp any any -> any any "
671  "(%s%scontent:\"one\"; fast_pattern:only; sid:1;)",
672  sticky ? sticky : "", sticky ? "; " : " ");
673  Signature *s = DetectEngineAppendSig(de_ctx, string);
674  FAIL_IF_NULL(s);
675  SigMatch *sm = GetMatches(s, list);
676  FAIL_IF_NULL(sm);
683  PASS;
684 }
685 
686 static int DetectFastPatternModifierFPOnly(const char *sticky, const int list)
687 {
690  char string[1024];
691  snprintf(string, sizeof(string),
692  "alert tcp any any -> any any "
693  "(content:\"one\"; %s%sfast_pattern:only; sid:1;)",
694  sticky ? sticky : "", sticky ? "; " : " ");
695  Signature *s = DetectEngineAppendSig(de_ctx, string);
696  FAIL_IF_NULL(s);
697  SigMatch *sm = GetMatches(s, list);
698  FAIL_IF_NULL(sm);
704 
705  snprintf(string, sizeof(string),
706  "alert tcp any any -> any any "
707  "(content:\"one\"; %s%scontent:\"two\"; %s%sfast_pattern:only; sid:2;)",
708  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
709  s = DetectEngineAppendSig(de_ctx, string);
710  FAIL_IF_NULL(s);
711  sm = GetMatches(s, list);
712  FAIL_IF_NULL(sm);
713  FAIL_IF_NULL(sm->next);
715  cd = (DetectContentData *)sm->ctx;
717  FAIL_IF_NOT(
719  sm = sm->next;
721  cd = (DetectContentData *)sm->ctx;
725 
726  snprintf(string, sizeof(string),
727  "alert tcp any any -> any any "
728  "(content:\"one\"; %s%scontent:\"two\"; distance:10; %s%scontent:\"three\"; "
729  "%s%sfast_pattern:only; sid:3;)",
730  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
731  sticky ? sticky : "", sticky ? "; " : " ");
732  s = DetectEngineAppendSig(de_ctx, string);
733  FAIL_IF_NULL(s);
734  sm = GetMatches(s, list);
735  FAIL_IF_NULL(sm);
736  FAIL_IF_NULL(sm->next);
738  cd = (DetectContentData *)sm->ctx;
740  FAIL_IF_NOT(
742  sm = sm->next;
743  FAIL_IF_NULL(sm->next);
745  cd = (DetectContentData *)sm->ctx;
747  FAIL_IF_NOT(
749  sm = sm->next;
750  FAIL_IF_NOT_NULL(sm->next);
752  cd = (DetectContentData *)sm->ctx;
756 
757  snprintf(string, sizeof(string),
758  "alert tcp any any -> any any "
759  "(content:\"one\"; %s%scontent:\"two\"; within:10; %s%scontent:\"three\"; "
760  "%s%sfast_pattern:only; sid:4;)",
761  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
762  sticky ? sticky : "", sticky ? "; " : " ");
763  s = DetectEngineAppendSig(de_ctx, string);
764  FAIL_IF_NULL(s);
765  sm = GetMatches(s, list);
766  FAIL_IF_NULL(sm);
767  FAIL_IF_NULL(sm->next);
769  cd = (DetectContentData *)sm->ctx;
771  FAIL_IF_NOT(
773  sm = sm->next;
774  FAIL_IF_NULL(sm->next);
776  cd = (DetectContentData *)sm->ctx;
778  FAIL_IF_NOT(
780  sm = sm->next;
781  FAIL_IF_NOT_NULL(sm->next);
783  cd = (DetectContentData *)sm->ctx;
787 
788  snprintf(string, sizeof(string),
789  "alert tcp any any -> any any "
790  "(content:\"one\"; %s%scontent:\"two\"; offset:10; %s%scontent:\"three\"; "
791  "%s%sfast_pattern:only; sid:5;)",
792  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
793  sticky ? sticky : "", sticky ? "; " : " ");
794  s = DetectEngineAppendSig(de_ctx, string);
795  FAIL_IF_NULL(s);
796  sm = GetMatches(s, list);
797  FAIL_IF_NULL(sm);
798  FAIL_IF_NULL(sm->next);
800  cd = (DetectContentData *)sm->ctx;
802  FAIL_IF_NOT(
804  sm = sm->next;
805  FAIL_IF_NULL(sm->next);
807  cd = (DetectContentData *)sm->ctx;
809  FAIL_IF_NOT(
811  sm = sm->next;
812  FAIL_IF_NOT_NULL(sm->next);
814  cd = (DetectContentData *)sm->ctx;
818 
819  snprintf(string, sizeof(string),
820  "alert tcp any any -> any any "
821  "(content:\"one\"; %s%scontent:\"two\"; depth:10; %s%scontent:\"three\"; "
822  "%s%sfast_pattern:only; sid:6;)",
823  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
824  sticky ? sticky : "", sticky ? "; " : " ");
825  s = DetectEngineAppendSig(de_ctx, string);
826  FAIL_IF_NULL(s);
827  sm = GetMatches(s, list);
828  FAIL_IF_NULL(sm);
829  FAIL_IF_NULL(sm->next);
831  cd = (DetectContentData *)sm->ctx;
833  FAIL_IF_NOT(
835  sm = sm->next;
836  FAIL_IF_NULL(sm->next);
838  cd = (DetectContentData *)sm->ctx;
840  FAIL_IF_NOT(
842  sm = sm->next;
843  FAIL_IF_NOT_NULL(sm->next);
845  cd = (DetectContentData *)sm->ctx;
849 
850  snprintf(string, sizeof(string),
851  "alert tcp any any -> any any "
852  "(content:!\"one\"; %s%sfast_pattern; content:\"two\"; depth:10; %s%ssid:7;)",
853  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
854  s = DetectEngineAppendSig(de_ctx, string);
855  FAIL_IF_NULL(s);
856  sm = GetMatches(s, list);
857  FAIL_IF_NULL(sm);
858  FAIL_IF_NULL(sm->next);
860  cd = (DetectContentData *)sm->ctx;
865  sm = sm->next;
866  FAIL_IF_NOT_NULL(sm->next);
868  cd = (DetectContentData *)sm->ctx;
870  FAIL_IF_NOT(
872 
874  PASS;
875 }
876 
877 static int DetectFastPatternStickyFPChop(const char *sticky, const int list)
878 {
881  char string[1024];
882  snprintf(string, sizeof(string),
883  "alert tcp any any -> any any "
884  "(%s%scontent:\"onetwothree\"; fast_pattern:3,4; sid:1;)",
885  sticky ? sticky : "", sticky ? "; " : " ");
886  Signature *s = DetectEngineAppendSig(de_ctx, string);
887  FAIL_IF_NULL(s);
888  SigMatch *sm = GetMatches(s, list);
889  FAIL_IF_NULL(sm);
896  FAIL_IF_NOT(cd->fp_chop_offset == 3);
897  FAIL_IF_NOT(cd->fp_chop_len == 4);
898 
899  snprintf(string, sizeof(string),
900  "alert tcp any any -> any any "
901  "(%s%scontent:\"onetwothree\"; fast_pattern:3,4; content:\"xyz\"; distance:10; sid:2;)",
902  sticky ? sticky : "", sticky ? "; " : " ");
903  s = DetectEngineAppendSig(de_ctx, string);
904  FAIL_IF_NULL(s);
905  sm = GetMatches(s, list);
906  FAIL_IF_NULL(sm);
908  cd = (DetectContentData *)sm->ctx;
913  FAIL_IF_NOT(cd->fp_chop_offset == 3);
914  FAIL_IF_NOT(cd->fp_chop_len == 4);
915 
917  PASS;
918 }
919 
920 static int DetectFastPatternModifierFPChop(const char *sticky, const int list)
921 {
924  char string[1024];
925  snprintf(string, sizeof(string),
926  "alert tcp any any -> any any "
927  "(content:\"onetwothree\"; %s%sfast_pattern:3,4; sid:1;)",
928  sticky ? sticky : "", sticky ? "; " : " ");
929  Signature *s = DetectEngineAppendSig(de_ctx, string);
930  FAIL_IF_NULL(s);
931  SigMatch *sm = GetMatches(s, list);
932  FAIL_IF_NULL(sm);
939  FAIL_IF_NOT(cd->fp_chop_offset == 3);
940  FAIL_IF_NOT(cd->fp_chop_len == 4);
941 
942  snprintf(string, sizeof(string),
943  "alert tcp any any -> any any "
944  "(content:!\"onetwothree\"; %s%sfast_pattern:3,4; sid:2;)",
945  sticky ? sticky : "", sticky ? "; " : " ");
946  s = DetectEngineAppendSig(de_ctx, string);
947  FAIL_IF_NULL(s);
948  sm = GetMatches(s, list);
949  FAIL_IF_NULL(sm);
951  cd = (DetectContentData *)sm->ctx;
958  FAIL_IF_NOT(cd->fp_chop_offset == 3);
959  FAIL_IF_NOT(cd->fp_chop_len == 4);
960 
962  PASS;
963 }
964 
965 /**
966  * \test Checks if a fast_pattern is registered in a Signature
967  */
968 static int DetectFastPatternTest01(void)
969 {
970  FAIL_IF_NOT(DetectFastPatternStickySingle(NULL, DETECT_SM_LIST_PMATCH));
971  FAIL_IF_NOT(DetectFastPatternModifierSingle(NULL, DETECT_SM_LIST_PMATCH));
972  FAIL_IF_NOT(DetectFastPatternStickySingleNoFP(NULL, DETECT_SM_LIST_PMATCH));
973  FAIL_IF_NOT(DetectFastPatternModifierSingleNoFP(NULL, DETECT_SM_LIST_PMATCH));
974  FAIL_IF_NOT(DetectFastPatternStickySingleBadArg(NULL));
975  FAIL_IF_NOT(DetectFastPatternModifierBadRules(NULL));
976  FAIL_IF_NOT(DetectFastPatternStickySingleFPOnly(NULL, DETECT_SM_LIST_PMATCH));
977  FAIL_IF_NOT(DetectFastPatternModifierFPOnly(NULL, DETECT_SM_LIST_PMATCH));
978  FAIL_IF_NOT(DetectFastPatternStickyFPChop(NULL, DETECT_SM_LIST_PMATCH));
979  FAIL_IF_NOT(DetectFastPatternModifierFPChop(NULL, DETECT_SM_LIST_PMATCH));
980 
981  struct {
982  const char *buffer_name;
983  const char *sb_name;
984  const char *mod_name;
985  } keywords[] = {
986  { "file_data", "file.data", NULL },
987  { "http_uri", "http.uri", "http_uri" },
988  { "http_raw_uri", "http.uri.raw", "http_raw_uri" },
989  { "http_user_agent", "http.user_agent", "http_user_agent" },
990  { "http_header", "http.header", "http_header" },
991  // http_raw_header requires sigs to have a direction
992  //{ "http_raw_header", "http.header.raw", "http_raw_header" },
993  { "http_method", "http.method", "http_method" },
994  { "http_cookie", "http.cookie", "http_cookie" },
995  { "http_host", "http.host", "http_host" },
996  { "http_raw_host", "http.host.raw", "http_raw_host" },
997  { "http_stat_code", "http.stat_code", "http_stat_code" },
998  { "http_stat_msg", "http.stat_msg", "http_stat_msg" },
999  { "http_client_body", "http.request_body", "http_client_body" },
1000  { NULL, NULL, NULL },
1001  };
1002 
1003  for (int i = 0; keywords[i].buffer_name != NULL; i++) {
1004  const int list_id = DetectBufferTypeGetByName(keywords[i].buffer_name);
1005  FAIL_IF(list_id == -1);
1006 
1007  const char *k = keywords[i].sb_name;
1008  if (k) {
1009  FAIL_IF_NOT(DetectFastPatternStickySingle(k, list_id));
1010  FAIL_IF_NOT(DetectFastPatternStickySingleNoFP(k, list_id));
1011  FAIL_IF_NOT(DetectFastPatternStickySingleBadArg(k));
1012  FAIL_IF_NOT(DetectFastPatternStickySingleFPOnly(k, list_id));
1013  FAIL_IF_NOT(DetectFastPatternStickyFPChop(k, list_id));
1014  }
1015  k = keywords[i].mod_name;
1016  if (k) {
1017  FAIL_IF_NOT(DetectFastPatternModifierSingle(k, list_id));
1018  FAIL_IF_NOT(DetectFastPatternModifierSingleNoFP(k, list_id));
1019  FAIL_IF_NOT(DetectFastPatternModifierBadRules(k));
1020  FAIL_IF_NOT(DetectFastPatternModifierFPOnly(k, list_id));
1021  FAIL_IF_NOT(DetectFastPatternModifierFPChop(k, list_id));
1022  }
1023  }
1024 
1025  PASS;
1026 }
1027 
1028 /**
1029  * \test Checks to make sure that other sigs work that should when fast_pattern is inspecting on the
1030  * same payload
1031  *
1032  */
1033 static int DetectFastPatternTest14(void)
1034 {
1035  uint8_t *buf = (uint8_t *)"Dummy is our name. Oh yes. From right here "
1036  "right now, all the way to hangover. right. strings5_imp now here "
1037  "comes our dark knight strings_string5. Yes here is our dark knight";
1038  uint16_t buflen = strlen((char *)buf);
1039  ThreadVars th_v;
1040  DetectEngineThreadCtx *det_ctx = NULL;
1041 
1042  memset(&th_v, 0, sizeof(th_v));
1043  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
1044  FAIL_IF_NULL(p);
1045 
1048  de_ctx->flags |= DE_QUIET;
1049 
1051 
1053  "alert tcp any any -> any any "
1054  "(msg:\"fast_pattern test\"; content:\"strings_string5\"; content:\"knight\"; "
1055  "fast_pattern; sid:1;)");
1056  FAIL_IF_NULL(s);
1057 
1059  "alert tcp any any -> any any "
1060  "(msg:\"test different content\"; content:\"Dummy is our name\"; sid:2;)");
1061  FAIL_IF_NULL(s);
1062 
1064  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1065 
1066  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1069 
1070  UTHFreePackets(&p, 1);
1071  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1073  FlowShutdown();
1074  PASS;
1075 }
1076 
1077 /**
1078  * Unittest to check
1079  * - if we assign different content_ids to duplicate patterns, but one of the
1080  * patterns has a fast_pattern chop set.
1081  * - if 2 unique patterns get unique ids.
1082  * - if 2 duplicate patterns, with no chop set get unique ids.
1083  */
1084 static int DetectFastPatternTest671(void)
1085 {
1088  de_ctx->flags |= DE_QUIET;
1089 
1090  Signature *s[6];
1091  s[0] = DetectEngineAppendSig(
1092  de_ctx, "alert tcp any any -> any any (content:\"onetwothreefour\"; sid:1;)");
1093  FAIL_IF_NULL(s[0]);
1094  s[1] = DetectEngineAppendSig(
1095  de_ctx, "alert tcp any any -> any any (content:\"onetwothreefour\"; sid:2;)");
1096  FAIL_IF_NULL(s[1]);
1097  s[2] = DetectEngineAppendSig(
1098  de_ctx, "alert tcp any any -> any any (content:\"uniquepattern\"; sid:3;)");
1099  FAIL_IF_NULL(s[2]);
1101  "alert tcp any any -> any any (content:\"onetwothreefour\"; fast_pattern:3,5; sid:4;)");
1102  FAIL_IF_NULL(s[3]);
1103  s[4] = DetectEngineAppendSig(
1104  de_ctx, "alert tcp any any -> any any (content:\"twoth\"; sid:5;)");
1105  FAIL_IF_NULL(s[4]);
1107  "alert tcp any any -> any any (content:\"onetwothreefour\"; fast_pattern:0,15; "
1108  "sid:6;)");
1109  FAIL_IF_NULL(s[5]);
1110 
1112 
1114  DetectContentData *cd = (DetectContentData *)smd->ctx;
1115  FAIL_IF(cd->id != 0);
1116 
1117  smd = s[1]->sm_arrays[DETECT_SM_LIST_PMATCH];
1118  cd = (DetectContentData *)smd->ctx;
1119  FAIL_IF(cd->id != 0);
1120 
1121  smd = s[2]->sm_arrays[DETECT_SM_LIST_PMATCH];
1122  cd = (DetectContentData *)smd->ctx;
1123  FAIL_IF(cd->id != 2);
1124 
1125  smd = s[3]->sm_arrays[DETECT_SM_LIST_PMATCH];
1126  cd = (DetectContentData *)smd->ctx;
1127  FAIL_IF(cd->id != 1);
1128 
1129  smd = s[4]->sm_arrays[DETECT_SM_LIST_PMATCH];
1130  cd = (DetectContentData *)smd->ctx;
1131  FAIL_IF(cd->id != 1);
1132 
1133  smd = s[5]->sm_arrays[DETECT_SM_LIST_PMATCH];
1134  cd = (DetectContentData *)smd->ctx;
1135  FAIL_IF(cd->id != 0);
1136 
1138  PASS;
1139 }
1140 
1141 static int DetectFastPatternPrefilter(void)
1142 {
1145  const char *string = "alert tcp any any -> any any "
1146  "(content:\"one\"; prefilter; sid:1;)";
1147  Signature *s = DetectEngineAppendSig(de_ctx, string);
1148  FAIL_IF_NULL(s);
1150  FAIL_IF_NULL(sm);
1156  PASS;
1157 }
1158 
1159 static void DetectFastPatternRegisterTests(void)
1160 {
1161  UtRegisterTest("DetectFastPatternTest01", DetectFastPatternTest01);
1162  UtRegisterTest("DetectFastPatternTest14", DetectFastPatternTest14);
1163  /* Unittest to check
1164  * - if we assign different content_ids to duplicate patterns, but one of the
1165  * patterns has a fast_pattern chop set.
1166  * - if 2 unique patterns get unique ids.
1167  * - if 2 duplicate patterns, with no chop set get unique ids.
1168  */
1169  UtRegisterTest("DetectFastPatternTest671", DetectFastPatternTest671);
1170 
1171  UtRegisterTest("DetectFastPatternPrefilter", DetectFastPatternPrefilter);
1172 }
1173 #endif
util-byte.h
SCFPSupportSMList_
Definition: detect.h:839
SigTableElmt_::url
const char * url
Definition: detect.h:1460
detect-content.h
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:119
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:642
DetectContentData_::fp_chop_len
uint16_t fp_chop_len
Definition: detect-content.h:98
SigTableElmt_::desc
const char * desc
Definition: detect.h:1459
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:79
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1444
SCFPSupportSMList_::next
struct SCFPSupportSMList_ * next
Definition: detect.h:842
DetectBufferGetFirstSigMatch
SigMatch * DetectBufferGetFirstSigMatch(const Signature *s, const uint32_t buf_id)
Definition: detect-engine-buffer.c:157
DetectParseRegex
Definition: detect-parse.h:93
SCFPSupportSMList_::list_id
int list_id
Definition: detect.h:840
SigTableElmt_::name
const char * name
Definition: detect.h:1457
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:69
Signature_::alproto
AppProto alproto
Definition: detect.h:673
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:275
SIG_FLAG_INIT_TXDIR_FAST_TOCLIENT
#define SIG_FLAG_INIT_TXDIR_FAST_TOCLIENT
Definition: detect.h:306
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:142
DETECT_FAST_PATTERN
@ DETECT_FAST_PATTERN
Definition: detect-engine-register.h:80
SigMatchData_::ctx
SigMatchCtx * ctx
Definition: detect.h:368
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1448
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:932
StringParseUint16
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:343
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2641
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:250
DE_QUIET
#define DE_QUIET
Definition: detect.h:330
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:365
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:2416
Signature_::sm_arrays
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
Definition: detect.h:731
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:608
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:3491
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:3437
SigMatchData_
Data needed for Match()
Definition: detect.h:365
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1439
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:1277
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:546
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:1244
DetectGetLastSMFromMpmLists
SigMatch * DetectGetLastSMFromMpmLists(const DetectEngineCtx *de_ctx, const Signature *s)
get the last SigMatch from lists that support MPM.
Definition: detect-parse.c:527
DETECT_SM_LIST_BASE64_DATA
@ DETECT_SM_LIST_BASE64_DATA
Definition: detect.h:124
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:3617
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:3372
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:360
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:359
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:317
DetectBufferToClient
bool DetectBufferToClient(const DetectEngineCtx *de_ctx, int buf_id, AppProto alproto)
Definition: detect-engine-mpm.c:1074
Signature_::flags
uint32_t flags
Definition: detect.h:669
DetectEngineInitializeFastPatternList
void DetectEngineInitializeFastPatternList(DetectEngineCtx *de_ctx)
Definition: detect-fast-pattern.c:149
Packet_
Definition: decode.h:501
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:747
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:1419
SCFPSupportSMList_::priority
int priority
Definition: detect.h:841
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2185
DetectEngineBufferTypeSupportsMpmGetById
bool DetectEngineBufferTypeSupportsMpmGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1453
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:358
SigMatch_::type
uint16_t type
Definition: detect.h:357
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:690
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:650
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
Definition: detect-engine.c:3600
detect-engine-buffer.h
FatalError
#define FatalError(...)
Definition: util-debug.h:510
SIGMATCH_OPTIONAL_OPT
#define SIGMATCH_OPTIONAL_OPT
Definition: detect.h:1659
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:304
HtpBodyChunk_::next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:123
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:267
SigMatchListSMBelongsTo
int SigMatchListSMBelongsTo(const Signature *s, const SigMatch *key_sm)
Definition: detect-parse.c:763
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Signature_::id
uint32_t id
Definition: detect.h:713
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:525
Signature_
Signature container.
Definition: detect.h:668
SigMatch_
a single match condition for a signature
Definition: detect.h:356
DETECT_SM_LIST_MAX
@ DETECT_SM_LIST_MAX
Definition: detect.h:135
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2602
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:564
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:934
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:1106
DETECT_CONTENT_WITHIN
#define DETECT_CONTENT_WITHIN
Definition: detect-content.h:31
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1446
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:456