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-ttl.h"
45 #include "detect-tcp-flags.h"
46 #include "detect-tcp-ack.h"
47 #include "detect-ipopts.h"
48 #include "detect-tcp-seq.h"
49 #include "feature.h"
50 #include "util-print.h"
51 #include "util-time.h"
52 #include "util-validate.h"
53 #include "util-conf.h"
54 #include "detect-flowbits.h"
55 #include "util-var-name.h"
56 #include "detect-icmp-id.h"
57 #include "detect-tcp-window.h"
58 
59 static int rule_warnings_only = 0;
60 
61 /* Details for each buffer being tracked */
62 typedef struct DetectEngineAnalyzerItems {
63  int16_t item_id;
64  bool item_seen;
67  const char *item_name;
68  const char *display_name;
70 
71 typedef struct FpPatternStats_ {
72  uint16_t min;
73  uint16_t max;
74  uint32_t cnt;
75  uint64_t tot;
77 
78 /* Track which items require the item_seen value to be exposed */
80  const char *bufname;
82 };
83 
84 typedef struct EngineAnalysisCtx_ {
85 
88 
90  char *file_prefix;
91  pcre2_code *percent_re;
92 
93  /*
94  * This array contains the map between the `analyzer_items` array listed above and
95  * the item ids returned by DetectBufferTypeGetByName. Iterating signature's sigmatch
96  * array provides list_ids. The map converts those ids into elements of the
97  * analyzer items array.
98  *
99  * Ultimately, the g_buffer_type_hash is searched for each buffer name. The size of that
100  * hashlist is 256, so that's the value we use here.
101  */
102  int16_t analyzer_item_map[256];
104  /*
105  * Certain values must be directly accessible. This array contains items that are directly
106  * accessed when checking if they've been seen or not.
107  */
109 
112 
114  /* request keywords */
115  { 0, false, false, true, "http_uri", "http uri" },
116  { 0, false, false, false, "http_raw_uri", "http raw uri" },
117  { 0, false, true, false, "http_method", "http method" },
118  { 0, false, false, false, "http_request_line", "http request line" },
119  { 0, false, false, false, "http_client_body", "http client body" },
120  { 0, false, false, true, "http_header", "http header" },
121  { 0, false, false, false, "http_raw_header", "http raw header" },
122  { 0, false, false, true, "http_cookie", "http cookie" },
123  { 0, false, false, false, "http_user_agent", "http user agent" },
124  { 0, false, false, false, "http_host", "http host" },
125  { 0, false, false, false, "http_raw_host", "http raw host" },
126  { 0, false, false, false, "http_accept_enc", "http accept enc" },
127  { 0, false, false, false, "http_referer", "http referer" },
128  { 0, false, false, false, "http_content_type", "http content type" },
129  { 0, false, false, false, "http_header_names", "http header names" },
130 
131  /* response keywords not listed above */
132  { 0, false, false, false, "http_stat_msg", "http stat msg" },
133  { 0, false, false, false, "http_stat_code", "http stat code" },
134  { 0, false, true, false, "file_data", "http server body" },
135 
136  /* missing request keywords */
137  { 0, false, false, false, "http_request_line", "http request line" },
138  { 0, false, false, false, "http_accept", "http accept" },
139  { 0, false, false, false, "http_accept_lang", "http accept lang" },
140  { 0, false, false, false, "http_connection", "http connection" },
141  { 0, false, false, false, "http_content_len", "http content len" },
142  { 0, false, false, false, "http_protocol", "http protocol" },
143  { 0, false, false, false, "http_start", "http start" },
144 
145  /* missing response keywords; some of the missing are listed above*/
146  { 0, false, false, false, "http_response_line", "http response line" },
147  { 0, false, false, false, "http.server", "http server" },
148  { 0, false, false, false, "http.location", "http location" },
149 };
150 
151 static void FpPatternStatsAdd(FpPatternStats *fp, int list, uint16_t patlen)
152 {
153  if (list < 0 || list >= DETECT_SM_LIST_MAX)
154  return;
155 
156  FpPatternStats *f = &fp[list];
157 
158  if (f->min == 0)
159  f->min = patlen;
160  else if (patlen < f->min)
161  f->min = patlen;
162 
163  if (patlen > f->max)
164  f->max = patlen;
165 
166  f->cnt++;
167  f->tot += patlen;
168 }
169 
170 void EngineAnalysisFP(const DetectEngineCtx *de_ctx, const Signature *s, const char *line)
171 {
172  int fast_pattern_set = 0;
173  int fast_pattern_only_set = 0;
174  int fast_pattern_chop_set = 0;
175  const DetectContentData *fp_cd = NULL;
176  const SigMatch *mpm_sm = s->init_data->mpm_sm;
177  const int mpm_sm_list = s->init_data->mpm_sm_list;
178 
179  if (mpm_sm != NULL) {
180  fp_cd = (DetectContentData *)mpm_sm->ctx;
181  if (fp_cd->flags & DETECT_CONTENT_FAST_PATTERN) {
182  fast_pattern_set = 1;
184  fast_pattern_only_set = 1;
185  } else if (fp_cd->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) {
186  fast_pattern_chop_set = 1;
187  }
188  }
189  }
190 
191  FILE *fp = de_ctx->ea->rule_engine_analysis_fp;
192  fprintf(fp, "== Sid: %u ==\n", s->id);
193  fprintf(fp, "%s\n", line);
194 
195  fprintf(fp, " Fast Pattern analysis:\n");
196  if (s->init_data->prefilter_sm != NULL) {
197  fprintf(fp, " Prefilter on: %s\n",
199  fprintf(fp, "\n");
200  return;
201  }
202 
203  if (fp_cd == NULL) {
204  fprintf(fp, " No content present\n");
205  fprintf(fp, "\n");
206  return;
207  }
208 
209  fprintf(fp, " Fast pattern matcher: ");
210  int list_type = mpm_sm_list;
211  if (list_type == DETECT_SM_LIST_PMATCH)
212  fprintf(fp, "content\n");
213  else {
214  const char *desc = DetectEngineBufferTypeGetDescriptionById(de_ctx, list_type);
215  const char *name = DetectEngineBufferTypeGetNameById(de_ctx, list_type);
216  if (desc && name) {
217  fprintf(fp, "%s (%s)\n", desc, name);
218  }
219  }
220 
221  int flags_set = 0;
222  fprintf(fp, " Flags:");
223  if (fp_cd->flags & DETECT_CONTENT_OFFSET) {
224  fprintf(fp, " Offset");
225  flags_set = 1;
226  } if (fp_cd->flags & DETECT_CONTENT_DEPTH) {
227  fprintf(fp, " Depth");
228  flags_set = 1;
229  }
230  if (fp_cd->flags & DETECT_CONTENT_WITHIN) {
231  fprintf(fp, " Within");
232  flags_set = 1;
233  }
234  if (fp_cd->flags & DETECT_CONTENT_DISTANCE) {
235  fprintf(fp, " Distance");
236  flags_set = 1;
237  }
238  if (fp_cd->flags & DETECT_CONTENT_NOCASE) {
239  fprintf(fp, " Nocase");
240  flags_set = 1;
241  }
242  if (fp_cd->flags & DETECT_CONTENT_NEGATED) {
243  fprintf(fp, " Negated");
244  flags_set = 1;
245  }
246  if (flags_set == 0)
247  fprintf(fp, " None");
248  fprintf(fp, "\n");
249 
250  fprintf(fp, " Fast pattern set: %s\n", fast_pattern_set ? "yes" : "no");
251  fprintf(fp, " Fast pattern only set: %s\n", fast_pattern_only_set ? "yes" : "no");
252  fprintf(fp, " Fast pattern chop set: %s\n", fast_pattern_chop_set ? "yes" : "no");
253  if (fast_pattern_chop_set) {
254  fprintf(fp, " Fast pattern offset, length: %u, %u\n", fp_cd->fp_chop_offset,
255  fp_cd->fp_chop_len);
256  }
257 
258  uint16_t patlen = fp_cd->content_len;
259  uint8_t *pat = SCMalloc(fp_cd->content_len + 1);
260  if (unlikely(pat == NULL)) {
261  FatalError("Error allocating memory");
262  }
263  memcpy(pat, fp_cd->content, fp_cd->content_len);
264  pat[fp_cd->content_len] = '\0';
265  fprintf(fp, " Original content: ");
266  PrintRawUriFp(fp, pat, patlen);
267  fprintf(fp, "\n");
268 
269  if (fast_pattern_chop_set) {
270  SCFree(pat);
271  patlen = fp_cd->fp_chop_len;
272  pat = SCMalloc(fp_cd->fp_chop_len + 1);
273  if (unlikely(pat == NULL)) {
274  exit(EXIT_FAILURE);
275  }
276  memcpy(pat, fp_cd->content + fp_cd->fp_chop_offset, fp_cd->fp_chop_len);
277  pat[fp_cd->fp_chop_len] = '\0';
278  fprintf(fp, " Final content: ");
279  PrintRawUriFp(fp, pat, patlen);
280  fprintf(fp, "\n");
281 
282  FpPatternStatsAdd(&de_ctx->ea->fp_pattern_stats[0], list_type, patlen);
283  } else {
284  fprintf(fp, " Final content: ");
285  PrintRawUriFp(fp, pat, patlen);
286  fprintf(fp, "\n");
287 
288  FpPatternStatsAdd(&de_ctx->ea->fp_pattern_stats[0], list_type, patlen);
289  }
290  SCFree(pat);
291 
292  fprintf(fp, "\n");
293 }
294 
295 /**
296  * \brief Sets up the fast pattern analyzer according to the config.
297  *
298  * \retval 1 If rule analyzer successfully enabled.
299  * \retval 0 If not enabled.
300  */
301 static int SetupFPAnalyzer(DetectEngineCtx *de_ctx)
302 {
303  int fp_engine_analysis_set = 0;
304 
305  if ((SCConfGetBool("engine-analysis.rules-fast-pattern", &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 = SCConfigGetLogDirectory();
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  SCConfNode *conf = SCConfGetNode("engine-analysis");
383  int enabled = 0;
384  if (conf != NULL) {
385  const char *value = SCConfNodeLookupChildValue(conf, "rules");
386  if (value && SCConfValIsTrue(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 = SCConfigGetLogDirectory();
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  size_t cfg_prefix_len = strlen(de_ctx->config_prefix);
487  if (cfg_prefix_len > 0) {
488  char prefix[sizeof(de_ctx->config_prefix) + 1];
489  snprintf(prefix, sizeof(prefix), "%s.", de_ctx->config_prefix);
490  ea->file_prefix = SCStrdup(prefix);
491  if (ea->file_prefix == NULL) {
492  FatalError("Unable to allocate per-engine analysis context name buffer");
493  }
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 
623  const DetectEngineCtx *de_ctx, const char *line, const char *file, int lineno)
624 {
627  if (tmp_fp) {
628  fprintf(tmp_fp, "== Sid: UNKNOWN ==\n");
629  fprintf(tmp_fp, "%s\n", line);
630  fprintf(tmp_fp, " FAILURE: invalid rule.\n");
631  fprintf(tmp_fp, " File: %s.\n", file);
632  fprintf(tmp_fp, " Line: %d.\n", lineno);
633  fprintf(tmp_fp, "\n");
634  }
635 }
636 
637 typedef struct RuleAnalyzer {
638  SCJsonBuilder *js; /* document root */
639 
640  SCJsonBuilder *js_warnings;
641  SCJsonBuilder *js_notes;
643 
644 static void ATTR_FMT_PRINTF(2, 3) AnalyzerNote(RuleAnalyzer *ctx, char *fmt, ...)
645 {
646  va_list ap;
647  char str[1024];
648 
649  va_start(ap, fmt);
650  vsnprintf(str, sizeof(str), fmt, ap);
651  va_end(ap);
652 
653  if (!ctx->js_notes)
654  ctx->js_notes = SCJbNewArray();
655  if (ctx->js_notes)
656  SCJbAppendString(ctx->js_notes, str);
657 }
658 
659 static void ATTR_FMT_PRINTF(2, 3) AnalyzerWarning(RuleAnalyzer *ctx, char *fmt, ...)
660 {
661  va_list ap;
662  char str[1024];
663 
664  va_start(ap, fmt);
665  vsnprintf(str, sizeof(str), fmt, ap);
666  va_end(ap);
667 
668  if (!ctx->js_warnings)
669  ctx->js_warnings = SCJbNewArray();
670  if (ctx->js_warnings)
671  SCJbAppendString(ctx->js_warnings, str);
672 }
673 
674 #define CHECK(pat) if (strlen((pat)) <= len && memcmp((pat), buf, MIN(len, strlen((pat)))) == 0) return true;
675 
676 static bool LooksLikeHTTPMethod(const uint8_t *buf, uint16_t len)
677 {
678  CHECK("GET /");
679  CHECK("POST /");
680  CHECK("HEAD /");
681  CHECK("PUT /");
682  return false;
683 }
684 
685 static bool LooksLikeHTTPUA(const uint8_t *buf, uint16_t len)
686 {
687  CHECK("User-Agent: ");
688  CHECK("\nUser-Agent: ");
689  return false;
690 }
691 
692 static void DumpContent(SCJsonBuilder *js, const DetectContentData *cd)
693 {
694  char pattern_str[1024] = "";
695  DetectContentPatternPrettyPrint(cd, pattern_str, sizeof(pattern_str));
696 
697  SCJbSetString(js, "pattern", pattern_str);
698  SCJbSetUint(js, "length", cd->content_len);
699  SCJbSetBool(js, "nocase", cd->flags & DETECT_CONTENT_NOCASE);
700  SCJbSetBool(js, "negated", cd->flags & DETECT_CONTENT_NEGATED);
701  SCJbSetBool(js, "starts_with", cd->flags & DETECT_CONTENT_STARTS_WITH);
702  SCJbSetBool(js, "ends_with", cd->flags & DETECT_CONTENT_ENDS_WITH);
703  SCJbSetBool(js, "is_mpm", cd->flags & DETECT_CONTENT_MPM);
704  SCJbSetBool(js, "no_double_inspect", cd->flags & DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED);
705  if (cd->flags & DETECT_CONTENT_OFFSET) {
706  SCJbSetUint(js, "offset", cd->offset);
707  }
708  if (cd->flags & DETECT_CONTENT_DEPTH) {
709  SCJbSetUint(js, "depth", cd->depth);
710  }
711  if (cd->flags & DETECT_CONTENT_DISTANCE) {
712  SCJbSetInt(js, "distance", cd->distance);
713  }
714  if (cd->flags & DETECT_CONTENT_WITHIN) {
715  SCJbSetInt(js, "within", cd->within);
716  }
717  SCJbSetBool(js, "fast_pattern", cd->flags & DETECT_CONTENT_FAST_PATTERN);
718  SCJbSetBool(js, "relative_next", cd->flags & DETECT_CONTENT_RELATIVE_NEXT);
719 }
720 
721 static void DumpPcre(SCJsonBuilder *js, const DetectPcreData *cd)
722 {
723  SCJbSetBool(js, "relative", cd->flags & DETECT_PCRE_RELATIVE);
724  SCJbSetBool(js, "relative_next", cd->flags & DETECT_PCRE_RELATIVE_NEXT);
725  SCJbSetBool(js, "nocase", cd->flags & DETECT_PCRE_CASELESS);
726  SCJbSetBool(js, "negated", cd->flags & DETECT_PCRE_NEGATE);
727 }
728 
729 static void DumpMatches(RuleAnalyzer *ctx, SCJsonBuilder *js, const SigMatchData *smd)
730 {
731  if (smd == NULL)
732  return;
733 
734  SCJbOpenArray(js, "matches");
735  do {
736  SCJbStartObject(js);
737  const char *mname = sigmatch_table[smd->type].name;
738  SCJbSetString(js, "name", mname);
739 
740  switch (smd->type) {
741  case DETECT_CONTENT: {
742  const DetectContentData *cd = (const DetectContentData *)smd->ctx;
743 
744  SCJbOpenObject(js, "content");
745  DumpContent(js, cd);
747  AnalyzerNote(ctx, (char *)"'fast_pattern:only' option is silently ignored and "
748  "is interpreted as regular 'fast_pattern'");
749  }
750  if (LooksLikeHTTPMethod(cd->content, cd->content_len)) {
751  AnalyzerNote(ctx,
752  (char *)"pattern looks like it inspects HTTP, use http.request_line or "
753  "http.method and http.uri instead for improved performance");
754  }
755  if (LooksLikeHTTPUA(cd->content, cd->content_len)) {
756  AnalyzerNote(ctx,
757  (char *)"pattern looks like it inspects HTTP, use http.user_agent "
758  "or http.header for improved performance");
759  }
761  AnalyzerNote(ctx, (char *)"'within' option for pattern w/o previous content "
762  "was converted to 'depth'");
763  }
765  AnalyzerNote(ctx, (char *)"'distance' option for pattern w/o previous content "
766  "was converted to 'offset'");
767  }
768  SCJbClose(js);
769  break;
770  }
771  case DETECT_PCRE: {
772  const DetectPcreData *cd = (const DetectPcreData *)smd->ctx;
773 
774  SCJbOpenObject(js, "pcre");
775  DumpPcre(js, cd);
776  SCJbClose(js);
777  if (cd->flags & DETECT_PCRE_RAWBYTES) {
778  AnalyzerNote(ctx,
779  (char *)"'/B' (rawbytes) option is a no-op and is silently ignored");
780  }
781  break;
782  }
783  case DETECT_BYTEJUMP: {
784  const DetectBytejumpData *cd = (const DetectBytejumpData *)smd->ctx;
785 
786  SCJbOpenObject(js, "byte_jump");
787  SCJbSetUint(js, "nbytes", cd->nbytes);
788  SCJbSetInt(js, "offset", cd->offset);
789  SCJbSetUint(js, "multiplier", cd->multiplier);
790  SCJbSetInt(js, "post_offset", cd->post_offset);
791  switch (cd->base) {
793  SCJbSetString(js, "base", "unset");
794  break;
796  SCJbSetString(js, "base", "oct");
797  break;
799  SCJbSetString(js, "base", "dec");
800  break;
802  SCJbSetString(js, "base", "hex");
803  break;
804  }
805  SCJbOpenArray(js, "flags");
806  if (cd->flags & DETECT_BYTEJUMP_BEGIN)
807  SCJbAppendString(js, "from_beginning");
808  if (cd->flags & DETECT_BYTEJUMP_LITTLE)
809  SCJbAppendString(js, "little_endian");
810  if (cd->flags & DETECT_BYTEJUMP_BIG)
811  SCJbAppendString(js, "big_endian");
812  if (cd->flags & DETECT_BYTEJUMP_STRING)
813  SCJbAppendString(js, "string");
815  SCJbAppendString(js, "relative");
816  if (cd->flags & DETECT_BYTEJUMP_ALIGN)
817  SCJbAppendString(js, "align");
818  if (cd->flags & DETECT_BYTEJUMP_DCE)
819  SCJbAppendString(js, "dce");
821  SCJbAppendString(js, "offset_be");
822  if (cd->flags & DETECT_BYTEJUMP_END)
823  SCJbAppendString(js, "from_end");
824  SCJbClose(js);
825  SCJbClose(js);
826  break;
827  }
828  case DETECT_BYTETEST: {
829  const DetectBytetestData *cd = (const DetectBytetestData *)smd->ctx;
830 
831  SCJbOpenObject(js, "byte_test");
832  SCJbSetUint(js, "nbytes", cd->nbytes);
833  SCJbSetInt(js, "offset", cd->offset);
834  switch (cd->base) {
836  SCJbSetString(js, "base", "unset");
837  break;
839  SCJbSetString(js, "base", "oct");
840  break;
842  SCJbSetString(js, "base", "dec");
843  break;
845  SCJbSetString(js, "base", "hex");
846  break;
847  }
848  SCJbOpenArray(js, "flags");
849  if (cd->flags & DETECT_BYTETEST_LITTLE)
850  SCJbAppendString(js, "little_endian");
851  if (cd->flags & DETECT_BYTETEST_BIG)
852  SCJbAppendString(js, "big_endian");
853  if (cd->flags & DETECT_BYTETEST_STRING)
854  SCJbAppendString(js, "string");
856  SCJbAppendString(js, "relative");
857  if (cd->flags & DETECT_BYTETEST_DCE)
858  SCJbAppendString(js, "dce");
859  SCJbClose(js);
860  SCJbClose(js);
861  break;
862  }
863  case DETECT_ABSENT: {
864  const DetectAbsentData *dad = (const DetectAbsentData *)smd->ctx;
865  SCJbOpenObject(js, "absent");
866  SCJbSetBool(js, "or_else", dad->or_else);
867  SCJbClose(js);
868  break;
869  }
870 
871  case DETECT_IPOPTS: {
872  const DetectIpOptsData *cd = (const DetectIpOptsData *)smd->ctx;
873 
874  SCJbOpenObject(js, "ipopts");
875  const char *flag = IpOptsFlagToString(cd->ipopt);
876  SCJbSetString(js, "option", flag);
877  SCJbClose(js);
878  break;
879  }
880  case DETECT_FLOWBITS: {
881  const DetectFlowbitsData *cd = (const DetectFlowbitsData *)smd->ctx;
882 
883  SCJbOpenObject(js, "flowbits");
884  switch (cd->cmd) {
886  SCJbSetString(js, "cmd", "isset");
887  break;
889  SCJbSetString(js, "cmd", "isnotset");
890  break;
892  SCJbSetString(js, "cmd", "set");
893  break;
895  SCJbSetString(js, "cmd", "unset");
896  break;
898  SCJbSetString(js, "cmd", "toggle");
899  break;
900  }
901  bool is_or = false;
902  SCJbOpenArray(js, "names");
903  if (cd->or_list_size == 0) {
904  SCJbAppendString(js, VarNameStoreSetupLookup(cd->idx, VAR_TYPE_FLOW_BIT));
905  } else if (cd->or_list_size > 0) {
906  is_or = true;
907  for (uint8_t i = 0; i < cd->or_list_size; i++) {
908  const char *varname =
910  SCJbAppendString(js, varname);
911  }
912  }
913  SCJbClose(js); // array
914  if (is_or) {
915  SCJbSetString(js, "operator", "or");
916  }
917  SCJbClose(js); // object
918  break;
919  }
920  case DETECT_ACK: {
921  const DetectU32Data *cd = (const DetectU32Data *)smd->ctx;
922  SCJbOpenObject(js, "ack");
923  SCDetectU32ToJson(js, cd);
924  SCJbClose(js);
925  break;
926  }
927  case DETECT_SEQ: {
928  const DetectU32Data *cd = (const DetectU32Data *)smd->ctx;
929  SCJbOpenObject(js, "seq");
930  SCDetectU32ToJson(js, cd);
931  SCJbClose(js);
932  break;
933  }
934  case DETECT_TCPMSS: {
935  const DetectU16Data *cd = (const DetectU16Data *)smd->ctx;
936  SCJbOpenObject(js, "tcp_mss");
937  SCDetectU16ToJson(js, cd);
938  SCJbClose(js);
939  break;
940  }
941  case DETECT_DSIZE: {
942  const DetectU16Data *cd = (const DetectU16Data *)smd->ctx;
943  SCJbOpenObject(js, "dsize");
944  SCDetectU16ToJson(js, cd);
945  SCJbClose(js);
946  break;
947  }
948  case DETECT_ICODE: {
949  const DetectU8Data *cd = (const DetectU8Data *)smd->ctx;
950  SCJbOpenObject(js, "code");
951  SCDetectU8ToJson(js, cd);
952  SCJbClose(js);
953  break;
954  }
955  case DETECT_TTL: {
956  const DetectU8Data *cd = (const DetectU8Data *)smd->ctx;
957  SCJbOpenObject(js, "ttl");
958  SCDetectU8ToJson(js, cd);
959  SCJbClose(js);
960  break;
961  }
962  case DETECT_ICMP_ID: {
963  const DetectU16Data *cd = (const DetectU16Data *)smd->ctx;
964  SCJbOpenObject(js, "id");
965  SCDetectU16ToJson(js, cd);
966  SCJbClose(js);
967  break;
968  }
969  case DETECT_WINDOW: {
970  const DetectU16Data *cd = (const DetectU16Data *)smd->ctx;
971  SCJbOpenObject(js, "window");
972  SCDetectU16ToJson(js, cd);
973  SCJbClose(js);
974  break;
975  }
976  case DETECT_FLOW_AGE: {
977  const DetectU32Data *cd = (const DetectU32Data *)smd->ctx;
978  SCJbOpenObject(js, "flow_age");
979  SCDetectU32ToJson(js, cd);
980  SCJbClose(js);
981  break;
982  }
983  }
984  SCJbClose(js);
985 
986  if (smd->is_last)
987  break;
988  smd++;
989  } while (1);
990  SCJbClose(js);
991 }
992 
995 {
996  SCEnter();
997 
998  RuleAnalyzer ctx = { NULL, NULL, NULL };
999 
1000  ctx.js = SCJbNewObject();
1001  if (ctx.js == NULL)
1002  SCReturn;
1003 
1004  if (s->init_data->firewall_rule) {
1005  JB_SET_STRING(ctx.js, "class", "firewall");
1006  } else {
1007  JB_SET_STRING(ctx.js, "class", "threat detection");
1008  }
1009 
1010  SCJbSetString(ctx.js, "raw", s->sig_str);
1011  SCJbSetUint(ctx.js, "id", s->id);
1012  SCJbSetUint(ctx.js, "gid", s->gid);
1013  SCJbSetUint(ctx.js, "rev", s->rev);
1014  SCJbSetString(ctx.js, "msg", s->msg);
1015 
1016  const char *alproto = AppProtoToString(s->alproto);
1017  SCJbSetString(ctx.js, "app_proto", alproto);
1018 
1019  SCJbOpenArray(ctx.js, "requirements");
1020  if (s->mask & SIG_MASK_REQUIRE_PAYLOAD) {
1021  SCJbAppendString(ctx.js, "payload");
1022  }
1023  if (s->mask & SIG_MASK_REQUIRE_NO_PAYLOAD) {
1024  SCJbAppendString(ctx.js, "no_payload");
1025  }
1026  if (s->mask & SIG_MASK_REQUIRE_FLOW) {
1027  SCJbAppendString(ctx.js, "flow");
1028  }
1030  SCJbAppendString(ctx.js, "tcp_flags_init_deinit");
1031  }
1033  SCJbAppendString(ctx.js, "tcp_flags_unusual");
1034  }
1036  SCJbAppendString(ctx.js, "engine_event");
1037  }
1038  if (s->mask & SIG_MASK_REQUIRE_REAL_PKT) {
1039  SCJbAppendString(ctx.js, "real_pkt");
1040  }
1041  SCJbClose(ctx.js);
1042 
1043  SCJbOpenObject(ctx.js, "match_policy");
1044  SCJbOpenArray(ctx.js, "actions");
1045  if (s->action & ACTION_ALERT) {
1046  SCJbAppendString(ctx.js, "alert");
1047  }
1048  if (s->action & ACTION_DROP) {
1049  SCJbAppendString(ctx.js, "drop");
1050  }
1051  if (s->action & ACTION_REJECT) {
1052  SCJbAppendString(ctx.js, "reject");
1053  }
1054  if (s->action & ACTION_REJECT_DST) {
1055  SCJbAppendString(ctx.js, "reject_dst");
1056  }
1057  if (s->action & ACTION_REJECT_BOTH) {
1058  SCJbAppendString(ctx.js, "reject_both");
1059  }
1060  if (s->action & ACTION_CONFIG) {
1061  SCJbAppendString(ctx.js, "config");
1062  }
1063  if (s->action & ACTION_PASS) {
1064  SCJbAppendString(ctx.js, "pass");
1065  }
1066  if (s->action & ACTION_ACCEPT) {
1067  SCJbAppendString(ctx.js, "accept");
1068  }
1069  SCJbClose(ctx.js);
1070 
1071  if (s->action_scope == ACTION_SCOPE_AUTO) {
1073  switch (flow_action) {
1075  SCJbSetString(ctx.js, "scope", "packet");
1076  break;
1078  SCJbSetString(ctx.js, "scope", "flow");
1079  break;
1081  SCJbSetString(ctx.js, "scope", "flow_if_stateful");
1082  break;
1083  }
1084  } else {
1085  enum ActionScope as = s->action_scope;
1086  switch (as) {
1087  case ACTION_SCOPE_PACKET:
1088  SCJbSetString(ctx.js, "scope", "packet");
1089  break;
1090  case ACTION_SCOPE_FLOW:
1091  SCJbSetString(ctx.js, "scope", "flow");
1092  break;
1093  case ACTION_SCOPE_HOOK:
1094  SCJbSetString(ctx.js, "scope", "hook");
1095  break;
1096  case ACTION_SCOPE_TX:
1097  SCJbSetString(ctx.js, "scope", "tx");
1098  break;
1099  case ACTION_SCOPE_AUTO: /* should be unreachable */
1100  break;
1101  }
1102  }
1103  SCJbClose(ctx.js);
1104 
1105  switch (s->type) {
1106  case SIG_TYPE_NOT_SET:
1107  SCJbSetString(ctx.js, "type", "unset");
1108  break;
1109  case SIG_TYPE_IPONLY:
1110  SCJbSetString(ctx.js, "type", "ip_only");
1111  break;
1112  case SIG_TYPE_LIKE_IPONLY:
1113  SCJbSetString(ctx.js, "type", "like_ip_only");
1114  break;
1115  case SIG_TYPE_PDONLY:
1116  SCJbSetString(ctx.js, "type", "pd_only");
1117  break;
1118  case SIG_TYPE_DEONLY:
1119  SCJbSetString(ctx.js, "type", "de_only");
1120  break;
1121  case SIG_TYPE_PKT:
1122  SCJbSetString(ctx.js, "type", "pkt");
1123  break;
1124  case SIG_TYPE_PKT_STREAM:
1125  SCJbSetString(ctx.js, "type", "pkt_stream");
1126  break;
1127  case SIG_TYPE_STREAM:
1128  SCJbSetString(ctx.js, "type", "stream");
1129  break;
1130  case SIG_TYPE_APPLAYER:
1131  SCJbSetString(ctx.js, "type", "app_layer");
1132  break;
1133  case SIG_TYPE_APP_TX:
1134  SCJbSetString(ctx.js, "type", "app_tx");
1135  break;
1136  case SIG_TYPE_MAX:
1137  SCJbSetString(ctx.js, "type", "error");
1138  break;
1139  }
1140 
1141  // dependencies object and its subfields only logged if we have values
1143  SCJbOpenObject(ctx.js, "dependencies");
1144  SCJbOpenObject(ctx.js, "flowbits");
1145  SCJbOpenObject(ctx.js, "upstream");
1147  SCJbOpenObject(ctx.js, "state_modifying_rules");
1148  SCJbOpenArray(ctx.js, "sids");
1149  for (uint32_t i = 0; i < s->init_data->rule_state_dependant_sids_idx; i++) {
1150  SCJbAppendUint(ctx.js, s->init_data->rule_state_dependant_sids_array[i]);
1151  }
1152  SCJbClose(ctx.js); // sids
1153  SCJbOpenArray(ctx.js, "names");
1154  for (uint32_t i = 0; i < s->init_data->rule_state_flowbits_ids_size - 1; i++) {
1155  if (s->init_data->rule_state_flowbits_ids_array[i] != 0) {
1156  SCJbAppendString(ctx.js,
1159  }
1160  }
1161  SCJbClose(ctx.js); // names
1162  SCJbClose(ctx.js); // state_modifying_rules
1163  }
1164  SCJbClose(ctx.js); // upstream
1165  SCJbClose(ctx.js); // flowbits
1166  SCJbClose(ctx.js); // dependencies
1167  }
1168 
1169  SCJbOpenArray(ctx.js, "flags");
1170  if (s->flags & SIG_FLAG_SRC_ANY) {
1171  SCJbAppendString(ctx.js, "src_any");
1172  }
1173  if (s->flags & SIG_FLAG_DST_ANY) {
1174  SCJbAppendString(ctx.js, "dst_any");
1175  }
1176  if (s->flags & SIG_FLAG_SP_ANY) {
1177  SCJbAppendString(ctx.js, "sp_any");
1178  }
1179  if (s->flags & SIG_FLAG_DP_ANY) {
1180  SCJbAppendString(ctx.js, "dp_any");
1181  }
1182  if ((s->action & ACTION_ALERT) == 0) {
1183  SCJbAppendString(ctx.js, "noalert");
1184  }
1185  if (s->flags & SIG_FLAG_DSIZE) {
1186  SCJbAppendString(ctx.js, "dsize");
1187  }
1188  if (s->flags & SIG_FLAG_APPLAYER) {
1189  SCJbAppendString(ctx.js, "applayer");
1190  }
1191  if (s->flags & SIG_FLAG_REQUIRE_PACKET) {
1192  SCJbAppendString(ctx.js, "need_packet");
1193  }
1194  if (s->flags & SIG_FLAG_REQUIRE_STREAM) {
1195  SCJbAppendString(ctx.js, "need_stream");
1196  }
1197  if (s->flags & SIG_FLAG_MPM_NEG) {
1198  SCJbAppendString(ctx.js, "negated_mpm");
1199  }
1200  if (s->flags & SIG_FLAG_FLUSH) {
1201  SCJbAppendString(ctx.js, "flush");
1202  }
1203  if (s->flags & SIG_FLAG_REQUIRE_FLOWVAR) {
1204  SCJbAppendString(ctx.js, "need_flowvar");
1205  }
1206  if (s->flags & SIG_FLAG_FILESTORE) {
1207  SCJbAppendString(ctx.js, "filestore");
1208  }
1209  if (s->flags & SIG_FLAG_TOSERVER) {
1210  SCJbAppendString(ctx.js, "toserver");
1211  }
1212  if (s->flags & SIG_FLAG_TOCLIENT) {
1213  SCJbAppendString(ctx.js, "toclient");
1214  }
1215  if (s->flags & SIG_FLAG_TLSSTORE) {
1216  SCJbAppendString(ctx.js, "tlsstore");
1217  }
1218  if (s->flags & SIG_FLAG_BYPASS) {
1219  SCJbAppendString(ctx.js, "bypass");
1220  }
1221  if (s->flags & SIG_FLAG_PREFILTER) {
1222  SCJbAppendString(ctx.js, "prefilter");
1223  }
1224  if (s->flags & SIG_FLAG_SRC_IS_TARGET) {
1225  SCJbAppendString(ctx.js, "src_is_target");
1226  }
1227  if (s->flags & SIG_FLAG_DEST_IS_TARGET) {
1228  SCJbAppendString(ctx.js, "dst_is_target");
1229  }
1230  SCJbClose(ctx.js);
1231 
1232  const DetectEnginePktInspectionEngine *pkt_mpm = NULL;
1233  const DetectEngineAppInspectionEngine *app_mpm = NULL;
1234 
1235  SCJbOpenArray(ctx.js, "pkt_engines");
1237  for ( ; pkt != NULL; pkt = pkt->next) {
1239  if (name == NULL) {
1240  switch (pkt->sm_list) {
1241  case DETECT_SM_LIST_PMATCH:
1242  name = "payload";
1243  break;
1244  case DETECT_SM_LIST_MATCH:
1245  name = "packet";
1246  break;
1247  default:
1248  name = "unknown";
1249  break;
1250  }
1251  }
1252  SCJbStartObject(ctx.js);
1253  SCJbSetString(ctx.js, "name", name);
1254  SCJbSetBool(ctx.js, "is_mpm", pkt->mpm);
1255  if (pkt->v1.transforms != NULL) {
1256  SCJbOpenArray(ctx.js, "transforms");
1257  for (int t = 0; t < pkt->v1.transforms->cnt; t++) {
1258  SCJbStartObject(ctx.js);
1259  SCJbSetString(ctx.js, "name",
1261  SCJbClose(ctx.js);
1262  }
1263  SCJbClose(ctx.js);
1264  }
1265  DumpMatches(&ctx, ctx.js, pkt->smd);
1266  SCJbClose(ctx.js);
1267  if (pkt->mpm) {
1268  pkt_mpm = pkt;
1269  }
1270  }
1271  SCJbClose(ctx.js);
1272  SCJbOpenArray(ctx.js, "frame_engines");
1274  for (; frame != NULL; frame = frame->next) {
1275  const char *name = DetectEngineBufferTypeGetNameById(de_ctx, frame->sm_list);
1276  SCJbStartObject(ctx.js);
1277  SCJbSetString(ctx.js, "name", name);
1278  SCJbSetBool(ctx.js, "is_mpm", frame->mpm);
1279  if (frame->v1.transforms != NULL) {
1280  SCJbOpenArray(ctx.js, "transforms");
1281  for (int t = 0; t < frame->v1.transforms->cnt; t++) {
1282  SCJbStartObject(ctx.js);
1283  SCJbSetString(ctx.js, "name",
1285  SCJbClose(ctx.js);
1286  }
1287  SCJbClose(ctx.js);
1288  }
1289  DumpMatches(&ctx, ctx.js, frame->smd);
1290  SCJbClose(ctx.js);
1291  }
1292  SCJbClose(ctx.js);
1293 
1295  bool has_stream = false;
1296  bool has_client_body_mpm = false;
1297  bool has_file_data_mpm = false;
1298 
1299  SCJbOpenArray(ctx.js, "engines");
1301  for ( ; app != NULL; app = app->next) {
1303  if (name == NULL) {
1304  switch (app->sm_list) {
1305  case DETECT_SM_LIST_PMATCH:
1306  name = "stream";
1307  break;
1308  default:
1309  name = "unknown";
1310  break;
1311  }
1312  }
1313 
1314  if (app->sm_list == DETECT_SM_LIST_PMATCH && !app->mpm) {
1315  has_stream = true;
1316  } else if (app->mpm && strcmp(name, "http_client_body") == 0) {
1317  has_client_body_mpm = true;
1318  } else if (app->mpm && strcmp(name, "file_data") == 0) {
1319  has_file_data_mpm = true;
1320  }
1321 
1322  SCJbStartObject(ctx.js);
1323  SCJbSetString(ctx.js, "name", name);
1324  const char *direction = app->dir == 0 ? "toserver" : "toclient";
1325  SCJbSetString(ctx.js, "direction", direction);
1326  SCJbSetBool(ctx.js, "is_mpm", app->mpm);
1327  SCJbSetString(ctx.js, "app_proto", AppProtoToString(app->alproto));
1328  SCJbSetUint(ctx.js, "progress", app->progress);
1329 
1330  if (app->v2.transforms != NULL) {
1331  SCJbOpenArray(ctx.js, "transforms");
1332  for (int t = 0; t < app->v2.transforms->cnt; t++) {
1333  SCJbStartObject(ctx.js);
1334  SCJbSetString(ctx.js, "name",
1336  SCJbClose(ctx.js);
1337  }
1338  SCJbClose(ctx.js);
1339  }
1340  DumpMatches(&ctx, ctx.js, app->smd);
1341  SCJbClose(ctx.js);
1342  if (app->mpm) {
1343  app_mpm = app;
1344  }
1345  }
1346  SCJbClose(ctx.js);
1347 
1348  if (has_stream && has_client_body_mpm)
1349  AnalyzerNote(&ctx, (char *)"mpm in http_client_body combined with stream match leads to stream buffering");
1350  if (has_stream && has_file_data_mpm)
1351  AnalyzerNote(&ctx, (char *)"mpm in file_data combined with stream match leads to stream buffering");
1352  }
1353 
1354  SCJbOpenObject(ctx.js, "lists");
1355  for (int i = 0; i < DETECT_SM_LIST_MAX; i++) {
1356  if (s->sm_arrays[i] != NULL) {
1357  SCJbOpenObject(ctx.js, DetectListToHumanString(i));
1358  DumpMatches(&ctx, ctx.js, s->sm_arrays[i]);
1359  SCJbClose(ctx.js);
1360  }
1361  }
1362  SCJbClose(ctx.js);
1363 
1364  if (pkt_mpm || app_mpm) {
1365  SCJbOpenObject(ctx.js, "mpm");
1366 
1367  int mpm_list = pkt_mpm ? DETECT_SM_LIST_PMATCH : app_mpm->sm_list;
1368  const char *name;
1369  if (mpm_list < DETECT_SM_LIST_DYNAMIC_START)
1370  name = DetectListToHumanString(mpm_list);
1371  else
1373  SCJbSetString(ctx.js, "buffer", name);
1374 
1375  SigMatchData *smd = pkt_mpm ? pkt_mpm->smd : app_mpm->smd;
1376  if (smd == NULL && mpm_list == DETECT_SM_LIST_PMATCH) {
1377  smd = s->sm_arrays[mpm_list];
1378  }
1379  do {
1380  switch (smd->type) {
1381  case DETECT_CONTENT: {
1382  const DetectContentData *cd = (const DetectContentData *)smd->ctx;
1383  if (cd->flags & DETECT_CONTENT_MPM) {
1384  DumpContent(ctx.js, cd);
1385  }
1386  break;
1387  }
1388  }
1389 
1390  if (smd->is_last)
1391  break;
1392  smd++;
1393  } while (1);
1394  SCJbClose(ctx.js);
1395  } else if (s->init_data->prefilter_sm) {
1396  SCJbOpenObject(ctx.js, "prefilter");
1397  int prefilter_list = SigMatchListSMBelongsTo(s, s->init_data->prefilter_sm);
1398  const char *name;
1399  if (prefilter_list < DETECT_SM_LIST_DYNAMIC_START)
1400  name = DetectListToHumanString(prefilter_list);
1401  else
1402  name = DetectEngineBufferTypeGetNameById(de_ctx, prefilter_list);
1403  SCJbSetString(ctx.js, "buffer", name);
1404  const char *mname = sigmatch_table[s->init_data->prefilter_sm->type].name;
1405  SCJbSetString(ctx.js, "name", mname);
1406  SCJbClose(ctx.js);
1407  }
1408 
1409  if (ctx.js_warnings) {
1410  SCJbClose(ctx.js_warnings);
1411  SCJbSetObject(ctx.js, "warnings", ctx.js_warnings);
1412  SCJbFree(ctx.js_warnings);
1413  ctx.js_warnings = NULL;
1414  }
1415  if (ctx.js_notes) {
1416  SCJbClose(ctx.js_notes);
1417  SCJbSetObject(ctx.js, "notes", ctx.js_notes);
1418  SCJbFree(ctx.js_notes);
1419  ctx.js_notes = NULL;
1420  }
1421  SCJbClose(ctx.js);
1422 
1423  const char *filename = "rules.json";
1424  const char *log_dir = SCConfigGetLogDirectory();
1425  char json_path[PATH_MAX] = "";
1426  snprintf(json_path, sizeof(json_path), "%s/%s%s", log_dir,
1427  de_ctx->ea->file_prefix ? de_ctx->ea->file_prefix : "", filename);
1428 
1430  FILE *fp = fopen(json_path, "a");
1431  if (fp != NULL) {
1432  fwrite(SCJbPtr(ctx.js), SCJbLen(ctx.js), 1, fp);
1433  fprintf(fp, "\n");
1434  fclose(fp);
1435  }
1437  SCJbFree(ctx.js);
1438  SCReturn;
1439 }
1440 
1442 {
1443  if (de_ctx->pattern_hash_table == NULL)
1444  return;
1445 
1446  SCJsonBuilder *root_jb = SCJbNewObject();
1447  SCJsonBuilder *arrays[de_ctx->buffer_type_id];
1448  memset(&arrays, 0, sizeof(SCJsonBuilder *) * de_ctx->buffer_type_id);
1449 
1450  SCJbOpenArray(root_jb, "buffers");
1451 
1453  htb != NULL; htb = HashListTableGetListNext(htb)) {
1454  char str[1024] = "";
1456  DetectContentPatternPrettyPrint(p->cd, str, sizeof(str));
1457 
1458  SCJsonBuilder *jb = arrays[p->sm_list];
1459  if (arrays[p->sm_list] == NULL) {
1460  jb = arrays[p->sm_list] = SCJbNewObject();
1461  const char *name;
1464  else
1466  SCJbSetString(jb, "name", name);
1467  SCJbSetUint(jb, "list_id", p->sm_list);
1468 
1469  SCJbOpenArray(jb, "patterns");
1470  }
1471 
1472  SCJbStartObject(jb);
1473  SCJbSetString(jb, "pattern", str);
1474  SCJbSetUint(jb, "patlen", p->cd->content_len);
1475  SCJbSetUint(jb, "cnt", p->cnt);
1476  SCJbSetUint(jb, "mpm", p->mpm);
1477  SCJbOpenObject(jb, "flags");
1478  SCJbSetBool(jb, "nocase", p->cd->flags & DETECT_CONTENT_NOCASE);
1479  SCJbSetBool(jb, "negated", p->cd->flags & DETECT_CONTENT_NEGATED);
1480  SCJbSetBool(jb, "depth", p->cd->flags & DETECT_CONTENT_DEPTH);
1481  SCJbSetBool(jb, "offset", p->cd->flags & DETECT_CONTENT_OFFSET);
1482  SCJbSetBool(jb, "endswith", p->cd->flags & DETECT_CONTENT_ENDS_WITH);
1483  SCJbClose(jb);
1484  SCJbClose(jb);
1485  }
1486 
1487  for (uint32_t i = 0; i < de_ctx->buffer_type_id; i++) {
1488  SCJsonBuilder *jb = arrays[i];
1489  if (jb == NULL)
1490  continue;
1491 
1492  SCJbClose(jb); // array
1493  SCJbClose(jb); // object
1494 
1495  SCJbAppendObject(root_jb, jb);
1496  SCJbFree(jb);
1497  }
1498  SCJbClose(root_jb);
1499  SCJbClose(root_jb);
1500 
1501  const char *filename = "patterns.json";
1502  const char *log_dir = SCConfigGetLogDirectory();
1503  char json_path[PATH_MAX] = "";
1504  snprintf(json_path, sizeof(json_path), "%s/%s%s", log_dir,
1505  de_ctx->ea->file_prefix ? de_ctx->ea->file_prefix : "", filename);
1506 
1508  FILE *fp = fopen(json_path, "a");
1509  if (fp != NULL) {
1510  fwrite(SCJbPtr(root_jb), SCJbLen(root_jb), 1, fp);
1511  fprintf(fp, "\n");
1512  fclose(fp);
1513  }
1515  SCJbFree(root_jb);
1516 
1518  de_ctx->pattern_hash_table = NULL;
1519 }
1520 
1521 static void EngineAnalysisItemsReset(EngineAnalysisCtx *ea_ctx)
1522 {
1523  for (size_t i = 0; i < ARRAY_SIZE(analyzer_items); i++) {
1524  ea_ctx->analyzer_items[i].item_seen = false;
1525  }
1526 }
1527 
1528 static void EngineAnalysisItemsInit(EngineAnalysisCtx *ea_ctx)
1529 {
1530  if (ea_ctx->analyzer_initialized) {
1531  EngineAnalysisItemsReset(ea_ctx);
1532  return;
1533  }
1534 
1535  ea_ctx->exposed_item_seen_list[0].bufname = "http_method";
1536  ea_ctx->exposed_item_seen_list[1].bufname = "file_data";
1537  ea_ctx->analyzer_items = SCCalloc(1, sizeof(analyzer_items));
1538  if (!ea_ctx->analyzer_items) {
1539  FatalError("Unable to allocate analysis scratch pad");
1540  }
1541  memset(ea_ctx->analyzer_item_map, -1, sizeof(ea_ctx->analyzer_item_map));
1542 
1543  for (size_t i = 0; i < ARRAY_SIZE(analyzer_items); i++) {
1544  ea_ctx->analyzer_items[i] = analyzer_items[i];
1545  DetectEngineAnalyzerItems *analyzer_item = &ea_ctx->analyzer_items[i];
1546 
1547  int item_id = DetectBufferTypeGetByName(analyzer_item->item_name);
1548  DEBUG_VALIDATE_BUG_ON(item_id < 0 || item_id > UINT16_MAX);
1549  analyzer_item->item_id = (uint16_t)item_id;
1550  if (analyzer_item->item_id == -1) {
1551  /* Mismatch between the analyzer_items array and what's supported */
1552  FatalError("unable to initialize engine-analysis table: detect buffer \"%s\" not "
1553  "recognized.",
1554  analyzer_item->item_name);
1555  }
1556  analyzer_item->item_seen = false;
1557 
1558  if (analyzer_item->export_item_seen) {
1559  for (size_t k = 0; k < ARRAY_SIZE(ea_ctx->exposed_item_seen_list); k++) {
1560  if (0 ==
1561  strcmp(ea_ctx->exposed_item_seen_list[k].bufname, analyzer_item->item_name))
1562  ea_ctx->exposed_item_seen_list[k].item_seen_ptr = &analyzer_item->item_seen;
1563  }
1564  }
1565  ea_ctx->analyzer_item_map[analyzer_item->item_id] = (int16_t)i;
1566  }
1567 
1568  ea_ctx->analyzer_initialized = true;
1569 }
1570 
1571 /**
1572  * \brief Prints analysis of loaded rules.
1573  *
1574  * Warns if potential rule issues are detected. For example,
1575  * warns if a rule uses a construct that may perform poorly,
1576  * e.g. pcre without content or with http_method content only;
1577  * warns if a rule uses a construct that may not be consistent with intent,
1578  * e.g. client side ports only, http and content without any http_* modifiers, etc.
1579  *
1580  * \param s Pointer to the signature.
1581  */
1583  const Signature *s, const char *line)
1584 {
1585  uint32_t rule_bidirectional = 0;
1586  uint32_t rule_pcre = 0;
1587  uint32_t rule_pcre_http = 0;
1588  uint32_t rule_content = 0;
1589  uint32_t rule_flow = 0;
1590  uint32_t rule_flags = 0;
1591  uint32_t rule_flow_toserver = 0;
1592  uint32_t rule_flow_toclient = 0;
1593  uint32_t rule_flow_nostream = 0;
1594  uint32_t rule_ipv4_only = 0;
1595  uint32_t rule_ipv6_only = 0;
1596  uint32_t rule_flowbits = 0;
1597  uint32_t rule_flowint = 0;
1598  uint32_t rule_content_http = 0;
1599  uint32_t rule_content_offset_depth = 0;
1600  int32_t list_id = 0;
1601  uint32_t rule_warning = 0;
1602  uint32_t stream_buf = 0;
1603  uint32_t packet_buf = 0;
1604  uint32_t file_store = 0;
1605  uint32_t warn_pcre_no_content = 0;
1606  uint32_t warn_pcre_http_content = 0;
1607  uint32_t warn_pcre_http = 0;
1608  uint32_t warn_content_http_content = 0;
1609  uint32_t warn_content_http = 0;
1610  uint32_t warn_tcp_no_flow = 0;
1611  uint32_t warn_client_ports = 0;
1612  uint32_t warn_direction = 0;
1613  uint32_t warn_method_toclient = 0;
1614  uint32_t warn_method_serverbody = 0;
1615  uint32_t warn_pcre_method = 0;
1616  uint32_t warn_encoding_norm_http_buf = 0;
1617  uint32_t warn_file_store_not_present = 0;
1618  uint32_t warn_offset_depth_pkt_stream = 0;
1619  uint32_t warn_offset_depth_alproto = 0;
1620  uint32_t warn_non_alproto_fp_for_alproto_sig = 0;
1621  uint32_t warn_no_direction = 0;
1622  uint32_t warn_both_direction = 0;
1623 
1624  EngineAnalysisItemsInit(de_ctx->ea);
1625 
1626  bool *http_method_item_seen_ptr = de_ctx->ea->exposed_item_seen_list[0].item_seen_ptr;
1627  bool *http_server_body_item_seen_ptr = de_ctx->ea->exposed_item_seen_list[1].item_seen_ptr;
1628 
1630  rule_bidirectional = 1;
1631  }
1632 
1633  if (s->flags & SIG_FLAG_REQUIRE_PACKET) {
1634  packet_buf += 1;
1635  }
1636  if (s->flags & SIG_FLAG_FILESTORE) {
1637  file_store += 1;
1638  }
1639  if (s->flags & SIG_FLAG_REQUIRE_STREAM) {
1640  stream_buf += 1;
1641  }
1642 
1643  if (s->proto.flags & DETECT_PROTO_IPV4) {
1644  rule_ipv4_only += 1;
1645  }
1646  if (s->proto.flags & DETECT_PROTO_IPV6) {
1647  rule_ipv6_only += 1;
1648  }
1649 
1650  for (list_id = 0; list_id < DETECT_SM_LIST_MAX; list_id++) {
1651  SigMatch *sm = NULL;
1652  for (sm = s->init_data->smlists[list_id]; sm != NULL; sm = sm->next) {
1653  int16_t item_slot = de_ctx->ea->analyzer_item_map[list_id];
1654  if (sm->type == DETECT_PCRE) {
1655  if (item_slot == -1) {
1656  rule_pcre++;
1657  continue;
1658  }
1659 
1660  rule_pcre_http++;
1661  de_ctx->ea->analyzer_items[item_slot].item_seen = true;
1662  } else if (sm->type == DETECT_CONTENT) {
1663  if (item_slot == -1) {
1664  rule_content++;
1665  if (list_id == DETECT_SM_LIST_PMATCH) {
1668  rule_content_offset_depth++;
1669  }
1670  }
1671  continue;
1672  }
1673 
1674  rule_content_http++;
1675  de_ctx->ea->analyzer_items[item_slot].item_seen = true;
1676 
1677  if (de_ctx->ea->analyzer_items[item_slot].check_encoding_match) {
1679  if (cd != NULL &&
1680  PerCentEncodingMatch(de_ctx->ea, cd->content, cd->content_len) > 0) {
1681  warn_encoding_norm_http_buf += 1;
1682  }
1683  }
1684  }
1685  else if (sm->type == DETECT_FLOW) {
1686  rule_flow += 1;
1687  if ((s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_TOCLIENT)) {
1688  rule_flow_toserver = 1;
1689  }
1690  else if ((s->flags & SIG_FLAG_TOCLIENT) && !(s->flags & SIG_FLAG_TOSERVER)) {
1691  rule_flow_toclient = 1;
1692  }
1693  DetectFlowData *fd = (DetectFlowData *)sm->ctx;
1694  if (fd != NULL) {
1695  if (fd->flags & DETECT_FLOW_FLAG_NOSTREAM)
1696  rule_flow_nostream = 1;
1697  }
1698  }
1699  else if (sm->type == DETECT_FLOWBITS) {
1700  if (list_id == DETECT_SM_LIST_MATCH) {
1701  rule_flowbits += 1;
1702  }
1703  }
1704  else if (sm->type == DETECT_FLOWINT) {
1705  if (list_id == DETECT_SM_LIST_MATCH) {
1706  rule_flowint += 1;
1707  }
1708  }
1709  else if (sm->type == DETECT_FLAGS) {
1710  if (sm->ctx != NULL) {
1711  rule_flags = 1;
1712  }
1713  }
1714  } /* for (sm = s->init_data->smlists[list_id]; sm != NULL; sm = sm->next) */
1715 
1716  } /* for ( ; list_id < DETECT_SM_LIST_MAX; list_id++) */
1717 
1718  if (file_store && !RequiresFeature("output::file-store")) {
1719  rule_warning += 1;
1720  warn_file_store_not_present = 1;
1721  }
1722 
1723  if (rule_pcre > 0 && rule_content == 0 && rule_content_http == 0) {
1724  rule_warning += 1;
1725  warn_pcre_no_content = 1;
1726  }
1727 
1728  if (rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0) {
1729  rule_warning += 1;
1730  warn_pcre_http_content = 1;
1731  } else if (s->alproto == ALPROTO_HTTP1 && rule_pcre > 0 && rule_pcre_http == 0) {
1732  rule_warning += 1;
1733  warn_pcre_http = 1;
1734  }
1735 
1736  if (rule_content > 0 && rule_content_http > 0) {
1737  rule_warning += 1;
1738  warn_content_http_content = 1;
1739  }
1740  if (s->alproto == ALPROTO_HTTP1 && rule_content > 0 && rule_content_http == 0) {
1741  rule_warning += 1;
1742  warn_content_http = 1;
1743  }
1744  if (rule_content == 1) {
1745  //todo: warning if content is weak, separate warning for pcre + weak content
1746  }
1747  if (rule_flow == 0 && rule_flags == 0 && !(s->proto.flags & DETECT_PROTO_ANY) &&
1748  DetectProtoContainsProto(&s->proto, IPPROTO_TCP) &&
1749  (rule_content || rule_content_http || rule_pcre || rule_pcre_http || rule_flowbits ||
1750  rule_flowint)) {
1751  rule_warning += 1;
1752  warn_tcp_no_flow = 1;
1753  }
1754  if (rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1755  && !((s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY))) {
1756  if (((s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY))
1757  || ((s->flags & SIG_FLAG_TOCLIENT) && !(s->flags & SIG_FLAG_DP_ANY) && (s->flags & SIG_FLAG_SP_ANY))) {
1758  rule_warning += 1;
1759  warn_client_ports = 1;
1760  }
1761  }
1762  if (rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)) {
1763  rule_warning += 1;
1764  warn_direction = 1;
1765  }
1766 
1767  if (*http_method_item_seen_ptr) {
1768  if (rule_flow && rule_flow_toclient) {
1769  rule_warning += 1;
1770  warn_method_toclient = 1;
1771  }
1772  if (*http_server_body_item_seen_ptr) {
1773  rule_warning += 1;
1774  warn_method_serverbody = 1;
1775  }
1776  if (rule_content == 0 && rule_content_http == 0 && (rule_pcre > 0 || rule_pcre_http > 0)) {
1777  rule_warning += 1;
1778  warn_pcre_method = 1;
1779  }
1780  }
1781  if (rule_content_offset_depth > 0 && stream_buf && packet_buf) {
1782  rule_warning += 1;
1783  warn_offset_depth_pkt_stream = 1;
1784  }
1785  if (rule_content_offset_depth > 0 && !stream_buf && packet_buf && s->alproto != ALPROTO_UNKNOWN) {
1786  rule_warning += 1;
1787  warn_offset_depth_alproto = 1;
1788  }
1789  if (s->init_data->mpm_sm != NULL && s->alproto == ALPROTO_HTTP1 &&
1791  rule_warning += 1;
1792  warn_non_alproto_fp_for_alproto_sig = 1;
1793  }
1794 
1795  if ((s->flags & (SIG_FLAG_TOSERVER|SIG_FLAG_TOCLIENT)) == 0) {
1796  warn_no_direction += 1;
1797  rule_warning += 1;
1798  }
1799 
1800  /* No warning about direction for ICMP protos */
1801  if (!(DetectProtoContainsProto(&s->proto, IPPROTO_ICMPV6) && DetectProtoContainsProto(&s->proto, IPPROTO_ICMP))) {
1803  warn_both_direction += 1;
1804  rule_warning += 1;
1805  }
1806  }
1807 
1808  if (!rule_warnings_only || (rule_warnings_only && rule_warning > 0)) {
1809  FILE *fp = de_ctx->ea->rule_engine_analysis_fp;
1810  fprintf(fp, "== Sid: %u ==\n", s->id);
1811  fprintf(fp, "%s\n", line);
1812 
1813  switch (s->type) {
1814  case SIG_TYPE_NOT_SET:
1815  break;
1816  case SIG_TYPE_IPONLY:
1817  fprintf(fp, " Rule is ip only.\n");
1818  break;
1819  case SIG_TYPE_LIKE_IPONLY:
1820  fprintf(fp, " Rule is like ip only.\n");
1821  break;
1822  case SIG_TYPE_PDONLY:
1823  fprintf(fp, " Rule is PD only.\n");
1824  break;
1825  case SIG_TYPE_DEONLY:
1826  fprintf(fp, " Rule is DE only.\n");
1827  break;
1828  case SIG_TYPE_PKT:
1829  fprintf(fp, " Rule is packet inspecting.\n");
1830  break;
1831  case SIG_TYPE_PKT_STREAM:
1832  fprintf(fp, " Rule is packet and stream inspecting.\n");
1833  break;
1834  case SIG_TYPE_STREAM:
1835  fprintf(fp, " Rule is stream inspecting.\n");
1836  break;
1837  case SIG_TYPE_APPLAYER:
1838  fprintf(fp, " Rule is app-layer inspecting.\n");
1839  break;
1840  case SIG_TYPE_APP_TX:
1841  fprintf(fp, " Rule is App-layer TX inspecting.\n");
1842  break;
1843  case SIG_TYPE_MAX:
1844  break;
1845  }
1846  if (rule_ipv6_only)
1847  fprintf(fp, " Rule is IPv6 only.\n");
1848  if (rule_ipv4_only)
1849  fprintf(fp, " Rule is IPv4 only.\n");
1850  if (packet_buf)
1851  fprintf(fp, " Rule matches on packets.\n");
1852  if (!rule_flow_nostream && stream_buf &&
1853  (rule_flow || rule_flowbits || rule_flowint || rule_content || rule_pcre)) {
1854  fprintf(fp, " Rule matches on reassembled stream.\n");
1855  }
1856  for(size_t i = 0; i < ARRAY_SIZE(analyzer_items); i++) {
1858  if (ai->item_seen) {
1859  fprintf(fp, " Rule matches on %s buffer.\n", ai->display_name);
1860  }
1861  }
1862  if (s->alproto != ALPROTO_UNKNOWN) {
1863  fprintf(fp, " App layer protocol is %s.\n", AppProtoToString(s->alproto));
1864  }
1865  if (rule_content || rule_content_http || rule_pcre || rule_pcre_http) {
1866  fprintf(fp,
1867  " Rule contains %u content options, %u http content options, %u pcre "
1868  "options, and %u pcre options with http modifiers.\n",
1869  rule_content, rule_content_http, rule_pcre, rule_pcre_http);
1870  }
1871 
1872  /* print fast pattern info */
1873  if (s->init_data->prefilter_sm) {
1874  fprintf(fp, " Prefilter on: %s.\n",
1876  } else {
1877  EngineAnalysisRulesPrintFP(de_ctx, s);
1878  }
1879 
1880  /* this is where the warnings start */
1881  if (warn_pcre_no_content /*rule_pcre > 0 && rule_content == 0 && rule_content_http == 0*/) {
1882  fprintf(fp, " Warning: Rule uses pcre without a content option present.\n"
1883  " -Consider adding a content to improve performance of this "
1884  "rule.\n");
1885  }
1886  if (warn_pcre_http_content /*rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0*/) {
1887  fprintf(fp, " Warning: Rule uses content options with http_* and pcre options "
1888  "without http modifiers.\n"
1889  " -Consider adding http pcre modifier.\n");
1890  }
1891  else if (warn_pcre_http /*s->alproto == ALPROTO_HTTP1 && rule_pcre > 0 && rule_pcre_http == 0*/) {
1892  fprintf(fp, " Warning: Rule app layer protocol is http, but pcre options do not "
1893  "have http modifiers.\n"
1894  " -Consider adding http pcre modifiers.\n");
1895  }
1896  if (warn_content_http_content /*rule_content > 0 && rule_content_http > 0*/) {
1897  fprintf(fp,
1898  " Warning: Rule contains content with http_* and content without http_*.\n"
1899  " -Consider adding http content modifiers.\n");
1900  }
1901  if (warn_content_http /*s->alproto == ALPROTO_HTTP1 && rule_content > 0 && rule_content_http == 0*/) {
1902  fprintf(fp, " Warning: Rule app layer protocol is http, but content options do not "
1903  "have http_* modifiers.\n"
1904  " -Consider adding http content modifiers.\n");
1905  }
1906  if (rule_content == 1) {
1907  //todo: warning if content is weak, separate warning for pcre + weak content
1908  }
1909  if (warn_encoding_norm_http_buf) {
1910  fprintf(fp, " Warning: Rule may contain percent encoded content for a normalized "
1911  "http buffer match.\n");
1912  }
1913  if (warn_tcp_no_flow /*rule_flow == 0 && rule_flags == 0
1914  && !(s->proto.flags & DETECT_PROTO_ANY) && DetectProtoContainsProto(&s->proto, IPPROTO_TCP)*/) {
1915  fprintf(fp, " Warning: TCP rule without a flow or flags option.\n"
1916  " -Consider adding flow or flags to improve performance of "
1917  "this rule.\n");
1918  }
1919  if (warn_client_ports /*rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1920  && !((s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY)))
1921  if (((s->flags & SIG_FLAG_TOSERVER) && !(s->flags & SIG_FLAG_SP_ANY) && (s->flags & SIG_FLAG_DP_ANY))
1922  || ((s->flags & SIG_FLAG_TOCLIENT) && !(s->flags & SIG_FLAG_DP_ANY) && (s->flags & SIG_FLAG_SP_ANY))*/) {
1923  fprintf(fp,
1924  " Warning: Rule contains ports or port variables only on the client side.\n"
1925  " -Flow direction possibly inconsistent with rule.\n");
1926  }
1927  if (warn_direction /*rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)*/) {
1928  fprintf(fp, " Warning: Rule is bidirectional and has a flow option with a specific "
1929  "direction.\n");
1930  }
1931  if (warn_method_toclient /*http_method_buf && rule_flow && rule_flow_toclient*/) {
1932  fprintf(fp, " Warning: Rule uses content or pcre for http_method with "
1933  "flow:to_client or from_server\n");
1934  }
1935  if (warn_method_serverbody /*http_method_buf && http_server_body_buf*/) {
1936  fprintf(fp, " Warning: Rule uses content or pcre for http_method with content or "
1937  "pcre for http_server_body.\n");
1938  }
1939  if (warn_pcre_method /*http_method_buf && rule_content == 0 && rule_content_http == 0
1940  && (rule_pcre > 0 || rule_pcre_http > 0)*/) {
1941  fprintf(fp, " Warning: Rule uses pcre with only a http_method content; possible "
1942  "performance issue.\n");
1943  }
1944  if (warn_offset_depth_pkt_stream) {
1945  fprintf(fp, " Warning: Rule has depth"
1946  "/offset with raw content keywords. Please note the "
1947  "offset/depth will be checked against both packet "
1948  "payloads and stream. If you meant to have the offset/"
1949  "depth checked against just the payload, you can update "
1950  "the signature as \"alert tcp-pkt...\"\n");
1951  }
1952  if (warn_offset_depth_alproto) {
1953  fprintf(fp,
1954  " Warning: Rule has "
1955  "offset/depth set along with a match on a specific "
1956  "app layer protocol - %d. This can lead to FNs if we "
1957  "have a offset/depth content match on a packet payload "
1958  "before we can detect the app layer protocol for the "
1959  "flow.\n",
1960  s->alproto);
1961  }
1962  if (warn_non_alproto_fp_for_alproto_sig) {
1963  fprintf(fp, " Warning: Rule app layer "
1964  "protocol is http, but the fast_pattern is set on the raw "
1965  "stream. Consider adding fast_pattern over a http "
1966  "buffer for increased performance.");
1967  }
1968  if (warn_no_direction) {
1969  fprintf(fp, " Warning: Rule has no direction indicator.\n");
1970  }
1971  if (warn_both_direction) {
1972  fprintf(fp, " Warning: Rule is inspecting both the request and the response.\n");
1973  }
1974  if (warn_file_store_not_present) {
1975  fprintf(fp, " Warning: Rule requires file-store but the output file-store is not "
1976  "enabled.\n");
1977  }
1978  if (rule_warning == 0) {
1979  fprintf(fp, " No warnings for this rule.\n");
1980  }
1981  fprintf(fp, "\n");
1982  }
1983 }
1984 
1985 #include "app-layer-parser.h"
1986 
1987 static void FirewallAddRulesForState(const DetectEngineCtx *de_ctx, const AppProto a,
1988  const uint8_t state, const uint8_t direction, RuleAnalyzer *ctx)
1989 {
1990  uint32_t accept_rules = 0;
1991  SCJbSetString(ctx->js, "policy", "drop:flow");
1992  SCJbOpenArray(ctx->js, "rules");
1993  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
1994  if ((s->flags & SIG_FLAG_FIREWALL) == 0)
1995  break;
1996  if (s->type != SIG_TYPE_APP_TX)
1997  continue;
1998  if (s->alproto != a)
1999  continue;
2000 
2001  if (direction == STREAM_TOSERVER) {
2002  if (s->flags & SIG_FLAG_TOCLIENT) {
2003  continue;
2004  }
2005  } else {
2006  if (s->flags & SIG_FLAG_TOSERVER) {
2007  continue;
2008  }
2009  }
2010 
2011  if (s->app_progress_hook == state) {
2012  SCJbAppendString(ctx->js, s->sig_str);
2013  accept_rules += ((s->action & ACTION_ACCEPT) != 0);
2014  }
2015  }
2016  SCJbClose(ctx->js);
2017 
2018  if (accept_rules == 0) {
2019  AnalyzerWarning(ctx, (char *)"no accept rules for state, default policy will be applied");
2020  }
2021 }
2022 
2024 {
2025  RuleAnalyzer ctx = { NULL, NULL, NULL };
2026  ctx.js = SCJbNewObject();
2027  if (ctx.js == NULL)
2028  return -1;
2029 
2030  SCJbOpenObject(ctx.js, "tables");
2031  SCJbOpenObject(ctx.js, "packet:filter");
2032  SCJbSetString(ctx.js, "policy", "drop:packet");
2033  SCJbOpenArray(ctx.js, "rules");
2034  uint32_t accept_rules = 0;
2035  uint32_t last_sid = 0;
2036  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
2037  if ((s->flags & SIG_FLAG_FIREWALL) == 0)
2038  break;
2039  if (s->type != SIG_TYPE_PKT)
2040  continue;
2041  /* don't double list <> sigs */
2042  if (last_sid == s->id)
2043  continue;
2044  last_sid = s->id;
2045  SCJbAppendString(ctx.js, s->sig_str);
2046  accept_rules += ((s->action & ACTION_ACCEPT) != 0);
2047  }
2048  SCJbClose(ctx.js);
2049  if (accept_rules == 0) {
2050  AnalyzerWarning(&ctx,
2051  (char *)"no accept rules for \'packet:filter\', default policy will be applied");
2052  }
2053  if (ctx.js_warnings) {
2054  SCJbClose(ctx.js_warnings);
2055  SCJbSetObject(ctx.js, "warnings", ctx.js_warnings);
2056  SCJbFree(ctx.js_warnings);
2057  ctx.js_warnings = NULL;
2058  }
2059  SCJbClose(ctx.js); // packet_filter
2060 
2061  for (AppProto a = 0; a < g_alproto_max; a++) {
2062  if (!AppProtoIsValid(a))
2063  continue;
2064 
2065  // HACK not all protocols have named states yet
2066  const char *hack = AppLayerParserGetStateNameById(IPPROTO_TCP, a, 0, STREAM_TOSERVER);
2067  if (!hack)
2068  continue;
2069 
2070  SCJbOpenObject(ctx.js, AppProtoToString(a));
2071  const uint8_t complete_state_ts =
2072  (const uint8_t)AppLayerParserGetStateProgressCompletionStatus(a, STREAM_TOSERVER);
2073  for (uint8_t state = 0; state < complete_state_ts; state++) {
2074  const char *name =
2075  AppLayerParserGetStateNameById(IPPROTO_TCP, a, state, STREAM_TOSERVER);
2076  char table_name[128];
2077  snprintf(table_name, sizeof(table_name), "app:%s:%s", AppProtoToString(a), name);
2078  SCJbOpenObject(ctx.js, table_name);
2079  FirewallAddRulesForState(de_ctx, a, state, STREAM_TOSERVER, &ctx);
2080  if (ctx.js_warnings) {
2081  SCJbClose(ctx.js_warnings);
2082  SCJbSetObject(ctx.js, "warnings", ctx.js_warnings);
2083  SCJbFree(ctx.js_warnings);
2084  ctx.js_warnings = NULL;
2085  }
2086  SCJbClose(ctx.js);
2087  }
2088  const uint8_t complete_state_tc =
2089  (const uint8_t)AppLayerParserGetStateProgressCompletionStatus(a, STREAM_TOCLIENT);
2090  for (uint8_t state = 0; state < complete_state_tc; state++) {
2091  const char *name =
2092  AppLayerParserGetStateNameById(IPPROTO_TCP, a, state, STREAM_TOCLIENT);
2093  char table_name[128];
2094  snprintf(table_name, sizeof(table_name), "app:%s:%s", AppProtoToString(a), name);
2095  SCJbOpenObject(ctx.js, table_name);
2096  FirewallAddRulesForState(de_ctx, a, state, STREAM_TOCLIENT, &ctx);
2097  if (ctx.js_warnings) {
2098  SCJbClose(ctx.js_warnings);
2099  SCJbSetObject(ctx.js, "warnings", ctx.js_warnings);
2100  SCJbFree(ctx.js_warnings);
2101  ctx.js_warnings = NULL;
2102  }
2103  SCJbClose(ctx.js);
2104  }
2105  SCJbClose(ctx.js); // app layer
2106  }
2107  SCJbOpenObject(ctx.js, "packet:td");
2108  SCJbSetString(ctx.js, "policy", "accept:hook");
2109  last_sid = 0;
2110  SCJbOpenArray(ctx.js, "rules");
2111  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
2112  if ((s->flags & SIG_FLAG_FIREWALL) != 0)
2113  continue;
2114  if (s->type == SIG_TYPE_APP_TX)
2115  continue;
2116  if (last_sid == s->id)
2117  continue;
2118  last_sid = s->id;
2119  SCJbAppendString(ctx.js, s->sig_str);
2120  }
2121  SCJbClose(ctx.js); // rules
2122  SCJbClose(ctx.js); // packet:td
2123  SCJbOpenObject(ctx.js, "app:td");
2124  SCJbSetString(ctx.js, "policy", "accept:hook");
2125  last_sid = 0;
2126  SCJbOpenArray(ctx.js, "rules");
2127  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
2128  if ((s->flags & SIG_FLAG_FIREWALL) != 0)
2129  continue;
2130  if (s->type != SIG_TYPE_APP_TX)
2131  continue;
2132  if (last_sid == s->id)
2133  continue;
2134  last_sid = s->id;
2135  SCJbAppendString(ctx.js, s->sig_str);
2136  }
2137  SCJbClose(ctx.js); // rules
2138  SCJbClose(ctx.js); // app:td
2139  SCJbClose(ctx.js); // tables
2140 
2141  SCJbOpenObject(ctx.js, "lists");
2142  SCJbOpenObject(ctx.js, "firewall");
2143  last_sid = 0;
2144  SCJbOpenArray(ctx.js, "rules");
2145  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
2146  if ((s->flags & SIG_FLAG_FIREWALL) == 0)
2147  continue;
2148  if (last_sid == s->id)
2149  continue;
2150  last_sid = s->id;
2151  SCJbAppendString(ctx.js, s->sig_str);
2152  }
2153  SCJbClose(ctx.js); // rules
2154  SCJbClose(ctx.js); // firewall
2155 
2156  SCJbOpenObject(ctx.js, "td");
2157  last_sid = 0;
2158  SCJbOpenArray(ctx.js, "rules");
2159  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
2160  if ((s->flags & SIG_FLAG_FIREWALL) != 0)
2161  continue;
2162  if (last_sid == s->id)
2163  continue;
2164  last_sid = s->id;
2165  SCJbAppendString(ctx.js, s->sig_str);
2166  }
2167  SCJbClose(ctx.js); // rules
2168  SCJbClose(ctx.js); // td
2169 
2170  SCJbOpenObject(ctx.js, "all");
2171  last_sid = 0;
2172  SCJbOpenArray(ctx.js, "rules");
2173  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
2174  if (last_sid == s->id)
2175  continue;
2176  last_sid = s->id;
2177  SCJbAppendString(ctx.js, s->sig_str);
2178  }
2179  SCJbClose(ctx.js); // rules
2180  SCJbClose(ctx.js); // all
2181 
2182  SCJbClose(ctx.js); // lists
2183 
2184  SCJbClose(ctx.js); // top level object
2185 
2186  const char *filename = "firewall.json";
2187  const char *log_dir = SCConfigGetLogDirectory();
2188  char json_path[PATH_MAX] = "";
2189  snprintf(json_path, sizeof(json_path), "%s/%s", log_dir, filename);
2190 
2192  FILE *fp = fopen(json_path, "w");
2193  if (fp != NULL) {
2194  fwrite(SCJbPtr(ctx.js), SCJbLen(ctx.js), 1, fp);
2195  fprintf(fp, "\n");
2196  fclose(fp);
2197  }
2199  SCJbFree(ctx.js);
2200  return 0;
2201 }
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:853
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:74
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:808
SignatureInitData_::rule_state_dependant_sids_idx
uint32_t rule_state_dependant_sids_idx
Definition: detect.h:659
DetectEngineAppInspectionEngine_
Definition: detect.h:416
DETECT_CONTENT_RELATIVE_NEXT
#define DETECT_CONTENT_RELATIVE_NEXT
Definition: detect-content.h:66
DetectEngineAppInspectionEngine_::mpm
bool mpm
Definition: detect.h:420
DETECT_TTL
@ DETECT_TTL
Definition: detect-engine-register.h:45
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
DetectEngineAppInspectionEngine_::v2
struct DetectEngineAppInspectionEngine_::@82 v2
SCConfValIsTrue
int SCConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:551
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:119
SIG_MASK_REQUIRE_REAL_PKT
#define SIG_MASK_REQUIRE_REAL_PKT
Definition: detect.h:316
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:642
DetectContentData_::fp_chop_len
uint16_t fp_chop_len
Definition: detect-content.h:98
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:79
Signature_::sig_str
char * sig_str
Definition: detect.h:745
SIG_TYPE_APP_TX
@ SIG_TYPE_APP_TX
Definition: detect.h:77
AppLayerParserGetStateNameById
const char * AppLayerParserGetStateNameById(uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
Definition: app-layer-parser.c:1603
DetectEnginePktInspectionEngine
Definition: detect.h:483
DetectEngineAppInspectionEngine_::next
struct DetectEngineAppInspectionEngine_ * next
Definition: detect.h:441
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:1457
DETECT_BYTEJUMP
@ DETECT_BYTEJUMP
Definition: detect-engine-register.h:83
DetectPatternTracker::mpm
uint32_t mpm
Definition: detect.h:812
DETECT_ABSENT
@ DETECT_ABSENT
Definition: detect-engine-register.h:95
DetectListToHumanString
const char * DetectListToHumanString(int list)
Definition: detect-parse.c:112
DetectEngineCtx_::pattern_hash_table
HashListTable * pattern_hash_table
Definition: detect.h:965
DumpPatterns
void DumpPatterns(DetectEngineCtx *de_ctx)
Definition: detect-engine-analyzer.c:1441
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
Signature_::app_progress_hook
uint8_t app_progress_hook
Definition: detect.h:705
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:69
SignatureInitData_::prefilter_sm
SigMatch * prefilter_sm
Definition: detect.h:625
EngineAnalysisCtx_::rule_engine_analysis_fp
FILE * rule_engine_analysis_fp
Definition: detect-engine-analyzer.c:86
DETECT_FLOW
@ DETECT_FLOW
Definition: detect-engine-register.h:54
Signature_::alproto
AppProto alproto
Definition: detect.h:673
SignatureInitData_::is_rule_state_dependant
bool is_rule_state_dependant
Definition: detect.h:656
detect-isdataat.h
DETECT_BYTETEST_BASE_HEX
#define DETECT_BYTETEST_BASE_HEX
Definition: detect-bytetest.h:40
SigMatchData_::is_last
bool is_last
Definition: detect.h:367
g_rules_analyzer_write_m
SCMutex g_rules_analyzer_write_m
Definition: detect-engine-analyzer.c:993
DetectEngineAnalyzerItems::display_name
const char * display_name
Definition: detect-engine-analyzer.c:68
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:86
DETECT_CONTENT_WITHIN2DEPTH
#define DETECT_CONTENT_WITHIN2DEPTH
Definition: detect-content.h:62
EngineAnalysisCtx_::percent_re
pcre2_code * percent_re
Definition: detect-engine-analyzer.c:91
DETECT_SM_LIST_DYNAMIC_START
@ DETECT_SM_LIST_DYNAMIC_START
Definition: detect.h:138
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:285
SigMatchData_::ctx
SigMatchCtx * ctx
Definition: detect.h:368
DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED
#define DETECT_CONTENT_NO_DOUBLE_INSPECTION_REQUIRED
Definition: detect-content.h:55
action-globals.h
EngineAnalysisCtx_
Definition: detect-engine-analyzer.c:84
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:41
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:518
DetectFlowData_::flags
uint16_t flags
Definition: detect-flow.h:38
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:932
DETECT_PROTO_ANY
#define DETECT_PROTO_ANY
Definition: detect-engine-proto.h:28
DetectEnginePktInspectionEngine::smd
SigMatchData * smd
Definition: detect.h:484
AppLayerParserGetStateProgressCompletionStatus
int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:1102
SIG_TYPE_PKT_STREAM
@ SIG_TYPE_PKT_STREAM
Definition: detect.h:73
DetectFlowbitsData_::cmd
uint8_t cmd
Definition: detect-flowbits.h:37
DetectEngineFrameInspectionEngine::mpm
bool mpm
Definition: detect.h:512
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:103
DetectEngineBufferTypeGetNameById
const char * DetectEngineBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1308
SIG_FLAG_DST_ANY
#define SIG_FLAG_DST_ANY
Definition: detect.h:242
ACTION_SCOPE_FLOW
@ ACTION_SCOPE_FLOW
Definition: action-globals.h:45
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:255
DetectPatternTracker::cnt
uint32_t cnt
Definition: detect.h:811
rust.h
EngineAnalysisCtx_::fp_engine_analysis_fp
FILE * fp_engine_analysis_fp
Definition: detect-engine-analyzer.c:87
SCConfGetBool
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
Definition: conf.c:497
EngineAnalysisCtx_::analyzer_initialized
bool analyzer_initialized
Definition: detect-engine-analyzer.c:110
DetectEngineAnalyzerItems
Definition: detect-engine-analyzer.c:62
DETECT_BYTEJUMP_DCE
#define DETECT_BYTEJUMP_DCE
Definition: detect-bytejump.h:40
DetectPatternTracker::cd
const struct DetectContentData_ * cd
Definition: detect.h:809
VarNameStoreSetupLookup
const char * VarNameStoreSetupLookup(const uint32_t id, const enum VarTypes type)
Definition: util-var-name.c:191
SCMUTEX_INITIALIZER
#define SCMUTEX_INITIALIZER
Definition: threads-debug.h:122
Signature_::sm_arrays
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
Definition: detect.h:731
FpPatternStats_::max
uint16_t max
Definition: detect-engine-analyzer.c:73
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:608
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:51
SCConfNodeLookupChildValue
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition: conf.c:824
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:102
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:272
DETECT_BYTEJUMP_BIG
#define DETECT_BYTEJUMP_BIG
Definition: detect-bytejump.h:36
SIG_FLAG_SRC_ANY
#define SIG_FLAG_SRC_ANY
Definition: detect.h:241
EngineAnalysisRulesFailure
void EngineAnalysisRulesFailure(const DetectEngineCtx *de_ctx, const char *line, const char *file, int lineno)
Definition: detect-engine-analyzer.c:622
SigMatchData_
Data needed for Match()
Definition: detect.h:365
DetectBytejumpData_::base
uint8_t base
Definition: detect-bytejump.h:48
detect-pcre.h
SIG_TYPE_APPLAYER
@ SIG_TYPE_APPLAYER
Definition: detect.h:76
SigMatchData_::type
uint16_t type
Definition: detect.h:366
DetectBytejumpData_
Definition: detect-bytejump.h:46
Signature_::frame_inspect
DetectEngineFrameInspectionEngine * frame_inspect
Definition: detect.h:727
DetectBytejumpData_::offset
int32_t offset
Definition: detect-bytejump.h:50
DetectEnginePktInspectionEngine::transforms
const DetectEngineTransforms * transforms
Definition: detect.h:492
EngineAnalysisCtx_::analyzer_items
DetectEngineAnalyzerItems * analyzer_items
Definition: detect-engine-analyzer.c:89
DETECT_PERCENT_ENCODING_REGEX
#define DETECT_PERCENT_ENCODING_REGEX
FirewallAnalyzer
int FirewallAnalyzer(const DetectEngineCtx *de_ctx)
Definition: detect-engine-analyzer.c:2023
DetectBytejumpData_::multiplier
uint16_t multiplier
Definition: detect-bytejump.h:52
SIG_FLAG_APPLAYER
#define SIG_FLAG_APPLAYER
Definition: detect.h:249
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1278
SIG_FLAG_FIREWALL
#define SIG_FLAG_FIREWALL
Definition: detect.h:246
Signature_::gid
uint32_t gid
Definition: detect.h:714
Signature_::next
struct Signature_ * next
Definition: detect.h:750
ACTION_REJECT_DST
#define ACTION_REJECT_DST
Definition: action-globals.h:32
DetectEngineAppInspectionEngine_::sm_list
uint16_t sm_list
Definition: detect.h:424
ATTR_FMT_PRINTF
#define ATTR_FMT_PRINTF(x, y)
Definition: suricata-common.h:427
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:65
SignaturePropertyFlowAction
SignaturePropertyFlowAction
Definition: detect.h:83
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:271
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:72
feature.h
RuleAnalyzer::js
SCJsonBuilder * js
Definition: detect-engine-analyzer.c:638
IpOptsFlagToString
const char * IpOptsFlagToString(uint16_t flag)
Return human readable value for ipopts flag.
Definition: detect-ipopts.c:117
JB_SET_STRING
#define JB_SET_STRING(jb, key, val)
Definition: rust.h:31
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:486
SIG_FLAG_INIT_BIDIREC
#define SIG_FLAG_INIT_BIDIREC
Definition: detect.h:293
g_alproto_max
AppProto g_alproto_max
Definition: app-layer-protos.c:30
DETECT_FLOWINT
@ DETECT_FLOWINT
Definition: detect-engine-register.h:62
SIG_MASK_REQUIRE_ENGINE_EVENT
#define SIG_MASK_REQUIRE_ENGINE_EVENT
Definition: detect.h:318
DETECT_ICODE
@ DETECT_ICODE
Definition: detect-engine-register.h:48
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:66
DETECT_BYTEJUMP_ALIGN
#define DETECT_BYTEJUMP_ALIGN
Definition: detect-bytejump.h:39
SignatureInitData_::mpm_sm
SigMatch * mpm_sm
Definition: detect.h:623
DetectEngineBufferTypeGetDescriptionById
const char * DetectEngineBufferTypeGetDescriptionById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1386
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:120
SIG_FLAG_FLUSH
#define SIG_FLAG_FLUSH
Definition: detect.h:259
DetectIpOptsData_::ipopt
uint16_t ipopt
Definition: detect-ipopts.h:38
SignatureInitData_::mpm_sm_list
int mpm_sm_list
Definition: detect.h:621
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:312
SIG_FLAG_BYPASS
#define SIG_FLAG_BYPASS
Definition: detect.h:276
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:637
DETECT_BYTEJUMP_END
#define DETECT_BYTEJUMP_END
Definition: detect-bytejump.h:42
Signature_::pkt_inspect
DetectEnginePktInspectionEngine * pkt_inspect
Definition: detect.h:726
DetectEngineAnalyzerItems
struct DetectEngineAnalyzerItems DetectEngineAnalyzerItems
util-print.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:281
detect-engine-mpm.h
detect.h
SIG_MASK_REQUIRE_FLAGS_INITDEINIT
#define SIG_MASK_REQUIRE_FLAGS_INITDEINIT
Definition: detect.h:313
SignatureInitData_::rule_state_flowbits_ids_size
uint32_t rule_state_flowbits_ids_size
Definition: detect.h:661
DetectEngineFrameInspectionEngine::sm_list
uint16_t sm_list
Definition: detect.h:513
detect-tcp-window.h
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:360
DetectEngineAnalyzerItems::item_seen
bool item_seen
Definition: detect-engine-analyzer.c:64
DETECT_CONTENT_NEGATED
#define DETECT_CONTENT_NEGATED
Definition: detect-content.h:40
DetectU8Data
DetectUintData_u8 DetectU8Data
Definition: detect-engine-uint.h:43
util-time.h
DETECT_ICMP_ID
@ DETECT_ICMP_ID
Definition: detect-engine-register.h:49
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:117
EngineAnalysisRules
void EngineAnalysisRules(const DetectEngineCtx *de_ctx, const Signature *s, const char *line)
Prints analysis of loaded rules.
Definition: detect-engine-analyzer.c:1582
app-layer-parser.h
Signature_::app_inspect
DetectEngineAppInspectionEngine * app_inspect
Definition: detect.h:725
DETECT_SEQ
@ DETECT_SEQ
Definition: detect-engine-register.h:37
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:359
DETECT_ACK
@ DETECT_ACK
Definition: detect-engine-register.h:36
RuleAnalyzer::js_warnings
SCJsonBuilder * js_warnings
Definition: detect-engine-analyzer.c:640
SIG_FLAG_REQUIRE_FLOWVAR
#define SIG_FLAG_REQUIRE_FLOWVAR
Definition: detect.h:267
Signature_::action
uint8_t action
Definition: detect.h:683
FpPatternStats_::cnt
uint32_t cnt
Definition: detect-engine-analyzer.c:74
SCReturn
#define SCReturn
Definition: util-debug.h:283
Signature_::flags
uint32_t flags
Definition: detect.h:669
DetectContentData_::depth
uint16_t depth
Definition: detect-content.h:106
DetectEngineFrameInspectionEngine::v1
struct DetectEngineFrameInspectionEngine::@86 v1
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
ACTION_SCOPE_TX
@ ACTION_SCOPE_TX
Definition: action-globals.h:47
SCConfigGetLogDirectory
const char * SCConfigGetLogDirectory(void)
Definition: util-conf.c:38
ACTION_SCOPE_AUTO
@ ACTION_SCOPE_AUTO
Definition: action-globals.h:43
conf.h
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:104
CHECK
#define CHECK(pat)
Definition: detect-engine-analyzer.c:674
DetectEngineFrameInspectionEngine
Definition: detect.h:508
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:1298
DETECT_BYTEJUMP_BASE_UNSET
#define DETECT_BYTEJUMP_BASE_UNSET
Definition: detect-bytejump.h:28
name
const char * name
Definition: tm-threads.c:2163
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:747
SIG_FLAG_SRC_IS_TARGET
#define SIG_FLAG_SRC_IS_TARGET
Definition: detect.h:283
SignatureInitData_::rule_state_dependant_sids_array
uint32_t * rule_state_dependant_sids_array
Definition: detect.h:657
DetectContentPatternPrettyPrint
void DetectContentPatternPrettyPrint(const DetectContentData *cd, char *str, size_t str_len)
Definition: detect-content.c:750
SignatureInitData_::rule_state_dependant_sids_size
uint32_t rule_state_dependant_sids_size
Definition: detect.h:658
DetectEngineTransforms::transforms
TransformData transforms[DETECT_TRANSFORMS_MAX]
Definition: detect.h:392
DETECT_BYTEJUMP_BASE_HEX
#define DETECT_BYTEJUMP_BASE_HEX
Definition: detect-bytejump.h:31
SIG_TYPE_DEONLY
@ SIG_TYPE_DEONLY
Definition: detect.h:71
SIG_PROP_FLOW_ACTION_PACKET
@ SIG_PROP_FLOW_ACTION_PACKET
Definition: detect.h:84
signature_properties
const struct SignatureProperties signature_properties[SIG_TYPE_MAX]
Definition: detect-engine.c:116
detect-flowbits.h
SIG_MASK_REQUIRE_PAYLOAD
#define SIG_MASK_REQUIRE_PAYLOAD
Definition: detect.h:311
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:229
DETECT_PCRE
@ DETECT_PCRE
Definition: detect-engine-register.h:71
DETECT_DSIZE
@ DETECT_DSIZE
Definition: detect-engine-register.h:52
SIG_TYPE_NOT_SET
@ SIG_TYPE_NOT_SET
Definition: detect.h:65
ExposedItemSeen::bufname
const char * bufname
Definition: detect-engine-analyzer.c:80
DETECT_BYTEJUMP_OFFSET_BE
#define DETECT_BYTEJUMP_OFFSET_BE
Definition: detect-bytejump.h:41
detect-ttl.h
DetectEngineCtx_::config_prefix
char config_prefix[64]
Definition: detect.h:1051
DetectSigmatchListEnumToString
const char * DetectSigmatchListEnumToString(enum DetectSigmatchListEnum type)
Definition: detect-engine.c:4987
analyzer_items
const DetectEngineAnalyzerItems analyzer_items[]
Definition: detect-engine-analyzer.c:113
DetectEngineAppInspectionEngine_::alproto
AppProto alproto
Definition: detect.h:417
SIG_FLAG_MPM_NEG
#define SIG_FLAG_MPM_NEG
Definition: detect.h:257
detect-engine-analyzer.h
SIG_FLAG_INIT_STATE_MATCH
#define SIG_FLAG_INIT_STATE_MATCH
Definition: detect.h:296
DetectEngineAnalyzerItems::item_id
int16_t item_id
Definition: detect-engine-analyzer.c:63
DetectPatternTracker::sm_list
int sm_list
Definition: detect.h:810
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:439
EngineAnalysisRules2
void EngineAnalysisRules2(const DetectEngineCtx *de_ctx, const Signature *s)
Definition: detect-engine-analyzer.c:994
ACTION_REJECT_BOTH
#define ACTION_REJECT_BOTH
Definition: action-globals.h:33
ARRAY_SIZE
#define ARRAY_SIZE(arr)
Definition: suricata-common.h:562
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:82
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:883
FpPatternStats_::min
uint16_t min
Definition: detect-engine-analyzer.c:72
VAR_TYPE_FLOW_BIT
@ VAR_TYPE_FLOW_BIT
Definition: util-var.h:36
Signature_::proto
DetectProto proto
Definition: detect.h:687
suricata-common.h
SIG_MASK_REQUIRE_NO_PAYLOAD
#define SIG_MASK_REQUIRE_NO_PAYLOAD
Definition: detect.h:315
DetectEnginePktInspectionEngine::v1
struct DetectEnginePktInspectionEngine::@85 v1
SIG_FLAG_SP_ANY
#define SIG_FLAG_SP_ANY
Definition: detect.h:243
SIG_PROP_FLOW_ACTION_FLOW_IF_STATEFUL
@ SIG_PROP_FLOW_ACTION_FLOW_IF_STATEFUL
Definition: detect.h:86
ActionScope
ActionScope
Definition: action-globals.h:42
DetectAbsentData_
Definition: detect-isdataat.h:37
ExposedItemSeen
Definition: detect-engine-analyzer.c:79
SigMatch_::type
uint16_t type
Definition: detect.h:357
HashListTableFree
void HashListTableFree(HashListTable *ht)
Definition: util-hashlist.c:88
DetectEngineAnalyzerItems::check_encoding_match
bool check_encoding_match
Definition: detect-engine-analyzer.c:66
DetectContentData_::distance
int32_t distance
Definition: detect-content.h:108
ACTION_SCOPE_HOOK
@ ACTION_SCOPE_HOOK
Definition: action-globals.h:46
CleanupEngineAnalysis
void CleanupEngineAnalysis(DetectEngineCtx *de_ctx)
Definition: detect-engine-analyzer.c:510
DetectBytejumpData_::nbytes
uint8_t nbytes
Definition: detect-bytejump.h:47
Signature_::action_scope
uint8_t action_scope
Definition: detect.h:690
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:36
DetectEngineFrameInspectionEngine::next
struct DetectEngineFrameInspectionEngine * next
Definition: detect.h:521
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:494
DetectContentData_::content
uint8_t * content
Definition: detect-content.h:94
Signature_::rev
uint32_t rev
Definition: detect.h:715
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
FatalError
#define FatalError(...)
Definition: util-debug.h:514
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:941
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:314
TransformData_::transform
int transform
Definition: detect.h:387
DETECT_FLOWBITS
@ DETECT_FLOWBITS
Definition: detect-engine-register.h:59
SIG_TYPE_MAX
@ SIG_TYPE_MAX
Definition: detect.h:79
DetectEngineCtx_::ea
struct EngineAnalysisCtx_ * ea
Definition: detect.h:1129
DetectEngineAppInspectionEngine_::progress
int16_t progress
Definition: detect.h:426
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:170
SignatureInitData_::firewall_rule
bool firewall_rule
Definition: detect.h:664
FpPatternStats
struct FpPatternStats_ FpPatternStats
detect-tcp-ack.h
str
#define str(s)
Definition: suricata-common.h:308
SCConfGetNode
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
Definition: conf.c:181
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:271
SigMatchListSMBelongsTo
int SigMatchListSMBelongsTo(const Signature *s, const SigMatch *key_sm)
Definition: detect-parse.c:763
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DetectFlowbitsData_::or_list
uint32_t * or_list
Definition: detect-flowbits.h:42
Signature_::id
uint32_t id
Definition: detect.h:713
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
ACTION_SCOPE_PACKET
@ ACTION_SCOPE_PACKET
Definition: action-globals.h:44
DetectBufferType_::transforms
DetectEngineTransforms transforms
Definition: detect.h:462
detect-parse.h
Signature_
Signature container.
Definition: detect.h:668
SigMatch_
a single match condition for a signature
Definition: detect.h:356
DetectEngineAppInspectionEngine_::transforms
const DetectEngineTransforms * transforms
Definition: detect.h:436
DETECT_SM_LIST_MAX
@ DETECT_SM_LIST_MAX
Definition: detect.h:135
FpPatternStats_::tot
uint64_t tot
Definition: detect-engine-analyzer.c:75
DETECT_BYTETEST_STRING
#define DETECT_BYTETEST_STRING
Definition: detect-bytetest.h:45
DetectBytetestData_::offset
int32_t offset
Definition: detect-bytetest.h:60
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
ACTION_ACCEPT
#define ACTION_ACCEPT
Definition: action-globals.h:36
detect-ipopts.h
DetectEngineTransforms::cnt
int cnt
Definition: detect.h:393
suricata.h
DetectPcreData_
Definition: detect-pcre.h:47
DetectEngineAppInspectionEngine_::dir
uint8_t dir
Definition: detect.h:418
DetectEngineAnalyzerItems::item_name
const char * item_name
Definition: detect-engine-analyzer.c:67
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:81
DETECT_BYTEJUMP_STRING
#define DETECT_BYTEJUMP_STRING
Definition: detect-bytejump.h:37
DetectEngineCtx_::buffer_type_id
uint32_t buffer_type_id
Definition: detect.h:1081
EngineAnalysisCtx_::file_prefix
char * file_prefix
Definition: detect-engine-analyzer.c:90
DetectEnginePktInspectionEngine::mpm
bool mpm
Definition: detect.h:485
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:660
SIG_PROP_FLOW_ACTION_FLOW
@ SIG_PROP_FLOW_ACTION_FLOW
Definition: detect.h:85
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:38
SIG_FLAG_TLSSTORE
#define SIG_FLAG_TLSSTORE
Definition: detect.h:274
DetectU16Data
DetectUintData_u16 DetectU16Data
Definition: detect-engine-uint.h:42
Signature_::msg
char * msg
Definition: detect.h:736
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
RuleAnalyzer::js_notes
SCJsonBuilder * js_notes
Definition: detect-engine-analyzer.c:641
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:108
Signature_::type
enum SignatureType type
Definition: detect.h:671
SCConfNode_
Definition: conf.h:37
FpPatternStats_
Definition: detect-engine-analyzer.c:71
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:70
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:278
SignatureProperties::flow_action
enum SignaturePropertyFlowAction flow_action
Definition: detect.h:90
DETECT_TCPMSS
@ DETECT_TCPMSS
Definition: detect-engine-register.h:289
SIG_FLAG_FILESTORE
#define SIG_FLAG_FILESTORE
Definition: detect.h:269
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:244
DETECT_FLOWBITS_CMD_SET
#define DETECT_FLOWBITS_CMD_SET
Definition: detect-flowbits.h:28
SIG_FLAG_DSIZE
#define SIG_FLAG_DSIZE
Definition: detect.h:248
DetectBytejumpData_::flags
uint16_t flags
Definition: detect-bytejump.h:49
Signature_::mask
SignatureMask mask
Definition: detect.h:679
SIG_TYPE_LIKE_IPONLY
@ SIG_TYPE_LIKE_IPONLY
Definition: detect.h:67
detect-bytetest.h
DetectProtoContainsProto
int DetectProtoContainsProto(const DetectProto *dp, int proto)
see if a DetectProto contains a certain proto
Definition: detect-engine-proto.c:115
SIG_FLAG_REQUIRE_PACKET
#define SIG_FLAG_REQUIRE_PACKET
Definition: detect.h:254
DetectEngineFrameInspectionEngine::smd
SigMatchData * smd
Definition: detect.h:520