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