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  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(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 = pcre2_substring_get_bynumber(
114  parse_regex.match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
115  if (res < 0) {
116  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "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(SC_ERR_PCRE_GET_SUBSTRING, "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(SC_ERR_PCRE_GET_SUBSTRING, "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(SC_ERR_INVALID_ARGUMENT, "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(SC_ERR_INVALID_VALUE, "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(SC_ERR_INVALID_SIGNATURE, "Unknown byte_extract var "
251  "seen in isdataat - %s\n", offset);
252  goto end;
253  }
254  idad->dataat = index;
255  idad->flags |= ISDATAAT_OFFSET_VAR;
256  SCLogDebug("isdataat uses byte_extract with local id %u", idad->dataat);
257  SCFree(offset);
258  offset = NULL;
259  }
260 
261  /* 'ends with' scenario */
262  if (prev_pm != NULL && prev_pm->type == DETECT_CONTENT &&
263  idad->dataat == 1 &&
265  {
266  DetectIsdataatFree(de_ctx, idad);
267  DetectContentData *cd = (DetectContentData *)prev_pm->ctx;
269  ret = 0;
270  goto end;
271  }
272 
273  sm = SigMatchAlloc();
274  if (sm == NULL)
275  goto end;
276  sm->type = DETECT_ISDATAAT;
277  sm->ctx = (SigMatchCtx *)idad;
278  SigMatchAppendSMToList(s, sm, sm_list);
279 
280  if (!(idad->flags & ISDATAAT_RELATIVE)) {
281  ret = 0;
282  goto end;
283  }
284 
285  if (prev_pm == NULL) {
286  ret = 0;
287  goto end;
288  }
289 
290  if (prev_pm->type == DETECT_CONTENT) {
291  DetectContentData *cd = (DetectContentData *)prev_pm->ctx;
293  } else if (prev_pm->type == DETECT_PCRE) {
294  DetectPcreData *pd = (DetectPcreData *)prev_pm->ctx;
296  }
297 
298  ret = 0;
299 
300 end:
301  if (offset)
302  SCFree(offset);
303  if (ret != 0)
304  DetectIsdataatFree(de_ctx, idad);
305  return ret;
306 }
307 
308 /**
309  * \brief this function will free memory associated with DetectIsdataatData
310  *
311  * \param idad pointer to DetectIsdataatData
312  */
314 {
315  DetectIsdataatData *idad = (DetectIsdataatData *)ptr;
316  SCFree(idad);
317 }
318 
319 static int DetectEndsWithSetup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr)
320 {
321  SigMatch *pm = NULL;
322  int ret = -1;
323 
324  /* retrieve the sm to apply the depth against */
326  if (pm == NULL) {
327  SCLogError(SC_ERR_DEPTH_MISSING_CONTENT, "endswith needs a "
328  "preceding content option");
329  goto end;
330  }
331 
332  /* verify other conditions. */
334 
336 
337  ret = 0;
338  end:
339  return ret;
340 }
341 
342 #ifdef UNITTESTS
343 static int g_dce_stub_data_buffer_id = 0;
344 
345 /**
346  * \test DetectIsdataatTestParse01 is a test to make sure that we return a correct IsdataatData structure
347  * when given valid isdataat opt
348  */
349 static int DetectIsdataatTestParse01 (void)
350 {
351  int result = 0;
352  DetectIsdataatData *idad = NULL;
353  idad = DetectIsdataatParse(NULL, "30 ", NULL);
354  if (idad != NULL) {
355  DetectIsdataatFree(NULL, idad);
356  result = 1;
357  }
358 
359  return result;
360 }
361 
362 /**
363  * \test DetectIsdataatTestParse02 is a test to make sure that we return a correct IsdataatData structure
364  * when given valid isdataat opt
365  */
366 static int DetectIsdataatTestParse02 (void)
367 {
368  int result = 0;
369  DetectIsdataatData *idad = NULL;
370  idad = DetectIsdataatParse(NULL, "30 , relative", NULL);
371  if (idad != NULL && idad->flags & ISDATAAT_RELATIVE && !(idad->flags & ISDATAAT_RAWBYTES)) {
372  DetectIsdataatFree(NULL, idad);
373  result = 1;
374  }
375 
376  return result;
377 }
378 
379 /**
380  * \test DetectIsdataatTestParse03 is a test to make sure that we return a correct IsdataatData structure
381  * when given valid isdataat opt
382  */
383 static int DetectIsdataatTestParse03 (void)
384 {
385  int result = 0;
386  DetectIsdataatData *idad = NULL;
387  idad = DetectIsdataatParse(NULL, "30,relative, rawbytes ", NULL);
388  if (idad != NULL && idad->flags & ISDATAAT_RELATIVE && idad->flags & ISDATAAT_RAWBYTES) {
389  DetectIsdataatFree(NULL, idad);
390  result = 1;
391  }
392 
393  return result;
394 }
395 
396 /**
397  * \test Test isdataat option for dce sig.
398  */
399 static int DetectIsdataatTestParse04(void)
400 {
401  Signature *s = SigAlloc();
402  int result = 1;
403 
405  SigFree(NULL, s);
406  return 0;
407  }
408 
409  result &= (DetectIsdataatSetup(NULL, s, "30") == 0);
410  result &= (s->sm_lists[g_dce_stub_data_buffer_id] == NULL && s->sm_lists[DETECT_SM_LIST_PMATCH] != NULL);
411  SigFree(NULL, s);
412 
413  s = SigAlloc();
415  SigFree(NULL, s);
416  return 0;
417  }
418  /* failure since we have no preceding content/pcre/bytejump */
419  result &= (DetectIsdataatSetup(NULL, s, "30,relative") == 0);
420  result &= (s->sm_lists[g_dce_stub_data_buffer_id] == NULL && s->sm_lists[DETECT_SM_LIST_PMATCH] != NULL);
421 
422  SigFree(NULL, s);
423 
424  return result;
425 }
426 
427 /**
428  * \test Test isdataat option for dce sig.
429  */
430 static int DetectIsdataatTestParse05(void)
431 {
432  DetectEngineCtx *de_ctx = NULL;
433  int result = 1;
434  Signature *s = NULL;
435  DetectIsdataatData *data = NULL;
436 
438  if (de_ctx == NULL)
439  goto end;
440 
441  de_ctx->flags |= DE_QUIET;
442  de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
443  "(msg:\"Testing bytejump_body\"; "
444  "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
445  "dce_stub_data; "
446  "content:\"one\"; distance:0; "
447  "isdataat:4,relative; sid:1;)");
448  if (de_ctx->sig_list == NULL) {
449  result = 0;
450  goto end;
451  }
452  s = de_ctx->sig_list;
453  if (s->sm_lists_tail[g_dce_stub_data_buffer_id] == NULL) {
454  result = 0;
455  goto end;
456  }
457  result &= (s->sm_lists_tail[g_dce_stub_data_buffer_id]->type == DETECT_ISDATAAT);
458  data = (DetectIsdataatData *)s->sm_lists_tail[g_dce_stub_data_buffer_id]->ctx;
459  if ( !(data->flags & ISDATAAT_RELATIVE) ||
460  (data->flags & ISDATAAT_RAWBYTES) ) {
461  result = 0;
462  goto end;
463  }
464 
465  s->next = SigInit(de_ctx, "alert tcp any any -> any any "
466  "(msg:\"Testing bytejump_body\"; "
467  "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
468  "dce_stub_data; "
469  "content:\"one\"; distance:0; "
470  "isdataat:4,relative; sid:1;)");
471  if (s->next == NULL) {
472  result = 0;
473  goto end;
474  }
475  s = s->next;
476  if (s->sm_lists_tail[g_dce_stub_data_buffer_id] == NULL) {
477  result = 0;
478  goto end;
479  }
480  result &= (s->sm_lists_tail[g_dce_stub_data_buffer_id]->type == DETECT_ISDATAAT);
481  data = (DetectIsdataatData *)s->sm_lists_tail[g_dce_stub_data_buffer_id]->ctx;
482  if ( !(data->flags & ISDATAAT_RELATIVE) ||
483  (data->flags & ISDATAAT_RAWBYTES) ) {
484  result = 0;
485  goto end;
486  }
487 
488  s->next = SigInit(de_ctx, "alert tcp any any -> any any "
489  "(msg:\"Testing bytejump_body\"; "
490  "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
491  "dce_stub_data; "
492  "content:\"one\"; distance:0; "
493  "isdataat:4,relative,rawbytes; sid:1;)");
494  if (s->next == NULL) {
495  result = 0;
496  goto end;
497  }
498  s = s->next;
499  if (s->sm_lists_tail[g_dce_stub_data_buffer_id] == NULL) {
500  result = 0;
501  goto end;
502  }
503  result &= (s->sm_lists_tail[g_dce_stub_data_buffer_id]->type == DETECT_ISDATAAT);
504  data = (DetectIsdataatData *)s->sm_lists_tail[g_dce_stub_data_buffer_id]->ctx;
505  if ( !(data->flags & ISDATAAT_RELATIVE) ||
506  !(data->flags & ISDATAAT_RAWBYTES) ) {
507  result = 0;
508  goto end;
509  }
510 
511  s->next = SigInit(de_ctx, "alert tcp any any -> any any "
512  "(msg:\"Testing bytejump_body\"; "
513  "content:\"one\"; isdataat:4,relative,rawbytes; sid:1;)");
514  if (s->next == NULL) {
515  result = 0;
516  goto end;
517  }
518  s = s->next;
519  if (s->sm_lists_tail[g_dce_stub_data_buffer_id] != NULL) {
520  result = 0;
521  goto end;
522  }
523 
524  end:
528 
529  return result;
530 }
531 
532 static int DetectIsdataatTestParse06(void)
533 {
535  FAIL_IF(de_ctx == NULL);
536  de_ctx->flags |= DE_QUIET;
537 
538  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
539  "(msg:\"Testing bytejump_body\"; "
540  "content:\"one\"; "
541  "isdataat:!4,relative; sid:1;)");
542  FAIL_IF(s == NULL);
543 
544  FAIL_IF(s->sm_lists_tail[DETECT_SM_LIST_PMATCH] == NULL);
545 
546  FAIL_IF_NOT(s->sm_lists_tail[DETECT_SM_LIST_PMATCH]->type == DETECT_ISDATAAT);
547  DetectIsdataatData *data = (DetectIsdataatData *)s->sm_lists_tail[DETECT_SM_LIST_PMATCH]->ctx;
548 
552 
553  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
554  "(msg:\"Testing bytejump_body\"; "
555  "content:\"one\"; "
556  "isdataat: !4,relative; sid:2;)");
557  FAIL_IF(s == NULL);
558 
559  FAIL_IF(s->sm_lists_tail[DETECT_SM_LIST_PMATCH] == NULL);
560 
561  FAIL_IF_NOT(s->sm_lists_tail[DETECT_SM_LIST_PMATCH]->type == DETECT_ISDATAAT);
562  data = (DetectIsdataatData *)s->sm_lists_tail[DETECT_SM_LIST_PMATCH]->ctx;
563 
568 
569  PASS;
570 }
571 
572 /**
573  * \test DetectIsdataatTestPacket01 is a test to check matches of
574  * isdataat, and isdataat relative
575  */
576 static int DetectIsdataatTestPacket01 (void)
577 {
578  int result = 0;
579  uint8_t *buf = (uint8_t *)"Hi all!";
580  uint16_t buflen = strlen((char *)buf);
581  Packet *p[3];
582  p[0] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
583  p[1] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_UDP);
584  p[2] = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_ICMP);
585 
586  if (p[0] == NULL || p[1] == NULL ||p[2] == NULL)
587  goto end;
588 
589  const char *sigs[5];
590  sigs[0]= "alert ip any any -> any any (msg:\"Testing window 1\"; isdataat:6; sid:1;)";
591  sigs[1]= "alert ip any any -> any any (msg:\"Testing window 2\"; content:\"all\"; isdataat:1, relative; isdataat:6; sid:2;)";
592  sigs[2]= "alert ip any any -> any any (msg:\"Testing window 3\"; isdataat:8; sid:3;)";
593  sigs[3]= "alert ip any any -> any any (msg:\"Testing window 4\"; content:\"Hi\"; isdataat:5, relative; sid:4;)";
594  sigs[4]= "alert ip any any -> any any (msg:\"Testing window 4\"; content:\"Hi\"; isdataat:6, relative; sid:5;)";
595 
596  uint32_t sid[5] = {1, 2, 3, 4, 5};
597 
598  uint32_t results[3][5] = {
599  /* packet 0 match sid 1 but should not match sid 2 */
600  {1, 1, 0, 1, 0},
601  /* packet 1 should not match */
602  {1, 1, 0, 1, 0},
603  /* packet 2 should not match */
604  {1, 1, 0, 1, 0} };
605 
606  result = UTHGenericTest(p, 3, sigs, sid, (uint32_t *) results, 5);
607 
608  UTHFreePackets(p, 3);
609 end:
610  return result;
611 }
612 
613 /**
614  * \test DetectIsdataatTestPacket02 is a test to check matches of
615  * isdataat, and isdataat relative works if the previous keyword is pcre
616  * (bug 144)
617  */
618 static int DetectIsdataatTestPacket02 (void)
619 {
620  int result = 0;
621  uint8_t *buf = (uint8_t *)"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
622  "User-Agent: Wget/1.11.4"
623  "Accept: */*"
624  "Host: www.google.com"
625  "Connection: Keep-Alive"
626  "Date: Mon, 04 Jan 2010 17:29:39 GMT";
627  uint16_t buflen = strlen((char *)buf);
628  Packet *p;
629  p = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
630 
631  if (p == NULL)
632  goto end;
633 
634  char sig[] = "alert tcp any any -> any any (msg:\"pcre with"
635  " isdataat + relative\"; pcre:\"/A(ll|pp)WorkAndNoPlayMakesWillA"
636  "DullBoy/\"; isdataat:96,relative; sid:1;)";
637 
638  result = UTHPacketMatchSig(p, sig);
639 
640  UTHFreePacket(p);
641 end:
642  return result;
643 }
644 
645 /**
646  * \test DetectIsdataatTestPacket03 is a test to check matches of
647  * isdataat, and isdataat relative works if the previous keyword is byte_jump
648  * (bug 146)
649  */
650 static int DetectIsdataatTestPacket03 (void)
651 {
652  int result = 0;
653  uint8_t *buf = (uint8_t *)"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
654  "User-Agent: Wget/1.11.4"
655  "Accept: */*"
656  "Host: www.google.com"
657  "Connection: Keep-Alive"
658  "Date: Mon, 04 Jan 2010 17:29:39 GMT";
659  uint16_t buflen = strlen((char *)buf);
660  Packet *p;
661  p = UTHBuildPacket((uint8_t *)buf, buflen, IPPROTO_TCP);
662 
663  if (p == NULL)
664  goto end;
665 
666  char sig[] = "alert tcp any any -> any any (msg:\"byte_jump match = 0 "
667  "with distance content HTTP/1. relative against HTTP/1.0\"; byte_jump:1,"
668  "46,string,dec; isdataat:87,relative; sid:109; rev:1;)";
669 
670  result = UTHPacketMatchSig(p, sig);
671 
672  UTHFreePacket(p);
673 end:
674  return result;
675 }
676 
677 /**
678  * \brief this function registers unit tests for DetectIsdataat
679  */
680 void DetectIsdataatRegisterTests(void)
681 {
682  g_dce_stub_data_buffer_id = DetectBufferTypeGetByName("dce_stub_data");
683 
684  UtRegisterTest("DetectIsdataatTestParse01", DetectIsdataatTestParse01);
685  UtRegisterTest("DetectIsdataatTestParse02", DetectIsdataatTestParse02);
686  UtRegisterTest("DetectIsdataatTestParse03", DetectIsdataatTestParse03);
687  UtRegisterTest("DetectIsdataatTestParse04", DetectIsdataatTestParse04);
688  UtRegisterTest("DetectIsdataatTestParse05", DetectIsdataatTestParse05);
689  UtRegisterTest("DetectIsdataatTestParse06", DetectIsdataatTestParse06);
690 
691  UtRegisterTest("DetectIsdataatTestPacket01", DetectIsdataatTestPacket01);
692  UtRegisterTest("DetectIsdataatTestPacket02", DetectIsdataatTestPacket02);
693  UtRegisterTest("DetectIsdataatTestPacket03", DetectIsdataatTestPacket03);
694 }
695 #endif
util-byte.h
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:45
SigTableElmt_::url
const char * url
Definition: detect.h:1270
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:1490
detect-content.h
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:90
SigTableElmt_::desc
const char * desc
Definition: detect.h:1269
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
Definition: detect-parse.c:2474
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:1257
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:42
SigTableElmt_::name
const char * name
Definition: detect.h:1267
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:1389
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:2115
results
struct DetectRfbSecresult_ results[]
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1261
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:811
StringParseUint16
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:336
SC_ERR_INVALID_SIGNATURE
@ SC_ERR_INVALID_SIGNATURE
Definition: util-error.h:69
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2433
DE_QUIET
#define DE_QUIET
Definition: detect.h:295
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:44
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:42
DetectBufferGetActiveList
int DetectBufferGetActiveList(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine.c:1304
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1252
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 evaluates to false.
Definition: util-unittest.h:82
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1077
Signature_::next
struct Signature_ * next
Definition: detect.h:622
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:2597
SignatureInitData_::list
int list
Definition: detect.h:525
detect.h
SC_ERR_INVALID_ARGUMENT
@ SC_ERR_INVALID_ARGUMENT
Definition: util-error.h:43
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:324
SigGroupCleanup
int SigGroupCleanup(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:2016
Packet_
Definition: decode.h:427
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:619
ISDATAAT_RAWBYTES
#define ISDATAAT_RAWBYTES
Definition: detect-isdataat.h:28
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1235
detect-byte.h
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:235
DETECT_PCRE
@ DETECT_PCRE
Definition: detect-engine-register.h:62
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:316
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:2420
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:322
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
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:817
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:173
detect-parse.h
Signature_
Signature container.
Definition: detect.h:548
SigMatch_
a single match condition for a signature
Definition: detect.h:321
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:2394
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:1453
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:812
SigAlloc
Signature * SigAlloc(void)
Definition: detect-parse.c:1264
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:313
debug.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1259
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