suricata
detect-isdataat.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2020 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 Pablo Rincon <pablo.rincon.crespo@gmail.com>
22  *
23  * Implements isdataat keyword
24  */
25 
26 #include "suricata-common.h"
27 #include "decode.h"
28 #include "detect.h"
29 #include "detect-engine.h"
30 #include "detect-engine-buffer.h"
31 #include "detect-parse.h"
32 #include "app-layer.h"
33 
34 #include "util-unittest-helper.h"
35 
36 #include "detect-isdataat.h"
37 #include "detect-content.h"
38 #include "detect-bytetest.h"
39 #include "detect-uricontent.h"
40 #include "detect-engine-build.h"
41 
42 #include "flow.h"
43 #include "flow-var.h"
44 
45 #include "util-debug.h"
46 #include "util-byte.h"
47 #include "detect-pcre.h"
48 #include "detect-byte.h"
49 
50 /**
51  * \brief Regex for parsing our isdataat options
52  */
53 #define PARSE_REGEX "^\\s*!?([^\\s,]+)\\s*(,\\s*relative)?\\s*(,\\s*rawbytes\\s*)?\\s*$"
54 
55 static DetectParseRegex parse_regex;
56 
57 int DetectIsdataatSetup (DetectEngineCtx *, Signature *, const char *);
58 #ifdef UNITTESTS
59 static void DetectIsdataatRegisterTests(void);
60 static void DetectAbsentRegisterTests(void);
61 #endif
62 void DetectIsdataatFree(DetectEngineCtx *, void *);
63 
64 static int DetectEndsWithSetup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr);
65 
66 static void DetectAbsentFree(DetectEngineCtx *de_ctx, void *ptr)
67 {
68  SCFree(ptr);
69 }
70 
71 static int DetectAbsentSetup(DetectEngineCtx *de_ctx, Signature *s, const char *optstr)
72 {
74  SCLogError("no buffer for absent keyword");
75  return -1;
76  }
77 
78  if (DetectBufferGetActiveList(de_ctx, s) == -1)
79  return -1;
80 
81  bool or_else;
82  if (optstr == NULL) {
83  or_else = false;
84  } else if (strcmp(optstr, "or_else") == 0) {
85  or_else = true;
86  } else {
87  SCLogError("unhandled value for absent keyword: %s", optstr);
88  return -1;
89  }
90  if (s->init_data->curbuf == NULL || s->init_data->list != (int)s->init_data->curbuf->id) {
91  SCLogError("unspected buffer for absent keyword");
92  return -1;
93  }
95  if (!b || b->frame) {
96  SCLogError("absent does not work with frames");
97  return -1;
98  }
99  if (s->init_data->curbuf->tail != NULL) {
100  SCLogError("absent must come first right after buffer");
101  return -1;
102  }
104  if (unlikely(dad == NULL))
105  return -1;
106 
107  dad->or_else = or_else;
108 
110  de_ctx, s, DETECT_ABSENT, (SigMatchCtx *)dad, s->init_data->list) == NULL) {
111  DetectAbsentFree(de_ctx, dad);
112  return -1;
113  }
114  return 0;
115 }
116 
118 {
119  bool has_other = false;
120  bool only_absent = false;
121  bool has_absent = false;
122  for (const SigMatch *sm = b->head; sm != NULL; sm = sm->next) {
123  if (sm->type == DETECT_ABSENT) {
124  has_absent = true;
125  const DetectAbsentData *dad = (const DetectAbsentData *)sm->ctx;
126  if (!dad->or_else) {
127  only_absent = true;
128  }
129  } else {
130  has_other = true;
131  if (sm->type == DETECT_CONTENT) {
132  const DetectContentData *cd = (DetectContentData *)sm->ctx;
133  if (has_absent && (cd->flags & DETECT_CONTENT_FAST_PATTERN)) {
134  SCLogError("signature can't have absent and fast_pattern on the same buffer");
135  return false;
136  }
137  }
138  }
139  }
140 
141  if (only_absent && has_other) {
142  SCLogError("signature can't have a buffer tested absent and tested with other keywords "
143  "such as content");
144  return false;
145  } else if (has_absent && !only_absent && !has_other) {
146  SCLogError(
147  "signature with absent: or_else expects other keywords to test on such as content");
148  return false;
149  }
150  return true;
151 }
152 
153 /**
154  * \brief Registration function for isdataat: keyword
155  */
157 {
158  sigmatch_table[DETECT_ISDATAAT].name = "isdataat";
159  sigmatch_table[DETECT_ISDATAAT].desc = "check if there is still data at a specific part of the payload";
160  sigmatch_table[DETECT_ISDATAAT].url = "/rules/payload-keywords.html#isdataat";
161  /* match is handled in DetectEngineContentInspection() */
165 #ifdef UNITTESTS
166  sigmatch_table[DETECT_ISDATAAT].RegisterTests = DetectIsdataatRegisterTests;
167 #endif
168  sigmatch_table[DETECT_ENDS_WITH].name = "endswith";
169  sigmatch_table[DETECT_ENDS_WITH].desc = "make sure the previous content matches exactly at the end of the buffer";
170  sigmatch_table[DETECT_ENDS_WITH].url = "/rules/payload-keywords.html#endswith";
171  sigmatch_table[DETECT_ENDS_WITH].Setup = DetectEndsWithSetup;
173 
174  sigmatch_table[DETECT_ABSENT].name = "absent";
175  sigmatch_table[DETECT_ABSENT].desc = "test if the buffer is absent";
176  sigmatch_table[DETECT_ABSENT].url = "/rules/payload-keywords.html#absent";
177  sigmatch_table[DETECT_ABSENT].Setup = DetectAbsentSetup;
178  sigmatch_table[DETECT_ABSENT].Free = DetectAbsentFree;
180 #ifdef UNITTESTS
181  sigmatch_table[DETECT_ABSENT].RegisterTests = DetectAbsentRegisterTests;
182 #endif
183 
184  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
185 }
186 
187 /**
188  * \brief This function is used to parse isdataat options passed via isdataat: keyword
189  *
190  * \param de_ctx Pointer to the detection engine context
191  * \param isdataatstr Pointer to the user provided isdataat options
192  *
193  * \retval idad pointer to DetectIsdataatData on success
194  * \retval NULL on failure
195  */
196 static DetectIsdataatData *DetectIsdataatParse (DetectEngineCtx *de_ctx, const char *isdataatstr, char **offset)
197 {
198  DetectIsdataatData *idad = NULL;
199  char *args[3] = {NULL,NULL,NULL};
200  int res = 0;
201  size_t pcre2_len;
202  int i=0;
203 
204  pcre2_match_data *match = NULL;
205  int ret = DetectParsePcreExec(&parse_regex, &match, isdataatstr, 0, 0);
206  if (ret < 1 || ret > 4) {
207  SCLogError("pcre_exec parse error, ret %" PRId32 ", string %s", ret, isdataatstr);
208  goto error;
209  }
210 
211  if (ret > 1) {
212  const char *str_ptr;
213  res = pcre2_substring_get_bynumber(match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
214  if (res < 0) {
215  SCLogError("pcre2_substring_get_bynumber failed");
216  goto error;
217  }
218  args[0] = (char *)str_ptr;
219 
220 
221  if (ret > 2) {
222  res = pcre2_substring_get_bynumber(match, 2, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
223  if (res < 0) {
224  SCLogError("pcre2_substring_get_bynumber failed");
225  goto error;
226  }
227  args[1] = (char *)str_ptr;
228  }
229  if (ret > 3) {
230  res = pcre2_substring_get_bynumber(match, 3, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
231  if (res < 0) {
232  SCLogError("pcre2_substring_get_bynumber failed");
233  goto error;
234  }
235  args[2] = (char *)str_ptr;
236  }
237 
238  idad = SCMalloc(sizeof(DetectIsdataatData));
239  if (unlikely(idad == NULL))
240  goto error;
241 
242  idad->flags = 0;
243  idad->dataat = 0;
244 
245  if (args[0][0] != '-' && isalpha((unsigned char)args[0][0])) {
246  if (offset == NULL) {
247  SCLogError("isdataat supplied with "
248  "var name for offset. \"offset\" argument supplied to "
249  "this function has to be non-NULL");
250  goto error;
251  }
252  *offset = SCStrdup(args[0]);
253  if (*offset == NULL)
254  goto error;
255  } else {
256  if (StringParseUint16(&idad->dataat, 10,
257  strlen(args[0]), args[0]) < 0 ) {
258  SCLogError("isdataat out of range");
259  SCFree(idad);
260  idad = NULL;
261  goto error;
262  }
263  }
264 
265  if (args[1] !=NULL) {
266  idad->flags |= ISDATAAT_RELATIVE;
267 
268  if(args[2] !=NULL)
269  idad->flags |= ISDATAAT_RAWBYTES;
270  }
271 
272  if (isdataatstr[0] == '!') {
273  idad->flags |= ISDATAAT_NEGATED;
274  }
275 
276  for (i = 0; i < (ret -1); i++) {
277  if (args[i] != NULL)
278  pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
279  }
280 
281  pcre2_match_data_free(match);
282  return idad;
283 
284  }
285 
286 error:
287  if (match) {
288  pcre2_match_data_free(match);
289  }
290  for (i = 0; i < (ret -1) && i < 3; i++){
291  if (args[i] != NULL)
292  pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
293  }
294 
295  if (idad != NULL)
296  DetectIsdataatFree(de_ctx, idad);
297  return NULL;
298 
299 }
300 
301 /**
302  * \brief This function is used to add the parsed isdataatdata into the current
303  * signature.
304  * \param de_ctx pointer to the Detection Engine Context
305  * \param s pointer to the Current Signature
306  * \param isdataatstr pointer to the user provided isdataat options
307  *
308  * \retval 0 on Success
309  * \retval -1 on Failure
310  */
311 int DetectIsdataatSetup (DetectEngineCtx *de_ctx, Signature *s, const char *isdataatstr)
312 {
313  SigMatch *prev_pm = NULL;
314  DetectIsdataatData *idad = NULL;
315  char *offset = NULL;
316  int ret = -1;
317 
318  idad = DetectIsdataatParse(de_ctx, isdataatstr, &offset);
319  if (idad == NULL)
320  return -1;
321 
322  int sm_list;
323  if (s->init_data->list != DETECT_SM_LIST_NOTSET) {
324  if (DetectBufferGetActiveList(de_ctx, s) == -1)
325  goto end;
326  sm_list = s->init_data->list;
327 
328  if (idad->flags & ISDATAAT_RELATIVE) {
330  }
331  } else if (idad->flags & ISDATAAT_RELATIVE) {
334  if (prev_pm == NULL)
335  sm_list = DETECT_SM_LIST_PMATCH;
336  else {
337  sm_list = SigMatchListSMBelongsTo(s, prev_pm);
338  if (sm_list < 0)
339  goto end;
340  }
341  } else {
342  sm_list = DETECT_SM_LIST_PMATCH;
343  }
344 
345  if (offset != NULL) {
346  DetectByteIndexType index;
347  if (!DetectByteRetrieveSMVar(offset, s, -1, &index)) {
348  SCLogError("Unknown byte_extract var "
349  "seen in isdataat - %s\n",
350  offset);
351  goto end;
352  }
353  idad->dataat = index;
354  idad->flags |= ISDATAAT_OFFSET_VAR;
355  SCLogDebug("isdataat uses byte_extract with local id %u", idad->dataat);
356  SCFree(offset);
357  offset = NULL;
358  }
359 
360  /* 'ends with' scenario */
361  if (prev_pm != NULL && prev_pm->type == DETECT_CONTENT &&
362  idad->dataat == 1 &&
364  {
365  DetectIsdataatFree(de_ctx, idad);
366  DetectContentData *cd = (DetectContentData *)prev_pm->ctx;
368  ret = 0;
369  goto end;
370  }
371 
372  if (SCSigMatchAppendSMToList(de_ctx, s, DETECT_ISDATAAT, (SigMatchCtx *)idad, sm_list) ==
373  NULL) {
374  goto end;
375  }
376 
377  if (!(idad->flags & ISDATAAT_RELATIVE)) {
378  ret = 0;
379  goto end;
380  }
381 
382  if (prev_pm == NULL) {
383  ret = 0;
384  goto end;
385  }
386 
387  if (prev_pm->type == DETECT_CONTENT) {
388  DetectContentData *cd = (DetectContentData *)prev_pm->ctx;
390  } else if (prev_pm->type == DETECT_PCRE) {
391  DetectPcreData *pd = (DetectPcreData *)prev_pm->ctx;
393  }
394 
395  ret = 0;
396 
397 end:
398  if (offset)
399  SCFree(offset);
400  if (ret != 0)
401  DetectIsdataatFree(de_ctx, idad);
402  return ret;
403 }
404 
405 /**
406  * \brief this function will free memory associated with DetectIsdataatData
407  *
408  * \param idad pointer to DetectIsdataatData
409  */
411 {
412  DetectIsdataatData *idad = (DetectIsdataatData *)ptr;
413  SCFree(idad);
414 }
415 
416 static int DetectEndsWithSetup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr)
417 {
418  SigMatch *pm = NULL;
419  int ret = -1;
420 
421  /* retrieve the sm to apply the depth against */
423  if (pm == NULL) {
424  SCLogError("endswith needs a "
425  "preceding content option");
426  goto end;
427  }
428 
429  /* verify other conditions. */
431 
433 
434  ret = 0;
435  end:
436  return ret;
437 }
438 
439 #ifdef UNITTESTS
440 static int g_dce_stub_data_buffer_id = 0;
441 
442 /**
443  * \test DetectIsdataatTestParse01 is a test to make sure that we return a correct IsdataatData structure
444  * when given valid isdataat opt
445  */
446 static int DetectIsdataatTestParse01 (void)
447 {
448  int result = 0;
449  DetectIsdataatData *idad = NULL;
450  idad = DetectIsdataatParse(NULL, "30 ", NULL);
451  if (idad != NULL) {
452  DetectIsdataatFree(NULL, idad);
453  result = 1;
454  }
455 
456  return result;
457 }
458 
459 /**
460  * \test DetectIsdataatTestParse02 is a test to make sure that we return a correct IsdataatData structure
461  * when given valid isdataat opt
462  */
463 static int DetectIsdataatTestParse02 (void)
464 {
465  int result = 0;
466  DetectIsdataatData *idad = NULL;
467  idad = DetectIsdataatParse(NULL, "30 , relative", NULL);
468  if (idad != NULL && idad->flags & ISDATAAT_RELATIVE && !(idad->flags & ISDATAAT_RAWBYTES)) {
469  DetectIsdataatFree(NULL, idad);
470  result = 1;
471  }
472 
473  return result;
474 }
475 
476 /**
477  * \test DetectIsdataatTestParse03 is a test to make sure that we return a correct IsdataatData structure
478  * when given valid isdataat opt
479  */
480 static int DetectIsdataatTestParse03 (void)
481 {
482  int result = 0;
483  DetectIsdataatData *idad = NULL;
484  idad = DetectIsdataatParse(NULL, "30,relative, rawbytes ", NULL);
485  if (idad != NULL && idad->flags & ISDATAAT_RELATIVE && idad->flags & ISDATAAT_RAWBYTES) {
486  DetectIsdataatFree(NULL, idad);
487  result = 1;
488  }
489 
490  return result;
491 }
492 
493 /**
494  * \test Test isdataat option for dce sig.
495  */
496 static int DetectIsdataatTestParse04(void)
497 {
498  Signature *s = SigAlloc();
499  FAIL_IF_NULL(s);
500 
502 
503  FAIL_IF_NOT(DetectIsdataatSetup(NULL, s, "30") == 0);
504  SigMatch *sm = DetectBufferGetFirstSigMatch(s, g_dce_stub_data_buffer_id);
505  FAIL_IF_NOT_NULL(sm);
507  SigFree(NULL, s);
508 
509  s = SigAlloc();
510  FAIL_IF_NULL(s);
512  /* relative w/o preceeding match defaults to "pmatch" */
513  FAIL_IF_NOT(DetectIsdataatSetup(NULL, s, "30,relative") == 0);
514  sm = DetectBufferGetFirstSigMatch(s, g_dce_stub_data_buffer_id);
515  FAIL_IF_NOT_NULL(sm);
517 
518  SigFree(NULL, s);
519  PASS;
520 }
521 
522 static int DetectIsdataatTestParse06(void)
523 {
525  FAIL_IF(de_ctx == NULL);
526  de_ctx->flags |= DE_QUIET;
527 
528  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
529  "(msg:\"Testing bytejump_body\"; "
530  "content:\"one\"; "
531  "isdataat:!4,relative; sid:1;)");
532  FAIL_IF(s == NULL);
533 
535 
537  DetectIsdataatData *data =
539 
543 
544  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
545  "(msg:\"Testing bytejump_body\"; "
546  "content:\"one\"; "
547  "isdataat: !4,relative; sid:2;)");
548  FAIL_IF(s == NULL);
549 
551 
554 
559 
560  PASS;
561 }
562 
563 /**
564  * \test DetectIsdataatTestPacket01 is a test to check matches of
565  * isdataat, and isdataat relative
566  */
567 static int DetectIsdataatTestPacket01 (void)
568 {
569  int result = 0;
570  uint8_t *buf = (uint8_t *)"Hi all!";
571  uint16_t buflen = strlen((char *)buf);
572  Packet *p[3];
573  p[0] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
574  p[1] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_UDP);
575  p[2] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_ICMP);
576 
577  if (p[0] == NULL || p[1] == NULL ||p[2] == NULL)
578  goto end;
579 
580  const char *sigs[5];
581  sigs[0]= "alert ip any any -> any any (msg:\"Testing window 1\"; isdataat:6; sid:1;)";
582  sigs[1]= "alert ip any any -> any any (msg:\"Testing window 2\"; content:\"all\"; isdataat:1, relative; isdataat:6; sid:2;)";
583  sigs[2]= "alert ip any any -> any any (msg:\"Testing window 3\"; isdataat:8; sid:3;)";
584  sigs[3]= "alert ip any any -> any any (msg:\"Testing window 4\"; content:\"Hi\"; isdataat:5, relative; sid:4;)";
585  sigs[4]= "alert ip any any -> any any (msg:\"Testing window 4\"; content:\"Hi\"; isdataat:6, relative; sid:5;)";
586 
587  uint32_t sid[5] = {1, 2, 3, 4, 5};
588 
589  uint32_t results[3][5] = {
590  /* packet 0 match sid 1 but should not match sid 2 */
591  {1, 1, 0, 1, 0},
592  /* packet 1 should not match */
593  {1, 1, 0, 1, 0},
594  /* packet 2 should not match */
595  {1, 1, 0, 1, 0} };
596 
597  result = UTHGenericTest(p, 3, sigs, sid, (uint32_t *) results, 5);
598 
599  UTHFreePackets(p, 3);
600 end:
601  return result;
602 }
603 
604 /**
605  * \test DetectIsdataatTestPacket02 is a test to check matches of
606  * isdataat, and isdataat relative works if the previous keyword is pcre
607  * (bug 144)
608  */
609 static int DetectIsdataatTestPacket02 (void)
610 {
611  int result = 0;
612  uint8_t *buf = (uint8_t *)"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
613  "User-Agent: Wget/1.11.4"
614  "Accept: */*"
615  "Host: www.google.com"
616  "Connection: Keep-Alive"
617  "Date: Mon, 04 Jan 2010 17:29:39 GMT";
618  uint16_t buflen = strlen((char *)buf);
619  Packet *p;
620  p = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
621 
622  if (p == NULL)
623  goto end;
624 
625  char sig[] = "alert tcp any any -> any any (msg:\"pcre with"
626  " isdataat + relative\"; pcre:\"/A(ll|pp)WorkAndNoPlayMakesWillA"
627  "DullBoy/\"; isdataat:96,relative; sid:1;)";
628 
629  result = UTHPacketMatchSig(p, sig);
630 
631  UTHFreePacket(p);
632 end:
633  return result;
634 }
635 
636 /**
637  * \test DetectIsdataatTestPacket03 is a test to check matches of
638  * isdataat, and isdataat relative works if the previous keyword is byte_jump
639  * (bug 146)
640  */
641 static int DetectIsdataatTestPacket03 (void)
642 {
643  int result = 0;
644  uint8_t *buf = (uint8_t *)"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
645  "User-Agent: Wget/1.11.4"
646  "Accept: */*"
647  "Host: www.google.com"
648  "Connection: Keep-Alive"
649  "Date: Mon, 04 Jan 2010 17:29:39 GMT";
650  uint16_t buflen = strlen((char *)buf);
651  Packet *p;
652  p = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
653 
654  if (p == NULL)
655  goto end;
656 
657  char sig[] = "alert tcp any any -> any any (msg:\"byte_jump match = 0 "
658  "with distance content HTTP/1. relative against HTTP/1.0\"; byte_jump:1,"
659  "46,string,dec; isdataat:87,relative; sid:109; rev:1;)";
660 
661  result = UTHPacketMatchSig(p, sig);
662 
663  UTHFreePacket(p);
664 end:
665  return result;
666 }
667 
668 /**
669  * \brief this function registers unit tests for DetectIsdataat
670  */
671 void DetectIsdataatRegisterTests(void)
672 {
673  g_dce_stub_data_buffer_id = DetectBufferTypeGetByName("dce_stub_data");
674 
675  UtRegisterTest("DetectIsdataatTestParse01", DetectIsdataatTestParse01);
676  UtRegisterTest("DetectIsdataatTestParse02", DetectIsdataatTestParse02);
677  UtRegisterTest("DetectIsdataatTestParse03", DetectIsdataatTestParse03);
678  UtRegisterTest("DetectIsdataatTestParse04", DetectIsdataatTestParse04);
679  UtRegisterTest("DetectIsdataatTestParse06", DetectIsdataatTestParse06);
680 
681  UtRegisterTest("DetectIsdataatTestPacket01", DetectIsdataatTestPacket01);
682  UtRegisterTest("DetectIsdataatTestPacket02", DetectIsdataatTestPacket02);
683  UtRegisterTest("DetectIsdataatTestPacket03", DetectIsdataatTestPacket03);
684 }
685 
686 static int DetectAbsentTestParse01(void)
687 {
689  FAIL_IF(de_ctx == NULL);
690  de_ctx->flags |= DE_QUIET;
691 
693  "alert http any any -> any any "
694  "(msg:\"invalid absent only with negated content\"; http.user_agent; "
695  "absent; content:!\"one\"; sid:2;)");
696  FAIL_IF(s != NULL);
697  s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
698  "(msg:\"invalid absent\"; http.user_agent; "
699  "content:!\"one\"; absent; sid:2;)");
700  FAIL_IF(s != NULL);
701  s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
702  "(msg:\"invalid absent\"; http.user_agent; "
703  "content:\"one\"; absent: or_else; sid:2;)");
704  FAIL_IF(s != NULL);
705  s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
706  "(msg:\"absent without sticky buffer\"; "
707  "content:!\"one\"; absent: or_else; sid:2;)");
708  FAIL_IF(s != NULL);
710  "alert websocket any any -> any any "
711  "(msg:\"absent with frame\"; "
712  "frame: websocket.pdu; absent: or_else; content:!\"one\"; sid:2;)");
713  FAIL_IF(s != NULL);
715  PASS;
716 }
717 
718 void DetectAbsentRegisterTests(void)
719 {
720  UtRegisterTest("DetectAbsentTestParse01", DetectAbsentTestParse01);
721 }
722 #endif
util-byte.h
SigTableElmt_::url
const char * url
Definition: detect.h:1545
DETECT_CONTENT_RELATIVE_NEXT
#define DETECT_CONTENT_RELATIVE_NEXT
Definition: detect-content.h:66
SignatureInitDataBuffer_::head
SigMatch * head
Definition: detect.h:543
detect-content.h
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:120
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect-engine-register.h:308
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SignatureInitData_::smlists
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
Definition: detect.h:666
SigTableElmt_::desc
const char * desc
Definition: detect.h:1544
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:78
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
ALPROTO_DCERPC
@ ALPROTO_DCERPC
Definition: app-layer-protos.h:44
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1529
DetectBufferGetFirstSigMatch
SigMatch * DetectBufferGetFirstSigMatch(const Signature *s, const uint32_t buf_id)
Definition: detect-engine-buffer.c:157
DetectIsdataatSetup
int DetectIsdataatSetup(DetectEngineCtx *, Signature *, const char *)
This function is used to add the parsed isdataatdata into the current signature.
Definition: detect-isdataat.c:311
DetectParseRegex
Definition: detect-parse.h:94
SigTableElmt_::name
const char * name
Definition: detect.h:1542
SignatureInitData_::smlists_tail
struct SigMatch_ * smlists_tail[DETECT_SM_LIST_MAX]
Definition: detect.h:668
DETECT_BYTEJUMP
@ DETECT_BYTEJUMP
Definition: detect-engine-register.h:92
ISDATAAT_OFFSET_VAR
#define ISDATAAT_OFFSET_VAR
Definition: detect-isdataat.h:30
DETECT_ABSENT
@ DETECT_ABSENT
Definition: detect-engine-register.h:104
SigFree
void SigFree(DetectEngineCtx *, Signature *)
Definition: detect-parse.c:2383
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:101
DetectIsdataatData_::flags
uint8_t flags
Definition: detect-isdataat.h:34
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:78
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1533
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
detect-isdataat.h
SCDetectGetLastSMFromLists
SigMatch * SCDetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
Definition: detect-parse.c:600
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:995
StringParseUint16
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:295
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2912
DE_QUIET
#define DE_QUIET
Definition: detect.h:334
UTHPacketMatchSig
int UTHPacketMatchSig(Packet *p, const char *sig)
Definition: util-unittest-helper.c:833
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:241
p
Packet * p
Definition: fuzz_dataset.c:30
DetectIsdataatData_
Definition: detect-isdataat.h:32
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:4025
DetectBufferType_
Definition: detect.h:454
DetectContentData_
Definition: detect-content.h:93
DetectPcreData_::flags
uint16_t flags
Definition: detect-pcre.h:52
SCDetectSignatureSetAppProto
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:2619
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3971
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1524
detect-pcre.h
PARSE_REGEX
#define PARSE_REGEX
Regex for parsing our isdataat options.
Definition: detect-isdataat.c:53
DetectByteIndexType
uint8_t DetectByteIndexType
Definition: detect-byte.h:28
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:1452
decode.h
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
DETECT_CONTENT_ENDS_WITH
#define DETECT_CONTENT_ENDS_WITH
Definition: detect-content.h:42
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:4151
SignatureInitData_::list
int list
Definition: detect.h:645
SCSigMatchAppendSMToList
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:424
detect.h
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:364
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:363
Packet_
Definition: decode.h:516
detect-engine-build.h
ISDATAAT_RELATIVE
#define ISDATAAT_RELATIVE
Definition: detect-isdataat.h:27
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:104
DetectEngineBufferTypeGetById
const DetectBufferType * DetectEngineBufferTypeGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1472
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:775
ISDATAAT_RAWBYTES
#define ISDATAAT_RAWBYTES
Definition: detect-isdataat.h:28
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1504
detect-byte.h
DETECT_PCRE
@ DETECT_PCRE
Definition: detect-engine-register.h:80
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:355
DETECT_SM_LIST_NOTSET
#define DETECT_SM_LIST_NOTSET
Definition: detect.h:145
DetectAbsentValidateContentCallback
bool DetectAbsentValidateContentCallback(const Signature *s, const SignatureInitDataBuffer *b)
Definition: detect-isdataat.c:117
SignatureInitDataBuffer_::tail
SigMatch * tail
Definition: detect.h:544
DetectBufferType_::frame
bool frame
Definition: detect.h:461
DETECT_BYTETEST
@ DETECT_BYTETEST
Definition: detect-engine-register.h:91
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
suricata-common.h
DetectAbsentData_
Definition: detect-isdataat.h:37
SigMatch_::type
uint16_t type
Definition: detect.h:361
SIGMATCH_OPTIONAL_OPT
#define SIGMATCH_OPTIONAL_OPT
Definition: detect-engine-register.h:315
SignatureInitData_::curbuf
SignatureInitDataBuffer * curbuf
Definition: detect.h:674
detect-engine-buffer.h
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
UTHGenericTest
int UTHGenericTest(Packet **pkt, int numpkts, const char *sigs[], uint32_t sids[], uint32_t *results, int numsigs)
UTHGenericTest: function that perform a generic check taking care of as maximum common unittest eleme...
Definition: util-unittest-helper.c:578
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
ISDATAAT_NEGATED
#define ISDATAAT_NEGATED
Definition: detect-isdataat.h:29
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
SigMatchListSMBelongsTo
int SigMatchListSMBelongsTo(const Signature *s, const SigMatch *key_sm)
Definition: detect-parse.c:799
SCFree
#define SCFree(p)
Definition: util-mem.h:61
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:470
DETECT_BYTE_EXTRACT
@ DETECT_BYTE_EXTRACT
Definition: detect-engine-register.h:94
detect-parse.h
SignatureInitDataBuffer_::id
uint32_t id
Definition: detect.h:534
Signature_
Signature container.
Definition: detect.h:692
SigMatch_
a single match condition for a signature
Definition: detect.h:360
DETECT_ISDATAAT
@ DETECT_ISDATAAT
Definition: detect-engine-register.h:102
DetectIsdataatData_::dataat
uint16_t dataat
Definition: detect-isdataat.h:33
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2873
DETECT_PCRE_RELATIVE_NEXT
#define DETECT_PCRE_RELATIVE_NEXT
Definition: detect-pcre.h:34
DetectPcreData_
Definition: detect-pcre.h:48
DETECT_BYTEMATH
@ DETECT_BYTEMATH
Definition: detect-engine-register.h:93
detect-uricontent.h
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:997
DetectByteRetrieveSMVar
bool DetectByteRetrieveSMVar(const char *arg, const Signature *s, int sm_list, DetectByteIndexType *index)
Used to retrieve args from BM.
Definition: detect-byte.c:41
SigAlloc
Signature * SigAlloc(void)
Definition: detect-parse.c:2263
flow.h
SignatureInitDataBuffer_
Definition: detect.h:533
DETECT_CONTENT_FAST_PATTERN
#define DETECT_CONTENT_FAST_PATTERN
Definition: detect-content.h:34
DetectAbsentData_::or_else
bool or_else
Definition: detect-isdataat.h:39
DETECT_ENDS_WITH
@ DETECT_ENDS_WITH
Definition: detect-engine-register.h:83
DetectBufferGetActiveList
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine-buffer.c:109
flow-var.h
DetectIsdataatFree
void DetectIsdataatFree(DetectEngineCtx *, void *)
this function will free memory associated with DetectIsdataatData
Definition: detect-isdataat.c:410
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1531
DetectIsdataatRegister
void DetectIsdataatRegister(void)
Registration function for isdataat: keyword.
Definition: detect-isdataat.c:156
app-layer.h
detect-bytetest.h
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:453