54 static int rule_warnings_only = 0;
110 { 0,
false,
false,
true,
"http_uri",
"http uri" },
111 { 0,
false,
false,
false,
"http_raw_uri",
"http raw uri" },
112 { 0,
false,
true,
false,
"http_method",
"http method" },
113 { 0,
false,
false,
false,
"http_request_line",
"http request line" },
114 { 0,
false,
false,
false,
"http_client_body",
"http client body" },
115 { 0,
false,
false,
true,
"http_header",
"http header" },
116 { 0,
false,
false,
false,
"http_raw_header",
"http raw header" },
117 { 0,
false,
false,
true,
"http_cookie",
"http cookie" },
118 { 0,
false,
false,
false,
"http_user_agent",
"http user agent" },
119 { 0,
false,
false,
false,
"http_host",
"http host" },
120 { 0,
false,
false,
false,
"http_raw_host",
"http raw host" },
121 { 0,
false,
false,
false,
"http_accept_enc",
"http accept enc" },
122 { 0,
false,
false,
false,
"http_referer",
"http referer" },
123 { 0,
false,
false,
false,
"http_content_type",
"http content type" },
124 { 0,
false,
false,
false,
"http_header_names",
"http header names" },
127 { 0,
false,
false,
false,
"http_stat_msg",
"http stat msg" },
128 { 0,
false,
false,
false,
"http_stat_code",
"http stat code" },
129 { 0,
false,
true,
false,
"file_data",
"http server body" },
132 { 0,
false,
false,
false,
"http_request_line",
"http request line" },
133 { 0,
false,
false,
false,
"http_accept",
"http accept" },
134 { 0,
false,
false,
false,
"http_accept_lang",
"http accept lang" },
135 { 0,
false,
false,
false,
"http_connection",
"http connection" },
136 { 0,
false,
false,
false,
"http_content_len",
"http content len" },
137 { 0,
false,
false,
false,
"http_protocol",
"http protocol" },
138 { 0,
false,
false,
false,
"http_start",
"http start" },
141 { 0,
false,
false,
false,
"http_response_line",
"http response line" },
142 { 0,
false,
false,
false,
"http.server",
"http server" },
143 { 0,
false,
false,
false,
"http.location",
"http location" },
146 static void FpPatternStatsAdd(
FpPatternStats *fp,
int list, uint16_t patlen)
155 else if (patlen < f->min)
167 int fast_pattern_set = 0;
168 int fast_pattern_only_set = 0;
169 int fast_pattern_chop_set = 0;
174 if (mpm_sm != NULL) {
177 fast_pattern_set = 1;
179 fast_pattern_only_set = 1;
181 fast_pattern_chop_set = 1;
187 fprintf(fp,
"== Sid: %u ==\n", s->
id);
188 fprintf(fp,
"%s\n", line);
190 fprintf(fp,
" Fast Pattern analysis:\n");
192 fprintf(fp,
" Prefilter on: %s\n",
199 fprintf(fp,
" No content present\n");
204 fprintf(fp,
" Fast pattern matcher: ");
205 int list_type = mpm_sm_list;
207 fprintf(fp,
"content\n");
212 fprintf(fp,
"%s (%s)\n", desc, name);
217 fprintf(fp,
" Flags:");
219 fprintf(fp,
" Offset");
222 fprintf(fp,
" Depth");
226 fprintf(fp,
" Within");
230 fprintf(fp,
" Distance");
234 fprintf(fp,
" Nocase");
238 fprintf(fp,
" Negated");
242 fprintf(fp,
" None");
245 fprintf(fp,
" Fast pattern set: %s\n", fast_pattern_set ?
"yes" :
"no");
246 fprintf(fp,
" Fast pattern only set: %s\n", fast_pattern_only_set ?
"yes" :
"no");
247 fprintf(fp,
" Fast pattern chop set: %s\n", fast_pattern_chop_set ?
"yes" :
"no");
248 if (fast_pattern_chop_set) {
249 fprintf(fp,
" Fast pattern offset, length: %u, %u\n", fp_cd->
fp_chop_offset,
260 fprintf(fp,
" Original content: ");
264 if (fast_pattern_chop_set) {
273 fprintf(fp,
" Final content: ");
279 fprintf(fp,
" Final content: ");
299 int fp_engine_analysis_set = 0;
301 if ((
ConfGetBool(
"engine-analysis.rules-fast-pattern",
302 &fp_engine_analysis_set)) == 0) {
306 if (fp_engine_analysis_set == 0)
310 char *log_path =
SCMalloc(PATH_MAX);
311 if (log_path == NULL) {
312 FatalError(
"Unable to allocate scratch memory for rule filename");
314 snprintf(log_path, PATH_MAX,
"%s/%s%s", log_dir,
317 FILE *fp = fopen(log_path,
"w");
319 SCLogError(
"failed to open %s: %s", log_path, strerror(errno));
326 SCLogInfo(
"Engine-Analysis for fast_pattern printed to file - %s",
331 gettimeofday(&tval, NULL);
333 struct tm *tms =
SCLocalTime(tval.tv_sec, &local_tm);
334 fprintf(fp,
"----------------------------------------------"
335 "---------------------\n");
337 "Date: %" PRId32
"/%" PRId32
"/%04d -- "
339 tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min,
341 fprintf(fp,
"----------------------------------------------"
342 "---------------------\n");
355 #define DETECT_PERCENT_ENCODING_REGEX "%[0-9|a-f|A-F]{2}"
361 PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
363 PCRE2_UCHAR errbuffer[256];
364 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
385 }
else if (value && strcasecmp(value,
"warnings-only") == 0) {
387 rule_warnings_only = 1;
392 char log_path[PATH_MAX];
393 snprintf(log_path,
sizeof(log_path),
"%s/%s%s", log_dir,
397 SCLogError(
"failed to open %s: %s", log_path, strerror(errno));
401 SCLogInfo(
"Engine-Analysis for rules printed to file - %s",
405 gettimeofday(&tval, NULL);
407 struct tm *tms =
SCLocalTime(tval.tv_sec, &local_tm);
409 "----------------------------------------------"
410 "---------------------\n");
412 "Date: %" PRId32
"/%" PRId32
"/%04d -- "
414 tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min,
417 "----------------------------------------------"
418 "---------------------\n");
421 if (!PerCentEncodingSetup(
de_ctx->
ea)) {
423 "Error compiling regex; can't check for percent encoding in normalized "
429 SCLogInfo(
"Conf parameter \"engine-analysis.rules\" not found. "
430 "Defaulting to not printing the rules analysis report.");
433 SCLogInfo(
"Engine-Analysis for rules disabled in conf file.");
442 fprintf(fp,
"============\n"
443 "Summary:\n============\n");
451 "%s, smallest pattern %u byte(s), longest pattern %u byte(s), number of patterns "
452 "%u, avg pattern len %.2f byte(s)\n",
454 (
float)((
double)f->
tot / (
float)f->
cnt));
476 *fp_analysis =
false;
477 *rule_analysis =
false;
481 FatalError(
"Unable to allocate per-engine analysis context");
486 if (cfg_prefix_len > 0) {
490 FatalError(
"Unable to allocate per-engine analysis context name buffer");
498 *fp_analysis = SetupFPAnalyzer(
de_ctx);
499 *rule_analysis = SetupRuleAnalyzer(
de_ctx);
501 if (!(*fp_analysis || *rule_analysis)) {
513 CleanupRuleAnalyzer(
de_ctx);
514 CleanupFPAnalyzer(
de_ctx);
531 static int PerCentEncodingMatch(
EngineAnalysisCtx *ea_ctx, uint8_t *content, uint16_t content_len)
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);
539 }
else if (ret < -1) {
540 SCLogError(
"Error parsing content - %s; error code is %d", content, ret);
543 pcre2_match_data_free(match);
553 if (mpm_sm != NULL) {
591 const int list_type = mpm_sm_list;
600 payload ? (stream ?
"payload and reassembled stream" :
"payload")
601 :
"reassembled stream");
608 }
else if (desc || name) {
647 vsnprintf(
str,
sizeof(
str), fmt, ap);
651 ctx->js_notes = jb_new_array();
653 jb_append_string(ctx->js_notes,
str);
662 vsnprintf(
str,
sizeof(
str), fmt, ap);
665 if (!ctx->js_warnings)
666 ctx->js_warnings = jb_new_array();
667 if (ctx->js_warnings)
668 jb_append_string(ctx->js_warnings,
str);
671 #define CHECK(pat) if (strlen((pat)) <= len && memcmp((pat), buf, MIN(len, strlen((pat)))) == 0) return true;
673 static bool LooksLikeHTTPMethod(
const uint8_t *buf, uint16_t
len)
682 static bool LooksLikeHTTPUA(
const uint8_t *buf, uint16_t
len)
684 CHECK(
"User-Agent: ");
685 CHECK(
"\nUser-Agent: ");
691 char pattern_str[1024] =
"";
694 jb_set_string(js,
"pattern", pattern_str);
703 jb_set_uint(js,
"offset", cd->
offset);
706 jb_set_uint(js,
"depth", cd->
depth);
709 jb_set_int(js,
"distance", cd->
distance);
712 jb_set_int(js,
"within", cd->
within);
731 jb_open_array(js,
"matches");
735 jb_set_string(js,
"name", mname);
741 jb_open_object(js,
"content");
744 AnalyzerNote(ctx, (
char *)
"'fast_pattern:only' option is silently ignored and "
745 "is interpreted as regular 'fast_pattern'");
749 (
char *)
"pattern looks like it inspects HTTP, use http.request_line or "
750 "http.method and http.uri instead for improved performance");
754 (
char *)
"pattern looks like it inspects HTTP, use http.user_agent "
755 "or http.header for improved performance");
758 AnalyzerNote(ctx, (
char *)
"'within' option for pattern w/o previous content "
759 "was converted to 'depth'");
762 AnalyzerNote(ctx, (
char *)
"'distance' option for pattern w/o previous content "
763 "was converted to 'offset'");
771 jb_open_object(js,
"pcre");
776 (
char *)
"'/B' (rawbytes) option is a no-op and is silently ignored");
783 jb_open_object(js,
"byte_jump");
784 jb_set_uint(js,
"nbytes", cd->
nbytes);
785 jb_set_int(js,
"offset", cd->
offset);
786 jb_set_uint(js,
"multiplier", cd->
multiplier);
790 jb_set_string(js,
"base",
"unset");
793 jb_set_string(js,
"base",
"oct");
796 jb_set_string(js,
"base",
"dec");
799 jb_set_string(js,
"base",
"hex");
802 jb_open_array(js,
"flags");
804 jb_append_string(js,
"from_beginning");
806 jb_append_string(js,
"little_endian");
808 jb_append_string(js,
"big_endian");
810 jb_append_string(js,
"string");
812 jb_append_string(js,
"relative");
814 jb_append_string(js,
"align");
816 jb_append_string(js,
"dce");
818 jb_append_string(js,
"offset_be");
820 jb_append_string(js,
"from_end");
828 jb_open_object(js,
"byte_test");
829 jb_set_uint(js,
"nbytes", cd->
nbytes);
830 jb_set_int(js,
"offset", cd->
offset);
833 jb_set_string(js,
"base",
"unset");
836 jb_set_string(js,
"base",
"oct");
839 jb_set_string(js,
"base",
"dec");
842 jb_set_string(js,
"base",
"hex");
845 jb_open_array(js,
"flags");
847 jb_append_string(js,
"little_endian");
849 jb_append_string(js,
"big_endian");
851 jb_append_string(js,
"string");
853 jb_append_string(js,
"relative");
855 jb_append_string(js,
"dce");
863 jb_open_object(js,
"ipopts");
865 jb_set_string(js,
"option", flag);
872 jb_open_object(js,
"flowbits");
875 jb_set_string(js,
"cmd",
"isset");
878 jb_set_string(js,
"cmd",
"isnotset");
881 jb_set_string(js,
"cmd",
"set");
884 jb_set_string(js,
"cmd",
"unset");
887 jb_set_string(js,
"cmd",
"toggle");
891 jb_open_array(js,
"names");
897 const char *varname =
899 jb_append_string(js, varname);
904 jb_set_string(js,
"operator",
"or");
912 jb_open_object(js,
"ack");
913 jb_set_uint(js,
"number", cd->
ack);
919 jb_open_object(js,
"seq");
920 jb_set_uint(js,
"number", cd->
seq);
926 jb_open_object(js,
"tcp_mss");
927 SCDetectU16ToJson(js, cd);
948 ctx.
js = jb_new_object();
952 jb_set_string(ctx.
js,
"raw", s->
sig_str);
953 jb_set_uint(ctx.
js,
"id", s->
id);
954 jb_set_uint(ctx.
js,
"gid", s->
gid);
955 jb_set_uint(ctx.
js,
"rev", s->
rev);
956 jb_set_string(ctx.
js,
"msg", s->
msg);
959 jb_set_string(ctx.
js,
"app_proto", alproto);
961 jb_open_array(ctx.
js,
"requirements");
963 jb_append_string(ctx.
js,
"payload");
966 jb_append_string(ctx.
js,
"no_payload");
969 jb_append_string(ctx.
js,
"flow");
972 jb_append_string(ctx.
js,
"tcp_flags_init_deinit");
975 jb_append_string(ctx.
js,
"tcp_flags_unusual");
978 jb_append_string(ctx.
js,
"engine_event");
984 jb_set_string(ctx.
js,
"type",
"unset");
987 jb_set_string(ctx.
js,
"type",
"ip_only");
990 jb_set_string(ctx.
js,
"type",
"like_ip_only");
993 jb_set_string(ctx.
js,
"type",
"pd_only");
996 jb_set_string(ctx.
js,
"type",
"de_only");
999 jb_set_string(ctx.
js,
"type",
"pkt");
1002 jb_set_string(ctx.
js,
"type",
"pkt_stream");
1005 jb_set_string(ctx.
js,
"type",
"stream");
1008 jb_set_string(ctx.
js,
"type",
"app_layer");
1011 jb_set_string(ctx.
js,
"type",
"app_tx");
1014 jb_set_string(ctx.
js,
"type",
"error");
1018 jb_open_array(ctx.
js,
"flags");
1020 jb_append_string(ctx.
js,
"src_any");
1023 jb_append_string(ctx.
js,
"dst_any");
1026 jb_append_string(ctx.
js,
"sp_any");
1029 jb_append_string(ctx.
js,
"dp_any");
1032 jb_append_string(ctx.
js,
"noalert");
1035 jb_append_string(ctx.
js,
"dsize");
1038 jb_append_string(ctx.
js,
"applayer");
1041 jb_append_string(ctx.
js,
"need_packet");
1044 jb_append_string(ctx.
js,
"need_stream");
1047 jb_append_string(ctx.
js,
"negated_mpm");
1050 jb_append_string(ctx.
js,
"flush");
1053 jb_append_string(ctx.
js,
"need_flowvar");
1056 jb_append_string(ctx.
js,
"filestore");
1059 jb_append_string(ctx.
js,
"toserver");
1062 jb_append_string(ctx.
js,
"toclient");
1065 jb_append_string(ctx.
js,
"tlsstore");
1068 jb_append_string(ctx.
js,
"bypass");
1071 jb_append_string(ctx.
js,
"prefilter");
1074 jb_append_string(ctx.
js,
"src_is_target");
1077 jb_append_string(ctx.
js,
"dst_is_target");
1084 jb_open_array(ctx.
js,
"pkt_engines");
1086 for ( ; pkt != NULL; pkt = pkt->
next) {
1101 jb_start_object(ctx.
js);
1102 jb_set_string(ctx.
js,
"name", name);
1103 jb_set_bool(ctx.
js,
"is_mpm", pkt->
mpm);
1105 jb_open_array(ctx.
js,
"transforms");
1107 jb_start_object(ctx.
js);
1108 jb_set_string(ctx.
js,
"name",
1114 DumpMatches(&ctx, ctx.
js, pkt->
smd);
1121 jb_open_array(ctx.
js,
"frame_engines");
1123 for (; frame != NULL; frame = frame->
next) {
1125 jb_start_object(ctx.
js);
1126 jb_set_string(ctx.
js,
"name", name);
1127 jb_set_bool(ctx.
js,
"is_mpm", frame->
mpm);
1129 jb_open_array(ctx.
js,
"transforms");
1131 jb_start_object(ctx.
js);
1132 jb_set_string(ctx.
js,
"name",
1138 DumpMatches(&ctx, ctx.
js, frame->
smd);
1144 bool has_stream =
false;
1145 bool has_client_body_mpm =
false;
1146 bool has_file_data_mpm =
false;
1148 jb_open_array(ctx.
js,
"engines");
1150 for ( ; app != NULL; app = app->
next) {
1165 }
else if (app->
mpm && strcmp(name,
"http_client_body") == 0) {
1166 has_client_body_mpm =
true;
1167 }
else if (app->
mpm && strcmp(name,
"file_data") == 0) {
1168 has_file_data_mpm =
true;
1171 jb_start_object(ctx.
js);
1172 jb_set_string(ctx.
js,
"name", name);
1173 const char *direction = app->
dir == 0 ?
"toserver" :
"toclient";
1174 jb_set_string(ctx.
js,
"direction", direction);
1175 jb_set_bool(ctx.
js,
"is_mpm", app->
mpm);
1177 jb_set_uint(ctx.
js,
"progress", app->
progress);
1180 jb_open_array(ctx.
js,
"transforms");
1182 jb_start_object(ctx.
js);
1183 jb_set_string(ctx.
js,
"name",
1189 DumpMatches(&ctx, ctx.
js, app->
smd);
1197 if (has_stream && has_client_body_mpm)
1198 AnalyzerNote(&ctx, (
char *)
"mpm in http_client_body combined with stream match leads to stream buffering");
1199 if (has_stream && has_file_data_mpm)
1200 AnalyzerNote(&ctx, (
char *)
"mpm in file_data combined with stream match leads to stream buffering");
1203 jb_open_object(ctx.
js,
"lists");
1213 if (pkt_mpm || app_mpm) {
1214 jb_open_object(ctx.
js,
"mpm");
1222 jb_set_string(ctx.
js,
"buffer", name);
1229 switch (smd->
type) {
1233 DumpContent(ctx.
js, cd);
1245 jb_open_object(ctx.
js,
"prefilter");
1252 jb_set_string(ctx.
js,
"buffer", name);
1254 jb_set_string(ctx.
js,
"name", mname);
1266 jb_set_object(ctx.
js,
"notes", ctx.
js_notes);
1272 const char *filename =
"rules.json";
1274 char json_path[PATH_MAX] =
"";
1275 snprintf(json_path,
sizeof(json_path),
"%s/%s%s", log_dir,
1279 FILE *fp = fopen(json_path,
"a");
1281 fwrite(jb_ptr(ctx.
js), jb_len(ctx.
js), 1, fp);
1295 JsonBuilder *root_jb = jb_new_object();
1299 jb_open_array(root_jb,
"buffers");
1303 char str[1024] =
"";
1307 JsonBuilder *jb = arrays[p->
sm_list];
1308 if (arrays[p->
sm_list] == NULL) {
1309 jb = arrays[p->
sm_list] = jb_new_object();
1315 jb_set_string(jb,
"name", name);
1316 jb_set_uint(jb,
"list_id", p->
sm_list);
1318 jb_open_array(jb,
"patterns");
1321 jb_start_object(jb);
1322 jb_set_string(jb,
"pattern",
str);
1324 jb_set_uint(jb,
"cnt", p->
cnt);
1325 jb_set_uint(jb,
"mpm", p->
mpm);
1326 jb_open_object(jb,
"flags");
1337 JsonBuilder *jb = arrays[i];
1344 jb_append_object(root_jb, jb);
1350 const char *filename =
"patterns.json";
1352 char json_path[PATH_MAX] =
"";
1353 snprintf(json_path,
sizeof(json_path),
"%s/%s%s", log_dir,
1357 FILE *fp = fopen(json_path,
"a");
1359 fwrite(jb_ptr(root_jb), jb_len(root_jb), 1, fp);
1380 EngineAnalysisItemsReset(ea_ctx);
1388 FatalError(
"Unable to allocate analysis scratch pad");
1398 analyzer_item->
item_id = (uint16_t)item_id;
1399 if (analyzer_item->
item_id == -1) {
1401 FatalError(
"unable to initialize engine-analysis table: detect buffer \"%s\" not "
1434 uint32_t rule_bidirectional = 0;
1435 uint32_t rule_pcre = 0;
1436 uint32_t rule_pcre_http = 0;
1437 uint32_t rule_content = 0;
1438 uint32_t rule_flow = 0;
1439 uint32_t rule_flags = 0;
1440 uint32_t rule_flow_toserver = 0;
1441 uint32_t rule_flow_toclient = 0;
1442 uint32_t rule_flow_nostream = 0;
1443 uint32_t rule_ipv4_only = 0;
1444 uint32_t rule_ipv6_only = 0;
1445 uint32_t rule_flowbits = 0;
1446 uint32_t rule_flowint = 0;
1447 uint32_t rule_content_http = 0;
1448 uint32_t rule_content_offset_depth = 0;
1449 int32_t list_id = 0;
1450 uint32_t rule_warning = 0;
1451 uint32_t stream_buf = 0;
1452 uint32_t packet_buf = 0;
1453 uint32_t file_store = 0;
1454 uint32_t warn_pcre_no_content = 0;
1455 uint32_t warn_pcre_http_content = 0;
1456 uint32_t warn_pcre_http = 0;
1457 uint32_t warn_content_http_content = 0;
1458 uint32_t warn_content_http = 0;
1459 uint32_t warn_tcp_no_flow = 0;
1460 uint32_t warn_client_ports = 0;
1461 uint32_t warn_direction = 0;
1462 uint32_t warn_method_toclient = 0;
1463 uint32_t warn_method_serverbody = 0;
1464 uint32_t warn_pcre_method = 0;
1465 uint32_t warn_encoding_norm_http_buf = 0;
1466 uint32_t warn_file_store_not_present = 0;
1467 uint32_t warn_offset_depth_pkt_stream = 0;
1468 uint32_t warn_offset_depth_alproto = 0;
1469 uint32_t warn_non_alproto_fp_for_alproto_sig = 0;
1470 uint32_t warn_no_direction = 0;
1471 uint32_t warn_both_direction = 0;
1473 EngineAnalysisItemsInit(
de_ctx->
ea);
1479 rule_bidirectional = 1;
1493 rule_ipv4_only += 1;
1496 rule_ipv6_only += 1;
1504 if (item_slot == -1) {
1512 if (item_slot == -1) {
1517 rule_content_offset_depth++;
1523 rule_content_http++;
1530 warn_encoding_norm_http_buf += 1;
1537 rule_flow_toserver = 1;
1540 rule_flow_toclient = 1;
1545 rule_flow_nostream = 1;
1570 warn_file_store_not_present = 1;
1573 if (rule_pcre > 0 && rule_content == 0 && rule_content_http == 0) {
1575 warn_pcre_no_content = 1;
1578 if (rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0) {
1580 warn_pcre_http_content = 1;
1586 if (rule_content > 0 && rule_content_http > 0) {
1588 warn_content_http_content = 1;
1592 warn_content_http = 1;
1594 if (rule_content == 1) {
1599 (rule_content || rule_content_http || rule_pcre || rule_pcre_http || rule_flowbits ||
1602 warn_tcp_no_flow = 1;
1604 if (rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1609 warn_client_ports = 1;
1612 if (rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)) {
1617 if (*http_method_item_seen_ptr) {
1618 if (rule_flow && rule_flow_toclient) {
1620 warn_method_toclient = 1;
1622 if (*http_server_body_item_seen_ptr) {
1624 warn_method_serverbody = 1;
1626 if (rule_content == 0 && rule_content_http == 0 && (rule_pcre > 0 || rule_pcre_http > 0)) {
1628 warn_pcre_method = 1;
1631 if (rule_content_offset_depth > 0 && stream_buf && packet_buf) {
1633 warn_offset_depth_pkt_stream = 1;
1637 warn_offset_depth_alproto = 1;
1642 warn_non_alproto_fp_for_alproto_sig = 1;
1646 warn_no_direction += 1;
1653 warn_both_direction += 1;
1658 if (!rule_warnings_only || (rule_warnings_only && rule_warning > 0)) {
1660 fprintf(fp,
"== Sid: %u ==\n", s->
id);
1661 fprintf(fp,
"%s\n", line);
1667 fprintf(fp,
" Rule is ip only.\n");
1670 fprintf(fp,
" Rule is like ip only.\n");
1673 fprintf(fp,
" Rule is PD only.\n");
1676 fprintf(fp,
" Rule is DE only.\n");
1679 fprintf(fp,
" Rule is packet inspecting.\n");
1682 fprintf(fp,
" Rule is packet and stream inspecting.\n");
1685 fprintf(fp,
" Rule is stream inspecting.\n");
1688 fprintf(fp,
" Rule is app-layer inspecting.\n");
1691 fprintf(fp,
" Rule is App-layer TX inspecting.\n");
1697 fprintf(fp,
" Rule is IPv6 only.\n");
1699 fprintf(fp,
" Rule is IPv4 only.\n");
1701 fprintf(fp,
" Rule matches on packets.\n");
1702 if (!rule_flow_nostream && stream_buf &&
1703 (rule_flow || rule_flowbits || rule_flowint || rule_content || rule_pcre)) {
1704 fprintf(fp,
" Rule matches on reassembled stream.\n");
1709 fprintf(fp,
" Rule matches on %s buffer.\n", ai->
display_name);
1715 if (rule_content || rule_content_http || rule_pcre || rule_pcre_http) {
1717 " Rule contains %u content options, %u http content options, %u pcre "
1718 "options, and %u pcre options with http modifiers.\n",
1719 rule_content, rule_content_http, rule_pcre, rule_pcre_http);
1724 fprintf(fp,
" Prefilter on: %s.\n",
1727 EngineAnalysisRulesPrintFP(
de_ctx, s);
1731 if (warn_pcre_no_content ) {
1732 fprintf(fp,
" Warning: Rule uses pcre without a content option present.\n"
1733 " -Consider adding a content to improve performance of this "
1736 if (warn_pcre_http_content ) {
1737 fprintf(fp,
" Warning: Rule uses content options with http_* and pcre options "
1738 "without http modifiers.\n"
1739 " -Consider adding http pcre modifier.\n");
1741 else if (warn_pcre_http ) {
1742 fprintf(fp,
" Warning: Rule app layer protocol is http, but pcre options do not "
1743 "have http modifiers.\n"
1744 " -Consider adding http pcre modifiers.\n");
1746 if (warn_content_http_content ) {
1748 " Warning: Rule contains content with http_* and content without http_*.\n"
1749 " -Consider adding http content modifiers.\n");
1751 if (warn_content_http ) {
1752 fprintf(fp,
" Warning: Rule app layer protocol is http, but content options do not "
1753 "have http_* modifiers.\n"
1754 " -Consider adding http content modifiers.\n");
1756 if (rule_content == 1) {
1759 if (warn_encoding_norm_http_buf) {
1760 fprintf(fp,
" Warning: Rule may contain percent encoded content for a normalized "
1761 "http buffer match.\n");
1763 if (warn_tcp_no_flow
1765 fprintf(fp,
" Warning: TCP rule without a flow or flags option.\n"
1766 " -Consider adding flow or flags to improve performance of "
1769 if (warn_client_ports
1774 " Warning: Rule contains ports or port variables only on the client side.\n"
1775 " -Flow direction possibly inconsistent with rule.\n");
1777 if (warn_direction ) {
1778 fprintf(fp,
" Warning: Rule is bidirectional and has a flow option with a specific "
1781 if (warn_method_toclient ) {
1782 fprintf(fp,
" Warning: Rule uses content or pcre for http_method with "
1783 "flow:to_client or from_server\n");
1785 if (warn_method_serverbody ) {
1786 fprintf(fp,
" Warning: Rule uses content or pcre for http_method with content or "
1787 "pcre for http_server_body.\n");
1789 if (warn_pcre_method
1791 fprintf(fp,
" Warning: Rule uses pcre with only a http_method content; possible "
1792 "performance issue.\n");
1794 if (warn_offset_depth_pkt_stream) {
1795 fprintf(fp,
" Warning: Rule has depth"
1796 "/offset with raw content keywords. Please note the "
1797 "offset/depth will be checked against both packet "
1798 "payloads and stream. If you meant to have the offset/"
1799 "depth checked against just the payload, you can update "
1800 "the signature as \"alert tcp-pkt...\"\n");
1802 if (warn_offset_depth_alproto) {
1804 " Warning: Rule has "
1805 "offset/depth set along with a match on a specific "
1806 "app layer protocol - %d. This can lead to FNs if we "
1807 "have a offset/depth content match on a packet payload "
1808 "before we can detect the app layer protocol for the "
1812 if (warn_non_alproto_fp_for_alproto_sig) {
1813 fprintf(fp,
" Warning: Rule app layer "
1814 "protocol is http, but the fast_pattern is set on the raw "
1815 "stream. Consider adding fast_pattern over a http "
1816 "buffer for increased performance.");
1818 if (warn_no_direction) {
1819 fprintf(fp,
" Warning: Rule has no direction indicator.\n");
1821 if (warn_both_direction) {
1822 fprintf(fp,
" Warning: Rule is inspecting both the request and the response.\n");
1824 if (warn_file_store_not_present) {
1825 fprintf(fp,
" Warning: Rule requires file-store but the output file-store is not "
1828 if (rule_warning == 0) {
1829 fprintf(fp,
" No warnings for this rule.\n");