suricata
detect-engine-payload.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2021 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 Victor Julien <victor@inliniac.net>
22  *
23  * Performs payload matching functions
24  */
25 
26 #include "suricata-common.h"
27 #include "suricata.h"
28 #include "rust.h"
29 
30 #include "decode.h"
31 
32 #include "detect.h"
33 #include "detect-engine.h"
34 #include "detect-parse.h"
37 #include "detect-engine-state.h"
38 #include "detect-engine-payload.h"
39 #include "detect-engine-build.h"
40 
41 #include "stream.h"
42 #include "stream-tcp.h"
43 
44 #include "util-debug.h"
45 #include "util-print.h"
46 
47 #include "util-unittest-helper.h"
48 #include "util-validate.h"
49 #include "util-profiling.h"
50 #include "util-mpm-ac.h"
51 
52 struct StreamMpmData {
54  const MpmCtx *mpm_ctx;
55 };
56 
57 static int StreamMpmFunc(
58  void *cb_data, const uint8_t *data, const uint32_t data_len, const uint64_t _offset)
59 {
60  struct StreamMpmData *smd = cb_data;
61  if (data_len >= smd->mpm_ctx->minlen) {
62 #ifdef DEBUG
63  smd->det_ctx->stream_mpm_cnt++;
64  smd->det_ctx->stream_mpm_size += data_len;
65 #endif
66  (void)mpm_table[smd->mpm_ctx->mpm_type].Search(
67  smd->mpm_ctx, &smd->det_ctx->mtc, &smd->det_ctx->pmq, data, data_len);
68  PREFILTER_PROFILING_ADD_BYTES(smd->det_ctx, data_len);
69  }
70  return 0;
71 }
72 
73 static int StreamMpmFuncNop(
74  void *cb_data, const uint8_t *data, const uint32_t data_len, const uint64_t _offset)
75 {
76  return 0;
77 }
78 
79 static void PrefilterPktStreamNoMpm(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx)
80 {
81  /* used to advance raw_stream_progress */
84  p->flow->protoctx, p, StreamMpmFuncNop, NULL, &det_ctx->raw_stream_progress, false);
85  }
86 }
87 
88 static void PrefilterPktStream(DetectEngineThreadCtx *det_ctx,
89  Packet *p, const void *pectx)
90 {
91  SCEnter();
92 
93  const MpmCtx *mpm_ctx = (MpmCtx *)pectx;
94 
95  /* for established packets inspect any stream we may have queued up */
97  SCLogDebug("PRE det_ctx->raw_stream_progress %"PRIu64,
99  struct StreamMpmData stream_mpm_data = { det_ctx, mpm_ctx };
101  StreamMpmFunc, &stream_mpm_data,
103  false /* mpm doesn't use min inspect depth */);
104  SCLogDebug("POST det_ctx->raw_stream_progress %"PRIu64,
106 
107  /* packets that have not been added to the stream will be inspected as if they are stream
108  * chunks */
109  } else if ((p->flags & (PKT_NOPAYLOAD_INSPECTION | PKT_STREAM_ADD)) == 0) {
110  if (p->payload_len >= mpm_ctx->minlen) {
111 #ifdef DEBUG
112  det_ctx->payload_mpm_cnt++;
113  det_ctx->payload_mpm_size += p->payload_len;
114 #endif
116  &det_ctx->mtc, &det_ctx->pmq,
117  p->payload, p->payload_len);
119  }
120  }
121 }
122 
124  SigGroupHead *sgh, MpmCtx *mpm_ctx)
125 {
127  PrefilterPktStream, mpm_ctx, NULL, "stream");
128 }
129 
130 static void FreePrefilterNoMpmCtx(void *ctx)
131 {
132  SCFree(ctx);
133 }
134 
136 {
137  return PrefilterAppendPayloadEngine(de_ctx, sgh, PrefilterPktStreamNoMpm, mpm_ctx,
138  FreePrefilterNoMpmCtx, "stream_progress_only");
139 }
140 
141 static void PrefilterPktPayload(DetectEngineThreadCtx *det_ctx,
142  Packet *p, const void *pectx)
143 {
144  SCEnter();
145 
146  const MpmCtx *mpm_ctx = (MpmCtx *)pectx;
147  if (p->payload_len < mpm_ctx->minlen)
148  SCReturn;
149 
151  &det_ctx->mtc, &det_ctx->pmq,
152  p->payload, p->payload_len);
153 
155 }
156 
158  SigGroupHead *sgh, MpmCtx *mpm_ctx)
159 {
161  PrefilterPktPayload, mpm_ctx, NULL, "payload");
162 }
163 
164 
165 /**
166  * \brief Do the content inspection & validation for a signature
167  *
168  * \param de_ctx Detection engine context
169  * \param det_ctx Detection engine thread context
170  * \param s Signature to inspect
171  * \param f flow (for pcre flowvar storage)
172  * \param p Packet
173  *
174  * \retval 0 no match
175  * \retval 1 match
176  */
178  const Signature *s, Flow *f, Packet *p)
179 {
180  SCEnter();
181 
182  if (s->sm_arrays[DETECT_SM_LIST_PMATCH] == NULL) {
183  SCReturnInt(0);
184  }
185 #ifdef DEBUG
186  det_ctx->payload_persig_cnt++;
187  det_ctx->payload_persig_size += p->payload_len;
188 #endif
189  const bool match = DetectEngineContentInspection(de_ctx, det_ctx, s,
192  if (match) {
193  SCReturnInt(1);
194  }
195  SCReturnInt(0);
196 }
197 
198 /**
199  * \brief Do the content inspection & validation for a sigmatch list
200  *
201  * \param de_ctx Detection engine context
202  * \param det_ctx Detection engine thread context
203  * \param s Signature to inspect
204  * \param smd array of matches to eval
205  * \param f flow (for pcre flowvar storage)
206  * \param p Packet
207  *
208  * \retval 0 no match
209  * \retval 1 match
210  */
211 static uint8_t DetectEngineInspectStreamUDPPayload(DetectEngineCtx *de_ctx,
212  DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Flow *f,
213  Packet *p)
214 {
215  SCEnter();
216 
217  if (smd == NULL) {
218  SCReturnInt(0);
219  }
220 #ifdef DEBUG
221  det_ctx->payload_persig_cnt++;
222  det_ctx->payload_persig_size += p->payload_len;
223 #endif
224  const bool match =
227  if (match) {
228  SCReturnInt(1);
229  }
230  SCReturnInt(0);
231 }
232 
236  const Signature *s;
237  Flow *f;
238 };
239 
240 static int StreamContentInspectFunc(
241  void *cb_data, const uint8_t *data, const uint32_t data_len, const uint64_t _offset)
242 {
243  SCEnter();
244  struct StreamContentInspectData *smd = cb_data;
245 #ifdef DEBUG
246  smd->det_ctx->stream_persig_cnt++;
247  smd->det_ctx->stream_persig_size += data_len;
248 #endif
249 
250  const bool match = DetectEngineContentInspection(smd->de_ctx, smd->det_ctx, smd->s,
251  smd->s->sm_arrays[DETECT_SM_LIST_PMATCH], NULL, smd->f, data, data_len, 0,
252  0, // TODO
254  if (match) {
255  SCReturnInt(1);
256  }
257 
258  SCReturnInt(0);
259 }
260 
261 /**
262  * \brief Do the content inspection & validation for a signature
263  * on the raw stream
264  *
265  * \param de_ctx Detection engine context
266  * \param det_ctx Detection engine thread context
267  * \param s Signature to inspect
268  * \param f flow (for pcre flowvar storage)
269  *
270  * \retval 0 no match
271  * \retval 1 match
272  */
275  Flow *f, Packet *p)
276 {
277  SCEnter();
278  SCLogDebug("FLUSH? %s", (s->flags & SIG_FLAG_FLUSH)?"true":"false");
279  uint64_t unused;
280  struct StreamContentInspectData inspect_data = { de_ctx, det_ctx, s, f };
281  int r = StreamReassembleRaw(f->protoctx, p,
282  StreamContentInspectFunc, &inspect_data,
283  &unused, ((s->flags & SIG_FLAG_FLUSH) != 0));
284  return r;
285 }
286 
290  const Signature *s;
292  Flow *f;
293 };
294 
295 static int StreamContentInspectEngineFunc(
296  void *cb_data, const uint8_t *data, const uint32_t data_len, const uint64_t _offset)
297 {
298  SCEnter();
299  struct StreamContentInspectEngineData *smd = cb_data;
300 #ifdef DEBUG
301  smd->det_ctx->stream_persig_cnt++;
302  smd->det_ctx->stream_persig_size += data_len;
303 #endif
304 
305  const bool match = DetectEngineContentInspection(smd->de_ctx, smd->det_ctx, smd->s, smd->smd,
306  NULL, smd->f, data, data_len, 0, 0, // TODO
308  if (match) {
309  SCReturnInt(1);
310  }
311 
312  SCReturnInt(0);
313 }
314 
315 /**
316  * \brief inspect engine for stateful rules
317  *
318  * Caches results as it may be called multiple times if we inspect
319  * multiple transactions in one packet.
320  *
321  * Returns "can't match" if depth is reached.
322  */
324  const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f,
325  uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
326 {
327  Packet *p = det_ctx->p; /* TODO: get rid of this HACK */
328 
329  /* in certain sigs, e.g. 'alert dns', which apply to both tcp and udp
330  * we can get called for UDP. Then we simply inspect the packet payload */
331  if (p->proto == IPPROTO_UDP) {
332  return DetectEngineInspectStreamUDPPayload(de_ctx, det_ctx, s, engine->smd, f, p);
333  /* for other non-TCP protocols we assume match */
334  } else if (p->proto != IPPROTO_TCP)
336 
337  TcpSession *ssn = f->protoctx;
338  if (ssn == NULL)
340 
341  SCLogDebug("pre-inspect det_ctx->raw_stream_progress %"PRIu64" FLUSH? %s",
343  (s->flags & SIG_FLAG_FLUSH)?"true":"false");
344  uint64_t unused;
345  struct StreamContentInspectEngineData inspect_data = { de_ctx, det_ctx, s, engine->smd, f };
346  int match = StreamReassembleRaw(f->protoctx, p,
347  StreamContentInspectEngineFunc, &inspect_data,
348  &unused, ((s->flags & SIG_FLAG_FLUSH) != 0));
349 
350  bool is_last = false;
351  if (flags & STREAM_TOSERVER) {
352  TcpStream *stream = &ssn->client;
354  is_last = true;
355  } else {
356  TcpStream *stream = &ssn->server;
358  is_last = true;
359  }
360 
361  SCLogDebug("%s ran stream for sid %u on packet %" PRIu64 " and we %s",
362  is_last ? "LAST:" : "normal:", s->id, PcapPacketCntGet(p),
363  match ? "matched" : "didn't match");
364 
365  if (match) {
367  } else {
368  if (is_last) {
369  //SCLogNotice("last, so DETECT_ENGINE_INSPECT_SIG_CANT_MATCH");
371  }
372  /* TODO maybe we can set 'CANT_MATCH' for EOF too? */
374  }
375 }
376 
377 #ifdef UNITTESTS
378 #include "detect-engine-alert.h"
379 
380 /** \test Not the first but the second occurrence of "abc" should be used
381  * for the 2nd match */
382 static int PayloadTestSig01 (void)
383 {
384  uint8_t *buf = (uint8_t *)
385  "abcabcd";
386  uint16_t buflen = strlen((char *)buf);
387  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
388 
389  FAIL_IF_NULL(p);
390 
391  char sig[] = "alert tcp any any -> any any (content:\"abc\"; content:\"d\"; distance:0; within:1; sid:1;)";
392 
394 
395  UTHFreePacket(p);
396 
397  PASS;
398 }
399 
400 /** \test Nocase matching */
401 static int PayloadTestSig02 (void)
402 {
403  uint8_t *buf = (uint8_t *)
404  "abcaBcd";
405  uint16_t buflen = strlen((char *)buf);
406  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
407 
408  FAIL_IF_NULL(p);
409 
410  char sig[] = "alert tcp any any -> any any (content:\"abc\"; nocase; content:\"d\"; distance:0; within:1; sid:1;)";
411 
413 
414  UTHFreePacket(p);
415 
416  PASS;
417 }
418 
419 /** \test Negative distance matching */
420 static int PayloadTestSig03 (void)
421 {
422  uint8_t *buf = (uint8_t *)
423  "abcaBcd";
424  uint16_t buflen = strlen((char *)buf);
425  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
426 
427  FAIL_IF_NULL(p);
428 
429  char sig[] = "alert tcp any any -> any any (content:\"aBc\"; nocase; content:\"abca\"; distance:-10; within:4; sid:1;)";
430 
432 
433  UTHFreePacket(p);
434 
435  PASS;
436 }
437 
438 /**
439  * \test Test multiple relative matches.
440  */
441 static int PayloadTestSig04(void)
442 {
443  uint8_t *buf = (uint8_t *)"now this is is big big string now";
444  uint16_t buflen = strlen((char *)buf);
445  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
446 
447  FAIL_IF_NULL(p);
448 
449  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
450  "content:\"this\"; content:\"is\"; within:6; content:\"big\"; within:8; "
451  "content:\"string\"; within:8; sid:1;)";
452 
454 
455  UTHFreePacket(p);
456 
457  PASS;
458 }
459 
460 /**
461  * \test Test multiple relative matches.
462  */
463 static int PayloadTestSig05(void)
464 {
465  uint8_t *buf = (uint8_t *)"now this is is is big big big string now";
466  uint16_t buflen = strlen((char *)buf);
467  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
468 
469  FAIL_IF_NULL(p);
470 
471  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
472  "content:\"this\"; content:\"is\"; within:9; content:\"big\"; within:12; "
473  "content:\"string\"; within:8; sid:1;)";
474 
476 
477  UTHFreePacket(p);
478 
479  PASS;
480 }
481 
482 /**
483  * \test Test multiple relative matches.
484  */
485 static int PayloadTestSig06(void)
486 {
487  uint8_t *buf = (uint8_t *)"this this now is is big string now";
488  uint16_t buflen = strlen((char *)buf);
489  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
490 
491  FAIL_IF_NULL(p);
492 
493  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
494  "content:\"now\"; content:\"this\"; content:\"is\"; within:12; content:\"big\"; within:8; "
495  "content:\"string\"; within:8; sid:1;)";
496 
498 
499  UTHFreePacket(p);
500 
501  PASS;
502 }
503 
504 /**
505  * \test Test multiple relative matches.
506  */
507 static int PayloadTestSig07(void)
508 {
509  uint8_t *buf = (uint8_t *)" thus thus is a big";
510  uint16_t buflen = strlen((char *)buf);
511  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
512 
513  FAIL_IF_NULL(p);
514 
515  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
516  "content:\"thus\"; offset:8; content:\"is\"; within:6; content:\"big\"; within:8; sid:1;)";
517 
519 
520  UTHFreePacket(p);
521 
522  PASS;
523 }
524 
525 /**
526  * \test Test multiple relative matches with negative matches
527  * and show the need for det_ctx->discontinue_matching.
528  */
529 static int PayloadTestSig08(void)
530 {
531  uint8_t *buf = (uint8_t *)"we need to fix this and yes fix this now";
532  uint16_t buflen = strlen((char *)buf);
533  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
534 
535  FAIL_IF_NULL(p);
536 
537  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
538  "content:\"fix\"; content:\"this\"; within:6; content:!\"and\"; distance:0; sid:1;)";
539 
541 
542  UTHFreePacket(p);
543 
544  PASS;
545 }
546 
547 /**
548  * \test Test pcre recursive matching.
549  */
550 static int PayloadTestSig09(void)
551 {
552  uint8_t *buf = (uint8_t *)"this is a super duper nova in super nova now";
553  uint16_t buflen = strlen((char *)buf);
554  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
555 
556  FAIL_IF_NULL(p);
557 
558  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
559  "pcre:/super/; content:\"nova\"; within:7; sid:1;)";
560 
562 
563  UTHFreePacket(p);
564 
565  PASS;
566 }
567 
568 /**
569  * \test Test invalid sig.
570  */
571 static int PayloadTestSig10(void)
572 {
573  uint8_t *buf = (uint8_t *)"this is a super duper nova in super nova now";
574  uint16_t buflen = strlen((char *)buf);
575  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
576 
577  FAIL_IF_NULL(p);
578 
579  char sig[] = "alert udp any any -> any any (msg:\"crash\"; "
580  "byte_test:4,>,2,0,relative; sid:11;)";
581 
583 
584  UTHFreePacket(p);
585 
586  PASS;
587 }
588 
589 /**
590  * \test Test invalid sig.
591  */
592 static int PayloadTestSig11(void)
593 {
594  uint8_t *buf = (uint8_t *)"this is a super duper nova in super nova now";
595  uint16_t buflen = strlen((char *)buf);
596  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
597 
598  FAIL_IF_NULL(p);
599 
600  char sig[] = "alert udp any any -> any any (msg:\"crash\"; "
601  "byte_jump:1,0,relative; sid:11;)";
602 
604 
605  UTHFreePacket(p);
606 
607  PASS;
608 }
609 
610 /**
611  * \test Test invalid sig.
612  */
613 static int PayloadTestSig12(void)
614 {
615  uint8_t *buf = (uint8_t *)"this is a super duper nova in super nova now";
616  uint16_t buflen = strlen((char *)buf);
617  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
618 
619  FAIL_IF_NULL(p);
620 
621  char sig[] = "alert udp any any -> any any (msg:\"crash\"; "
622  "isdataat:10,relative; sid:11;)";
623 
625 
626  UTHFreePacket(p);
627 
628  PASS;
629 }
630 
631 /**
632  * \test Used to check the working of recursion_limit counter.
633  */
634 static int PayloadTestSig13(void)
635 {
636  uint8_t *buf = (uint8_t *)"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
637  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
638  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
639  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
640  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
641  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
642  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
643  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
644  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
645  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
646  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
647  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
648  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
649  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
650  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
651  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
652  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
653  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
654  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
655  "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
656 
657  uint16_t buflen = strlen((char *)buf);
658  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
659  uint16_t mpm_type = mpm_default_matcher;
660 
661  FAIL_IF_NULL(p);
662 
663  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
664  "content:\"aa\"; content:\"aa\"; distance:0; content:\"aa\"; distance:0; "
665  "byte_test:1,>,200,0,relative; sid:1;)";
666 
670 
671  memset(&dtv, 0, sizeof(DecodeThreadVars));
672  memset(&th_v, 0, sizeof(th_v));
674 
678  de_ctx->flags |= DE_QUIET;
679  de_ctx->mpm_matcher = mpm_type;
680 
682  FAIL_IF_NULL(s);
683 
685  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
686 
689 
690  UTHFreePacket(p);
694  PASS;
695 }
696 
697 /**
698  * \test normal & negated matching, both absolute and relative
699  */
700 static int PayloadTestSig14(void)
701 {
702  uint8_t *buf = (uint8_t *)"User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b4) Gecko/20090423 Firefox/3.6 GTB5";
703  uint16_t buflen = strlen((char *)buf);
704  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
705 
706  FAIL_IF_NULL(p);
707 
708  char sig[] = "alert tcp any any -> any any (content:\"User-Agent|3A| Mozilla/5.0 |28|Macintosh|3B| \"; content:\"Firefox/3.\"; distance:0; content:!\"Firefox/3.6.12\"; distance:-10; content:!\"Mozilla/5.0 |28|Macintosh|3B| U|3B| Intel Mac OS X 10.5|3B| en-US|3B| rv|3A|1.9.1b4|29| Gecko/20090423 Firefox/3.6 GTB5\"; sid:1; rev:1;)";
709 
710  //char sig[] = "alert tcp any any -> any any (content:\"User-Agent: Mozilla/5.0 (Macintosh; \"; content:\"Firefox/3.\"; distance:0; content:!\"Firefox/3.6.12\"; distance:-10; content:!\"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b4) Gecko/20090423 Firefox/3.6 GTB5\"; sid:1; rev:1;)";
711 
713 
714  UTHFreePacket(p);
715 
716  PASS;
717 }
718 
719 static int PayloadTestSig15(void)
720 {
721  uint8_t *buf = (uint8_t *)"this is a super duper nova in super nova now";
722  uint16_t buflen = strlen((char *)buf);
723  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
724 
725  FAIL_IF_NULL(p);
726 
727  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
728  "content:\"nova\"; isdataat:18,relative; sid:1;)";
729 
731 
732  UTHFreePacket(p);
733 
734  PASS;
735 }
736 
737 static int PayloadTestSig16(void)
738 {
739  uint8_t *buf = (uint8_t *)"this is a super duper nova in super nova now";
740  uint16_t buflen = strlen((char *)buf);
741  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
742 
743  FAIL_IF_NULL(p);
744 
745  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
746  "content:\"nova\"; isdataat:!20,relative; sid:1;)";
747 
749 
750  UTHFreePacket(p);
751 
752  PASS;
753 }
754 
755 static int PayloadTestSig17(void)
756 {
757  uint8_t buf[] = { 0xEB, 0x29, 0x25, 0x38, 0x78, 0x25, 0x38, 0x78, 0x25 };
758  uint16_t buflen = 9;
759  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
760 
761  FAIL_IF_NULL(p);
762 
763  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
764  "content:\"%\"; depth:4; offset:0; "
765  "content:\"%\"; within:2; distance:1; sid:1;)";
766 
768 
769  UTHFreePacket(p);
770 
771  PASS;
772 }
773 
774 static int PayloadTestSig18(void)
775 {
776  uint8_t buf[] = {
777  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x35, /* the last byte is 2 */
778  0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
779  0x0E, 0x0F,
780  };
781  uint16_t buflen = sizeof(buf);
782  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
783 
784  FAIL_IF_NULL(p);
785 
786  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
787  "content:\"|01 02 03 04|\"; "
788  "byte_extract:1,2,one,string,dec,relative; "
789  "content:\"|0C 0D 0E 0F|\"; distance:one; sid:1;)";
790 
792 
793  UTHFreePacket(p);
794 
795  PASS;
796 }
797 
798 static int PayloadTestSig19(void)
799 {
800  uint8_t buf[] = {
801  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x35, /* the last byte is 2 */
802  0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
803  0x0E, 0x0F,
804  };
805  uint16_t buflen = sizeof(buf);
806  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
807 
808  FAIL_IF_NULL(p);
809 
810  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
811  "content:\"|01 02 03 04|\"; "
812  "byte_extract:1,2,one,string,hex,relative; "
813  "content:\"|0C 0D 0E 0F|\"; distance:one; sid:1;)";
814 
816 
817  UTHFreePacket(p);
818 
819  PASS;
820 }
821 
822 static int PayloadTestSig20(void)
823 {
824  uint8_t buf[] = {
825  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x35, /* the last byte is 2 */
826  0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
827  0x0E, 0x0F,
828  };
829  uint16_t buflen = sizeof(buf);
830  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
831 
832  FAIL_IF_NULL(p);
833 
834  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
835  "content:\"|01 02 03 04|\"; "
836  "byte_extract:1,2,one,string,dec,relative; "
837  "content:\"|06 35 07 08|\"; offset:one; sid:1;)";
838 
840 
841  UTHFreePacket(p);
842 
843  PASS;
844 }
845 
846 static int PayloadTestSig21(void)
847 {
848  uint8_t buf[] = {
849  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x36, /* the last byte is 2 */
850  0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
851  0x0E, 0x0F,
852  };
853  uint16_t buflen = sizeof(buf);
854  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
855 
856  FAIL_IF_NULL(p);
857 
858  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
859  "content:\"|01 02 03 04|\"; "
860  "byte_extract:1,2,one,string,dec,relative; "
861  "content:\"|03 04 05 06|\"; depth:one; sid:1;)";
862 
864 
865  UTHFreePacket(p);
866 
867  PASS;
868 }
869 
870 static int PayloadTestSig22(void)
871 {
872  uint8_t buf[] = {
873  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x36, /* the last byte is 2 */
874  0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
875  0x0E, 0x0F,
876  };
877  uint16_t buflen = sizeof(buf);
878  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
879 
880  FAIL_IF_NULL(p);
881 
882  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
883  "content:\"|01 02 03 04|\"; "
884  "byte_extract:1,2,one,string,dec,relative; "
885  "content:\"|09 0A 0B 0C|\"; within:one; sid:1;)";
886 
888 
889  UTHFreePacket(p);
890 
891  PASS;
892 }
893 
894 static int PayloadTestSig23(void)
895 {
896  uint8_t buf[] = {
897  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x32, /* the last byte is 2 */
898  0x07, 0x08, 0x09, 0x33, 0x0B, 0x0C, 0x0D,
899  0x32, 0x0F,
900  };
901  uint16_t buflen = sizeof(buf);
902  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
903 
904  FAIL_IF_NULL(p);
905 
906  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
907  "content:\"|01 02 03 04|\"; "
908  "byte_extract:1,2,one,string,dec,relative; "
909  "byte_extract:1,3,two,string,dec,relative; "
910  "byte_test:1,=,one,two,string,dec,relative; sid:1;)";
911 
913 
914  UTHFreePacket(p);
915 
916  PASS;
917 }
918 
919 static int PayloadTestSig24(void)
920 {
921  uint8_t buf[] = {
922  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x32, /* the last byte is 2 */
923  0x07, 0x08, 0x33, 0x0A, 0x0B, 0x0C, 0x0D,
924  0x0E, 0x0F,
925  };
926  uint16_t buflen = sizeof(buf);
927  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
928 
929  FAIL_IF_NULL(p);
930 
931  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
932  "content:\"|01 02 03 04|\"; "
933  "byte_extract:1,2,one,string,dec,relative; "
934  "byte_jump:1,one,string,dec,relative; "
935  "content:\"|0D 0E 0F|\"; distance:0; sid:1;)";
936 
938 
939  UTHFreePacket(p);
940 
941  PASS;
942 }
943 
944 /*
945  * \test Test negative byte extract.
946  */
947 static int PayloadTestSig25(void)
948 {
949  uint8_t buf[] = {
950  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x35, /* the last byte is 2 */
951  0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
952  0x0E, 0x0F,
953  };
954  uint16_t buflen = sizeof(buf);
955  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
956 
957  FAIL_IF_NULL(p);
958 
959  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
960  "content:\"|35 07 08 09|\"; "
961  "byte_extract:1,-4,one,string,dec,relative; "
962  "content:\"|0C 0D 0E 0F|\"; distance:one; sid:1;)";
963 
965 
966  UTHFreePacket(p);
967 
968  PASS;
969 }
970 
971 /*
972  * \test Test negative byte extract.
973  */
974 static int PayloadTestSig26(void)
975 {
976  uint8_t buf[] = {
977  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x35, /* the last byte is 2 */
978  0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
979  0x0E, 0x0F,
980  };
981  uint16_t buflen = sizeof(buf);
982  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
983 
984  FAIL_IF_NULL(p);
985 
986  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
987  "content:\"|35 07 08 09|\"; "
988  "byte_extract:1,-3000,one,string,dec,relative; "
989  "content:\"|0C 0D 0E 0F|\"; distance:one; sid:1;)";
990 
992 
993  UTHFreePacket(p);
994 
995  PASS;
996 }
997 
998 /*
999  * \test Test packet/stream sigs
1000  */
1001 static int PayloadTestSig27(void)
1002 {
1003  uint8_t buf[] = "dummypayload";
1004  uint16_t buflen = sizeof(buf) - 1;
1005  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
1006 
1007  FAIL_IF_NULL(p);
1008 
1009  char sig[] = "alert tcp any any -> any any (content:\"dummy\"; "
1010  "depth:5; sid:1;)";
1011 
1012  p->flags |= PKT_STREAM_ADD;
1014 
1015  UTHFreePacket(p);
1016 
1017  PASS;
1018 }
1019 
1020 /*
1021  * \test Test packet/stream sigs
1022  */
1023 static int PayloadTestSig28(void)
1024 {
1025  uint8_t buf[] = "dummypayload";
1026  uint16_t buflen = sizeof(buf) - 1;
1027  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
1028 
1029  FAIL_IF_NULL(p);
1030 
1031  char sig[] = "alert tcp any any -> any any (content:\"payload\"; "
1032  "offset:4; depth:12; sid:1;)";
1033 
1034  p->flags |= PKT_STREAM_ADD;
1036 
1037  UTHFreePacket(p);
1038 
1039  PASS;
1040 }
1041 
1042 /**
1043  * \test Test pcre recursive matching - bug #529
1044  */
1045 static int PayloadTestSig29(void)
1046 {
1047  uint8_t *buf = (uint8_t *)"this is a super dupernova in super nova now";
1048  uint16_t buflen = strlen((char *)buf);
1049  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
1050 
1051  FAIL_IF_NULL(p);
1052 
1053  char sig[] = "alert tcp any any -> any any (msg:\"dummy\"; "
1054  "pcre:/^.{4}/; content:\"nova\"; within:4; sid:1;)";
1055 
1057 
1058  UTHFreePacket(p);
1059 
1060  PASS;
1061 }
1062 
1063 static int PayloadTestSig30(void)
1064 {
1065  uint8_t *buf = (uint8_t *)
1066  "xyonexxxxxxtwojunkonetwo";
1067  uint16_t buflen = strlen((char *)buf);
1068  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
1069 
1070  FAIL_IF_NULL(p);
1071 
1072  char sig[] = "alert tcp any any -> any any (content:\"one\"; pcre:\"/^two/R\"; sid:1;)";
1073 
1075 
1076  UTHFreePacket(p);
1077 
1078  PASS;
1079 }
1080 
1081 static int PayloadTestSig31(void)
1082 {
1083  uint8_t *buf = (uint8_t *)
1084  "xyonexxxxxxtwojunkonetwo";
1085  uint16_t buflen = strlen((char *)buf);
1086  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
1087 
1088  FAIL_IF_NULL(p);
1089 
1090  char sig[] = "alert tcp any any -> any any (content:\"one\"; pcre:\"/(fiv|^two)/R\"; sid:1;)";
1091 
1093 
1094  UTHFreePacket(p);
1095 
1096  PASS;
1097 }
1098 
1099 /**
1100  * \test Test byte_jump.
1101  */
1102 static int PayloadTestSig32(void)
1103 {
1104  uint8_t *buf = (uint8_t *)"dummy2xxcardmessage";
1105  uint16_t buflen = strlen((char *)buf);
1106  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
1107 
1108  FAIL_IF_NULL(p);
1109 
1110  char sig[] = "alert tcp any any -> any any (msg:\"crash\"; "
1111  "content:\"message\"; byte_jump:2,-14,string,dec,relative; content:\"card\"; within:4; sid:1;)";
1112 
1114 
1115  UTHFreePacket(p);
1116 
1117  PASS;
1118 }
1119 
1120 /**
1121  * \test Test byte_test.
1122  */
1123 static int PayloadTestSig33(void)
1124 {
1125  uint8_t *buf = (uint8_t *)"dummy2xxcardmessage";
1126  uint16_t buflen = strlen((char *)buf);
1127  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
1128 
1129  FAIL_IF_NULL(p);
1130 
1131  char sig[] = "alert tcp any any -> any any (msg:\"crash\"; "
1132  "content:\"message\"; byte_test:1,=,2,-14,string,dec,relative; sid:1;)";
1133 
1135 
1136  UTHFreePacket(p);
1137 
1138  PASS;
1139 }
1140 
1141 /**
1142  * \test Test byte_extract.
1143  */
1144 static int PayloadTestSig34(void)
1145 {
1146  uint8_t *buf = (uint8_t *)"dummy2xxcardmessage";
1147  uint16_t buflen = strlen((char *)buf);
1148  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
1149 
1150  FAIL_IF_NULL(p);
1151 
1152  char sig[] = "alert tcp any any -> any any (msg:\"crash\"; "
1153  "content:\"message\"; byte_extract:1,-14,boom,string,dec,relative; sid:1;)";
1154 
1156 
1157  UTHFreePacket(p);
1158 
1159  PASS;
1160 }
1161 
1162 #endif /* UNITTESTS */
1163 
1165 {
1166 #ifdef UNITTESTS
1167  UtRegisterTest("PayloadTestSig01", PayloadTestSig01);
1168  UtRegisterTest("PayloadTestSig02", PayloadTestSig02);
1169  UtRegisterTest("PayloadTestSig03", PayloadTestSig03);
1170  UtRegisterTest("PayloadTestSig04", PayloadTestSig04);
1171  UtRegisterTest("PayloadTestSig05", PayloadTestSig05);
1172  UtRegisterTest("PayloadTestSig06", PayloadTestSig06);
1173  UtRegisterTest("PayloadTestSig07", PayloadTestSig07);
1174  UtRegisterTest("PayloadTestSig08", PayloadTestSig08);
1175  UtRegisterTest("PayloadTestSig09", PayloadTestSig09);
1176  UtRegisterTest("PayloadTestSig10", PayloadTestSig10);
1177  UtRegisterTest("PayloadTestSig11", PayloadTestSig11);
1178  UtRegisterTest("PayloadTestSig12", PayloadTestSig12);
1179  UtRegisterTest("PayloadTestSig13", PayloadTestSig13);
1180  UtRegisterTest("PayloadTestSig14", PayloadTestSig14);
1181  UtRegisterTest("PayloadTestSig15", PayloadTestSig15);
1182  UtRegisterTest("PayloadTestSig16", PayloadTestSig16);
1183  UtRegisterTest("PayloadTestSig17", PayloadTestSig17);
1184 
1185  UtRegisterTest("PayloadTestSig18", PayloadTestSig18);
1186  UtRegisterTest("PayloadTestSig19", PayloadTestSig19);
1187  UtRegisterTest("PayloadTestSig20", PayloadTestSig20);
1188  UtRegisterTest("PayloadTestSig21", PayloadTestSig21);
1189  UtRegisterTest("PayloadTestSig22", PayloadTestSig22);
1190  UtRegisterTest("PayloadTestSig23", PayloadTestSig23);
1191  UtRegisterTest("PayloadTestSig24", PayloadTestSig24);
1192  UtRegisterTest("PayloadTestSig25", PayloadTestSig25);
1193  UtRegisterTest("PayloadTestSig26", PayloadTestSig26);
1194  UtRegisterTest("PayloadTestSig27", PayloadTestSig27);
1195  UtRegisterTest("PayloadTestSig28", PayloadTestSig28);
1196  UtRegisterTest("PayloadTestSig29", PayloadTestSig29);
1197 
1198  UtRegisterTest("PayloadTestSig30", PayloadTestSig30);
1199  UtRegisterTest("PayloadTestSig31", PayloadTestSig31);
1200  UtRegisterTest("PayloadTestSig32", PayloadTestSig32);
1201  UtRegisterTest("PayloadTestSig33", PayloadTestSig33);
1202  UtRegisterTest("PayloadTestSig34", PayloadTestSig34);
1203 #endif /* UNITTESTS */
1204 }
DetectEngineAppInspectionEngine_
Definition: detect.h:420
Packet_::proto
uint8_t proto
Definition: decode.h:538
TcpStream_
Definition: stream-tcp-private.h:106
DETECT_ENGINE_CONTENT_INSPECTION_MODE_STREAM
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_STREAM
Definition: detect-engine-content-inspection.h:34
MpmCtx_::mpm_type
uint8_t mpm_type
Definition: util-mpm.h:113
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:120
StreamContentInspectEngineData::de_ctx
DetectEngineCtx * de_ctx
Definition: detect-engine-payload.c:288
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
StreamReassembleRaw
int StreamReassembleRaw(TcpSession *ssn, const Packet *p, StreamReassembleRawFunc Callback, void *cb_data, uint64_t *progress_out, bool respect_inspect_depth)
Definition: stream-tcp-reassemble.c:1912
stream-tcp.h
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1730
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:101
PcapPacketCntGet
uint64_t PcapPacketCntGet(const Packet *p)
Definition: decode.c:1193
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
Packet_::payload
uint8_t * payload
Definition: decode.h:620
PacketAlertCheck
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
Definition: detect-engine-alert.c:144
Packet_::flags
uint32_t flags
Definition: decode.h:562
ssn
TcpSession ssn
Definition: fuzz_dataset.c:31
Flow_
Flow data structure.
Definition: flow.h:359
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1429
ctx
struct Thresholds ctx
DetectEngineCtx_::inspection_recursion_limit
int inspection_recursion_limit
Definition: detect.h:1040
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:995
UTHPacketMatchSigMpm
int UTHPacketMatchSigMpm(Packet *p, char *sig, uint16_t mpm_type)
Definition: util-unittest-helper.c:768
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2912
DetectEngineThreadCtx_::p
Packet * p
Definition: detect.h:1396
DetectEngineInspectPacketPayload
uint8_t DetectEngineInspectPacketPayload(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p)
Do the content inspection & validation for a signature.
Definition: detect-engine-payload.c:177
rust.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:334
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:241
TcpStream_::flags
uint16_t flags
Definition: stream-tcp-private.h:107
mpm_default_matcher
uint8_t mpm_default_matcher
Definition: util-mpm.c:47
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:3305
p
Packet * p
Definition: fuzz_dataset.c:30
Signature_::sm_arrays
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
Definition: detect.h:759
PKT_NOPAYLOAD_INSPECTION
#define PKT_NOPAYLOAD_INSPECTION
Definition: decode.h:1297
detect-engine-payload.h
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3971
Flow_::protoctx
void * protoctx
Definition: flow.h:438
SigMatchData_
Data needed for Match()
Definition: detect.h:369
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:621
STREAMTCP_STREAM_FLAG_DEPTH_REACHED
#define STREAMTCP_STREAM_FLAG_DEPTH_REACHED
Definition: stream-tcp-private.h:223
DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD
Definition: detect-engine-content-inspection.h:32
detect-engine-prefilter.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
StreamMpmData::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-engine-payload.c:54
decode.h
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
DetectEngineThreadCtx_
Definition: detect.h:1316
StreamContentInspectData::de_ctx
DetectEngineCtx * de_ctx
Definition: detect-engine-payload.c:234
PKT_STREAM_ADD
#define PKT_STREAM_ADD
Definition: decode.h:1305
PrefilterPktStreamRegisterNoMpm
int PrefilterPktStreamRegisterNoMpm(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx)
Definition: detect-engine-payload.c:135
StreamMpmData::det_ctx
DetectEngineThreadCtx * det_ctx
Definition: detect-engine-payload.c:53
SIG_FLAG_FLUSH
#define SIG_FLAG_FLUSH
Definition: detect.h:262
DetectEngineInspectStreamPayload
int DetectEngineInspectStreamPayload(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p)
Do the content inspection & validation for a signature on the raw stream.
Definition: detect-engine-payload.c:273
util-print.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:284
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
StreamContentInspectEngineData::s
const Signature * s
Definition: detect-engine-payload.c:290
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
Definition: detect-engine.c:3660
DETECT_ENGINE_INSPECT_SIG_MATCH
#define DETECT_ENGINE_INSPECT_SIG_MATCH
Definition: detect-engine-state.h:41
PKT_DETECT_HAS_STREAMDATA
#define PKT_DETECT_HAS_STREAMDATA
Definition: decode.h:1350
DetectEngineCtx_::mpm_matcher
uint8_t mpm_matcher
Definition: detect.h:998
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:122
DetectEngineContentInspection
bool DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Packet *p, Flow *f, const uint8_t *buffer, const uint32_t buffer_len, const uint64_t stream_start_offset, const uint8_t flags, const enum DetectContentInspectionType inspection_mode)
wrapper around DetectEngineContentInspectionInternal to return true/false only
Definition: detect-engine-content-inspection.c:750
util-profiling.h
DetectEngineThreadCtx_::raw_stream_progress
uint64_t raw_stream_progress
Definition: detect.h:1337
DetectEngineInspectStream
uint8_t DetectEngineInspectStream(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
inspect engine for stateful rules
Definition: detect-engine-payload.c:323
SCReturn
#define SCReturn
Definition: util-debug.h:286
Signature_::flags
uint32_t flags
Definition: detect.h:693
stream.h
Packet_
Definition: decode.h:516
detect-engine-build.h
detect-engine-alert.h
PrefilterPktPayloadRegister
int PrefilterPktPayloadRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx)
Definition: detect-engine-payload.c:157
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
util-mpm-ac.h
MpmTableElmt_::Search
uint32_t(* Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint32_t)
Definition: util-mpm.h:200
DETECT_ENGINE_INSPECT_SIG_CANT_MATCH
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH
Definition: detect-engine-state.h:42
DetectEngineThreadCtx_::mtc
MpmThreadCtx mtc
Definition: detect.h:1425
StreamContentInspectData::det_ctx
DetectEngineThreadCtx * det_ctx
Definition: detect-engine-payload.c:235
StreamContentInspectData::f
Flow * f
Definition: detect-engine-payload.c:237
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2300
PrefilterAppendPayloadEngine
int PrefilterAppendPayloadEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterPktFn PrefilterFunc, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
Definition: detect-engine-prefilter.c:349
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:35
StatsThreadInit
void StatsThreadInit(StatsThreadContext *stats)
Definition: counters.c:1332
detect-engine-content-inspection.h
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:444
th_v
ThreadVars * th_v
Definition: fuzz_dataset.c:29
PREFILTER_PROFILING_ADD_BYTES
#define PREFILTER_PROFILING_ADD_BYTES(det_ctx, bytes)
Definition: util-profiling.h:286
Packet_::flow
struct Flow_ * flow
Definition: decode.h:564
StreamMpmData
Definition: detect-engine-payload.c:52
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
DETECT_CI_FLAGS_SINGLE
#define DETECT_CI_FLAGS_SINGLE
Definition: detect-engine-content-inspection.h:50
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
Definition: detect-engine.c:3905
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:1005
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:297
DETECT_ENGINE_INSPECT_SIG_NO_MATCH
#define DETECT_ENGINE_INSPECT_SIG_NO_MATCH
Definition: detect-engine-state.h:40
util-validate.h
StreamContentInspectEngineData
Definition: detect-engine-payload.c:287
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:296
StreamContentInspectData
Definition: detect-engine-payload.c:233
SCFree
#define SCFree(p)
Definition: util-mem.h:61
StreamContentInspectEngineData::f
Flow * f
Definition: detect-engine-payload.c:292
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:995
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:470
Signature_::id
uint32_t id
Definition: detect.h:741
StreamContentInspectEngineData::det_ctx
DetectEngineThreadCtx * det_ctx
Definition: detect-engine-payload.c:289
detect-parse.h
Signature_
Signature container.
Definition: detect.h:692
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2873
mpm_table
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.c:46
suricata.h
StreamContentInspectData::s
const Signature * s
Definition: detect-engine-payload.c:236
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:997
MpmCtx_
Definition: util-mpm.h:111
TcpSession_
Definition: stream-tcp-private.h:283
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:120
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:288
StatsThreadCleanup
void StatsThreadCleanup(StatsThreadContext *stats)
Definition: counters.c:1428
PrefilterPktStreamRegister
int PrefilterPktStreamRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx)
Definition: detect-engine-payload.c:123
StreamContentInspectEngineData::smd
const SigMatchData * smd
Definition: detect-engine-payload.c:291
PayloadRegisterTests
void PayloadRegisterTests(void)
Definition: detect-engine-payload.c:1164
f
Flow f
Definition: fuzz_dataset.c:32