suricata
detect-filename.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2014 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  * \author Pablo Rincon <pablo.rincon.crespo@gmail.com>
23  *
24  */
25 
26 #include "suricata-common.h"
27 #include "threads.h"
28 #include "debug.h"
29 #include "decode.h"
30 
31 #include "detect.h"
32 #include "detect-parse.h"
33 
34 #include "detect-engine.h"
35 #include "detect-engine-mpm.h"
36 #include "detect-engine-state.h"
37 #include "detect-engine-file.h"
40 
41 #include "flow.h"
42 #include "flow-var.h"
43 #include "flow-util.h"
44 
45 #include "util-debug.h"
46 #include "util-spm-bm.h"
47 #include "util-unittest.h"
48 #include "util-unittest-helper.h"
49 
50 #include "app-layer.h"
51 
52 #include "stream-tcp.h"
53 
54 #include "detect-filename.h"
55 #include "app-layer-parser.h"
56 
57 static int DetectFilenameMatch (DetectEngineThreadCtx *, Flow *,
58  uint8_t, File *, const Signature *, const SigMatchCtx *);
59 static int DetectFilenameSetup (DetectEngineCtx *, Signature *, const char *);
60 static int DetectFilenameSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str);
61 static void DetectFilenameRegisterTests(void);
62 static void DetectFilenameFree(void *);
63 static int g_file_match_list_id = 0;
64 static int g_file_name_buffer_id = 0;
65 
66 static int PrefilterMpmFilenameRegister(DetectEngineCtx *de_ctx,
67  SigGroupHead *sgh, MpmCtx *mpm_ctx,
68  const DetectBufferMpmRegistery *mpm_reg, int list_id);
69 static int DetectEngineInspectFilename(
70  DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
71  const DetectEngineAppInspectionEngine *engine,
72  const Signature *s,
73  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id);
74 
75 /**
76  * \brief Registration function for keyword: filename
77  */
79 {
80  sigmatch_table[DETECT_FILENAME].name = "filename";
81  sigmatch_table[DETECT_FILENAME].desc = "match on the file name";
82  sigmatch_table[DETECT_FILENAME].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filename";
83  sigmatch_table[DETECT_FILENAME].FileMatch = DetectFilenameMatch;
84  sigmatch_table[DETECT_FILENAME].Setup = DetectFilenameSetup;
85  sigmatch_table[DETECT_FILENAME].Free = DetectFilenameFree;
86  sigmatch_table[DETECT_FILENAME].RegisterTests = DetectFilenameRegisterTests;
89 
90  sigmatch_table[DETECT_FILE_NAME].name = "file.name";
91  sigmatch_table[DETECT_FILE_NAME].desc = "sticky buffer to match on the file name";
92  sigmatch_table[DETECT_FILE_NAME].url = DOC_URL DOC_VERSION "/rules/file-keywords.html#filename";
93  sigmatch_table[DETECT_FILE_NAME].Setup = DetectFilenameSetupSticky;
95 
97  ALPROTO_HTTP, SIG_FLAG_TOSERVER, HTP_REQUEST_BODY,
100  ALPROTO_HTTP, SIG_FLAG_TOCLIENT, HTP_RESPONSE_BODY,
102 
106 
113 
120 
127 
128  g_file_match_list_id = DetectBufferTypeGetByName("files");
129 
130  AppProto protos_ts[] = {
132  AppProto protos_tc[] = {
134 
135  for (int i = 0; protos_ts[i] != 0; i++) {
136  DetectAppLayerInspectEngineRegister2("file.name", protos_ts[i],
138  DetectEngineInspectFilename, NULL);
139 
141  PrefilterMpmFilenameRegister, NULL, protos_ts[i],
142  0);
143  }
144  for (int i = 0; protos_tc[i] != 0; i++) {
145  DetectAppLayerInspectEngineRegister2("file.name", protos_tc[i],
147  DetectEngineInspectFilename, NULL);
148 
150  PrefilterMpmFilenameRegister, NULL, protos_tc[i],
151  0);
152  }
153 
155  "http user agent");
156 
157  g_file_name_buffer_id = DetectBufferTypeGetByName("file.name");
158  SCLogDebug("registering filename rule option");
159  return;
160 }
161 
162 /**
163  * \brief match the specified filename
164  *
165  * \param t thread local vars
166  * \param det_ctx pattern matcher thread local data
167  * \param f *LOCKED* flow
168  * \param flags direction flags
169  * \param file file being inspected
170  * \param s signature being inspected
171  * \param m sigmatch that we will cast into DetectFilenameData
172  *
173  * \retval 0 no match
174  * \retval 1 match
175  */
176 static int DetectFilenameMatch (DetectEngineThreadCtx *det_ctx,
177  Flow *f, uint8_t flags, File *file, const Signature *s, const SigMatchCtx *m)
178 {
179  SCEnter();
180  int ret = 0;
181 
182  DetectFilenameData *filename = (DetectFilenameData *)m;
183 
184  if (file->name == NULL)
185  SCReturnInt(0);
186 
187  if (BoyerMooreNocase(filename->name, filename->len, file->name,
188  file->name_len, filename->bm_ctx) != NULL)
189  {
190 #ifdef DEBUG
191  if (SCLogDebugEnabled()) {
192  char *name = SCMalloc(filename->len + 1);
193  if (name != NULL) {
194  memcpy(name, filename->name, filename->len);
195  name[filename->len] = '\0';
196  SCLogDebug("will look for filename %s", name);
197  SCFree(name);
198  }
199  }
200 #endif
201 
202  if (!(filename->flags & DETECT_CONTENT_NEGATED)) {
203  ret = 1;
204  }
205  }
206 
207  else if (filename->flags & DETECT_CONTENT_NEGATED) {
208  SCLogDebug("negated match");
209  ret = 1;
210  }
211 
212  SCReturnInt(ret);
213 }
214 
215 /**
216  * \brief Parse the filename keyword
217  *
218  * \param idstr Pointer to the user provided option
219  *
220  * \retval filename pointer to DetectFilenameData on success
221  * \retval NULL on failure
222  */
223 static DetectFilenameData *DetectFilenameParse (const char *str, bool negate)
224 {
225  DetectFilenameData *filename = NULL;
226 
227  /* We have a correct filename option */
228  filename = SCMalloc(sizeof(DetectFilenameData));
229  if (unlikely(filename == NULL))
230  goto error;
231 
232  memset(filename, 0x00, sizeof(DetectFilenameData));
233 
234  if (DetectContentDataParse ("filename", str, &filename->name, &filename->len) == -1) {
235  goto error;
236  }
237 
238  filename->bm_ctx = BoyerMooreNocaseCtxInit(filename->name, filename->len);
239  if (filename->bm_ctx == NULL) {
240  goto error;
241  }
242 
243  if (negate) {
244  filename->flags |= DETECT_CONTENT_NEGATED;
245  }
246 
247  SCLogDebug("flags %02X", filename->flags);
248  if (filename->flags & DETECT_CONTENT_NEGATED) {
249  SCLogDebug("negated filename");
250  }
251 
252 #ifdef DEBUG
253  if (SCLogDebugEnabled()) {
254  char *name = SCMalloc(filename->len + 1);
255  if (name != NULL) {
256  memcpy(name, filename->name, filename->len);
257  name[filename->len] = '\0';
258  SCLogDebug("will look for filename %s", name);
259  SCFree(name);
260  }
261  }
262 #endif
263 
264  return filename;
265 
266 error:
267  if (filename != NULL)
268  DetectFilenameFree(filename);
269  return NULL;
270 }
271 
272 /**
273  * \brief this function is used to parse filename options
274  * \brief into the current signature
275  *
276  * \param de_ctx pointer to the Detection Engine Context
277  * \param s pointer to the Current Signature
278  * \param str pointer to the user provided "filename" option
279  *
280  * \retval 0 on Success
281  * \retval -1 on Failure
282  */
283 static int DetectFilenameSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
284 {
285  DetectFilenameData *filename = NULL;
286  SigMatch *sm = NULL;
287 
288  filename = DetectFilenameParse(str, s->init_data->negated);
289  if (filename == NULL)
290  goto error;
291 
292  /* Okay so far so good, lets get this into a SigMatch
293  * and put it in the Signature. */
294  sm = SigMatchAlloc();
295  if (sm == NULL)
296  goto error;
297 
298  sm->type = DETECT_FILENAME;
299  sm->ctx = (void *)filename;
300 
301  SigMatchAppendSMToList(s, sm, g_file_match_list_id);
302 
304  return 0;
305 
306 error:
307  if (filename != NULL)
308  DetectFilenameFree(filename);
309  if (sm != NULL)
310  SCFree(sm);
311  return -1;
312 }
313 
314 /**
315  * \brief this function will free memory associated with DetectFilenameData
316  *
317  * \param filename pointer to DetectFilenameData
318  */
319 static void DetectFilenameFree(void *ptr)
320 {
321  if (ptr != NULL) {
322  DetectFilenameData *filename = (DetectFilenameData *)ptr;
323  if (filename->bm_ctx != NULL) {
324  BoyerMooreCtxDeInit(filename->bm_ctx);
325  }
326  if (filename->name != NULL)
327  SCFree(filename->name);
328  SCFree(filename);
329  }
330 }
331 
332 /* file.name implementation */
333 
334 /**
335  * \brief this function setup the file.data keyword used in the rule
336  *
337  * \param de_ctx Pointer to the Detection Engine Context
338  * \param s Pointer to the Signature to which the current keyword belongs
339  * \param str Should hold an empty string always
340  *
341  * \retval 0 On success
342  */
343 static int DetectFilenameSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str)
344 {
345  if (DetectBufferSetActiveList(s, g_file_name_buffer_id) < 0)
346  return -1;
347  return 0;
348 }
349 
350 static InspectionBuffer *FilenameGetDataCallback(DetectEngineThreadCtx *det_ctx,
351  const DetectEngineTransforms *transforms,
352  Flow *f, uint8_t flow_flags, File *cur_file,
353  int list_id, int local_file_id, bool first)
354 {
355  SCEnter();
356 
358  InspectionBuffer *buffer = InspectionBufferMultipleForListGet(fb, local_file_id);
359  if (buffer == NULL)
360  return NULL;
361  if (!first && buffer->inspect != NULL)
362  return buffer;
363 
364  const uint8_t *data = cur_file->name;
365  uint32_t data_len = cur_file->name_len;
366 
367  InspectionBufferSetup(buffer, data, data_len);
368  InspectionBufferApplyTransforms(buffer, transforms);
369 
370  SCReturnPtr(buffer, "InspectionBuffer");
371 }
372 
373 static int DetectEngineInspectFilename(
374  DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
375  const DetectEngineAppInspectionEngine *engine,
376  const Signature *s,
377  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
378 {
379  const DetectEngineTransforms *transforms = NULL;
380  if (!engine->mpm) {
381  transforms = engine->v2.transforms;
382  }
383 
385  f->alstate, flags);
386  if (ffc == NULL) {
388  }
389 
391  int local_file_id = 0;
392  for (File *file = ffc->head; file != NULL; file = file->next) {
393  if (file->txid != tx_id)
394  continue;
395 
396  InspectionBuffer *buffer = FilenameGetDataCallback(det_ctx,
397  transforms, f, flags, file, engine->sm_list, local_file_id, false);
398  if (buffer == NULL)
399  continue;
400 
401  det_ctx->buffer_offset = 0;
402  det_ctx->discontinue_matching = 0;
403  det_ctx->inspection_recursion_counter = 0;
404  int match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
405  NULL, f,
406  (uint8_t *)buffer->inspect,
407  buffer->inspect_len,
410  if (match == 1) {
412  } else {
414  }
415  local_file_id++;
416  }
417  return r;
418 }
419 
420 typedef struct PrefilterMpmFilename {
421  int list_id;
422  const MpmCtx *mpm_ctx;
425 
426 /** \brief Filedata Filedata Mpm prefilter callback
427  *
428  * \param det_ctx detection engine thread ctx
429  * \param p packet to inspect
430  * \param f flow to inspect
431  * \param txv tx to inspect
432  * \param pectx inspection context
433  */
434 static void PrefilterTxFilename(DetectEngineThreadCtx *det_ctx,
435  const void *pectx,
436  Packet *p, Flow *f, void *txv,
437  const uint64_t idx, const uint8_t flags)
438 {
439  SCEnter();
440 
441  const PrefilterMpmFilename *ctx = (const PrefilterMpmFilename *)pectx;
442  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
443  const int list_id = ctx->list_id;
444 
446  f->alstate, flags);
447  int local_file_id = 0;
448  if (ffc != NULL) {
449  File *file = ffc->head;
450  for (; file != NULL; file = file->next) {
451  if (file->txid != idx)
452  continue;
453 
454  InspectionBuffer *buffer = FilenameGetDataCallback(det_ctx,
455  ctx->transforms, f, flags, file, list_id, local_file_id, true);
456  if (buffer == NULL)
457  continue;
458 
459  if (buffer->inspect_len >= mpm_ctx->minlen) {
460  (void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
461  &det_ctx->mtcu, &det_ctx->pmq,
462  buffer->inspect, buffer->inspect_len);
463  }
464  }
465  }
466 }
467 
468 static void PrefilterMpmFilenameFree(void *ptr)
469 {
470  SCFree(ptr);
471 }
472 
473 static int PrefilterMpmFilenameRegister(DetectEngineCtx *de_ctx,
474  SigGroupHead *sgh, MpmCtx *mpm_ctx,
475  const DetectBufferMpmRegistery *mpm_reg, int list_id)
476 {
477  PrefilterMpmFilename *pectx = SCCalloc(1, sizeof(*pectx));
478  if (pectx == NULL)
479  return -1;
480  pectx->list_id = list_id;
481  pectx->mpm_ctx = mpm_ctx;
482  pectx->transforms = &mpm_reg->transforms;
483 
484  return PrefilterAppendTxEngine(de_ctx, sgh, PrefilterTxFilename,
485  mpm_reg->app_v2.alproto, mpm_reg->app_v2.tx_min_progress,
486  pectx, PrefilterMpmFilenameFree, mpm_reg->pname);
487 }
488 
489 #ifdef UNITTESTS /* UNITTESTS */
490 
491 /**
492  * \test Test parser accepting valid rules and rejecting invalid rules
493  */
494 static int DetectFilenameSignatureParseTest01(void)
495 {
496  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; sid:1;)", true));
497  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; nocase; sid:1;)", true));
498  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; endswith; sid:1;)", true));
499  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; startswith; sid:1;)", true));
500  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; startswith; endswith; sid:1;)", true));
501  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; bsize:10; sid:1;)", true));
502 
503  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; rawbytes; sid:1;)", false));
504  FAIL_IF_NOT(UTHParseSignature("alert tcp any any -> any any (flow:to_client; file.name; sid:1;)", false));
505  //FAIL_IF_NOT(UTHParseSignature("alert tls any any -> any any (flow:to_client; file.name; content:\"abc\"; sid:1;)", false));
506  PASS;
507 }
508 /**
509  * \test DetectFilenameTestParse01
510  */
511 static int DetectFilenameTestParse01 (void)
512 {
513  DetectFilenameData *dnd = DetectFilenameParse("secret.pdf", false);
514  if (dnd != NULL) {
515  DetectFilenameFree(dnd);
516  return 1;
517  }
518  return 0;
519 }
520 
521 /**
522  * \test DetectFilenameTestParse02
523  */
524 static int DetectFilenameTestParse02 (void)
525 {
526  int result = 0;
527 
528  DetectFilenameData *dnd = DetectFilenameParse("backup.tar.gz", false);
529  if (dnd != NULL) {
530  if (dnd->len == 13 && memcmp(dnd->name, "backup.tar.gz", 13) == 0) {
531  result = 1;
532  }
533 
534  DetectFilenameFree(dnd);
535  return result;
536  }
537  return 0;
538 }
539 
540 /**
541  * \test DetectFilenameTestParse03
542  */
543 static int DetectFilenameTestParse03 (void)
544 {
545  int result = 0;
546 
547  DetectFilenameData *dnd = DetectFilenameParse("cmd.exe", false);
548  if (dnd != NULL) {
549  if (dnd->len == 7 && memcmp(dnd->name, "cmd.exe", 7) == 0) {
550  result = 1;
551  }
552 
553  DetectFilenameFree(dnd);
554  return result;
555  }
556  return 0;
557 }
558 
559 #endif /* UNITTESTS */
560 
561 /**
562  * \brief this function registers unit tests for DetectFilename
563  */
564 void DetectFilenameRegisterTests(void)
565 {
566 #ifdef UNITTESTS /* UNITTESTS */
567  UtRegisterTest("DetectFilenameSignatureParseTest01", DetectFilenameSignatureParseTest01);
568 
569  UtRegisterTest("DetectFilenameTestParse01", DetectFilenameTestParse01);
570  UtRegisterTest("DetectFilenameTestParse02", DetectFilenameTestParse02);
571  UtRegisterTest("DetectFilenameTestParse03", DetectFilenameTestParse03);
572 #endif /* UNITTESTS */
573 }
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect.h:1448
SignatureInitData * init_data
Definition: detect.h:591
uint16_t flags
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1186
#define SCLogDebug(...)
Definition: util-debug.h:335
uint16_t minlen
Definition: util-mpm.h:99
struct DetectEngineAppInspectionEngine_::@93 v2
uint16_t discontinue_matching
Definition: detect.h:1067
uint8_t proto
Definition: flow.h:344
#define PASS
Pass the test.
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms transforms
Definition: detect.h:618
int UTHParseSignature(const char *str, bool expect)
parser a sig and see if the expected result is correct
struct DetectBufferMpmRegistery_::@95::@97 app_v2
int DetectContentDataParse(const char *keyword, const char *contentstr, uint8_t **pstr, uint16_t *plen)
Parse a content string, ie "abc|DE|fgh".
#define FILE_SIG_NEED_FILENAME
Definition: detect.h:283
Container for matching data for a signature group.
Definition: detect.h:1336
uint32_t buffer_offset
Definition: detect.h:1032
const char * name
Definition: detect.h:1200
uint16_t AppProto
Signature container.
Definition: detect.h:522
struct File_ * next
Definition: util-file.h:77
void DetectAppLayerMpmRegister2(const char *name, int direction, int priority, int(*PrefilterRegister)(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistery *mpm_reg, int list_id), InspectionBufferGetDataPtr GetData, AppProto alproto, int tx_min_progress)
register a MPM engine
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:313
int DetectFileInspectGeneric(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Flow *f, uint8_t flags, void *alstate, void *tx, uint64_t tx_id)
Inspect the file inspecting keywords against the state.
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
main detection engine ctx
Definition: detect.h:761
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
Definition: util-debug.c:624
uint8_t * BoyerMooreNocase(const uint8_t *x, uint16_t m, const uint8_t *y, uint32_t n, BmCtx *bm_ctx)
Boyer Moore search algorithm Is better as the pattern length increases and for big buffers to search ...
Definition: util-spm-bm.c:350
void * alstate
Definition: flow.h:438
void BoyerMooreCtxDeInit(BmCtx *bmctx)
Free the memory allocated to Booyer Moore context.
Definition: util-spm-bm.c:120
int DetectBufferTypeGetByName(const char *name)
#define str(s)
#define SCCalloc(nm, a)
Definition: util-mem.h:253
#define SIG_FLAG_TOCLIENT
Definition: detect.h:237
#define SIGMATCH_INFO_STICKY_BUFFER
Definition: detect.h:1393
void DetectFilenameRegister(void)
Registration function for keyword: filename.
const DetectEngineTransforms * transforms
#define DETECT_ENGINE_INSPECT_SIG_MATCH
int(* FileMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, File *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1178
uint64_t inspect_offset
Definition: detect.h:344
Data structures and function prototypes for keeping state for the detection engine.
void(* Free)(void *)
Definition: detect.h:1191
uint8_t mpm_type
Definition: util-mpm.h:90
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
one time registration of keywords at start up
Definition: detect.h:605
uint64_t txid
Definition: util-file.h:68
#define SIGMATCH_QUOTES_OPTIONAL
Definition: detect.h:1381
#define SIG_FLAG_TOSERVER
Definition: detect.h:236
#define SCEnter(...)
Definition: util-debug.h:337
void DetectAppLayerInspectEngineRegister2(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr2 Callback2, InspectionBufferGetDataPtr GetData)
register inspect engine at start up time
PrefilterRuleStore pmq
Definition: detect.h:1102
uint16_t name_len
Definition: util-file.h:65
uint16_t alternative
Definition: detect.h:1198
File * head
Definition: util-file.h:99
const MpmCtx * mpm_ctx
uint8_t type
Definition: detect.h:319
#define SCReturnInt(x)
Definition: util-debug.h:341
#define FILE_SIG_NEED_FILE
Definition: detect.h:282
const char * desc
Definition: detect.h:1202
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:346
SigMatchCtx * ctx
Definition: detect.h:321
#define SCMalloc(a)
Definition: util-mem.h:222
#define DETECT_CONTENT_NEGATED
#define DETECT_ENGINE_INSPECT_SIG_NO_MATCH
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.h:169
#define SCFree(a)
Definition: util-mem.h:322
uint16_t tx_id
void InspectionBufferSetup(InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
MpmThreadCtx mtcu
Definition: detect.h:1100
struct PrefilterMpmFilename PrefilterMpmFilename
void InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
#define SIGMATCH_NOOPT
Definition: detect.h:1369
const char * url
Definition: detect.h:1203
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 SCReturnPtr(x, type)
Definition: util-debug.h:353
SCMutex m
Definition: flow-hash.h:105
BmCtx * BoyerMooreNocaseCtxInit(uint8_t *needle, uint16_t needle_len)
Setup a Booyer Moore context for nocase search.
Definition: util-spm-bm.c:106
InspectionBufferMultipleForList * InspectionBufferGetMulti(DetectEngineThreadCtx *det_ctx, const int list_id)
int inspection_recursion_counter
Definition: detect.h:1079
#define DETECT_CI_FLAGS_SINGLE
uint32_t inspect_len
Definition: detect.h:345
int DetectBufferSetActiveList(Signature *s, const int list)
const uint8_t * inspect
Definition: detect.h:343
#define DOC_URL
Definition: suricata.h:86
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
uint32_t(* Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint32_t)
Definition: util-mpm.h:162
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:232
int PrefilterAppendTxEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, void(*PrefilterTxFunc)(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p, Flow *f, void *tx, const uint64_t idx, const uint8_t flags), AppProto alproto, int tx_min_progress, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
AppProto alproto
application level protocol
Definition: flow.h:409
uint8_t file_flags
Definition: detect.h:536
FileContainer * AppLayerParserGetFiles(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t direction)
#define SIGMATCH_HANDLE_NEGATION
Definition: detect.h:1389
#define DOC_VERSION
Definition: suricata.h:91
InspectionBuffer * InspectionBufferMultipleForListGet(InspectionBufferMultipleForList *fb, uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
uint16_t flags
Definition: detect.h:1194
Flow data structure.
Definition: flow.h:325
uint8_t * name
Definition: util-file.h:73
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback)
register inspect engine at start up time
void(* RegisterTests)(void)
Definition: detect.h:1192
a single match condition for a signature
Definition: detect.h:318
#define FAIL_IF_NOT(expr)
Fail a test if expression to true.
Definition: util-unittest.h:82
const DetectEngineTransforms * transforms
Definition: detect.h:416