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