suricata
detect-file-data.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2020 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 static inline HtpBody *GetResponseBody(htp_tx_t *tx);
63 
64 /* HTTP */
65 static InspectionBuffer *HttpServerBodyGetDataCallback(DetectEngineThreadCtx *det_ctx,
66  const DetectEngineTransforms *transforms,
67  Flow *f, const uint8_t flow_flags,
68  void *txv, const int list_id);
69 
70 /* file API */
71 static int DetectEngineInspectFiledata(
73  const DetectEngineAppInspectionEngine *engine,
74  const Signature *s,
75  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id);
77  SigGroupHead *sgh, MpmCtx *mpm_ctx,
78  const DetectBufferMpmRegistery *mpm_reg, int list_id);
79 
80 static int DetectEngineInspectBufferHttpBody(DetectEngineCtx *de_ctx,
82  const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id);
83 
84 /**
85  * \brief Registration function for keyword: file_data
86  */
88 {
89  sigmatch_table[DETECT_FILE_DATA].name = "file.data";
90  sigmatch_table[DETECT_FILE_DATA].alias = "file_data";
91  sigmatch_table[DETECT_FILE_DATA].desc = "make content keywords match on file data";
92  sigmatch_table[DETECT_FILE_DATA].url = "/rules/http-keywords.html#file-data";
93  sigmatch_table[DETECT_FILE_DATA].Setup = DetectFiledataSetup;
94 #ifdef UNITTESTS
96 #endif
98 
101  ALPROTO_SMTP, 0);
104  HttpServerBodyGetDataCallback,
105  ALPROTO_HTTP, HTP_RESPONSE_BODY);
108  ALPROTO_SMB, 0);
111  ALPROTO_SMB, 0);
114  ALPROTO_HTTP2, HTTP2StateDataClient);
117  ALPROTO_HTTP2, HTTP2StateDataServer);
118 
120  HTP_RESPONSE_BODY, DetectEngineInspectBufferHttpBody, HttpServerBodyGetDataCallback);
123  DetectEngineInspectFiledata, NULL);
125  DetectFiledataSetupCallback);
128  DetectEngineInspectFiledata, NULL);
131  DetectEngineInspectFiledata, NULL);
133  ALPROTO_HTTP2, SIG_FLAG_TOSERVER, HTTP2StateDataClient,
134  DetectEngineInspectFiledata, NULL);
136  ALPROTO_HTTP2, SIG_FLAG_TOCLIENT, HTTP2StateDataServer,
137  DetectEngineInspectFiledata, NULL);
138 
140  "http response body, smb files or smtp attachments data");
141 
142  g_file_data_buffer_id = DetectBufferTypeGetByName("file_data");
143 }
144 
145 #define FILEDATA_CONTENT_LIMIT 100000
146 #define FILEDATA_CONTENT_INSPECT_MIN_SIZE 32768
147 #define FILEDATA_CONTENT_INSPECT_WINDOW 4096
148 
149 static void SetupDetectEngineConfig(DetectEngineCtx *de_ctx) {
151  return;
152 
153  /* initialize default */
154  for (int i = 0; i < (int)ALPROTO_MAX; i++) {
158  }
159 
160  /* add protocol specific settings here */
161 
162  /* SMTP */
166 
168 }
169 
170 static int DetectEngineInspectBufferHttpBody(DetectEngineCtx *de_ctx,
172  const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
173 {
174  const int list_id = engine->sm_list;
175  const InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
176  bool eof = false;
177  if (buffer->inspect == NULL) {
178  SCLogDebug("running inspect on %d", list_id);
179 
180  eof = (AppLayerParserGetStateProgress(f->proto, f->alproto, txv, flags) > engine->progress);
181 
182  SCLogDebug("list %d mpm? %s transforms %p", engine->sm_list, engine->mpm ? "true" : "false",
183  engine->v2.transforms);
184 
185  /* if prefilter didn't already run, we need to consider transformations */
186  const DetectEngineTransforms *transforms = NULL;
187  if (!engine->mpm) {
188  transforms = engine->v2.transforms;
189  }
190 
191  buffer = engine->v2.GetData(det_ctx, transforms, f, flags, txv, list_id);
192  if (unlikely(buffer == NULL)) {
194  }
195  }
196 
197  const uint32_t data_len = buffer->inspect_len;
198  const uint8_t *data = buffer->inspect;
199  const uint64_t offset = buffer->inspect_offset;
200 
201  uint8_t ci_flags = eof ? DETECT_CI_FLAGS_END : 0;
202  ci_flags |= (offset == 0 ? DETECT_CI_FLAGS_START : 0);
203  ci_flags |= buffer->flags;
204 
205  det_ctx->discontinue_matching = 0;
206  det_ctx->buffer_offset = 0;
207  det_ctx->inspection_recursion_counter = 0;
208 
209  /* Inspect all the uricontents fetched on each
210  * transaction at the app layer */
211  int r = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd, NULL, f, (uint8_t *)data,
213 
214  /* move inspected tracker to end of the data. HtpBodyPrune will consider
215  * the window sizes when freeing data */
216  htp_tx_t *tx = txv;
217  HtpBody *body = GetResponseBody(tx);
218  body->body_inspected = body->content_len_so_far;
219  SCLogDebug("body->body_inspected now: %" PRIu64, body->body_inspected);
220 
221  if (r == 1) {
223  }
224 
225  if (flags & STREAM_TOSERVER) {
226  if (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP, txv, flags) >
227  HTP_REQUEST_BODY)
229  } else {
230  if (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP, txv, flags) >
231  HTP_RESPONSE_BODY)
233  }
235 }
236 
237 /**
238  * \brief this function is used to parse filedata options
239  * \brief into the current signature
240  *
241  * \param de_ctx pointer to the Detection Engine Context
242  * \param s pointer to the Current Signature
243  * \param str pointer to the user provided "filestore" option
244  *
245  * \retval 0 on Success
246  * \retval -1 on Failure
247  */
248 static int DetectFiledataSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
249 {
250  SCEnter();
251 
252  if (!DetectProtoContainsProto(&s->proto, IPPROTO_TCP) ||
253  (s->alproto != ALPROTO_UNKNOWN && s->alproto != ALPROTO_HTTP &&
254  s->alproto != ALPROTO_SMTP && s->alproto != ALPROTO_SMB &&
255  s->alproto != ALPROTO_HTTP2)) {
256  SCLogError(SC_ERR_CONFLICTING_RULE_KEYWORDS, "rule contains conflicting keywords.");
257  return -1;
258  }
259 
261  (s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_TOCLIENT)) {
262  SCLogError(SC_ERR_INVALID_SIGNATURE, "Can't use file_data with "
263  "flow:to_server or flow:from_client with http.");
264  return -1;
265  }
266 
268  !(s->flags & SIG_FLAG_TOSERVER) && (s->flags & SIG_FLAG_TOCLIENT)) {
269  SCLogError(SC_ERR_INVALID_SIGNATURE, "Can't use file_data with "
270  "flow:to_client or flow:from_server with smtp.");
271  return -1;
272  }
273 
274  if (DetectBufferSetActiveList(s, DetectBufferTypeGetByName("file_data")) < 0)
275  return -1;
276 
278  SetupDetectEngineConfig(de_ctx);
279  return 0;
280 }
281 
282 static void DetectFiledataSetupCallback(const DetectEngineCtx *de_ctx,
283  Signature *s)
284 {
285  if (s->alproto == ALPROTO_HTTP || s->alproto == ALPROTO_UNKNOWN) {
287  }
288 
289 
290  /* server body needs to be inspected in sync with stream if possible */
292 
293  SCLogDebug("callback invoked by %u", s->id);
294 }
295 
296 /* HTTP based detection */
297 
298 static inline HtpBody *GetResponseBody(htp_tx_t *tx)
299 {
300  HtpTxUserData *htud = (HtpTxUserData *)htp_tx_get_user_data(tx);
301  if (htud == NULL) {
302  SCLogDebug("no htud");
303  return NULL;
304  }
305 
306  return &htud->response_body;
307 }
308 
309 static InspectionBuffer *HttpServerBodyGetDataCallback(DetectEngineThreadCtx *det_ctx,
310  const DetectEngineTransforms *transforms,
311  Flow *f, const uint8_t flow_flags,
312  void *txv, const int list_id)
313 {
314  SCEnter();
315 
316  InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
317  if (buffer->inspect != NULL)
318  return buffer;
319 
320  htp_tx_t *tx = txv;
321  HtpState *htp_state = f->alstate;
322  const uint8_t flags = flow_flags;
323 
324  HtpBody *body = GetResponseBody(tx);
325  if (body == NULL) {
326  return NULL;
327  }
328 
329  /* no new data */
330  if (body->body_inspected == body->content_len_so_far) {
331  SCLogDebug("no new data");
332  return NULL;
333  }
334 
335  HtpBodyChunk *cur = body->first;
336  if (cur == NULL) {
337  SCLogDebug("No http chunks to inspect for this transaction");
338  return NULL;
339  }
340 
341  SCLogDebug("response.body_limit %u response_body.content_len_so_far %"PRIu64
342  ", response.inspect_min_size %"PRIu32", EOF %s, progress > body? %s",
343  htp_state->cfg->response.body_limit,
344  body->content_len_so_far,
345  htp_state->cfg->response.inspect_min_size,
346  flags & STREAM_EOF ? "true" : "false",
347  (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP, tx, flags) > HTP_RESPONSE_BODY) ? "true" : "false");
348 
349  if (!htp_state->cfg->http_body_inline) {
350  /* inspect the body if the transfer is complete or we have hit
351  * our body size limit */
352  if ((htp_state->cfg->response.body_limit == 0 ||
353  body->content_len_so_far < htp_state->cfg->response.body_limit) &&
354  body->content_len_so_far < htp_state->cfg->response.inspect_min_size &&
355  !(AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP, tx, flags) > HTP_RESPONSE_BODY) &&
356  !(flags & STREAM_EOF)) {
357  SCLogDebug("we still haven't seen the entire response body. "
358  "Let's defer body inspection till we see the "
359  "entire body.");
360  return NULL;
361  }
362  }
363 
364  /* get the inspect buffer
365  *
366  * make sure that we have at least the configured inspect_win size.
367  * If we have more, take at least 1/4 of the inspect win size before
368  * the new data.
369  */
370  uint64_t offset = 0;
371  if (body->body_inspected > htp_state->cfg->response.inspect_min_size) {
373  uint64_t inspect_win = body->content_len_so_far - body->body_inspected;
374  SCLogDebug("inspect_win %"PRIu64, inspect_win);
375  if (inspect_win < htp_state->cfg->response.inspect_window) {
376  uint64_t inspect_short = htp_state->cfg->response.inspect_window - inspect_win;
377  if (body->body_inspected < inspect_short)
378  offset = 0;
379  else
380  offset = body->body_inspected - inspect_short;
381  } else {
382  offset = body->body_inspected - (htp_state->cfg->response.inspect_window / 4);
383  }
384  }
385 
386  const uint8_t *data;
387  uint32_t data_len;
388 
390  &data, &data_len, offset);
391  InspectionBufferSetup(buffer, data, data_len);
392  buffer->inspect_offset = offset;
393 
394  /* built-in 'transformation' */
395  if (htp_state->cfg->swf_decompression_enabled) {
396  int swf_file_type = FileIsSwfFile(data, data_len);
397  if (swf_file_type == FILE_SWF_ZLIB_COMPRESSION ||
398  swf_file_type == FILE_SWF_LZMA_COMPRESSION)
399  {
400  (void)FileSwfDecompression(data, data_len,
401  det_ctx,
402  buffer,
403  htp_state->cfg->swf_compression_type,
404  htp_state->cfg->swf_decompress_depth,
405  htp_state->cfg->swf_compress_depth);
406  }
407  }
408 
409  InspectionBufferApplyTransforms(buffer, transforms);
410 
411  SCReturnPtr(buffer, "InspectionBuffer");
412 }
413 
414 /* file API based inspection */
415 
416 static InspectionBuffer *FiledataGetDataCallback(DetectEngineThreadCtx *det_ctx,
417  const DetectEngineTransforms *transforms,
418  Flow *f, uint8_t flow_flags, File *cur_file,
419  int list_id, int local_file_id, bool first)
420 {
421  SCEnter();
422 
424  InspectionBuffer *buffer = InspectionBufferMultipleForListGet(fb, local_file_id);
425  if (buffer == NULL)
426  return NULL;
427  if (!first && buffer->inspect != NULL)
428  return buffer;
429 
430  const uint64_t file_size = FileDataSize(cur_file);
431  const DetectEngineCtx *de_ctx = det_ctx->de_ctx;
432  const uint32_t content_limit = de_ctx->filedata_config[f->alproto].content_limit;
433  const uint32_t content_inspect_min_size = de_ctx->filedata_config[f->alproto].content_inspect_min_size;
434  // TODO this is unused, is that right?
435  //const uint32_t content_inspect_window = de_ctx->filedata_config[f->alproto].content_inspect_window;
436 
437  SCLogDebug("[list %d] first: %d, content_limit %u, content_inspect_min_size %u", list_id,
438  first ? 1 : 0, content_limit, content_inspect_min_size);
439 
440  SCLogDebug("[list %d] file %p size %" PRIu64 ", state %d", list_id, cur_file, file_size,
441  cur_file->state);
442 
443  /* no new data */
444  if (cur_file->content_inspected == file_size) {
445  SCLogDebug("no new data");
446  return NULL;
447  }
448 
449  if (file_size == 0) {
450  SCLogDebug("no data to inspect for this transaction");
451  return NULL;
452  }
453 
454  if ((content_limit == 0 || file_size < content_limit) &&
455  file_size < content_inspect_min_size &&
456  !(flow_flags & STREAM_EOF) && !(cur_file->state > FILE_STATE_OPENED)) {
457  SCLogDebug("we still haven't seen the entire content. "
458  "Let's defer content inspection till we see the "
459  "entire content.");
460  return NULL;
461  }
462 
463  const uint8_t *data;
464  uint32_t data_len;
465 
467  &data, &data_len,
468  cur_file->content_inspected);
469  InspectionBufferSetup(buffer, data, data_len);
470  SCLogDebug("[list %d] [before] buffer offset %" PRIu64 "; buffer len %" PRIu32
471  "; data_len %" PRIu32 "; file_size %" PRIu64,
472  list_id, buffer->inspect_offset, buffer->inspect_len, data_len, file_size);
473  buffer->inspect_offset = cur_file->content_inspected;
474  InspectionBufferApplyTransforms(buffer, transforms);
475  SCLogDebug("[list %d] [after] buffer offset %" PRIu64 "; buffer len %" PRIu32, list_id,
476  buffer->inspect_offset, buffer->inspect_len);
477 
478  SCLogDebug("[list %d] content_inspected %" PRIu64, list_id, cur_file->content_inspected);
479 
480  SCLogDebug("[list %d] file_data buffer %p, data %p len %u offset %" PRIu64, list_id, buffer,
481  buffer->inspect, buffer->inspect_len, buffer->inspect_offset);
482 
483  SCReturnPtr(buffer, "InspectionBuffer");
484 }
485 
486 static int DetectEngineInspectFiledata(
488  const DetectEngineAppInspectionEngine *engine,
489  const Signature *s,
490  Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
491 {
492  int r = 0;
493  int match = 0;
494 
495  const DetectEngineTransforms *transforms = NULL;
496  if (!engine->mpm) {
497  transforms = engine->v2.transforms;
498  }
499 
501  if (ffc == NULL) {
503  }
504 
505  int local_file_id = 0;
506  File *file = ffc->head;
507  for (; file != NULL; file = file->next) {
508  if (file->txid != tx_id)
509  continue;
510 
511  InspectionBuffer *buffer = FiledataGetDataCallback(det_ctx,
512  transforms, f, flags, file, engine->sm_list, local_file_id, false);
513  if (buffer == NULL)
514  continue;
515 
516  bool eof = (file->state == FILE_STATE_CLOSED);
517  uint8_t ciflags = eof ? DETECT_CI_FLAGS_END : 0;
518  if (buffer->inspect_offset == 0)
519  ciflags |= DETECT_CI_FLAGS_START;
520 
521  det_ctx->buffer_offset = 0;
522  det_ctx->discontinue_matching = 0;
523  det_ctx->inspection_recursion_counter = 0;
524  match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd,
525  NULL, f,
526  (uint8_t *)buffer->inspect,
527  buffer->inspect_len,
528  buffer->inspect_offset, ciflags,
530  /* update inspected tracker */
531  file->content_inspected = buffer->inspect_len + buffer->inspect_offset;
532  if (match == 1) {
533  r = 1;
534  break;
535  }
536  local_file_id++;
537  }
538 
539  if (r == 1)
541  else
543 }
544 
545 typedef struct PrefilterMpmFiledata {
546  int list_id;
547  const MpmCtx *mpm_ctx;
550 
551 /** \brief Filedata Filedata Mpm prefilter callback
552  *
553  * \param det_ctx detection engine thread ctx
554  * \param pectx inspection context
555  * \param p packet to inspect
556  * \param f flow to inspect
557  * \param txv tx to inspect
558  * \param idx transaction id
559  * \param flags STREAM_* flags including direction
560  */
561 static void PrefilterTxFiledata(DetectEngineThreadCtx *det_ctx,
562  const void *pectx,
563  Packet *p, Flow *f, void *txv,
564  const uint64_t idx, const uint8_t flags)
565 {
566  SCEnter();
567 
568  const PrefilterMpmFiledata *ctx = (const PrefilterMpmFiledata *)pectx;
569  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
570  const int list_id = ctx->list_id;
571 
573  int local_file_id = 0;
574  if (ffc != NULL) {
575  File *file = ffc->head;
576  for (; file != NULL; file = file->next) {
577  if (file->txid != idx)
578  continue;
579 
580  InspectionBuffer *buffer = FiledataGetDataCallback(det_ctx,
581  ctx->transforms, f, flags, file, list_id, local_file_id, true);
582  if (buffer == NULL)
583  continue;
584 
585  if (buffer->inspect_len >= mpm_ctx->minlen) {
586  (void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx,
587  &det_ctx->mtcu, &det_ctx->pmq,
588  buffer->inspect, buffer->inspect_len);
589  }
590  local_file_id++;
591  }
592  }
593 }
594 
595 static void PrefilterMpmFiledataFree(void *ptr)
596 {
597  SCFree(ptr);
598 }
599 
601  SigGroupHead *sgh, MpmCtx *mpm_ctx,
602  const DetectBufferMpmRegistery *mpm_reg, int list_id)
603 {
604  PrefilterMpmFiledata *pectx = SCCalloc(1, sizeof(*pectx));
605  if (pectx == NULL)
606  return -1;
607  pectx->list_id = list_id;
608  pectx->mpm_ctx = mpm_ctx;
609  pectx->transforms = &mpm_reg->transforms;
610 
611  return PrefilterAppendTxEngine(de_ctx, sgh, PrefilterTxFiledata,
612  mpm_reg->app_v2.alproto, mpm_reg->app_v2.tx_min_progress,
613  pectx, PrefilterMpmFiledataFree, mpm_reg->pname);
614 }
615 
616 #ifdef UNITTESTS
617 #include "tests/detect-file-data.c"
618 #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:1215
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:1042
detect-engine.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1214
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:1212
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1348
HtpBody_::sb
StreamingBuffer * sb
Definition: app-layer-htp.h:189
SIG_FLAG_INIT_FLOW
#define SIG_FLAG_INIT_FLOW
Definition: detect.h:258
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
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:145
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
Flow_::proto
uint8_t proto
Definition: flow.h:365
FILEDATA_CONTENT_INSPECT_WINDOW
#define FILEDATA_CONTENT_INSPECT_WINDOW
Definition: detect-file-data.c:147
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:1033
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
DetectEngineAppInspectionEngine_::GetData
InspectionBufferGetDataPtr GetData
Definition: detect.h:420
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:1112
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:1206
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
InspectionBuffer::flags
uint8_t flags
Definition: detect.h:348
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:1197
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:1110
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:548
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:1011
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
STREAM_TOSERVER
#define STREAM_TOSERVER
Definition: stream.h:31
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:600
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:547
DetectFiledataRegister
void DetectFiledataRegister(void)
Registration function for keyword: file_data.
Definition: detect-file-data.c:87
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
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:164
HtpTxUserData_::response_body
HtpBody response_body
Definition: app-layer-htp.h:217
DETECT_FILE_DATA
@ DETECT_FILE_DATA
Definition: detect-engine-register.h:172
DETECT_ENGINE_INSPECT_SIG_CANT_MATCH
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH
Definition: detect-engine-state.h:40
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:1077
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:1213
suricata-common.h
FILEDATA_CONTENT_INSPECT_MIN_SIZE
#define FILEDATA_CONTENT_INSPECT_MIN_SIZE
Definition: detect-file-data.c:146
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:1089
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
DetectEngineAppInspectionEngine_::progress
int16_t progress
Definition: detect.h:409
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:1137
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:1381
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:545
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:546
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:1204
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