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  ALPROTO_HTTP, SIG_FLAG_TOSERVER, HTP_REQUEST_BODY,
104  ALPROTO_HTTP, SIG_FLAG_TOCLIENT, HTP_RESPONSE_BODY,
106 
110 
117 
124 
131 
132  g_file_match_list_id = DetectBufferTypeGetByName("files");
133 
134  AppProto protos_ts[] = {
136  AppProto protos_tc[] = {
138 
139  for (int i = 0; protos_ts[i] != 0; i++) {
140  DetectAppLayerInspectEngineRegister2("file.name", protos_ts[i],
142  DetectEngineInspectFilename, NULL);
143 
145  PrefilterMpmFilenameRegister, NULL, protos_ts[i],
146  0);
147  }
148  for (int i = 0; protos_tc[i] != 0; i++) {
149  DetectAppLayerInspectEngineRegister2("file.name", protos_tc[i],
151  DetectEngineInspectFilename, NULL);
152 
154  PrefilterMpmFilenameRegister, NULL, protos_tc[i],
155  0);
156  }
157 
159  "http user agent");
160 
161  g_file_name_buffer_id = DetectBufferTypeGetByName("file.name");
162  SCLogDebug("registering filename rule option");
163  return;
164 }
165 
166 /**
167  * \brief match the specified filename
168  *
169  * \param t thread local vars
170  * \param det_ctx pattern matcher thread local data
171  * \param f *LOCKED* flow
172  * \param flags direction flags
173  * \param file file being inspected
174  * \param s signature being inspected
175  * \param m sigmatch that we will cast into DetectFilenameData
176  *
177  * \retval 0 no match
178  * \retval 1 match
179  */
180 static int DetectFilenameMatch (DetectEngineThreadCtx *det_ctx,
181  Flow *f, uint8_t flags, File *file, const Signature *s, const SigMatchCtx *m)
182 {
183  SCEnter();
184  int ret = 0;
185 
186  DetectFilenameData *filename = (DetectFilenameData *)m;
187 
188  if (file->name == NULL)
189  SCReturnInt(0);
190 
191  if (BoyerMooreNocase(filename->name, filename->len, file->name,
192  file->name_len, filename->bm_ctx) != NULL)
193  {
194 #ifdef DEBUG
195  if (SCLogDebugEnabled()) {
196  char *name = SCMalloc(filename->len + 1);
197  if (name != NULL) {
198  memcpy(name, filename->name, filename->len);
199  name[filename->len] = '\0';
200  SCLogDebug("will look for filename %s", name);
201  SCFree(name);
202  }
203  }
204 #endif
205 
206  if (!(filename->flags & DETECT_CONTENT_NEGATED)) {
207  ret = 1;
208  }
209  }
210 
211  else if (filename->flags & DETECT_CONTENT_NEGATED) {
212  SCLogDebug("negated match");
213  ret = 1;
214  }
215 
216  SCReturnInt(ret);
217 }
218 
219 /**
220  * \brief Parse the filename keyword
221  *
222  * \param de_ctx Pointer to the detection engine context
223  * \param idstr Pointer to the user provided option
224  *
225  * \retval filename pointer to DetectFilenameData on success
226  * \retval NULL on failure
227  */
228 static DetectFilenameData *DetectFilenameParse (DetectEngineCtx *de_ctx, const char *str, bool negate)
229 {
230  DetectFilenameData *filename = NULL;
231 
232  /* We have a correct filename option */
233  filename = SCMalloc(sizeof(DetectFilenameData));
234  if (unlikely(filename == NULL))
235  goto error;
236 
237  memset(filename, 0x00, sizeof(DetectFilenameData));
238 
239  if (DetectContentDataParse ("filename", str, &filename->name, &filename->len) == -1) {
240  goto error;
241  }
242 
243  filename->bm_ctx = BoyerMooreNocaseCtxInit(filename->name, filename->len);
244  if (filename->bm_ctx == NULL) {
245  goto error;
246  }
247 
248  if (negate) {
249  filename->flags |= DETECT_CONTENT_NEGATED;
250  }
251 
252  SCLogDebug("flags %02X", filename->flags);
253  if (filename->flags & DETECT_CONTENT_NEGATED) {
254  SCLogDebug("negated filename");
255  }
256 
257 #ifdef DEBUG
258  if (SCLogDebugEnabled()) {
259  char *name = SCMalloc(filename->len + 1);
260  if (name != NULL) {
261  memcpy(name, filename->name, filename->len);
262  name[filename->len] = '\0';
263  SCLogDebug("will look for filename %s", name);
264  SCFree(name);
265  }
266  }
267 #endif
268 
269  return filename;
270 
271 error:
272  if (filename != NULL)
273  DetectFilenameFree(de_ctx, filename);
274  return NULL;
275 }
276 
277 /**
278  * \brief this function is used to parse filename options
279  * \brief into the current signature
280  *
281  * \param de_ctx pointer to the Detection Engine Context
282  * \param s pointer to the Current Signature
283  * \param str pointer to the user provided "filename" option
284  *
285  * \retval 0 on Success
286  * \retval -1 on Failure
287  */
288 static int DetectFilenameSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
289 {
290  DetectFilenameData *filename = NULL;
291  SigMatch *sm = NULL;
292 
293  filename = DetectFilenameParse(de_ctx, str, s->init_data->negated);
294  if (filename == NULL)
295  goto error;
296 
297  /* Okay so far so good, lets get this into a SigMatch
298  * and put it in the Signature. */
299  sm = SigMatchAlloc();
300  if (sm == NULL)
301  goto error;
302 
303  sm->type = DETECT_FILENAME;
304  sm->ctx = (void *)filename;
305 
306  SigMatchAppendSMToList(s, sm, g_file_match_list_id);
307 
309  return 0;
310 
311 error:
312  if (filename != NULL)
313  DetectFilenameFree(de_ctx, filename);
314  if (sm != NULL)
315  SCFree(sm);
316  return -1;
317 }
318 
319 /**
320  * \brief this function will free memory associated with DetectFilenameData
321  *
322  * \param filename pointer to DetectFilenameData
323  */
324 static void DetectFilenameFree(DetectEngineCtx *de_ctx, void *ptr)
325 {
326  if (ptr != NULL) {
327  DetectFilenameData *filename = (DetectFilenameData *)ptr;
328  if (filename->bm_ctx != NULL) {
329  BoyerMooreCtxDeInit(filename->bm_ctx);
330  }
331  if (filename->name != NULL)
332  SCFree(filename->name);
333  SCFree(filename);
334  }
335 }
336 
337 /* file.name implementation */
338 
339 /**
340  * \brief this function setup the file.data keyword used in the rule
341  *
342  * \param de_ctx Pointer to the Detection Engine Context
343  * \param s Pointer to the Signature to which the current keyword belongs
344  * \param str Should hold an empty string always
345  *
346  * \retval 0 On success
347  */
348 static int DetectFilenameSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str)
349 {
350  if (DetectBufferSetActiveList(s, g_file_name_buffer_id) < 0)
351  return -1;
352  return 0;
353 }
354 
355 static InspectionBuffer *FilenameGetDataCallback(DetectEngineThreadCtx *det_ctx,
356  const DetectEngineTransforms *transforms,
357  Flow *f, uint8_t flow_flags, File *cur_file,
358  int list_id, int local_file_id, bool first)
359 {
360  SCEnter();
361 
363  InspectionBuffer *buffer = InspectionBufferMultipleForListGet(fb, local_file_id);
364  if (buffer == NULL)
365  return NULL;
366  if (!first && buffer->inspect != NULL)
367  return buffer;
368 
369  const uint8_t *data = cur_file->name;
370  uint32_t data_len = cur_file->name_len;
371 
372  InspectionBufferSetup(buffer, data, data_len);
373  InspectionBufferApplyTransforms(buffer, transforms);
374 
375  SCReturnPtr(buffer, "InspectionBuffer");
376 }
377 
378 static int DetectEngineInspectFilename(
380  const DetectEngineAppInspectionEngine *engine,
381  const Signature *s,
382  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
383 {
384  const DetectEngineTransforms *transforms = NULL;
385  if (!engine->mpm) {
386  transforms = engine->v2.transforms;
387  }
388 
390  if (ffc == NULL) {
392  }
393 
395  int local_file_id = 0;
396  for (File *file = ffc->head; file != NULL; file = file->next) {
397  if (file->txid != tx_id)
398  continue;
399 
400  InspectionBuffer *buffer = FilenameGetDataCallback(det_ctx,
401  transforms, f, flags, file, engine->sm_list, local_file_id, false);
402  if (buffer == NULL)
403  continue;
404 
405  det_ctx->buffer_offset = 0;
406  det_ctx->discontinue_matching = 0;
407  det_ctx->inspection_recursion_counter = 0;
408  int match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
409  NULL, f,
410  (uint8_t *)buffer->inspect,
411  buffer->inspect_len,
414  if (match == 1) {
416  } else {
418  }
419  local_file_id++;
420  }
421  return r;
422 }
423 
424 typedef struct PrefilterMpmFilename {
425  int list_id;
426  const MpmCtx *mpm_ctx;
429 
430 /** \brief Filedata Filedata Mpm prefilter callback
431  *
432  * \param det_ctx detection engine thread ctx
433  * \param p packet to inspect
434  * \param f flow to inspect
435  * \param txv tx to inspect
436  * \param pectx inspection context
437  */
438 static void PrefilterTxFilename(DetectEngineThreadCtx *det_ctx,
439  const void *pectx,
440  Packet *p, Flow *f, void *txv,
441  const uint64_t idx, const uint8_t flags)
442 {
443  SCEnter();
444 
445  const PrefilterMpmFilename *ctx = (const PrefilterMpmFilename *)pectx;
446  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
447  const int list_id = ctx->list_id;
448 
450  int local_file_id = 0;
451  if (ffc != NULL) {
452  File *file = ffc->head;
453  for (; file != NULL; file = file->next) {
454  if (file->txid != idx)
455  continue;
456 
457  InspectionBuffer *buffer = FilenameGetDataCallback(det_ctx,
458  ctx->transforms, f, flags, file, list_id, local_file_id, true);
459  if (buffer == NULL)
460  continue;
461 
462  if (buffer->inspect_len >= mpm_ctx->minlen) {
463  (void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
464  &det_ctx->mtcu, &det_ctx->pmq,
465  buffer->inspect, buffer->inspect_len);
466  }
467  }
468  }
469 }
470 
471 static void PrefilterMpmFilenameFree(void *ptr)
472 {
473  SCFree(ptr);
474 }
475 
476 static int PrefilterMpmFilenameRegister(DetectEngineCtx *de_ctx,
477  SigGroupHead *sgh, MpmCtx *mpm_ctx,
478  const DetectBufferMpmRegistery *mpm_reg, int list_id)
479 {
480  PrefilterMpmFilename *pectx = SCCalloc(1, sizeof(*pectx));
481  if (pectx == NULL)
482  return -1;
483  pectx->list_id = list_id;
484  pectx->mpm_ctx = mpm_ctx;
485  pectx->transforms = &mpm_reg->transforms;
486 
487  return PrefilterAppendTxEngine(de_ctx, sgh, PrefilterTxFilename,
488  mpm_reg->app_v2.alproto, mpm_reg->app_v2.tx_min_progress,
489  pectx, PrefilterMpmFilenameFree, mpm_reg->pname);
490 }
491 
492 #ifdef UNITTESTS /* UNITTESTS */
493 
494 /**
495  * \test Test parser accepting valid rules and rejecting invalid rules
496  */
497 static int DetectFilenameSignatureParseTest01(void)
498 {
499  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; sid:1;)", true));
500  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; nocase; sid:1;)", true));
501  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; endswith; sid:1;)", true));
502  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; startswith; sid:1;)", true));
503  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; startswith; endswith; sid:1;)", true));
504  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; bsize:10; sid:1;)", true));
505 
506  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_client; file.name; content:\"abc\"; rawbytes; sid:1;)", false));
507  FAIL_IF_NOT(UTHParseSignature("alert tcp any any -> any any (flow:to_client; file.name; sid:1;)", false));
508  //FAIL_IF_NOT(UTHParseSignature("alert tls any any -> any any (flow:to_client; file.name; content:\"abc\"; sid:1;)", false));
509  PASS;
510 }
511 /**
512  * \test DetectFilenameTestParse01
513  */
514 static int DetectFilenameTestParse01 (void)
515 {
516  DetectFilenameData *dnd = DetectFilenameParse(NULL, "secret.pdf", false);
517  if (dnd != NULL) {
518  DetectFilenameFree(NULL, dnd);
519  return 1;
520  }
521  return 0;
522 }
523 
524 /**
525  * \test DetectFilenameTestParse02
526  */
527 static int DetectFilenameTestParse02 (void)
528 {
529  int result = 0;
530 
531  DetectFilenameData *dnd = DetectFilenameParse(NULL, "backup.tar.gz", false);
532  if (dnd != NULL) {
533  if (dnd->len == 13 && memcmp(dnd->name, "backup.tar.gz", 13) == 0) {
534  result = 1;
535  }
536 
537  DetectFilenameFree(NULL, dnd);
538  return result;
539  }
540  return 0;
541 }
542 
543 /**
544  * \test DetectFilenameTestParse03
545  */
546 static int DetectFilenameTestParse03 (void)
547 {
548  int result = 0;
549 
550  DetectFilenameData *dnd = DetectFilenameParse(NULL, "cmd.exe", false);
551  if (dnd != NULL) {
552  if (dnd->len == 7 && memcmp(dnd->name, "cmd.exe", 7) == 0) {
553  result = 1;
554  }
555 
556  DetectFilenameFree(NULL, dnd);
557  return result;
558  }
559  return 0;
560 }
561 
562 
563 /**
564  * \brief this function registers unit tests for DetectFilename
565  */
566 void DetectFilenameRegisterTests(void)
567 {
568  UtRegisterTest("DetectFilenameSignatureParseTest01", DetectFilenameSignatureParseTest01);
569 
570  UtRegisterTest("DetectFilenameTestParse01", DetectFilenameTestParse01);
571  UtRegisterTest("DetectFilenameTestParse02", DetectFilenameTestParse02);
572  UtRegisterTest("DetectFilenameTestParse03", DetectFilenameTestParse03);
573 }
574 #endif /* UNITTESTS */
DetectEngineAppInspectionEngine_
Definition: detect.h:402
SigTableElmt_::url
const char * url
Definition: detect.h:1214
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
FileContainer_
Definition: util-file.h:100
MpmCtx_::mpm_type
uint8_t mpm_type
Definition: util-mpm.h:90
DetectEngineThreadCtx_::buffer_offset
uint32_t buffer_offset
Definition: detect.h:1041
detect-engine.h
SIGMATCH_INFO_STICKY_BUFFER
#define SIGMATCH_INFO_STICKY_BUFFER
Definition: detect.h:1404
DetectFileInspectGeneric
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.
Definition: detect-engine-file.c:219
SigTableElmt_::desc
const char * desc
Definition: detect.h:1213
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1201
flow-util.h
SigTableElmt_::name
const char * name
Definition: detect.h:1211
stream-tcp.h
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1347
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms
Definition: detect.h:376
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:1392
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:73
DetectBufferMpmRegistery_::transforms
DetectEngineTransforms transforms
Definition: detect.h:624
InspectionBuffer
Definition: detect.h:344
threads.h
Flow_
Flow data structure.
Definition: flow.h:347
SigTableElmt_::FileMatch
int(* FileMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, File *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1187
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1111
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1205
PrefilterMpmFilename::transforms
const DetectEngineTransforms * transforms
Definition: detect-filename.c:427
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:767
AppLayerParserGetFiles
FileContainer * AppLayerParserGetFiles(const Flow *f, const uint8_t direction)
Definition: app-layer-parser.c:858
ALPROTO_FTP
@ ALPROTO_FTP
Definition: app-layer-protos.h:31
DetectBufferMpmRegistery_
one time registration of keywords at start up
Definition: detect.h:611
FILE_SIG_NEED_FILENAME
#define FILE_SIG_NEED_FILENAME
Definition: detect.h:285
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:104
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:1196
detect-engine-prefilter.h
DetectEngineThreadCtx_::mtcu
MpmThreadCtx mtcu
Definition: detect.h:1109
util-unittest.h
detect-filename.h
util-unittest-helper.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression to true.
Definition: util-unittest.h:82
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:880
File_::name_len
uint16_t name_len
Definition: util-file.h:65
DetectEngineAppInspectionEngine_::sm_list
uint16_t sm_list
Definition: detect.h:408
DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
Definition: detect-engine-state.h:44
InspectionBufferMultipleForList
Definition: detect.h:364
PrefilterMpmFilename::list_id
int list_id
Definition: detect-filename.c:425
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:1010
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:101
detect.h
DetectEngineAppInspectionEngine_::mpm
uint16_t mpm
Definition: detect.h:406
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:346
DETECT_FILENAME
@ DETECT_FILENAME
Definition: detect-engine-register.h:197
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1209
app-layer-parser.h
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:99
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:323
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:350
Packet_
Definition: decode.h:414
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:232
SIGMATCH_HANDLE_NEGATION
#define SIGMATCH_HANDLE_NEGATION
Definition: detect.h:1400
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:597
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:316
File_::name
uint8_t * name
Definition: util-file.h:73
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
SignatureInitData_::negated
bool negated
Definition: detect.h:485
MpmTableElmt_::Search
uint32_t(* Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint32_t)
Definition: util-mpm.h:162
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:235
PrefilterMpmFilename::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-filename.c:426
SigMatch_::type
uint8_t type
Definition: detect.h:321
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:315
DetectEngineThreadCtx_::discontinue_matching
uint16_t discontinue_matching
Definition: detect.h:1076
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:426
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:63
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:198
DETECT_CI_FLAGS_SINGLE
#define DETECT_CI_FLAGS_SINGLE
Definition: detect-engine-content-inspection.h:46
DetectBufferMpmRegistery_::pname
char pname[32]
Definition: detect.h:613
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
PrefilterMpmFilename
struct PrefilterMpmFilename PrefilterMpmFilename
InspectionBufferSetup
void InspectionBufferSetup(InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
Definition: detect-engine.c:1120
Signature_::file_flags
uint8_t file_flags
Definition: detect.h:542
InspectionBufferApplyTransforms
void InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
Definition: detect-engine.c:1211
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
DetectEngineThreadCtx_::inspection_recursion_counter
int inspection_recursion_counter
Definition: detect.h:1088
File_::next
struct File_ * next
Definition: util-file.h:77
ALPROTO_FTPDATA
@ ALPROTO_FTPDATA
Definition: app-layer-protos.h:47
PrefilterMpmFilename
Definition: detect-filename.c:424
util-spm-bm.h
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:347
DetectBufferMpmRegistery_::app_v2
struct DetectBufferMpmRegistery_::@93::@95 app_v2
InspectionBuffer::inspect
const uint8_t * inspect
Definition: detect.h:345
str
#define str(s)
Definition: suricata-common.h:273
SCFree
#define SCFree(p)
Definition: util-mem.h:61
detect-parse.h
Signature_
Signature container.
Definition: detect.h:528
SigMatch_
a single match condition for a signature
Definition: detect.h:320
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:257
DetectEngineAppInspectionEngine_::transforms
const DetectEngineTransforms * transforms
Definition: detect.h:423
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition: app-layer-protos.h:30
mpm_table
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.c:48
InspectionBufferGetMulti
InspectionBufferMultipleForList * InspectionBufferGetMulti(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine.c:1100
FILE_SIG_NEED_FILE
#define FILE_SIG_NEED_FILE
Definition: detect.h:284
File_::txid
uint64_t txid
Definition: util-file.h:68
ALPROTO_SMB
@ ALPROTO_SMB
Definition: app-layer-protos.h:37
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect.h:1380
DetectBufferSetActiveList
int DetectBufferSetActiveList(Signature *s, const int list)
Definition: detect-engine.c:992
DetectBufferTypeSetDescriptionByName
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
Definition: detect-engine.c:908
MpmCtx_
Definition: util-mpm.h:88
flow.h
DetectAppLayerInspectEngineRegister
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback)
register inspect engine at start up time
Definition: detect-engine.c:171
DetectFilenameRegister
void DetectFilenameRegister(void)
Registration function for keyword: filename.
Definition: detect-filename.c:80
DetectEngineAppInspectionEngine_::v2
struct DetectEngineAppInspectionEngine_::@91 v2
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
DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
Definition: detect-engine-content-inspection.h:35
BoyerMooreNocaseCtxInit
BmCtx * BoyerMooreNocaseCtxInit(uint8_t *needle, uint16_t needle_len)
Setup a Booyer Moore context for nocase search.
Definition: util-spm-bm.c:106
SCLogDebugEnabled
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
Definition: util-debug.c:662
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
InspectionBufferMultipleForListGet
InspectionBuffer * InspectionBufferMultipleForListGet(InspectionBufferMultipleForList *fb, uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
Definition: detect-engine.c:1074
debug.h
DetectFilenameData::flags
uint32_t flags
Definition: detect-filename.h:33
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1203
app-layer.h
BoyerMooreCtxDeInit
void BoyerMooreCtxDeInit(BmCtx *bmctx)
Free the memory allocated to Booyer Moore context.
Definition: util-spm-bm.c:120