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-parse.h"
31 #include "app-layer.h"
32 
33 #include "util-unittest.h"
34 #include "util-unittest-helper.h"
35 
36 #include "detect-isdataat.h"
37 #include "detect-content.h"
38 #include "detect-uricontent.h"
39 #include "detect-engine-build.h"
40 
41 #include "flow.h"
42 #include "flow-var.h"
43 
44 #include "util-debug.h"
45 #include "util-byte.h"
46 #include "detect-pcre.h"
47 #include "detect-byte.h"
48 
49 /**
50  * \brief Regex for parsing our isdataat options
51  */
52 #define PARSE_REGEX "^\\s*!?([^\\s,]+)\\s*(,\\s*relative)?\\s*(,\\s*rawbytes\\s*)?\\s*$"
53 
54 static DetectParseRegex parse_regex;
55 
56 int DetectIsdataatSetup (DetectEngineCtx *, Signature *, const char *);
57 #ifdef UNITTESTS
58 static void DetectIsdataatRegisterTests(void);
59 #endif
60 void DetectIsdataatFree(DetectEngineCtx *, void *);
61 
62 static int DetectEndsWithSetup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr);
63 
64 /**
65  * \brief Registration function for isdataat: keyword
66  */
68 {
69  sigmatch_table[DETECT_ISDATAAT].name = "isdataat";
70  sigmatch_table[DETECT_ISDATAAT].desc = "check if there is still data at a specific part of the payload";
71  sigmatch_table[DETECT_ISDATAAT].url = "/rules/payload-keywords.html#isdataat";
72  /* match is handled in DetectEngineContentInspection() */
76 #ifdef UNITTESTS
77  sigmatch_table[DETECT_ISDATAAT].RegisterTests = DetectIsdataatRegisterTests;
78 #endif
79  sigmatch_table[DETECT_ENDS_WITH].name = "endswith";
80  sigmatch_table[DETECT_ENDS_WITH].desc = "make sure the previous content matches exactly at the end of the buffer";
81  sigmatch_table[DETECT_ENDS_WITH].url = "/rules/payload-keywords.html#endswith";
82  sigmatch_table[DETECT_ENDS_WITH].Setup = DetectEndsWithSetup;
84 
85  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
86 }
87 
88 /**
89  * \brief This function is used to parse isdataat options passed via isdataat: keyword
90  *
91  * \param de_ctx Pointer to the detection engine context
92  * \param isdataatstr Pointer to the user provided isdataat options
93  *
94  * \retval idad pointer to DetectIsdataatData on success
95  * \retval NULL on failure
96  */
97 static DetectIsdataatData *DetectIsdataatParse (DetectEngineCtx *de_ctx, const char *isdataatstr, char **offset)
98 {
99  DetectIsdataatData *idad = NULL;
100  char *args[3] = {NULL,NULL,NULL};
101  int ret = 0, res = 0;
102  size_t pcre2_len;
103  int i=0;
104 
105  ret = DetectParsePcreExec(&parse_regex, isdataatstr, 0, 0);
106  if (ret < 1 || ret > 4) {
107  SCLogError("pcre_exec parse error, ret %" PRId32 ", string %s", ret, isdataatstr);
108  goto error;
109  }
110 
111  if (ret > 1) {
112  const char *str_ptr;
113  res = pcre2_substring_get_bynumber(
114  parse_regex.match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
115  if (res < 0) {
116  SCLogError("pcre2_substring_get_bynumber failed");
117  goto error;
118  }
119  args[0] = (char *)str_ptr;
120 
121 
122  if (ret > 2) {
123  res = pcre2_substring_get_bynumber(
124  parse_regex.match, 2, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
125  if (res < 0) {
126  SCLogError("pcre2_substring_get_bynumber failed");
127  goto error;
128  }
129  args[1] = (char *)str_ptr;
130  }
131  if (ret > 3) {
132  res = pcre2_substring_get_bynumber(
133  parse_regex.match, 3, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
134  if (res < 0) {
135  SCLogError("pcre2_substring_get_bynumber failed");
136  goto error;
137  }
138  args[2] = (char *)str_ptr;
139  }
140 
141  idad = SCMalloc(sizeof(DetectIsdataatData));
142  if (unlikely(idad == NULL))
143  goto error;
144 
145  idad->flags = 0;
146  idad->dataat = 0;
147 
148  if (args[0][0] != '-' && isalpha((unsigned char)args[0][0])) {
149  if (offset == NULL) {
150  SCLogError("isdataat supplied with "
151  "var name for offset. \"offset\" argument supplied to "
152  "this function has to be non-NULL");
153  goto error;
154  }
155  *offset = SCStrdup(args[0]);
156  if (*offset == NULL)
157  goto error;
158  } else {
159  if (StringParseUint16(&idad->dataat, 10,
160  strlen(args[0]), args[0]) < 0 ) {
161  SCLogError("isdataat out of range");
162  SCFree(idad);
163  idad = NULL;
164  goto error;
165  }
166  }
167 
168  if (args[1] !=NULL) {
169  idad->flags |= ISDATAAT_RELATIVE;
170 
171  if(args[2] !=NULL)
172  idad->flags |= ISDATAAT_RAWBYTES;
173  }
174 
175  if (isdataatstr[0] == '!') {
176  idad->flags |= ISDATAAT_NEGATED;
177  }
178 
179  for (i = 0; i < (ret -1); i++) {
180  if (args[i] != NULL)
181  pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
182  }
183 
184  return idad;
185 
186  }
187 
188 error:
189  for (i = 0; i < (ret -1) && i < 3; i++){
190  if (args[i] != NULL)
191  pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
192  }
193 
194  if (idad != NULL)
195  DetectIsdataatFree(de_ctx, idad);
196  return NULL;
197 
198 }
199 
200 /**
201  * \brief This function is used to add the parsed isdataatdata into the current
202  * signature.
203  * \param de_ctx pointer to the Detection Engine Context
204  * \param s pointer to the Current Signature
205  * \param isdataatstr pointer to the user provided isdataat options
206  *
207  * \retval 0 on Success
208  * \retval -1 on Failure
209  */
210 int DetectIsdataatSetup (DetectEngineCtx *de_ctx, Signature *s, const char *isdataatstr)
211 {
212  SigMatch *sm = NULL;
213  SigMatch *prev_pm = NULL;
214  DetectIsdataatData *idad = NULL;
215  char *offset = NULL;
216  int ret = -1;
217 
218  idad = DetectIsdataatParse(de_ctx, isdataatstr, &offset);
219  if (idad == NULL)
220  return -1;
221 
222  int sm_list;
223  if (s->init_data->list != DETECT_SM_LIST_NOTSET) {
224  if (DetectBufferGetActiveList(de_ctx, s) == -1)
225  goto end;
226  sm_list = s->init_data->list;
227 
228  if (idad->flags & ISDATAAT_RELATIVE) {
230  }
231  } else if (idad->flags & ISDATAAT_RELATIVE) {
232  prev_pm = DetectGetLastSMFromLists(s,
236  if (prev_pm == NULL)
237  sm_list = DETECT_SM_LIST_PMATCH;
238  else {
239  sm_list = SigMatchListSMBelongsTo(s, prev_pm);
240  if (sm_list < 0)
241  goto end;
242  }
243  } else {
244  sm_list = DETECT_SM_LIST_PMATCH;
245  }
246 
247  if (offset != NULL) {
248  DetectByteIndexType index;
249  if (!DetectByteRetrieveSMVar(offset, s, &index)) {
250  SCLogError("Unknown byte_extract var "
251  "seen in isdataat - %s\n",
252  offset);
253  goto end;
254  }
255  idad->dataat = index;
256  idad->flags |= ISDATAAT_OFFSET_VAR;
257  SCLogDebug("isdataat uses byte_extract with local id %u", idad->dataat);
258  SCFree(offset);
259  offset = NULL;
260  }
261 
262  /* 'ends with' scenario */
263  if (prev_pm != NULL && prev_pm->type == DETECT_CONTENT &&
264  idad->dataat == 1 &&
266  {
267  DetectIsdataatFree(de_ctx, idad);
268  DetectContentData *cd = (DetectContentData *)prev_pm->ctx;
270  ret = 0;
271  goto end;
272  }
273 
274  sm = SigMatchAlloc();
275  if (sm == NULL)
276  goto end;
277  sm->type = DETECT_ISDATAAT;
278  sm->ctx = (SigMatchCtx *)idad;
279  SigMatchAppendSMToList(s, sm, sm_list);
280 
281  if (!(idad->flags & ISDATAAT_RELATIVE)) {
282  ret = 0;
283  goto end;
284  }
285 
286  if (prev_pm == NULL) {
287  ret = 0;
288  goto end;
289  }
290 
291  if (prev_pm->type == DETECT_CONTENT) {
292  DetectContentData *cd = (DetectContentData *)prev_pm->ctx;
294  } else if (prev_pm->type == DETECT_PCRE) {
295  DetectPcreData *pd = (DetectPcreData *)prev_pm->ctx;
297  }
298 
299  ret = 0;
300 
301 end:
302  if (offset)
303  SCFree(offset);
304  if (ret != 0)
305  DetectIsdataatFree(de_ctx, idad);
306  return ret;
307 }
308 
309 /**
310  * \brief this function will free memory associated with DetectIsdataatData
311  *
312  * \param idad pointer to DetectIsdataatData
313  */
315 {
316  DetectIsdataatData *idad = (DetectIsdataatData *)ptr;
317  SCFree(idad);
318 }
319 
320 static int DetectEndsWithSetup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr)
321 {
322  SigMatch *pm = NULL;
323  int ret = -1;
324 
325  /* retrieve the sm to apply the depth against */
327  if (pm == NULL) {
328  SCLogError("endswith needs a "
329  "preceding content option");
330  goto end;
331  }
332 
333  /* verify other conditions. */
335 
337 
338  ret = 0;
339  end:
340  return ret;
341 }
342 
343 #ifdef UNITTESTS
344 static int g_dce_stub_data_buffer_id = 0;
345 
346 /**
347  * \test DetectIsdataatTestParse01 is a test to make sure that we return a correct IsdataatData structure
348  * when given valid isdataat opt
349  */
350 static int DetectIsdataatTestParse01 (void)
351 {
352  int result = 0;
353  DetectIsdataatData *idad = NULL;
354  idad = DetectIsdataatParse(NULL, "30 ", NULL);
355  if (idad != NULL) {
356  DetectIsdataatFree(NULL, idad);
357  result = 1;
358  }
359 
360  return result;
361 }
362 
363 /**
364  * \test DetectIsdataatTestParse02 is a test to make sure that we return a correct IsdataatData structure
365  * when given valid isdataat opt
366  */
367 static int DetectIsdataatTestParse02 (void)
368 {
369  int result = 0;
370  DetectIsdataatData *idad = NULL;
371  idad = DetectIsdataatParse(NULL, "30 , relative", NULL);
372  if (idad != NULL && idad->flags & ISDATAAT_RELATIVE && !(idad->flags & ISDATAAT_RAWBYTES)) {
373  DetectIsdataatFree(NULL, idad);
374  result = 1;
375  }
376 
377  return result;
378 }
379 
380 /**
381  * \test DetectIsdataatTestParse03 is a test to make sure that we return a correct IsdataatData structure
382  * when given valid isdataat opt
383  */
384 static int DetectIsdataatTestParse03 (void)
385 {
386  int result = 0;
387  DetectIsdataatData *idad = NULL;
388  idad = DetectIsdataatParse(NULL, "30,relative, rawbytes ", NULL);
389  if (idad != NULL && idad->flags & ISDATAAT_RELATIVE && idad->flags & ISDATAAT_RAWBYTES) {
390  DetectIsdataatFree(NULL, idad);
391  result = 1;
392  }
393 
394  return result;
395 }
396 
397 /**
398  * \test Test isdataat option for dce sig.
399  */
400 static int DetectIsdataatTestParse04(void)
401 {
402  Signature *s = SigAlloc();
403  int result = 1;
404 
406  SigFree(NULL, s);
407  return 0;
408  }
409 
410  result &= (DetectIsdataatSetup(NULL, s, "30") == 0);
411  result &= (s->sm_lists[g_dce_stub_data_buffer_id] == NULL && s->sm_lists[DETECT_SM_LIST_PMATCH] != NULL);
412  SigFree(NULL, s);
413 
414  s = SigAlloc();
416  SigFree(NULL, s);
417  return 0;
418  }
419  /* failure since we have no preceding content/pcre/bytejump */
420  result &= (DetectIsdataatSetup(NULL, s, "30,relative") == 0);
421  result &= (s->sm_lists[g_dce_stub_data_buffer_id] == NULL && s->sm_lists[DETECT_SM_LIST_PMATCH] != NULL);
422 
423  SigFree(NULL, s);
424 
425  return result;
426 }
427 
428 /**
429  * \test Test isdataat option for dce sig.
430  */
431 static int DetectIsdataatTestParse05(void)
432 {
433  DetectEngineCtx *de_ctx = NULL;
434  int result = 1;
435  Signature *s = NULL;
436  DetectIsdataatData *data = NULL;
437 
439  if (de_ctx == NULL)
440  goto end;
441 
442  de_ctx->flags |= DE_QUIET;
443  de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
444  "(msg:\"Testing bytejump_body\"; "
445  "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
446  "dce_stub_data; "
447  "content:\"one\"; distance:0; "
448  "isdataat:4,relative; sid:1;)");
449  if (de_ctx->sig_list == NULL) {
450  result = 0;
451  goto end;
452  }
453  s = de_ctx->sig_list;
454  if (s->sm_lists_tail[g_dce_stub_data_buffer_id] == NULL) {
455  result = 0;
456  goto end;
457  }
458  result &= (s->sm_lists_tail[g_dce_stub_data_buffer_id]->type == DETECT_ISDATAAT);
459  data = (DetectIsdataatData *)s->sm_lists_tail[g_dce_stub_data_buffer_id]->ctx;
460  if ( !(data->flags & ISDATAAT_RELATIVE) ||
461  (data->flags & ISDATAAT_RAWBYTES) ) {
462  result = 0;
463  goto end;
464  }
465 
466  s->next = SigInit(de_ctx, "alert tcp any any -> any any "
467  "(msg:\"Testing bytejump_body\"; "
468  "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
469  "dce_stub_data; "
470  "content:\"one\"; distance:0; "
471  "isdataat:4,relative; sid:1;)");
472  if (s->next == NULL) {
473  result = 0;
474  goto end;
475  }
476  s = s->next;
477  if (s->sm_lists_tail[g_dce_stub_data_buffer_id] == NULL) {
478  result = 0;
479  goto end;
480  }
481  result &= (s->sm_lists_tail[g_dce_stub_data_buffer_id]->type == DETECT_ISDATAAT);
482  data = (DetectIsdataatData *)s->sm_lists_tail[g_dce_stub_data_buffer_id]->ctx;
483  if ( !(data->flags & ISDATAAT_RELATIVE) ||
484  (data->flags & ISDATAAT_RAWBYTES) ) {
485  result = 0;
486  goto end;
487  }
488 
489  s->next = SigInit(de_ctx, "alert tcp any any -> any any "
490  "(msg:\"Testing bytejump_body\"; "
491  "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
492  "dce_stub_data; "
493  "content:\"one\"; distance:0; "
494  "isdataat:4,relative,rawbytes; sid:1;)");
495  if (s->next == NULL) {
496  result = 0;
497  goto end;
498  }
499  s = s->next;
500  if (s->sm_lists_tail[g_dce_stub_data_buffer_id] == NULL) {
501  result = 0;
502  goto end;
503  }
504  result &= (s->sm_lists_tail[g_dce_stub_data_buffer_id]->type == DETECT_ISDATAAT);
505  data = (DetectIsdataatData *)s->sm_lists_tail[g_dce_stub_data_buffer_id]->ctx;
506  if ( !(data->flags & ISDATAAT_RELATIVE) ||
507  !(data->flags & ISDATAAT_RAWBYTES) ) {
508  result = 0;
509  goto end;
510  }
511 
512  s->next = SigInit(de_ctx, "alert tcp any any -> any any "
513  "(msg:\"Testing bytejump_body\"; "
514  "content:\"one\"; isdataat:4,relative,rawbytes; sid:1;)");
515  if (s->next == NULL) {
516  result = 0;
517  goto end;
518  }
519  s = s->next;
520  if (s->sm_lists_tail[g_dce_stub_data_buffer_id] != NULL) {
521  result = 0;
522  goto end;
523  }
524 
525  end:
529 
530  return result;
531 }
532 
533 static int DetectIsdataatTestParse06(void)
534 {
536  FAIL_IF(de_ctx == NULL);
537  de_ctx->flags |= DE_QUIET;
538 
539  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
540  "(msg:\"Testing bytejump_body\"; "
541  "content:\"one\"; "
542  "isdataat:!4,relative; sid:1;)");
543  FAIL_IF(s == NULL);
544 
545  FAIL_IF(s->sm_lists_tail[DETECT_SM_LIST_PMATCH] == NULL);
546 
547  FAIL_IF_NOT(s->sm_lists_tail[DETECT_SM_LIST_PMATCH]->type == DETECT_ISDATAAT);
548  DetectIsdataatData *data = (DetectIsdataatData *)s->sm_lists_tail[DETECT_SM_LIST_PMATCH]->ctx;
549 
553 
554  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
555  "(msg:\"Testing bytejump_body\"; "
556  "content:\"one\"; "
557  "isdataat: !4,relative; sid:2;)");
558  FAIL_IF(s == NULL);
559 
560  FAIL_IF(s->sm_lists_tail[DETECT_SM_LIST_PMATCH] == NULL);
561 
562  FAIL_IF_NOT(s->sm_lists_tail[DETECT_SM_LIST_PMATCH]->type == DETECT_ISDATAAT);
563  data = (DetectIsdataatData *)s->sm_lists_tail[DETECT_SM_LIST_PMATCH]->ctx;
564 
569 
570  PASS;
571 }
572 
573 /**
574  * \test DetectIsdataatTestPacket01 is a test to check matches of
575  * isdataat, and isdataat relative
576  */
577 static int DetectIsdataatTestPacket01 (void)
578 {
579  int result = 0;
580  uint8_t *buf = (uint8_t *)"Hi all!";
581  uint16_t buflen = strlen((char *)buf);
582  Packet *p[3];
583  p[0] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
584  p[1] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_UDP);
585  p[2] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_ICMP);
586 
587  if (p[0] == NULL || p[1] == NULL ||p[2] == NULL)
588  goto end;
589 
590  const char *sigs[5];
591  sigs[0]= "alert ip any any -> any any (msg:\"Testing window 1\"; isdataat:6; sid:1;)";
592  sigs[1]= "alert ip any any -> any any (msg:\"Testing window 2\"; content:\"all\"; isdataat:1, relative; isdataat:6; sid:2;)";
593  sigs[2]= "alert ip any any -> any any (msg:\"Testing window 3\"; isdataat:8; sid:3;)";
594  sigs[3]= "alert ip any any -> any any (msg:\"Testing window 4\"; content:\"Hi\"; isdataat:5, relative; sid:4;)";
595  sigs[4]= "alert ip any any -> any any (msg:\"Testing window 4\"; content:\"Hi\"; isdataat:6, relative; sid:5;)";
596 
597  uint32_t sid[5] = {1, 2, 3, 4, 5};
598 
599  uint32_t results[3][5] = {
600  /* packet 0 match sid 1 but should not match sid 2 */
601  {1, 1, 0, 1, 0},
602  /* packet 1 should not match */
603  {1, 1, 0, 1, 0},
604  /* packet 2 should not match */
605  {1, 1, 0, 1, 0} };
606 
607  result = UTHGenericTest(p, 3, sigs, sid, (uint32_t *) results, 5);
608 
609  UTHFreePackets(p, 3);
610 end:
611  return result;
612 }
613 
614 /**
615  * \test DetectIsdataatTestPacket02 is a test to check matches of
616  * isdataat, and isdataat relative works if the previous keyword is pcre
617  * (bug 144)
618  */
619 static int DetectIsdataatTestPacket02 (void)
620 {
621  int result = 0;
622  uint8_t *buf = (uint8_t *)"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
623  "User-Agent: Wget/1.11.4"
624  "Accept: */*"
625  "Host: www.google.com"
626  "Connection: Keep-Alive"
627  "Date: Mon, 04 Jan 2010 17:29:39 GMT";
628  uint16_t buflen = strlen((char *)buf);
629  Packet *p;
630  p = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
631 
632  if (p == NULL)
633  goto end;
634 
635  char sig[] = "alert tcp any any -> any any (msg:\"pcre with"
636  " isdataat + relative\"; pcre:\"/A(ll|pp)WorkAndNoPlayMakesWillA"
637  "DullBoy/\"; isdataat:96,relative; sid:1;)";
638 
639  result = UTHPacketMatchSig(p, sig);
640 
641  UTHFreePacket(p);
642 end:
643  return result;
644 }
645 
646 /**
647  * \test DetectIsdataatTestPacket03 is a test to check matches of
648  * isdataat, and isdataat relative works if the previous keyword is byte_jump
649  * (bug 146)
650  */
651 static int DetectIsdataatTestPacket03 (void)
652 {
653  int result = 0;
654  uint8_t *buf = (uint8_t *)"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
655  "User-Agent: Wget/1.11.4"
656  "Accept: */*"
657  "Host: www.google.com"
658  "Connection: Keep-Alive"
659  "Date: Mon, 04 Jan 2010 17:29:39 GMT";
660  uint16_t buflen = strlen((char *)buf);
661  Packet *p;
662  p = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
663 
664  if (p == NULL)
665  goto end;
666 
667  char sig[] = "alert tcp any any -> any any (msg:\"byte_jump match = 0 "
668  "with distance content HTTP/1. relative against HTTP/1.0\"; byte_jump:1,"
669  "46,string,dec; isdataat:87,relative; sid:109; rev:1;)";
670 
671  result = UTHPacketMatchSig(p, sig);
672 
673  UTHFreePacket(p);
674 end:
675  return result;
676 }
677 
678 /**
679  * \brief this function registers unit tests for DetectIsdataat
680  */
681 void DetectIsdataatRegisterTests(void)
682 {
683  g_dce_stub_data_buffer_id = DetectBufferTypeGetByName("dce_stub_data");
684 
685  UtRegisterTest("DetectIsdataatTestParse01", DetectIsdataatTestParse01);
686  UtRegisterTest("DetectIsdataatTestParse02", DetectIsdataatTestParse02);
687  UtRegisterTest("DetectIsdataatTestParse03", DetectIsdataatTestParse03);
688  UtRegisterTest("DetectIsdataatTestParse04", DetectIsdataatTestParse04);
689  UtRegisterTest("DetectIsdataatTestParse05", DetectIsdataatTestParse05);
690  UtRegisterTest("DetectIsdataatTestParse06", DetectIsdataatTestParse06);
691 
692  UtRegisterTest("DetectIsdataatTestPacket01", DetectIsdataatTestPacket01);
693  UtRegisterTest("DetectIsdataatTestPacket02", DetectIsdataatTestPacket02);
694  UtRegisterTest("DetectIsdataatTestPacket03", DetectIsdataatTestPacket03);
695 }
696 #endif
util-byte.h
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:47
SigTableElmt_::url
const char * url
Definition: detect.h:1241
DETECT_CONTENT_RELATIVE_NEXT
#define DETECT_CONTENT_RELATIVE_NEXT
Definition: detect-content.h:64
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1498
detect-content.h
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:79
SigTableElmt_::desc
const char * desc
Definition: detect.h:1240
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
Definition: detect-parse.c:2488
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
ALPROTO_DCERPC
@ ALPROTO_DCERPC
Definition: app-layer-protos.h:38
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1228
DetectIsdataatSetup
int DetectIsdataatSetup(DetectEngineCtx *, Signature *, const char *)
This function is used to add the parsed isdataatdata into the current signature.
Definition: detect-isdataat.c:210
DetectParseRegex
Definition: detect-parse.h:44
SigTableElmt_::name
const char * name
Definition: detect.h:1238
DETECT_BYTEJUMP
@ DETECT_BYTEJUMP
Definition: detect-engine-register.h:76
ISDATAAT_OFFSET_VAR
#define ISDATAAT_OFFSET_VAR
Definition: detect-isdataat.h:30
SigFree
void SigFree(DetectEngineCtx *, Signature *)
Definition: detect-parse.c:1397
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
DetectIsdataatData_::flags
uint8_t flags
Definition: detect-isdataat.h:37
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:62
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
detect-isdataat.h
results
struct DetectRfbSecresult_ results[]
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1232
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:785
StringParseUint16
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:337
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2442
DE_QUIET
#define DE_QUIET
Definition: detect.h:287
UTHPacketMatchSig
int UTHPacketMatchSig(Packet *p, const char *sig)
Definition: util-unittest-helper.c:844
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
DetectIsdataatData_
Definition: detect-isdataat.h:35
DetectContentData_
Definition: detect-content.h:86
DetectPcreData_::flags
uint16_t flags
Definition: detect-pcre.h:47
SigCleanSignatures
void SigCleanSignatures(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:46
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:2434
DetectBufferGetActiveList
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine.c:1306
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1223
detect-pcre.h
PARSE_REGEX
#define PARSE_REGEX
Regex for parsing our isdataat options.
Definition: detect-isdataat.c:52
DetectByteIndexType
uint8_t DetectByteIndexType
Definition: detect-byte.h:28
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:1079
Signature_::next
struct Signature_ * next
Definition: detect.h:614
decode.h
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:17
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2609
SignatureInitData_::list
int list
Definition: detect.h:517
detect.h
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2129
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:316
SigGroupCleanup
int SigGroupCleanup(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:2019
Packet_
Definition: decode.h:428
detect-engine-build.h
ISDATAAT_RELATIVE
#define ISDATAAT_RELATIVE
Definition: detect-isdataat.h:27
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:97
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:611
ISDATAAT_RAWBYTES
#define ISDATAAT_RAWBYTES
Definition: detect-isdataat.h:28
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1206
detect-byte.h
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:239
DETECT_PCRE
@ DETECT_PCRE
Definition: detect-engine-register.h:64
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:308
DETECT_SM_LIST_NOTSET
#define DETECT_SM_LIST_NOTSET
Definition: detect.h:104
DETECT_BYTETEST
@ DETECT_BYTETEST
Definition: detect-engine-register.h:75
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
DetectByteRetrieveSMVar
bool DetectByteRetrieveSMVar(const char *arg, const Signature *s, DetectByteIndexType *index)
Used to retrieve args from BM.
Definition: detect-byte.c:39
suricata-common.h
SigMatch_::type
uint16_t type
Definition: detect.h:314
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:76
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:791
UTHGenericTest
int UTHGenericTest(Packet **pkt, int numpkts, const char *sigs[], uint32_t sids[], uint32_t *results, int numsigs)
UTHGenericTest: function that perfom a generic check taking care of as maximum common unittest elemen...
Definition: util-unittest-helper.c:604
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:261
SigMatchListSMBelongsTo
int SigMatchListSMBelongsTo(const Signature *s, const SigMatch *key_sm)
Definition: detect-parse.c:631
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:485
DETECT_BYTE_EXTRACT
@ DETECT_BYTE_EXTRACT
Definition: detect-engine-register.h:178
detect-parse.h
Signature_
Signature container.
Definition: detect.h:540
SigMatch_
a single match condition for a signature
Definition: detect.h:313
DETECT_ISDATAAT
@ DETECT_ISDATAAT
Definition: detect-engine-register.h:82
DetectIsdataatData_::dataat
uint16_t dataat
Definition: detect-isdataat.h:36
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2403
DETECT_PCRE_RELATIVE_NEXT
#define DETECT_PCRE_RELATIVE_NEXT
Definition: detect-pcre.h:34
DetectPcreData_
Definition: detect-pcre.h:42
DETECT_BYTEMATH
@ DETECT_BYTEMATH
Definition: detect-engine-register.h:77
detect-uricontent.h
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect.h:1423
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:474
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:786
SigAlloc
Signature * SigAlloc(void)
Definition: detect-parse.c:1272
flow.h
DETECT_ENDS_WITH
@ DETECT_ENDS_WITH
Definition: detect-engine-register.h:67
flow-var.h
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:354
DetectIsdataatFree
void DetectIsdataatFree(DetectEngineCtx *, void *)
this function will free memory associated with DetectIsdataatData
Definition: detect-isdataat.c:314
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1230
DetectIsdataatRegister
void DetectIsdataatRegister(void)
Registration function for isdataat: keyword.
Definition: detect-isdataat.c:67
app-layer.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:468