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