55 static int rule_warnings_only = 0;
111 { 0,
false,
false,
true,
"http_uri",
"http uri" },
112 { 0,
false,
false,
false,
"http_raw_uri",
"http raw uri" },
113 { 0,
false,
true,
false,
"http_method",
"http method" },
114 { 0,
false,
false,
false,
"http_request_line",
"http request line" },
115 { 0,
false,
false,
false,
"http_client_body",
"http client body" },
116 { 0,
false,
false,
true,
"http_header",
"http header" },
117 { 0,
false,
false,
false,
"http_raw_header",
"http raw header" },
118 { 0,
false,
false,
true,
"http_cookie",
"http cookie" },
119 { 0,
false,
false,
false,
"http_user_agent",
"http user agent" },
120 { 0,
false,
false,
false,
"http_host",
"http host" },
121 { 0,
false,
false,
false,
"http_raw_host",
"http raw host" },
122 { 0,
false,
false,
false,
"http_accept_enc",
"http accept enc" },
123 { 0,
false,
false,
false,
"http_referer",
"http referer" },
124 { 0,
false,
false,
false,
"http_content_type",
"http content type" },
125 { 0,
false,
false,
false,
"http_header_names",
"http header names" },
128 { 0,
false,
false,
false,
"http_stat_msg",
"http stat msg" },
129 { 0,
false,
false,
false,
"http_stat_code",
"http stat code" },
130 { 0,
false,
true,
false,
"file_data",
"http server body" },
133 { 0,
false,
false,
false,
"http_request_line",
"http request line" },
134 { 0,
false,
false,
false,
"http_accept",
"http accept" },
135 { 0,
false,
false,
false,
"http_accept_lang",
"http accept lang" },
136 { 0,
false,
false,
false,
"http_connection",
"http connection" },
137 { 0,
false,
false,
false,
"http_content_len",
"http content len" },
138 { 0,
false,
false,
false,
"http_protocol",
"http protocol" },
139 { 0,
false,
false,
false,
"http_start",
"http start" },
142 { 0,
false,
false,
false,
"http_response_line",
"http response line" },
143 { 0,
false,
false,
false,
"http.server",
"http server" },
144 { 0,
false,
false,
false,
"http.location",
"http location" },
147 static void FpPatternStatsAdd(
FpPatternStats *fp,
int list, uint16_t patlen)
156 else if (patlen < f->min)
168 int fast_pattern_set = 0;
169 int fast_pattern_only_set = 0;
170 int fast_pattern_chop_set = 0;
175 if (mpm_sm != NULL) {
178 fast_pattern_set = 1;
180 fast_pattern_only_set = 1;
182 fast_pattern_chop_set = 1;
188 fprintf(fp,
"== Sid: %u ==\n", s->
id);
189 fprintf(fp,
"%s\n", line);
191 fprintf(fp,
" Fast Pattern analysis:\n");
193 fprintf(fp,
" Prefilter on: %s\n",
200 fprintf(fp,
" No content present\n");
205 fprintf(fp,
" Fast pattern matcher: ");
206 int list_type = mpm_sm_list;
208 fprintf(fp,
"content\n");
213 fprintf(fp,
"%s (%s)\n", desc, name);
218 fprintf(fp,
" Flags:");
220 fprintf(fp,
" Offset");
223 fprintf(fp,
" Depth");
227 fprintf(fp,
" Within");
231 fprintf(fp,
" Distance");
235 fprintf(fp,
" Nocase");
239 fprintf(fp,
" Negated");
243 fprintf(fp,
" None");
246 fprintf(fp,
" Fast pattern set: %s\n", fast_pattern_set ?
"yes" :
"no");
247 fprintf(fp,
" Fast pattern only set: %s\n", fast_pattern_only_set ?
"yes" :
"no");
248 fprintf(fp,
" Fast pattern chop set: %s\n", fast_pattern_chop_set ?
"yes" :
"no");
249 if (fast_pattern_chop_set) {
250 fprintf(fp,
" Fast pattern offset, length: %u, %u\n", fp_cd->
fp_chop_offset,
261 fprintf(fp,
" Original content: ");
265 if (fast_pattern_chop_set) {
274 fprintf(fp,
" Final content: ");
280 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));
474 *fp_analysis =
false;
475 *rule_analysis =
false;
479 FatalError(
"Unable to allocate per-engine analysis context");
484 if (cfg_prefix_len > 0) {
488 FatalError(
"Unable to allocate per-engine analysis context name buffer");
496 *fp_analysis = SetupFPAnalyzer(
de_ctx);
497 *rule_analysis = SetupRuleAnalyzer(
de_ctx);
499 if (!(*fp_analysis || *rule_analysis)) {
511 CleanupRuleAnalyzer(
de_ctx);
512 CleanupFPAnalyzer(
de_ctx);
529 static int PerCentEncodingMatch(
EngineAnalysisCtx *ea_ctx, uint8_t *content, uint16_t content_len)
533 pcre2_match_data *match = pcre2_match_data_create_from_pattern(ea_ctx->
percent_re, NULL);
534 ret = pcre2_match(ea_ctx->
percent_re, (PCRE2_SPTR8)content, content_len, 0, 0, match, NULL);
537 }
else if (ret < -1) {
538 SCLogError(
"Error parsing content - %s; error code is %d", content, ret);
541 pcre2_match_data_free(match);
551 if (mpm_sm != NULL) {
589 const int list_type = mpm_sm_list;
598 payload ? (stream ?
"payload and reassembled stream" :
"payload")
599 :
"reassembled stream");
606 }
else if (desc || name) {
643 vsnprintf(
str,
sizeof(
str), fmt, ap);
647 ctx->js_notes = jb_new_array();
649 jb_append_string(
ctx->js_notes,
str);
658 vsnprintf(
str,
sizeof(
str), fmt, ap);
661 if (!
ctx->js_warnings)
662 ctx->js_warnings = jb_new_array();
663 if (
ctx->js_warnings)
664 jb_append_string(
ctx->js_warnings,
str);
667 #define CHECK(pat) if (strlen((pat)) <= len && memcmp((pat), buf, MIN(len, strlen((pat)))) == 0) return true;
669 static bool LooksLikeHTTPMethod(
const uint8_t *buf, uint16_t
len)
678 static bool LooksLikeHTTPUA(
const uint8_t *buf, uint16_t
len)
680 CHECK(
"User-Agent: ");
681 CHECK(
"\nUser-Agent: ");
687 char pattern_str[1024] =
"";
690 jb_set_string(js,
"pattern", pattern_str);
699 jb_set_uint(js,
"offset", cd->
offset);
702 jb_set_uint(js,
"depth", cd->
depth);
705 jb_set_int(js,
"distance", cd->
distance);
708 jb_set_int(js,
"within", cd->
within);
727 jb_open_array(js,
"matches");
731 jb_set_string(js,
"name", mname);
737 jb_open_object(js,
"content");
740 AnalyzerNote(
ctx, (
char *)
"'fast_pattern:only' option is silently ignored and "
741 "is interpreted as regular 'fast_pattern'");
745 (
char *)
"pattern looks like it inspects HTTP, use http.request_line or "
746 "http.method and http.uri instead for improved performance");
750 (
char *)
"pattern looks like it inspects HTTP, use http.user_agent "
751 "or http.header for improved performance");
754 AnalyzerNote(
ctx, (
char *)
"'within' option for pattern w/o previous content "
755 "was converted to 'depth'");
758 AnalyzerNote(
ctx, (
char *)
"'distance' option for pattern w/o previous content "
759 "was converted to 'offset'");
767 jb_open_object(js,
"pcre");
772 (
char *)
"'/B' (rawbytes) option is a no-op and is silently ignored");
779 jb_open_object(js,
"byte_jump");
780 jb_set_uint(js,
"nbytes", cd->
nbytes);
781 jb_set_int(js,
"offset", cd->
offset);
782 jb_set_uint(js,
"multiplier", cd->
multiplier);
786 jb_set_string(js,
"base",
"unset");
789 jb_set_string(js,
"base",
"oct");
792 jb_set_string(js,
"base",
"dec");
795 jb_set_string(js,
"base",
"hex");
798 jb_open_array(js,
"flags");
800 jb_append_string(js,
"from_beginning");
802 jb_append_string(js,
"little_endian");
804 jb_append_string(js,
"big_endian");
806 jb_append_string(js,
"string");
808 jb_append_string(js,
"relative");
810 jb_append_string(js,
"align");
812 jb_append_string(js,
"dce");
814 jb_append_string(js,
"offset_be");
816 jb_append_string(js,
"from_end");
824 jb_open_object(js,
"byte_test");
825 jb_set_uint(js,
"nbytes", cd->
nbytes);
826 jb_set_int(js,
"offset", cd->
offset);
829 jb_set_string(js,
"base",
"unset");
832 jb_set_string(js,
"base",
"oct");
835 jb_set_string(js,
"base",
"dec");
838 jb_set_string(js,
"base",
"hex");
841 jb_open_array(js,
"flags");
843 jb_append_string(js,
"little_endian");
845 jb_append_string(js,
"big_endian");
847 jb_append_string(js,
"string");
849 jb_append_string(js,
"relative");
851 jb_append_string(js,
"dce");
859 jb_open_object(js,
"ipopts");
861 jb_set_string(js,
"option", flag);
868 jb_open_object(js,
"flowbits");
871 jb_set_string(js,
"cmd",
"isset");
874 jb_set_string(js,
"cmd",
"isnotset");
877 jb_set_string(js,
"cmd",
"set");
880 jb_set_string(js,
"cmd",
"unset");
883 jb_set_string(js,
"cmd",
"toggle");
887 jb_open_array(js,
"names");
893 const char *varname =
895 jb_append_string(js, varname);
900 jb_set_string(js,
"operator",
"or");
908 jb_open_object(js,
"ack");
909 jb_set_uint(js,
"number", cd->
ack);
915 jb_open_object(js,
"seq");
916 jb_set_uint(js,
"number", cd->
seq);
922 jb_open_object(js,
"tcp_mss");
923 SCDetectU16ToJson(js, cd);
944 ctx.js = jb_new_object();
949 jb_set_uint(
ctx.js,
"id", s->
id);
950 jb_set_uint(
ctx.js,
"gid", s->
gid);
951 jb_set_uint(
ctx.js,
"rev", s->
rev);
952 jb_set_string(
ctx.js,
"msg", s->
msg);
955 jb_set_string(
ctx.js,
"app_proto", alproto);
957 jb_open_array(
ctx.js,
"requirements");
959 jb_append_string(
ctx.js,
"payload");
962 jb_append_string(
ctx.js,
"no_payload");
965 jb_append_string(
ctx.js,
"flow");
968 jb_append_string(
ctx.js,
"tcp_flags_init_deinit");
971 jb_append_string(
ctx.js,
"tcp_flags_unusual");
974 jb_append_string(
ctx.js,
"engine_event");
977 jb_append_string(
ctx.js,
"real_pkt");
983 jb_set_string(
ctx.js,
"type",
"unset");
986 jb_set_string(
ctx.js,
"type",
"ip_only");
989 jb_set_string(
ctx.js,
"type",
"like_ip_only");
992 jb_set_string(
ctx.js,
"type",
"pd_only");
995 jb_set_string(
ctx.js,
"type",
"de_only");
998 jb_set_string(
ctx.js,
"type",
"pkt");
1001 jb_set_string(
ctx.js,
"type",
"pkt_stream");
1004 jb_set_string(
ctx.js,
"type",
"stream");
1007 jb_set_string(
ctx.js,
"type",
"app_layer");
1010 jb_set_string(
ctx.js,
"type",
"app_tx");
1013 jb_set_string(
ctx.js,
"type",
"error");
1017 jb_open_array(
ctx.js,
"flags");
1019 jb_append_string(
ctx.js,
"src_any");
1022 jb_append_string(
ctx.js,
"dst_any");
1025 jb_append_string(
ctx.js,
"sp_any");
1028 jb_append_string(
ctx.js,
"dp_any");
1031 jb_append_string(
ctx.js,
"noalert");
1034 jb_append_string(
ctx.js,
"dsize");
1037 jb_append_string(
ctx.js,
"applayer");
1040 jb_append_string(
ctx.js,
"need_packet");
1043 jb_append_string(
ctx.js,
"need_stream");
1046 jb_append_string(
ctx.js,
"negated_mpm");
1049 jb_append_string(
ctx.js,
"flush");
1052 jb_append_string(
ctx.js,
"need_flowvar");
1055 jb_append_string(
ctx.js,
"filestore");
1058 jb_append_string(
ctx.js,
"toserver");
1061 jb_append_string(
ctx.js,
"toclient");
1064 jb_append_string(
ctx.js,
"tlsstore");
1067 jb_append_string(
ctx.js,
"bypass");
1070 jb_append_string(
ctx.js,
"prefilter");
1073 jb_append_string(
ctx.js,
"src_is_target");
1076 jb_append_string(
ctx.js,
"dst_is_target");
1083 jb_open_array(
ctx.js,
"pkt_engines");
1085 for ( ; pkt != NULL; pkt = pkt->
next) {
1100 jb_start_object(
ctx.js);
1101 jb_set_string(
ctx.js,
"name", name);
1102 jb_set_bool(
ctx.js,
"is_mpm", pkt->
mpm);
1104 jb_open_array(
ctx.js,
"transforms");
1106 jb_start_object(
ctx.js);
1107 jb_set_string(
ctx.js,
"name",
1120 jb_open_array(
ctx.js,
"frame_engines");
1122 for (; frame != NULL; frame = frame->
next) {
1124 jb_start_object(
ctx.js);
1125 jb_set_string(
ctx.js,
"name", name);
1126 jb_set_bool(
ctx.js,
"is_mpm", frame->
mpm);
1128 jb_open_array(
ctx.js,
"transforms");
1130 jb_start_object(
ctx.js);
1131 jb_set_string(
ctx.js,
"name",
1143 bool has_stream =
false;
1144 bool has_client_body_mpm =
false;
1145 bool has_file_data_mpm =
false;
1147 jb_open_array(
ctx.js,
"engines");
1149 for ( ; app != NULL; app = app->
next) {
1164 }
else if (app->
mpm && strcmp(name,
"http_client_body") == 0) {
1165 has_client_body_mpm =
true;
1166 }
else if (app->
mpm && strcmp(name,
"file_data") == 0) {
1167 has_file_data_mpm =
true;
1170 jb_start_object(
ctx.js);
1171 jb_set_string(
ctx.js,
"name", name);
1172 const char *direction = app->
dir == 0 ?
"toserver" :
"toclient";
1173 jb_set_string(
ctx.js,
"direction", direction);
1174 jb_set_bool(
ctx.js,
"is_mpm", app->
mpm);
1179 jb_open_array(
ctx.js,
"transforms");
1181 jb_start_object(
ctx.js);
1182 jb_set_string(
ctx.js,
"name",
1196 if (has_stream && has_client_body_mpm)
1197 AnalyzerNote(&
ctx, (
char *)
"mpm in http_client_body combined with stream match leads to stream buffering");
1198 if (has_stream && has_file_data_mpm)
1199 AnalyzerNote(&
ctx, (
char *)
"mpm in file_data combined with stream match leads to stream buffering");
1202 jb_open_object(
ctx.js,
"lists");
1212 if (pkt_mpm || app_mpm) {
1213 jb_open_object(
ctx.js,
"mpm");
1221 jb_set_string(
ctx.js,
"buffer", name);
1228 switch (smd->
type) {
1232 DumpContent(
ctx.js, cd);
1244 jb_open_object(
ctx.js,
"prefilter");
1251 jb_set_string(
ctx.js,
"buffer", name);
1253 jb_set_string(
ctx.js,
"name", mname);
1257 if (
ctx.js_warnings) {
1258 jb_close(
ctx.js_warnings);
1259 jb_set_object(
ctx.js,
"warnings",
ctx.js_warnings);
1260 jb_free(
ctx.js_warnings);
1261 ctx.js_warnings = NULL;
1264 jb_close(
ctx.js_notes);
1265 jb_set_object(
ctx.js,
"notes",
ctx.js_notes);
1266 jb_free(
ctx.js_notes);
1267 ctx.js_notes = NULL;
1271 const char *filename =
"rules.json";
1273 char json_path[PATH_MAX] =
"";
1274 snprintf(json_path,
sizeof(json_path),
"%s/%s%s", log_dir,
1278 FILE *fp = fopen(json_path,
"a");
1280 fwrite(jb_ptr(
ctx.js), jb_len(
ctx.js), 1, fp);
1294 JsonBuilder *root_jb = jb_new_object();
1298 jb_open_array(root_jb,
"buffers");
1302 char str[1024] =
"";
1306 JsonBuilder *jb = arrays[p->
sm_list];
1307 if (arrays[p->
sm_list] == NULL) {
1308 jb = arrays[p->
sm_list] = jb_new_object();
1314 jb_set_string(jb,
"name", name);
1315 jb_set_uint(jb,
"list_id", p->
sm_list);
1317 jb_open_array(jb,
"patterns");
1320 jb_start_object(jb);
1321 jb_set_string(jb,
"pattern",
str);
1323 jb_set_uint(jb,
"cnt", p->
cnt);
1324 jb_set_uint(jb,
"mpm", p->
mpm);
1325 jb_open_object(jb,
"flags");
1336 JsonBuilder *jb = arrays[i];
1343 jb_append_object(root_jb, jb);
1349 const char *filename =
"patterns.json";
1351 char json_path[PATH_MAX] =
"";
1352 snprintf(json_path,
sizeof(json_path),
"%s/%s%s", log_dir,
1356 FILE *fp = fopen(json_path,
"a");
1358 fwrite(jb_ptr(root_jb), jb_len(root_jb), 1, fp);
1379 EngineAnalysisItemsReset(ea_ctx);
1387 FatalError(
"Unable to allocate analysis scratch pad");
1397 analyzer_item->
item_id = (uint16_t)item_id;
1398 if (analyzer_item->
item_id == -1) {
1400 FatalError(
"unable to initialize engine-analysis table: detect buffer \"%s\" not "
1433 uint32_t rule_bidirectional = 0;
1434 uint32_t rule_pcre = 0;
1435 uint32_t rule_pcre_http = 0;
1436 uint32_t rule_content = 0;
1437 uint32_t rule_flow = 0;
1438 uint32_t rule_flags = 0;
1439 uint32_t rule_flow_toserver = 0;
1440 uint32_t rule_flow_toclient = 0;
1441 uint32_t rule_flow_nostream = 0;
1442 uint32_t rule_ipv4_only = 0;
1443 uint32_t rule_ipv6_only = 0;
1444 uint32_t rule_flowbits = 0;
1445 uint32_t rule_flowint = 0;
1446 uint32_t rule_content_http = 0;
1447 uint32_t rule_content_offset_depth = 0;
1448 int32_t list_id = 0;
1449 uint32_t rule_warning = 0;
1450 uint32_t stream_buf = 0;
1451 uint32_t packet_buf = 0;
1452 uint32_t file_store = 0;
1453 uint32_t warn_pcre_no_content = 0;
1454 uint32_t warn_pcre_http_content = 0;
1455 uint32_t warn_pcre_http = 0;
1456 uint32_t warn_content_http_content = 0;
1457 uint32_t warn_content_http = 0;
1458 uint32_t warn_tcp_no_flow = 0;
1459 uint32_t warn_client_ports = 0;
1460 uint32_t warn_direction = 0;
1461 uint32_t warn_method_toclient = 0;
1462 uint32_t warn_method_serverbody = 0;
1463 uint32_t warn_pcre_method = 0;
1464 uint32_t warn_encoding_norm_http_buf = 0;
1465 uint32_t warn_file_store_not_present = 0;
1466 uint32_t warn_offset_depth_pkt_stream = 0;
1467 uint32_t warn_offset_depth_alproto = 0;
1468 uint32_t warn_non_alproto_fp_for_alproto_sig = 0;
1469 uint32_t warn_no_direction = 0;
1470 uint32_t warn_both_direction = 0;
1472 EngineAnalysisItemsInit(
de_ctx->
ea);
1478 rule_bidirectional = 1;
1492 rule_ipv4_only += 1;
1495 rule_ipv6_only += 1;
1503 if (item_slot == -1) {
1511 if (item_slot == -1) {
1516 rule_content_offset_depth++;
1522 rule_content_http++;
1529 warn_encoding_norm_http_buf += 1;
1536 rule_flow_toserver = 1;
1539 rule_flow_toclient = 1;
1544 rule_flow_nostream = 1;
1569 warn_file_store_not_present = 1;
1572 if (rule_pcre > 0 && rule_content == 0 && rule_content_http == 0) {
1574 warn_pcre_no_content = 1;
1577 if (rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0) {
1579 warn_pcre_http_content = 1;
1585 if (rule_content > 0 && rule_content_http > 0) {
1587 warn_content_http_content = 1;
1591 warn_content_http = 1;
1593 if (rule_content == 1) {
1598 (rule_content || rule_content_http || rule_pcre || rule_pcre_http || rule_flowbits ||
1601 warn_tcp_no_flow = 1;
1603 if (rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1608 warn_client_ports = 1;
1611 if (rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)) {
1616 if (*http_method_item_seen_ptr) {
1617 if (rule_flow && rule_flow_toclient) {
1619 warn_method_toclient = 1;
1621 if (*http_server_body_item_seen_ptr) {
1623 warn_method_serverbody = 1;
1625 if (rule_content == 0 && rule_content_http == 0 && (rule_pcre > 0 || rule_pcre_http > 0)) {
1627 warn_pcre_method = 1;
1630 if (rule_content_offset_depth > 0 && stream_buf && packet_buf) {
1632 warn_offset_depth_pkt_stream = 1;
1636 warn_offset_depth_alproto = 1;
1641 warn_non_alproto_fp_for_alproto_sig = 1;
1645 warn_no_direction += 1;
1652 warn_both_direction += 1;
1657 if (!rule_warnings_only || (rule_warnings_only && rule_warning > 0)) {
1659 fprintf(fp,
"== Sid: %u ==\n", s->
id);
1660 fprintf(fp,
"%s\n", line);
1666 fprintf(fp,
" Rule is ip only.\n");
1669 fprintf(fp,
" Rule is like ip only.\n");
1672 fprintf(fp,
" Rule is PD only.\n");
1675 fprintf(fp,
" Rule is DE only.\n");
1678 fprintf(fp,
" Rule is packet inspecting.\n");
1681 fprintf(fp,
" Rule is packet and stream inspecting.\n");
1684 fprintf(fp,
" Rule is stream inspecting.\n");
1687 fprintf(fp,
" Rule is app-layer inspecting.\n");
1690 fprintf(fp,
" Rule is App-layer TX inspecting.\n");
1696 fprintf(fp,
" Rule is IPv6 only.\n");
1698 fprintf(fp,
" Rule is IPv4 only.\n");
1700 fprintf(fp,
" Rule matches on packets.\n");
1701 if (!rule_flow_nostream && stream_buf &&
1702 (rule_flow || rule_flowbits || rule_flowint || rule_content || rule_pcre)) {
1703 fprintf(fp,
" Rule matches on reassembled stream.\n");
1708 fprintf(fp,
" Rule matches on %s buffer.\n", ai->
display_name);
1714 if (rule_content || rule_content_http || rule_pcre || rule_pcre_http) {
1716 " Rule contains %u content options, %u http content options, %u pcre "
1717 "options, and %u pcre options with http modifiers.\n",
1718 rule_content, rule_content_http, rule_pcre, rule_pcre_http);
1723 fprintf(fp,
" Prefilter on: %s.\n",
1726 EngineAnalysisRulesPrintFP(
de_ctx, s);
1730 if (warn_pcre_no_content ) {
1731 fprintf(fp,
" Warning: Rule uses pcre without a content option present.\n"
1732 " -Consider adding a content to improve performance of this "
1735 if (warn_pcre_http_content ) {
1736 fprintf(fp,
" Warning: Rule uses content options with http_* and pcre options "
1737 "without http modifiers.\n"
1738 " -Consider adding http pcre modifier.\n");
1740 else if (warn_pcre_http ) {
1741 fprintf(fp,
" Warning: Rule app layer protocol is http, but pcre options do not "
1742 "have http modifiers.\n"
1743 " -Consider adding http pcre modifiers.\n");
1745 if (warn_content_http_content ) {
1747 " Warning: Rule contains content with http_* and content without http_*.\n"
1748 " -Consider adding http content modifiers.\n");
1750 if (warn_content_http ) {
1751 fprintf(fp,
" Warning: Rule app layer protocol is http, but content options do not "
1752 "have http_* modifiers.\n"
1753 " -Consider adding http content modifiers.\n");
1755 if (rule_content == 1) {
1758 if (warn_encoding_norm_http_buf) {
1759 fprintf(fp,
" Warning: Rule may contain percent encoded content for a normalized "
1760 "http buffer match.\n");
1762 if (warn_tcp_no_flow
1764 fprintf(fp,
" Warning: TCP rule without a flow or flags option.\n"
1765 " -Consider adding flow or flags to improve performance of "
1768 if (warn_client_ports
1773 " Warning: Rule contains ports or port variables only on the client side.\n"
1774 " -Flow direction possibly inconsistent with rule.\n");
1776 if (warn_direction ) {
1777 fprintf(fp,
" Warning: Rule is bidirectional and has a flow option with a specific "
1780 if (warn_method_toclient ) {
1781 fprintf(fp,
" Warning: Rule uses content or pcre for http_method with "
1782 "flow:to_client or from_server\n");
1784 if (warn_method_serverbody ) {
1785 fprintf(fp,
" Warning: Rule uses content or pcre for http_method with content or "
1786 "pcre for http_server_body.\n");
1788 if (warn_pcre_method
1790 fprintf(fp,
" Warning: Rule uses pcre with only a http_method content; possible "
1791 "performance issue.\n");
1793 if (warn_offset_depth_pkt_stream) {
1794 fprintf(fp,
" Warning: Rule has depth"
1795 "/offset with raw content keywords. Please note the "
1796 "offset/depth will be checked against both packet "
1797 "payloads and stream. If you meant to have the offset/"
1798 "depth checked against just the payload, you can update "
1799 "the signature as \"alert tcp-pkt...\"\n");
1801 if (warn_offset_depth_alproto) {
1803 " Warning: Rule has "
1804 "offset/depth set along with a match on a specific "
1805 "app layer protocol - %d. This can lead to FNs if we "
1806 "have a offset/depth content match on a packet payload "
1807 "before we can detect the app layer protocol for the "
1811 if (warn_non_alproto_fp_for_alproto_sig) {
1812 fprintf(fp,
" Warning: Rule app layer "
1813 "protocol is http, but the fast_pattern is set on the raw "
1814 "stream. Consider adding fast_pattern over a http "
1815 "buffer for increased performance.");
1817 if (warn_no_direction) {
1818 fprintf(fp,
" Warning: Rule has no direction indicator.\n");
1820 if (warn_both_direction) {
1821 fprintf(fp,
" Warning: Rule is inspecting both the request and the response.\n");
1823 if (warn_file_store_not_present) {
1824 fprintf(fp,
" Warning: Rule requires file-store but the output file-store is not "
1827 if (rule_warning == 0) {
1828 fprintf(fp,
" No warnings for this rule.\n");