suricata
detect-engine-analyzer.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2023 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 "action-globals.h"
31 #include "detect.h"
32 #include "detect-parse.h"
33 #include "detect-engine.h"
34 #include "detect-engine-analyzer.h"
35 #include "detect-engine-mpm.h"
36 #include "detect-engine-uint.h"
37 #include "conf.h"
38 #include "detect-content.h"
39 #include "detect-pcre.h"
40 #include "detect-bytejump.h"
41 #include "detect-bytetest.h"
42 #include "detect-flow.h"
43 #include "detect-tcp-flags.h"
44 #include "detect-tcp-ack.h"
45 #include "detect-ipopts.h"
46 #include "detect-tcp-seq.h"
47 #include "feature.h"
48 #include "util-print.h"
49 #include "util-time.h"
50 #include "util-validate.h"
51 #include "util-conf.h"
52 #include "detect-flowbits.h"
53 #include "util-var-name.h"
54 #include "detect-icmp-id.h"
55 
56 static int rule_warnings_only = 0;
57 
58 /* Details for each buffer being tracked */
59 typedef struct DetectEngineAnalyzerItems {
60  int16_t item_id;
61  bool item_seen;
64  const char *item_name;
65  const char *display_name;
67 
68 typedef struct FpPatternStats_ {
69  uint16_t min;
70  uint16_t max;
71  uint32_t cnt;
72  uint64_t tot;
74 
75 /* Track which items require the item_seen value to be exposed */
77  const char *bufname;
79 };
80 
81 typedef struct EngineAnalysisCtx_ {
82 
85 
87  char *file_prefix;
88  pcre2_code *percent_re;
89 
90  /*
91  * This array contains the map between the `analyzer_items` array listed above and
92  * the item ids returned by DetectBufferTypeGetByName. Iterating signature's sigmatch
93  * array provides list_ids. The map converts those ids into elements of the
94  * analyzer items array.
95  *
96  * Ultimately, the g_buffer_type_hash is searched for each buffer name. The size of that
97  * hashlist is 256, so that's the value we use here.
98  */
99  int16_t analyzer_item_map[256];
101  /*
102  * Certain values must be directly accessible. This array contains items that are directly
103  * accessed when checking if they've been seen or not.
104  */
106 
109 
111  /* request keywords */
112  { 0, false, false, true, "http_uri", "http uri" },
113  { 0, false, false, false, "http_raw_uri", "http raw uri" },
114  { 0, false, true, false, "http_method", "http method" },
115  { 0, false, false, false, "http_request_line", "http request line" },
116  { 0, false, false, false, "http_client_body", "http client body" },
117  { 0, false, false, true, "http_header", "http header" },
118  { 0, false, false, false, "http_raw_header", "http raw header" },
119  { 0, false, false, true, "http_cookie", "http cookie" },
120  { 0, false, false, false, "http_user_agent", "http user agent" },
121  { 0, false, false, false, "http_host", "http host" },
122  { 0, false, false, false, "http_raw_host", "http raw host" },
123  { 0, false, false, false, "http_accept_enc", "http accept enc" },
124  { 0, false, false, false, "http_referer", "http referer" },
125  { 0, false, false, false, "http_content_type", "http content type" },
126  { 0, false, false, false, "http_header_names", "http header names" },
127 
128  /* response keywords not listed above */
129  { 0, false, false, false, "http_stat_msg", "http stat msg" },
130  { 0, false, false, false, "http_stat_code", "http stat code" },
131  { 0, false, true, false, "file_data", "http server body" },
132 
133  /* missing request keywords */
134  { 0, false, false, false, "http_request_line", "http request line" },
135  { 0, false, false, false, "http_accept", "http accept" },
136  { 0, false, false, false, "http_accept_lang", "http accept lang" },
137  { 0, false, false, false, "http_connection", "http connection" },
138  { 0, false, false, false, "http_content_len", "http content len" },
139  { 0, false, false, false, "http_protocol", "http protocol" },
140  { 0, false, false, false, "http_start", "http start" },
141 
142  /* missing response keywords; some of the missing are listed above*/
143  { 0, false, false, false, "http_response_line", "http response line" },
144  { 0, false, false, false, "http.server", "http server" },
145  { 0, false, false, false, "http.location", "http location" },
146 };
147 
148 static void FpPatternStatsAdd(FpPatternStats *fp, int list, uint16_t patlen)
149 {
150  if (list < 0 || list >= DETECT_SM_LIST_MAX)
151  return;
152 
153  FpPatternStats *f = &fp[list];
154 
155  if (f->min == 0)
156  f->min = patlen;
157  else if (patlen < f->min)
158  f->min = patlen;
159 
160  if (patlen > f->max)
161  f->max = patlen;
162 
163  f->cnt++;
164  f->tot += patlen;
165 }
166 
167 void EngineAnalysisFP(const DetectEngineCtx *de_ctx, const Signature *s, char *line)
168 {
169  int fast_pattern_set = 0;
170  int fast_pattern_only_set = 0;
171  int fast_pattern_chop_set = 0;
172  const DetectContentData *fp_cd = NULL;
173  const SigMatch *mpm_sm = s->init_data->mpm_sm;
174  const int mpm_sm_list = s->init_data->mpm_sm_list;
175 
176  if (mpm_sm != NULL) {
177  fp_cd = (DetectContentData *)mpm_sm->ctx;
178  if (fp_cd->flags & DETECT_CONTENT_FAST_PATTERN) {
179  fast_pattern_set = 1;
181  fast_pattern_only_set = 1;
182  } else if (fp_cd->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) {
183  fast_pattern_chop_set = 1;
184  }
185  }
186  }
187 
188  FILE *fp = de_ctx->ea->rule_engine_analysis_fp;
189  fprintf(fp, "== Sid: %u ==\n", s->id);
190  fprintf(fp, "%s\n", line);
191 
192  fprintf(fp, " Fast Pattern analysis:\n");
193  if (s->init_data->prefilter_sm != NULL) {
194  fprintf(fp, " Prefilter on: %s\n",
196  fprintf(fp, "\n");
197  return;
198  }
199 
200  if (fp_cd == NULL) {
201  fprintf(fp, " No content present\n");
202  fprintf(fp, "\n");
203  return;
204  }
205 
206  fprintf(fp, " Fast pattern matcher: ");
207  int list_type = mpm_sm_list;
208  if (list_type == DETECT_SM_LIST_PMATCH)
209  fprintf(fp, "content\n");
210  else {
211  const char *desc = DetectEngineBufferTypeGetDescriptionById(de_ctx, list_type);
212  const char *name = DetectEngineBufferTypeGetNameById(de_ctx, list_type);
213  if (desc && name) {
214  fprintf(fp, "%s (%s)\n", desc, name);
215  }
216  }
217 
218  int flags_set = 0;
219  fprintf(fp, " Flags:");
220  if (fp_cd->flags & DETECT_CONTENT_OFFSET) {
221  fprintf(fp, " Offset");
222  flags_set = 1;
223  } if (fp_cd->flags & DETECT_CONTENT_DEPTH) {
224  fprintf(fp, " Depth");
225  flags_set = 1;
226  }
227  if (fp_cd->flags & DETECT_CONTENT_WITHIN) {
228  fprintf(fp, " Within");
229  flags_set = 1;
230  }
231  if (fp_cd->flags & DETECT_CONTENT_DISTANCE) {
232  fprintf(fp, " Distance");
233  flags_set = 1;
234  }
235  if (fp_cd->flags & DETECT_CONTENT_NOCASE) {
236  fprintf(fp, " Nocase");
237  flags_set = 1;
238  }
239  if (fp_cd->flags & DETECT_CONTENT_NEGATED) {
240  fprintf(fp, " Negated");
241  flags_set = 1;
242  }
243  if (flags_set == 0)
244  fprintf(fp, " None");
245  fprintf(fp, "\n");
246 
247  fprintf(fp, " Fast pattern set: %s\n", fast_pattern_set ? "yes" : "no");
248  fprintf(fp, " Fast pattern only set: %s\n", fast_pattern_only_set ? "yes" : "no");
249  fprintf(fp, " Fast pattern chop set: %s\n", fast_pattern_chop_set ? "yes" : "no");
250  if (fast_pattern_chop_set) {
251  fprintf(fp, " Fast pattern offset, length: %u, %u\n", fp_cd->fp_chop_offset,
252  fp_cd->fp_chop_len);
253  }
254 
255  uint16_t patlen = fp_cd->content_len;
256  uint8_t *pat = SCMalloc(fp_cd->content_len + 1);
257  if (unlikely(pat == NULL)) {
258  FatalError("Error allocating memory");
259  }
260  memcpy(pat, fp_cd->content, fp_cd->content_len);
261  pat[fp_cd->content_len] = '\0';
262  fprintf(fp, " Original content: ");
263  PrintRawUriFp(fp, pat, patlen);
264  fprintf(fp, "\n");
265 
266  if (fast_pattern_chop_set) {
267  SCFree(pat);
268  patlen = fp_cd->fp_chop_len;
269  pat = SCMalloc(fp_cd->fp_chop_len + 1);
270  if (unlikely(pat == NULL)) {
271  exit(EXIT_FAILURE);
272  }
273  memcpy(pat, fp_cd->content + fp_cd->fp_chop_offset, fp_cd->fp_chop_len);
274  pat[fp_cd->fp_chop_len] = '\0';
275  fprintf(fp, " Final content: ");
276  PrintRawUriFp(fp, pat, patlen);
277  fprintf(fp, "\n");
278 
279  FpPatternStatsAdd(&de_ctx->ea->fp_pattern_stats[0], list_type, patlen);
280  } else {
281  fprintf(fp, " Final content: ");
282  PrintRawUriFp(fp, pat, patlen);
283  fprintf(fp, "\n");
284 
285  FpPatternStatsAdd(&de_ctx->ea->fp_pattern_stats[0], list_type, patlen);
286  }
287  SCFree(pat);
288 
289  fprintf(fp, "\n");
290 }
291 
292 /**
293  * \brief Sets up the fast pattern analyzer according to the config.
294  *
295  * \retval 1 If rule analyzer successfully enabled.
296  * \retval 0 If not enabled.
297  */
298 static int SetupFPAnalyzer(DetectEngineCtx *de_ctx)
299 {
300  int fp_engine_analysis_set = 0;
301 
302  if ((ConfGetBool("engine-analysis.rules-fast-pattern",
303  &fp_engine_analysis_set)) == 0) {
304  return false;
305  }
306 
307  if (fp_engine_analysis_set == 0)
308  return false;
309 
310  const char *log_dir = ConfigGetLogDirectory();
311  char *log_path = SCMalloc(PATH_MAX);
312  if (log_path == NULL) {
313  FatalError("Unable to allocate scratch memory for rule filename");
314  }
315  snprintf(log_path, PATH_MAX, "%s/%s%s", log_dir,
316  de_ctx->ea->file_prefix ? de_ctx->ea->file_prefix : "", "rules_fast_pattern.txt");
317 
318  FILE *fp = fopen(log_path, "w");
319  if (fp == NULL) {
320  SCLogError("failed to open %s: %s", log_path, strerror(errno));
321  SCFree(log_path);
322  return false;
323  }
324 
326 
327  SCLogInfo("Engine-Analysis for fast_pattern printed to file - %s",
328  log_path);
329  SCFree(log_path);
330 
331  struct timeval tval;
332  gettimeofday(&tval, NULL);
333  struct tm local_tm;
334  struct tm *tms = SCLocalTime(tval.tv_sec, &local_tm);
335  fprintf(fp, "----------------------------------------------"
336  "---------------------\n");
337  fprintf(fp,
338  "Date: %" PRId32 "/%" PRId32 "/%04d -- "
339  "%02d:%02d:%02d\n",
340  tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min,
341  tms->tm_sec);
342  fprintf(fp, "----------------------------------------------"
343  "---------------------\n");
344 
345  memset(&de_ctx->ea->fp_pattern_stats[0], 0, sizeof(de_ctx->ea->fp_pattern_stats));
346  return true;
347 }
348 
349 /**
350  * \brief Compiles regex for rule analysis
351  * \retval 1 if successful
352  * \retval 0 if on error
353  */
354 static bool PerCentEncodingSetup(EngineAnalysisCtx *ea_ctx)
355 {
356 #define DETECT_PERCENT_ENCODING_REGEX "%[0-9|a-f|A-F]{2}"
357  int en;
358  PCRE2_SIZE eo = 0;
359  int opts = 0; // PCRE2_NEWLINE_ANY??
360 
361  ea_ctx->percent_re = pcre2_compile((PCRE2_SPTR8)DETECT_PERCENT_ENCODING_REGEX,
362  PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
363  if (ea_ctx->percent_re == NULL) {
364  PCRE2_UCHAR errbuffer[256];
365  pcre2_get_error_message(en, errbuffer, sizeof(errbuffer));
366  SCLogError("Compile of \"%s\" failed at offset %d: %s", DETECT_PERCENT_ENCODING_REGEX,
367  (int)eo, errbuffer);
368  return false;
369  }
370 
371  return true;
372 }
373 /**
374  * \brief Sets up the rule analyzer according to the config
375  * \retval 1 if rule analyzer successfully enabled
376  * \retval 0 if not enabled
377  */
378 static int SetupRuleAnalyzer(DetectEngineCtx *de_ctx)
379 {
380  ConfNode *conf = ConfGetNode("engine-analysis");
381  int enabled = 0;
382  if (conf != NULL) {
383  const char *value = ConfNodeLookupChildValue(conf, "rules");
384  if (value && ConfValIsTrue(value)) {
385  enabled = 1;
386  } else if (value && strcasecmp(value, "warnings-only") == 0) {
387  enabled = 1;
388  rule_warnings_only = 1;
389  }
390  if (enabled) {
391  const char *log_dir;
392  log_dir = ConfigGetLogDirectory();
393  char log_path[PATH_MAX];
394  snprintf(log_path, sizeof(log_path), "%s/%s%s", log_dir,
395  de_ctx->ea->file_prefix ? de_ctx->ea->file_prefix : "", "rules_analysis.txt");
396  de_ctx->ea->rule_engine_analysis_fp = fopen(log_path, "w");
397  if (de_ctx->ea->rule_engine_analysis_fp == NULL) {
398  SCLogError("failed to open %s: %s", log_path, strerror(errno));
399  return 0;
400  }
401 
402  SCLogInfo("Engine-Analysis for rules printed to file - %s",
403  log_path);
404 
405  struct timeval tval;
406  gettimeofday(&tval, NULL);
407  struct tm local_tm;
408  struct tm *tms = SCLocalTime(tval.tv_sec, &local_tm);
410  "----------------------------------------------"
411  "---------------------\n");
413  "Date: %" PRId32 "/%" PRId32 "/%04d -- "
414  "%02d:%02d:%02d\n",
415  tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min,
416  tms->tm_sec);
418  "----------------------------------------------"
419  "---------------------\n");
420 
421  /*compile regex's for rule analysis*/
422  if (!PerCentEncodingSetup(de_ctx->ea)) {
424  "Error compiling regex; can't check for percent encoding in normalized "
425  "http content.\n");
426  }
427  }
428  }
429  else {
430  SCLogInfo("Conf parameter \"engine-analysis.rules\" not found. "
431  "Defaulting to not printing the rules analysis report.");
432  }
433  if (!enabled) {
434  SCLogInfo("Engine-Analysis for rules disabled in conf file.");
435  return 0;
436  }
437  return 1;
438 }
439 
440 static void CleanupFPAnalyzer(DetectEngineCtx *de_ctx)
441 {
442  FILE *fp = de_ctx->ea->rule_engine_analysis_fp;
443  fprintf(fp, "============\n"
444  "Summary:\n============\n");
445 
446  for (int i = 0; i < DETECT_SM_LIST_MAX; i++) {
448  if (f->cnt == 0)
449  continue;
450 
451  fprintf(fp,
452  "%s, smallest pattern %u byte(s), longest pattern %u byte(s), number of patterns "
453  "%u, avg pattern len %.2f byte(s)\n",
454  DetectSigmatchListEnumToString(i), f->min, f->max, f->cnt,
455  (float)((double)f->tot / (float)f->cnt));
456  }
457 
460 }
461 
462 static void CleanupRuleAnalyzer(DetectEngineCtx *de_ctx)
463 {
464  if (de_ctx->ea->fp_engine_analysis_fp != NULL) {
465  fclose(de_ctx->ea->fp_engine_analysis_fp);
467  }
468  if (de_ctx->ea->percent_re != NULL) {
469  pcre2_code_free(de_ctx->ea->percent_re);
470  }
471 }
472 
473 void SetupEngineAnalysis(DetectEngineCtx *de_ctx, bool *fp_analysis, bool *rule_analysis)
474 {
475  *fp_analysis = false;
476  *rule_analysis = false;
477 
478  EngineAnalysisCtx *ea = SCCalloc(1, sizeof(EngineAnalysisCtx));
479  if (ea == NULL) {
480  FatalError("Unable to allocate per-engine analysis context");
481  }
482 
483  ea->file_prefix = NULL;
484  int cfg_prefix_len = strlen(de_ctx->config_prefix);
485  if (cfg_prefix_len > 0) {
486  /* length of prefix + NULL + "." */
487  ea->file_prefix = SCCalloc(1, cfg_prefix_len + 1 + 1);
488  if (ea->file_prefix == NULL) {
489  FatalError("Unable to allocate per-engine analysis context name buffer");
490  }
491 
492  snprintf(ea->file_prefix, cfg_prefix_len + 1 + 1, "%s.", de_ctx->config_prefix);
493  }
494 
495  de_ctx->ea = ea;
496 
497  *fp_analysis = SetupFPAnalyzer(de_ctx);
498  *rule_analysis = SetupRuleAnalyzer(de_ctx);
499 
500  if (!(*fp_analysis || *rule_analysis)) {
501  if (ea->file_prefix)
502  SCFree(ea->file_prefix);
503  if (ea->analyzer_items)
504  SCFree(ea->analyzer_items);
505  SCFree(ea);
506  }
507 }
508 
510 {
511  if (de_ctx->ea) {
512  CleanupRuleAnalyzer(de_ctx);
513  CleanupFPAnalyzer(de_ctx);
514  if (de_ctx->ea->file_prefix)
516  if (de_ctx->ea->analyzer_items)
518  SCFree(de_ctx->ea);
519  de_ctx->ea = NULL;
520  }
521 }
522 
523 /**
524  * \brief Checks for % encoding in content.
525  * \param Pointer to content
526  * \retval number of matches if content has % encoding
527  * \retval 0 if it doesn't have % encoding
528  * \retval -1 on error
529  */
530 static int PerCentEncodingMatch(EngineAnalysisCtx *ea_ctx, uint8_t *content, uint16_t content_len)
531 {
532  int ret = 0;
533 
534  pcre2_match_data *match = pcre2_match_data_create_from_pattern(ea_ctx->percent_re, NULL);
535  ret = pcre2_match(ea_ctx->percent_re, (PCRE2_SPTR8)content, content_len, 0, 0, match, NULL);
536  if (ret == -1) {
537  return 0;
538  } else if (ret < -1) {
539  SCLogError("Error parsing content - %s; error code is %d", content, ret);
540  ret = -1;
541  }
542  pcre2_match_data_free(match);
543  return ret;
544 }
545 
546 static void EngineAnalysisRulesPrintFP(const DetectEngineCtx *de_ctx, const Signature *s)
547 {
548  const DetectContentData *fp_cd = NULL;
549  const SigMatch *mpm_sm = s->init_data->mpm_sm;
550  const int mpm_sm_list = s->init_data->mpm_sm_list;
551 
552  if (mpm_sm != NULL) {
553  fp_cd = (DetectContentData *)mpm_sm->ctx;
554  }
555 
556  if (fp_cd == NULL) {
557  return;
558  }
559 
560  uint16_t patlen = fp_cd->content_len;
561  uint8_t *pat = SCMalloc(fp_cd->content_len + 1);
562  if (unlikely(pat == NULL)) {
563  FatalError("Error allocating memory");
564  }
565 
566  EngineAnalysisCtx *ea_ctx = de_ctx->ea;
567 
568  memcpy(pat, fp_cd->content, fp_cd->content_len);
569  pat[fp_cd->content_len] = '\0';
570 
572  SCFree(pat);
573  patlen = fp_cd->fp_chop_len;
574  pat = SCMalloc(fp_cd->fp_chop_len + 1);
575  if (unlikely(pat == NULL)) {
576  exit(EXIT_FAILURE);
577  }
578  memcpy(pat, fp_cd->content + fp_cd->fp_chop_offset, fp_cd->fp_chop_len);
579  pat[fp_cd->fp_chop_len] = '\0';
580  fprintf(ea_ctx->rule_engine_analysis_fp, " Fast Pattern \"");
581  PrintRawUriFp(ea_ctx->rule_engine_analysis_fp, pat, patlen);
582  } else {
583  fprintf(ea_ctx->rule_engine_analysis_fp, " Fast Pattern \"");
584  PrintRawUriFp(ea_ctx->rule_engine_analysis_fp, pat, patlen);
585  }
586  SCFree(pat);
587 
588  fprintf(ea_ctx->rule_engine_analysis_fp, "\" on \"");
589 
590  const int list_type = mpm_sm_list;
591  if (list_type == DETECT_SM_LIST_PMATCH) {
592  int payload = 0;
593  int stream = 0;
595  payload = 1;
597  stream = 1;
598  fprintf(ea_ctx->rule_engine_analysis_fp, "%s",
599  payload ? (stream ? "payload and reassembled stream" : "payload")
600  : "reassembled stream");
601  }
602  else {
603  const char *desc = DetectEngineBufferTypeGetDescriptionById(de_ctx, list_type);
604  const char *name = DetectEngineBufferTypeGetNameById(de_ctx, list_type);
605  if (desc && name) {
606  fprintf(ea_ctx->rule_engine_analysis_fp, "%s (%s)", desc, name);
607  } else if (desc || name) {
608  fprintf(ea_ctx->rule_engine_analysis_fp, "%s", desc ? desc : name);
609  }
610 
611  }
612 
613  fprintf(ea_ctx->rule_engine_analysis_fp, "\" ");
614  const DetectBufferType *bt = DetectEngineBufferTypeGetById(de_ctx, list_type);
615  if (bt && bt->transforms.cnt) {
616  fprintf(ea_ctx->rule_engine_analysis_fp, "(with %d transform(s)) ", bt->transforms.cnt);
617  }
618  fprintf(ea_ctx->rule_engine_analysis_fp, "buffer.\n");
619 }
620 
621 void EngineAnalysisRulesFailure(const DetectEngineCtx *de_ctx, char *line, char *file, int lineno)
622 {
623  fprintf(de_ctx->ea->fp_engine_analysis_fp, "== Sid: UNKNOWN ==\n");
624  fprintf(de_ctx->ea->fp_engine_analysis_fp, "%s\n", line);
625  fprintf(de_ctx->ea->fp_engine_analysis_fp, " FAILURE: invalid rule.\n");
626  fprintf(de_ctx->ea->fp_engine_analysis_fp, " File: %s.\n", file);
627  fprintf(de_ctx->ea->fp_engine_analysis_fp, " Line: %d.\n", lineno);
628  fprintf(de_ctx->ea->fp_engine_analysis_fp, "\n");
629 }
630 
631 typedef struct RuleAnalyzer {
632  JsonBuilder *js; /* document root */
633 
634  JsonBuilder *js_warnings;
635  JsonBuilder *js_notes;
637 
638 static void ATTR_FMT_PRINTF(2, 3) AnalyzerNote(RuleAnalyzer *ctx, char *fmt, ...)
639 {
640  va_list ap;
641  char str[1024];
642 
643  va_start(ap, fmt);
644  vsnprintf(str, sizeof(str), fmt, ap);
645  va_end(ap);
646 
647  if (!ctx->js_notes)
648  ctx->js_notes = jb_new_array();
649  if (ctx->js_notes)
650  jb_append_string(ctx->js_notes, str);
651 }
652 
653 static void ATTR_FMT_PRINTF(2, 3) AnalyzerWarning(RuleAnalyzer *ctx, char *fmt, ...)
654 {
655  va_list ap;
656  char str[1024];
657 
658  va_start(ap, fmt);
659  vsnprintf(str, sizeof(str), fmt, ap);
660  va_end(ap);
661 
662  if (!ctx->js_warnings)
663  ctx->js_warnings = jb_new_array();
664  if (ctx->js_warnings)
665  jb_append_string(ctx->js_warnings, str);
666 }
667 
668 #define CHECK(pat) if (strlen((pat)) <= len && memcmp((pat), buf, MIN(len, strlen((pat)))) == 0) return true;
669 
670 static bool LooksLikeHTTPMethod(const uint8_t *buf, uint16_t len)
671 {
672  CHECK("GET /");
673  CHECK("POST /");
674  CHECK("HEAD /");
675  CHECK("PUT /");
676  return false;
677 }
678 
679 static bool LooksLikeHTTPUA(const uint8_t *buf, uint16_t len)
680 {
681  CHECK("User-Agent: ");
682  CHECK("\nUser-Agent: ");
683  return false;
684 }
685 
686 static void DumpContent(JsonBuilder *js, const DetectContentData *cd)
687 {
688  char pattern_str[1024] = "";
689  DetectContentPatternPrettyPrint(cd, pattern_str, sizeof(pattern_str));
690 
691  jb_set_string(js, "pattern", pattern_str);
692  jb_set_uint(js, "length", cd->content_len);
693  jb_set_bool(js, "nocase", cd->flags & DETECT_CONTENT_NOCASE);
694  jb_set_bool(js, "negated", cd->flags & DETECT_CONTENT_NEGATED);
695  jb_set_bool(js, "starts_with", cd->flags & DETECT_CONTENT_STARTS_WITH);
696  jb_set_bool(js, "ends_with", cd->flags & DETECT_CONTENT_ENDS_WITH);
697  jb_set_bool(js, "is_mpm", cd->flags & DETECT_CONTENT_MPM);
698  jb_set_bool(js, "no_double_inspect", cd->flags & DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED);
699  if (cd->flags & DETECT_CONTENT_OFFSET) {
700  jb_set_uint(js, "offset", cd->offset);
701  }
702  if (cd->flags & DETECT_CONTENT_DEPTH) {
703  jb_set_uint(js, "depth", cd->depth);
704  }
705  if (cd->flags & DETECT_CONTENT_DISTANCE) {
706  jb_set_int(js, "distance", cd->distance);
707  }
708  if (cd->flags & DETECT_CONTENT_WITHIN) {
709  jb_set_int(js, "within", cd->within);
710  }
711  jb_set_bool(js, "fast_pattern", cd->flags & DETECT_CONTENT_FAST_PATTERN);
712  jb_set_bool(js, "relative_next", cd->flags & DETECT_CONTENT_RELATIVE_NEXT);
713 }
714 
715 static void DumpPcre(JsonBuilder *js, const DetectPcreData *cd)
716 {
717  jb_set_bool(js, "relative", cd->flags & DETECT_PCRE_RELATIVE);
718  jb_set_bool(js, "relative_next", cd->flags & DETECT_PCRE_RELATIVE_NEXT);
719  jb_set_bool(js, "nocase", cd->flags & DETECT_PCRE_CASELESS);
720  jb_set_bool(js, "negated", cd->flags & DETECT_PCRE_NEGATE);
721 }
722 
723 static void DumpMatches(RuleAnalyzer *ctx, JsonBuilder *js, const SigMatchData *smd)
724 {
725  if (smd == NULL)
726  return;
727 
728  jb_open_array(js, "matches");
729  do {
730  jb_start_object(js);
731  const char *mname = sigmatch_table[smd->type].name;
732  jb_set_string(js, "name", mname);
733 
734  switch (smd->type) {
735  case DETECT_CONTENT: {
736  const DetectContentData *cd = (const DetectContentData *)smd->ctx;
737 
738  jb_open_object(js, "content");
739  DumpContent(js, cd);
741  AnalyzerNote(ctx, (char *)"'fast_pattern:only' option is silently ignored and "
742  "is interpreted as regular 'fast_pattern'");
743  }
744  if (LooksLikeHTTPMethod(cd->content, cd->content_len)) {
745  AnalyzerWarning(ctx,
746  (char *)"pattern looks like it inspects HTTP, use http.request_line or "
747  "http.method and http.uri instead for improved performance");
748  }
749  if (LooksLikeHTTPUA(cd->content, cd->content_len)) {
750  AnalyzerWarning(ctx,
751  (char *)"pattern looks like it inspects HTTP, use http.user_agent "
752  "or http.header for improved performance");
753  }
755  AnalyzerNote(ctx, (char *)"'within' option for pattern w/o previous content "
756  "was converted to 'depth'");
757  }
759  AnalyzerNote(ctx, (char *)"'distance' option for pattern w/o previous content "
760  "was converted to 'offset'");
761  }
762  jb_close(js);
763  break;
764  }
765  case DETECT_PCRE: {
766  const DetectPcreData *cd = (const DetectPcreData *)smd->ctx;
767 
768  jb_open_object(js, "pcre");
769  DumpPcre(js, cd);
770  jb_close(js);
771  if (cd->flags & DETECT_PCRE_RAWBYTES) {
772  AnalyzerNote(ctx,
773  (char *)"'/B' (rawbytes) option is a no-op and is silently ignored");
774  }
775  break;
776  }
777  case DETECT_BYTEJUMP: {
778  const DetectBytejumpData *cd = (const DetectBytejumpData *)smd->ctx;
779 
780  jb_open_object(js, "byte_jump");
781  jb_set_uint(js, "nbytes", cd->nbytes);
782  jb_set_int(js, "offset", cd->offset);
783  jb_set_uint(js, "multiplier", cd->multiplier);
784  jb_set_int(js, "post_offset", cd->post_offset);
785  switch (cd->base) {
787  jb_set_string(js, "base", "unset");
788  break;
790  jb_set_string(js, "base", "oct");
791  break;
793  jb_set_string(js, "base", "dec");
794  break;
796  jb_set_string(js, "base", "hex");
797  break;
798  }
799  jb_open_array(js, "flags");
800  if (cd->flags & DETECT_BYTEJUMP_BEGIN)
801  jb_append_string(js, "from_beginning");
802  if (cd->flags & DETECT_BYTEJUMP_LITTLE)
803  jb_append_string(js, "little_endian");
804  if (cd->flags & DETECT_BYTEJUMP_BIG)
805  jb_append_string(js, "big_endian");
806  if (cd->flags & DETECT_BYTEJUMP_STRING)
807  jb_append_string(js, "string");
809  jb_append_string(js, "relative");
810  if (cd->flags & DETECT_BYTEJUMP_ALIGN)
811  jb_append_string(js, "align");
812  if (cd->flags & DETECT_BYTEJUMP_DCE)
813  jb_append_string(js, "dce");
815  jb_append_string(js, "offset_be");
816  if (cd->flags & DETECT_BYTEJUMP_END)
817  jb_append_string(js, "from_end");
818  jb_close(js);
819  jb_close(js);
820  break;
821  }
822  case DETECT_BYTETEST: {
823  const DetectBytetestData *cd = (const DetectBytetestData *)smd->ctx;
824 
825  jb_open_object(js, "byte_test");
826  jb_set_uint(js, "nbytes", cd->nbytes);
827  jb_set_int(js, "offset", cd->offset);
828  switch (cd->base) {
830  jb_set_string(js, "base", "unset");
831  break;
833  jb_set_string(js, "base", "oct");
834  break;
836  jb_set_string(js, "base", "dec");
837  break;
839  jb_set_string(js, "base", "hex");
840  break;
841  }
842  jb_open_array(js, "flags");
843  if (cd->flags & DETECT_BYTETEST_LITTLE)
844  jb_append_string(js, "little_endian");
845  if (cd->flags & DETECT_BYTETEST_BIG)
846  jb_append_string(js, "big_endian");
847  if (cd->flags & DETECT_BYTETEST_STRING)
848  jb_append_string(js, "string");
850  jb_append_string(js, "relative");
851  if (cd->flags & DETECT_BYTETEST_DCE)
852  jb_append_string(js, "dce");
853  jb_close(js);
854  jb_close(js);
855  break;
856  }
857  case DETECT_IPOPTS: {
858  const DetectIpOptsData *cd = (const DetectIpOptsData *)smd->ctx;
859 
860  jb_open_object(js, "ipopts");
861  const char *flag = IpOptsFlagToString(cd->ipopt);
862  jb_set_string(js, "option", flag);
863  jb_close(js);
864  break;
865  }
866  case DETECT_FLOWBITS: {
867  const DetectFlowbitsData *cd = (const DetectFlowbitsData *)smd->ctx;
868 
869  jb_open_object(js, "flowbits");
870  switch (cd->cmd) {
872  jb_set_string(js, "cmd", "isset");
873  break;
875  jb_set_string(js, "cmd", "isnotset");
876  break;
878  jb_set_string(js, "cmd", "set");
879  break;
881  jb_set_string(js, "cmd", "unset");
882  break;
884  jb_set_string(js, "cmd", "toggle");
885  break;
886  }
887  bool is_or = false;
888  jb_open_array(js, "names");
889  if (cd->or_list_size == 0) {
890  jb_append_string(js, VarNameStoreSetupLookup(cd->idx, VAR_TYPE_FLOW_BIT));
891  } else if (cd->or_list_size > 0) {
892  is_or = true;
893  for (uint8_t i = 0; i < cd->or_list_size; i++) {
894  const char *varname =
896  jb_append_string(js, varname);
897  }
898  }
899  jb_close(js); // array
900  if (is_or) {
901  jb_set_string(js, "operator", "or");
902  }
903  jb_close(js); // object
904  break;
905  }
906  case DETECT_ACK: {
907  const DetectAckData *cd = (const DetectAckData *)smd->ctx;
908 
909  jb_open_object(js, "ack");
910  jb_set_uint(js, "number", cd->ack);
911  jb_close(js);
912  break;
913  }
914  case DETECT_SEQ: {
915  const DetectSeqData *cd = (const DetectSeqData *)smd->ctx;
916  jb_open_object(js, "seq");
917  jb_set_uint(js, "number", cd->seq);
918  jb_close(js);
919  break;
920  }
921  case DETECT_TCPMSS: {
922  const DetectU16Data *cd = (const DetectU16Data *)smd->ctx;
923  jb_open_object(js, "tcp_mss");
924  SCDetectU16ToJson(js, cd);
925  jb_close(js);
926  break;
927  }
928  case DETECT_ICMP_ID: {
929  const DetectIcmpIdData *cd = (const DetectIcmpIdData *)smd->ctx;
930  jb_open_object(js, "id");
931  jb_set_uint(js, "number", SCNtohs(cd->id));
932  jb_close(js);
933  break;
934  }
935  }
936  jb_close(js);
937 
938  if (smd->is_last)
939  break;
940  smd++;
941  } while (1);
942  jb_close(js);
943 }
944 
947 {
948  SCEnter();
949 
950  RuleAnalyzer ctx = { NULL, NULL, NULL };
951 
952  ctx.js = jb_new_object();
953  if (ctx.js == NULL)
954  SCReturn;
955 
956  jb_set_string(ctx.js, "raw", s->sig_str);
957  jb_set_uint(ctx.js, "id", s->id);
958  jb_set_uint(ctx.js, "gid", s->gid);
959  jb_set_uint(ctx.js, "rev", s->rev);
960  jb_set_string(ctx.js, "msg", s->msg);
961 
962  const char *alproto = AppProtoToString(s->alproto);
963  jb_set_string(ctx.js, "app_proto", alproto);
964 
965  jb_open_array(ctx.js, "requirements");
966  if (s->mask & SIG_MASK_REQUIRE_PAYLOAD) {
967  jb_append_string(ctx.js, "payload");
968  }
970  jb_append_string(ctx.js, "no_payload");
971  }
972  if (s->mask & SIG_MASK_REQUIRE_FLOW) {
973  jb_append_string(ctx.js, "flow");
974  }
976  jb_append_string(ctx.js, "tcp_flags_init_deinit");
977  }
979  jb_append_string(ctx.js, "tcp_flags_unusual");
980  }
982  jb_append_string(ctx.js, "engine_event");
983  }
984  if (s->mask & SIG_MASK_REQUIRE_REAL_PKT) {
985  jb_append_string(ctx.js, "real_pkt");
986  }
987  jb_close(ctx.js);
988 
989  switch (s->type) {
990  case SIG_TYPE_NOT_SET:
991  jb_set_string(ctx.js, "type", "unset");
992  break;
993  case SIG_TYPE_IPONLY:
994  jb_set_string(ctx.js, "type", "ip_only");
995  break;
997  jb_set_string(ctx.js, "type", "like_ip_only");
998  break;
999  case SIG_TYPE_PDONLY:
1000  jb_set_string(ctx.js, "type", "pd_only");
1001  break;
1002  case SIG_TYPE_DEONLY:
1003  jb_set_string(ctx.js, "type", "de_only");
1004  break;
1005  case SIG_TYPE_PKT:
1006  jb_set_string(ctx.js, "type", "pkt");
1007  break;
1008  case SIG_TYPE_PKT_STREAM:
1009  jb_set_string(ctx.js, "type", "pkt_stream");
1010  break;
1011  case SIG_TYPE_STREAM:
1012  jb_set_string(ctx.js, "type", "stream");
1013  break;
1014  case SIG_TYPE_APPLAYER:
1015  jb_set_string(ctx.js, "type", "app_layer");
1016  break;
1017  case SIG_TYPE_APP_TX:
1018  jb_set_string(ctx.js, "type", "app_tx");
1019  break;
1020  case SIG_TYPE_MAX:
1021  jb_set_string(ctx.js, "type", "error");
1022  break;
1023  }
1024 
1025  jb_open_array(ctx.js, "flags");
1026  if (s->flags & SIG_FLAG_SRC_ANY) {
1027  jb_append_string(ctx.js, "src_any");
1028  }
1029  if (s->flags & SIG_FLAG_DST_ANY) {
1030  jb_append_string(ctx.js, "dst_any");
1031  }
1032  if (s->flags & SIG_FLAG_SP_ANY) {
1033  jb_append_string(ctx.js, "sp_any");
1034  }
1035  if (s->flags & SIG_FLAG_DP_ANY) {
1036  jb_append_string(ctx.js, "dp_any");
1037  }
1038  if ((s->action & ACTION_ALERT) == 0) {
1039  jb_append_string(ctx.js, "noalert");
1040  }
1041  if (s->flags & SIG_FLAG_DSIZE) {
1042  jb_append_string(ctx.js, "dsize");
1043  }
1044  if (s->flags & SIG_FLAG_APPLAYER) {
1045  jb_append_string(ctx.js, "applayer");
1046  }
1047  if (s->flags & SIG_FLAG_REQUIRE_PACKET) {
1048  jb_append_string(ctx.js, "need_packet");
1049  }
1050  if (s->flags & SIG_FLAG_REQUIRE_STREAM) {
1051  jb_append_string(ctx.js, "need_stream");
1052  }
1053  if (s->flags & SIG_FLAG_MPM_NEG) {
1054  jb_append_string(ctx.js, "negated_mpm");
1055  }
1056  if (s->flags & SIG_FLAG_FLUSH) {
1057  jb_append_string(ctx.js, "flush");
1058  }
1059  if (s->flags & SIG_FLAG_REQUIRE_FLOWVAR) {
1060  jb_append_string(ctx.js, "need_flowvar");
1061  }
1062  if (s->flags & SIG_FLAG_FILESTORE) {
1063  jb_append_string(ctx.js, "filestore");
1064  }
1065  if (s->flags & SIG_FLAG_TOSERVER) {
1066  jb_append_string(ctx.js, "toserver");
1067  }
1068  if (s->flags & SIG_FLAG_TOCLIENT) {
1069  jb_append_string(ctx.js, "toclient");
1070  }
1071  if (s->flags & SIG_FLAG_TLSSTORE) {
1072  jb_append_string(ctx.js, "tlsstore");
1073  }
1074  if (s->flags & SIG_FLAG_BYPASS) {
1075  jb_append_string(ctx.js, "bypass");
1076  }
1077  if (s->flags & SIG_FLAG_PREFILTER) {
1078  jb_append_string(ctx.js, "prefilter");
1079  }
1080  if (s->flags & SIG_FLAG_SRC_IS_TARGET) {
1081  jb_append_string(ctx.js, "src_is_target");
1082  }
1083  if (s->flags & SIG_FLAG_DEST_IS_TARGET) {
1084  jb_append_string(ctx.js, "dst_is_target");
1085  }
1086  jb_close(ctx.js);
1087 
1088  const DetectEnginePktInspectionEngine *pkt_mpm = NULL;
1089  const DetectEngineAppInspectionEngine *app_mpm = NULL;
1090 
1091  jb_open_array(ctx.js, "pkt_engines");
1093  for ( ; pkt != NULL; pkt = pkt->next) {
1094  const char *name = DetectEngineBufferTypeGetNameById(de_ctx, pkt->sm_list);
1095  if (name == NULL) {
1096  switch (pkt->sm_list) {
1097  case DETECT_SM_LIST_PMATCH:
1098  name = "payload";
1099  break;
1100  case DETECT_SM_LIST_MATCH:
1101  name = "packet";
1102  break;
1103  default:
1104  name = "unknown";
1105  break;
1106  }
1107  }
1108  jb_start_object(ctx.js);
1109  jb_set_string(ctx.js, "name", name);
1110  jb_set_bool(ctx.js, "is_mpm", pkt->mpm);
1111  if (pkt->v1.transforms != NULL) {
1112  jb_open_array(ctx.js, "transforms");
1113  for (int t = 0; t < pkt->v1.transforms->cnt; t++) {
1114  jb_start_object(ctx.js);
1115  jb_set_string(ctx.js, "name",
1117  jb_close(ctx.js);
1118  }
1119  jb_close(ctx.js);
1120  }
1121  DumpMatches(&ctx, ctx.js, pkt->smd);
1122  jb_close(ctx.js);
1123  if (pkt->mpm) {
1124  pkt_mpm = pkt;
1125  }
1126  }
1127  jb_close(ctx.js);
1128  jb_open_array(ctx.js, "frame_engines");
1130  for (; frame != NULL; frame = frame->next) {
1131  const char *name = DetectEngineBufferTypeGetNameById(de_ctx, frame->sm_list);
1132  jb_start_object(ctx.js);
1133  jb_set_string(ctx.js, "name", name);
1134  jb_set_bool(ctx.js, "is_mpm", frame->mpm);
1135  if (frame->v1.transforms != NULL) {
1136  jb_open_array(ctx.js, "transforms");
1137  for (int t = 0; t < frame->v1.transforms->cnt; t++) {
1138  jb_start_object(ctx.js);
1139  jb_set_string(ctx.js, "name",
1141  jb_close(ctx.js);
1142  }
1143  jb_close(ctx.js);
1144  }
1145  DumpMatches(&ctx, ctx.js, frame->smd);
1146  jb_close(ctx.js);
1147  }
1148  jb_close(ctx.js);
1149 
1151  bool has_stream = false;
1152  bool has_client_body_mpm = false;
1153  bool has_file_data_mpm = false;
1154 
1155  jb_open_array(ctx.js, "engines");
1157  for ( ; app != NULL; app = app->next) {
1158  const char *name = DetectEngineBufferTypeGetNameById(de_ctx, app->sm_list);
1159  if (name == NULL) {
1160  switch (app->sm_list) {
1161  case DETECT_SM_LIST_PMATCH:
1162  name = "stream";
1163  break;
1164  default:
1165  name = "unknown";
1166  break;
1167  }
1168  }
1169 
1170  if (app->sm_list == DETECT_SM_LIST_PMATCH && !app->mpm) {
1171  has_stream = true;
1172  } else if (app->mpm && strcmp(name, "http_client_body") == 0) {
1173  has_client_body_mpm = true;
1174  } else if (app->mpm && strcmp(name, "file_data") == 0) {
1175  has_file_data_mpm = true;
1176  }
1177 
1178  jb_start_object(ctx.js);
1179  jb_set_string(ctx.js, "name", name);
1180  const char *direction = app->dir == 0 ? "toserver" : "toclient";
1181  jb_set_string(ctx.js, "direction", direction);
1182  jb_set_bool(ctx.js, "is_mpm", app->mpm);
1183  jb_set_string(ctx.js, "app_proto", AppProtoToString(app->alproto));
1184  jb_set_uint(ctx.js, "progress", app->progress);
1185 
1186  if (app->v2.transforms != NULL) {
1187  jb_open_array(ctx.js, "transforms");
1188  for (int t = 0; t < app->v2.transforms->cnt; t++) {
1189  jb_start_object(ctx.js);
1190  jb_set_string(ctx.js, "name",
1192  jb_close(ctx.js);
1193  }
1194  jb_close(ctx.js);
1195  }
1196  DumpMatches(&ctx, ctx.js, app->smd);
1197  jb_close(ctx.js);
1198  if (app->mpm) {
1199  app_mpm = app;
1200  }
1201  }
1202  jb_close(ctx.js);
1203 
1204  if (has_stream && has_client_body_mpm)
1205  AnalyzerNote(&ctx, (char *)"mpm in http_client_body combined with stream match leads to stream buffering");
1206  if (has_stream && has_file_data_mpm)
1207  AnalyzerNote(&ctx, (char *)"mpm in file_data combined with stream match leads to stream buffering");
1208  }
1209 
1210  jb_open_object(ctx.js, "lists");
1211  for (int i = 0; i < DETECT_SM_LIST_MAX; i++) {
1212  if (s->sm_arrays[i] != NULL) {
1213  jb_open_object(ctx.js, DetectListToHumanString(i));
1214  DumpMatches(&ctx, ctx.js, s->sm_arrays[i]);
1215  jb_close(ctx.js);
1216  }
1217  }
1218  jb_close(ctx.js);
1219 
1220  if (pkt_mpm || app_mpm) {
1221  jb_open_object(ctx.js, "mpm");
1222 
1223  int mpm_list = pkt_mpm ? DETECT_SM_LIST_PMATCH : app_mpm->sm_list;
1224  const char *name;
1225  if (mpm_list < DETECT_SM_LIST_DYNAMIC_START)
1226  name = DetectListToHumanString(mpm_list);
1227  else
1228  name = DetectEngineBufferTypeGetNameById(de_ctx, mpm_list);
1229  jb_set_string(ctx.js, "buffer", name);
1230 
1231  SigMatchData *smd = pkt_mpm ? pkt_mpm->smd : app_mpm->smd;
1232  if (smd == NULL && mpm_list == DETECT_SM_LIST_PMATCH) {
1233  smd = s->sm_arrays[mpm_list];
1234  }
1235  do {
1236  switch (smd->type) {
1237  case DETECT_CONTENT: {
1238  const DetectContentData *cd = (const DetectContentData *)smd->ctx;
1239  if (cd->flags & DETECT_CONTENT_MPM) {
1240  DumpContent(ctx.js, cd);
1241  }
1242  break;
1243  }
1244  }
1245 
1246  if (smd->is_last)
1247  break;
1248  smd++;
1249  } while (1);
1250  jb_close(ctx.js);
1251  } else if (s->init_data->prefilter_sm) {
1252  jb_open_object(ctx.js, "prefilter");
1253  int prefilter_list = SigMatchListSMBelongsTo(s, s->init_data->prefilter_sm);
1254  const char *name;
1255  if (prefilter_list < DETECT_SM_LIST_DYNAMIC_START)
1256  name = DetectListToHumanString(prefilter_list);
1257  else
1258  name = DetectEngineBufferTypeGetNameById(de_ctx, prefilter_list);
1259  jb_set_string(ctx.js, "buffer", name);
1260  const char *mname = sigmatch_table[s->init_data->prefilter_sm->type].name;
1261  jb_set_string(ctx.js, "name", mname);
1262  jb_close(ctx.js);
1263  }
1264 
1265  if (ctx.js_warnings) {
1266  jb_close(ctx.js_warnings);
1267  jb_set_object(ctx.js, "warnings", ctx.js_warnings);
1268  jb_free(ctx.js_warnings);
1269  ctx.js_warnings = NULL;
1270  }
1271  if (ctx.js_notes) {
1272  jb_close(ctx.js_notes);
1273  jb_set_object(ctx.js, "notes", ctx.js_notes);
1274  jb_free(ctx.js_notes);
1275  ctx.js_notes = NULL;
1276  }
1277  jb_close(ctx.js);
1278 
1279  const char *filename = "rules.json";
1280  const char *log_dir = ConfigGetLogDirectory();
1281  char json_path[PATH_MAX] = "";
1282  snprintf(json_path, sizeof(json_path), "%s/%s%s", log_dir,
1283  de_ctx->ea->file_prefix ? de_ctx->ea->file_prefix : "", filename);
1284 
1286  FILE *fp = fopen(json_path, "a");
1287  if (fp != NULL) {
1288  fwrite(jb_ptr(ctx.js), jb_len(ctx.js), 1, fp);
1289  fprintf(fp, "\n");
1290  fclose(fp);
1291  }
1293  jb_free(ctx.js);
1294  SCReturn;
1295 }
1296 
1298 {
1299  if (de_ctx->pattern_hash_table == NULL)
1300  return;
1301 
1302  JsonBuilder *root_jb = jb_new_object();
1303  JsonBuilder *arrays[de_ctx->buffer_type_id];
1304  memset(&arrays, 0, sizeof(JsonBuilder *) * de_ctx->buffer_type_id);
1305 
1306  jb_open_array(root_jb, "buffers");
1307 
1309  htb != NULL; htb = HashListTableGetListNext(htb)) {
1310  char str[1024] = "";
1312  DetectContentPatternPrettyPrint(p->cd, str, sizeof(str));
1313 
1314  JsonBuilder *jb = arrays[p->sm_list];
1315  if (arrays[p->sm_list] == NULL) {
1316  jb = arrays[p->sm_list] = jb_new_object();
1317  const char *name;
1319  name = DetectListToHumanString(p->sm_list);
1320  else
1322  jb_set_string(jb, "name", name);
1323  jb_set_uint(jb, "list_id", p->sm_list);
1324 
1325  jb_open_array(jb, "patterns");
1326  }
1327 
1328  jb_start_object(jb);
1329  jb_set_string(jb, "pattern", str);
1330  jb_set_uint(jb, "patlen", p->cd->content_len);
1331  jb_set_uint(jb, "cnt", p->cnt);
1332  jb_set_uint(jb, "mpm", p->mpm);
1333  jb_open_object(jb, "flags");
1334  jb_set_bool(jb, "nocase", p->cd->flags & DETECT_CONTENT_NOCASE);
1335  jb_set_bool(jb, "negated", p->cd->flags & DETECT_CONTENT_NEGATED);
1336  jb_set_bool(jb, "depth", p->cd->flags & DETECT_CONTENT_DEPTH);
1337  jb_set_bool(jb, "offset", p->cd->flags & DETECT_CONTENT_OFFSET);
1338  jb_set_bool(jb, "endswith", p->cd->flags & DETECT_CONTENT_ENDS_WITH);
1339  jb_close(jb);
1340  jb_close(jb);
1341  }
1342 
1343  for (uint32_t i = 0; i < de_ctx->buffer_type_id; i++) {
1344  JsonBuilder *jb = arrays[i];
1345  if (jb == NULL)
1346  continue;
1347 
1348  jb_close(jb); // array
1349  jb_close(jb); // object
1350 
1351  jb_append_object(root_jb, jb);
1352  jb_free(jb);
1353  }
1354  jb_close(root_jb);
1355  jb_close(root_jb);
1356 
1357  const char *filename = "patterns.json";
1358  const char *log_dir = ConfigGetLogDirectory();
1359  char json_path[PATH_MAX] = "";
1360  snprintf(json_path, sizeof(json_path), "%s/%s%s", log_dir,
1361  de_ctx->ea->file_prefix ? de_ctx->ea->file_prefix : "", filename);
1362 
1364  FILE *fp = fopen(json_path, "a");
1365  if (fp != NULL) {
1366  fwrite(jb_ptr(root_jb), jb_len(root_jb), 1, fp);
1367  fprintf(fp, "\n");
1368  fclose(fp);
1369  }
1371  jb_free(root_jb);
1372 
1374  de_ctx->pattern_hash_table = NULL;
1375 }
1376 
1377 static void EngineAnalysisItemsReset(EngineAnalysisCtx *ea_ctx)
1378 {
1379  for (size_t i = 0; i < ARRAY_SIZE(analyzer_items); i++) {
1380  ea_ctx->analyzer_items[i].item_seen = false;
1381  }
1382 }
1383 
1384 static void EngineAnalysisItemsInit(EngineAnalysisCtx *ea_ctx)
1385 {
1386  if (ea_ctx->analyzer_initialized) {
1387  EngineAnalysisItemsReset(ea_ctx);
1388  return;
1389  }
1390 
1391  ea_ctx->exposed_item_seen_list[0].bufname = "http_method";
1392  ea_ctx->exposed_item_seen_list[1].bufname = "file_data";
1393  ea_ctx->analyzer_items = SCCalloc(1, sizeof(analyzer_items));
1394  if (!ea_ctx->analyzer_items) {
1395  FatalError("Unable to allocate analysis scratch pad");
1396  }
1397  memset(ea_ctx->analyzer_item_map, -1, sizeof(ea_ctx->analyzer_item_map));
1398 
1399  for (size_t i = 0; i < ARRAY_SIZE(analyzer_items); i++) {
1400  ea_ctx->analyzer_items[i] = analyzer_items[i];
1401  DetectEngineAnalyzerItems *analyzer_item = &ea_ctx->analyzer_items[i];
1402 
1403  int item_id = DetectBufferTypeGetByName(analyzer_item->item_name);
1404  DEBUG_VALIDATE_BUG_ON(item_id < 0 || item_id > UINT16_MAX);
1405  analyzer_item->item_id = (uint16_t)item_id;
1406  if (analyzer_item->item_id == -1) {
1407  /* Mismatch between the analyzer_items array and what's supported */
1408  FatalError("unable to initialize engine-analysis table: detect buffer \"%s\" not "
1409  "recognized.",
1410  analyzer_item->item_name);
1411  }
1412  analyzer_item->item_seen = false;
1413 
1414  if (analyzer_item->export_item_seen) {
1415  for (size_t k = 0; k < ARRAY_SIZE(ea_ctx->exposed_item_seen_list); k++) {
1416  if (0 ==
1417  strcmp(ea_ctx->exposed_item_seen_list[k].bufname, analyzer_item->item_name))
1418  ea_ctx->exposed_item_seen_list[k].item_seen_ptr = &analyzer_item->item_seen;
1419  }
1420  }
1421  ea_ctx->analyzer_item_map[analyzer_item->item_id] = (int16_t)i;
1422  }
1423 
1424  ea_ctx->analyzer_initialized = true;
1425 }
1426 
1427 /**
1428  * \brief Prints analysis of loaded rules.
1429  *
1430  * Warns if potential rule issues are detected. For example,
1431  * warns if a rule uses a construct that may perform poorly,
1432  * e.g. pcre without content or with http_method content only;
1433  * warns if a rule uses a construct that may not be consistent with intent,
1434  * e.g. client side ports only, http and content without any http_* modifiers, etc.
1435  *
1436  * \param s Pointer to the signature.
1437  */
1439  const Signature *s, const char *line)
1440 {
1441  uint32_t rule_bidirectional = 0;
1442  uint32_t rule_pcre = 0;
1443  uint32_t rule_pcre_http = 0;
1444  uint32_t rule_content = 0;
1445  uint32_t rule_flow = 0;
1446  uint32_t rule_flags = 0;
1447  uint32_t rule_flow_toserver = 0;
1448  uint32_t rule_flow_toclient = 0;
1449  uint32_t rule_flow_nostream = 0;
1450  uint32_t rule_ipv4_only = 0;
1451  uint32_t rule_ipv6_only = 0;
1452  uint32_t rule_flowbits = 0;
1453  uint32_t rule_flowint = 0;
1454  uint32_t rule_content_http = 0;
1455  uint32_t rule_content_offset_depth = 0;
1456  int32_t list_id = 0;
1457  uint32_t rule_warning = 0;
1458  uint32_t stream_buf = 0;
1459  uint32_t packet_buf = 0;
1460  uint32_t file_store = 0;
1461  uint32_t warn_pcre_no_content = 0;
1462  uint32_t warn_pcre_http_content = 0;
1463  uint32_t warn_pcre_http = 0;
1464  uint32_t warn_content_http_content = 0;
1465  uint32_t warn_content_http = 0;
1466  uint32_t warn_tcp_no_flow = 0;
1467  uint32_t warn_client_ports = 0;
1468  uint32_t warn_direction = 0;
1469  uint32_t warn_method_toclient = 0;
1470  uint32_t warn_method_serverbody = 0;
1471  uint32_t warn_pcre_method = 0;
1472  uint32_t warn_encoding_norm_http_buf = 0;
1473  uint32_t warn_file_store_not_present = 0;
1474  uint32_t warn_offset_depth_pkt_stream = 0;
1475  uint32_t warn_offset_depth_alproto = 0;
1476  uint32_t warn_non_alproto_fp_for_alproto_sig = 0;
1477  uint32_t warn_no_direction = 0;
1478  uint32_t warn_both_direction = 0;
1479 
1480  EngineAnalysisItemsInit(de_ctx->ea);
1481 
1482  bool *http_method_item_seen_ptr = de_ctx->ea->exposed_item_seen_list[0].item_seen_ptr;
1483  bool *http_server_body_item_seen_ptr = de_ctx->ea->exposed_item_seen_list[1].item_seen_ptr;
1484 
1486  rule_bidirectional = 1;
1487  }
1488 
1489  if (s->flags & SIG_FLAG_REQUIRE_PACKET) {
1490  packet_buf += 1;
1491  }
1492  if (s->flags & SIG_FLAG_FILESTORE) {
1493  file_store += 1;
1494  }
1495  if (s->flags & SIG_FLAG_REQUIRE_STREAM) {
1496  stream_buf += 1;
1497  }
1498 
1499  if (s->proto.flags & DETECT_PROTO_IPV4) {
1500  rule_ipv4_only += 1;
1501  }
1502  if (s->proto.flags & DETECT_PROTO_IPV6) {
1503  rule_ipv6_only += 1;
1504  }
1505 
1506  for (list_id = 0; list_id < DETECT_SM_LIST_MAX; list_id++) {
1507  SigMatch *sm = NULL;
1508  for (sm = s->init_data->smlists[list_id]; sm != NULL; sm = sm->next) {
1509  int16_t item_slot = de_ctx->ea->analyzer_item_map[list_id];
1510  if (sm->type == DETECT_PCRE) {
1511  if (item_slot == -1) {
1512  rule_pcre++;
1513  continue;
1514  }
1515 
1516  rule_pcre_http++;
1517  de_ctx->ea->analyzer_items[item_slot].item_seen = true;
1518  } else if (sm->type == DETECT_CONTENT) {
1519  if (item_slot == -1) {
1520  rule_content++;
1521  if (list_id == DETECT_SM_LIST_PMATCH) {
1524  rule_content_offset_depth++;
1525  }
1526  }
1527  continue;
1528  }
1529 
1530  rule_content_http++;
1531  de_ctx->ea->analyzer_items[item_slot].item_seen = true;
1532 
1533  if (de_ctx->ea->analyzer_items[item_slot].check_encoding_match) {
1535  if (cd != NULL &&
1536  PerCentEncodingMatch(de_ctx->ea, cd->content, cd->content_len) > 0) {
1537  warn_encoding_norm_http_buf += 1;
1538  }
1539  }
1540  }
1541  else if (sm->type == DETECT_FLOW) {
1542  rule_flow += 1;
1543  if ((s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_TOCLIENT)) {
1544  rule_flow_toserver = 1;
1545  }
1546  else if ((s->flags & SIG_FLAG_TOCLIENT) && !(s->flags & SIG_FLAG_TOSERVER)) {
1547  rule_flow_toclient = 1;
1548  }
1549  DetectFlowData *fd = (DetectFlowData *)sm->ctx;
1550  if (fd != NULL) {
1551  if (fd->flags & DETECT_FLOW_FLAG_NOSTREAM)
1552  rule_flow_nostream = 1;
1553  }
1554  }
1555  else if (sm->type == DETECT_FLOWBITS) {
1556  if (list_id == DETECT_SM_LIST_MATCH) {
1557  rule_flowbits += 1;
1558  }
1559  }
1560  else if (sm->type == DETECT_FLOWINT) {
1561  if (list_id == DETECT_SM_LIST_MATCH) {
1562  rule_flowint += 1;
1563  }
1564  }
1565  else if (sm->type == DETECT_FLAGS) {
1566  DetectFlagsData *fd = (DetectFlagsData *)sm->ctx;
1567  if (fd != NULL) {
1568  rule_flags = 1;
1569  }
1570  }
1571  } /* for (sm = s->init_data->smlists[list_id]; sm != NULL; sm = sm->next) */
1572 
1573  } /* for ( ; list_id < DETECT_SM_LIST_MAX; list_id++) */
1574 
1575  if (file_store && !RequiresFeature("output::file-store")) {
1576  rule_warning += 1;
1577  warn_file_store_not_present = 1;
1578  }
1579 
1580  if (rule_pcre > 0 && rule_content == 0 && rule_content_http == 0) {
1581  rule_warning += 1;
1582  warn_pcre_no_content = 1;
1583  }
1584 
1585  if (rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0) {
1586  rule_warning += 1;
1587  warn_pcre_http_content = 1;
1588  } else if (s->alproto == ALPROTO_HTTP1 && rule_pcre > 0 && rule_pcre_http == 0) {
1589  rule_warning += 1;
1590  warn_pcre_http = 1;
1591  }
1592 
1593  if (rule_content > 0 && rule_content_http > 0) {
1594  rule_warning += 1;
1595  warn_content_http_content = 1;
1596  }
1597  if (s->alproto == ALPROTO_HTTP1 && rule_content > 0 && rule_content_http == 0) {
1598  rule_warning += 1;
1599  warn_content_http = 1;
1600  }
1601  if (rule_content == 1) {
1602  //todo: warning if content is weak, separate warning for pcre + weak content
1603  }
1604  if (rule_flow == 0 && rule_flags == 0 && !(s->proto.flags & DETECT_PROTO_ANY) &&
1605  DetectProtoContainsProto(&s->proto, IPPROTO_TCP) &&
1606  (rule_content || rule_content_http || rule_pcre || rule_pcre_http || rule_flowbits ||
1607  rule_flowint)) {
1608  rule_warning += 1;
1609  warn_tcp_no_flow = 1;
1610  }
1611  if (rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1612  && !((s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY))) {
1613  if (((s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY))
1614  || ((s->flags & SIG_FLAG_TOCLIENT) && !(s->flags & SIG_FLAG_DP_ANY) && (s->flags & SIG_FLAG_SP_ANY))) {
1615  rule_warning += 1;
1616  warn_client_ports = 1;
1617  }
1618  }
1619  if (rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)) {
1620  rule_warning += 1;
1621  warn_direction = 1;
1622  }
1623 
1624  if (*http_method_item_seen_ptr) {
1625  if (rule_flow && rule_flow_toclient) {
1626  rule_warning += 1;
1627  warn_method_toclient = 1;
1628  }
1629  if (*http_server_body_item_seen_ptr) {
1630  rule_warning += 1;
1631  warn_method_serverbody = 1;
1632  }
1633  if (rule_content == 0 && rule_content_http == 0 && (rule_pcre > 0 || rule_pcre_http > 0)) {
1634  rule_warning += 1;
1635  warn_pcre_method = 1;
1636  }
1637  }
1638  if (rule_content_offset_depth > 0 && stream_buf && packet_buf) {
1639  rule_warning += 1;
1640  warn_offset_depth_pkt_stream = 1;
1641  }
1642  if (rule_content_offset_depth > 0 && !stream_buf && packet_buf && s->alproto != ALPROTO_UNKNOWN) {
1643  rule_warning += 1;
1644  warn_offset_depth_alproto = 1;
1645  }
1646  if (s->init_data->mpm_sm != NULL && s->alproto == ALPROTO_HTTP1 &&
1648  rule_warning += 1;
1649  warn_non_alproto_fp_for_alproto_sig = 1;
1650  }
1651 
1652  if ((s->flags & (SIG_FLAG_TOSERVER|SIG_FLAG_TOCLIENT)) == 0) {
1653  warn_no_direction += 1;
1654  rule_warning += 1;
1655  }
1656 
1657  /* No warning about direction for ICMP protos */
1658  if (!(DetectProtoContainsProto(&s->proto, IPPROTO_ICMPV6) && DetectProtoContainsProto(&s->proto, IPPROTO_ICMP))) {
1660  warn_both_direction += 1;
1661  rule_warning += 1;
1662  }
1663  }
1664 
1665  if (!rule_warnings_only || (rule_warnings_only && rule_warning > 0)) {
1666  FILE *fp = de_ctx->ea->rule_engine_analysis_fp;
1667  fprintf(fp, "== Sid: %u ==\n", s->id);
1668  fprintf(fp, "%s\n", line);
1669 
1670  switch (s->type) {
1671  case SIG_TYPE_NOT_SET:
1672  break;
1673  case SIG_TYPE_IPONLY:
1674  fprintf(fp, " Rule is ip only.\n");
1675  break;
1676  case SIG_TYPE_LIKE_IPONLY:
1677  fprintf(fp, " Rule is like ip only.\n");
1678  break;
1679  case SIG_TYPE_PDONLY:
1680  fprintf(fp, " Rule is PD only.\n");
1681  break;
1682  case SIG_TYPE_DEONLY:
1683  fprintf(fp, " Rule is DE only.\n");
1684  break;
1685  case SIG_TYPE_PKT:
1686  fprintf(fp, " Rule is packet inspecting.\n");
1687  break;
1688  case SIG_TYPE_PKT_STREAM:
1689  fprintf(fp, " Rule is packet and stream inspecting.\n");
1690  break;
1691  case SIG_TYPE_STREAM:
1692  fprintf(fp, " Rule is stream inspecting.\n");
1693  break;
1694  case SIG_TYPE_APPLAYER:
1695  fprintf(fp, " Rule is app-layer inspecting.\n");
1696  break;
1697  case SIG_TYPE_APP_TX:
1698  fprintf(fp, " Rule is App-layer TX inspecting.\n");
1699  break;
1700  case SIG_TYPE_MAX:
1701  break;
1702  }
1703  if (rule_ipv6_only)
1704  fprintf(fp, " Rule is IPv6 only.\n");
1705  if (rule_ipv4_only)
1706  fprintf(fp, " Rule is IPv4 only.\n");
1707  if (packet_buf)
1708  fprintf(fp, " Rule matches on packets.\n");
1709  if (!rule_flow_nostream && stream_buf &&
1710  (rule_flow || rule_flowbits || rule_flowint || rule_content || rule_pcre)) {
1711  fprintf(fp, " Rule matches on reassembled stream.\n");
1712  }
1713  for(size_t i = 0; i < ARRAY_SIZE(analyzer_items); i++) {
1715  if (ai->item_seen) {
1716  fprintf(fp, " Rule matches on %s buffer.\n", ai->display_name);
1717  }
1718  }
1719  if (s->alproto != ALPROTO_UNKNOWN) {
1720  fprintf(fp, " App layer protocol is %s.\n", AppProtoToString(s->alproto));
1721  }
1722  if (rule_content || rule_content_http || rule_pcre || rule_pcre_http) {
1723  fprintf(fp,
1724  " Rule contains %u content options, %u http content options, %u pcre "
1725  "options, and %u pcre options with http modifiers.\n",
1726  rule_content, rule_content_http, rule_pcre, rule_pcre_http);
1727  }
1728 
1729  /* print fast pattern info */
1730  if (s->init_data->prefilter_sm) {
1731  fprintf(fp, " Prefilter on: %s.\n",
1733  } else {
1734  EngineAnalysisRulesPrintFP(de_ctx, s);
1735  }
1736 
1737  /* this is where the warnings start */
1738  if (warn_pcre_no_content /*rule_pcre > 0 && rule_content == 0 && rule_content_http == 0*/) {
1739  fprintf(fp, " Warning: Rule uses pcre without a content option present.\n"
1740  " -Consider adding a content to improve performance of this "
1741  "rule.\n");
1742  }
1743  if (warn_pcre_http_content /*rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0*/) {
1744  fprintf(fp, " Warning: Rule uses content options with http_* and pcre options "
1745  "without http modifiers.\n"
1746  " -Consider adding http pcre modifier.\n");
1747  }
1748  else if (warn_pcre_http /*s->alproto == ALPROTO_HTTP1 && rule_pcre > 0 && rule_pcre_http == 0*/) {
1749  fprintf(fp, " Warning: Rule app layer protocol is http, but pcre options do not "
1750  "have http modifiers.\n"
1751  " -Consider adding http pcre modifiers.\n");
1752  }
1753  if (warn_content_http_content /*rule_content > 0 && rule_content_http > 0*/) {
1754  fprintf(fp,
1755  " Warning: Rule contains content with http_* and content without http_*.\n"
1756  " -Consider adding http content modifiers.\n");
1757  }
1758  if (warn_content_http /*s->alproto == ALPROTO_HTTP1 && rule_content > 0 && rule_content_http == 0*/) {
1759  fprintf(fp, " Warning: Rule app layer protocol is http, but content options do not "
1760  "have http_* modifiers.\n"
1761  " -Consider adding http content modifiers.\n");
1762  }
1763  if (rule_content == 1) {
1764  //todo: warning if content is weak, separate warning for pcre + weak content
1765  }
1766  if (warn_encoding_norm_http_buf) {
1767  fprintf(fp, " Warning: Rule may contain percent encoded content for a normalized "
1768  "http buffer match.\n");
1769  }
1770  if (warn_tcp_no_flow /*rule_flow == 0 && rule_flags == 0
1771  && !(s->proto.flags & DETECT_PROTO_ANY) && DetectProtoContainsProto(&s->proto, IPPROTO_TCP)*/) {
1772  fprintf(fp, " Warning: TCP rule without a flow or flags option.\n"
1773  " -Consider adding flow or flags to improve performance of "
1774  "this rule.\n");
1775  }
1776  if (warn_client_ports /*rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1777  && !((s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY)))
1778  if (((s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY))
1779  || ((s->flags & SIG_FLAG_TOCLIENT) && !(s->flags & SIG_FLAG_DP_ANY) && (s->flags & SIG_FLAG_SP_ANY))*/) {
1780  fprintf(fp,
1781  " Warning: Rule contains ports or port variables only on the client side.\n"
1782  " -Flow direction possibly inconsistent with rule.\n");
1783  }
1784  if (warn_direction /*rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)*/) {
1785  fprintf(fp, " Warning: Rule is bidirectional and has a flow option with a specific "
1786  "direction.\n");
1787  }
1788  if (warn_method_toclient /*http_method_buf && rule_flow && rule_flow_toclient*/) {
1789  fprintf(fp, " Warning: Rule uses content or pcre for http_method with "
1790  "flow:to_client or from_server\n");
1791  }
1792  if (warn_method_serverbody /*http_method_buf && http_server_body_buf*/) {
1793  fprintf(fp, " Warning: Rule uses content or pcre for http_method with content or "
1794  "pcre for http_server_body.\n");
1795  }
1796  if (warn_pcre_method /*http_method_buf && rule_content == 0 && rule_content_http == 0
1797  && (rule_pcre > 0 || rule_pcre_http > 0)*/) {
1798  fprintf(fp, " Warning: Rule uses pcre with only a http_method content; possible "
1799  "performance issue.\n");
1800  }
1801  if (warn_offset_depth_pkt_stream) {
1802  fprintf(fp, " Warning: Rule has depth"
1803  "/offset with raw content keywords. Please note the "
1804  "offset/depth will be checked against both packet "
1805  "payloads and stream. If you meant to have the offset/"
1806  "depth checked against just the payload, you can update "
1807  "the signature as \"alert tcp-pkt...\"\n");
1808  }
1809  if (warn_offset_depth_alproto) {
1810  fprintf(fp,
1811  " Warning: Rule has "
1812  "offset/depth set along with a match on a specific "
1813  "app layer protocol - %d. This can lead to FNs if we "
1814  "have a offset/depth content match on a packet payload "
1815  "before we can detect the app layer protocol for the "
1816  "flow.\n",
1817  s->alproto);
1818  }
1819  if (warn_non_alproto_fp_for_alproto_sig) {
1820  fprintf(fp, " Warning: Rule app layer "
1821  "protocol is http, but the fast_pattern is set on the raw "
1822  "stream. Consider adding fast_pattern over a http "
1823  "buffer for increased performance.");
1824  }
1825  if (warn_no_direction) {
1826  fprintf(fp, " Warning: Rule has no direction indicator.\n");
1827  }
1828  if (warn_both_direction) {
1829  fprintf(fp, " Warning: Rule is inspecting both the request and the response.\n");
1830  }
1831  if (warn_file_store_not_present) {
1832  fprintf(fp, " Warning: Rule requires file-store but the output file-store is not "
1833  "enabled.\n");
1834  }
1835  if (rule_warning == 0) {
1836  fprintf(fp, " No warnings for this rule.\n");
1837  }
1838  fprintf(fp, "\n");
1839  }
1840 }
detect-tcp-flags.h
DETECT_PCRE_CASELESS
#define DETECT_PCRE_CASELESS
Definition: detect-pcre.h:32
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:796
RuleAnalyzer::js
JsonBuilder * js
Definition: detect-engine-analyzer.c:632
DetectBytejumpData_::post_offset
int32_t post_offset
Definition: detect-bytejump.h:51
HashListTableGetListData
#define HashListTableGetListData(hb)
Definition: util-hashlist.h:56
SIG_TYPE_STREAM
@ SIG_TYPE_STREAM
Definition: detect.h:72
DetectContentData_::offset
uint16_t offset
Definition: detect-content.h:107
DetectBytetestData_::flags
uint16_t flags
Definition: detect-bytetest.h:58
detect-engine-uint.h
DetectPatternTracker
Definition: detect.h:730
DetectEngineAppInspectionEngine_
Definition: detect.h:429
DETECT_CONTENT_RELATIVE_NEXT
#define DETECT_CONTENT_RELATIVE_NEXT
Definition: detect-content.h:66
DetectEngineAppInspectionEngine_::mpm
bool mpm
Definition: detect.h:433
detect-content.h
DetectFlowbitsData_::or_list_size
uint8_t or_list_size
Definition: detect-flowbits.h:38
len
uint8_t len
Definition: app-layer-dnp3.h:2
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:116
SIG_MASK_REQUIRE_REAL_PKT
#define SIG_MASK_REQUIRE_REAL_PKT
Definition: detect.h:306
DETECT_CONTENT_FAST_PATTERN_CHOP
#define DETECT_CONTENT_FAST_PATTERN_CHOP
Definition: detect-content.h:36
SignatureInitData_::smlists
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
Definition: detect.h:586
DetectContentData_::fp_chop_len
uint16_t fp_chop_len
Definition: detect-content.h:98
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:127
Signature_::sig_str
char * sig_str
Definition: detect.h:668
SIG_TYPE_APP_TX
@ SIG_TYPE_APP_TX
Definition: detect.h:75
DetectSeqData_::seq
uint32_t seq
Definition: detect-tcp-seq.h:31
DetectIcmpIdData_
Definition: detect-icmp-id.h:27
DetectEnginePktInspectionEngine
Definition: detect.h:486
DetectEngineAppInspectionEngine_::next
struct DetectEngineAppInspectionEngine_ * next
Definition: detect.h:451
DETECT_PROTO_IPV6
#define DETECT_PROTO_IPV6
Definition: detect-engine-proto.h:32
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:1304
DETECT_BYTEJUMP
@ DETECT_BYTEJUMP
Definition: detect-engine-register.h:84
DetectPatternTracker::mpm
uint32_t mpm
Definition: detect.h:734
ConfGetBool
int ConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
Definition: conf.c:482
DetectListToHumanString
const char * DetectListToHumanString(int list)
Definition: detect-parse.c:160
DetectEngineCtx_::pattern_hash_table
HashListTable * pattern_hash_table
Definition: detect.h:877
DumpPatterns
void DumpPatterns(DetectEngineCtx *de_ctx)
Definition: detect-engine-analyzer.c:1297
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectContentData_::within
int32_t within
Definition: detect-content.h:109
DETECT_BYTEJUMP_LITTLE
#define DETECT_BYTEJUMP_LITTLE
Definition: detect-bytejump.h:35
SetupEngineAnalysis
void SetupEngineAnalysis(DetectEngineCtx *de_ctx, bool *fp_analysis, bool *rule_analysis)
Definition: detect-engine-analyzer.c:473
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:70
SignatureInitData_::prefilter_sm
SigMatch * prefilter_sm
Definition: detect.h:567
EngineAnalysisCtx_::rule_engine_analysis_fp
FILE * rule_engine_analysis_fp
Definition: detect-engine-analyzer.c:83
DETECT_FLOW
@ DETECT_FLOW
Definition: detect-engine-register.h:54
Signature_::alproto
AppProto alproto
Definition: detect.h:606
RuleAnalyzer::js_warnings
JsonBuilder * js_warnings
Definition: detect-engine-analyzer.c:634
DETECT_BYTETEST_BASE_HEX
#define DETECT_BYTETEST_BASE_HEX
Definition: detect-bytetest.h:40
SigMatchData_::is_last
bool is_last
Definition: detect.h:360
g_rules_analyzer_write_m
SCMutex g_rules_analyzer_write_m
Definition: detect-engine-analyzer.c:945
DetectEngineAnalyzerItems::display_name
const char * display_name
Definition: detect-engine-analyzer.c:65
DETECT_CONTENT_WITHIN2DEPTH
#define DETECT_CONTENT_WITHIN2DEPTH
Definition: detect-content.h:62
EngineAnalysisCtx_::percent_re
pcre2_code * percent_re
Definition: detect-engine-analyzer.c:88
DETECT_SM_LIST_DYNAMIC_START
@ DETECT_SM_LIST_DYNAMIC_START
Definition: detect.h:135
DETECT_FLOWBITS_CMD_ISNOTSET
#define DETECT_FLOWBITS_CMD_ISNOTSET
Definition: detect-flowbits.h:31
SIG_FLAG_DEST_IS_TARGET
#define SIG_FLAG_DEST_IS_TARGET
Definition: detect.h:281
SigMatchData_::ctx
SigMatchCtx * ctx
Definition: detect.h:361
DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED
#define DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED
Definition: detect-content.h:55
action-globals.h
ConfGetNode
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Definition: conf.c:181
EngineAnalysisCtx_
Definition: detect-engine-analyzer.c:81
DETECT_IPOPTS
@ DETECT_IPOPTS
Definition: detect-engine-register.h:39
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
Definition: app-layer-protos.c:78
ctx
struct Thresholds ctx
DETECT_BYTEJUMP_BASE_OCT
#define DETECT_BYTEJUMP_BASE_OCT
Definition: detect-bytejump.h:29
DetectEngineFrameInspectionEngine::transforms
const DetectEngineTransforms * transforms
Definition: detect.h:521
DetectFlowData_::flags
uint16_t flags
Definition: detect-flow.h:38
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:841
DETECT_PROTO_ANY
#define DETECT_PROTO_ANY
Definition: detect-engine-proto.h:28
DetectEnginePktInspectionEngine::smd
SigMatchData * smd
Definition: detect.h:487
SIG_TYPE_PKT_STREAM
@ SIG_TYPE_PKT_STREAM
Definition: detect.h:71
DetectFlowbitsData_::cmd
uint8_t cmd
Definition: detect-flowbits.h:37
DetectEngineFrameInspectionEngine::mpm
bool mpm
Definition: detect.h:515
DETECT_BYTETEST_DCE
#define DETECT_BYTETEST_DCE
Definition: detect-bytetest.h:47
HashListTableGetListHead
HashListTableBucket * HashListTableGetListHead(HashListTable *ht)
Definition: util-hashlist.c:287
detect-tcp-seq.h
DetectEngineAppInspectionEngine_::v2
struct DetectEngineAppInspectionEngine_::@79 v2
EngineAnalysisCtx_::fp_pattern_stats
FpPatternStats fp_pattern_stats[DETECT_SM_LIST_MAX]
Definition: detect-engine-analyzer.c:100
DetectEngineBufferTypeGetNameById
const char * DetectEngineBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1121
SIG_FLAG_DST_ANY
#define SIG_FLAG_DST_ANY
Definition: detect.h:239
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
util-var-name.h
SIG_FLAG_REQUIRE_STREAM
#define SIG_FLAG_REQUIRE_STREAM
Definition: detect.h:251
DetectPatternTracker::cnt
uint32_t cnt
Definition: detect.h:733
rust.h
EngineAnalysisCtx_::fp_engine_analysis_fp
FILE * fp_engine_analysis_fp
Definition: detect-engine-analyzer.c:84
EngineAnalysisCtx_::analyzer_initialized
bool analyzer_initialized
Definition: detect-engine-analyzer.c:107
DetectEngineAnalyzerItems
Definition: detect-engine-analyzer.c:59
DETECT_BYTEJUMP_DCE
#define DETECT_BYTEJUMP_DCE
Definition: detect-bytejump.h:40
DetectPatternTracker::cd
const struct DetectContentData_ * cd
Definition: detect.h:731
VarNameStoreSetupLookup
const char * VarNameStoreSetupLookup(const uint32_t id, const enum VarTypes type)
Definition: util-var-name.c:188
SCMUTEX_INITIALIZER
#define SCMUTEX_INITIALIZER
Definition: threads-debug.h:121
Signature_::sm_arrays
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
Definition: detect.h:654
FpPatternStats_::max
uint16_t max
Definition: detect-engine-analyzer.c:70
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:553
DetectBufferType_
Definition: detect.h:454
DETECT_FLOWBITS_CMD_TOGGLE
#define DETECT_FLOWBITS_CMD_TOGGLE
Definition: detect-flowbits.h:29
DetectContentData_
Definition: detect-content.h:93
DETECT_FLOWBITS_CMD_ISSET
#define DETECT_FLOWBITS_CMD_ISSET
Definition: detect-flowbits.h:32
DetectPcreData_::flags
uint16_t flags
Definition: detect-pcre.h:46
DetectContentData_::fp_chop_offset
uint16_t fp_chop_offset
Definition: detect-content.h:100
DetectBytetestData_::nbytes
uint8_t nbytes
Definition: detect-bytetest.h:54
DetectBytetestData_
Definition: detect-bytetest.h:53
EngineAnalysisCtx_::analyzer_item_map
int16_t analyzer_item_map[256]
Definition: detect-engine-analyzer.c:99
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:268
DETECT_BYTEJUMP_BIG
#define DETECT_BYTEJUMP_BIG
Definition: detect-bytejump.h:36
SIG_FLAG_SRC_ANY
#define SIG_FLAG_SRC_ANY
Definition: detect.h:238
SigMatchData_
Data needed for Match()
Definition: detect.h:358
DetectBytejumpData_::base
uint8_t base
Definition: detect-bytejump.h:48
detect-pcre.h
SIG_TYPE_APPLAYER
@ SIG_TYPE_APPLAYER
Definition: detect.h:74
SigMatchData_::type
uint16_t type
Definition: detect.h:359
DetectBytejumpData_
Definition: detect-bytejump.h:46
Signature_::frame_inspect
DetectEngineFrameInspectionEngine * frame_inspect
Definition: detect.h:650
DetectBytejumpData_::offset
int32_t offset
Definition: detect-bytejump.h:50
DetectEnginePktInspectionEngine::transforms
const DetectEngineTransforms * transforms
Definition: detect.h:495
ConfValIsTrue
int ConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:536
EngineAnalysisCtx_::analyzer_items
DetectEngineAnalyzerItems * analyzer_items
Definition: detect-engine-analyzer.c:86
DETECT_PERCENT_ENCODING_REGEX
#define DETECT_PERCENT_ENCODING_REGEX
DetectEngineBufferTypeGetById
const DetectBufferType * DetectEngineBufferTypeGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1111
DetectBytejumpData_::multiplier
uint16_t multiplier
Definition: detect-bytejump.h:52
SIG_FLAG_APPLAYER
#define SIG_FLAG_APPLAYER
Definition: detect.h:246
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1091
Signature_::gid
uint32_t gid
Definition: detect.h:637
DetectEngineAppInspectionEngine_::sm_list
uint16_t sm_list
Definition: detect.h:435
ATTR_FMT_PRINTF
#define ATTR_FMT_PRINTF(x, y)
Definition: suricata-common.h:410
DetectFlowbitsData_
Definition: detect-flowbits.h:35
HashListTableGetListNext
#define HashListTableGetListNext(hb)
Definition: util-hashlist.h:55
DetectEngineAnalyzerItems::export_item_seen
bool export_item_seen
Definition: detect-engine-analyzer.c:62
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:267
RequiresFeature
bool RequiresFeature(const char *feature_name)
Definition: feature.c:126
DETECT_BYTETEST_RELATIVE
#define DETECT_BYTETEST_RELATIVE
Definition: detect-bytetest.h:46
SIG_TYPE_PKT
@ SIG_TYPE_PKT
Definition: detect.h:70
DetectSeqData_
seq data
Definition: detect-tcp-seq.h:30
feature.h
IpOptsFlagToString
const char * IpOptsFlagToString(uint16_t flag)
Return human readable value for ipopts flag.
Definition: detect-ipopts.c:117
EngineAnalysisCtx
struct EngineAnalysisCtx_ EngineAnalysisCtx
DETECT_CONTENT_ENDS_WITH
#define DETECT_CONTENT_ENDS_WITH
Definition: detect-content.h:42
DETECT_PCRE_RAWBYTES
#define DETECT_PCRE_RAWBYTES
Definition: detect-pcre.h:31
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:489
SIG_FLAG_INIT_BIDIREC
#define SIG_FLAG_INIT_BIDIREC
Definition: detect.h:289
DETECT_FLOWINT
@ DETECT_FLOWINT
Definition: detect-engine-register.h:63
SIG_MASK_REQUIRE_ENGINE_EVENT
#define SIG_MASK_REQUIRE_ENGINE_EVENT
Definition: detect.h:308
DETECT_BYTETEST_BASE_UNSET
#define DETECT_BYTETEST_BASE_UNSET
Definition: detect-bytetest.h:37
SIG_TYPE_IPONLY
@ SIG_TYPE_IPONLY
Definition: detect.h:64
DETECT_BYTEJUMP_ALIGN
#define DETECT_BYTEJUMP_ALIGN
Definition: detect-bytejump.h:39
SignatureInitData_::mpm_sm
SigMatch * mpm_sm
Definition: detect.h:565
DetectEngineBufferTypeGetDescriptionById
const char * DetectEngineBufferTypeGetDescriptionById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1199
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:119
SIG_FLAG_FLUSH
#define SIG_FLAG_FLUSH
Definition: detect.h:255
DetectIpOptsData_::ipopt
uint16_t ipopt
Definition: detect-ipopts.h:38
SignatureInitData_::mpm_sm_list
int mpm_sm_list
Definition: detect.h:563
DETECT_BYTETEST_BASE_DEC
#define DETECT_BYTETEST_BASE_DEC
Definition: detect-bytetest.h:39
SIG_MASK_REQUIRE_FLOW
#define SIG_MASK_REQUIRE_FLOW
Definition: detect.h:302
SIG_FLAG_BYPASS
#define SIG_FLAG_BYPASS
Definition: detect.h:272
DETECT_CONTENT_DEPTH
#define DETECT_CONTENT_DEPTH
Definition: detect-content.h:33
DETECT_CONTENT_DISTANCE2OFFSET
#define DETECT_CONTENT_DISTANCE2OFFSET
Definition: detect-content.h:63
RuleAnalyzer
Definition: detect-engine-analyzer.c:631
DETECT_BYTEJUMP_END
#define DETECT_BYTEJUMP_END
Definition: detect-bytejump.h:42
Signature_::pkt_inspect
DetectEnginePktInspectionEngine * pkt_inspect
Definition: detect.h:649
DetectEngineAnalyzerItems
struct DetectEngineAnalyzerItems DetectEngineAnalyzerItems
util-print.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
detect-engine-mpm.h
detect.h
SIG_MASK_REQUIRE_FLAGS_INITDEINIT
#define SIG_MASK_REQUIRE_FLAGS_INITDEINIT
Definition: detect.h:303
DetectEngineFrameInspectionEngine::sm_list
uint16_t sm_list
Definition: detect.h:516
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:353
DetectEngineAnalyzerItems::item_seen
bool item_seen
Definition: detect-engine-analyzer.c:61
DETECT_CONTENT_NEGATED
#define DETECT_CONTENT_NEGATED
Definition: detect-content.h:40
util-time.h
DETECT_ICMP_ID
@ DETECT_ICMP_ID
Definition: detect-engine-register.h:49
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:114
DetectAckData_::ack
uint32_t ack
Definition: detect-tcp-ack.h:31
EngineAnalysisRules
void EngineAnalysisRules(const DetectEngineCtx *de_ctx, const Signature *s, const char *line)
Prints analysis of loaded rules.
Definition: detect-engine-analyzer.c:1438
Signature_::app_inspect
DetectEngineAppInspectionEngine * app_inspect
Definition: detect.h:648
DETECT_SEQ
@ DETECT_SEQ
Definition: detect-engine-register.h:37
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:352
DETECT_ACK
@ DETECT_ACK
Definition: detect-engine-register.h:36
SIG_FLAG_REQUIRE_FLOWVAR
#define SIG_FLAG_REQUIRE_FLOWVAR
Definition: detect.h:263
Signature_::action
uint8_t action
Definition: detect.h:616
FpPatternStats_::cnt
uint32_t cnt
Definition: detect-engine-analyzer.c:71
SCReturn
#define SCReturn
Definition: util-debug.h:273
Signature_::flags
uint32_t flags
Definition: detect.h:602
DetectContentData_::depth
uint16_t depth
Definition: detect-content.h:106
ACTION_ALERT
#define ACTION_ALERT
Definition: action-globals.h:29
DETECT_BYTETEST_BIG
#define DETECT_BYTETEST_BIG
Definition: detect-bytetest.h:44
SCLocalTime
struct tm * SCLocalTime(time_t timep, struct tm *result)
Definition: util-time.c:267
detect-bytejump.h
conf.h
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:104
CHECK
#define CHECK(pat)
Definition: detect-engine-analyzer.c:668
DetectEngineFrameInspectionEngine
Definition: detect.h:511
DetectFlowbitsData_::idx
uint32_t idx
Definition: detect-flowbits.h:36
DETECT_BYTEJUMP_BASE_UNSET
#define DETECT_BYTEJUMP_BASE_UNSET
Definition: detect-bytejump.h:28
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:670
SIG_FLAG_SRC_IS_TARGET
#define SIG_FLAG_SRC_IS_TARGET
Definition: detect.h:279
DetectContentPatternPrettyPrint
void DetectContentPatternPrettyPrint(const DetectContentData *cd, char *str, size_t str_len)
Definition: detect-content.c:763
DetectIcmpIdData_::id
uint16_t id
Definition: detect-icmp-id.h:28
DetectEngineTransforms::transforms
TransformData transforms[DETECT_TRANSFORMS_MAX]
Definition: detect.h:409
DETECT_BYTEJUMP_BASE_HEX
#define DETECT_BYTEJUMP_BASE_HEX
Definition: detect-bytejump.h:31
SIG_TYPE_DEONLY
@ SIG_TYPE_DEONLY
Definition: detect.h:69
detect-flowbits.h
SIG_MASK_REQUIRE_PAYLOAD
#define SIG_MASK_REQUIRE_PAYLOAD
Definition: detect.h:301
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:224
DETECT_PCRE
@ DETECT_PCRE
Definition: detect-engine-register.h:72
SIG_TYPE_NOT_SET
@ SIG_TYPE_NOT_SET
Definition: detect.h:63
ExposedItemSeen::bufname
const char * bufname
Definition: detect-engine-analyzer.c:77
EngineAnalysisRulesFailure
void EngineAnalysisRulesFailure(const DetectEngineCtx *de_ctx, char *line, char *file, int lineno)
Definition: detect-engine-analyzer.c:621
DETECT_BYTEJUMP_OFFSET_BE
#define DETECT_BYTEJUMP_OFFSET_BE
Definition: detect-bytejump.h:41
DetectEngineCtx_::config_prefix
char config_prefix[64]
Definition: detect.h:960
DetectSigmatchListEnumToString
const char * DetectSigmatchListEnumToString(enum DetectSigmatchListEnum type)
Definition: detect-engine.c:4930
analyzer_items
const DetectEngineAnalyzerItems analyzer_items[]
Definition: detect-engine-analyzer.c:110
DetectEngineAppInspectionEngine_::alproto
AppProto alproto
Definition: detect.h:430
SIG_FLAG_MPM_NEG
#define SIG_FLAG_MPM_NEG
Definition: detect.h:253
detect-engine-analyzer.h
SIG_FLAG_INIT_STATE_MATCH
#define SIG_FLAG_INIT_STATE_MATCH
Definition: detect.h:292
DetectEngineAnalyzerItems::item_id
int16_t item_id
Definition: detect-engine-analyzer.c:60
DetectPatternTracker::sm_list
int sm_list
Definition: detect.h:732
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:449
EngineAnalysisRules2
void EngineAnalysisRules2(const DetectEngineCtx *de_ctx, const Signature *s)
Definition: detect-engine-analyzer.c:946
ARRAY_SIZE
#define ARRAY_SIZE(arr)
Definition: suricata-common.h:545
DETECT_CONTENT_STARTS_WITH
#define DETECT_CONTENT_STARTS_WITH
Definition: detect-content.h:59
DetectProto_::flags
uint8_t flags
Definition: detect-engine-proto.h:37
DETECT_BYTETEST
@ DETECT_BYTETEST
Definition: detect-engine-register.h:83
DETECT_PROTO_IPV4
#define DETECT_PROTO_IPV4
Definition: detect-engine-proto.h:31
util-conf.h
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:826
RuleAnalyzer::js_notes
JsonBuilder * js_notes
Definition: detect-engine-analyzer.c:635
EngineAnalysisFP
void EngineAnalysisFP(const DetectEngineCtx *de_ctx, const Signature *s, char *line)
Definition: detect-engine-analyzer.c:167
FpPatternStats_::min
uint16_t min
Definition: detect-engine-analyzer.c:69
VAR_TYPE_FLOW_BIT
@ VAR_TYPE_FLOW_BIT
Definition: util-var.h:36
Signature_::proto
DetectProto proto
Definition: detect.h:620
SCNtohs
#define SCNtohs(x)
Definition: suricata-common.h:414
suricata-common.h
SIG_MASK_REQUIRE_NO_PAYLOAD
#define SIG_MASK_REQUIRE_NO_PAYLOAD
Definition: detect.h:305
SIG_FLAG_SP_ANY
#define SIG_FLAG_SP_ANY
Definition: detect.h:240
ExposedItemSeen
Definition: detect-engine-analyzer.c:76
SigMatch_::type
uint16_t type
Definition: detect.h:350
HashListTableFree
void HashListTableFree(HashListTable *ht)
Definition: util-hashlist.c:88
DetectEngineAnalyzerItems::check_encoding_match
bool check_encoding_match
Definition: detect-engine-analyzer.c:63
DetectContentData_::distance
int32_t distance
Definition: detect-content.h:108
CleanupEngineAnalysis
void CleanupEngineAnalysis(DetectEngineCtx *de_ctx)
Definition: detect-engine-analyzer.c:509
DetectBytejumpData_::nbytes
uint8_t nbytes
Definition: detect-bytejump.h:47
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:30
DetectEngineFrameInspectionEngine::next
struct DetectEngineFrameInspectionEngine * next
Definition: detect.h:524
DetectEnginePktInspectionEngine::next
struct DetectEnginePktInspectionEngine * next
Definition: detect.h:497
DetectContentData_::content
uint8_t * content
Definition: detect-content.h:94
Signature_::rev
uint32_t rev
Definition: detect.h:638
DetectEngineFrameInspectionEngine::v1
struct DetectEngineFrameInspectionEngine::@83 v1
FatalError
#define FatalError(...)
Definition: util-debug.h:502
DETECT_BYTEJUMP_BASE_DEC
#define DETECT_BYTEJUMP_BASE_DEC
Definition: detect-bytejump.h:30
DetectIpOptsData_
Definition: detect-ipopts.h:37
SIG_MASK_REQUIRE_FLAGS_UNUSUAL
#define SIG_MASK_REQUIRE_FLAGS_UNUSUAL
Definition: detect.h:304
TransformData_::transform
int transform
Definition: detect.h:404
DETECT_FLOWBITS
@ DETECT_FLOWBITS
Definition: detect-engine-register.h:60
SIG_TYPE_MAX
@ SIG_TYPE_MAX
Definition: detect.h:77
DetectEngineCtx_::ea
struct EngineAnalysisCtx_ * ea
Definition: detect.h:1038
DetectEngineAppInspectionEngine_::progress
int16_t progress
Definition: detect.h:437
DETECT_BYTETEST_BASE_OCT
#define DETECT_BYTETEST_BASE_OCT
Definition: detect-bytetest.h:38
util-validate.h
detect-flow.h
PrintRawUriFp
void PrintRawUriFp(FILE *fp, uint8_t *buf, uint32_t buflen)
Definition: util-print.c:69
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
ConfigGetLogDirectory
const char * ConfigGetLogDirectory(void)
Definition: util-conf.c:38
FpPatternStats
struct FpPatternStats_ FpPatternStats
detect-tcp-ack.h
str
#define str(s)
Definition: suricata-common.h:291
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
SigMatchListSMBelongsTo
int SigMatchListSMBelongsTo(const Signature *s, const SigMatch *key_sm)
Definition: detect-parse.c:805
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DetectFlowbitsData_::or_list
uint32_t * or_list
Definition: detect-flowbits.h:39
ConfNode_
Definition: conf.h:32
Signature_::id
uint32_t id
Definition: detect.h:636
DETECT_CONTENT_OFFSET
#define DETECT_CONTENT_OFFSET
Definition: detect-content.h:32
HashListTableBucket_
Definition: util-hashlist.h:28
DETECT_FLOWBITS_CMD_UNSET
#define DETECT_FLOWBITS_CMD_UNSET
Definition: detect-flowbits.h:30
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:466
DetectEnginePktInspectionEngine::v1
struct DetectEnginePktInspectionEngine::@82 v1
detect-parse.h
Signature_
Signature container.
Definition: detect.h:601
SigMatch_
a single match condition for a signature
Definition: detect.h:349
DetectEngineAppInspectionEngine_::transforms
const DetectEngineTransforms * transforms
Definition: detect.h:446
DETECT_SM_LIST_MAX
@ DETECT_SM_LIST_MAX
Definition: detect.h:132
FpPatternStats_::tot
uint64_t tot
Definition: detect-engine-analyzer.c:72
DETECT_BYTETEST_STRING
#define DETECT_BYTETEST_STRING
Definition: detect-bytetest.h:45
DetectBytetestData_::offset
int32_t offset
Definition: detect-bytetest.h:60
DetectFlagsData_
Definition: detect-tcp-flags.h:37
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
DETECT_PCRE_RELATIVE_NEXT
#define DETECT_PCRE_RELATIVE_NEXT
Definition: detect-pcre.h:34
detect-icmp-id.h
detect-ipopts.h
DetectEngineTransforms::cnt
int cnt
Definition: detect.h:410
suricata.h
DetectPcreData_
Definition: detect-pcre.h:42
DetectEngineAppInspectionEngine_::dir
uint8_t dir
Definition: detect.h:431
DetectEngineAnalyzerItems::item_name
const char * item_name
Definition: detect-engine-analyzer.c:64
DetectContentData_::content_len
uint16_t content_len
Definition: detect-content.h:95
ExposedItemSeen::item_seen_ptr
bool * item_seen_ptr
Definition: detect-engine-analyzer.c:78
DETECT_BYTEJUMP_STRING
#define DETECT_BYTEJUMP_STRING
Definition: detect-bytejump.h:37
DetectEngineCtx_::buffer_type_id
uint32_t buffer_type_id
Definition: detect.h:990
EngineAnalysisCtx_::file_prefix
char * file_prefix
Definition: detect-engine-analyzer.c:87
DetectEnginePktInspectionEngine::mpm
bool mpm
Definition: detect.h:488
DETECT_BYTEJUMP_BEGIN
#define DETECT_BYTEJUMP_BEGIN
Definition: detect-bytejump.h:34
DETECT_PCRE_RELATIVE
#define DETECT_PCRE_RELATIVE
Definition: detect-pcre.h:29
RuleAnalyzer
struct RuleAnalyzer RuleAnalyzer
SIG_FLAG_TLSSTORE
#define SIG_FLAG_TLSSTORE
Definition: detect.h:270
DetectU16Data
DetectUintData_u16 DetectU16Data
Definition: detect-engine-uint.h:42
Signature_::msg
char * msg
Definition: detect.h:659
DETECT_CONTENT_FAST_PATTERN
#define DETECT_CONTENT_FAST_PATTERN
Definition: detect-content.h:34
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
DETECT_FLAGS
@ DETECT_FLAGS
Definition: detect-engine-register.h:42
DETECT_PCRE_NEGATE
#define DETECT_PCRE_NEGATE
Definition: detect-pcre.h:35
EngineAnalysisCtx_::exposed_item_seen_list
struct ExposedItemSeen exposed_item_seen_list[2]
Definition: detect-engine-analyzer.c:105
Signature_::type
enum SignatureType type
Definition: detect.h:604
FpPatternStats_
Definition: detect-engine-analyzer.c:68
DetectBytetestData_::base
uint8_t base
Definition: detect-bytetest.h:56
DETECT_BYTETEST_LITTLE
#define DETECT_BYTETEST_LITTLE
Definition: detect-bytetest.h:43
SCMutex
#define SCMutex
Definition: threads-debug.h:114
SIG_TYPE_PDONLY
@ SIG_TYPE_PDONLY
Definition: detect.h:68
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
SIG_FLAG_PREFILTER
#define SIG_FLAG_PREFILTER
Definition: detect.h:274
DETECT_TCPMSS
@ DETECT_TCPMSS
Definition: detect-engine-register.h:291
DetectAckData_
ack data
Definition: detect-tcp-ack.h:30
SIG_FLAG_FILESTORE
#define SIG_FLAG_FILESTORE
Definition: detect.h:265
DETECT_CONTENT_WITHIN
#define DETECT_CONTENT_WITHIN
Definition: detect-content.h:31
DETECT_BYTEJUMP_RELATIVE
#define DETECT_BYTEJUMP_RELATIVE
Definition: detect-bytejump.h:38
SIG_FLAG_DP_ANY
#define SIG_FLAG_DP_ANY
Definition: detect.h:241
DETECT_FLOWBITS_CMD_SET
#define DETECT_FLOWBITS_CMD_SET
Definition: detect-flowbits.h:28
SIG_FLAG_DSIZE
#define SIG_FLAG_DSIZE
Definition: detect.h:245
DetectBytejumpData_::flags
uint16_t flags
Definition: detect-bytejump.h:49
Signature_::mask
SignatureMask mask
Definition: detect.h:612
SIG_TYPE_LIKE_IPONLY
@ SIG_TYPE_LIKE_IPONLY
Definition: detect.h:65
detect-bytetest.h
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:250
DetectEngineFrameInspectionEngine::smd
SigMatchData * smd
Definition: detect.h:523
ConfNodeLookupChildValue
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition: conf.c:809