suricata
detect-engine-analyzer.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 Eileen Donlon <emdonlo@gmail.com>
22  * \author Victor Julien <victor@inliniac.net>
23  *
24  * Rule analyzers for the detection engine
25  */
26 
27 #include "suricata-common.h"
28 #include "suricata.h"
29 #include "rust.h"
30 #include "detect.h"
31 #include "detect-parse.h"
32 #include "detect-engine.h"
33 #include "detect-engine-analyzer.h"
34 #include "detect-engine-mpm.h"
35 #include "conf.h"
36 #include "detect-content.h"
37 #include "detect-flow.h"
38 #include "detect-tcp-flags.h"
39 #include "feature.h"
40 #include "util-print.h"
41 
42 static int rule_warnings_only = 0;
43 static FILE *rule_engine_analysis_FD = NULL;
44 static FILE *fp_engine_analysis_FD = NULL;
45 static pcre *percent_re = NULL;
46 static pcre_extra *percent_re_study = NULL;
47 static char log_path[PATH_MAX];
48 
49 typedef struct FpPatternStats_ {
50  uint16_t min;
51  uint16_t max;
52  uint32_t cnt;
53  uint64_t tot;
55 
56 /* Details for each buffer being tracked */
57 typedef struct DetectEngineAnalyzerItems {
58  int16_t item_id;
59  bool item_seen;
62  const char *item_name;
63  const char *display_name;
65 
66 /* Track which items require the item_seen value to be exposed */
68  const char *bufname;
70 };
71 
73  /* request keywords */
74  { 0, false, false, true, "http_uri", "http uri" },
75  { 0, false, false, false, "http_raw_uri", "http raw uri" },
76  { 0, false, true, false, "http_method", "http method" },
77  { 0, false, false, false, "http_request_line", "http request line" },
78  { 0, false, false, false, "http_client_body", "http client body" },
79  { 0, false, false, true, "http_header", "http header" },
80  { 0, false, false, false, "http_raw_header", "http raw header" },
81  { 0, false, false, true, "http_cookie", "http cookie" },
82  { 0, false, false, false, "http_user_agent", "http user agent" },
83  { 0, false, false, false, "http_host", "http host" },
84  { 0, false, false, false, "http_raw_host", "http raw host" },
85  { 0, false, false, false, "http_accept_enc", "http accept enc" },
86  { 0, false, false, false, "http_referer", "http referer" },
87  { 0, false, false, false, "http_content_type", "http content type" },
88  { 0, false, false, false, "http_header_names", "http header names" },
89 
90  /* response keywords not listed above */
91  { 0, false, false, false, "http_stat_msg", "http stat msg" },
92  { 0, false, false, false, "http_stat_code", "http stat code" },
93  { 0, false, true, false, "file_data", "http server body"},
94 
95  /* missing request keywords */
96  { 0, false, false, false, "http_request_line", "http request line" },
97  { 0, false, false, false, "http_accept", "http accept" },
98  { 0, false, false, false, "http_accept_lang", "http accept lang" },
99  { 0, false, false, false, "http_connection", "http connection" },
100  { 0, false, false, false, "http_content_len", "http content len" },
101  { 0, false, false, false, "http_protocol", "http protocol" },
102  { 0, false, false, false, "http_start", "http start" },
103 
104  /* missing response keywords; some of the missing are listed above*/
105  { 0, false, false, false, "http_response_line", "http response line" },
106  { 0, false, false, false, "http.server", "http server" },
107  { 0, false, false, false, "http.location", "http location" },
108 };
109 
110 /*
111  * This array contains the map between the `analyzer_items` array listed above and
112  * the item ids returned by DetectBufferTypeGetByName. Iterating signature's sigmatch
113  * array provides list_ids. The map converts those ids into elements of the
114  * analyzer items array.
115  *
116  * Ultimately, the g_buffer_type_hash is searched for each buffer name. The size of that
117  * hashlist is 256, so that's the value we use here.
118  */
119 int16_t analyzer_item_map[256];
120 
121 /*
122  * Certain values must be directly accessible. This array contains items that are directly
123  * accessed when checking if they've been seen or not.
124  */
126  { .bufname = "http_method"},
127  { .bufname = "file_data"}
128 };
129 
130 static FpPatternStats fp_pattern_stats[DETECT_SM_LIST_MAX];
131 
132 static void FpPatternStatsAdd(int list, uint16_t patlen)
133 {
134  if (list < 0 || list >= DETECT_SM_LIST_MAX)
135  return;
136 
137  FpPatternStats *f = &fp_pattern_stats[list];
138 
139  if (f->min == 0)
140  f->min = patlen;
141  else if (patlen < f->min)
142  f->min = patlen;
143 
144  if (patlen > f->max)
145  f->max = patlen;
146 
147  f->cnt++;
148  f->tot += patlen;
149 }
150 
151 void EngineAnalysisFP(const DetectEngineCtx *de_ctx, const Signature *s, char *line)
152 {
153  int fast_pattern_set = 0;
154  int fast_pattern_only_set = 0;
155  int fast_pattern_chop_set = 0;
156  DetectContentData *fp_cd = NULL;
157  SigMatch *mpm_sm = s->init_data->mpm_sm;
158 
159  if (mpm_sm != NULL) {
160  fp_cd = (DetectContentData *)mpm_sm->ctx;
161  if (fp_cd->flags & DETECT_CONTENT_FAST_PATTERN) {
162  fast_pattern_set = 1;
164  fast_pattern_only_set = 1;
165  } else if (fp_cd->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) {
166  fast_pattern_chop_set = 1;
167  }
168  }
169  }
170 
171  fprintf(fp_engine_analysis_FD, "== Sid: %u ==\n", s->id);
172  fprintf(fp_engine_analysis_FD, "%s\n", line);
173 
174  fprintf(fp_engine_analysis_FD, " Fast Pattern analysis:\n");
175  if (s->init_data->prefilter_sm != NULL) {
176  fprintf(fp_engine_analysis_FD, " Prefilter on: %s\n",
178  fprintf(fp_engine_analysis_FD, "\n");
179  return;
180  }
181 
182  if (fp_cd == NULL) {
183  fprintf(fp_engine_analysis_FD, " No content present\n");
184  fprintf(fp_engine_analysis_FD, "\n");
185  return;
186  }
187 
188  fprintf(fp_engine_analysis_FD, " Fast pattern matcher: ");
189  int list_type = SigMatchListSMBelongsTo(s, mpm_sm);
190  if (list_type == DETECT_SM_LIST_PMATCH)
191  fprintf(fp_engine_analysis_FD, "content\n");
192  else {
193  const char *desc = DetectBufferTypeGetDescriptionById(de_ctx, list_type);
194  const char *name = DetectBufferTypeGetNameById(de_ctx, list_type);
195  if (desc && name) {
196  fprintf(fp_engine_analysis_FD, "%s (%s)\n", desc, name);
197  }
198  }
199 
200  int flags_set = 0;
201  fprintf(fp_engine_analysis_FD, " Flags:");
202  if (fp_cd->flags & DETECT_CONTENT_OFFSET) {
203  fprintf(fp_engine_analysis_FD, " Offset");
204  flags_set = 1;
205  } if (fp_cd->flags & DETECT_CONTENT_DEPTH) {
206  fprintf(fp_engine_analysis_FD, " Depth");
207  flags_set = 1;
208  }
209  if (fp_cd->flags & DETECT_CONTENT_WITHIN) {
210  fprintf(fp_engine_analysis_FD, " Within");
211  flags_set = 1;
212  }
213  if (fp_cd->flags & DETECT_CONTENT_DISTANCE) {
214  fprintf(fp_engine_analysis_FD, " Distance");
215  flags_set = 1;
216  }
217  if (fp_cd->flags & DETECT_CONTENT_NOCASE) {
218  fprintf(fp_engine_analysis_FD, " Nocase");
219  flags_set = 1;
220  }
221  if (fp_cd->flags & DETECT_CONTENT_NEGATED) {
222  fprintf(fp_engine_analysis_FD, " Negated");
223  flags_set = 1;
224  }
225  if (flags_set == 0)
226  fprintf(fp_engine_analysis_FD, " None");
227  fprintf(fp_engine_analysis_FD, "\n");
228 
229  fprintf(fp_engine_analysis_FD, " Fast pattern set: %s\n", fast_pattern_set ? "yes" : "no");
230  fprintf(fp_engine_analysis_FD, " Fast pattern only set: %s\n",
231  fast_pattern_only_set ? "yes" : "no");
232  fprintf(fp_engine_analysis_FD, " Fast pattern chop set: %s\n",
233  fast_pattern_chop_set ? "yes" : "no");
234  if (fast_pattern_chop_set) {
235  fprintf(fp_engine_analysis_FD, " Fast pattern offset, length: %u, %u\n",
236  fp_cd->fp_chop_offset, fp_cd->fp_chop_len);
237  }
238 
239  uint16_t patlen = fp_cd->content_len;
240  uint8_t *pat = SCMalloc(fp_cd->content_len + 1);
241  if (unlikely(pat == NULL)) {
242  FatalError(SC_ERR_FATAL, "Error allocating memory");
243  }
244  memcpy(pat, fp_cd->content, fp_cd->content_len);
245  pat[fp_cd->content_len] = '\0';
246  fprintf(fp_engine_analysis_FD, " Original content: ");
247  PrintRawUriFp(fp_engine_analysis_FD, pat, patlen);
248  fprintf(fp_engine_analysis_FD, "\n");
249 
250  if (fast_pattern_chop_set) {
251  SCFree(pat);
252  patlen = fp_cd->fp_chop_len;
253  pat = SCMalloc(fp_cd->fp_chop_len + 1);
254  if (unlikely(pat == NULL)) {
255  exit(EXIT_FAILURE);
256  }
257  memcpy(pat, fp_cd->content + fp_cd->fp_chop_offset, fp_cd->fp_chop_len);
258  pat[fp_cd->fp_chop_len] = '\0';
259  fprintf(fp_engine_analysis_FD, " Final content: ");
260  PrintRawUriFp(fp_engine_analysis_FD, pat, patlen);
261  fprintf(fp_engine_analysis_FD, "\n");
262 
263  FpPatternStatsAdd(list_type, patlen);
264  } else {
265  fprintf(fp_engine_analysis_FD, " Final content: ");
266  PrintRawUriFp(fp_engine_analysis_FD, pat, patlen);
267  fprintf(fp_engine_analysis_FD, "\n");
268 
269  FpPatternStatsAdd(list_type, patlen);
270  }
271  SCFree(pat);
272 
273  fprintf(fp_engine_analysis_FD, "\n");
274  return;
275 }
276 
277 /**
278  * \brief Sets up the fast pattern analyzer according to the config.
279  *
280  * \retval 1 If rule analyzer successfully enabled.
281  * \retval 0 If not enabled.
282  */
284 {
285  int fp_engine_analysis_set = 0;
286 
287  if ((ConfGetBool("engine-analysis.rules-fast-pattern",
288  &fp_engine_analysis_set)) == 0) {
289  return 0;
290  }
291 
292  if (fp_engine_analysis_set == 0)
293  return 0;
294 
295  const char *log_dir;
296  log_dir = ConfigGetLogDirectory();
297  snprintf(log_path, sizeof(log_path), "%s/%s", log_dir,
298  "rules_fast_pattern.txt");
299 
300  fp_engine_analysis_FD = fopen(log_path, "w");
301  if (fp_engine_analysis_FD == NULL) {
302  SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", log_path,
303  strerror(errno));
304  return 0;
305  }
306 
307  SCLogInfo("Engine-Analysis for fast_pattern printed to file - %s",
308  log_path);
309 
310  struct timeval tval;
311  struct tm *tms;
312  gettimeofday(&tval, NULL);
313  struct tm local_tm;
314  tms = SCLocalTime(tval.tv_sec, &local_tm);
315  fprintf(fp_engine_analysis_FD, "----------------------------------------------"
316  "---------------------\n");
317  fprintf(fp_engine_analysis_FD, "Date: %" PRId32 "/%" PRId32 "/%04d -- "
318  "%02d:%02d:%02d\n",
319  tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour,
320  tms->tm_min, tms->tm_sec);
321  fprintf(fp_engine_analysis_FD, "----------------------------------------------"
322  "---------------------\n");
323 
324  memset(&fp_pattern_stats, 0, sizeof(fp_pattern_stats));
325  return 1;
326 }
327 
328 /**
329  * \brief Sets up the rule analyzer according to the config
330  * \retval 1 if rule analyzer successfully enabled
331  * \retval 0 if not enabled
332  */
334 {
335  ConfNode *conf = ConfGetNode("engine-analysis");
336  int enabled = 0;
337  if (conf != NULL) {
338  const char *value = ConfNodeLookupChildValue(conf, "rules");
339  if (value && ConfValIsTrue(value)) {
340  enabled = 1;
341  } else if (value && strcasecmp(value, "warnings-only") == 0) {
342  enabled = 1;
343  rule_warnings_only = 1;
344  }
345  if (enabled) {
346  const char *log_dir;
347  log_dir = ConfigGetLogDirectory();
348  snprintf(log_path, sizeof(log_path), "%s/%s", log_dir, "rules_analysis.txt");
349  rule_engine_analysis_FD = fopen(log_path, "w");
350  if (rule_engine_analysis_FD == NULL) {
351  SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", log_path, strerror(errno));
352  return 0;
353  }
354 
355  SCLogInfo("Engine-Analysis for rules printed to file - %s",
356  log_path);
357 
358  struct timeval tval;
359  struct tm *tms;
360  gettimeofday(&tval, NULL);
361  struct tm local_tm;
362  tms = SCLocalTime(tval.tv_sec, &local_tm);
363  fprintf(rule_engine_analysis_FD, "----------------------------------------------"
364  "---------------------\n");
365  fprintf(rule_engine_analysis_FD, "Date: %" PRId32 "/%" PRId32 "/%04d -- "
366  "%02d:%02d:%02d\n",
367  tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour,
368  tms->tm_min, tms->tm_sec);
369  fprintf(rule_engine_analysis_FD, "----------------------------------------------"
370  "---------------------\n");
371 
372  /*compile regex's for rule analysis*/
373  if (PerCentEncodingSetup()== 0) {
374  fprintf(rule_engine_analysis_FD, "Error compiling regex; can't check for percent encoding in normalized http content.\n");
375  }
376  }
377  }
378  else {
379  SCLogInfo("Conf parameter \"engine-analysis.rules\" not found. "
380  "Defaulting to not printing the rules analysis report.");
381  }
382  if (!enabled) {
383  SCLogInfo("Engine-Analysis for rules disabled in conf file.");
384  return 0;
385  }
386  return 1;
387 }
388 
390 {
391  fprintf(fp_engine_analysis_FD, "============\n"
392  "Summary:\n============\n");
393  int i;
394  for (i = 0; i < DETECT_SM_LIST_MAX; i++) {
395  FpPatternStats *f = &fp_pattern_stats[i];
396  if (f->cnt == 0)
397  continue;
398 
399  fprintf(fp_engine_analysis_FD,
400  "%s, smallest pattern %u byte(s), longest pattern %u byte(s), number of patterns %u, avg pattern len %.2f byte(s)\n",
401  DetectSigmatchListEnumToString(i), f->min, f->max, f->cnt, (float)((double)f->tot/(float)f->cnt));
402  }
403 
404  if (fp_engine_analysis_FD != NULL) {
405  fclose(fp_engine_analysis_FD);
406  fp_engine_analysis_FD = NULL;
407  }
408 
409  return;
410 }
411 
412 
414 {
415  if (rule_engine_analysis_FD != NULL) {
416  SCLogInfo("Engine-Analysis for rules printed to file - %s", log_path);
417  fclose(rule_engine_analysis_FD);
418  rule_engine_analysis_FD = NULL;
419  }
420 }
421 
422 /**
423  * \brief Compiles regex for rule analysis
424  * \retval 1 if successful
425  * \retval 0 if on error
426  */
428 {
429 #define DETECT_PERCENT_ENCODING_REGEX "%[0-9|a-f|A-F]{2}"
430  const char *eb = NULL;
431  int eo = 0;
432  int opts = 0; //PCRE_NEWLINE_ANY??
433 
434  percent_re = pcre_compile(DETECT_PERCENT_ENCODING_REGEX, opts, &eb, &eo, NULL);
435  if (percent_re == NULL) {
436  SCLogError(SC_ERR_PCRE_COMPILE, "Compile of \"%s\" failed at offset %" PRId32 ": %s",
438  return 0;
439  }
440 
441  percent_re_study = pcre_study(percent_re, 0, &eb);
442  if (eb != NULL) {
443  SCLogError(SC_ERR_PCRE_STUDY, "pcre study failed: %s", eb);
444  return 0;
445  }
446  return 1;
447 }
448 
449 /**
450  * \brief Checks for % encoding in content.
451  * \param Pointer to content
452  * \retval number of matches if content has % encoding
453  * \retval 0 if it doesn't have % encoding
454  * \retval -1 on error
455  */
456 int PerCentEncodingMatch (uint8_t *content, uint8_t content_len)
457 {
458 #define MAX_ENCODED_CHARS 240
459  int ret = 0;
460  int ov[MAX_ENCODED_CHARS];
461 
462  ret = pcre_exec(percent_re, percent_re_study, (char *)content, content_len, 0, 0, ov, MAX_ENCODED_CHARS);
463  if (ret == -1) {
464  return 0;
465  }
466  else if (ret < -1) {
467  SCLogError(SC_ERR_PCRE_MATCH, "Error parsing content - %s; error code is %d", content, ret);
468  return -1;
469  }
470  return ret;
471 }
472 
473 static void EngineAnalysisRulesPrintFP(const DetectEngineCtx *de_ctx, const Signature *s)
474 {
475  DetectContentData *fp_cd = NULL;
476  SigMatch *mpm_sm = s->init_data->mpm_sm;
477 
478  if (mpm_sm != NULL) {
479  fp_cd = (DetectContentData *)mpm_sm->ctx;
480  }
481 
482  if (fp_cd == NULL) {
483  return;
484  }
485 
486  uint16_t patlen = fp_cd->content_len;
487  uint8_t *pat = SCMalloc(fp_cd->content_len + 1);
488  if (unlikely(pat == NULL)) {
489  FatalError(SC_ERR_FATAL, "Error allocating memory");
490  }
491  memcpy(pat, fp_cd->content, fp_cd->content_len);
492  pat[fp_cd->content_len] = '\0';
493 
495  SCFree(pat);
496  patlen = fp_cd->fp_chop_len;
497  pat = SCMalloc(fp_cd->fp_chop_len + 1);
498  if (unlikely(pat == NULL)) {
499  exit(EXIT_FAILURE);
500  }
501  memcpy(pat, fp_cd->content + fp_cd->fp_chop_offset, fp_cd->fp_chop_len);
502  pat[fp_cd->fp_chop_len] = '\0';
503  fprintf(rule_engine_analysis_FD, " Fast Pattern \"");
504  PrintRawUriFp(rule_engine_analysis_FD, pat, patlen);
505  } else {
506  fprintf(rule_engine_analysis_FD, " Fast Pattern \"");
507  PrintRawUriFp(rule_engine_analysis_FD, pat, patlen);
508  }
509  SCFree(pat);
510 
511  fprintf(rule_engine_analysis_FD, "\" on \"");
512 
513  int list_type = SigMatchListSMBelongsTo(s, mpm_sm);
514  if (list_type == DETECT_SM_LIST_PMATCH) {
515  int payload = 0;
516  int stream = 0;
518  payload = 1;
520  stream = 1;
521  fprintf(rule_engine_analysis_FD, "%s",
522  payload ? (stream ? "payload and reassembled stream" : "payload") : "reassembled stream");
523  }
524  else {
525  const char *desc = DetectBufferTypeGetDescriptionById(de_ctx, list_type);
526  const char *name = DetectBufferTypeGetNameById(de_ctx, list_type);
527  if (desc && name) {
528  fprintf(rule_engine_analysis_FD, "%s (%s)", desc, name);
529  } else if (desc || name) {
530  fprintf(rule_engine_analysis_FD, "%s", desc ? desc : name);
531  }
532 
533  }
534 
535  fprintf(rule_engine_analysis_FD, "\" ");
536  if (de_ctx->buffer_type_map[list_type] && de_ctx->buffer_type_map[list_type]->transforms.cnt) {
537  fprintf(rule_engine_analysis_FD, "(with %d transform(s)) ",
538  de_ctx->buffer_type_map[list_type]->transforms.cnt);
539  }
540  fprintf(rule_engine_analysis_FD, "buffer.\n");
541 
542  return;
543 }
544 
545 
546 void EngineAnalysisRulesFailure(char *line, char *file, int lineno)
547 {
548  fprintf(rule_engine_analysis_FD, "== Sid: UNKNOWN ==\n");
549  fprintf(rule_engine_analysis_FD, "%s\n", line);
550  fprintf(rule_engine_analysis_FD, " FAILURE: invalid rule.\n");
551  fprintf(rule_engine_analysis_FD, " File: %s.\n", file);
552  fprintf(rule_engine_analysis_FD, " Line: %d.\n", lineno);
553  fprintf(rule_engine_analysis_FD, "\n");
554 }
555 
556 typedef struct RuleAnalyzer {
557  JsonBuilder *js; /* document root */
558 
559  JsonBuilder *js_warnings;
560  JsonBuilder *js_notes;
562 
563 static void __attribute__ ((format (printf, 2, 3)))
564 AnalyzerNote(RuleAnalyzer *ctx, char *fmt, ...)
565 {
566  va_list ap;
567  char str[1024];
568 
569  va_start(ap, fmt);
570  vsnprintf(str, sizeof(str), fmt, ap);
571  va_end(ap);
572 
573  if (!ctx->js_notes)
574  ctx->js_notes = jb_new_array();
575  if (ctx->js_notes)
576  jb_append_string(ctx->js_notes, str);
577 }
578 
579 static void __attribute__ ((format (printf, 2, 3)))
580 AnalyzerWarning(RuleAnalyzer *ctx, char *fmt, ...)
581 {
582  va_list ap;
583  char str[1024];
584 
585  va_start(ap, fmt);
586  vsnprintf(str, sizeof(str), fmt, ap);
587  va_end(ap);
588 
589  if (!ctx->js_warnings)
590  ctx->js_warnings = jb_new_array();
591  if (ctx->js_warnings)
592  jb_append_string(ctx->js_warnings, str);
593 }
594 
595 #define CHECK(pat) if (strlen((pat)) <= len && memcmp((pat), buf, MIN(len, strlen((pat)))) == 0) return true;
596 
597 static bool LooksLikeHTTPMethod(const uint8_t *buf, uint16_t len)
598 {
599  CHECK("GET /");
600  CHECK("POST /");
601  CHECK("HEAD /");
602  CHECK("PUT /");
603  return false;
604 }
605 
606 static bool LooksLikeHTTPUA(const uint8_t *buf, uint16_t len)
607 {
608  CHECK("User-Agent: ");
609  CHECK("\nUser-Agent: ");
610  return false;
611 }
612 
613 static void DumpMatches(RuleAnalyzer *ctx, JsonBuilder *js, const SigMatchData *smd)
614 {
615  if (smd == NULL)
616  return;
617 
618  jb_open_array(js, "matches");
619  do {
620  jb_start_object(js);
621  const char *mname = sigmatch_table[smd->type].name;
622  jb_set_string(js, "name", mname);
623 
624  switch (smd->type) {
625  case DETECT_CONTENT: {
626  const DetectContentData *cd = (const DetectContentData *)smd->ctx;
627 
628  jb_open_object(js, "content");
629  jb_set_string_from_bytes(js, "pattern", cd->content, cd->content_len);
630  jb_set_bool(js, "nocase", cd->flags & DETECT_CONTENT_NOCASE);
631  jb_set_bool(js, "negated", cd->flags & DETECT_CONTENT_NEGATED);
632  jb_set_bool(js, "starts_with", cd->flags & DETECT_CONTENT_STARTS_WITH);
633  jb_set_bool(js, "ends_with", cd->flags & DETECT_CONTENT_ENDS_WITH);
634  jb_set_bool(js, "is_mpm", cd->flags & DETECT_CONTENT_MPM);
635  if (cd->flags & DETECT_CONTENT_OFFSET) {
636  jb_set_uint(js, "offset", cd->offset);
637  }
638  if (cd->flags & DETECT_CONTENT_DEPTH) {
639  jb_set_uint(js, "depth", cd->depth);
640  }
641  if (cd->flags & DETECT_CONTENT_DISTANCE) {
642  jb_set_uint(js, "distance", cd->distance);
643  }
644  if (cd->flags & DETECT_CONTENT_WITHIN) {
645  jb_set_uint(js, "within", cd->within);
646  }
647  jb_set_bool(js, "fast_pattern", cd->flags & DETECT_CONTENT_FAST_PATTERN);
649  AnalyzerNote(ctx, (char *)"'fast_pattern:only' option is silently ignored and "
650  "is interpreted as regular 'fast_pattern'");
651  }
652  if (LooksLikeHTTPMethod(cd->content, cd->content_len)) {
653  AnalyzerWarning(ctx,
654  (char *)"pattern looks like it inspects HTTP, use http_request_line or "
655  "http_method and http_uri instead for improved performance");
656  }
657  if (LooksLikeHTTPUA(cd->content, cd->content_len)) {
658  AnalyzerWarning(ctx,
659  (char *)"pattern looks like it inspects HTTP, use http_user_agent "
660  "or http_header for improved performance");
661  }
662  jb_close(js);
663  break;
664  }
665  }
666  jb_close(js);
667 
668  if (smd->is_last)
669  break;
670  smd++;
671  } while (1);
672  jb_close(js);
673 }
674 
677 {
678  SCEnter();
679 
680  RuleAnalyzer ctx = { NULL, NULL, NULL };
681 
682  ctx.js = jb_new_object();
683  if (ctx.js == NULL)
684  SCReturn;
685 
686  jb_set_string(ctx.js, "raw", s->sig_str);
687  jb_set_uint(ctx.js, "id", s->id);
688  jb_set_uint(ctx.js, "gid", s->gid);
689  jb_set_uint(ctx.js, "rev", s->rev);
690  jb_set_string(ctx.js, "msg", s->msg);
691 
692  const char *alproto = AppProtoToString(s->alproto);
693  jb_set_string(ctx.js, "app_proto", alproto);
694 
695  jb_open_array(ctx.js, "requirements");
696  if (s->mask & SIG_MASK_REQUIRE_PAYLOAD) {
697  jb_append_string(ctx.js, "payload");
698  }
700  jb_append_string(ctx.js, "no_payload");
701  }
702  if (s->mask & SIG_MASK_REQUIRE_FLOW) {
703  jb_append_string(ctx.js, "flow");
704  }
706  jb_append_string(ctx.js, "tcp_flags_init_deinit");
707  }
709  jb_append_string(ctx.js, "tcp_flags_unusual");
710  }
711  if (s->mask & SIG_MASK_REQUIRE_DCERPC) {
712  jb_append_string(ctx.js, "dcerpc");
713  }
715  jb_append_string(ctx.js, "engine_event");
716  }
717  jb_close(ctx.js);
718 
719  jb_open_array(ctx.js, "flags");
720  if (s->flags & SIG_FLAG_SRC_ANY) {
721  jb_append_string(ctx.js, "src_any");
722  }
723  if (s->flags & SIG_FLAG_DST_ANY) {
724  jb_append_string(ctx.js, "dst_any");
725  }
726  if (s->flags & SIG_FLAG_SP_ANY) {
727  jb_append_string(ctx.js, "sp_any");
728  }
729  if (s->flags & SIG_FLAG_DP_ANY) {
730  jb_append_string(ctx.js, "dp_any");
731  }
732  if (s->flags & SIG_FLAG_NOALERT) {
733  jb_append_string(ctx.js, "noalert");
734  }
735  if (s->flags & SIG_FLAG_DSIZE) {
736  jb_append_string(ctx.js, "dsize");
737  }
738  if (s->flags & SIG_FLAG_APPLAYER) {
739  jb_append_string(ctx.js, "applayer");
740  }
741  if (s->flags & SIG_FLAG_IPONLY) {
742  jb_append_string(ctx.js, "ip_only");
743  }
744  if (s->flags & SIG_FLAG_REQUIRE_PACKET) {
745  jb_append_string(ctx.js, "need_packet");
746  }
747  if (s->flags & SIG_FLAG_REQUIRE_STREAM) {
748  jb_append_string(ctx.js, "need_stream");
749  }
750  if (s->flags & SIG_FLAG_MPM_NEG) {
751  jb_append_string(ctx.js, "negated_mpm");
752  }
753  if (s->flags & SIG_FLAG_FLUSH) {
754  jb_append_string(ctx.js, "flush");
755  }
756  if (s->flags & SIG_FLAG_REQUIRE_FLOWVAR) {
757  jb_append_string(ctx.js, "need_flowvar");
758  }
759  if (s->flags & SIG_FLAG_FILESTORE) {
760  jb_append_string(ctx.js, "filestore");
761  }
762  if (s->flags & SIG_FLAG_TOSERVER) {
763  jb_append_string(ctx.js, "toserver");
764  }
765  if (s->flags & SIG_FLAG_TOCLIENT) {
766  jb_append_string(ctx.js, "toclient");
767  }
768  if (s->flags & SIG_FLAG_TLSSTORE) {
769  jb_append_string(ctx.js, "tlsstore");
770  }
771  if (s->flags & SIG_FLAG_BYPASS) {
772  jb_append_string(ctx.js, "bypass");
773  }
774  if (s->flags & SIG_FLAG_PREFILTER) {
775  jb_append_string(ctx.js, "prefilter");
776  }
777  if (s->flags & SIG_FLAG_PDONLY) {
778  jb_append_string(ctx.js, "proto_detect_only");
779  }
780  if (s->flags & SIG_FLAG_SRC_IS_TARGET) {
781  jb_append_string(ctx.js, "src_is_target");
782  }
783  if (s->flags & SIG_FLAG_DEST_IS_TARGET) {
784  jb_append_string(ctx.js, "dst_is_target");
785  }
786  jb_close(ctx.js);
787 
788  jb_open_array(ctx.js, "pkt_engines");
790  for ( ; pkt != NULL; pkt = pkt->next) {
791  const char *name = DetectBufferTypeGetNameById(de_ctx, pkt->sm_list);
792  if (name == NULL) {
793  switch (pkt->sm_list) {
795  name = "payload";
796  break;
798  name = "packet";
799  break;
800  default:
801  name = "unknown";
802  break;
803  }
804  }
805  jb_start_object(ctx.js);
806  jb_set_string(ctx.js, "name", name);
807  jb_set_bool(ctx.js, "is_mpm", pkt->mpm);
808  DumpMatches(&ctx, ctx.js, pkt->smd);
809  jb_close(ctx.js);
810  }
811  jb_close(ctx.js);
812 
814  bool has_stream = false;
815  bool has_client_body_mpm = false;
816  bool has_file_data_mpm = false;
817 
818  jb_open_array(ctx.js, "engines");
820  for ( ; app != NULL; app = app->next) {
821  const char *name = DetectBufferTypeGetNameById(de_ctx, app->sm_list);
822  if (name == NULL) {
823  switch (app->sm_list) {
825  name = "stream";
826  break;
827  default:
828  name = "unknown";
829  break;
830  }
831  }
832 
833  if (app->sm_list == DETECT_SM_LIST_PMATCH && !app->mpm) {
834  has_stream = true;
835  } else if (app->mpm && strcmp(name, "http_client_body") == 0) {
836  has_client_body_mpm = true;
837  } else if (app->mpm && strcmp(name, "file_data") == 0) {
838  has_file_data_mpm = true;
839  }
840 
841  jb_start_object(ctx.js);
842  jb_set_string(ctx.js, "name", name);
843  const char *direction = app->dir == 0 ? "toserver" : "toclient";
844  jb_set_string(ctx.js, "direction", direction);
845  jb_set_bool(ctx.js, "is_mpm", app->mpm);
846  jb_set_string(ctx.js, "app_proto", AppProtoToString(app->alproto));
847  jb_set_uint(ctx.js, "progress", app->progress);
848  DumpMatches(&ctx, ctx.js, app->smd);
849  jb_close(ctx.js);
850  }
851  jb_close(ctx.js);
852 
853  if (has_stream && has_client_body_mpm)
854  AnalyzerNote(&ctx, (char *)"mpm in http_client_body combined with stream match leads to stream buffering");
855  if (has_stream && has_file_data_mpm)
856  AnalyzerNote(&ctx, (char *)"mpm in file_data combined with stream match leads to stream buffering");
857  }
858 
859  jb_open_object(ctx.js, "lists");
860  for (int i = 0; i < DETECT_SM_LIST_MAX; i++) {
861  if (s->sm_arrays[i] != NULL) {
862  jb_open_object(ctx.js, DetectSigmatchListEnumToString(i));
863  DumpMatches(&ctx, ctx.js, s->sm_arrays[i]);
864  jb_close(ctx.js);
865  }
866  }
867  jb_close(ctx.js);
868 
869  if (ctx.js_warnings) {
870  jb_set_object(ctx.js, "warnings", ctx.js_warnings);
871  jb_free(ctx.js_warnings);
872  ctx.js_warnings = NULL;
873  }
874  if (ctx.js_notes) {
875  jb_set_object(ctx.js, "notes", ctx.js_notes);
876  jb_free(ctx.js_notes);
877  ctx.js_notes = NULL;
878  }
879  jb_close(ctx.js);
880 
881  const char *filename = "rules.json";
882  const char *log_dir = ConfigGetLogDirectory();
883  char json_path[PATH_MAX] = "";
884  snprintf(json_path, sizeof(json_path), "%s/%s", log_dir, filename);
885 
887  FILE *fp = fopen(json_path, "a");
888  if (fp != NULL) {
889  fwrite(jb_ptr(ctx.js), jb_len(ctx.js), 1, fp);
890  fprintf(fp, "\n");
891  fclose(fp);
892  }
894  jb_free(ctx.js);
895  SCReturn;
896 }
897 
898 static void EngineAnalysisItemsReset(void)
899 {
900  for (size_t i = 0; i < ARRAY_SIZE(analyzer_items); i++) {
901  analyzer_items[i].item_seen = false;
902  }
903 }
904 
905 static void EngineAnalysisItemsInit(void)
906 {
907  static bool analyzer_init = false;
908 
909  if (analyzer_init) {
910  EngineAnalysisItemsReset();
911  return;
912  }
913 
914  memset(analyzer_item_map, -1, sizeof(analyzer_item_map));
915 
916  for (size_t i = 0; i < ARRAY_SIZE(analyzer_items); i++) {
917  DetectEngineAnalyzerItems *analyzer_item = &analyzer_items[i];
918 
919  analyzer_item->item_id = DetectBufferTypeGetByName(analyzer_item->item_name);
920  if (analyzer_item->item_id == -1) {
921  /* Mismatch between the analyzer_items array and what's supported */
923  "unable to initialize engine-analysis table: detect buffer \"%s\" not recognized.",
924  analyzer_item->item_name);
925  }
926  analyzer_item->item_seen = false;
927 
928  if (analyzer_item->export_item_seen) {
929  for (size_t k = 0; k < ARRAY_SIZE(exposed_item_seen_list); k++) {
930  if (0 == strcmp(exposed_item_seen_list[k].bufname, analyzer_item->item_name))
931  exposed_item_seen_list[k].item_seen_ptr = &analyzer_item->item_seen;
932  }
933 
934  }
935  analyzer_item_map[analyzer_item->item_id] = (int16_t) i;
936  }
937 
938  analyzer_init = true;
939 }
940 
941 /**
942  * \brief Prints analysis of loaded rules.
943  *
944  * Warns if potential rule issues are detected. For example,
945  * warns if a rule uses a construct that may perform poorly,
946  * e.g. pcre without content or with http_method content only;
947  * warns if a rule uses a construct that may not be consistent with intent,
948  * e.g. client side ports only, http and content without any http_* modifiers, etc.
949  *
950  * \param s Pointer to the signature.
951  */
953  const Signature *s, const char *line)
954 {
955  uint32_t rule_bidirectional = 0;
956  uint32_t rule_pcre = 0;
957  uint32_t rule_pcre_http = 0;
958  uint32_t rule_content = 0;
959  uint32_t rule_flow = 0;
960  uint32_t rule_flags = 0;
961  uint32_t rule_flow_toserver = 0;
962  uint32_t rule_flow_toclient = 0;
963  uint32_t rule_flow_nostream = 0;
964  uint32_t rule_ipv4_only = 0;
965  uint32_t rule_ipv6_only = 0;
966  uint32_t rule_flowbits = 0;
967  uint32_t rule_flowint = 0;
968  uint32_t rule_content_http = 0;
969  uint32_t rule_content_offset_depth = 0;
970  int32_t list_id = 0;
971  uint32_t rule_warning = 0;
972  uint32_t stream_buf = 0;
973  uint32_t packet_buf = 0;
974  uint32_t file_store = 0;
975  uint32_t warn_pcre_no_content = 0;
976  uint32_t warn_pcre_http_content = 0;
977  uint32_t warn_pcre_http = 0;
978  uint32_t warn_content_http_content = 0;
979  uint32_t warn_content_http = 0;
980  uint32_t warn_tcp_no_flow = 0;
981  uint32_t warn_client_ports = 0;
982  uint32_t warn_direction = 0;
983  uint32_t warn_method_toclient = 0;
984  uint32_t warn_method_serverbody = 0;
985  uint32_t warn_pcre_method = 0;
986  uint32_t warn_encoding_norm_http_buf = 0;
987  uint32_t warn_file_store_not_present = 0;
988  uint32_t warn_offset_depth_pkt_stream = 0;
989  uint32_t warn_offset_depth_alproto = 0;
990  uint32_t warn_non_alproto_fp_for_alproto_sig = 0;
991  uint32_t warn_no_direction = 0;
992  uint32_t warn_both_direction = 0;
993 
994  EngineAnalysisItemsInit();
995 
996  bool *http_method_item_seen_ptr = exposed_item_seen_list[0].item_seen_ptr;
997  bool *http_server_body_item_seen_ptr = exposed_item_seen_list[1].item_seen_ptr;
998 
1000  rule_bidirectional = 1;
1001  }
1002 
1003  if (s->flags & SIG_FLAG_REQUIRE_PACKET) {
1004  packet_buf += 1;
1005  }
1006  if (s->flags & SIG_FLAG_FILESTORE) {
1007  file_store += 1;
1008  }
1009  if (s->flags & SIG_FLAG_REQUIRE_STREAM) {
1010  stream_buf += 1;
1011  }
1012 
1013  if (s->proto.flags & DETECT_PROTO_IPV4) {
1014  rule_ipv4_only += 1;
1015  }
1016  if (s->proto.flags & DETECT_PROTO_IPV6) {
1017  rule_ipv6_only += 1;
1018  }
1019 
1020  for (list_id = 0; list_id < (int)s->init_data->smlists_array_size; list_id++) {
1021  SigMatch *sm = NULL;
1022  for (sm = s->init_data->smlists[list_id]; sm != NULL; sm = sm->next) {
1023  int16_t item_slot = analyzer_item_map[list_id];
1024  if (sm->type == DETECT_PCRE) {
1025  if (item_slot == -1) {
1026  rule_pcre++;
1027  continue;
1028  }
1029 
1030  rule_pcre_http++;
1031  analyzer_items[item_slot].item_seen = true;
1032  } else if (sm->type == DETECT_CONTENT) {
1033  if (item_slot == -1) {
1034  rule_content++;
1035  if (list_id == DETECT_SM_LIST_PMATCH) {
1038  rule_content_offset_depth++;
1039  }
1040  }
1041  continue;
1042  }
1043 
1044  rule_content_http++;
1045  analyzer_items[item_slot].item_seen = true;
1046 
1047  if (analyzer_items[item_slot].check_encoding_match) {
1049  if (cd != NULL && PerCentEncodingMatch(cd->content, cd->content_len) > 0) {
1050  warn_encoding_norm_http_buf += 1;
1051  }
1052  }
1053  }
1054  else if (sm->type == DETECT_FLOW) {
1055  rule_flow += 1;
1056  if ((s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_TOCLIENT)) {
1057  rule_flow_toserver = 1;
1058  }
1059  else if ((s->flags & SIG_FLAG_TOCLIENT) && !(s->flags & SIG_FLAG_TOSERVER)) {
1060  rule_flow_toclient = 1;
1061  }
1062  DetectFlowData *fd = (DetectFlowData *)sm->ctx;
1063  if (fd != NULL) {
1064  if (fd->flags & DETECT_FLOW_FLAG_NOSTREAM)
1065  rule_flow_nostream = 1;
1066  }
1067  }
1068  else if (sm->type == DETECT_FLOWBITS) {
1069  if (list_id == DETECT_SM_LIST_MATCH) {
1070  rule_flowbits += 1;
1071  }
1072  }
1073  else if (sm->type == DETECT_FLOWINT) {
1074  if (list_id == DETECT_SM_LIST_MATCH) {
1075  rule_flowint += 1;
1076  }
1077  }
1078  else if (sm->type == DETECT_FLAGS) {
1079  DetectFlagsData *fd = (DetectFlagsData *)sm->ctx;
1080  if (fd != NULL) {
1081  rule_flags = 1;
1082  }
1083  }
1084  } /* for (sm = s->sm_lists[list_id]; sm != NULL; sm = sm->next) */
1085 
1086  } /* for ( ; list_id < DETECT_SM_LIST_MAX; list_id++) */
1087 
1088 
1089  if (file_store && !RequiresFeature("output::file-store")) {
1090  rule_warning += 1;
1091  warn_file_store_not_present = 1;
1092  }
1093 
1094  if (rule_pcre > 0 && rule_content == 0 && rule_content_http == 0) {
1095  rule_warning += 1;
1096  warn_pcre_no_content = 1;
1097  }
1098 
1099  if (rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0) {
1100  rule_warning += 1;
1101  warn_pcre_http_content = 1;
1102  }
1103  else if (s->alproto == ALPROTO_HTTP && rule_pcre > 0 && rule_pcre_http == 0) {
1104  rule_warning += 1;
1105  warn_pcre_http = 1;
1106  }
1107 
1108  if (rule_content > 0 && rule_content_http > 0) {
1109  rule_warning += 1;
1110  warn_content_http_content = 1;
1111  }
1112  if (s->alproto == ALPROTO_HTTP && rule_content > 0 && rule_content_http == 0) {
1113  rule_warning += 1;
1114  warn_content_http = 1;
1115  }
1116  if (rule_content == 1) {
1117  //todo: warning if content is weak, separate warning for pcre + weak content
1118  }
1119  if (rule_flow == 0 && rule_flags == 0
1120  && !(s->proto.flags & DETECT_PROTO_ANY) && DetectProtoContainsProto(&s->proto, IPPROTO_TCP)
1121  && (rule_content || rule_content_http || rule_pcre || rule_pcre_http || rule_flowbits)) {
1122  rule_warning += 1;
1123  warn_tcp_no_flow = 1;
1124  }
1125  if (rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1126  && !((s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY))) {
1127  if (((s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY))
1128  || ((s->flags & SIG_FLAG_TOCLIENT) && !(s->flags & SIG_FLAG_DP_ANY) && (s->flags & SIG_FLAG_SP_ANY))) {
1129  rule_warning += 1;
1130  warn_client_ports = 1;
1131  }
1132  }
1133  if (rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)) {
1134  rule_warning += 1;
1135  warn_direction = 1;
1136  }
1137 
1138  if (*http_method_item_seen_ptr) {
1139  if (rule_flow && rule_flow_toclient) {
1140  rule_warning += 1;
1141  warn_method_toclient = 1;
1142  }
1143  if (*http_server_body_item_seen_ptr) {
1144  rule_warning += 1;
1145  warn_method_serverbody = 1;
1146  }
1147  if (rule_content == 0 && rule_content_http == 0 && (rule_pcre > 0 || rule_pcre_http > 0)) {
1148  rule_warning += 1;
1149  warn_pcre_method = 1;
1150  }
1151  }
1152  if (rule_content_offset_depth > 0 && stream_buf && packet_buf) {
1153  rule_warning += 1;
1154  warn_offset_depth_pkt_stream = 1;
1155  }
1156  if (rule_content_offset_depth > 0 && !stream_buf && packet_buf && s->alproto != ALPROTO_UNKNOWN) {
1157  rule_warning += 1;
1158  warn_offset_depth_alproto = 1;
1159  }
1160  if (s->init_data->mpm_sm != NULL && s->alproto == ALPROTO_HTTP &&
1162  rule_warning += 1;
1163  warn_non_alproto_fp_for_alproto_sig = 1;
1164  }
1165 
1166  if ((s->flags & (SIG_FLAG_TOSERVER|SIG_FLAG_TOCLIENT)) == 0) {
1167  warn_no_direction += 1;
1168  rule_warning += 1;
1169  }
1170 
1171  /* No warning about direction for ICMP protos */
1172  if (!(DetectProtoContainsProto(&s->proto, IPPROTO_ICMPV6) && DetectProtoContainsProto(&s->proto, IPPROTO_ICMP))) {
1174  warn_both_direction += 1;
1175  rule_warning += 1;
1176  }
1177  }
1178 
1179  if (!rule_warnings_only || (rule_warnings_only && rule_warning > 0)) {
1180  fprintf(rule_engine_analysis_FD, "== Sid: %u ==\n", s->id);
1181  fprintf(rule_engine_analysis_FD, "%s\n", line);
1182 
1183  if (s->flags & SIG_FLAG_IPONLY) fprintf(rule_engine_analysis_FD, " Rule is ip only.\n");
1184  if (s->flags & SIG_FLAG_PDONLY) fprintf(rule_engine_analysis_FD, " Rule is PD only.\n");
1185  if (rule_ipv6_only) fprintf(rule_engine_analysis_FD, " Rule is IPv6 only.\n");
1186  if (rule_ipv4_only) fprintf(rule_engine_analysis_FD, " Rule is IPv4 only.\n");
1187  if (packet_buf) fprintf(rule_engine_analysis_FD, " Rule matches on packets.\n");
1188  if (!rule_flow_nostream && stream_buf && (rule_flow || rule_flowbits || rule_content || rule_pcre)) {
1189  fprintf(rule_engine_analysis_FD, " Rule matches on reassembled stream.\n");
1190  }
1191  for(size_t i = 0; i < ARRAY_SIZE(analyzer_items); i++) {
1193  if (ai->item_seen) {
1194  fprintf(rule_engine_analysis_FD, " Rule matches on %s buffer.\n", ai->display_name);
1195  }
1196  }
1197  if (s->alproto != ALPROTO_UNKNOWN) {
1198  fprintf(rule_engine_analysis_FD, " App layer protocol is %s.\n", AppProtoToString(s->alproto));
1199  }
1200  if (rule_content || rule_content_http || rule_pcre || rule_pcre_http) {
1201  fprintf(rule_engine_analysis_FD, " Rule contains %d content options, %d http content options, %d pcre options, and %d pcre options with http modifiers.\n", rule_content, rule_content_http, rule_pcre, rule_pcre_http);
1202  }
1203 
1204  /* print fast pattern info */
1205  if (s->init_data->prefilter_sm) {
1206  fprintf(rule_engine_analysis_FD, " Prefilter on: %s.\n",
1208  } else {
1209  EngineAnalysisRulesPrintFP(de_ctx, s);
1210  }
1211 
1212  /* this is where the warnings start */
1213  if (warn_pcre_no_content /*rule_pcre > 0 && rule_content == 0 && rule_content_http == 0*/) {
1214  fprintf(rule_engine_analysis_FD, " Warning: Rule uses pcre without a content option present.\n"
1215  " -Consider adding a content to improve performance of this rule.\n");
1216  }
1217  if (warn_pcre_http_content /*rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0*/) {
1218  fprintf(rule_engine_analysis_FD, " Warning: Rule uses content options with http_* and pcre options without http modifiers.\n"
1219  " -Consider adding http pcre modifier.\n");
1220  }
1221  else if (warn_pcre_http /*s->alproto == ALPROTO_HTTP && rule_pcre > 0 && rule_pcre_http == 0*/) {
1222  fprintf(rule_engine_analysis_FD, " Warning: Rule app layer protocol is http, but pcre options do not have http modifiers.\n"
1223  " -Consider adding http pcre modifiers.\n");
1224  }
1225  if (warn_content_http_content /*rule_content > 0 && rule_content_http > 0*/) {
1226  fprintf(rule_engine_analysis_FD, " Warning: Rule contains content with http_* and content without http_*.\n"
1227  " -Consider adding http content modifiers.\n");
1228  }
1229  if (warn_content_http /*s->alproto == ALPROTO_HTTP && rule_content > 0 && rule_content_http == 0*/) {
1230  fprintf(rule_engine_analysis_FD, " Warning: Rule app layer protocol is http, but content options do not have http_* modifiers.\n"
1231  " -Consider adding http content modifiers.\n");
1232  }
1233  if (rule_content == 1) {
1234  //todo: warning if content is weak, separate warning for pcre + weak content
1235  }
1236  if (warn_encoding_norm_http_buf) {
1237  fprintf(rule_engine_analysis_FD, " Warning: Rule may contain percent encoded content for a normalized http buffer match.\n");
1238  }
1239  if (warn_tcp_no_flow /*rule_flow == 0 && rule_flags == 0
1240  && !(s->proto.flags & DETECT_PROTO_ANY) && DetectProtoContainsProto(&s->proto, IPPROTO_TCP)*/) {
1241  fprintf(rule_engine_analysis_FD, " Warning: TCP rule without a flow or flags option.\n"
1242  " -Consider adding flow or flags to improve performance of this rule.\n");
1243  }
1244  if (warn_client_ports /*rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1245  && !((s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY)))
1246  if (((s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY))
1247  || ((s->flags & SIG_FLAG_TOCLIENT) && !(s->flags & SIG_FLAG_DP_ANY) && (s->flags & SIG_FLAG_SP_ANY))*/) {
1248  fprintf(rule_engine_analysis_FD, " Warning: Rule contains ports or port variables only on the client side.\n"
1249  " -Flow direction possibly inconsistent with rule.\n");
1250  }
1251  if (warn_direction /*rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)*/) {
1252  fprintf(rule_engine_analysis_FD, " Warning: Rule is bidirectional and has a flow option with a specific direction.\n");
1253  }
1254  if (warn_method_toclient /*http_method_buf && rule_flow && rule_flow_toclient*/) {
1255  fprintf(rule_engine_analysis_FD, " Warning: Rule uses content or pcre for http_method with flow:to_client or from_server\n");
1256  }
1257  if (warn_method_serverbody /*http_method_buf && http_server_body_buf*/) {
1258  fprintf(rule_engine_analysis_FD, " Warning: Rule uses content or pcre for http_method with content or pcre for http_server_body.\n");
1259  }
1260  if (warn_pcre_method /*http_method_buf && rule_content == 0 && rule_content_http == 0
1261  && (rule_pcre > 0 || rule_pcre_http > 0)*/) {
1262  fprintf(rule_engine_analysis_FD, " Warning: Rule uses pcre with only a http_method content; possible performance issue.\n");
1263  }
1264  if (warn_offset_depth_pkt_stream) {
1265  fprintf(rule_engine_analysis_FD, " Warning: Rule has depth"
1266  "/offset with raw content keywords. Please note the "
1267  "offset/depth will be checked against both packet "
1268  "payloads and stream. If you meant to have the offset/"
1269  "depth checked against just the payload, you can update "
1270  "the signature as \"alert tcp-pkt...\"\n");
1271  }
1272  if (warn_offset_depth_alproto) {
1273  fprintf(rule_engine_analysis_FD, " Warning: Rule has "
1274  "offset/depth set along with a match on a specific "
1275  "app layer protocol - %d. This can lead to FNs if we "
1276  "have a offset/depth content match on a packet payload "
1277  "before we can detect the app layer protocol for the "
1278  "flow.\n", s->alproto);
1279  }
1280  if (warn_non_alproto_fp_for_alproto_sig) {
1281  fprintf(rule_engine_analysis_FD, " Warning: Rule app layer "
1282  "protocol is http, but the fast_pattern is set on the raw "
1283  "stream. Consider adding fast_pattern over a http "
1284  "buffer for increased performance.");
1285  }
1286  if (warn_no_direction) {
1287  fprintf(rule_engine_analysis_FD, " Warning: Rule has no direction indicator.\n");
1288  }
1289  if (warn_both_direction) {
1290  fprintf(rule_engine_analysis_FD, " Warning: Rule is inspecting both the request and the response.\n");
1291  }
1292  if (warn_file_store_not_present) {
1293  fprintf(rule_engine_analysis_FD, " Warning: Rule requires file-store but the output file-store is not enabled.\n");
1294  }
1295  if (rule_warning == 0) {
1296  fprintf(rule_engine_analysis_FD, " No warnings for this rule.\n");
1297  }
1298  fprintf(rule_engine_analysis_FD, "\n");
1299  }
1300  return;
1301 }
detect-tcp-flags.h
DETECT_CONTENT_NOCASE
#define DETECT_CONTENT_NOCASE
Definition: detect-content.h:29
SignatureHasPacketContent
int SignatureHasPacketContent(const Signature *s)
check if a signature has patterns that are to be inspected against a packets payload (as opposed to t...
Definition: detect-engine-mpm.c:545
RuleAnalyzer::js
JsonBuilder * js
Definition: detect-engine-analyzer.c:557
DetectContentData_::offset
uint16_t offset
Definition: detect-content.h:100
DetectEngineAppInspectionEngine_
Definition: detect.h:402
detect-content.h
len
uint8_t len
Definition: app-layer-dnp3.h:2
SC_ERR_PCRE_COMPILE
@ SC_ERR_PCRE_COMPILE
Definition: util-error.h:35
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:90
DETECT_CONTENT_FAST_PATTERN_CHOP
#define DETECT_CONTENT_FAST_PATTERN_CHOP
Definition: detect-content.h:36
DetectContentData_::fp_chop_len
uint16_t fp_chop_len
Definition: detect-content.h:91
Signature_::sig_str
char * sig_str
Definition: detect.h:595
DetectEnginePktInspectionEngine
Definition: detect.h:461
DetectEngineAppInspectionEngine_::next
struct DetectEngineAppInspectionEngine_ * next
Definition: detect.h:428
PerCentEncodingMatch
int PerCentEncodingMatch(uint8_t *content, uint8_t content_len)
Checks for % encoding in content.
Definition: detect-engine-analyzer.c:456
DETECT_PROTO_IPV6
#define DETECT_PROTO_IPV6
Definition: detect-engine-proto.h:34
SIG_FLAG_PDONLY
#define SIG_FLAG_PDONLY
Definition: detect.h:247
DetectFlowData_
Definition: detect-flow.h:37
DETECT_FLOW_FLAG_NOSTREAM
#define DETECT_FLOW_FLAG_NOSTREAM
Definition: detect-flow.h:33
SigTableElmt_::name
const char * name
Definition: detect.h:1211
ConfGetBool
int ConfGetBool(const char *name, int *val)
Retrieve a configuration value as an boolen.
Definition: conf.c:516
DetectEnginePktInspectionEngine::mpm
uint16_t mpm
Definition: detect.h:463
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectContentData_::within
int32_t within
Definition: detect-content.h:102
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:59
SignatureInitData_::prefilter_sm
SigMatch * prefilter_sm
Definition: detect.h:502
DETECT_FLOW
@ DETECT_FLOW
Definition: detect-engine-register.h:51
Signature_::alproto
AppProto alproto
Definition: detect.h:532
CleanupFPAnalyzer
void CleanupFPAnalyzer(void)
Definition: detect-engine-analyzer.c:389
RuleAnalyzer::js_warnings
JsonBuilder * js_warnings
Definition: detect-engine-analyzer.c:559
g_rules_analyzer_write_m
SCMutex g_rules_analyzer_write_m
Definition: detect-engine-analyzer.c:675
DetectEngineAnalyzerItems::display_name
const char * display_name
Definition: detect-engine-analyzer.c:63
SIG_FLAG_DEST_IS_TARGET
#define SIG_FLAG_DEST_IS_TARGET
Definition: detect.h:251
SigMatchData_::ctx
SigMatchCtx * ctx
Definition: detect.h:332
ConfGetNode
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Definition: conf.c:175
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
Definition: app-layer-protos.c:30
DetectFlowData_::flags
uint16_t flags
Definition: detect-flow.h:38
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:767
DETECT_PROTO_ANY
#define DETECT_PROTO_ANY
Definition: detect-engine-proto.h:27
DetectEnginePktInspectionEngine::smd
SigMatchData * smd
Definition: detect.h:462
SIG_FLAG_DST_ANY
#define SIG_FLAG_DST_ANY
Definition: detect.h:212
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
SIG_FLAG_REQUIRE_STREAM
#define SIG_FLAG_REQUIRE_STREAM
Definition: detect.h:224
rust.h
DetectEngineAnalyzerItems
Definition: detect-engine-analyzer.c:57
SCMUTEX_INITIALIZER
#define SCMUTEX_INITIALIZER
Definition: threads-debug.h:121
Signature_::sm_arrays
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
Definition: detect.h:581
FpPatternStats_::max
uint16_t max
Definition: detect-engine-analyzer.c:51
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:493
DetectContentData_
Definition: detect-content.h:86
DetectContentData_::fp_chop_offset
uint16_t fp_chop_offset
Definition: detect-content.h:93
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:237
SIG_FLAG_SRC_ANY
#define SIG_FLAG_SRC_ANY
Definition: detect.h:211
SigMatchData_
Data needed for Match()
Definition: detect.h:329
CleanupRuleAnalyzer
void CleanupRuleAnalyzer(void)
Definition: detect-engine-analyzer.c:413
ConfValIsTrue
int ConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:565
DETECT_PERCENT_ENCODING_REGEX
#define DETECT_PERCENT_ENCODING_REGEX
SIG_FLAG_APPLAYER
#define SIG_FLAG_APPLAYER
Definition: detect.h:218
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:880
analyzer_item_map
int16_t analyzer_item_map[256]
Definition: detect-engine-analyzer.c:119
Signature_::gid
uint32_t gid
Definition: detect.h:562
__attribute__
enum @31 __attribute__
DNP3 application header.
Definition: detect-engine-analyzer.c:579
DetectEngineAppInspectionEngine_::sm_list
uint16_t sm_list
Definition: detect.h:408
DetectEngineAnalyzerItems::export_item_seen
bool export_item_seen
Definition: detect-engine-analyzer.c:60
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:236
RequiresFeature
bool RequiresFeature(const char *feature_name)
Definition: feature.c:124
feature.h
SC_ERR_PCRE_MATCH
@ SC_ERR_PCRE_MATCH
Definition: util-error.h:32
DETECT_CONTENT_ENDS_WITH
#define DETECT_CONTENT_ENDS_WITH
Definition: detect-content.h:42
DETECT_CONTENT_DISTANCE
#define DETECT_CONTENT_DISTANCE
Definition: detect-content.h:30
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEnginePktInspectionEngine::sm_list
uint16_t sm_list
Definition: detect.h:464
SIG_FLAG_INIT_BIDIREC
#define SIG_FLAG_INIT_BIDIREC
Definition: detect.h:259
DETECT_FLOWINT
@ DETECT_FLOWINT
Definition: detect-engine-register.h:84
SIG_MASK_REQUIRE_ENGINE_EVENT
#define SIG_MASK_REQUIRE_ENGINE_EVENT
Definition: detect.h:277
SignatureInitData_::mpm_sm
SigMatch * mpm_sm
Definition: detect.h:500
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:119
SIG_FLAG_FLUSH
#define SIG_FLAG_FLUSH
Definition: detect.h:228
SIG_MASK_REQUIRE_FLOW
#define SIG_MASK_REQUIRE_FLOW
Definition: detect.h:271
SIG_FLAG_BYPASS
#define SIG_FLAG_BYPASS
Definition: detect.h:241
DETECT_CONTENT_DEPTH
#define DETECT_CONTENT_DEPTH
Definition: detect-content.h:33
RuleAnalyzer
Definition: detect-engine-analyzer.c:556
Signature_::pkt_inspect
DetectEnginePktInspectionEngine * pkt_inspect
Definition: detect.h:577
DetectEngineAnalyzerItems
struct DetectEngineAnalyzerItems DetectEngineAnalyzerItems
util-print.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
detect-engine-mpm.h
detect.h
SIG_MASK_REQUIRE_FLAGS_INITDEINIT
#define SIG_MASK_REQUIRE_FLAGS_INITDEINIT
Definition: detect.h:272
DetectEngineAppInspectionEngine_::mpm
uint16_t mpm
Definition: detect.h:406
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:324
SigMatchData_::type
uint8_t type
Definition: detect.h:330
DetectEngineAnalyzerItems::item_seen
bool item_seen
Definition: detect-engine-analyzer.c:59
DETECT_CONTENT_NEGATED
#define DETECT_CONTENT_NEGATED
Definition: detect-content.h:40
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:89
EngineAnalysisRules
void EngineAnalysisRules(const DetectEngineCtx *de_ctx, const Signature *s, const char *line)
Prints analysis of loaded rules.
Definition: detect-engine-analyzer.c:952
Signature_::app_inspect
DetectEngineAppInspectionEngine * app_inspect
Definition: detect.h:576
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:323
SIG_FLAG_REQUIRE_FLOWVAR
#define SIG_FLAG_REQUIRE_FLOWVAR
Definition: detect.h:232
FpPatternStats_::cnt
uint32_t cnt
Definition: detect-engine-analyzer.c:52
SCReturn
#define SCReturn
Definition: util-debug.h:302
Signature_::flags
uint32_t flags
Definition: detect.h:529
DetectContentData_::depth
uint16_t depth
Definition: detect-content.h:99
SC_ERR_FOPEN
@ SC_ERR_FOPEN
Definition: util-error.h:74
SIG_FLAG_IPONLY
#define SIG_FLAG_IPONLY
Definition: detect.h:219
SCLocalTime
struct tm * SCLocalTime(time_t timep, struct tm *result)
Definition: util-time.c:270
PerCentEncodingSetup
int PerCentEncodingSetup()
Compiles regex for rule analysis.
Definition: detect-engine-analyzer.c:427
conf.h
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:97
CHECK
#define CHECK(pat)
Definition: detect-engine-analyzer.c:595
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:597
SIG_FLAG_SRC_IS_TARGET
#define SIG_FLAG_SRC_IS_TARGET
Definition: detect.h:249
SignatureInitData_::smlists
struct SigMatch_ ** smlists
Definition: detect.h:522
SC_ERR_PCRE_STUDY
@ SC_ERR_PCRE_STUDY
Definition: util-error.h:36
SIG_MASK_REQUIRE_PAYLOAD
#define SIG_MASK_REQUIRE_PAYLOAD
Definition: detect.h:270
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:217
DETECT_PCRE
@ DETECT_PCRE
Definition: detect-engine-register.h:61
ExposedItemSeen::bufname
const char * bufname
Definition: detect-engine-analyzer.c:68
DetectSigmatchListEnumToString
const char * DetectSigmatchListEnumToString(enum DetectSigmatchListEnum type)
Definition: detect-engine.c:4237
SigMatch_::type
uint8_t type
Definition: detect.h:321
DetectEngineAppInspectionEngine_::alproto
AppProto alproto
Definition: detect.h:403
SIG_FLAG_MPM_NEG
#define SIG_FLAG_MPM_NEG
Definition: detect.h:226
detect-engine-analyzer.h
SIG_FLAG_INIT_STATE_MATCH
#define SIG_FLAG_INIT_STATE_MATCH
Definition: detect.h:262
DetectEngineAnalyzerItems::item_id
int16_t item_id
Definition: detect-engine-analyzer.c:58
MAX_ENCODED_CHARS
#define MAX_ENCODED_CHARS
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:426
EngineAnalysisRules2
void EngineAnalysisRules2(const DetectEngineCtx *de_ctx, const Signature *s)
Definition: detect-engine-analyzer.c:676
ARRAY_SIZE
#define ARRAY_SIZE(arr)
Definition: suricata-common.h:544
DETECT_CONTENT_STARTS_WITH
#define DETECT_CONTENT_STARTS_WITH
Definition: detect-content.h:59
DetectProto_::flags
uint8_t flags
Definition: detect-engine-proto.h:38
DETECT_PROTO_IPV4
#define DETECT_PROTO_IPV4
Definition: detect-engine-proto.h:33
SignatureHasStreamContent
int SignatureHasStreamContent(const Signature *s)
check if a signature has patterns that are to be inspected against the stream payload (as opposed to ...
Definition: detect-engine-mpm.c:581
RuleAnalyzer::js_notes
JsonBuilder * js_notes
Definition: detect-engine-analyzer.c:560
EngineAnalysisFP
void EngineAnalysisFP(const DetectEngineCtx *de_ctx, const Signature *s, char *line)
Definition: detect-engine-analyzer.c:151
FpPatternStats_::min
uint16_t min
Definition: detect-engine-analyzer.c:50
Signature_::proto
DetectProto proto
Definition: detect.h:545
SigMatchData_::is_last
uint8_t is_last
Definition: detect.h:331
suricata-common.h
SIG_MASK_REQUIRE_NO_PAYLOAD
#define SIG_MASK_REQUIRE_NO_PAYLOAD
Definition: detect.h:274
SIG_FLAG_SP_ANY
#define SIG_FLAG_SP_ANY
Definition: detect.h:213
ExposedItemSeen
Definition: detect-engine-analyzer.c:67
DetectEngineAnalyzerItems::check_encoding_match
bool check_encoding_match
Definition: detect-engine-analyzer.c:61
DetectContentData_::distance
int32_t distance
Definition: detect-content.h:101
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
DetectEnginePktInspectionEngine::next
struct DetectEnginePktInspectionEngine * next
Definition: detect.h:471
DetectContentData_::content
uint8_t * content
Definition: detect-content.h:87
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
Signature_::rev
uint32_t rev
Definition: detect.h:563
SetupFPAnalyzer
int SetupFPAnalyzer(void)
Sets up the fast pattern analyzer according to the config.
Definition: detect-engine-analyzer.c:283
DetectEngineCtx_::buffer_type_map
DetectBufferType ** buffer_type_map
Definition: detect.h:924
FatalError
#define FatalError(x,...)
Definition: util-debug.h:532
SIG_FLAG_NOALERT
#define SIG_FLAG_NOALERT
Definition: detect.h:216
SIG_MASK_REQUIRE_FLAGS_UNUSUAL
#define SIG_MASK_REQUIRE_FLAGS_UNUSUAL
Definition: detect.h:273
EngineAnalysisRulesFailure
void EngineAnalysisRulesFailure(char *line, char *file, int lineno)
Definition: detect-engine-analyzer.c:546
DETECT_FLOWBITS
@ DETECT_FLOWBITS
Definition: detect-engine-register.h:87
DetectEngineAppInspectionEngine_::progress
int16_t progress
Definition: detect.h:409
detect-flow.h
PrintRawUriFp
void PrintRawUriFp(FILE *fp, uint8_t *buf, uint32_t buflen)
Definition: util-print.c:93
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
FpPatternStats
struct FpPatternStats_ FpPatternStats
str
#define str(s)
Definition: suricata-common.h:273
ConfigGetLogDirectory
const char * ConfigGetLogDirectory()
Definition: util-conf.c:35
SigMatchListSMBelongsTo
int SigMatchListSMBelongsTo(const Signature *s, const SigMatch *key_sm)
Definition: detect-parse.c:625
SCFree
#define SCFree(p)
Definition: util-mem.h:61
ConfNode_
Definition: conf.h:32
SC_ERR_FATAL
@ SC_ERR_FATAL
Definition: util-error.h:203
Signature_::id
uint32_t id
Definition: detect.h:561
DETECT_CONTENT_OFFSET
#define DETECT_CONTENT_OFFSET
Definition: detect-content.h:32
DETECT_CONTENT_FAST_PATTERN_ONLY
#define DETECT_CONTENT_FAST_PATTERN_ONLY
Definition: detect-content.h:35
DETECT_CONTENT_MPM
#define DETECT_CONTENT_MPM
Definition: detect-content.h:61
DetectBufferType_::transforms
DetectEngineTransforms transforms
Definition: detect.h:441
detect-parse.h
Signature_
Signature container.
Definition: detect.h:528
SigMatch_
a single match condition for a signature
Definition: detect.h:320
DETECT_SM_LIST_MAX
@ DETECT_SM_LIST_MAX
Definition: detect.h:106
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition: app-layer-protos.h:30
FpPatternStats_::tot
uint64_t tot
Definition: detect-engine-analyzer.c:53
DetectFlagsData_
Definition: detect-tcp-flags.h:41
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
exposed_item_seen_list
struct ExposedItemSeen exposed_item_seen_list[]
Definition: detect-engine-analyzer.c:125
DetectEngineTransforms::cnt
int cnt
Definition: detect.h:378
suricata.h
SetupRuleAnalyzer
int SetupRuleAnalyzer(void)
Sets up the rule analyzer according to the config.
Definition: detect-engine-analyzer.c:333
DetectBufferTypeGetDescriptionById
const char * DetectBufferTypeGetDescriptionById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:917
DetectEngineAppInspectionEngine_::dir
uint8_t dir
Definition: detect.h:404
DetectEngineAnalyzerItems::item_name
const char * item_name
Definition: detect-engine-analyzer.c:62
DetectContentData_::content_len
uint16_t content_len
Definition: detect-content.h:88
ExposedItemSeen::item_seen_ptr
bool * item_seen_ptr
Definition: detect-engine-analyzer.c:69
DetectBufferTypeGetNameById
const char * DetectBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:889
SC_ERR_INITIALIZATION
@ SC_ERR_INITIALIZATION
Definition: util-error.h:75
RuleAnalyzer
struct RuleAnalyzer RuleAnalyzer
SIG_FLAG_TLSSTORE
#define SIG_FLAG_TLSSTORE
Definition: detect.h:239
Signature_::msg
char * msg
Definition: detect.h:586
DETECT_CONTENT_FAST_PATTERN
#define DETECT_CONTENT_FAST_PATTERN
Definition: detect-content.h:34
DETECT_FLAGS
@ DETECT_FLAGS
Definition: detect-engine-register.h:40
FpPatternStats_
Definition: detect-engine-analyzer.c:49
analyzer_items
DetectEngineAnalyzerItems analyzer_items[]
Definition: detect-engine-analyzer.c:72
SCMutex
#define SCMutex
Definition: threads-debug.h:114
SIG_FLAG_PREFILTER
#define SIG_FLAG_PREFILTER
Definition: detect.h:243
SIG_MASK_REQUIRE_DCERPC
#define SIG_MASK_REQUIRE_DCERPC
Definition: detect.h:275
SIG_FLAG_FILESTORE
#define SIG_FLAG_FILESTORE
Definition: detect.h:234
DETECT_CONTENT_WITHIN
#define DETECT_CONTENT_WITHIN
Definition: detect-content.h:31
SIG_FLAG_DP_ANY
#define SIG_FLAG_DP_ANY
Definition: detect.h:214
SIG_FLAG_DSIZE
#define SIG_FLAG_DSIZE
Definition: detect.h:217
Signature_::mask
SignatureMask mask
Definition: detect.h:537
SignatureInitData_::smlists_array_size
uint32_t smlists_array_size
Definition: detect.h:520
DetectProtoContainsProto
int DetectProtoContainsProto(const DetectProto *dp, int proto)
see if a DetectProto contains a certain proto
Definition: detect-engine-proto.c:135
SIG_FLAG_REQUIRE_PACKET
#define SIG_FLAG_REQUIRE_PACKET
Definition: detect.h:223
ConfNodeLookupChildValue
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition: conf.c:842