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(DetectEngineCtx *, 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(
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 = "/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 = "/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 de_ctx Pointer to the detection engine context
219  * \param idstr Pointer to the user provided option
220  *
221  * \retval filename pointer to DetectFilenameData on success
222  * \retval NULL on failure
223  */
224 static DetectFilenameData *DetectFilenameParse (DetectEngineCtx *de_ctx, const char *str, bool negate)
225 {
226  DetectFilenameData *filename = NULL;
227 
228  /* We have a correct filename option */
229  filename = SCMalloc(sizeof(DetectFilenameData));
230  if (unlikely(filename == NULL))
231  goto error;
232 
233  memset(filename, 0x00, sizeof(DetectFilenameData));
234 
235  if (DetectContentDataParse ("filename", str, &filename->name, &filename->len) == -1) {
236  goto error;
237  }
238 
239  filename->bm_ctx = BoyerMooreNocaseCtxInit(filename->name, filename->len);
240  if (filename->bm_ctx == NULL) {
241  goto error;
242  }
243 
244  if (negate) {
245  filename->flags |= DETECT_CONTENT_NEGATED;
246  }
247 
248  SCLogDebug("flags %02X", filename->flags);
249  if (filename->flags & DETECT_CONTENT_NEGATED) {
250  SCLogDebug("negated filename");
251  }
252 
253 #ifdef DEBUG
254  if (SCLogDebugEnabled()) {
255  char *name = SCMalloc(filename->len + 1);
256  if (name != NULL) {
257  memcpy(name, filename->name, filename->len);
258  name[filename->len] = '\0';
259  SCLogDebug("will look for filename %s", name);
260  SCFree(name);
261  }
262  }
263 #endif
264 
265  return filename;
266 
267 error:
268  if (filename != NULL)
269  DetectFilenameFree(de_ctx, filename);
270  return NULL;
271 }
272 
273 /**
274  * \brief this function is used to parse filename options
275  * \brief into the current signature
276  *
277  * \param de_ctx pointer to the Detection Engine Context
278  * \param s pointer to the Current Signature
279  * \param str pointer to the user provided "filename" option
280  *
281  * \retval 0 on Success
282  * \retval -1 on Failure
283  */
284 static int DetectFilenameSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
285 {
286  DetectFilenameData *filename = NULL;
287  SigMatch *sm = NULL;
288 
289  filename = DetectFilenameParse(de_ctx, str, s->init_data->negated);
290  if (filename == NULL)
291  goto error;
292 
293  /* Okay so far so good, lets get this into a SigMatch
294  * and put it in the Signature. */
295  sm = SigMatchAlloc();
296  if (sm == NULL)
297  goto error;
298 
299  sm->type = DETECT_FILENAME;
300  sm->ctx = (void *)filename;
301 
302  SigMatchAppendSMToList(s, sm, g_file_match_list_id);
303 
305  return 0;
306 
307 error:
308  if (filename != NULL)
309  DetectFilenameFree(de_ctx, filename);
310  if (sm != NULL)
311  SCFree(sm);
312  return -1;
313 }
314 
315 /**
316  * \brief this function will free memory associated with DetectFilenameData
317  *
318  * \param filename pointer to DetectFilenameData
319  */
320 static void DetectFilenameFree(DetectEngineCtx *de_ctx, void *ptr)
321 {
322  if (ptr != NULL) {
323  DetectFilenameData *filename = (DetectFilenameData *)ptr;
324  if (filename->bm_ctx != NULL) {
325  BoyerMooreCtxDeInit(filename->bm_ctx);
326  }
327  if (filename->name != NULL)
328  SCFree(filename->name);
329  SCFree(filename);
330  }
331 }
332 
333 /* file.name implementation */
334 
335 /**
336  * \brief this function setup the file.data keyword used in the rule
337  *
338  * \param de_ctx Pointer to the Detection Engine Context
339  * \param s Pointer to the Signature to which the current keyword belongs
340  * \param str Should hold an empty string always
341  *
342  * \retval 0 On success
343  */
344 static int DetectFilenameSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str)
345 {
346  if (DetectBufferSetActiveList(s, g_file_name_buffer_id) < 0)
347  return -1;
348  return 0;
349 }
350 
351 static InspectionBuffer *FilenameGetDataCallback(DetectEngineThreadCtx *det_ctx,
352  const DetectEngineTransforms *transforms,
353  Flow *f, uint8_t flow_flags, File *cur_file,
354  int list_id, int local_file_id, bool first)
355 {
356  SCEnter();
357 
359  InspectionBuffer *buffer = InspectionBufferMultipleForListGet(fb, local_file_id);
360  if (buffer == NULL)
361  return NULL;
362  if (!first && buffer->inspect != NULL)
363  return buffer;
364 
365  const uint8_t *data = cur_file->name;
366  uint32_t data_len = cur_file->name_len;
367 
368  InspectionBufferSetup(buffer, data, data_len);
369  InspectionBufferApplyTransforms(buffer, transforms);
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  int local_file_id = 0;
447  if (ffc != NULL) {
448  File *file = ffc->head;
449  for (; file != NULL; file = file->next) {
450  if (file->txid != idx)
451  continue;
452 
453  InspectionBuffer *buffer = FilenameGetDataCallback(det_ctx,
454  ctx->transforms, f, flags, file, list_id, local_file_id, true);
455  if (buffer == NULL)
456  continue;
457 
458  if (buffer->inspect_len >= mpm_ctx->minlen) {
459  (void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
460  &det_ctx->mtcu, &det_ctx->pmq,
461  buffer->inspect, buffer->inspect_len);
462  }
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 #endif /* UNITTESTS */
559 
560 /**
561  * \brief this function registers unit tests for DetectFilename
562  */
563 void DetectFilenameRegisterTests(void)
564 {
565 #ifdef UNITTESTS /* UNITTESTS */
566  UtRegisterTest("DetectFilenameSignatureParseTest01", DetectFilenameSignatureParseTest01);
567 
568  UtRegisterTest("DetectFilenameTestParse01", DetectFilenameTestParse01);
569  UtRegisterTest("DetectFilenameTestParse02", DetectFilenameTestParse02);
570  UtRegisterTest("DetectFilenameTestParse03", DetectFilenameTestParse03);
571 #endif /* UNITTESTS */
572 }
DetectEngineAppInspectionEngine_
Definition: detect.h:401
SigTableElmt_::url
const char * url
Definition: detect.h:1212
UTHParseSignature
int UTHParseSignature(const char *str, bool expect)
parser a sig and see if the expected result is correct
Definition: util-unittest-helper.c:957
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:1040
detect-engine.h
SIGMATCH_INFO_STICKY_BUFFER
#define SIGMATCH_INFO_STICKY_BUFFER
Definition: detect.h:1402
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:1211
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1200
flow-util.h
SigTableElmt_::name
const char * name
Definition: detect.h:1209
stream-tcp.h
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1345
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms
Definition: detect.h:375
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:1390
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:71
DetectBufferMpmRegistery_::transforms
DetectEngineTransforms transforms
Definition: detect.h:623
InspectionBuffer
Definition: detect.h:343
threads.h
Flow_
Flow data structure.
Definition: flow.h:343
SigTableElmt_::FileMatch
int(* FileMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, File *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1186
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1110
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1203
PrefilterMpmFilename::transforms
const DetectEngineTransforms * transforms
Definition: detect-filename.c:423
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:766
AppLayerParserGetFiles
FileContainer * AppLayerParserGetFiles(const Flow *f, const uint8_t direction)
Definition: app-layer-parser.c:864
ALPROTO_FTP
@ ALPROTO_FTP
Definition: app-layer-protos.h:31
DetectBufferMpmRegistery_
one time registration of keywords at start up
Definition: detect.h:610
FILE_SIG_NEED_FILENAME
#define FILE_SIG_NEED_FILENAME
Definition: detect.h:284
m
SCMutex m
Definition: flow-hash.h:3
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:103
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:1195
detect-engine-prefilter.h
DetectEngineThreadCtx_::mtcu
MpmThreadCtx mtcu
Definition: detect.h:1108
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:876
File_::name_len
uint16_t name_len
Definition: util-file.h:65
DetectEngineAppInspectionEngine_::sm_list
uint16_t sm_list
Definition: detect.h:407
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:363
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:1009
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:405
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:345
DETECT_FILENAME
@ DETECT_FILENAME
Definition: detect-engine-register.h:181
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1207
app-layer-parser.h
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:99
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:322
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:411
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:231
SIGMATCH_HANDLE_NEGATION
#define SIGMATCH_HANDLE_NEGATION
Definition: detect.h:1398
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:596
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:484
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:422
SigMatch_::type
uint8_t type
Definition: detect.h:320
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:314
DetectEngineThreadCtx_::discontinue_matching
uint16_t discontinue_matching
Definition: detect.h:1075
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:425
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:78
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:182
DETECT_CI_FLAGS_SINGLE
#define DETECT_CI_FLAGS_SINGLE
Definition: detect-engine-content-inspection.h:46
DetectBufferMpmRegistery_::pname
char pname[32]
Definition: detect.h:612
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:1116
Signature_::file_flags
uint8_t file_flags
Definition: detect.h:541
InspectionBufferApplyTransforms
void InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
Definition: detect-engine.c:1207
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
DetectEngineThreadCtx_::inspection_recursion_counter
int inspection_recursion_counter
Definition: detect.h:1087
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:420
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:346
DetectBufferMpmRegistery_::app_v2
struct DetectBufferMpmRegistery_::@93::@95 app_v2
InspectionBuffer::inspect
const uint8_t * inspect
Definition: detect.h:344
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:527
SigMatch_
a single match condition for a signature
Definition: detect.h:319
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:422
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:1096
FILE_SIG_NEED_FILE
#define FILE_SIG_NEED_FILE
Definition: detect.h:283
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:1378
DetectBufferSetActiveList
int DetectBufferSetActiveList(Signature *s, const int list)
Definition: detect-engine.c:988
DetectBufferTypeSetDescriptionByName
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
Definition: detect-engine.c:904
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:170
DetectFilenameRegister
void DetectFilenameRegister(void)
Registration function for keyword: filename.
Definition: detect-filename.c:78
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:1070
debug.h
DetectFilenameData::flags
uint32_t flags
Definition: detect-filename.h:33
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1201
app-layer.h
BoyerMooreCtxDeInit
void BoyerMooreCtxDeInit(BmCtx *bmctx)
Free the memory allocated to Booyer Moore context.
Definition: util-spm-bm.c:120