suricata
detect-engine-content-inspection.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2017 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 Anoop Saldanha <anoopsaldanha@gmail.com>
22  *
23  * Performs content inspection on any buffer supplied.
24  */
25 
26 #include "suricata-common.h"
27 #include "suricata.h"
28 
29 #include "decode.h"
30 
31 #include "detect.h"
32 #include "detect-engine.h"
33 #include "detect-parse.h"
34 #include "detect-content.h"
35 #include "detect-pcre.h"
36 #include "detect-isdataat.h"
37 #include "detect-bytetest.h"
38 #include "detect-bytejump.h"
39 #include "detect-byte-extract.h"
40 #include "detect-replace.h"
42 #include "detect-uricontent.h"
43 #include "detect-urilen.h"
44 #include "detect-bsize.h"
45 #include "detect-lua.h"
46 #include "detect-base64-decode.h"
47 #include "detect-base64-data.h"
48 #include "detect-dataset.h"
49 #include "detect-datarep.h"
50 
51 #include "app-layer-dcerpc.h"
52 
53 #include "util-spm.h"
54 #include "util-debug.h"
55 #include "util-print.h"
56 
57 #include "util-unittest.h"
58 #include "util-unittest-helper.h"
59 #include "util-profiling.h"
60 
61 #ifdef HAVE_LUA
62 #include "util-lua.h"
63 #endif
64 
65 /**
66  * \brief Run the actual payload match functions
67  *
68  * The following keywords are inspected:
69  * - content, including all the http and dce modified contents
70  * - isdaatat
71  * - pcre
72  * - bytejump
73  * - bytetest
74  * - byte_extract
75  * - urilen
76  * -
77  *
78  * All keywords are evaluated against the buffer with buffer_len.
79  *
80  * For accounting the last match in relative matching the
81  * det_ctx->buffer_offset int is used.
82  *
83  * \param de_ctx Detection engine context
84  * \param det_ctx Detection engine thread context
85  * \param s Signature to inspect
86  * \param sm SigMatch to inspect
87  * \param p Packet. Can be NULL.
88  * \param f Flow (for pcre flowvar storage)
89  * \param buffer Ptr to the buffer to inspect
90  * \param buffer_len Length of the payload
91  * \param stream_start_offset Indicates the start of the current buffer in
92  * the whole buffer stream inspected. This
93  * applies if the current buffer is inspected
94  * in chunks.
95  * \param inspection_mode Refers to the engine inspection mode we are currently
96  * inspecting. Can be payload, stream, one of the http
97  * buffer inspection modes or dce inspection mode.
98  * \param flags DETECT_CI_FLAG_*
99  *
100  * \retval 0 no match
101  * \retval 1 match
102  */
104  const Signature *s, const SigMatchData *smd,
105  Packet *p, Flow *f,
106  const uint8_t *buffer, uint32_t buffer_len,
107  uint32_t stream_start_offset, uint8_t flags,
108  uint8_t inspection_mode)
109 {
110  SCEnter();
112 
113  det_ctx->inspection_recursion_counter++;
114 
116  det_ctx->discontinue_matching = 1;
117  KEYWORD_PROFILING_END(det_ctx, smd->type, 0);
118  SCReturnInt(0);
119  }
120 
121  if (smd == NULL || buffer_len == 0) {
122  KEYWORD_PROFILING_END(det_ctx, smd->type, 0);
123  SCReturnInt(0);
124  }
125 
126  /* \todo unify this which is phase 2 of payload inspection unification */
127  if (smd->type == DETECT_CONTENT) {
128 
130  SCLogDebug("inspecting content %"PRIu32" buffer_len %"PRIu32, cd->id, buffer_len);
131 
132  /* we might have already have this content matched by the mpm.
133  * (if there is any other reason why we'd want to avoid checking
134  * it here, please fill it in) */
135  //if (cd->flags & DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED) {
136  // goto match;
137  //}
138 
139  /* rule parsers should take care of this */
140 #ifdef DEBUG
141  BUG_ON(cd->depth != 0 && cd->depth <= cd->offset);
142 #endif
143 
144  /* search for our pattern, checking the matches recursively.
145  * if we match we look for the next SigMatch as well */
146  const uint8_t *found = NULL;
147  uint32_t offset = 0;
148  uint32_t depth = buffer_len;
149  uint32_t prev_offset = 0; /**< used in recursive searching */
150  uint32_t prev_buffer_offset = det_ctx->buffer_offset;
151 
152  do {
153  if ((cd->flags & DETECT_CONTENT_DISTANCE) ||
154  (cd->flags & DETECT_CONTENT_WITHIN)) {
155  SCLogDebug("det_ctx->buffer_offset %"PRIu32, det_ctx->buffer_offset);
156 
157  offset = prev_buffer_offset;
158  depth = buffer_len;
159 
160  int distance = cd->distance;
161  if (cd->flags & DETECT_CONTENT_DISTANCE) {
162  if (cd->flags & DETECT_CONTENT_DISTANCE_BE) {
163  distance = det_ctx->bj_values[cd->distance];
164  }
165  if (distance < 0 && (uint32_t)(abs(distance)) > offset)
166  offset = 0;
167  else
168  offset += distance;
169 
170  SCLogDebug("cd->distance %"PRIi32", offset %"PRIu32", depth %"PRIu32,
171  distance, offset, depth);
172  }
173 
174  if (cd->flags & DETECT_CONTENT_WITHIN) {
175  if (cd->flags & DETECT_CONTENT_WITHIN_BE) {
176  if ((int32_t)depth > (int32_t)(prev_buffer_offset + det_ctx->bj_values[cd->within] + distance)) {
177  depth = prev_buffer_offset + det_ctx->bj_values[cd->within] + distance;
178  }
179  } else {
180  if ((int32_t)depth > (int32_t)(prev_buffer_offset + cd->within + distance)) {
181  depth = prev_buffer_offset + cd->within + distance;
182  }
183 
184  SCLogDebug("cd->within %"PRIi32", det_ctx->buffer_offset %"PRIu32", depth %"PRIu32,
185  cd->within, prev_buffer_offset, depth);
186  }
187 
188  if (stream_start_offset != 0 && prev_buffer_offset == 0) {
189  if (depth <= stream_start_offset) {
190  goto no_match;
191  } else if (depth >= (stream_start_offset + buffer_len)) {
192  ;
193  } else {
194  depth = depth - stream_start_offset;
195  }
196  }
197  }
198 
199  if (cd->flags & DETECT_CONTENT_DEPTH_BE) {
200  if ((det_ctx->bj_values[cd->depth] + prev_buffer_offset) < depth) {
201  depth = prev_buffer_offset + det_ctx->bj_values[cd->depth];
202  }
203  } else {
204  if (cd->depth != 0) {
205  if ((cd->depth + prev_buffer_offset) < depth) {
206  depth = prev_buffer_offset + cd->depth;
207  }
208 
209  SCLogDebug("cd->depth %"PRIu32", depth %"PRIu32, cd->depth, depth);
210  }
211  }
212 
213  if (cd->flags & DETECT_CONTENT_OFFSET_BE) {
214  if (det_ctx->bj_values[cd->offset] > offset)
215  offset = det_ctx->bj_values[cd->offset];
216  } else {
217  if (cd->offset > offset) {
218  offset = cd->offset;
219  SCLogDebug("setting offset %"PRIu32, offset);
220  }
221  }
222  } else { /* implied no relative matches */
223  /* set depth */
224  if (cd->flags & DETECT_CONTENT_DEPTH_BE) {
225  depth = det_ctx->bj_values[cd->depth];
226  } else {
227  if (cd->depth != 0) {
228  depth = cd->depth;
229  }
230  }
231 
232  if (stream_start_offset != 0 && cd->flags & DETECT_CONTENT_DEPTH) {
233  if (depth <= stream_start_offset) {
234  goto no_match;
235  } else if (depth >= (stream_start_offset + buffer_len)) {
236  ;
237  } else {
238  depth = depth - stream_start_offset;
239  }
240  }
241 
242  /* set offset */
244  offset = det_ctx->bj_values[cd->offset];
245  else
246  offset = cd->offset;
247  prev_buffer_offset = 0;
248  }
249 
250  /* If the value came from a variable, make sure to adjust the depth so it's relative
251  * to the offset value.
252  */
254  depth += offset;
255  }
256 
257  /* update offset with prev_offset if we're searching for
258  * matches after the first occurrence. */
259  SCLogDebug("offset %"PRIu32", prev_offset %"PRIu32, offset, prev_offset);
260  if (prev_offset != 0)
261  offset = prev_offset;
262 
263  SCLogDebug("offset %"PRIu32", depth %"PRIu32, offset, depth);
264 
265  if (depth > buffer_len)
266  depth = buffer_len;
267 
268  /* if offset is bigger than depth we can never match on a pattern.
269  * We can however, "match" on a negated pattern. */
270  if (offset > depth || depth == 0) {
271  if (cd->flags & DETECT_CONTENT_NEGATED) {
272  goto match;
273  } else {
274  goto no_match;
275  }
276  }
277 
278  const uint8_t *sbuffer = buffer + offset;
279  uint32_t sbuffer_len = depth - offset;
280  uint32_t match_offset = 0;
281  SCLogDebug("sbuffer_len %"PRIu32, sbuffer_len);
282 #ifdef DEBUG
283  BUG_ON(sbuffer_len > buffer_len);
284 #endif
285  if (cd->flags & DETECT_CONTENT_ENDS_WITH && depth < buffer_len) {
286  SCLogDebug("depth < buffer_len while DETECT_CONTENT_ENDS_WITH is set. Can't possibly match.");
287  found = NULL;
288  } else if (cd->content_len > sbuffer_len) {
289  found = NULL;
290  } else {
291  /* do the actual search */
292  found = SpmScan(cd->spm_ctx, det_ctx->spm_thread_ctx, sbuffer,
293  sbuffer_len);
294  }
295 
296  /* next we evaluate the result in combination with the
297  * negation flag. */
298  SCLogDebug("found %p cd negated %s", found, cd->flags & DETECT_CONTENT_NEGATED ? "true" : "false");
299 
300  if (found == NULL && !(cd->flags & DETECT_CONTENT_NEGATED)) {
302  /* independent match from previous matches, so failure is fatal */
303  det_ctx->discontinue_matching = 1;
304  }
305 
306  goto no_match;
307  } else if (found == NULL && (cd->flags & DETECT_CONTENT_NEGATED)) {
308  goto match;
309  } else if (found != NULL && (cd->flags & DETECT_CONTENT_NEGATED)) {
310  SCLogDebug("content %"PRIu32" matched at offset %"PRIu32", but negated so no match", cd->id, match_offset);
311  /* don't bother carrying recursive matches now, for preceding
312  * relative keywords */
313  if (DETECT_CONTENT_IS_SINGLE(cd))
314  det_ctx->discontinue_matching = 1;
315  goto no_match;
316  } else {
317  match_offset = (uint32_t)((found - buffer) + cd->content_len);
318  SCLogDebug("content %"PRIu32" matched at offset %"PRIu32"", cd->id, match_offset);
319  det_ctx->buffer_offset = match_offset;
320 
321  if ((cd->flags & DETECT_CONTENT_ENDS_WITH) == 0 || match_offset == buffer_len) {
322  /* Match branch, add replace to the list if needed */
323  if (cd->flags & DETECT_CONTENT_REPLACE) {
324  if (inspection_mode == DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD) {
325  /* we will need to replace content if match is confirmed
326  * cast to non-const as replace writes to it. */
327  det_ctx->replist = DetectReplaceAddToList(det_ctx->replist, (uint8_t *)found, cd);
328  } else {
329  SCLogWarning(SC_ERR_INVALID_VALUE, "Can't modify payload without packet");
330  }
331  }
332 
333  /* if this is the last match we're done */
334  if (smd->is_last) {
335  goto match;
336  }
337 
338  SCLogDebug("content %"PRIu32, cd->id);
339  KEYWORD_PROFILING_END(det_ctx, smd->type, 1);
340 
341  /* see if the next buffer keywords match. If not, we will
342  * search for another occurrence of this content and see
343  * if the others match then until we run out of matches */
344  int r = DetectEngineContentInspection(de_ctx, det_ctx, s, smd+1,
345  p, f, buffer, buffer_len, stream_start_offset, flags,
346  inspection_mode);
347  if (r == 1) {
348  SCReturnInt(1);
349  }
350  SCLogDebug("no match for 'next sm'");
351 
352  if (det_ctx->discontinue_matching) {
353  SCLogDebug("'next sm' said to discontinue this right now");
354  goto no_match;
355  }
356 
357  /* no match and no reason to look for another instance */
358  if ((cd->flags & DETECT_CONTENT_WITHIN_NEXT) == 0) {
359  SCLogDebug("'next sm' does not depend on me, so we can give up");
360  det_ctx->discontinue_matching = 1;
361  goto no_match;
362  }
363 
364  SCLogDebug("'next sm' depends on me %p, lets see what we can do (flags %u)", cd, cd->flags);
365  }
366  /* set the previous match offset to the start of this match + 1 */
367  prev_offset = (match_offset - (cd->content_len - 1));
368  SCLogDebug("trying to see if there is another match after prev_offset %"PRIu32, prev_offset);
369  }
370 
371  } while(1);
372 
373  } else if (smd->type == DETECT_ISDATAAT) {
374  SCLogDebug("inspecting isdataat");
375 
376  const DetectIsdataatData *id = (DetectIsdataatData *)smd->ctx;
377  uint32_t dataat = id->dataat;
378  if (id->flags & ISDATAAT_OFFSET_BE) {
379  uint64_t be_value = det_ctx->bj_values[dataat];
380  if (be_value >= 100000000) {
381  if ((id->flags & ISDATAAT_NEGATED) == 0) {
382  SCLogDebug("extracted value %"PRIu64" very big: no match", be_value);
383  goto no_match;
384  }
385  SCLogDebug("extracted value way %"PRIu64" very big: match", be_value);
386  goto match;
387  }
388  dataat = (uint32_t)be_value;
389  SCLogDebug("isdataat: using value %u from byte_extract local_id %u", dataat, id->dataat);
390  }
391 
392  if (id->flags & ISDATAAT_RELATIVE) {
393  if (det_ctx->buffer_offset + dataat > buffer_len) {
394  SCLogDebug("det_ctx->buffer_offset + dataat %"PRIu32" > %"PRIu32, det_ctx->buffer_offset + dataat, buffer_len);
395  if (id->flags & ISDATAAT_NEGATED)
396  goto match;
397  goto no_match;
398  } else {
399  SCLogDebug("relative isdataat match");
400  if (id->flags & ISDATAAT_NEGATED)
401  goto no_match;
402  goto match;
403  }
404  } else {
405  if (dataat < buffer_len) {
406  SCLogDebug("absolute isdataat match");
407  if (id->flags & ISDATAAT_NEGATED)
408  goto no_match;
409  goto match;
410  } else {
411  SCLogDebug("absolute isdataat mismatch, id->isdataat %"PRIu32", buffer_len %"PRIu32"", dataat, buffer_len);
412  if (id->flags & ISDATAAT_NEGATED)
413  goto match;
414  goto no_match;
415  }
416  }
417 
418  } else if (smd->type == DETECT_PCRE) {
419  SCLogDebug("inspecting pcre");
420  DetectPcreData *pe = (DetectPcreData *)smd->ctx;
421  uint32_t prev_buffer_offset = det_ctx->buffer_offset;
422  uint32_t prev_offset = 0;
423  int r = 0;
424 
425  det_ctx->pcre_match_start_offset = 0;
426  do {
427  r = DetectPcrePayloadMatch(det_ctx, s, smd, p, f,
428  buffer, buffer_len);
429  if (r == 0) {
430  goto no_match;
431  }
432 
433  if (!(pe->flags & DETECT_PCRE_RELATIVE_NEXT)) {
434  SCLogDebug("no relative match coming up, so this is a match");
435  goto match;
436  }
437  KEYWORD_PROFILING_END(det_ctx, smd->type, 1);
438 
439  /* save it, in case we need to do a pcre match once again */
440  prev_offset = det_ctx->pcre_match_start_offset;
441 
442  /* see if the next payload keywords match. If not, we will
443  * search for another occurrence of this pcre and see
444  * if the others match, until we run out of matches */
445  r = DetectEngineContentInspection(de_ctx, det_ctx, s, smd+1,
446  p, f, buffer, buffer_len, stream_start_offset, flags,
447  inspection_mode);
448  if (r == 1) {
449  SCReturnInt(1);
450  }
451 
452  if (det_ctx->discontinue_matching)
453  goto no_match;
454 
455  det_ctx->buffer_offset = prev_buffer_offset;
456  det_ctx->pcre_match_start_offset = prev_offset;
457  } while (1);
458 
459  } else if (smd->type == DETECT_BYTETEST) {
460  DetectBytetestData *btd = (DetectBytetestData *)smd->ctx;
461  uint8_t btflags = btd->flags;
462  int32_t offset = btd->offset;
463  uint64_t value = btd->value;
464  if (btflags & DETECT_BYTETEST_OFFSET_BE) {
465  offset = det_ctx->bj_values[offset];
466  }
467  if (btflags & DETECT_BYTETEST_VALUE_BE) {
468  value = det_ctx->bj_values[value];
469  }
470 
471  /* if we have dce enabled we will have to use the endianness
472  * specified by the dce header */
473  if (btflags & DETECT_BYTETEST_DCE) {
474  /* enable the endianness flag temporarily. once we are done
475  * processing we reset the flags to the original value*/
476  btflags |= ((flags & DETECT_CI_FLAGS_DCE_LE) ?
478  }
479 
480  if (DetectBytetestDoMatch(det_ctx, s, smd->ctx, buffer, buffer_len, btflags,
481  offset, value) != 1) {
482  goto no_match;
483  }
484 
485  goto match;
486 
487  } else if (smd->type == DETECT_BYTEJUMP) {
488  DetectBytejumpData *bjd = (DetectBytejumpData *)smd->ctx;
489  uint8_t bjflags = bjd->flags;
490  int32_t offset = bjd->offset;
491 
492  if (bjflags & DETECT_BYTEJUMP_OFFSET_BE) {
493  offset = det_ctx->bj_values[offset];
494  }
495 
496  /* if we have dce enabled we will have to use the endianness
497  * specified by the dce header */
498  if (bjflags & DETECT_BYTEJUMP_DCE) {
499  /* enable the endianness flag temporarily. once we are done
500  * processing we reset the flags to the original value*/
501  bjflags |= ((flags & DETECT_CI_FLAGS_DCE_LE) ?
503  }
504 
505  if (DetectBytejumpDoMatch(det_ctx, s, smd->ctx, buffer, buffer_len,
506  bjflags, offset) != 1) {
507  goto no_match;
508  }
509 
510  goto match;
511 
512  } else if (smd->type == DETECT_BYTE_EXTRACT) {
513 
514  DetectByteExtractData *bed = (DetectByteExtractData *)smd->ctx;
515  uint8_t endian = bed->endian;
516 
517  /* if we have dce enabled we will have to use the endianness
518  * specified by the dce header */
519  if ((bed->flags & DETECT_BYTE_EXTRACT_FLAG_ENDIAN) &&
520  endian == DETECT_BYTE_EXTRACT_ENDIAN_DCE &&
522 
523  /* enable the endianness flag temporarily. once we are done
524  * processing we reset the flags to the original value*/
525  endian |= ((flags & DETECT_CI_FLAGS_DCE_LE) ?
527  }
528 
529  if (DetectByteExtractDoMatch(det_ctx, smd, s, buffer,
530  buffer_len,
531  &det_ctx->bj_values[bed->local_id],
532  endian) != 1) {
533  goto no_match;
534  }
535 
536  goto match;
537 
538  } else if (smd->type == DETECT_BSIZE) {
539 
540  bool eof = (flags & DETECT_CI_FLAGS_END);
541  const uint64_t data_size = buffer_len + stream_start_offset;
542  int r = DetectBsizeMatch(smd->ctx, data_size, eof);
543  if (r < 0) {
544  det_ctx->discontinue_matching = 1;
545  goto no_match;
546 
547  } else if (r == 0) {
548  goto no_match;
549  }
550  goto match;
551 
552  } else if (smd->type == DETECT_DATASET) {
553 
554  //PrintRawDataFp(stdout, buffer, buffer_len);
555  const DetectDatasetData *sd = (const DetectDatasetData *) smd->ctx;
556  int r = DetectDatasetBufferMatch(det_ctx, sd, buffer, buffer_len); //TODO buffer offset?
557  if (r == 1) {
558  goto match;
559  }
560  det_ctx->discontinue_matching = 1;
561  goto no_match;
562 
563  } else if (smd->type == DETECT_DATAREP) {
564 
565  //PrintRawDataFp(stdout, buffer, buffer_len);
566  const DetectDatarepData *sd = (const DetectDatarepData *) smd->ctx;
567  int r = DetectDatarepBufferMatch(det_ctx, sd, buffer, buffer_len); //TODO buffer offset?
568  if (r == 1) {
569  goto match;
570  }
571  det_ctx->discontinue_matching = 1;
572  goto no_match;
573 
574  } else if (smd->type == DETECT_AL_URILEN) {
575  SCLogDebug("inspecting uri len");
576 
577  int r = 0;
578  DetectUrilenData *urilend = (DetectUrilenData *) smd->ctx;
579 
580  switch (urilend->mode) {
581  case DETECT_URILEN_EQ:
582  if (buffer_len == urilend->urilen1)
583  r = 1;
584  break;
585  case DETECT_URILEN_LT:
586  if (buffer_len < urilend->urilen1)
587  r = 1;
588  break;
589  case DETECT_URILEN_GT:
590  if (buffer_len > urilend->urilen1)
591  r = 1;
592  break;
593  case DETECT_URILEN_RA:
594  if (buffer_len > urilend->urilen1 &&
595  buffer_len < urilend->urilen2) {
596  r = 1;
597  }
598  break;
599  }
600 
601  if (r == 1) {
602  goto match;
603  }
604 
605  det_ctx->discontinue_matching = 0;
606 
607  goto no_match;
608 #ifdef HAVE_LUA
609  }
610  else if (smd->type == DETECT_LUA) {
611  SCLogDebug("lua starting");
612 
613  if (DetectLuaMatchBuffer(det_ctx, s, smd, buffer, buffer_len,
614  det_ctx->buffer_offset, f) != 1)
615  {
616  SCLogDebug("lua no_match");
617  goto no_match;
618  }
619  SCLogDebug("lua match");
620  goto match;
621 #endif /* HAVE_LUA */
622  } else if (smd->type == DETECT_BASE64_DECODE) {
623  if (DetectBase64DecodeDoMatch(det_ctx, s, smd, buffer, buffer_len)) {
624  if (s->sm_arrays[DETECT_SM_LIST_BASE64_DATA] != NULL) {
625  KEYWORD_PROFILING_END(det_ctx, smd->type, 1);
626  if (DetectBase64DataDoMatch(de_ctx, det_ctx, s, f)) {
627  /* Base64 is a terminal list. */
628  goto final_match;
629  }
630  }
631  }
632  } else {
633  SCLogDebug("sm->type %u", smd->type);
634 #ifdef DEBUG
635  BUG_ON(1);
636 #endif
637  }
638 
639 no_match:
640  KEYWORD_PROFILING_END(det_ctx, smd->type, 0);
641  SCReturnInt(0);
642 
643 match:
644  /* this sigmatch matched, inspect the next one. If it was the last,
645  * the buffer portion of the signature matched. */
646  if (!smd->is_last) {
647  KEYWORD_PROFILING_END(det_ctx, smd->type, 1);
648  int r = DetectEngineContentInspection(de_ctx, det_ctx, s, smd+1,
649  p, f, buffer, buffer_len, stream_start_offset, flags,
650  inspection_mode);
651  SCReturnInt(r);
652  }
653 final_match:
654  KEYWORD_PROFILING_END(det_ctx, smd->type, 1);
655  SCReturnInt(1);
656 }
657 
658 #ifdef UNITTESTS
660 #endif
#define ISDATAAT_OFFSET_BE
uint16_t flags
#define SCLogDebug(...)
Definition: util-debug.h:335
#define DETECT_BYTETEST_LITTLE
#define KEYWORD_PROFILING_END(ctx, type, m)
#define BUG_ON(x)
uint16_t discontinue_matching
Definition: detect.h:1067
#define DETECT_CI_FLAGS_DCE_LE
uint64_t * bj_values
Definition: detect.h:1112
uint8_t is_last
Definition: detect.h:329
int DetectBase64DecodeDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, const uint8_t *payload, uint32_t payload_len)
uint64_t offset
DetectReplaceList * replist
Definition: detect.h:1115
Data needed for Match()
Definition: detect.h:327
#define DETECT_CONTENT_DISTANCE_BE
#define ISDATAAT_RELATIVE
#define DETECT_BYTEJUMP_LITTLE
#define DETECT_CONTENT_DISTANCE
int DetectLuaMatchBuffer(DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, const uint8_t *buffer, uint32_t buffer_len, uint32_t offset, Flow *f)
uint32_t buffer_offset
Definition: detect.h:1032
Signature container.
Definition: detect.h:522
#define DETECT_CONTENT_DEPTH
#define DETECT_URILEN_EQ
Definition: detect-urilen.h:30
int DetectBytetestDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchCtx *ctx, const uint8_t *payload, uint32_t payload_len, uint8_t flags, int32_t offset, uint64_t value)
Bytetest detection code.
uint16_t flags
Definition: detect-pcre.h:42
#define DETECT_CONTENT_IS_SINGLE(c)
int DetectBase64DataDoMatch(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f)
DetectReplaceList * DetectReplaceAddToList(DetectReplaceList *replist, uint8_t *found, DetectContentData *cd)
main detection engine ctx
Definition: detect.h:761
#define DETECT_CI_FLAGS_END
int DetectPcrePayloadMatch(DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Packet *p, Flow *f, const uint8_t *payload, uint32_t payload_len)
Match a regex on a single payload.
Definition: detect-pcre.c:171
#define DETECT_CONTENT_WITHIN_BE
#define KEYWORD_PROFILING_START
int DetectDatarepBufferMatch(DetectEngineThreadCtx *det_ctx, const DetectDatarepData *sd, const uint8_t *data, const uint32_t data_len)
#define DETECT_URILEN_GT
Definition: detect-urilen.h:28
int DetectBytejumpDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchCtx *ctx, const uint8_t *payload, uint32_t payload_len, uint8_t flags, int32_t offset)
Byte jump match function.
#define ISDATAAT_NEGATED
#define DETECT_URILEN_LT
Definition: detect-urilen.h:27
#define SCEnter(...)
Definition: util-debug.h:337
#define DETECT_BYTETEST_VALUE_BE
#define DETECT_CI_FLAGS_DCE_BE
#define DETECT_BYTE_EXTRACT_ENDIAN_BIG
int DetectDatasetBufferMatch(DetectEngineThreadCtx *det_ctx, const DetectDatasetData *sd, const uint8_t *data, const uint32_t data_len)
#define DETECT_CONTENT_WITHIN_NEXT
#define DETECT_URILEN_RA
Definition: detect-urilen.h:29
#define SCReturnInt(x)
Definition: util-debug.h:341
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
Definition: util-debug.h:281
#define DETECT_CONTENT_ENDS_WITH
#define DETECT_BYTE_EXTRACT_ENDIAN_LITTLE
#define DETECT_CONTENT_OFFSET_BE
uint8_t type
Definition: detect.h:328
#define DETECT_CONTENT_NEGATED
#define DETECT_CONTENT_REPLACE
uint32_t pcre_match_start_offset
Definition: detect.h:1034
int DetectByteExtractDoMatch(DetectEngineThreadCtx *det_ctx, const SigMatchData *smd, const Signature *s, const uint8_t *payload, uint16_t payload_len, uint64_t *value, uint8_t endian)
int DetectBsizeMatch(const SigMatchCtx *ctx, const uint64_t buffer_size, bool eof)
bsize match function
Definition: detect-bsize.c:84
#define DETECT_BYTETEST_DCE
int DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Packet *p, Flow *f, const uint8_t *buffer, uint32_t buffer_len, uint32_t stream_start_offset, uint8_t flags, uint8_t inspection_mode)
Run the actual payload match functions.
#define DETECT_BYTETEST_OFFSET_BE
#define DETECT_CONTENT_WITHIN
int inspection_recursion_counter
Definition: detect.h:1079
#define DETECT_PCRE_RELATIVE_NEXT
Definition: detect-pcre.h:32
#define DETECT_BYTE_EXTRACT_FLAG_ENDIAN
Holds data related to byte_extract keyword.
#define DETECT_BYTEJUMP_OFFSET_BE
SpmThreadCtx * spm_thread_ctx
Definition: detect.h:1106
#define DETECT_CONTENT_DEPTH_BE
#define DETECT_BYTEJUMP_DCE
Flow data structure.
Definition: flow.h:325
SigMatchCtx * ctx
Definition: detect.h:330
int inspection_recursion_limit
Definition: detect.h:833
#define DETECT_BYTE_EXTRACT_ENDIAN_DCE
uint8_t * SpmScan(const SpmCtx *ctx, SpmThreadCtx *thread_ctx, const uint8_t *haystack, uint32_t haystack_len)
Definition: util-spm.c:186