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);
108  ALPROTO_HTTP2, HTTP2StateDataClient);
111  ALPROTO_HTTP2, HTTP2StateDataServer);
112 
114  ALPROTO_HTTP, SIG_FLAG_TOCLIENT, HTP_RESPONSE_BODY,
115  DetectEngineInspectBufferGeneric, HttpServerBodyGetDataCallback);
118  DetectEngineInspectFiledata, NULL);
120  DetectFiledataSetupCallback);
123  DetectEngineInspectFiledata, NULL);
126  DetectEngineInspectFiledata, NULL);
128  ALPROTO_HTTP2, SIG_FLAG_TOSERVER, HTTP2StateDataClient,
129  DetectEngineInspectFiledata, NULL);
131  ALPROTO_HTTP2, SIG_FLAG_TOCLIENT, HTTP2StateDataServer,
132  DetectEngineInspectFiledata, NULL);
133 
135  "http response body, smb files or smtp attachments data");
136 
137  g_file_data_buffer_id = DetectBufferTypeGetByName("file_data");
138 }
139 
140 #define FILEDATA_CONTENT_LIMIT 100000
141 #define FILEDATA_CONTENT_INSPECT_MIN_SIZE 32768
142 #define FILEDATA_CONTENT_INSPECT_WINDOW 4096
143 
144 static void SetupDetectEngineConfig(DetectEngineCtx *de_ctx) {
146  return;
147 
148  /* initialize default */
149  for (int i = 0; i < (int)ALPROTO_MAX; i++) {
153  }
154 
155  /* add protocol specific settings here */
156 
157  /* SMTP */
161 
163 }
164 
165 /**
166  * \brief this function is used to parse filedata options
167  * \brief into the current signature
168  *
169  * \param de_ctx pointer to the Detection Engine Context
170  * \param s pointer to the Current Signature
171  * \param str pointer to the user provided "filestore" option
172  *
173  * \retval 0 on Success
174  * \retval -1 on Failure
175  */
176 static int DetectFiledataSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
177 {
178  SCEnter();
179 
180  if (!DetectProtoContainsProto(&s->proto, IPPROTO_TCP) ||
181  (s->alproto != ALPROTO_UNKNOWN && s->alproto != ALPROTO_HTTP &&
182  s->alproto != ALPROTO_SMTP && s->alproto != ALPROTO_SMB &&
183  s->alproto != ALPROTO_HTTP2)) {
184  SCLogError(SC_ERR_CONFLICTING_RULE_KEYWORDS, "rule contains conflicting keywords.");
185  return -1;
186  }
187 
189  (s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_TOCLIENT)) {
190  SCLogError(SC_ERR_INVALID_SIGNATURE, "Can't use file_data with "
191  "flow:to_server or flow:from_client with http.");
192  return -1;
193  }
194 
196  !(s->flags & SIG_FLAG_TOSERVER) && (s->flags & SIG_FLAG_TOCLIENT)) {
197  SCLogError(SC_ERR_INVALID_SIGNATURE, "Can't use file_data with "
198  "flow:to_client or flow:from_server with smtp.");
199  return -1;
200  }
201 
202  if (DetectBufferSetActiveList(s, DetectBufferTypeGetByName("file_data")) < 0)
203  return -1;
204 
206  SetupDetectEngineConfig(de_ctx);
207  return 0;
208 }
209 
210 static void DetectFiledataSetupCallback(const DetectEngineCtx *de_ctx,
211  Signature *s)
212 {
213  if (s->alproto == ALPROTO_HTTP || s->alproto == ALPROTO_UNKNOWN) {
215  }
216 
217 
218  /* server body needs to be inspected in sync with stream if possible */
220 
221  SCLogDebug("callback invoked by %u", s->id);
222 }
223 
224 /* HTTP based detection */
225 
226 static inline HtpBody *GetResponseBody(htp_tx_t *tx)
227 {
228  HtpTxUserData *htud = (HtpTxUserData *)htp_tx_get_user_data(tx);
229  if (htud == NULL) {
230  SCLogDebug("no htud");
231  return NULL;
232  }
233 
234  return &htud->response_body;
235 }
236 
237 static InspectionBuffer *HttpServerBodyGetDataCallback(DetectEngineThreadCtx *det_ctx,
238  const DetectEngineTransforms *transforms,
239  Flow *f, const uint8_t flow_flags,
240  void *txv, const int list_id)
241 {
242  SCEnter();
243 
244  InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
245  if (buffer->inspect != NULL)
246  return buffer;
247 
248  htp_tx_t *tx = txv;
249  HtpState *htp_state = f->alstate;
250  const uint8_t flags = flow_flags;
251 
252  HtpBody *body = GetResponseBody(tx);
253  if (body == NULL) {
254  return NULL;
255  }
256 
257  /* no new data */
258  if (body->body_inspected == body->content_len_so_far) {
259  SCLogDebug("no new data");
260  return NULL;
261  }
262 
263  HtpBodyChunk *cur = body->first;
264  if (cur == NULL) {
265  SCLogDebug("No http chunks to inspect for this transacation");
266  return NULL;
267  }
268 
269  SCLogDebug("response.body_limit %u response_body.content_len_so_far %"PRIu64
270  ", response.inspect_min_size %"PRIu32", EOF %s, progress > body? %s",
271  htp_state->cfg->response.body_limit,
272  body->content_len_so_far,
273  htp_state->cfg->response.inspect_min_size,
274  flags & STREAM_EOF ? "true" : "false",
275  (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP, tx, flags) > HTP_RESPONSE_BODY) ? "true" : "false");
276 
277  if (!htp_state->cfg->http_body_inline) {
278  /* inspect the body if the transfer is complete or we have hit
279  * our body size limit */
280  if ((htp_state->cfg->response.body_limit == 0 ||
281  body->content_len_so_far < htp_state->cfg->response.body_limit) &&
282  body->content_len_so_far < htp_state->cfg->response.inspect_min_size &&
283  !(AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP, tx, flags) > HTP_RESPONSE_BODY) &&
284  !(flags & STREAM_EOF)) {
285  SCLogDebug("we still haven't seen the entire response body. "
286  "Let's defer body inspection till we see the "
287  "entire body.");
288  return NULL;
289  }
290  }
291 
292  /* get the inspect buffer
293  *
294  * make sure that we have at least the configured inspect_win size.
295  * If we have more, take at least 1/4 of the inspect win size before
296  * the new data.
297  */
298  uint64_t offset = 0;
299  if (body->body_inspected > htp_state->cfg->response.inspect_min_size) {
301  uint64_t inspect_win = body->content_len_so_far - body->body_inspected;
302  SCLogDebug("inspect_win %"PRIu64, inspect_win);
303  if (inspect_win < htp_state->cfg->response.inspect_window) {
304  uint64_t inspect_short = htp_state->cfg->response.inspect_window - inspect_win;
305  if (body->body_inspected < inspect_short)
306  offset = 0;
307  else
308  offset = body->body_inspected - inspect_short;
309  } else {
310  offset = body->body_inspected - (htp_state->cfg->response.inspect_window / 4);
311  }
312  }
313 
314  const uint8_t *data;
315  uint32_t data_len;
316 
318  &data, &data_len, offset);
319  InspectionBufferSetup(buffer, data, data_len);
320  buffer->inspect_offset = offset;
321 
322  /* built-in 'transformation' */
323  if (htp_state->cfg->swf_decompression_enabled) {
324  int swf_file_type = FileIsSwfFile(data, data_len);
325  if (swf_file_type == FILE_SWF_ZLIB_COMPRESSION ||
326  swf_file_type == FILE_SWF_LZMA_COMPRESSION)
327  {
328  (void)FileSwfDecompression(data, data_len,
329  det_ctx,
330  buffer,
331  htp_state->cfg->swf_compression_type,
332  htp_state->cfg->swf_decompress_depth,
333  htp_state->cfg->swf_compress_depth);
334  }
335  }
336 
337  /* move inspected tracker to end of the data. HtpBodyPrune will consider
338  * the window sizes when freeing data */
339  body->body_inspected = body->content_len_so_far;
340  SCLogDebug("body->body_inspected now: %"PRIu64, body->body_inspected);
341 
342  SCReturnPtr(buffer, "InspectionBuffer");
343 }
344 
345 /* file API based inspection */
346 
347 static InspectionBuffer *FiledataGetDataCallback(DetectEngineThreadCtx *det_ctx,
348  const DetectEngineTransforms *transforms,
349  Flow *f, uint8_t flow_flags, File *cur_file,
350  int list_id, int local_file_id, bool first)
351 {
352  SCEnter();
353 
355  InspectionBuffer *buffer = InspectionBufferMultipleForListGet(fb, local_file_id);
356  if (buffer == NULL)
357  return NULL;
358  if (!first && buffer->inspect != NULL)
359  return buffer;
360 
361  const uint64_t file_size = FileDataSize(cur_file);
362  const DetectEngineCtx *de_ctx = det_ctx->de_ctx;
363  const uint32_t content_limit = de_ctx->filedata_config[f->alproto].content_limit;
364  const uint32_t content_inspect_min_size = de_ctx->filedata_config[f->alproto].content_inspect_min_size;
365  // TODO this is unused, is that right?
366  //const uint32_t content_inspect_window = de_ctx->filedata_config[f->alproto].content_inspect_window;
367 
368  SCLogDebug("content_limit %u, content_inspect_min_size %u",
369  content_limit, content_inspect_min_size);
370 
371  SCLogDebug("file %p size %"PRIu64", state %d", cur_file, file_size, cur_file->state);
372 
373  /* no new data */
374  if (cur_file->content_inspected == file_size) {
375  SCLogDebug("no new data");
376  return NULL;
377  }
378 
379  if (file_size == 0) {
380  SCLogDebug("no data to inspect for this transaction");
381  return NULL;
382  }
383 
384  if ((content_limit == 0 || file_size < content_limit) &&
385  file_size < content_inspect_min_size &&
386  !(flow_flags & STREAM_EOF) && !(cur_file->state > FILE_STATE_OPENED)) {
387  SCLogDebug("we still haven't seen the entire content. "
388  "Let's defer content inspection till we see the "
389  "entire content.");
390  return NULL;
391  }
392 
393  const uint8_t *data;
394  uint32_t data_len;
395 
397  &data, &data_len,
398  cur_file->content_inspected);
399  InspectionBufferSetup(buffer, data, data_len);
400  buffer->inspect_offset = cur_file->content_inspected;
401  InspectionBufferApplyTransforms(buffer, transforms);
402 
403  /* update inspected tracker */
404  cur_file->content_inspected = file_size;
405  SCLogDebug("content_inspected %"PRIu64, cur_file->content_inspected);
406 
407  SCLogDebug("file_data buffer %p, data %p len %u offset %"PRIu64,
408  buffer, buffer->inspect, buffer->inspect_len, buffer->inspect_offset);
409 
410  SCReturnPtr(buffer, "InspectionBuffer");
411 }
412 
413 static int DetectEngineInspectFiledata(
415  const DetectEngineAppInspectionEngine *engine,
416  const Signature *s,
417  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
418 {
419  int r = 0;
420  int match = 0;
421 
422  const DetectEngineTransforms *transforms = NULL;
423  if (!engine->mpm) {
424  transforms = engine->v2.transforms;
425  }
426 
428  if (ffc == NULL) {
430  }
431 
432  int local_file_id = 0;
433  File *file = ffc->head;
434  for (; file != NULL; file = file->next) {
435  if (file->txid != tx_id)
436  continue;
437 
438  InspectionBuffer *buffer = FiledataGetDataCallback(det_ctx,
439  transforms, f, flags, file, engine->sm_list, local_file_id, false);
440  if (buffer == NULL)
441  continue;
442 
443  bool eof = (file->state == FILE_STATE_CLOSED);
444  uint8_t ciflags = eof ? DETECT_CI_FLAGS_END : 0;
445  if (buffer->inspect_offset == 0)
446  ciflags |= DETECT_CI_FLAGS_START;
447 
448  det_ctx->buffer_offset = 0;
449  det_ctx->discontinue_matching = 0;
450  det_ctx->inspection_recursion_counter = 0;
451  match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
452  NULL, f,
453  (uint8_t *)buffer->inspect,
454  buffer->inspect_len,
455  buffer->inspect_offset, ciflags,
457  if (match == 1) {
458  r = 1;
459  break;
460  }
461  local_file_id++;
462  }
463 
464  if (r == 1)
466  else
468 }
469 
470 typedef struct PrefilterMpmFiledata {
471  int list_id;
472  const MpmCtx *mpm_ctx;
475 
476 /** \brief Filedata Filedata Mpm prefilter callback
477  *
478  * \param det_ctx detection engine thread ctx
479  * \param pectx inspection context
480  * \param p packet to inspect
481  * \param f flow to inspect
482  * \param txv tx to inspect
483  * \param idx transaction id
484  * \param flags STREAM_* flags including direction
485  */
486 static void PrefilterTxFiledata(DetectEngineThreadCtx *det_ctx,
487  const void *pectx,
488  Packet *p, Flow *f, void *txv,
489  const uint64_t idx, const uint8_t flags)
490 {
491  SCEnter();
492 
493  const PrefilterMpmFiledata *ctx = (const PrefilterMpmFiledata *)pectx;
494  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
495  const int list_id = ctx->list_id;
496 
498  int local_file_id = 0;
499  if (ffc != NULL) {
500  File *file = ffc->head;
501  for (; file != NULL; file = file->next) {
502  if (file->txid != idx)
503  continue;
504 
505  InspectionBuffer *buffer = FiledataGetDataCallback(det_ctx,
506  ctx->transforms, f, flags, file, list_id, local_file_id, true);
507  if (buffer == NULL)
508  continue;
509 
510  if (buffer->inspect_len >= mpm_ctx->minlen) {
511  (void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
512  &det_ctx->mtcu, &det_ctx->pmq,
513  buffer->inspect, buffer->inspect_len);
514  }
515  local_file_id++;
516  }
517  }
518 }
519 
520 static void PrefilterMpmFiledataFree(void *ptr)
521 {
522  SCFree(ptr);
523 }
524 
526  SigGroupHead *sgh, MpmCtx *mpm_ctx,
527  const DetectBufferMpmRegistery *mpm_reg, int list_id)
528 {
529  PrefilterMpmFiledata *pectx = SCCalloc(1, sizeof(*pectx));
530  if (pectx == NULL)
531  return -1;
532  pectx->list_id = list_id;
533  pectx->mpm_ctx = mpm_ctx;
534  pectx->transforms = &mpm_reg->transforms;
535 
536  return PrefilterAppendTxEngine(de_ctx, sgh, PrefilterTxFiledata,
537  mpm_reg->app_v2.alproto, mpm_reg->app_v2.tx_min_progress,
538  pectx, PrefilterMpmFiledataFree, mpm_reg->pname);
539 }
540 
541 #ifdef UNITTESTS
542 #include "tests/detect-file-data.c"
543 #endif
HtpState_::cfg
const struct HTPCfgRec_ * cfg
Definition: app-layer-htp.h:253
SMTPConfig::content_limit
uint32_t content_limit
Definition: app-layer-smtp.h:98
DetectEngineAppInspectionEngine_
Definition: detect.h:402
SigTableElmt_::url
const char * url
Definition: detect.h:1214
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
SigTableElmt_::desc
const char * desc
Definition: detect.h:1213
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
SCFPSupportSMList_::list_id
int list_id
Definition: detect-fast-pattern.h:29
SigTableElmt_::name
const char * name
Definition: detect.h:1211
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1347
HtpBody_::sb
StreamingBuffer * sb
Definition: app-layer-htp.h:189
SIG_FLAG_INIT_FLOW
#define SIG_FLAG_INIT_FLOW
Definition: detect.h:258
DetectEngineTransforms
Definition: detect.h:376
HTPCfgRec_::response
HTPCfgDir response
Definition: app-layer-htp.h:173
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:140
Signature_::alproto
AppProto alproto
Definition: detect.h:532
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:149
FILEDATA_CONTENT_INSPECT_WINDOW
#define FILEDATA_CONTENT_INSPECT_WINDOW
Definition: detect-file-data.c:142
DetectBufferMpmRegistery_::transforms
DetectEngineTransforms transforms
Definition: detect.h:624
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:1008
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:344
threads.h
FILE_STATE_OPENED
@ FILE_STATE_OPENED
Definition: util-file.h:54
Flow_
Flow data structure.
Definition: flow.h:347
File_::state
FileState state
Definition: util-file.h:66
DetectBufferTypeRegisterSetupCallback
void DetectBufferTypeRegisterSetupCallback(const char *name, void(*SetupCallback)(const DetectEngineCtx *, Signature *))
Definition: detect-engine.c:953
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1111
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:1205
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:767
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:858
detect-file-data.h
DetectBufferMpmRegistery_
one time registration of keywords at start up
Definition: detect.h:611
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:493
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
HTPCfgRec_::swf_compress_depth
uint32_t swf_compress_depth
Definition: app-layer-htp.h:170
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:68
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1196
PrefilterMpmFiledata
struct PrefilterMpmFiledata PrefilterMpmFiledata
DetectEngineCtx_::content_inspect_window
uint32_t content_inspect_window
Definition: detect.h:884
detect-engine-prefilter.h
HTPCfgDir_::inspect_window
uint32_t inspect_window
Definition: app-layer-htp.h:151
DetectEngineThreadCtx_::mtcu
MpmThreadCtx mtcu
Definition: detect.h:1109
util-unittest.h
InspectionBufferGet
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine.c:1061
HtpBody_::first
HtpBodyChunk * first
Definition: app-layer-htp.h:186
HtpState_
Definition: app-layer-htp.h:243
SMTPConfig::content_inspect_min_size
uint32_t content_inspect_min_size
Definition: app-layer-smtp.h:99
util-unittest-helper.h
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:880
File_::sb
StreamingBuffer * sb
Definition: util-file.h:67
FILE_SWF_LZMA_COMPRESSION
@ FILE_SWF_LZMA_COMPRESSION
Definition: util-file-decompression.h:34
HtpBody_::content_len_so_far
uint64_t content_len_so_far
Definition: app-layer-htp.h:192
DetectEngineAppInspectionEngine_::sm_list
uint16_t sm_list
Definition: detect.h:408
InspectionBufferMultipleForList
Definition: detect.h:364
PrefilterMpmFiledata::transforms
const DetectEngineTransforms * transforms
Definition: detect-file-data.c:473
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:165
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1010
HTPCfgDir_::inspect_min_size
uint32_t inspect_min_size
Definition: app-layer-htp.h:150
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:525
HTPCfgRec_::swf_decompress_depth
uint32_t swf_decompress_depth
Definition: app-layer-htp.h:169
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
PrefilterMpmFiledata::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-file-data.c:472
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:167
InspectionBuffer::inspect_offset
uint64_t inspect_offset
Definition: detect.h:346
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:529
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:1641
Packet_
Definition: decode.h:414
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:232
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:597
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:486
HTPCfgRec_::swf_compression_type
HtpSwfCompressType swf_compression_type
Definition: app-layer-htp.h:168
ALPROTO_HTTP2
@ ALPROTO_HTTP2
Definition: app-layer-protos.h:59
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:217
DETECT_FILE_DATA
@ DETECT_FILE_DATA
Definition: detect-engine-register.h:171
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:1076
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:426
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:185
DetectEngineCtx_::filedata_config
struct DetectEngineCtx_::@97 filedata_config[ALPROTO_MAX]
DetectBufferMpmRegistery_::pname
char pname[32]
Definition: detect.h:613
flags
uint8_t flags
Definition: decode-gre.h:0
Signature_::proto
DetectProto proto
Definition: detect.h:545
SigTableElmt_::alias
const char * alias
Definition: detect.h:1212
suricata-common.h
FILEDATA_CONTENT_INSPECT_MIN_SIZE
#define FILEDATA_CONTENT_INSPECT_MIN_SIZE
Definition: detect-file-data.c:141
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
InspectionBufferApplyTransforms
void InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
Definition: detect-engine.c:1211
HtpBodyChunk_
Definition: app-layer-htp.h:177
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
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:208
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:347
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:345
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:476
Signature_::id
uint32_t id
Definition: detect.h:561
FILE_SWF_ZLIB_COMPRESSION
@ FILE_SWF_ZLIB_COMPRESSION
Definition: util-file-decompression.h:33
DetectEngineCtx_::content_limit
uint32_t content_limit
Definition: detect.h:882
detect-parse.h
Signature_
Signature container.
Definition: detect.h:528
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
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:886
DetectEngineCtx_::content_inspect_min_size
uint32_t content_inspect_min_size
Definition: detect.h:883
DetectEngineThreadCtx_::de_ctx
DetectEngineCtx * de_ctx
Definition: detect.h:1136
InspectionBufferGetMulti
InspectionBufferMultipleForList * InspectionBufferGetMulti(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine.c:1100
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
app-layer-smtp.h
DetectBufferTypeSetDescriptionByName
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
Definition: detect-engine.c:908
PrefilterMpmFiledata
Definition: detect-file-data.c:470
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:450
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
PrefilterMpmFiledata::list_id
int list_id
Definition: detect-file-data.c:471
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:100
InspectionBufferMultipleForListGet
InspectionBuffer * InspectionBufferMultipleForListGet(InspectionBufferMultipleForList *fb, uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
Definition: detect-engine.c:1074
debug.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1203
HtpBody_::body_inspected
uint64_t body_inspected
Definition: app-layer-htp.h:196
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