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 #ifdef UNITTESTS
62 static void DetectFilenameRegisterTests(void);
63 #endif
64 static void DetectFilenameFree(DetectEngineCtx *, void *);
65 static int g_file_match_list_id = 0;
66 static int g_file_name_buffer_id = 0;
67 
68 static int PrefilterMpmFilenameRegister(DetectEngineCtx *de_ctx,
69  SigGroupHead *sgh, MpmCtx *mpm_ctx,
70  const DetectBufferMpmRegistery *mpm_reg, int list_id);
71 static int DetectEngineInspectFilename(
73  const DetectEngineAppInspectionEngine *engine,
74  const Signature *s,
75  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id);
76 
77 /**
78  * \brief Registration function for keyword: filename
79  */
81 {
82  sigmatch_table[DETECT_FILENAME].name = "filename";
83  sigmatch_table[DETECT_FILENAME].desc = "match on the file name";
84  sigmatch_table[DETECT_FILENAME].url = "/rules/file-keywords.html#filename";
85  sigmatch_table[DETECT_FILENAME].FileMatch = DetectFilenameMatch;
86  sigmatch_table[DETECT_FILENAME].Setup = DetectFilenameSetup;
87  sigmatch_table[DETECT_FILENAME].Free = DetectFilenameFree;
88 #ifdef UNITTESTS
89  sigmatch_table[DETECT_FILENAME].RegisterTests = DetectFilenameRegisterTests;
90 #endif
93 
94  sigmatch_table[DETECT_FILE_NAME].name = "file.name";
95  sigmatch_table[DETECT_FILE_NAME].desc = "sticky buffer to match on the file name";
96  sigmatch_table[DETECT_FILE_NAME].url = "/rules/file-keywords.html#filename";
97  sigmatch_table[DETECT_FILE_NAME].Setup = DetectFilenameSetupSticky;
99 
101  HTP_REQUEST_BODY, DetectFileInspectGeneric, NULL);
103  HTP_RESPONSE_BODY, DetectFileInspectGeneric, NULL);
104 
107 
112 
117 
122 
123  //this is used by filestore
125  HTTP2StateDataClient, DetectFileInspectGeneric, NULL);
127  HTTP2StateDataServer, DetectFileInspectGeneric, NULL);
128 
129  g_file_match_list_id = DetectBufferTypeGetByName("files");
130 
132  ALPROTO_NFS, 0 };
134  0 };
135 
136  for (int i = 0; protos_ts[i] != 0; i++) {
137  DetectAppLayerInspectEngineRegister2("file.name", protos_ts[i],
139  DetectEngineInspectFilename, NULL);
140 
142  PrefilterMpmFilenameRegister, NULL, protos_ts[i],
143  0);
144  }
145  for (int i = 0; protos_tc[i] != 0; i++) {
146  DetectAppLayerInspectEngineRegister2("file.name", protos_tc[i],
148  DetectEngineInspectFilename, NULL);
149 
151  PrefilterMpmFilenameRegister, NULL, protos_tc[i],
152  0);
153  }
154 
156  "http user agent");
157 
158  g_file_name_buffer_id = DetectBufferTypeGetByName("file.name");
159  SCLogDebug("registering filename rule option");
160  return;
161 }
162 
163 /**
164  * \brief match the specified filename
165  *
166  * \param t thread local vars
167  * \param det_ctx pattern matcher thread local data
168  * \param f *LOCKED* flow
169  * \param flags direction flags
170  * \param file file being inspected
171  * \param s signature being inspected
172  * \param m sigmatch that we will cast into DetectFilenameData
173  *
174  * \retval 0 no match
175  * \retval 1 match
176  */
177 static int DetectFilenameMatch (DetectEngineThreadCtx *det_ctx,
178  Flow *f, uint8_t flags, File *file, const Signature *s, const SigMatchCtx *m)
179 {
180  SCEnter();
181  int ret = 0;
182 
183  DetectFilenameData *filename = (DetectFilenameData *)m;
184 
185  if (file->name == NULL)
186  SCReturnInt(0);
187 
188  if (BoyerMooreNocase(filename->name, filename->len, file->name,
189  file->name_len, filename->bm_ctx) != NULL)
190  {
191 #ifdef DEBUG
192  if (SCLogDebugEnabled()) {
193  char *name = SCMalloc(filename->len + 1);
194  if (name != NULL) {
195  memcpy(name, filename->name, filename->len);
196  name[filename->len] = '\0';
197  SCLogDebug("will look for filename %s", name);
198  SCFree(name);
199  }
200  }
201 #endif
202 
203  if (!(filename->flags & DETECT_CONTENT_NEGATED)) {
204  ret = 1;
205  }
206  }
207 
208  else if (filename->flags & DETECT_CONTENT_NEGATED) {
209  SCLogDebug("negated match");
210  ret = 1;
211  }
212 
213  SCReturnInt(ret);
214 }
215 
216 /**
217  * \brief Parse the filename keyword
218  *
219  * \param de_ctx Pointer to the detection engine context
220  * \param idstr Pointer to the user provided option
221  *
222  * \retval filename pointer to DetectFilenameData on success
223  * \retval NULL on failure
224  */
225 static DetectFilenameData *DetectFilenameParse (DetectEngineCtx *de_ctx, const char *str, bool negate)
226 {
227  DetectFilenameData *filename = NULL;
228 
229  /* We have a correct filename option */
230  filename = SCMalloc(sizeof(DetectFilenameData));
231  if (unlikely(filename == NULL))
232  goto error;
233 
234  memset(filename, 0x00, sizeof(DetectFilenameData));
235 
236  if (DetectContentDataParse ("filename", str, &filename->name, &filename->len) == -1) {
237  goto error;
238  }
239 
240  filename->bm_ctx = BoyerMooreNocaseCtxInit(filename->name, filename->len);
241  if (filename->bm_ctx == NULL) {
242  goto error;
243  }
244 
245  if (negate) {
246  filename->flags |= DETECT_CONTENT_NEGATED;
247  }
248 
249  SCLogDebug("flags %02X", filename->flags);
250  if (filename->flags & DETECT_CONTENT_NEGATED) {
251  SCLogDebug("negated filename");
252  }
253 
254 #ifdef DEBUG
255  if (SCLogDebugEnabled()) {
256  char *name = SCMalloc(filename->len + 1);
257  if (name != NULL) {
258  memcpy(name, filename->name, filename->len);
259  name[filename->len] = '\0';
260  SCLogDebug("will look for filename %s", name);
261  SCFree(name);
262  }
263  }
264 #endif
265 
266  return filename;
267 
268 error:
269  if (filename != NULL)
270  DetectFilenameFree(de_ctx, filename);
271  return NULL;
272 }
273 
274 /**
275  * \brief this function is used to parse filename options
276  * \brief into the current signature
277  *
278  * \param de_ctx pointer to the Detection Engine Context
279  * \param s pointer to the Current Signature
280  * \param str pointer to the user provided "filename" option
281  *
282  * \retval 0 on Success
283  * \retval -1 on Failure
284  */
285 static int DetectFilenameSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
286 {
287  DetectFilenameData *filename = NULL;
288  SigMatch *sm = NULL;
289 
290  filename = DetectFilenameParse(de_ctx, str, s->init_data->negated);
291  if (filename == NULL)
292  goto error;
293 
294  /* Okay so far so good, lets get this into a SigMatch
295  * and put it in the Signature. */
296  sm = SigMatchAlloc();
297  if (sm == NULL)
298  goto error;
299 
300  sm->type = DETECT_FILENAME;
301  sm->ctx = (void *)filename;
302 
303  SigMatchAppendSMToList(s, sm, g_file_match_list_id);
304 
306  return 0;
307 
308 error:
309  if (filename != NULL)
310  DetectFilenameFree(de_ctx, filename);
311  if (sm != NULL)
312  SCFree(sm);
313  return -1;
314 }
315 
316 /**
317  * \brief this function will free memory associated with DetectFilenameData
318  *
319  * \param filename pointer to DetectFilenameData
320  */
321 static void DetectFilenameFree(DetectEngineCtx *de_ctx, void *ptr)
322 {
323  if (ptr != NULL) {
324  DetectFilenameData *filename = (DetectFilenameData *)ptr;
325  if (filename->bm_ctx != NULL) {
326  BoyerMooreCtxDeInit(filename->bm_ctx);
327  }
328  if (filename->name != NULL)
329  SCFree(filename->name);
330  SCFree(filename);
331  }
332 }
333 
334 /* file.name implementation */
335 
336 /**
337  * \brief this function setup the file.data keyword used in the rule
338  *
339  * \param de_ctx Pointer to the Detection Engine Context
340  * \param s Pointer to the Signature to which the current keyword belongs
341  * \param str Should hold an empty string always
342  *
343  * \retval 0 On success
344  */
345 static int DetectFilenameSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str)
346 {
347  if (DetectBufferSetActiveList(s, g_file_name_buffer_id) < 0)
348  return -1;
350  return 0;
351 }
352 
353 static InspectionBuffer *FilenameGetDataCallback(DetectEngineThreadCtx *det_ctx,
354  const DetectEngineTransforms *transforms,
355  Flow *f, uint8_t flow_flags, File *cur_file,
356  int list_id, int local_file_id, bool first)
357 {
358  SCEnter();
359 
360  InspectionBuffer *buffer = InspectionBufferMultipleForListGet(det_ctx, list_id, local_file_id);
361  if (buffer == NULL)
362  return NULL;
363  if (!first && buffer->inspect != NULL)
364  return buffer;
365 
366  const uint8_t *data = cur_file->name;
367  uint32_t data_len = cur_file->name_len;
368 
369  InspectionBufferSetupMulti(buffer, transforms, data, data_len);
370 
371  SCReturnPtr(buffer, "InspectionBuffer");
372 }
373 
374 static int DetectEngineInspectFilename(
376  const DetectEngineAppInspectionEngine *engine,
377  const Signature *s,
378  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
379 {
380  const DetectEngineTransforms *transforms = NULL;
381  if (!engine->mpm) {
382  transforms = engine->v2.transforms;
383  }
384 
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  if (ffc != NULL) {
447  int local_file_id = 0;
448  for (File *file = ffc->head; file != NULL; file = file->next) {
449  if (file->txid != idx)
450  continue;
451 
452  InspectionBuffer *buffer = FilenameGetDataCallback(det_ctx,
453  ctx->transforms, f, flags, file, list_id, local_file_id, true);
454  if (buffer == NULL)
455  continue;
456 
457  if (buffer->inspect_len >= mpm_ctx->minlen) {
458  (void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
459  &det_ctx->mtcu, &det_ctx->pmq,
460  buffer->inspect, buffer->inspect_len);
461  }
462  local_file_id++;
463  }
464  }
465 }
466 
467 static void PrefilterMpmFilenameFree(void *ptr)
468 {
469  SCFree(ptr);
470 }
471 
472 static int PrefilterMpmFilenameRegister(DetectEngineCtx *de_ctx,
473  SigGroupHead *sgh, MpmCtx *mpm_ctx,
474  const DetectBufferMpmRegistery *mpm_reg, int list_id)
475 {
476  PrefilterMpmFilename *pectx = SCCalloc(1, sizeof(*pectx));
477  if (pectx == NULL)
478  return -1;
479  pectx->list_id = list_id;
480  pectx->mpm_ctx = mpm_ctx;
481  pectx->transforms = &mpm_reg->transforms;
482 
483  return PrefilterAppendTxEngine(de_ctx, sgh, PrefilterTxFilename,
484  mpm_reg->app_v2.alproto, mpm_reg->app_v2.tx_min_progress,
485  pectx, PrefilterMpmFilenameFree, mpm_reg->pname);
486 }
487 
488 #ifdef UNITTESTS /* UNITTESTS */
489 
490 /**
491  * \test Test parser accepting valid rules and rejecting invalid rules
492  */
493 static int DetectFilenameSignatureParseTest01(void)
494 {
495  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; sid:1;)", true));
496  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; nocase; sid:1;)", true));
497  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; endswith; sid:1;)", true));
498  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; startswith; sid:1;)", true));
499  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; startswith; endswith; sid:1;)", true));
500  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; bsize:10; sid:1;)", true));
501 
502  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; rawbytes; sid:1;)", false));
503  FAIL_IF_NOT(UTHParseSignature("alert tcp any any -> any any (flow:to_client; file.name; sid:1;)", false));
504  //FAIL_IF_NOT(UTHParseSignature("alert tls any any -> any any (flow:to_client; file.name; content:\"abc\"; sid:1;)", false));
505  PASS;
506 }
507 /**
508  * \test DetectFilenameTestParse01
509  */
510 static int DetectFilenameTestParse01 (void)
511 {
512  DetectFilenameData *dnd = DetectFilenameParse(NULL, "secret.pdf", false);
513  if (dnd != NULL) {
514  DetectFilenameFree(NULL, dnd);
515  return 1;
516  }
517  return 0;
518 }
519 
520 /**
521  * \test DetectFilenameTestParse02
522  */
523 static int DetectFilenameTestParse02 (void)
524 {
525  int result = 0;
526 
527  DetectFilenameData *dnd = DetectFilenameParse(NULL, "backup.tar.gz", false);
528  if (dnd != NULL) {
529  if (dnd->len == 13 && memcmp(dnd->name, "backup.tar.gz", 13) == 0) {
530  result = 1;
531  }
532 
533  DetectFilenameFree(NULL, dnd);
534  return result;
535  }
536  return 0;
537 }
538 
539 /**
540  * \test DetectFilenameTestParse03
541  */
542 static int DetectFilenameTestParse03 (void)
543 {
544  int result = 0;
545 
546  DetectFilenameData *dnd = DetectFilenameParse(NULL, "cmd.exe", false);
547  if (dnd != NULL) {
548  if (dnd->len == 7 && memcmp(dnd->name, "cmd.exe", 7) == 0) {
549  result = 1;
550  }
551 
552  DetectFilenameFree(NULL, dnd);
553  return result;
554  }
555  return 0;
556 }
557 
558 
559 /**
560  * \brief this function registers unit tests for DetectFilename
561  */
562 void DetectFilenameRegisterTests(void)
563 {
564  UtRegisterTest("DetectFilenameSignatureParseTest01", DetectFilenameSignatureParseTest01);
565 
566  UtRegisterTest("DetectFilenameTestParse01", DetectFilenameTestParse01);
567  UtRegisterTest("DetectFilenameTestParse02", DetectFilenameTestParse02);
568  UtRegisterTest("DetectFilenameTestParse03", DetectFilenameTestParse03);
569 }
570 #endif /* UNITTESTS */
DetectEngineAppInspectionEngine_
Definition: detect.h:398
SigTableElmt_::url
const char * url
Definition: detect.h:1270
UTHParseSignature
int UTHParseSignature(const char *str, bool expect)
parser a sig and see if the expected result is correct
Definition: util-unittest-helper.c:969
DetectEngineAppInspectionEngine_::mpm
bool mpm
Definition: detect.h:402
FileContainer_
Definition: util-file.h:110
MpmCtx_::mpm_type
uint8_t mpm_type
Definition: util-mpm.h:90
DetectEngineThreadCtx_::buffer_offset
uint32_t buffer_offset
Definition: detect.h:1088
detect-engine.h
SIGMATCH_INFO_STICKY_BUFFER
#define SIGMATCH_INFO_STICKY_BUFFER
Definition: detect.h:1477
SigTableElmt_::desc
const char * desc
Definition: detect.h:1269
DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
Definition: detect-engine-content-inspection.h:36
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1257
flow-util.h
SigTableElmt_::name
const char * name
Definition: detect.h:1267
stream-tcp.h
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1425
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms
Definition: detect.h:379
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
DetectFilenameData
Definition: detect-filename.h:29
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
SIGMATCH_QUOTES_OPTIONAL
#define SIGMATCH_QUOTES_OPTIONAL
Definition: detect.h:1465
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:80
DetectBufferMpmRegistery_::transforms
DetectEngineTransforms transforms
Definition: detect.h:648
InspectionBuffer
Definition: detect.h:345
threads.h
Flow_
Flow data structure.
Definition: flow.h:353
SigTableElmt_::FileMatch
int(* FileMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, File *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1243
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1167
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1261
DetectBufferMpmRegistery_::app_v2
struct DetectBufferMpmRegistery_::@87::@89 app_v2
PrefilterMpmFilename::transforms
const DetectEngineTransforms * transforms
Definition: detect-filename.c:423
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:811
AppLayerParserGetFiles
FileContainer * AppLayerParserGetFiles(const Flow *f, const uint8_t direction)
Definition: app-layer-parser.c:887
ALPROTO_FTP
@ ALPROTO_FTP
Definition: app-layer-protos.h:31
DetectBufferMpmRegistery_
one time registration of keywords at start up
Definition: detect.h:634
FILE_SIG_NEED_FILENAME
#define FILE_SIG_NEED_FILENAME
Definition: detect.h:286
m
SCMutex m
Definition: flow-hash.h:6
DetectEngineContentInspection
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.
Definition: detect-engine-content-inspection.c:102
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:237
DetectFilenameData::bm_ctx
BmCtx * bm_ctx
Definition: detect-filename.h:31
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1252
DetectEngineAppInspectionEngine_::v2
struct DetectEngineAppInspectionEngine_::@84 v2
detect-engine-prefilter.h
DetectEngineThreadCtx_::mtcu
MpmThreadCtx mtcu
Definition: detect.h:1165
util-unittest.h
detect-filename.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
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1077
File_::name_len
uint16_t name_len
Definition: util-file.h:77
DetectEngineAppInspectionEngine_::sm_list
uint16_t sm_list
Definition: detect.h:404
DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
Definition: detect-engine-state.h:44
PrefilterMpmFilename::list_id
int list_id
Definition: detect-filename.c:421
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:236
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:17
DetectEngineThreadCtx_
Definition: detect.h:1060
ALPROTO_SMTP
@ ALPROTO_SMTP
Definition: app-layer-protos.h:32
detect-engine-file.h
DetectFilenameData::name
uint8_t * name
Definition: detect-filename.h:30
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
detect-engine-mpm.h
FileContainer_::head
File * head
Definition: util-file.h:111
detect.h
DETECT_ENGINE_INSPECT_SIG_MATCH
#define DETECT_ENGINE_INSPECT_SIG_MATCH
Definition: detect-engine-state.h:39
DETECT_CONTENT_NEGATED
#define DETECT_CONTENT_NEGATED
Definition: detect-content.h:40
InspectionBuffer::inspect_offset
uint64_t inspect_offset
Definition: detect.h:347
DETECT_FILENAME
@ DETECT_FILENAME
Definition: detect-engine-register.h:200
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1265
app-layer-parser.h
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:99
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:324
BoyerMooreNocase
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:353
Packet_
Definition: decode.h:427
DetectAppLayerInspectEngineRegister2
void DetectAppLayerInspectEngineRegister2(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr2 Callback2, InspectionBufferGetDataPtr GetData)
register inspect engine at start up time
Definition: detect-engine.c:225
SIGMATCH_HANDLE_NEGATION
#define SIGMATCH_HANDLE_NEGATION
Definition: detect.h:1473
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:619
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:316
File_::name
uint8_t * name
Definition: util-file.h:85
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
SignatureInitData_::negated
bool negated
Definition: detect.h:503
ALPROTO_HTTP2
@ ALPROTO_HTTP2
Definition: app-layer-protos.h:62
MpmTableElmt_::Search
uint32_t(* Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint32_t)
Definition: util-mpm.h:165
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:235
DetectFileInspectGeneric
int DetectFileInspectGeneric(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *_alstate, void *tx, uint64_t tx_id)
Inspect the file inspecting keywords against the state.
Definition: detect-engine-file.c:216
PrefilterMpmFilename::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-filename.c:422
detect-engine-content-inspection.h
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:316
DetectEngineThreadCtx_::discontinue_matching
uint16_t discontinue_matching
Definition: detect.h:1127
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:415
DetectContentDataParse
int DetectContentDataParse(const char *keyword, const char *contentstr, uint8_t **pstr, uint16_t *plen)
Parse a content string, ie "abc|DE|fgh".
Definition: detect-content.c:82
File_
Definition: util-file.h:75
DetectAppLayerMpmRegister2
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
Definition: detect-engine-mpm.c:89
DETECT_FILE_NAME
@ DETECT_FILE_NAME
Definition: detect-engine-register.h:201
DETECT_CI_FLAGS_SINGLE
#define DETECT_CI_FLAGS_SINGLE
Definition: detect-engine-content-inspection.h:47
DetectBufferMpmRegistery_::pname
char pname[32]
Definition: detect.h:636
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
PrefilterMpmFilename
struct PrefilterMpmFilename PrefilterMpmFilename
SigMatch_::type
uint16_t type
Definition: detect.h:322
Signature_::file_flags
uint8_t file_flags
Definition: detect.h:563
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:30
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
DetectEngineThreadCtx_::inspection_recursion_counter
int inspection_recursion_counter
Definition: detect.h:1144
File_::next
struct File_ * next
Definition: util-file.h:89
ALPROTO_FTPDATA
@ ALPROTO_FTPDATA
Definition: app-layer-protos.h:47
PrefilterMpmFilename
Definition: detect-filename.c:420
util-spm-bm.h
InspectionBufferSetupMulti
void InspectionBufferSetupMulti(InspectionBuffer *buffer, const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
Definition: detect-engine.c:1427
DETECT_ENGINE_INSPECT_SIG_NO_MATCH
#define DETECT_ENGINE_INSPECT_SIG_NO_MATCH
Definition: detect-engine-state.h:38
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
InspectionBuffer::inspect_len
uint32_t inspect_len
Definition: detect.h:348
InspectionBuffer::inspect
const uint8_t * inspect
Definition: detect.h:346
str
#define str(s)
Definition: suricata-common.h:272
SCFree
#define SCFree(p)
Definition: util-mem.h:61
detect-parse.h
Signature_
Signature container.
Definition: detect.h:548
SigMatch_
a single match condition for a signature
Definition: detect.h:321
PrefilterAppendTxEngine
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)
Definition: detect-engine-prefilter.c:270
DetectEngineAppInspectionEngine_::transforms
const DetectEngineTransforms * transforms
Definition: detect.h:412
mpm_table
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.c:48
InspectionBufferMultipleForListGet
InspectionBuffer * InspectionBufferMultipleForListGet(DetectEngineThreadCtx *det_ctx, const int list_id, const uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
Definition: detect-engine.c:1380
FILE_SIG_NEED_FILE
#define FILE_SIG_NEED_FILE
Definition: detect.h:285
File_::txid
uint64_t txid
Definition: util-file.h:80
ALPROTO_SMB
@ ALPROTO_SMB
Definition: app-layer-protos.h:37
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect.h:1453
DetectBufferSetActiveList
int DetectBufferSetActiveList(Signature *s, const int list)
Definition: detect-engine.c:1291
DetectBufferTypeSetDescriptionByName
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
Definition: detect-engine.c:1174
MpmCtx_
Definition: util-mpm.h:88
flow.h
DetectFilenameRegister
void DetectFilenameRegister(void)
Registration function for keyword: filename.
Definition: detect-filename.c:80
DetectFilenameData::len
uint16_t len
Definition: detect-filename.h:32
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:304
flow-var.h
BoyerMooreNocaseCtxInit
BmCtx * BoyerMooreNocaseCtxInit(uint8_t *needle, uint16_t needle_len)
Setup a Booyer Moore context for nocase search.
Definition: util-spm-bm.c:107
SCLogDebugEnabled
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
Definition: util-debug.c:647
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:349
ALPROTO_NFS
@ ALPROTO_NFS
Definition: app-layer-protos.h:45
debug.h
DetectFilenameData::flags
uint32_t flags
Definition: detect-filename.h:33
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1259
app-layer.h
BoyerMooreCtxDeInit
void BoyerMooreCtxDeInit(BmCtx *bmctx)
Free the memory allocated to Booyer Moore context.
Definition: util-spm-bm.c:121