suricata
detect-file-data.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2018 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  *
23  */
24 
25 #include "suricata-common.h"
26 #include "threads.h"
27 #include "debug.h"
28 #include "decode.h"
29 
30 #include "detect.h"
31 #include "detect-parse.h"
32 
33 #include "detect-engine.h"
34 #include "detect-engine-mpm.h"
35 #include "detect-engine-state.h"
38 #include "detect-file-data.h"
39 
40 #include "app-layer-parser.h"
41 #include "app-layer-htp.h"
42 #include "app-layer-smtp.h"
43 
44 #include "flow.h"
45 #include "flow-var.h"
46 #include "flow-util.h"
47 
48 #include "util-debug.h"
49 #include "util-spm-bm.h"
50 #include "util-unittest.h"
51 #include "util-unittest-helper.h"
53 
54 static int DetectFiledataSetup (DetectEngineCtx *, Signature *, const char *);
55 #ifdef UNITTESTS
56 static void DetectFiledataRegisterTests(void);
57 #endif
58 static void DetectFiledataSetupCallback(const DetectEngineCtx *de_ctx,
59  Signature *s);
60 static int g_file_data_buffer_id = 0;
61 
62 /* HTTP */
63 static InspectionBuffer *HttpServerBodyGetDataCallback(DetectEngineThreadCtx *det_ctx,
64  const DetectEngineTransforms *transforms,
65  Flow *f, const uint8_t flow_flags,
66  void *txv, const int list_id);
67 
68 /* file API */
69 static int DetectEngineInspectFiledata(
71  const DetectEngineAppInspectionEngine *engine,
72  const Signature *s,
73  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id);
75  SigGroupHead *sgh, MpmCtx *mpm_ctx,
76  const DetectBufferMpmRegistery *mpm_reg, int list_id);
77 
78 /**
79  * \brief Registration function for keyword: file_data
80  */
82 {
83  sigmatch_table[DETECT_FILE_DATA].name = "file.data";
84  sigmatch_table[DETECT_FILE_DATA].alias = "file_data";
85  sigmatch_table[DETECT_FILE_DATA].desc = "make content keywords match on file data";
86  sigmatch_table[DETECT_FILE_DATA].url = "/rules/http-keywords.html#file-data";
87  sigmatch_table[DETECT_FILE_DATA].Setup = DetectFiledataSetup;
88 #ifdef UNITTESTS
90 #endif
92 
95  ALPROTO_SMTP, 0);
98  HttpServerBodyGetDataCallback,
99  ALPROTO_HTTP, HTP_RESPONSE_BODY);
102  ALPROTO_SMB, 0);
105  ALPROTO_SMB, 0);
106 
108  ALPROTO_HTTP, SIG_FLAG_TOCLIENT, HTP_RESPONSE_BODY,
109  DetectEngineInspectBufferGeneric, HttpServerBodyGetDataCallback);
112  DetectEngineInspectFiledata, NULL);
114  DetectFiledataSetupCallback);
117  DetectEngineInspectFiledata, NULL);
120  DetectEngineInspectFiledata, NULL);
121 
123  "http response body, smb files or smtp attachments data");
124 
125  g_file_data_buffer_id = DetectBufferTypeGetByName("file_data");
126 }
127 
128 #define FILEDATA_CONTENT_LIMIT 100000
129 #define FILEDATA_CONTENT_INSPECT_MIN_SIZE 32768
130 #define FILEDATA_CONTENT_INSPECT_WINDOW 4096
131 
132 static void SetupDetectEngineConfig(DetectEngineCtx *de_ctx) {
134  return;
135 
136  /* initialize default */
137  for (int i = 0; i < (int)ALPROTO_MAX; i++) {
141  }
142 
143  /* add protocol specific settings here */
144 
145  /* SMTP */
149 
151 }
152 
153 /**
154  * \brief this function is used to parse filedata options
155  * \brief into the current signature
156  *
157  * \param de_ctx pointer to the Detection Engine Context
158  * \param s pointer to the Current Signature
159  * \param str pointer to the user provided "filestore" option
160  *
161  * \retval 0 on Success
162  * \retval -1 on Failure
163  */
164 static int DetectFiledataSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
165 {
166  SCEnter();
167 
168  if (!DetectProtoContainsProto(&s->proto, IPPROTO_TCP) ||
169  (s->alproto != ALPROTO_UNKNOWN && s->alproto != ALPROTO_HTTP &&
170  s->alproto != ALPROTO_SMTP && s->alproto != ALPROTO_SMB)) {
171  SCLogError(SC_ERR_CONFLICTING_RULE_KEYWORDS, "rule contains conflicting keywords.");
172  return -1;
173  }
174 
176  (s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_TOCLIENT)) {
177  SCLogError(SC_ERR_INVALID_SIGNATURE, "Can't use file_data with "
178  "flow:to_server or flow:from_client with http.");
179  return -1;
180  }
181 
183  !(s->flags & SIG_FLAG_TOSERVER) && (s->flags & SIG_FLAG_TOCLIENT)) {
184  SCLogError(SC_ERR_INVALID_SIGNATURE, "Can't use file_data with "
185  "flow:to_client or flow:from_server with smtp.");
186  return -1;
187  }
188 
189  if (DetectBufferSetActiveList(s, DetectBufferTypeGetByName("file_data")) < 0)
190  return -1;
191 
193  SetupDetectEngineConfig(de_ctx);
194  return 0;
195 }
196 
197 static void DetectFiledataSetupCallback(const DetectEngineCtx *de_ctx,
198  Signature *s)
199 {
200  if (s->alproto == ALPROTO_HTTP || s->alproto == ALPROTO_UNKNOWN) {
202  }
203 
204 
205  /* server body needs to be inspected in sync with stream if possible */
207 
208  SCLogDebug("callback invoked by %u", s->id);
209 }
210 
211 /* HTTP based detection */
212 
213 static inline HtpBody *GetResponseBody(htp_tx_t *tx)
214 {
215  HtpTxUserData *htud = (HtpTxUserData *)htp_tx_get_user_data(tx);
216  if (htud == NULL) {
217  SCLogDebug("no htud");
218  return NULL;
219  }
220 
221  return &htud->response_body;
222 }
223 
224 static InspectionBuffer *HttpServerBodyGetDataCallback(DetectEngineThreadCtx *det_ctx,
225  const DetectEngineTransforms *transforms,
226  Flow *f, const uint8_t flow_flags,
227  void *txv, const int list_id)
228 {
229  SCEnter();
230 
231  InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
232  if (buffer->inspect != NULL)
233  return buffer;
234 
235  htp_tx_t *tx = txv;
236  HtpState *htp_state = f->alstate;
237  const uint8_t flags = flow_flags;
238 
239  HtpBody *body = GetResponseBody(tx);
240  if (body == NULL) {
241  return NULL;
242  }
243 
244  /* no new data */
245  if (body->body_inspected == body->content_len_so_far) {
246  SCLogDebug("no new data");
247  return NULL;
248  }
249 
250  HtpBodyChunk *cur = body->first;
251  if (cur == NULL) {
252  SCLogDebug("No http chunks to inspect for this transacation");
253  return NULL;
254  }
255 
256  SCLogDebug("response.body_limit %u response_body.content_len_so_far %"PRIu64
257  ", response.inspect_min_size %"PRIu32", EOF %s, progress > body? %s",
258  htp_state->cfg->response.body_limit,
259  body->content_len_so_far,
260  htp_state->cfg->response.inspect_min_size,
261  flags & STREAM_EOF ? "true" : "false",
262  (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP, tx, flags) > HTP_RESPONSE_BODY) ? "true" : "false");
263 
264  if (!htp_state->cfg->http_body_inline) {
265  /* inspect the body if the transfer is complete or we have hit
266  * our body size limit */
267  if ((htp_state->cfg->response.body_limit == 0 ||
268  body->content_len_so_far < htp_state->cfg->response.body_limit) &&
269  body->content_len_so_far < htp_state->cfg->response.inspect_min_size &&
270  !(AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP, tx, flags) > HTP_RESPONSE_BODY) &&
271  !(flags & STREAM_EOF)) {
272  SCLogDebug("we still haven't seen the entire response body. "
273  "Let's defer body inspection till we see the "
274  "entire body.");
275  return NULL;
276  }
277  }
278 
279  /* get the inspect buffer
280  *
281  * make sure that we have at least the configured inspect_win size.
282  * If we have more, take at least 1/4 of the inspect win size before
283  * the new data.
284  */
285  uint64_t offset = 0;
286  if (body->body_inspected > htp_state->cfg->response.inspect_min_size) {
288  uint64_t inspect_win = body->content_len_so_far - body->body_inspected;
289  SCLogDebug("inspect_win %"PRIu64, inspect_win);
290  if (inspect_win < htp_state->cfg->response.inspect_window) {
291  uint64_t inspect_short = htp_state->cfg->response.inspect_window - inspect_win;
292  if (body->body_inspected < inspect_short)
293  offset = 0;
294  else
295  offset = body->body_inspected - inspect_short;
296  } else {
297  offset = body->body_inspected - (htp_state->cfg->response.inspect_window / 4);
298  }
299  }
300 
301  const uint8_t *data;
302  uint32_t data_len;
303 
305  &data, &data_len, offset);
306  InspectionBufferSetup(buffer, data, data_len);
307  buffer->inspect_offset = offset;
308 
309  /* built-in 'transformation' */
310  if (htp_state->cfg->swf_decompression_enabled) {
311  int swf_file_type = FileIsSwfFile(data, data_len);
312  if (swf_file_type == FILE_SWF_ZLIB_COMPRESSION ||
313  swf_file_type == FILE_SWF_LZMA_COMPRESSION)
314  {
315  (void)FileSwfDecompression(data, data_len,
316  det_ctx,
317  buffer,
318  htp_state->cfg->swf_compression_type,
319  htp_state->cfg->swf_decompress_depth,
320  htp_state->cfg->swf_compress_depth);
321  }
322  }
323 
324  /* move inspected tracker to end of the data. HtpBodyPrune will consider
325  * the window sizes when freeing data */
326  body->body_inspected = body->content_len_so_far;
327  SCLogDebug("body->body_inspected now: %"PRIu64, body->body_inspected);
328 
329  SCReturnPtr(buffer, "InspectionBuffer");
330 }
331 
332 /* file API based inspection */
333 
334 static InspectionBuffer *FiledataGetDataCallback(DetectEngineThreadCtx *det_ctx,
335  const DetectEngineTransforms *transforms,
336  Flow *f, uint8_t flow_flags, File *cur_file,
337  int list_id, int local_file_id, bool first)
338 {
339  SCEnter();
340 
342  InspectionBuffer *buffer = InspectionBufferMultipleForListGet(fb, local_file_id);
343  if (buffer == NULL)
344  return NULL;
345  if (!first && buffer->inspect != NULL)
346  return buffer;
347 
348  const uint64_t file_size = FileDataSize(cur_file);
349  const DetectEngineCtx *de_ctx = det_ctx->de_ctx;
350  const uint32_t content_limit = de_ctx->filedata_config[f->alproto].content_limit;
351  const uint32_t content_inspect_min_size = de_ctx->filedata_config[f->alproto].content_inspect_min_size;
352  // TODO this is unused, is that right?
353  //const uint32_t content_inspect_window = de_ctx->filedata_config[f->alproto].content_inspect_window;
354 
355  SCLogDebug("content_limit %u, content_inspect_min_size %u",
356  content_limit, content_inspect_min_size);
357 
358  SCLogDebug("file %p size %"PRIu64", state %d", cur_file, file_size, cur_file->state);
359 
360  /* no new data */
361  if (cur_file->content_inspected == file_size) {
362  SCLogDebug("no new data");
363  return NULL;
364  }
365 
366  if (file_size == 0) {
367  SCLogDebug("no data to inspect for this transaction");
368  return NULL;
369  }
370 
371  if ((content_limit == 0 || file_size < content_limit) &&
372  file_size < content_inspect_min_size &&
373  !(flow_flags & STREAM_EOF) && !(cur_file->state > FILE_STATE_OPENED)) {
374  SCLogDebug("we still haven't seen the entire content. "
375  "Let's defer content inspection till we see the "
376  "entire content.");
377  return NULL;
378  }
379 
380  const uint8_t *data;
381  uint32_t data_len;
382 
384  &data, &data_len,
385  cur_file->content_inspected);
386  InspectionBufferSetup(buffer, data, data_len);
387  buffer->inspect_offset = cur_file->content_inspected;
388  InspectionBufferApplyTransforms(buffer, transforms);
389 
390  /* update inspected tracker */
391  cur_file->content_inspected = file_size;
392  SCLogDebug("content_inspected %"PRIu64, cur_file->content_inspected);
393 
394  SCLogDebug("file_data buffer %p, data %p len %u offset %"PRIu64,
395  buffer, buffer->inspect, buffer->inspect_len, buffer->inspect_offset);
396 
397  SCReturnPtr(buffer, "InspectionBuffer");
398 }
399 
400 static int DetectEngineInspectFiledata(
402  const DetectEngineAppInspectionEngine *engine,
403  const Signature *s,
404  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
405 {
406  int r = 0;
407  int match = 0;
408 
409  const DetectEngineTransforms *transforms = NULL;
410  if (!engine->mpm) {
411  transforms = engine->v2.transforms;
412  }
413 
415  if (ffc == NULL) {
417  }
418 
419  int local_file_id = 0;
420  File *file = ffc->head;
421  for (; file != NULL; file = file->next) {
422  if (file->txid != tx_id)
423  continue;
424 
425  InspectionBuffer *buffer = FiledataGetDataCallback(det_ctx,
426  transforms, f, flags, file, engine->sm_list, local_file_id, false);
427  if (buffer == NULL)
428  continue;
429 
430  bool eof = (file->state == FILE_STATE_CLOSED);
431  uint8_t ciflags = eof ? DETECT_CI_FLAGS_END : 0;
432  if (buffer->inspect_offset == 0)
433  ciflags |= DETECT_CI_FLAGS_START;
434 
435  det_ctx->buffer_offset = 0;
436  det_ctx->discontinue_matching = 0;
437  det_ctx->inspection_recursion_counter = 0;
438  match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
439  NULL, f,
440  (uint8_t *)buffer->inspect,
441  buffer->inspect_len,
442  buffer->inspect_offset, ciflags,
444  if (match == 1) {
445  r = 1;
446  break;
447  }
448  local_file_id++;
449  }
450 
451  if (r == 1)
453  else
455 }
456 
457 typedef struct PrefilterMpmFiledata {
458  int list_id;
459  const MpmCtx *mpm_ctx;
462 
463 /** \brief Filedata Filedata Mpm prefilter callback
464  *
465  * \param det_ctx detection engine thread ctx
466  * \param pectx inspection context
467  * \param p packet to inspect
468  * \param f flow to inspect
469  * \param txv tx to inspect
470  * \param idx transaction id
471  * \param flags STREAM_* flags including direction
472  */
473 static void PrefilterTxFiledata(DetectEngineThreadCtx *det_ctx,
474  const void *pectx,
475  Packet *p, Flow *f, void *txv,
476  const uint64_t idx, const uint8_t flags)
477 {
478  SCEnter();
479 
480  const PrefilterMpmFiledata *ctx = (const PrefilterMpmFiledata *)pectx;
481  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
482  const int list_id = ctx->list_id;
483 
485  int local_file_id = 0;
486  if (ffc != NULL) {
487  File *file = ffc->head;
488  for (; file != NULL; file = file->next) {
489  if (file->txid != idx)
490  continue;
491 
492  InspectionBuffer *buffer = FiledataGetDataCallback(det_ctx,
493  ctx->transforms, f, flags, file, list_id, local_file_id, true);
494  if (buffer == NULL)
495  continue;
496 
497  if (buffer->inspect_len >= mpm_ctx->minlen) {
498  (void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
499  &det_ctx->mtcu, &det_ctx->pmq,
500  buffer->inspect, buffer->inspect_len);
501  }
502  local_file_id++;
503  }
504  }
505 }
506 
507 static void PrefilterMpmFiledataFree(void *ptr)
508 {
509  SCFree(ptr);
510 }
511 
513  SigGroupHead *sgh, MpmCtx *mpm_ctx,
514  const DetectBufferMpmRegistery *mpm_reg, int list_id)
515 {
516  PrefilterMpmFiledata *pectx = SCCalloc(1, sizeof(*pectx));
517  if (pectx == NULL)
518  return -1;
519  pectx->list_id = list_id;
520  pectx->mpm_ctx = mpm_ctx;
521  pectx->transforms = &mpm_reg->transforms;
522 
523  return PrefilterAppendTxEngine(de_ctx, sgh, PrefilterTxFiledata,
524  mpm_reg->app_v2.alproto, mpm_reg->app_v2.tx_min_progress,
525  pectx, PrefilterMpmFiledataFree, mpm_reg->pname);
526 }
527 
528 #ifdef UNITTESTS
529 #include "tests/detect-file-data.c"
530 #endif
HtpState_::cfg
const struct HTPCfgRec_ * cfg
Definition: app-layer-htp.h:257
SMTPConfig::content_limit
uint32_t content_limit
Definition: app-layer-smtp.h:100
DetectEngineAppInspectionEngine_
Definition: detect.h:401
SigTableElmt_::url
const char * url
Definition: detect.h:1212
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
SigTableElmt_::desc
const char * desc
Definition: detect.h:1211
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
DETECT_CI_FLAGS_START
#define DETECT_CI_FLAGS_START
Definition: detect-engine-content-inspection.h:38
flow-util.h
FILE_SWF_LZMA_COMPRESSION
@ FILE_SWF_LZMA_COMPRESSION
Definition: util-file-decompression.h:34
SCFPSupportSMList_::list_id
int list_id
Definition: detect-fast-pattern.h:29
SigTableElmt_::name
const char * name
Definition: detect.h:1209
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1345
HtpBody_::sb
StreamingBuffer * sb
Definition: app-layer-htp.h:187
SIG_FLAG_INIT_FLOW
#define SIG_FLAG_INIT_FLOW
Definition: detect.h:258
DetectEngineTransforms
Definition: detect.h:375
HTPCfgRec_::response
HTPCfgDir response
Definition: app-layer-htp.h:171
SIG_FLAG_INIT_NEED_FLUSH
#define SIG_FLAG_INIT_NEED_FLUSH
Definition: detect.h:263
FILEDATA_CONTENT_LIMIT
#define FILEDATA_CONTENT_LIMIT
Definition: detect-file-data.c:128
Signature_::alproto
AppProto alproto
Definition: detect.h:531
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
SIG_FLAG_INIT_FILEDATA
#define SIG_FLAG_INIT_FILEDATA
Definition: detect.h:265
HTPCfgDir_::body_limit
uint32_t body_limit
Definition: app-layer-htp.h:147
FILEDATA_CONTENT_INSPECT_WINDOW
#define FILEDATA_CONTENT_INSPECT_WINDOW
Definition: detect-file-data.c:130
DetectBufferMpmRegistery_::transforms
DetectEngineTransforms transforms
Definition: detect.h:623
AppLayerParserGetStateProgress
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t flags)
get the progress value for a tx/protocol
Definition: app-layer-parser.c:1013
FileSwfDecompression
int FileSwfDecompression(const uint8_t *buffer, uint32_t buffer_len, DetectEngineThreadCtx *det_ctx, InspectionBuffer *out_buffer, int swf_type, uint32_t decompress_depth, uint32_t compress_depth)
This function decompresses a buffer with zlib/lzma algorithm.
Definition: util-file-decompression.c:71
InspectionBuffer
Definition: detect.h:343
threads.h
FILE_STATE_OPENED
@ FILE_STATE_OPENED
Definition: util-file.h:54
Flow_
Flow data structure.
Definition: flow.h:343
File_::state
FileState state
Definition: util-file.h:66
DetectBufferTypeRegisterSetupCallback
void DetectBufferTypeRegisterSetupCallback(const char *name, void(*SetupCallback)(const DetectEngineCtx *, Signature *))
Definition: detect-engine.c:949
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1110
PrefilterGenericMpmRegister
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistery *mpm_reg, int list_id)
Definition: detect-engine-prefilter.c:611
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1203
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:766
SC_ERR_INVALID_SIGNATURE
@ SC_ERR_INVALID_SIGNATURE
Definition: util-error.h:69
AppLayerParserGetFiles
FileContainer * AppLayerParserGetFiles(const Flow *f, const uint8_t direction)
Definition: app-layer-parser.c:864
detect-file-data.h
DetectBufferMpmRegistery_
one time registration of keywords at start up
Definition: detect.h:610
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:492
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
HTPCfgRec_::swf_compress_depth
uint32_t swf_compress_depth
Definition: app-layer-htp.h:168
StreamingBufferGetDataAtOffset
int StreamingBufferGetDataAtOffset(const StreamingBuffer *sb, const uint8_t **data, uint32_t *data_len, uint64_t offset)
Definition: util-streaming-buffer.c:866
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:237
ALPROTO_MAX
@ ALPROTO_MAX
Definition: app-layer-protos.h:66
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1195
PrefilterMpmFiledata
struct PrefilterMpmFiledata PrefilterMpmFiledata
DetectEngineCtx_::content_inspect_window
uint32_t content_inspect_window
Definition: detect.h:883
FILE_SWF_ZLIB_COMPRESSION
@ FILE_SWF_ZLIB_COMPRESSION
Definition: util-file-decompression.h:33
detect-engine-prefilter.h
HTPCfgDir_::inspect_window
uint32_t inspect_window
Definition: app-layer-htp.h:149
DetectEngineThreadCtx_::mtcu
MpmThreadCtx mtcu
Definition: detect.h:1108
util-unittest.h
InspectionBufferGet
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine.c:1057
HtpBody_::first
HtpBodyChunk * first
Definition: app-layer-htp.h:184
HtpState_
Definition: app-layer-htp.h:247
SMTPConfig::content_inspect_min_size
uint32_t content_inspect_min_size
Definition: app-layer-smtp.h:101
util-unittest-helper.h
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:876
File_::sb
StreamingBuffer * sb
Definition: util-file.h:67
HtpBody_::content_len_so_far
uint64_t content_len_so_far
Definition: app-layer-htp.h:190
DetectEngineAppInspectionEngine_::sm_list
uint16_t sm_list
Definition: detect.h:407
InspectionBufferMultipleForList
Definition: detect.h:363
PrefilterMpmFiledata::transforms
const DetectEngineTransforms * transforms
Definition: detect-file-data.c:460
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:236
app-layer-htp.h
decode.h
util-debug.h
HTPCfgRec_::http_body_inline
int http_body_inline
Definition: app-layer-htp.h:163
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1009
HTPCfgDir_::inspect_min_size
uint32_t inspect_min_size
Definition: app-layer-htp.h:148
ALPROTO_SMTP
@ ALPROTO_SMTP
Definition: app-layer-protos.h:32
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
detect-engine-mpm.h
FileContainer_::head
File * head
Definition: util-file.h:101
detect.h
PrefilterMpmFiledataRegister
int PrefilterMpmFiledataRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistery *mpm_reg, int list_id)
Definition: detect-file-data.c:512
HTPCfgRec_::swf_decompress_depth
uint32_t swf_decompress_depth
Definition: app-layer-htp.h:167
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
PrefilterMpmFiledata::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-file-data.c:459
DetectFiledataRegister
void DetectFiledataRegister(void)
Registration function for keyword: file_data.
Definition: detect-file-data.c:81
HTPCfgRec_::swf_decompression_enabled
int swf_decompression_enabled
Definition: app-layer-htp.h:165
InspectionBuffer::inspect_offset
uint64_t inspect_offset
Definition: detect.h:345
app-layer-parser.h
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:99
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:282
smtp_config
SMTPConfig smtp_config
Definition: app-layer-smtp.c:240
Signature_::flags
uint32_t flags
Definition: detect.h:528
DetectEngineInspectBufferGeneric
int DetectEngineInspectBufferGeneric(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:1637
Packet_
Definition: decode.h:411
DETECT_CI_FLAGS_END
#define DETECT_CI_FLAGS_END
Definition: detect-engine-content-inspection.h:39
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
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:596
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:316
FileIsSwfFile
int FileIsSwfFile(const uint8_t *buffer, uint32_t buffer_len)
Definition: util-file-decompression.c:41
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
AppLayerHtpEnableResponseBodyCallback
void AppLayerHtpEnableResponseBodyCallback(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request body...
Definition: app-layer-htp.c:483
HTPCfgRec_::swf_compression_type
HtpSwfCompressType swf_compression_type
Definition: app-layer-htp.h:166
MpmTableElmt_::Search
uint32_t(* Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint32_t)
Definition: util-mpm.h:162
HtpTxUserData_::response_body
HtpBody response_body
Definition: app-layer-htp.h:222
DETECT_FILE_DATA
@ DETECT_FILE_DATA
Definition: detect-engine-register.h:170
FileDataSize
uint64_t FileDataSize(const File *file)
get the size of the file data
Definition: util-file.c:291
detect-engine-content-inspection.h
DetectEngineThreadCtx_::discontinue_matching
uint16_t discontinue_matching
Definition: detect.h:1075
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:425
File_::content_inspected
uint64_t content_inspected
Definition: util-file.h:86
FILE_STATE_CLOSED
@ FILE_STATE_CLOSED
Definition: util-file.h:55
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
HtpBody_
Definition: app-layer-htp.h:183
DetectEngineCtx_::filedata_config
struct DetectEngineCtx_::@97 filedata_config[ALPROTO_MAX]
DetectBufferMpmRegistery_::pname
char pname[32]
Definition: detect.h:612
flags
uint8_t flags
Definition: decode-gre.h:0
Signature_::proto
DetectProto proto
Definition: detect.h:544
SigTableElmt_::alias
const char * alias
Definition: detect.h:1210
suricata-common.h
FILEDATA_CONTENT_INSPECT_MIN_SIZE
#define FILEDATA_CONTENT_INSPECT_MIN_SIZE
Definition: detect-file-data.c:129
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
InspectionBufferApplyTransforms
void InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
Definition: detect-engine.c:1207
HtpBodyChunk_
Definition: app-layer-htp.h:175
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
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
util-spm-bm.h
HtpTxUserData_
Definition: app-layer-htp.h:206
DETECT_ENGINE_INSPECT_SIG_NO_MATCH
#define DETECT_ENGINE_INSPECT_SIG_NO_MATCH
Definition: detect-engine-state.h:38
InspectionBuffer::inspect_len
uint32_t inspect_len
Definition: detect.h:346
DetectBufferMpmRegistery_::app_v2
struct DetectBufferMpmRegistery_::@93::@95 app_v2
DetectFiledataRegisterTests
void DetectFiledataRegisterTests(void)
Definition: detect-file-data.c:512
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
Flow_::alstate
void * alstate
Definition: flow.h:454
Signature_::id
uint32_t id
Definition: detect.h:560
DetectEngineCtx_::content_limit
uint32_t content_limit
Definition: detect.h:881
detect-parse.h
Signature_
Signature container.
Definition: detect.h:527
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
util-file-decompression.h
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition: app-layer-protos.h:30
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
STREAM_EOF
#define STREAM_EOF
Definition: stream.h:30
mpm_table
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.c:48
DetectEngineCtx_::filedata_config_initialized
bool filedata_config_initialized
Definition: detect.h:885
DetectEngineCtx_::content_inspect_min_size
uint32_t content_inspect_min_size
Definition: detect.h:882
DetectEngineThreadCtx_::de_ctx
DetectEngineCtx * de_ctx
Definition: detect.h:1135
InspectionBufferGetMulti
InspectionBufferMultipleForList * InspectionBufferGetMulti(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine.c:1096
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
app-layer-smtp.h
DetectBufferTypeSetDescriptionByName
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
Definition: detect-engine.c:904
PrefilterMpmFiledata
Definition: detect-file-data.c:457
MpmCtx_
Definition: util-mpm.h:88
flow.h
detect-file-data.c
DetectEngineAppInspectionEngine_::v2
struct DetectEngineAppInspectionEngine_::@91 v2
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:425
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
PrefilterMpmFiledata::list_id
int list_id
Definition: detect-file-data.c:458
flow-var.h
DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
Definition: detect-engine-content-inspection.h:35
SMTPConfig::content_inspect_window
uint32_t content_inspect_window
Definition: app-layer-smtp.h:102
InspectionBufferMultipleForListGet
InspectionBuffer * InspectionBufferMultipleForListGet(InspectionBufferMultipleForList *fb, uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
Definition: detect-engine.c:1070
debug.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1201
HtpBody_::body_inspected
uint64_t body_inspected
Definition: app-layer-htp.h:194
DetectProtoContainsProto
int DetectProtoContainsProto(const DetectProto *dp, int proto)
see if a DetectProto contains a certain proto
Definition: detect-engine-proto.c:135
SC_ERR_CONFLICTING_RULE_KEYWORDS
@ SC_ERR_CONFLICTING_RULE_KEYWORDS
Definition: util-error.h:171