suricata
detect-file-data.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 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 "decode.h"
28 
29 #include "detect.h"
30 #include "detect-parse.h"
31 
32 #include "detect-engine.h"
33 #include "detect-engine-mpm.h"
34 #include "detect-engine-state.h"
37 #include "detect-engine-file.h"
38 #include "detect-file-data.h"
39 
40 #include "app-layer.h"
41 #include "app-layer-parser.h"
42 #include "app-layer-htp.h"
43 #include "app-layer-smtp.h"
44 
45 #include "flow.h"
46 #include "flow-var.h"
47 #include "flow-util.h"
48 
49 #include "util-debug.h"
50 #include "util-spm-bm.h"
51 #include "util-unittest.h"
52 #include "util-unittest-helper.h"
54 #include "util-profiling.h"
55 
56 static int DetectFiledataSetup (DetectEngineCtx *, Signature *, const char *);
57 #ifdef UNITTESTS
58 static void DetectFiledataRegisterTests(void);
59 #endif
60 static void DetectFiledataSetupCallback(const DetectEngineCtx *de_ctx,
61  Signature *s);
62 static int g_file_data_buffer_id = 0;
63 
64 /* file API */
66  const DetectBufferMpmRegistry *mpm_reg, int list_id);
67 
68 /**
69  * \brief Registration function for keyword: file_data
70  */
72 {
73  sigmatch_table[DETECT_FILE_DATA].name = "file.data";
74  sigmatch_table[DETECT_FILE_DATA].alias = "file_data";
75  sigmatch_table[DETECT_FILE_DATA].desc = "make content keywords match on file data";
76  sigmatch_table[DETECT_FILE_DATA].url = "/rules/file-keywords.html#file-data";
77  sigmatch_table[DETECT_FILE_DATA].Setup = DetectFiledataSetup;
78 #ifdef UNITTESTS
80 #endif
82 
87 
88  DetectBufferTypeRegisterSetupCallback("file_data", DetectFiledataSetupCallback);
89 
90  DetectBufferTypeSetDescriptionByName("file_data", "data from tracked files");
92 
93  g_file_data_buffer_id = DetectBufferTypeGetByName("file_data");
94 }
95 
96 static void SetupDetectEngineConfig(DetectEngineCtx *de_ctx) {
98  return;
99 
101  if (unlikely(de_ctx->filedata_config == NULL))
102  return;
103  /* initialize default */
104  for (AppProto i = 0; i < ALPROTO_MAX; i++) {
107  }
108 
109  /* add protocol specific settings here */
110 
111  /* SMTP */
115 }
116 
117 /**
118  * \brief this function is used to parse filedata options
119  * \brief into the current signature
120  *
121  * \param de_ctx pointer to the Detection Engine Context
122  * \param s pointer to the Current Signature
123  * \param str pointer to the user provided "filestore" option
124  *
125  * \retval 0 on Success
126  * \retval -1 on Failure
127  */
128 static int DetectFiledataSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
129 {
130  SCEnter();
131 
132  if (!DetectProtoContainsProto(&s->proto, IPPROTO_TCP)) {
133  SCLogError("The 'file_data' keyword cannot be used with non-TCP protocols");
134  return -1;
135  }
136 
137  if (s->alproto != ALPROTO_UNKNOWN && !AppLayerParserSupportsFiles(IPPROTO_TCP, s->alproto)) {
138  SCLogError("The 'file_data' keyword cannot be used with TCP protocol %s",
140  return -1;
141  }
142 
144  !(s->flags & SIG_FLAG_TOSERVER) && (s->flags & SIG_FLAG_TOCLIENT)) {
145  SCLogError("The 'file-data' keyword cannot be used with SMTP flow:to_client or "
146  "flow:from_server.");
147  return -1;
148  }
149 
151  return -1;
152 
154  SetupDetectEngineConfig(de_ctx);
155  return 0;
156 }
157 
158 static void DetectFiledataSetupCallback(const DetectEngineCtx *de_ctx,
159  Signature *s)
160 {
161  if (s->alproto == ALPROTO_HTTP1 || s->alproto == ALPROTO_UNKNOWN ||
162  s->alproto == ALPROTO_HTTP) {
164  }
165 
166  /* server body needs to be inspected in sync with stream if possible */
168 
169  SCLogDebug("callback invoked by %u", s->id);
170 }
171 
172 /* common */
173 
174 static void PrefilterMpmFiledataFree(void *ptr)
175 {
176  SCFree(ptr);
177 }
178 
179 /* file API based inspection */
180 
181 static inline InspectionBuffer *FiledataWithXformsGetDataCallback(DetectEngineThreadCtx *det_ctx,
182  const DetectEngineTransforms *transforms, const int list_id, int local_file_id,
183  InspectionBuffer *base_buffer)
184 {
185  InspectionBuffer *buffer = InspectionBufferMultipleForListGet(det_ctx, list_id, local_file_id);
186  if (buffer == NULL) {
187  SCLogDebug("list_id: %d: no buffer", list_id);
188  return NULL;
189  }
190  if (buffer->initialized) {
191  SCLogDebug("list_id: %d: returning %p", list_id, buffer);
192  return buffer;
193  }
194 
195  InspectionBufferSetupMulti(buffer, transforms, base_buffer->inspect, base_buffer->inspect_len);
196  buffer->inspect_offset = base_buffer->inspect_offset;
197  SCLogDebug("xformed buffer %p size %u", buffer, buffer->inspect_len);
198  SCReturnPtr(buffer, "InspectionBuffer");
199 }
200 
201 static InspectionBuffer *FiledataGetDataCallback(DetectEngineThreadCtx *det_ctx,
202  const DetectEngineTransforms *transforms, Flow *f, uint8_t flow_flags, File *cur_file,
203  const int list_id, const int base_id, int local_file_id, void *txv)
204 {
205  SCEnter();
206  SCLogDebug("starting: list_id %d base_id %d", list_id, base_id);
207 
208  InspectionBuffer *buffer = InspectionBufferMultipleForListGet(det_ctx, base_id, local_file_id);
209  SCLogDebug("base: buffer %p", buffer);
210  if (buffer == NULL)
211  return NULL;
212  if (base_id != list_id && buffer->inspect != NULL) {
213  SCLogDebug("handle xform %s", (list_id != base_id) ? "true" : "false");
214  return FiledataWithXformsGetDataCallback(
215  det_ctx, transforms, list_id, local_file_id, buffer);
216  }
217  if (buffer->initialized) {
218  SCLogDebug("base_id: %d, not first: use %p", base_id, buffer);
219  return buffer;
220  }
221 
222  const uint64_t file_size = FileDataSize(cur_file);
223  const DetectEngineCtx *de_ctx = det_ctx->de_ctx;
224  uint32_t content_limit = FILEDATA_CONTENT_LIMIT;
225  uint32_t content_inspect_min_size = FILEDATA_CONTENT_INSPECT_MIN_SIZE;
226  if (de_ctx->filedata_config) {
227  content_limit = de_ctx->filedata_config[f->alproto].content_limit;
228  content_inspect_min_size = de_ctx->filedata_config[f->alproto].content_inspect_min_size;
229  }
230 
231  SCLogDebug("[list %d] content_limit %u, content_inspect_min_size %u", list_id, content_limit,
232  content_inspect_min_size);
233 
234  SCLogDebug("[list %d] file %p size %" PRIu64 ", state %d", list_id, cur_file, file_size,
235  cur_file->state);
236 
237  /* no new data */
238  if (cur_file->content_inspected == file_size) {
239  SCLogDebug("no new data");
240  goto empty_return;
241  }
242 
243  if (file_size == 0) {
244  SCLogDebug("no data to inspect for this transaction");
245  goto empty_return;
246  }
247 
248  SCLogDebug("offset %" PRIu64, StreamingBufferGetOffset(cur_file->sb));
249  SCLogDebug("size %" PRIu64, cur_file->size);
250  SCLogDebug("content_inspected %" PRIu64, cur_file->content_inspected);
251  SCLogDebug("inspect_window %" PRIu32, cur_file->inspect_window);
252  SCLogDebug("inspect_min_size %" PRIu32, cur_file->inspect_min_size);
253 
254  bool ips = false;
255  uint64_t offset = 0;
256  if (f->alproto == ALPROTO_HTTP1) {
257 
258  htp_tx_t *tx = txv;
259  HtpState *htp_state = f->alstate;
260  ips = htp_state->cfg->http_body_inline;
261 
262  const bool body_done = AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP1, tx,
263  flow_flags) > HTP_RESPONSE_BODY;
264 
265  SCLogDebug("response.body_limit %u file_size %" PRIu64
266  ", cur_file->inspect_min_size %" PRIu32 ", EOF %s, progress > body? %s",
267  htp_state->cfg->response.body_limit, file_size, cur_file->inspect_min_size,
268  flow_flags & STREAM_EOF ? "true" : "false", BOOL2STR(body_done));
269 
270  if (!htp_state->cfg->http_body_inline) {
271  /* inspect the body if the transfer is complete or we have hit
272  * our body size limit */
273  if ((htp_state->cfg->response.body_limit == 0 ||
274  file_size < htp_state->cfg->response.body_limit) &&
275  file_size < cur_file->inspect_min_size && !body_done &&
276  !(flow_flags & STREAM_EOF)) {
277  SCLogDebug("we still haven't seen the entire response body. "
278  "Let's defer body inspection till we see the "
279  "entire body.");
280  goto empty_return;
281  }
282  SCLogDebug("inline and we're continuing");
283  }
284 
285  bool force = (flow_flags & STREAM_EOF) || (cur_file->state > FILE_STATE_OPENED) ||
286  body_done || htp_state->cfg->http_body_inline;
287  /* get the inspect buffer
288  *
289  * make sure that we have at least the configured inspect_win size.
290  * If we have more, take at least 1/4 of the inspect win size before
291  * the new data.
292  */
293  if (cur_file->content_inspected == 0) {
294  if (!force && file_size < cur_file->inspect_min_size) {
295  SCLogDebug("skip as file_size %" PRIu64 " < inspect_min_size %u", file_size,
296  cur_file->inspect_min_size);
297  goto empty_return;
298  }
299  } else {
300  uint64_t new_data = file_size - cur_file->content_inspected;
301  BUG_ON(new_data == 0);
302  if (new_data < cur_file->inspect_window) {
303  uint64_t inspect_short = cur_file->inspect_window - new_data;
304  if (cur_file->content_inspected < inspect_short) {
305  offset = 0;
306  SCLogDebug("offset %" PRIu64, offset);
307  } else {
308  offset = cur_file->content_inspected - inspect_short;
309  SCLogDebug("offset %" PRIu64, offset);
310  }
311  } else {
312  BUG_ON(cur_file->content_inspected == 0);
313  uint32_t margin = cur_file->inspect_window / 4;
314  if ((uint64_t)margin <= cur_file->content_inspected) {
315  offset = cur_file->content_inspected - (cur_file->inspect_window / 4);
316  } else {
317  offset = 0;
318  }
319  SCLogDebug("offset %" PRIu64 " (data from offset %" PRIu64 ")", offset,
320  file_size - offset);
321  }
322  }
323 
324  } else {
325  if ((content_limit == 0 || file_size < content_limit) &&
326  file_size < content_inspect_min_size && !(flow_flags & STREAM_EOF) &&
327  !(cur_file->state > FILE_STATE_OPENED)) {
328  SCLogDebug("we still haven't seen the entire content. "
329  "Let's defer content inspection till we see the "
330  "entire content. We've seen %ld and need at least %d",
331  file_size, content_inspect_min_size);
332  goto empty_return;
333  }
334  offset = cur_file->content_inspected;
335  }
336 
337  const uint8_t *data;
338  uint32_t data_len;
339 
340  SCLogDebug("Fetching data at offset: %ld", offset);
341  StreamingBufferGetDataAtOffset(cur_file->sb, &data, &data_len, offset);
342  SCLogDebug("data_len %u", data_len);
343  /* update inspected tracker */
344  buffer->inspect_offset = offset;
345 
346  if (ips && file_size < cur_file->inspect_min_size) {
347  // don't update content_inspected yet
348  } else {
349  SCLogDebug("content inspected: %" PRIu64, cur_file->content_inspected);
350  cur_file->content_inspected = MAX(cur_file->content_inspected, offset + data_len);
351  SCLogDebug("content inspected: %" PRIu64, cur_file->content_inspected);
352  }
353 
354  InspectionBufferSetupMulti(buffer, NULL, data, data_len);
355  SCLogDebug("[list %d] [before] buffer offset %" PRIu64 "; buffer len %" PRIu32
356  "; data_len %" PRIu32 "; file_size %" PRIu64,
357  list_id, buffer->inspect_offset, buffer->inspect_len, data_len, file_size);
358 
359  if (f->alproto == ALPROTO_HTTP1 && flow_flags & STREAM_TOCLIENT) {
360  HtpState *htp_state = f->alstate;
361  /* built-in 'transformation' */
362  if (htp_state->cfg->swf_decompression_enabled) {
363  int swf_file_type = FileIsSwfFile(data, data_len);
364  if (swf_file_type == FILE_SWF_ZLIB_COMPRESSION ||
365  swf_file_type == FILE_SWF_LZMA_COMPRESSION) {
366  SCLogDebug("decompressing ...");
367  (void)FileSwfDecompression(data, data_len, det_ctx, buffer,
368  htp_state->cfg->swf_compression_type, htp_state->cfg->swf_decompress_depth,
369  htp_state->cfg->swf_compress_depth);
370  SCLogDebug("uncompressed buffer %p size %u; buf: \"%s\"", buffer,
371  buffer->inspect_len, (char *)buffer->inspect);
372  }
373  }
374  }
375 
376  SCLogDebug("content inspected: %" PRIu64, cur_file->content_inspected);
377 
378  /* get buffer for the list id if it is different from the base id */
379  if (list_id != base_id) {
380  SCLogDebug("regular %d has been set up: now handle xforms id %d", base_id, list_id);
381  InspectionBuffer *tbuffer = FiledataWithXformsGetDataCallback(
382  det_ctx, transforms, list_id, local_file_id, buffer);
383  SCReturnPtr(tbuffer, "InspectionBuffer");
384  }
385  SCReturnPtr(buffer, "InspectionBuffer");
386 
387 empty_return:
389  return NULL;
390 }
391 
393  const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags,
394  void *alstate, void *txv, uint64_t tx_id)
395 {
396  const DetectEngineTransforms *transforms = NULL;
397  if (!engine->mpm) {
398  transforms = engine->v2.transforms;
399  }
400 
401  AppLayerGetFileState files = AppLayerParserGetTxFiles(f, txv, flags);
402  FileContainer *ffc = files.fc;
403  if (ffc == NULL) {
405  }
406  if (ffc->head == NULL) {
407  const bool eof = (AppLayerParserGetStateProgress(f->proto, f->alproto, txv, flags) >
408  engine->progress);
409  if (eof && engine->match_on_null) {
411  }
413  }
414 
415  int local_file_id = 0;
416  File *file = ffc->head;
417  for (; file != NULL; file = file->next) {
418  InspectionBuffer *buffer = FiledataGetDataCallback(det_ctx, transforms, f, flags, file,
419  engine->sm_list, engine->sm_list_base, local_file_id, txv);
420  if (buffer == NULL)
421  continue;
422 
423  bool eof = (file->state == FILE_STATE_CLOSED);
424  uint8_t ciflags = eof ? DETECT_CI_FLAGS_END : 0;
425  if (buffer->inspect_offset == 0)
426  ciflags |= DETECT_CI_FLAGS_START;
427 
428  const bool match = DetectEngineContentInspection(de_ctx, det_ctx, s, engine->smd, NULL, f,
429  buffer->inspect, buffer->inspect_len, buffer->inspect_offset, ciflags,
431  if (match) {
433  }
434  local_file_id++;
435  }
436 
438 }
439 
440 /** \brief Filedata Filedata Mpm prefilter callback
441  *
442  * \param det_ctx detection engine thread ctx
443  * \param pectx inspection context
444  * \param p packet to inspect
445  * \param f flow to inspect
446  * \param txv tx to inspect
447  * \param idx transaction id
448  * \param flags STREAM_* flags including direction
449  */
450 static void PrefilterTxFiledata(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p,
451  Flow *f, void *txv, const uint64_t idx, const AppLayerTxData *txd, const uint8_t flags)
452 {
453  SCEnter();
454 
455  if (!AppLayerParserHasFilesInDir(txd, flags))
456  return;
457 
458  const PrefilterMpmFiledata *ctx = (const PrefilterMpmFiledata *)pectx;
459  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
460  const int list_id = ctx->list_id;
461 
462  AppLayerGetFileState files = AppLayerParserGetTxFiles(f, txv, flags);
463  FileContainer *ffc = files.fc;
464  if (ffc != NULL) {
465  int local_file_id = 0;
466  for (File *file = ffc->head; file != NULL; file = file->next) {
467  InspectionBuffer *buffer = FiledataGetDataCallback(det_ctx, ctx->transforms, f, flags,
468  file, list_id, ctx->base_list_id, local_file_id, txv);
469  if (buffer == NULL)
470  continue;
471  SCLogDebug("[%" PRIu64 "] buffer size %u", p->pcap_cnt, buffer->inspect_len);
472 
473  if (buffer->inspect_len >= mpm_ctx->minlen) {
474  uint32_t prev_rule_id_array_cnt = det_ctx->pmq.rule_id_array_cnt;
475  (void)mpm_table[mpm_ctx->mpm_type].Search(mpm_ctx, &det_ctx->mtc, &det_ctx->pmq,
476  buffer->inspect, buffer->inspect_len);
477  PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
478 
479  if (det_ctx->pmq.rule_id_array_cnt > prev_rule_id_array_cnt) {
480  SCLogDebug(
481  "%u matches", det_ctx->pmq.rule_id_array_cnt - prev_rule_id_array_cnt);
482  }
483  }
484  local_file_id++;
485  }
486  }
487 }
488 
490  const DetectBufferMpmRegistry *mpm_reg, int list_id)
491 {
492  PrefilterMpmFiledata *pectx = SCCalloc(1, sizeof(*pectx));
493  if (pectx == NULL)
494  return -1;
495  pectx->list_id = list_id;
496  pectx->base_list_id = mpm_reg->sm_list_base;
497  pectx->mpm_ctx = mpm_ctx;
498  pectx->transforms = &mpm_reg->transforms;
499 
500  return PrefilterAppendTxEngine(de_ctx, sgh, PrefilterTxFiledata,
501  mpm_reg->app_v2.alproto, mpm_reg->app_v2.tx_min_progress,
502  pectx, PrefilterMpmFiledataFree, mpm_reg->pname);
503 }
504 
505 #ifdef UNITTESTS
506 #include "tests/detect-file-data.c"
507 #endif
HtpState_::cfg
const struct HTPCfgRec_ * cfg
Definition: app-layer-htp.h:252
FILE_SWF_LZMA_COMPRESSION
@ FILE_SWF_LZMA_COMPRESSION
Definition: util-file-decompression.h:34
SMTPConfig::content_limit
uint32_t content_limit
Definition: app-layer-smtp.h:106
DetectEngineAppInspectionEngine_
Definition: detect.h:429
SigTableElmt_::url
const char * url
Definition: detect.h:1312
DetectEngineAppInspectionEngine_::mpm
bool mpm
Definition: detect.h:433
FileContainer_
Definition: util-file.h:113
MpmCtx_::mpm_type
uint8_t mpm_type
Definition: util-mpm.h:90
detect-engine.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1311
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:128
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:40
flow-util.h
SigTableElmt_::name
const char * name
Definition: detect.h:1309
InspectionBuffer::initialized
bool initialized
Definition: detect.h:377
PrefilterRuleStore_::rule_id_array_cnt
uint32_t rule_id_array_cnt
Definition: util-prefilter.h:40
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1465
SIG_FLAG_INIT_FLOW
#define SIG_FLAG_INIT_FLOW
Definition: detect.h:288
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms
Definition: detect.h:408
DetectBufferMpmRegistry_::sm_list_base
int16_t sm_list_base
Definition: detect.h:692
HTPCfgRec_::response
HTPCfgDir response
Definition: app-layer-htp.h:171
File_::inspect_min_size
uint32_t inspect_min_size
Definition: util-file.h:104
SIG_FLAG_INIT_NEED_FLUSH
#define SIG_FLAG_INIT_NEED_FLUSH
Definition: detect.h:293
File_::size
uint64_t size
Definition: util-file.h:102
Signature_::alproto
AppProto alproto
Definition: detect.h:608
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
SIG_FLAG_INIT_FILEDATA
#define SIG_FLAG_INIT_FILEDATA
Definition: detect.h:296
Packet_::pcap_cnt
uint64_t pcap_cnt
Definition: decode.h:595
DetectEngineCtx_::filedata_config
DetectFileDataCfg * filedata_config
Definition: detect.h:953
HTPCfgDir_::body_limit
uint32_t body_limit
Definition: app-layer-htp.h:150
Flow_::proto
uint8_t proto
Definition: flow.h:378
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:81
DetectBufferSetActiveList
int DetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
Definition: detect-engine.c:1357
DetectFileDataCfg
Definition: detect.h:837
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:1072
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:373
threads.h
FILE_STATE_OPENED
@ FILE_STATE_OPENED
Definition: util-file.h:70
Flow_
Flow data structure.
Definition: flow.h:356
File_::state
FileState state
Definition: util-file.h:82
DetectBufferTypeRegisterSetupCallback
void DetectBufferTypeRegisterSetupCallback(const char *name, void(*SetupCallback)(const DetectEngineCtx *, Signature *))
Definition: detect-engine.c:1288
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1205
DetectBufferMpmRegistry_::app_v2
struct DetectBufferMpmRegistry_::@84::@86 app_v2
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1303
ctx
struct Thresholds ctx
AppLayerParserSupportsFiles
bool AppLayerParserSupportsFiles(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:1154
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:843
PrefilterMpmFiledataRegister
int PrefilterMpmFiledataRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
Definition: detect-file-data.c:489
DetectBufferTypeSupportsMultiInstance
void DetectBufferTypeSupportsMultiInstance(const char *name)
Definition: detect-engine.c:1044
DetectEngineAppInspectionEngine_::v2
struct DetectEngineAppInspectionEngine_::@79 v2
DetectBufferMpmRegistry_
one time registration of keywords at start up
Definition: detect.h:687
detect-file-data.h
DetectEngineAppInspectionEngine_::sm_list_base
uint16_t sm_list_base
Definition: detect.h:438
FILEDATA_CONTENT_LIMIT
#define FILEDATA_CONTENT_LIMIT
Definition: app-layer-smtp.c:58
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:555
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:1808
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:268
MAX
#define MAX(x, y)
Definition: suricata-common.h:395
ALPROTO_MAX
@ ALPROTO_MAX
Definition: app-layer-protos.h:76
filehandler_table
DetectFileHandlerTableElmt filehandler_table[DETECT_TBLSIZE_STATIC]
Definition: detect-parse.c:78
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1294
DetectBufferMpmRegistry_::transforms
DetectEngineTransforms transforms
Definition: detect.h:700
detect-engine-prefilter.h
util-unittest.h
HtpState_
Definition: app-layer-htp.h:238
SMTPConfig::content_inspect_min_size
uint32_t content_inspect_min_size
Definition: app-layer-smtp.h:107
util-unittest-helper.h
AppLayerParserGetTxFiles
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
Definition: app-layer-parser.c:854
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1094
File_::sb
StreamingBuffer * sb
Definition: util-file.h:83
DetectEngineAppInspectionEngine_::sm_list
uint16_t sm_list
Definition: detect.h:437
DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
Definition: detect-engine-state.h:43
PrefilterMpmFiledata::transforms
const DetectEngineTransforms * transforms
Definition: detect-file-data.h:34
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:267
app-layer-htp.h
InspectionBufferSetupMultiEmpty
void InspectionBufferSetupMultiEmpty(InspectionBuffer *buffer)
setup the buffer empty
Definition: detect-engine.c:1568
DetectFileDataCfg::content_inspect_min_size
uint32_t content_inspect_min_size
Definition: detect.h:839
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:1098
ALPROTO_SMTP
@ ALPROTO_SMTP
Definition: app-layer-protos.h:32
detect-engine-file.h
BOOL2STR
#define BOOL2STR(b)
Definition: util-debug.h:527
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
detect-engine-mpm.h
FileContainer_::head
File * head
Definition: util-file.h:114
detect.h
HTPCfgRec_::swf_decompress_depth
uint32_t swf_decompress_depth
Definition: app-layer-htp.h:167
DETECT_ENGINE_INSPECT_SIG_MATCH
#define DETECT_ENGINE_INSPECT_SIG_MATCH
Definition: detect-engine-state.h:38
PrefilterMpmFiledata::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-file-data.h:33
DetectFiledataRegister
void DetectFiledataRegister(void)
Registration function for keyword: file_data.
Definition: detect-file-data.c:71
HTPCfgRec_::swf_decompression_enabled
int swf_decompression_enabled
Definition: app-layer-htp.h:165
FILEDATA_CONTENT_INSPECT_MIN_SIZE
#define FILEDATA_CONTENT_INSPECT_MIN_SIZE
Definition: app-layer-smtp.c:60
InspectionBuffer::inspect_offset
uint64_t inspect_offset
Definition: detect.h:375
DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
@ DETECT_ENGINE_CONTENT_INSPECTION_MODE_STATE
Definition: detect-engine-content-inspection.h:36
app-layer-parser.h
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:99
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:300
smtp_config
SMTPConfig smtp_config
Definition: app-layer-smtp.c:292
util-profiling.h
PrefilterMpmFiledata::base_list_id
int base_list_id
Definition: detect-file-data.h:32
Signature_::flags
uint32_t flags
Definition: detect.h:604
Packet_
Definition: decode.h:476
DETECT_CI_FLAGS_END
#define DETECT_CI_FLAGS_END
Definition: detect-engine-content-inspection.h:42
DetectEngineAppInspectionEngine_::match_on_null
bool match_on_null
Definition: detect.h:436
DetectFileDataCfg::content_limit
uint32_t content_limit
Definition: detect.h:838
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:672
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:287
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:485
DetectFileHandlerTableElmt_::priority
int priority
Definition: detect-parse.h:34
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:168
DETECT_FILE_DATA
@ DETECT_FILE_DATA
Definition: detect-engine-register.h:201
DetectEngineThreadCtx_::mtc
MpmThreadCtx mtc
Definition: detect.h:1204
FileDataSize
uint64_t FileDataSize(const File *file)
get the size of the file data
Definition: util-file.c:326
detect-engine-content-inspection.h
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:451
File_::content_inspected
uint64_t content_inspected
Definition: util-file.h:99
FILE_STATE_CLOSED
@ FILE_STATE_CLOSED
Definition: util-file.h:71
File_
Definition: util-file.h:79
AppLayerTxData
struct AppLayerTxData AppLayerTxData
Definition: detect.h:1372
PREFILTER_PROFILING_ADD_BYTES
#define PREFILTER_PROFILING_ADD_BYTES(det_ctx, bytes)
Definition: util-profiling.h:286
flags
uint8_t flags
Definition: decode-gre.h:0
Signature_::proto
DetectProto proto
Definition: detect.h:622
SigTableElmt_::alias
const char * alias
Definition: detect.h:1310
suricata-common.h
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:30
File_::next
struct File_ * next
Definition: util-file.h:92
DetectFileHandlerTableElmt_::PrefilterFn
PrefilterRegisterFunc PrefilterFn
Definition: detect-parse.h:35
util-spm-bm.h
InspectionBufferSetupMulti
void InspectionBufferSetupMulti(InspectionBuffer *buffer, const DetectEngineTransforms *transforms, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
Definition: detect-engine.c:1581
PrefilterAppendTxEngine
int PrefilterAppendTxEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterTxFn PrefilterTxFunc, AppProto alproto, int tx_min_progress, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
Definition: detect-engine-prefilter.c:273
DETECT_ENGINE_INSPECT_SIG_NO_MATCH
#define DETECT_ENGINE_INSPECT_SIG_NO_MATCH
Definition: detect-engine-state.h:37
DetectEngineAppInspectionEngine_::progress
int16_t progress
Definition: detect.h:439
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
InspectionBuffer::inspect_len
uint32_t inspect_len
Definition: detect.h:376
DetectFiledataRegisterTests
void DetectFiledataRegisterTests(void)
Definition: detect-file-data.c:64
InspectionBuffer::inspect
const uint8_t * inspect
Definition: detect.h:374
str
#define str(s)
Definition: suricata-common.h:291
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Flow_::alstate
void * alstate
Definition: flow.h:481
Signature_::id
uint32_t id
Definition: detect.h:638
detect-parse.h
Signature_
Signature container.
Definition: detect.h:603
AppLayerGetProtoName
const char * AppLayerGetProtoName(AppProto alproto)
Given the internal protocol id, returns a string representation of the protocol.
Definition: app-layer.c:1006
DetectEngineAppInspectionEngine_::transforms
const DetectEngineTransforms * transforms
Definition: detect.h:448
util-file-decompression.h
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition: app-layer-protos.h:70
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
File_::inspect_window
uint32_t inspect_window
Definition: util-file.h:103
mpm_table
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.c:47
DetectFileHandlerTableElmt_::Callback
InspectEngineFuncPtr Callback
Definition: detect-parse.h:36
DetectEngineThreadCtx_::de_ctx
DetectEngineCtx * de_ctx
Definition: detect.h:1220
InspectionBufferMultipleForListGet
InspectionBuffer * InspectionBufferMultipleForListGet(DetectEngineThreadCtx *det_ctx, const int list_id, const uint32_t local_id)
for a InspectionBufferMultipleForList get a InspectionBuffer
Definition: detect-engine.c:1521
FILE_SWF_ZLIB_COMPRESSION
@ FILE_SWF_ZLIB_COMPRESSION
Definition: util-file-decompression.h:33
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect.h:1493
DetectFileHandlerTableElmt_::name
const char * name
Definition: detect-parse.h:33
app-layer-smtp.h
DetectBufferTypeSetDescriptionByName
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
Definition: detect-engine.c:1191
PrefilterMpmFiledata
Definition: detect-file-data.h:30
MpmCtx_
Definition: util-mpm.h:88
flow.h
DetectEngineContentInspection
bool DetectEngineContentInspection(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Packet *p, Flow *f, const uint8_t *buffer, const uint32_t buffer_len, const uint32_t stream_start_offset, const uint8_t flags, const enum DetectContentInspectionType inspection_mode)
wrapper around DetectEngineContentInspectionInternal to return true/false only
Definition: detect-engine-content-inspection.c:723
detect-file-data.c
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:455
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
PrefilterMpmFiledata::list_id
int list_id
Definition: detect-file-data.h:31
flow-var.h
DetectEngineInspectFiledata
uint8_t DetectEngineInspectFiledata(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)
Definition: detect-file-data.c:392
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1301
app-layer.h
DetectProtoContainsProto
int DetectProtoContainsProto(const DetectProto *dp, int proto)
see if a DetectProto contains a certain proto
Definition: detect-engine-proto.c:135
DetectBufferMpmRegistry_::pname
char pname[32]
Definition: detect.h:689