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