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