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