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-fast-pattern.h"
34 
35 #include "util-error.h"
36 #include "util-byte.h"
37 #include "util-debug.h"
38 #include "util-unittest.h"
39 #include "util-unittest-helper.h"
40 
41 #define PARSE_REGEX "^(\\s*only\\s*)|\\s*([0-9]+)\\s*,\\s*([0-9]+)\\s*$"
42 
43 static DetectParseRegex parse_regex;
44 
45 static int DetectFastPatternSetup(DetectEngineCtx *, Signature *, const char *);
46 #ifdef UNITTESTS
47 static void DetectFastPatternRegisterTests(void);
48 #endif
49 
50 /* holds the list of sm match lists that need to be searched for a keyword
51  * that has fp support */
53 
54 /**
55  * \brief Checks if a particular list(Signature->sm_lists[]) is in the list
56  * of lists that need to be searched for a keyword that has fp support.
57  *
58  * \param list_id The list id.
59  *
60  * \retval 1 If supported.
61  * \retval 0 If not.
62  */
64  const int list_id)
65 {
66  if (sm_fp_support_smlist_list == NULL)
67  return 0;
68 
69  if (list_id == DETECT_SM_LIST_PMATCH)
70  return 1;
71 
73 }
74 
75 /**
76  * \brief Lets one add a sm list id to be searched for potential fp supported
77  * keywords later.
78  *
79  * \param list_id SM list id.
80  * \param priority Priority for this list.
81  */
82 void SupportFastPatternForSigMatchList(int list_id, int priority)
83 {
84  SCFPSupportSMList *ip = NULL;
85  /* insertion point - ip */
86  for (SCFPSupportSMList *tmp = sm_fp_support_smlist_list; tmp != NULL; tmp = tmp->next) {
87  if (list_id == tmp->list_id) {
88  SCLogDebug("SM list already registered.");
89  return;
90  }
91 
92  /* We need a strict check to be sure that the current list
93  * was not already registered
94  * and other lists with the same priority hide it.
95  */
96  if (priority < tmp->priority)
97  break;
98 
99  ip = tmp;
100  }
101 
102  if (sm_fp_support_smlist_list == NULL) {
104  if (unlikely(new == NULL))
105  exit(EXIT_FAILURE);
106  memset(new, 0, sizeof(SCFPSupportSMList));
107  new->list_id = list_id;
108  new->priority = priority;
109 
111 
112  return;
113  }
114 
116  if (unlikely(new == NULL))
117  exit(EXIT_FAILURE);
118  memset(new, 0, sizeof(SCFPSupportSMList));
119  new->list_id = list_id;
120  new->priority = priority;
121  if (ip == NULL) {
122  new->next = sm_fp_support_smlist_list;
124  } else {
125  new->next = ip->next;
126  ip->next = new;
127  }
128 
129  return;
130 }
131 
132 /**
133  * \brief Registers the keywords(SMs) that should be given fp support.
134  */
136 {
138 
139  /* other types are handled by DetectMpmAppLayerRegister() */
140 }
141 
142 /**
143  * \brief Registration function for fast_pattern keyword
144  */
146 {
147  sigmatch_table[DETECT_FAST_PATTERN].name = "fast_pattern";
148  sigmatch_table[DETECT_FAST_PATTERN].desc = "force using preceding content in the multi pattern matcher";
149  sigmatch_table[DETECT_FAST_PATTERN].url = "/rules/prefilter-keywords.html#fast-pattern";
151  sigmatch_table[DETECT_FAST_PATTERN].Setup = DetectFastPatternSetup;
153 #ifdef UNITTESTS
154  sigmatch_table[DETECT_FAST_PATTERN].RegisterTests = DetectFastPatternRegisterTests;
155 #endif
157 
158  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
159 }
160 
161 /**
162  * \brief Configures the previous content context for a fast_pattern modifier
163  * keyword used in the rule.
164  *
165  * \param de_ctx Pointer to the Detection Engine Context.
166  * \param s Pointer to the Signature to which the current keyword belongs.
167  * \param arg May hold an argument
168  *
169  * \retval 0 On success.
170  * \retval -1 On failure.
171  */
172 static int DetectFastPatternSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
173 {
174  int ret = 0, res = 0;
175  int ov[MAX_SUBSTRINGS];
176  char arg_substr[128] = "";
177  DetectContentData *cd = NULL;
178 
181  if (pm1 == NULL && pm2 == NULL) {
182  SCLogError(SC_ERR_INVALID_SIGNATURE, "fast_pattern found inside "
183  "the rule, without a content context. Please use a "
184  "content based keyword before using fast_pattern");
185  return -1;
186  }
187 
188  SigMatch *pm = NULL;
189  if (pm1 && pm2) {
190  if (pm1->idx > pm2->idx)
191  pm = pm1;
192  else
193  pm = pm2;
194  } else if (pm1 && !pm2) {
195  pm = pm1;
196  } else {
197  pm = pm2;
198  }
199 
200  cd = (DetectContentData *)pm->ctx;
201  if ((cd->flags & DETECT_CONTENT_NEGATED) &&
202  ((cd->flags & DETECT_CONTENT_DISTANCE) ||
203  (cd->flags & DETECT_CONTENT_WITHIN) ||
204  (cd->flags & DETECT_CONTENT_OFFSET) ||
205  (cd->flags & DETECT_CONTENT_DEPTH))) {
206 
207  /* we can't have any of these if we are having "only" */
208  SCLogError(SC_ERR_INVALID_SIGNATURE, "fast_pattern; cannot be "
209  "used with negated content, along with relative modifiers");
210  goto error;
211  }
212 
213  if (arg == NULL|| strcmp(arg, "") == 0) {
215  SCLogError(SC_ERR_INVALID_SIGNATURE, "can't use multiple fast_pattern "
216  "options for the same content");
217  goto error;
218  }
219  else { /*allow only one content to have fast_pattern modifier*/
220  uint32_t list_id = 0;
221  for (list_id = 0; list_id < s->init_data->smlists_array_size; list_id++) {
222  SigMatch *sm = NULL;
223  for (sm = s->init_data->smlists[list_id]; sm != NULL; sm = sm->next) {
224  if (sm->type == DETECT_CONTENT) {
225  DetectContentData *tmp_cd = (DetectContentData *)sm->ctx;
226  if (tmp_cd->flags & DETECT_CONTENT_FAST_PATTERN) {
227  SCLogError(SC_ERR_INVALID_SIGNATURE, "fast_pattern "
228  "can be used on only one content in a rule");
229  goto error;
230  }
231  }
232  } /* for (sm = s->sm_lists[list_id]; sm != NULL; sm = sm->next) */
233  }
234  }
236  return 0;
237  }
238 
239  /* Execute the regex and populate args with captures. */
240  ret = DetectParsePcreExec(&parse_regex, arg, 0, 0, ov, MAX_SUBSTRINGS);
241  /* fast pattern only */
242  if (ret == 2) {
243  if ((cd->flags & DETECT_CONTENT_NEGATED) ||
244  (cd->flags & DETECT_CONTENT_DISTANCE) ||
245  (cd->flags & DETECT_CONTENT_WITHIN) ||
246  (cd->flags & DETECT_CONTENT_OFFSET) ||
247  (cd->flags & DETECT_CONTENT_DEPTH)) {
248 
249  /* we can't have any of these if we are having "only" */
250  SCLogError(SC_ERR_INVALID_SIGNATURE, "fast_pattern: only; cannot be "
251  "used with negated content or with any of the relative "
252  "modifiers like distance, within, offset, depth");
253  goto error;
254  }
256 
257  /* fast pattern chop */
258  } else if (ret == 4) {
259  res = pcre_copy_substring((char *)arg, ov, MAX_SUBSTRINGS,
260  2, arg_substr, sizeof(arg_substr));
261  if (res < 0) {
262  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed "
263  "for fast_pattern offset");
264  goto error;
265  }
266  uint16_t offset;
267  if (StringParseUint16(&offset, 10, 0,
268  (const char *)arg_substr) < 0) {
269  SCLogError(SC_ERR_INVALID_SIGNATURE, "Invalid fast pattern offset:"
270  " \"%s\"", arg_substr);
271  goto error;
272  }
273 
274  res = pcre_copy_substring((char *)arg, ov, MAX_SUBSTRINGS,
275  3, arg_substr, sizeof(arg_substr));
276  if (res < 0) {
277  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed "
278  "for fast_pattern offset");
279  goto error;
280  }
281  uint16_t length;
282  if (StringParseUint16(&length, 10, 0,
283  (const char *)arg_substr) < 0) {
284  SCLogError(SC_ERR_INVALID_SIGNATURE, "Invalid value for fast "
285  "pattern: \"%s\"", arg_substr);
286  goto error;
287  }
288 
289  // Avoiding integer overflow
290  if (offset > (65535 - length)) {
291  SCLogError(SC_ERR_INVALID_SIGNATURE, "Fast pattern (length + offset) "
292  "exceeds limit pattern length limit");
293  goto error;
294  }
295 
296  if (offset + length > cd->content_len) {
297  SCLogError(SC_ERR_INVALID_SIGNATURE, "Fast pattern (length + "
298  "offset (%u)) exceeds pattern length (%u)",
299  offset + length, cd->content_len);
300  goto error;
301  }
302 
303  cd->fp_chop_offset = offset;
304  cd->fp_chop_len = length;
306 
307  } else {
308  SCLogError(SC_ERR_PCRE_PARSE, "parse error, ret %" PRId32
309  ", string %s", ret, arg);
310  goto error;
311  }
312 
314 
315  return 0;
316 
317  error:
318  return -1;
319 }
320 
321 /*----------------------------------Unittests---------------------------------*/
322 
323 #ifdef UNITTESTS
324 static int DetectFastPatternStickySingle(const char *sticky, const int list)
325 {
328  char string[1024];
329  snprintf(string, sizeof(string),
330  "alert tcp any any -> any any "
331  "(%s%scontent:\"one\"; fast_pattern; sid:1;)",
332  sticky ? sticky : "", sticky ? "; " : " ");
333  Signature *s = DetectEngineAppendSig(de_ctx, string);
334  FAIL_IF_NULL(s);
335  SigMatch *sm = de_ctx->sig_list->sm_lists[list];
336  FAIL_IF_NULL(sm);
342  PASS;
343 }
344 
345 static int DetectFastPatternModifierSingle(const char *sticky, const int list)
346 {
349  char string[1024];
350  snprintf(string, sizeof(string),
351  "alert tcp any any -> any any "
352  "(content:\"one\"; %s%sfast_pattern; sid:1;)",
353  sticky ? sticky : "", sticky ? "; " : " ");
354  Signature *s = DetectEngineAppendSig(de_ctx, string);
355  FAIL_IF_NULL(s);
356  SigMatch *sm = de_ctx->sig_list->sm_lists[list];
357  FAIL_IF_NULL(sm);
363  PASS;
364 }
365 
366 static int DetectFastPatternStickySingleNoFP(const char *sticky, const int list)
367 {
370  char string[1024];
371  snprintf(string, sizeof(string),
372  "alert tcp any any -> any any "
373  "(%s%scontent:\"one\"; sid:1;)",
374  sticky ? sticky : "", sticky ? "; " : " ");
375  Signature *s = DetectEngineAppendSig(de_ctx, string);
376  FAIL_IF_NULL(s);
377  SigMatch *sm = de_ctx->sig_list->sm_lists[list];
378  FAIL_IF_NULL(sm);
384  PASS;
385 }
386 
387 static int DetectFastPatternModifierSingleNoFP(const char *sticky, const int list)
388 {
391  char string[1024];
392  snprintf(string, sizeof(string),
393  "alert tcp any any -> any any "
394  "(content:\"one\"; %s%ssid:1;)",
395  sticky ? sticky : "", sticky ? "; " : " ");
396  Signature *s = DetectEngineAppendSig(de_ctx, string);
397  FAIL_IF_NULL(s);
398  SigMatch *sm = de_ctx->sig_list->sm_lists[list];
399  FAIL_IF_NULL(sm);
405  PASS;
406 }
407 
408 static int DetectFastPatternStickySingleBadArg(const char *sticky)
409 {
412  char string[1024];
413  /* bogus argument to fast_pattern */
414  snprintf(string, sizeof(string),
415  "alert tcp any any -> any any "
416  "(%s%scontent:\"one\"; fast_pattern:boo; sid:1;)",
417  sticky ? sticky : "", sticky ? "; " : " ");
418  Signature *s = DetectEngineAppendSig(de_ctx, string);
419  FAIL_IF_NOT_NULL(s);
420  /* fast_pattern only with distance */
421  snprintf(string, sizeof(string),
422  "alert tcp any any -> any any "
423  "(%s%scontent:\"one\"; fast_pattern:only; content:\"two\"; distance:10; sid:1;)",
424  sticky ? sticky : "", sticky ? "; " : " ");
425  s = DetectEngineAppendSig(de_ctx, string);
426  FAIL_IF_NOT_NULL(s);
427  /* fast_pattern only with distance */
428  snprintf(string, sizeof(string),
429  "alert tcp any any -> any any "
430  "(%s%scontent:\"one\"; content:\"two\"; fast_pattern:only; distance:10; sid:1;)",
431  sticky ? sticky : "", sticky ? "; " : " ");
432  s = DetectEngineAppendSig(de_ctx, string);
433  FAIL_IF_NOT_NULL(s);
434  /* fast_pattern only with distance */
435  snprintf(string, sizeof(string),
436  "alert tcp any any -> any any "
437  "(%s%scontent:\"one\"; content:\"two\"; distance:10; fast_pattern:only; sid:1;)",
438  sticky ? sticky : "", sticky ? "; " : " ");
439  s = DetectEngineAppendSig(de_ctx, string);
440  FAIL_IF_NOT_NULL(s);
441  /* fast_pattern chop with invalid values */
442  snprintf(string, sizeof(string),
443  "alert tcp any any -> any any "
444  "(%s%scontent:\"one\"; fast_pattern:5,6; sid:1;)",
445  sticky ? sticky : "", sticky ? "; " : " ");
446  s = DetectEngineAppendSig(de_ctx, string);
447  FAIL_IF_NOT_NULL(s);
449  PASS;
450 }
451 
452 static int DetectFastPatternModifierBadRules(const char *sticky)
453 {
456  char string[1024];
457  /* bogus argument to fast_pattern */
458  snprintf(string, sizeof(string),
459  "alert tcp any any -> any any "
460  "(content:\"one\"; %s%sfast_pattern:boo; sid:1;)",
461  sticky ? sticky : "", sticky ? "; " : " ");
462  Signature *s = DetectEngineAppendSig(de_ctx, string);
463  FAIL_IF_NOT_NULL(s);
464  /* fast_pattern only with distance */
465  snprintf(string, sizeof(string),
466  "alert tcp any any -> any any "
467  "(content:\"one\"; %s%sfast_pattern:only; content:\"two\"; %s%sdistance:10; sid:1;)",
468  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
469  s = DetectEngineAppendSig(de_ctx, string);
470  FAIL_IF_NOT_NULL(s);
471 #if 0 // TODO bug?
472  /* fast_pattern only with distance */
473  snprintf(string, sizeof(string), "alert tcp any any -> any any "
474  "(content:\"one\"; %s%s content:\"two\"; %s%sdistance:10; fast_pattern:only; sid:1;)",
475  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
476  s = DetectEngineAppendSig(de_ctx, string);
477  FAIL_IF_NOT_NULL(s);
478 #endif
479  /* fast_pattern only with within */
480  snprintf(string, sizeof(string),
481  "alert tcp any any -> any any "
482  "(content:\"one\"; %s%sfast_pattern:only; content:\"two\"; %s%swithin:10; sid:1;)",
483  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
484  s = DetectEngineAppendSig(de_ctx, string);
485  FAIL_IF_NOT_NULL(s);
486  /* fast_pattern only with within */
487  snprintf(string, sizeof(string),
488  "alert tcp any any -> any any "
489  "(content:\"one\"; %s%s content:\"two\"; %s%swithin:10; fast_pattern:only; sid:1;)",
490  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
491  s = DetectEngineAppendSig(de_ctx, string);
492  FAIL_IF_NOT_NULL(s);
493  /* fast_pattern only with offset */
494  snprintf(string, sizeof(string),
495  "alert tcp any any -> any any "
496  "(content:\"one\"; %s%sfast_pattern:only; offset:10; sid:1;)",
497  sticky ? sticky : "", sticky ? "; " : " ");
498  s = DetectEngineAppendSig(de_ctx, string);
499  FAIL_IF_NOT_NULL(s);
500  /* fast_pattern only with offset */
501  snprintf(string, sizeof(string),
502  "alert tcp any any -> any any "
503  "(content:\"one\"; %s%s offset:10; fast_pattern:only; sid:1;)",
504  sticky ? sticky : "", sticky ? "; " : " ");
505  s = DetectEngineAppendSig(de_ctx, string);
506  FAIL_IF_NOT_NULL(s);
507  /* fast_pattern only with depth */
508  snprintf(string, sizeof(string),
509  "alert tcp any any -> any any "
510  "(content:\"one\"; %s%sfast_pattern:only; depth:10; sid:1;)",
511  sticky ? sticky : "", sticky ? "; " : " ");
512  s = DetectEngineAppendSig(de_ctx, string);
513  FAIL_IF_NOT_NULL(s);
514  /* fast_pattern only with depth */
515  snprintf(string, sizeof(string),
516  "alert tcp any any -> any any "
517  "(content:\"one\"; %s%s depth:10; fast_pattern:only; sid:1;)",
518  sticky ? sticky : "", sticky ? "; " : " ");
519  s = DetectEngineAppendSig(de_ctx, string);
520  FAIL_IF_NOT_NULL(s);
521  /* fast_pattern only negate */
522  snprintf(string, sizeof(string),
523  "alert tcp any any -> any any "
524  "(content:\"one\"; %s%s content:!\"two\"; %s%sfast_pattern:only; sid:1;)",
525  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
526  s = DetectEngineAppendSig(de_ctx, string);
527  FAIL_IF_NOT_NULL(s);
528  /* fast_pattern chop with invalid values */
529  snprintf(string, sizeof(string),
530  "alert tcp any any -> any any "
531  "(content:\"one\"; %s%sfast_pattern:5,6; sid:1;)",
532  sticky ? sticky : "", sticky ? "; " : " ");
533  s = DetectEngineAppendSig(de_ctx, string);
534  FAIL_IF_NOT_NULL(s);
535  /* fast_pattern chop with invalid values */
536  snprintf(string, sizeof(string),
537  "alert tcp any any -> any any "
538  "(content:\"one\"; %s%sfast_pattern:65977,2; sid:1;)",
539  sticky ? sticky : "", sticky ? "; " : " ");
540  s = DetectEngineAppendSig(de_ctx, string);
541  FAIL_IF_NOT_NULL(s);
542  /* fast_pattern chop with invalid values */
543  snprintf(string, sizeof(string),
544  "alert tcp any any -> any any "
545  "(content:\"one\"; %s%sfast_pattern:2,65977; sid:1;)",
546  sticky ? sticky : "", sticky ? "; " : " ");
547  s = DetectEngineAppendSig(de_ctx, string);
548  FAIL_IF_NOT_NULL(s);
549  /* fast_pattern chop with invalid values */
550  snprintf(string, sizeof(string),
551  "alert tcp any any -> any any "
552  "(content:\"one\"; %s%sfast_pattern:2,65534; sid:1;)",
553  sticky ? sticky : "", sticky ? "; " : " ");
554  s = DetectEngineAppendSig(de_ctx, string);
555  FAIL_IF_NOT_NULL(s);
556  /* fast_pattern chop with invalid values */
557  snprintf(string, sizeof(string),
558  "alert tcp any any -> any any "
559  "(content:\"one\"; %s%sfast_pattern:65534,2; sid:1;)",
560  sticky ? sticky : "", sticky ? "; " : " ");
561  s = DetectEngineAppendSig(de_ctx, string);
562  FAIL_IF_NOT_NULL(s);
563  /* negated fast_pattern with distance */
564  snprintf(string, sizeof(string),
565  "alert tcp any any -> any any "
566  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%sdistance:10; sid:1;)",
567  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
568  s = DetectEngineAppendSig(de_ctx, string);
569  FAIL_IF_NOT_NULL(s);
570  /* negated fast_pattern with within */
571  snprintf(string, sizeof(string),
572  "alert tcp any any -> any any "
573  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%swithin:10; sid:1;)",
574  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
575  s = DetectEngineAppendSig(de_ctx, string);
576  FAIL_IF_NOT_NULL(s);
577  /* negated fast_pattern with depth */
578  snprintf(string, sizeof(string),
579  "alert tcp any any -> any any "
580  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%sdepth:10; sid:1;)",
581  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
582  s = DetectEngineAppendSig(de_ctx, string);
583  FAIL_IF_NOT_NULL(s);
584  /* negated fast_pattern with offset */
585  snprintf(string, sizeof(string),
586  "alert tcp any any -> any any "
587  "(content:\"one\"; %s%scontent:!\"two\"; fast_pattern:1,2; %s%soffset:10; sid:1;)",
588  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
589  s = DetectEngineAppendSig(de_ctx, string);
590  FAIL_IF_NOT_NULL(s);
592  PASS;
593 }
594 
595 static int DetectFastPatternStickySingleFPOnly(const char *sticky, const int list)
596 {
599  char string[1024];
600  snprintf(string, sizeof(string),
601  "alert tcp any any -> any any "
602  "(%s%scontent:\"one\"; fast_pattern:only; sid:1;)",
603  sticky ? sticky : "", sticky ? "; " : " ");
604  Signature *s = DetectEngineAppendSig(de_ctx, string);
605  FAIL_IF_NULL(s);
606  SigMatch *sm = de_ctx->sig_list->sm_lists[list];
607  FAIL_IF_NULL(sm);
614  PASS;
615 }
616 
617 static int DetectFastPatternModifierFPOnly(const char *sticky, const int list)
618 {
621  char string[1024];
622  snprintf(string, sizeof(string),
623  "alert tcp any any -> any any "
624  "(content:\"one\"; %s%sfast_pattern:only; sid:1;)",
625  sticky ? sticky : "", sticky ? "; " : " ");
626  Signature *s = DetectEngineAppendSig(de_ctx, string);
627  FAIL_IF_NULL(s);
628  SigMatch *sm = de_ctx->sig_list->sm_lists[list];
629  FAIL_IF_NULL(sm);
635 
636  snprintf(string, sizeof(string),
637  "alert tcp any any -> any any "
638  "(content:\"one\"; %s%scontent:\"two\"; %s%sfast_pattern:only; sid:2;)",
639  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
640  s = DetectEngineAppendSig(de_ctx, string);
641  FAIL_IF_NULL(s);
642  sm = de_ctx->sig_list->sm_lists[list];
643  FAIL_IF_NULL(sm);
644  FAIL_IF_NULL(sm->next);
646  cd = (DetectContentData *)sm->ctx;
648  FAIL_IF_NOT(
650  sm = sm->next;
652  cd = (DetectContentData *)sm->ctx;
656 
657  snprintf(string, sizeof(string),
658  "alert tcp any any -> any any "
659  "(content:\"one\"; %s%scontent:\"two\"; distance:10; %s%scontent:\"three\"; "
660  "%s%sfast_pattern:only; sid:3;)",
661  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
662  sticky ? sticky : "", sticky ? "; " : " ");
663  s = DetectEngineAppendSig(de_ctx, string);
664  FAIL_IF_NULL(s);
665  sm = de_ctx->sig_list->sm_lists[list];
666  FAIL_IF_NULL(sm);
667  FAIL_IF_NULL(sm->next);
669  cd = (DetectContentData *)sm->ctx;
671  FAIL_IF_NOT(
673  sm = sm->next;
674  FAIL_IF_NULL(sm->next);
676  cd = (DetectContentData *)sm->ctx;
678  FAIL_IF_NOT(
680  sm = sm->next;
681  FAIL_IF_NOT_NULL(sm->next);
683  cd = (DetectContentData *)sm->ctx;
687 
688  snprintf(string, sizeof(string),
689  "alert tcp any any -> any any "
690  "(content:\"one\"; %s%scontent:\"two\"; within:10; %s%scontent:\"three\"; "
691  "%s%sfast_pattern:only; sid:4;)",
692  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
693  sticky ? sticky : "", sticky ? "; " : " ");
694  s = DetectEngineAppendSig(de_ctx, string);
695  FAIL_IF_NULL(s);
696  sm = de_ctx->sig_list->sm_lists[list];
697  FAIL_IF_NULL(sm);
698  FAIL_IF_NULL(sm->next);
700  cd = (DetectContentData *)sm->ctx;
702  FAIL_IF_NOT(
704  sm = sm->next;
705  FAIL_IF_NULL(sm->next);
707  cd = (DetectContentData *)sm->ctx;
709  FAIL_IF_NOT(
711  sm = sm->next;
712  FAIL_IF_NOT_NULL(sm->next);
714  cd = (DetectContentData *)sm->ctx;
718 
719  snprintf(string, sizeof(string),
720  "alert tcp any any -> any any "
721  "(content:\"one\"; %s%scontent:\"two\"; offset:10; %s%scontent:\"three\"; "
722  "%s%sfast_pattern:only; sid:5;)",
723  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
724  sticky ? sticky : "", sticky ? "; " : " ");
725  s = DetectEngineAppendSig(de_ctx, string);
726  FAIL_IF_NULL(s);
727  sm = de_ctx->sig_list->sm_lists[list];
728  FAIL_IF_NULL(sm);
729  FAIL_IF_NULL(sm->next);
731  cd = (DetectContentData *)sm->ctx;
733  FAIL_IF_NOT(
735  sm = sm->next;
736  FAIL_IF_NULL(sm->next);
738  cd = (DetectContentData *)sm->ctx;
740  FAIL_IF_NOT(
742  sm = sm->next;
743  FAIL_IF_NOT_NULL(sm->next);
745  cd = (DetectContentData *)sm->ctx;
749 
750  snprintf(string, sizeof(string),
751  "alert tcp any any -> any any "
752  "(content:\"one\"; %s%scontent:\"two\"; depth:10; %s%scontent:\"three\"; "
753  "%s%sfast_pattern:only; sid:6;)",
754  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ",
755  sticky ? sticky : "", sticky ? "; " : " ");
756  s = DetectEngineAppendSig(de_ctx, string);
757  FAIL_IF_NULL(s);
758  sm = de_ctx->sig_list->sm_lists[list];
759  FAIL_IF_NULL(sm);
760  FAIL_IF_NULL(sm->next);
762  cd = (DetectContentData *)sm->ctx;
764  FAIL_IF_NOT(
766  sm = sm->next;
767  FAIL_IF_NULL(sm->next);
769  cd = (DetectContentData *)sm->ctx;
771  FAIL_IF_NOT(
773  sm = sm->next;
774  FAIL_IF_NOT_NULL(sm->next);
776  cd = (DetectContentData *)sm->ctx;
780 
781  snprintf(string, sizeof(string),
782  "alert tcp any any -> any any "
783  "(content:!\"one\"; %s%sfast_pattern; content:\"two\"; depth:10; %s%ssid:7;)",
784  sticky ? sticky : "", sticky ? "; " : " ", sticky ? sticky : "", sticky ? "; " : " ");
785  s = DetectEngineAppendSig(de_ctx, string);
786  FAIL_IF_NULL(s);
787  sm = de_ctx->sig_list->sm_lists[list];
788  FAIL_IF_NULL(sm);
789  FAIL_IF_NULL(sm->next);
791  cd = (DetectContentData *)sm->ctx;
796  sm = sm->next;
797  FAIL_IF_NOT_NULL(sm->next);
799  cd = (DetectContentData *)sm->ctx;
801  FAIL_IF_NOT(
803 
805  PASS;
806 }
807 
808 static int DetectFastPatternStickyFPChop(const char *sticky, const int list)
809 {
812  char string[1024];
813  snprintf(string, sizeof(string),
814  "alert tcp any any -> any any "
815  "(%s%scontent:\"onetwothree\"; fast_pattern:3,4; sid:1;)",
816  sticky ? sticky : "", sticky ? "; " : " ");
817  Signature *s = DetectEngineAppendSig(de_ctx, string);
818  FAIL_IF_NULL(s);
819  SigMatch *sm = de_ctx->sig_list->sm_lists[list];
820  FAIL_IF_NULL(sm);
827  FAIL_IF_NOT(cd->fp_chop_offset == 3);
828  FAIL_IF_NOT(cd->fp_chop_len == 4);
829 
830  snprintf(string, sizeof(string),
831  "alert tcp any any -> any any "
832  "(%s%scontent:\"onetwothree\"; fast_pattern:3,4; content:\"xyz\"; distance:10; sid:2;)",
833  sticky ? sticky : "", sticky ? "; " : " ");
834  s = DetectEngineAppendSig(de_ctx, string);
835  FAIL_IF_NULL(s);
836  sm = de_ctx->sig_list->sm_lists[list];
837  FAIL_IF_NULL(sm);
839  cd = (DetectContentData *)sm->ctx;
844  FAIL_IF_NOT(cd->fp_chop_offset == 3);
845  FAIL_IF_NOT(cd->fp_chop_len == 4);
846 
848  PASS;
849 }
850 
851 static int DetectFastPatternModifierFPChop(const char *sticky, const int list)
852 {
855  char string[1024];
856  snprintf(string, sizeof(string),
857  "alert tcp any any -> any any "
858  "(content:\"onetwothree\"; %s%sfast_pattern:3,4; sid:1;)",
859  sticky ? sticky : "", sticky ? "; " : " ");
860  Signature *s = DetectEngineAppendSig(de_ctx, string);
861  FAIL_IF_NULL(s);
862  SigMatch *sm = de_ctx->sig_list->sm_lists[list];
863  FAIL_IF_NULL(sm);
870  FAIL_IF_NOT(cd->fp_chop_offset == 3);
871  FAIL_IF_NOT(cd->fp_chop_len == 4);
872 
873  snprintf(string, sizeof(string),
874  "alert tcp any any -> any any "
875  "(content:!\"onetwothree\"; %s%sfast_pattern:3,4; sid:2;)",
876  sticky ? sticky : "", sticky ? "; " : " ");
877  s = DetectEngineAppendSig(de_ctx, string);
878  FAIL_IF_NULL(s);
879  sm = de_ctx->sig_list->sm_lists[list];
880  FAIL_IF_NULL(sm);
882  cd = (DetectContentData *)sm->ctx;
889  FAIL_IF_NOT(cd->fp_chop_offset == 3);
890  FAIL_IF_NOT(cd->fp_chop_len == 4);
891 
893  PASS;
894 }
895 
896 /**
897  * \test Checks if a fast_pattern is registered in a Signature
898  */
899 static int DetectFastPatternTest01(void)
900 {
901  FAIL_IF_NOT(DetectFastPatternStickySingle(NULL, DETECT_SM_LIST_PMATCH));
902  FAIL_IF_NOT(DetectFastPatternModifierSingle(NULL, DETECT_SM_LIST_PMATCH));
903  FAIL_IF_NOT(DetectFastPatternStickySingleNoFP(NULL, DETECT_SM_LIST_PMATCH));
904  FAIL_IF_NOT(DetectFastPatternModifierSingleNoFP(NULL, DETECT_SM_LIST_PMATCH));
905  FAIL_IF_NOT(DetectFastPatternStickySingleBadArg(NULL));
906  FAIL_IF_NOT(DetectFastPatternModifierBadRules(NULL));
907  FAIL_IF_NOT(DetectFastPatternStickySingleFPOnly(NULL, DETECT_SM_LIST_PMATCH));
908  FAIL_IF_NOT(DetectFastPatternModifierFPOnly(NULL, DETECT_SM_LIST_PMATCH));
909  FAIL_IF_NOT(DetectFastPatternStickyFPChop(NULL, DETECT_SM_LIST_PMATCH));
910  FAIL_IF_NOT(DetectFastPatternModifierFPChop(NULL, DETECT_SM_LIST_PMATCH));
911 
912  struct {
913  const char *buffer_name;
914  const char *sb_name;
915  const char *mod_name;
916  } keywords[] = {
917  { "file_data", "file.data", NULL },
918  { "http_uri", "http.uri", "http_uri" },
919  { "http_raw_uri", "http.uri.raw", "http_raw_uri" },
920  { "http_user_agent", "http.user_agent", "http_user_agent" },
921  { "http_header", "http.header", "http_header" },
922  // http_raw_header requires sigs to have a direction
923  //{ "http_raw_header", "http.header.raw", "http_raw_header" },
924  { "http_method", "http.method", "http_method" },
925  { "http_cookie", "http.cookie", "http_cookie" },
926  { "http_host", "http.host", "http_host" },
927  { "http_raw_host", "http.host.raw", "http_raw_host" },
928  { "http_stat_code", "http.stat_code", "http_stat_code" },
929  { "http_stat_msg", "http.stat_msg", "http_stat_msg" },
930  { "http_client_body", "http.request_body", "http_client_body" },
931  { NULL, NULL, NULL },
932  };
933 
934  for (int i = 0; keywords[i].buffer_name != NULL; i++) {
935  const int list_id = DetectBufferTypeGetByName(keywords[i].buffer_name);
936  FAIL_IF(list_id == -1);
937 
938  const char *k = keywords[i].sb_name;
939  if (k) {
940  FAIL_IF_NOT(DetectFastPatternStickySingle(k, list_id));
941  FAIL_IF_NOT(DetectFastPatternStickySingleNoFP(k, list_id));
942  FAIL_IF_NOT(DetectFastPatternStickySingleBadArg(k));
943  FAIL_IF_NOT(DetectFastPatternStickySingleFPOnly(k, list_id));
944  FAIL_IF_NOT(DetectFastPatternStickyFPChop(k, list_id));
945  }
946  k = keywords[i].mod_name;
947  if (k) {
948  FAIL_IF_NOT(DetectFastPatternModifierSingle(k, list_id));
949  FAIL_IF_NOT(DetectFastPatternModifierSingleNoFP(k, list_id));
950  FAIL_IF_NOT(DetectFastPatternModifierBadRules(k));
951  FAIL_IF_NOT(DetectFastPatternModifierFPOnly(k, list_id));
952  FAIL_IF_NOT(DetectFastPatternModifierFPChop(k, list_id));
953  }
954  }
955 
956  PASS;
957 }
958 
959 /**
960  * \test Checks to make sure that other sigs work that should when fast_pattern is inspecting on the
961  * same payload
962  *
963  */
964 static int DetectFastPatternTest14(void)
965 {
966  uint8_t *buf = (uint8_t *)"Dummy is our name. Oh yes. From right here "
967  "right now, all the way to hangover. right. strings5_imp now here "
968  "comes our dark knight strings_string5. Yes here is our dark knight";
969  uint16_t buflen = strlen((char *)buf);
970  ThreadVars th_v;
971  DetectEngineThreadCtx *det_ctx = NULL;
972 
973  memset(&th_v, 0, sizeof(th_v));
974  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
975  FAIL_IF_NULL(p);
976 
979  de_ctx->flags |= DE_QUIET;
980 
982 
984  "alert tcp any any -> any any "
985  "(msg:\"fast_pattern test\"; content:\"strings_string5\"; content:\"knight\"; "
986  "fast_pattern; sid:1;)");
987  FAIL_IF_NULL(s);
988 
990  "alert tcp any any -> any any "
991  "(msg:\"test different content\"; content:\"Dummy is our name\"; sid:2;)");
992  FAIL_IF_NULL(s);
993 
995  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
996 
997  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1000 
1001  UTHFreePackets(&p, 1);
1002  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1004  FlowShutdown();
1005  PASS;
1006 }
1007 
1008 /**
1009  * Unittest to check
1010  * - if we assign different content_ids to duplicate patterns, but one of the
1011  * patterns has a fast_pattern chop set.
1012  * - if 2 unique patterns get unique ids.
1013  * - if 2 duplicate patterns, with no chop set get unique ids.
1014  */
1015 static int DetectFastPatternTest671(void)
1016 {
1019  de_ctx->flags |= DE_QUIET;
1020 
1021  Signature *s[6];
1022  s[0] = DetectEngineAppendSig(
1023  de_ctx, "alert tcp any any -> any any (content:\"onetwothreefour\"; sid:1;)");
1024  FAIL_IF_NULL(s[0]);
1025  s[1] = DetectEngineAppendSig(
1026  de_ctx, "alert tcp any any -> any any (content:\"onetwothreefour\"; sid:2;)");
1027  FAIL_IF_NULL(s[1]);
1028  s[2] = DetectEngineAppendSig(
1029  de_ctx, "alert tcp any any -> any any (content:\"uniquepattern\"; sid:3;)");
1030  FAIL_IF_NULL(s[2]);
1032  "alert tcp any any -> any any (content:\"onetwothreefour\"; fast_pattern:3,5; sid:4;)");
1033  FAIL_IF_NULL(s[3]);
1034  s[4] = DetectEngineAppendSig(
1035  de_ctx, "alert tcp any any -> any any (content:\"twoth\"; sid:5;)");
1036  FAIL_IF_NULL(s[4]);
1038  "alert tcp any any -> any any (content:\"onetwothreefour\"; fast_pattern:0,15; "
1039  "sid:6;)");
1040  FAIL_IF_NULL(s[5]);
1041 
1043 
1045  DetectContentData *cd = (DetectContentData *)smd->ctx;
1046  FAIL_IF(cd->id != 0);
1047 
1048  smd = s[1]->sm_arrays[DETECT_SM_LIST_PMATCH];
1049  cd = (DetectContentData *)smd->ctx;
1050  FAIL_IF(cd->id != 0);
1051 
1052  smd = s[2]->sm_arrays[DETECT_SM_LIST_PMATCH];
1053  cd = (DetectContentData *)smd->ctx;
1054  FAIL_IF(cd->id != 2);
1055 
1056  smd = s[3]->sm_arrays[DETECT_SM_LIST_PMATCH];
1057  cd = (DetectContentData *)smd->ctx;
1058  FAIL_IF(cd->id != 1);
1059 
1060  smd = s[4]->sm_arrays[DETECT_SM_LIST_PMATCH];
1061  cd = (DetectContentData *)smd->ctx;
1062  FAIL_IF(cd->id != 1);
1063 
1064  smd = s[5]->sm_arrays[DETECT_SM_LIST_PMATCH];
1065  cd = (DetectContentData *)smd->ctx;
1066  FAIL_IF(cd->id != 0);
1067 
1069  PASS;
1070 }
1071 
1072 static int DetectFastPatternPrefilter(void)
1073 {
1076  const char *string = "alert tcp any any -> any any "
1077  "(content:\"one\"; prefilter; sid:1;)";
1078  Signature *s = DetectEngineAppendSig(de_ctx, string);
1079  FAIL_IF_NULL(s);
1080  SigMatch *sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_PMATCH];
1081  FAIL_IF_NULL(sm);
1087  PASS;
1088 }
1089 
1090 static void DetectFastPatternRegisterTests(void)
1091 {
1092  UtRegisterTest("DetectFastPatternTest01", DetectFastPatternTest01);
1093  UtRegisterTest("DetectFastPatternTest14", DetectFastPatternTest14);
1094  /* Unittest to check
1095  * - if we assign different content_ids to duplicate patterns, but one of the
1096  * patterns has a fast_pattern chop set.
1097  * - if 2 unique patterns get unique ids.
1098  * - if 2 duplicate patterns, with no chop set get unique ids.
1099  */
1100  UtRegisterTest("DetectFastPatternTest671", DetectFastPatternTest671);
1101 
1102  UtRegisterTest("DetectFastPatternPrefilter", DetectFastPatternPrefilter);
1103 }
1104 #endif
util-byte.h
SCFPSupportSMList_
Definition: detect-fast-pattern.h:27
SigTableElmt_::url
const char * url
Definition: detect.h:1205
detect-content.h
detect-engine.h
StringParseUint16
int StringParseUint16(uint16_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:336
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:90
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
DetectContentData_::fp_chop_len
uint16_t fp_chop_len
Definition: detect-content.h:91
SigTableElmt_::desc
const char * desc
Definition: detect.h:1204
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1192
SCFPSupportSMList_::next
struct SCFPSupportSMList_ * next
Definition: detect-fast-pattern.h:32
SigTableElmt_::name
const char * name
Definition: detect.h:1202
MAX_SUBSTRINGS
#define MAX_SUBSTRINGS
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:60
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
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:138
DETECT_FAST_PATTERN
@ DETECT_FAST_PATTERN
Definition: detect-engine-register.h:71
SigMatchData_::ctx
SigMatchCtx * ctx
Definition: detect.h:332
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1196
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:757
SC_ERR_INVALID_SIGNATURE
@ SC_ERR_INVALID_SIGNATURE
Definition: util-error.h:69
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2070
SupportFastPatternForSigMatchTypes
void SupportFastPatternForSigMatchTypes(void)
Registers the keywords(SMs) that should be given fp support.
Definition: detect-fast-pattern.c:135
DE_QUIET
#define DE_QUIET
Definition: detect.h:294
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:337
Signature_::sm_arrays
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
Definition: detect.h:570
DetectContentData_
Definition: detect-content.h:86
SC_ERR_PCRE_GET_SUBSTRING
@ SC_ERR_PCRE_GET_SUBSTRING
Definition: util-error.h:34
DetectContentData_::fp_chop_offset
uint16_t fp_chop_offset
Definition: detect-content.h:93
SigMatchData_
Data needed for Match()
Definition: detect.h:329
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1187
PARSE_REGEX
#define PARSE_REGEX
Definition: detect-fast-pattern.c:41
util-unittest.h
util-unittest-helper.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression to true.
Definition: util-unittest.h:82
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:830
SC_ERR_PCRE_PARSE
@ SC_ERR_PCRE_PARSE
Definition: util-error.h:37
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:516
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:17
DetectEngineThreadCtx_
Definition: detect.h:1001
DetectGetLastSMFromMpmLists
SigMatch * DetectGetLastSMFromMpmLists(const DetectEngineCtx *de_ctx, const Signature *s)
get the last SigMatch from lists that support MPM.
Definition: detect-parse.c:429
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2511
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
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:324
DETECT_CONTENT_IS_SINGLE
#define DETECT_CONTENT_IS_SINGLE(c)
Definition: detect-content.h:66
DETECT_CONTENT_NEGATED
#define DETECT_CONTENT_NEGATED
Definition: detect-content.h:40
DetectContentData_::id
PatIntId id
Definition: detect-content.h:98
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:323
sm_fp_support_smlist_list
SCFPSupportSMList * sm_fp_support_smlist_list
Definition: detect-fast-pattern.c:52
SigMatchSignatures
void SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1691
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options, int *ovector, int ovector_size)
Definition: detect-parse.c:2441
Packet_
Definition: decode.h:416
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:97
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:586
FastPatternSupportEnabledForSigMatchList
int FastPatternSupportEnabledForSigMatchList(const DetectEngineCtx *de_ctx, const int list_id)
Checks if a particular list(Signature->sm_lists[]) is in the list of lists that need to be searched f...
Definition: detect-fast-pattern.c:63
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1170
SignatureInitData_::smlists
struct SigMatch_ ** smlists
Definition: detect.h:511
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:1889
SigMatch_::type
uint8_t type
Definition: detect.h:321
detect-fast-pattern.h
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *de_ctx, const char *sigstr)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:2379
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:2774
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:71
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:2982
SigMatch_::idx
uint16_t idx
Definition: detect.h:322
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:644
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:82
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
DetectParseRegex_
Definition: detect-parse.h:42
DetectBufferTypeSupportsMpmGetById
bool DetectBufferTypeSupportsMpmGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:894
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:763
SIGMATCH_OPTIONAL_OPT
#define SIGMATCH_OPTIONAL_OPT
Definition: detect.h:1382
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
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
Signature_
Signature container.
Definition: detect.h:517
SigMatch_
a single match condition for a signature
Definition: detect.h:320
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2025
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:42
DetectFastPatternRegister
void DetectFastPatternRegister(void)
Registration function for fast_pattern keyword.
Definition: detect-fast-pattern.c:145
DetectContentData_::content_len
uint16_t content_len
Definition: detect-content.h:88
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:468
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:758
flow.h
DETECT_CONTENT_FAST_PATTERN
#define DETECT_CONTENT_FAST_PATTERN
Definition: detect-content.h:34
DETECT_CONTENT_WITHIN
#define DETECT_CONTENT_WITHIN
Definition: detect-content.h:31
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1194
SignatureInitData_::smlists_array_size
uint32_t smlists_array_size
Definition: detect.h:509
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:468