57 static int rule_warnings_only = 0;
113 { 0,
false,
false,
true,
"http_uri",
"http uri" },
114 { 0,
false,
false,
false,
"http_raw_uri",
"http raw uri" },
115 { 0,
false,
true,
false,
"http_method",
"http method" },
116 { 0,
false,
false,
false,
"http_request_line",
"http request line" },
117 { 0,
false,
false,
false,
"http_client_body",
"http client body" },
118 { 0,
false,
false,
true,
"http_header",
"http header" },
119 { 0,
false,
false,
false,
"http_raw_header",
"http raw header" },
120 { 0,
false,
false,
true,
"http_cookie",
"http cookie" },
121 { 0,
false,
false,
false,
"http_user_agent",
"http user agent" },
122 { 0,
false,
false,
false,
"http_host",
"http host" },
123 { 0,
false,
false,
false,
"http_raw_host",
"http raw host" },
124 { 0,
false,
false,
false,
"http_accept_enc",
"http accept enc" },
125 { 0,
false,
false,
false,
"http_referer",
"http referer" },
126 { 0,
false,
false,
false,
"http_content_type",
"http content type" },
127 { 0,
false,
false,
false,
"http_header_names",
"http header names" },
130 { 0,
false,
false,
false,
"http_stat_msg",
"http stat msg" },
131 { 0,
false,
false,
false,
"http_stat_code",
"http stat code" },
132 { 0,
false,
true,
false,
"file_data",
"http server body" },
135 { 0,
false,
false,
false,
"http_request_line",
"http request line" },
136 { 0,
false,
false,
false,
"http_accept",
"http accept" },
137 { 0,
false,
false,
false,
"http_accept_lang",
"http accept lang" },
138 { 0,
false,
false,
false,
"http_connection",
"http connection" },
139 { 0,
false,
false,
false,
"http_content_len",
"http content len" },
140 { 0,
false,
false,
false,
"http_protocol",
"http protocol" },
141 { 0,
false,
false,
false,
"http_start",
"http start" },
144 { 0,
false,
false,
false,
"http_response_line",
"http response line" },
145 { 0,
false,
false,
false,
"http.server",
"http server" },
146 { 0,
false,
false,
false,
"http.location",
"http location" },
149 static void FpPatternStatsAdd(
FpPatternStats *fp,
int list, uint16_t patlen)
158 else if (patlen < f->min)
170 int fast_pattern_set = 0;
171 int fast_pattern_only_set = 0;
172 int fast_pattern_chop_set = 0;
177 if (mpm_sm != NULL) {
180 fast_pattern_set = 1;
182 fast_pattern_only_set = 1;
184 fast_pattern_chop_set = 1;
190 fprintf(fp,
"== Sid: %u ==\n", s->
id);
191 fprintf(fp,
"%s\n", line);
193 fprintf(fp,
" Fast Pattern analysis:\n");
195 fprintf(fp,
" Prefilter on: %s\n",
202 fprintf(fp,
" No content present\n");
207 fprintf(fp,
" Fast pattern matcher: ");
208 int list_type = mpm_sm_list;
210 fprintf(fp,
"content\n");
215 fprintf(fp,
"%s (%s)\n", desc, name);
220 fprintf(fp,
" Flags:");
222 fprintf(fp,
" Offset");
225 fprintf(fp,
" Depth");
229 fprintf(fp,
" Within");
233 fprintf(fp,
" Distance");
237 fprintf(fp,
" Nocase");
241 fprintf(fp,
" Negated");
245 fprintf(fp,
" None");
248 fprintf(fp,
" Fast pattern set: %s\n", fast_pattern_set ?
"yes" :
"no");
249 fprintf(fp,
" Fast pattern only set: %s\n", fast_pattern_only_set ?
"yes" :
"no");
250 fprintf(fp,
" Fast pattern chop set: %s\n", fast_pattern_chop_set ?
"yes" :
"no");
251 if (fast_pattern_chop_set) {
252 fprintf(fp,
" Fast pattern offset, length: %u, %u\n", fp_cd->
fp_chop_offset,
263 fprintf(fp,
" Original content: ");
267 if (fast_pattern_chop_set) {
276 fprintf(fp,
" Final content: ");
282 fprintf(fp,
" Final content: ");
301 int fp_engine_analysis_set = 0;
303 if ((
ConfGetBool(
"engine-analysis.rules-fast-pattern",
304 &fp_engine_analysis_set)) == 0) {
308 if (fp_engine_analysis_set == 0)
312 char *log_path =
SCMalloc(PATH_MAX);
313 if (log_path == NULL) {
314 FatalError(
"Unable to allocate scratch memory for rule filename");
316 snprintf(log_path, PATH_MAX,
"%s/%s%s", log_dir,
319 FILE *fp = fopen(log_path,
"w");
321 SCLogError(
"failed to open %s: %s", log_path, strerror(errno));
328 SCLogInfo(
"Engine-Analysis for fast_pattern printed to file - %s",
333 gettimeofday(&tval, NULL);
335 struct tm *tms =
SCLocalTime(tval.tv_sec, &local_tm);
336 fprintf(fp,
"----------------------------------------------"
337 "---------------------\n");
339 "Date: %" PRId32
"/%" PRId32
"/%04d -- "
341 tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min,
343 fprintf(fp,
"----------------------------------------------"
344 "---------------------\n");
357 #define DETECT_PERCENT_ENCODING_REGEX "%[0-9|a-f|A-F]{2}"
363 PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
365 PCRE2_UCHAR errbuffer[256];
366 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
387 }
else if (value && strcasecmp(value,
"warnings-only") == 0) {
389 rule_warnings_only = 1;
394 char log_path[PATH_MAX];
395 snprintf(log_path,
sizeof(log_path),
"%s/%s%s", log_dir,
399 SCLogError(
"failed to open %s: %s", log_path, strerror(errno));
403 SCLogInfo(
"Engine-Analysis for rules printed to file - %s",
407 gettimeofday(&tval, NULL);
409 struct tm *tms =
SCLocalTime(tval.tv_sec, &local_tm);
411 "----------------------------------------------"
412 "---------------------\n");
414 "Date: %" PRId32
"/%" PRId32
"/%04d -- "
416 tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min,
419 "----------------------------------------------"
420 "---------------------\n");
423 if (!PerCentEncodingSetup(
de_ctx->
ea)) {
425 "Error compiling regex; can't check for percent encoding in normalized "
431 SCLogInfo(
"Conf parameter \"engine-analysis.rules\" not found. "
432 "Defaulting to not printing the rules analysis report.");
435 SCLogInfo(
"Engine-Analysis for rules disabled in conf file.");
444 fprintf(fp,
"============\n"
445 "Summary:\n============\n");
453 "%s, smallest pattern %u byte(s), longest pattern %u byte(s), number of patterns "
454 "%u, avg pattern len %.2f byte(s)\n",
456 (
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) {
645 vsnprintf(
str,
sizeof(
str), fmt, ap);
649 ctx->js_notes = jb_new_array();
651 jb_append_string(
ctx->js_notes,
str);
660 vsnprintf(
str,
sizeof(
str), fmt, ap);
663 if (!
ctx->js_warnings)
664 ctx->js_warnings = jb_new_array();
665 if (
ctx->js_warnings)
666 jb_append_string(
ctx->js_warnings,
str);
669 #define CHECK(pat) if (strlen((pat)) <= len && memcmp((pat), buf, MIN(len, strlen((pat)))) == 0) return true;
671 static bool LooksLikeHTTPMethod(
const uint8_t *buf, uint16_t
len)
680 static bool LooksLikeHTTPUA(
const uint8_t *buf, uint16_t
len)
682 CHECK(
"User-Agent: ");
683 CHECK(
"\nUser-Agent: ");
689 char pattern_str[1024] =
"";
692 jb_set_string(js,
"pattern", pattern_str);
701 jb_set_uint(js,
"offset", cd->
offset);
704 jb_set_uint(js,
"depth", cd->
depth);
707 jb_set_int(js,
"distance", cd->
distance);
710 jb_set_int(js,
"within", cd->
within);
729 jb_open_array(js,
"matches");
733 jb_set_string(js,
"name", mname);
739 jb_open_object(js,
"content");
742 AnalyzerNote(
ctx, (
char *)
"'fast_pattern:only' option is silently ignored and "
743 "is interpreted as regular 'fast_pattern'");
747 (
char *)
"pattern looks like it inspects HTTP, use http.request_line or "
748 "http.method and http.uri instead for improved performance");
752 (
char *)
"pattern looks like it inspects HTTP, use http.user_agent "
753 "or http.header for improved performance");
756 AnalyzerNote(
ctx, (
char *)
"'within' option for pattern w/o previous content "
757 "was converted to 'depth'");
760 AnalyzerNote(
ctx, (
char *)
"'distance' option for pattern w/o previous content "
761 "was converted to 'offset'");
769 jb_open_object(js,
"pcre");
774 (
char *)
"'/B' (rawbytes) option is a no-op and is silently ignored");
781 jb_open_object(js,
"byte_jump");
782 jb_set_uint(js,
"nbytes", cd->
nbytes);
783 jb_set_int(js,
"offset", cd->
offset);
784 jb_set_uint(js,
"multiplier", cd->
multiplier);
788 jb_set_string(js,
"base",
"unset");
791 jb_set_string(js,
"base",
"oct");
794 jb_set_string(js,
"base",
"dec");
797 jb_set_string(js,
"base",
"hex");
800 jb_open_array(js,
"flags");
802 jb_append_string(js,
"from_beginning");
804 jb_append_string(js,
"little_endian");
806 jb_append_string(js,
"big_endian");
808 jb_append_string(js,
"string");
810 jb_append_string(js,
"relative");
812 jb_append_string(js,
"align");
814 jb_append_string(js,
"dce");
816 jb_append_string(js,
"offset_be");
818 jb_append_string(js,
"from_end");
826 jb_open_object(js,
"byte_test");
827 jb_set_uint(js,
"nbytes", cd->
nbytes);
828 jb_set_int(js,
"offset", cd->
offset);
831 jb_set_string(js,
"base",
"unset");
834 jb_set_string(js,
"base",
"oct");
837 jb_set_string(js,
"base",
"dec");
840 jb_set_string(js,
"base",
"hex");
843 jb_open_array(js,
"flags");
845 jb_append_string(js,
"little_endian");
847 jb_append_string(js,
"big_endian");
849 jb_append_string(js,
"string");
851 jb_append_string(js,
"relative");
853 jb_append_string(js,
"dce");
861 jb_open_object(js,
"ipopts");
863 jb_set_string(js,
"option", flag);
870 jb_open_object(js,
"flowbits");
873 jb_set_string(js,
"cmd",
"isset");
876 jb_set_string(js,
"cmd",
"isnotset");
879 jb_set_string(js,
"cmd",
"set");
882 jb_set_string(js,
"cmd",
"unset");
885 jb_set_string(js,
"cmd",
"toggle");
889 jb_open_array(js,
"names");
895 const char *varname =
897 jb_append_string(js, varname);
902 jb_set_string(js,
"operator",
"or");
910 jb_open_object(js,
"ack");
911 jb_set_uint(js,
"number", cd->
ack);
917 jb_open_object(js,
"seq");
918 jb_set_uint(js,
"number", cd->
seq);
924 jb_open_object(js,
"tcp_mss");
925 SCDetectU16ToJson(js, cd);
931 jb_open_object(js,
"id");
932 jb_set_uint(js,
"number",
SCNtohs(cd->
id));
938 jb_open_object(js,
"window");
939 jb_set_uint(js,
"size", wd->
size);
940 jb_set_bool(js,
"negated", wd->
negated);
946 jb_open_object(js,
"flow_age");
947 SCDetectU32ToJson(js, cd);
968 ctx.js = jb_new_object();
973 jb_set_uint(
ctx.js,
"id", s->
id);
974 jb_set_uint(
ctx.js,
"gid", s->
gid);
975 jb_set_uint(
ctx.js,
"rev", s->
rev);
976 jb_set_string(
ctx.js,
"msg", s->
msg);
979 jb_set_string(
ctx.js,
"app_proto", alproto);
981 jb_open_array(
ctx.js,
"requirements");
983 jb_append_string(
ctx.js,
"payload");
986 jb_append_string(
ctx.js,
"no_payload");
989 jb_append_string(
ctx.js,
"flow");
992 jb_append_string(
ctx.js,
"tcp_flags_init_deinit");
995 jb_append_string(
ctx.js,
"tcp_flags_unusual");
998 jb_append_string(
ctx.js,
"engine_event");
1001 jb_append_string(
ctx.js,
"real_pkt");
1007 jb_set_string(
ctx.js,
"type",
"unset");
1010 jb_set_string(
ctx.js,
"type",
"ip_only");
1013 jb_set_string(
ctx.js,
"type",
"like_ip_only");
1016 jb_set_string(
ctx.js,
"type",
"pd_only");
1019 jb_set_string(
ctx.js,
"type",
"de_only");
1022 jb_set_string(
ctx.js,
"type",
"pkt");
1025 jb_set_string(
ctx.js,
"type",
"pkt_stream");
1028 jb_set_string(
ctx.js,
"type",
"stream");
1031 jb_set_string(
ctx.js,
"type",
"app_layer");
1034 jb_set_string(
ctx.js,
"type",
"app_tx");
1037 jb_set_string(
ctx.js,
"type",
"error");
1041 jb_open_array(
ctx.js,
"flags");
1043 jb_append_string(
ctx.js,
"src_any");
1046 jb_append_string(
ctx.js,
"dst_any");
1049 jb_append_string(
ctx.js,
"sp_any");
1052 jb_append_string(
ctx.js,
"dp_any");
1055 jb_append_string(
ctx.js,
"noalert");
1058 jb_append_string(
ctx.js,
"dsize");
1061 jb_append_string(
ctx.js,
"applayer");
1064 jb_append_string(
ctx.js,
"need_packet");
1067 jb_append_string(
ctx.js,
"need_stream");
1070 jb_append_string(
ctx.js,
"negated_mpm");
1073 jb_append_string(
ctx.js,
"flush");
1076 jb_append_string(
ctx.js,
"need_flowvar");
1079 jb_append_string(
ctx.js,
"filestore");
1082 jb_append_string(
ctx.js,
"toserver");
1085 jb_append_string(
ctx.js,
"toclient");
1088 jb_append_string(
ctx.js,
"tlsstore");
1091 jb_append_string(
ctx.js,
"bypass");
1094 jb_append_string(
ctx.js,
"prefilter");
1097 jb_append_string(
ctx.js,
"src_is_target");
1100 jb_append_string(
ctx.js,
"dst_is_target");
1107 jb_open_array(
ctx.js,
"pkt_engines");
1109 for ( ; pkt != NULL; pkt = pkt->
next) {
1124 jb_start_object(
ctx.js);
1125 jb_set_string(
ctx.js,
"name", name);
1126 jb_set_bool(
ctx.js,
"is_mpm", pkt->
mpm);
1128 jb_open_array(
ctx.js,
"transforms");
1130 jb_start_object(
ctx.js);
1131 jb_set_string(
ctx.js,
"name",
1144 jb_open_array(
ctx.js,
"frame_engines");
1146 for (; frame != NULL; frame = frame->
next) {
1148 jb_start_object(
ctx.js);
1149 jb_set_string(
ctx.js,
"name", name);
1150 jb_set_bool(
ctx.js,
"is_mpm", frame->
mpm);
1152 jb_open_array(
ctx.js,
"transforms");
1154 jb_start_object(
ctx.js);
1155 jb_set_string(
ctx.js,
"name",
1167 bool has_stream =
false;
1168 bool has_client_body_mpm =
false;
1169 bool has_file_data_mpm =
false;
1171 jb_open_array(
ctx.js,
"engines");
1173 for ( ; app != NULL; app = app->
next) {
1188 }
else if (app->
mpm && strcmp(name,
"http_client_body") == 0) {
1189 has_client_body_mpm =
true;
1190 }
else if (app->
mpm && strcmp(name,
"file_data") == 0) {
1191 has_file_data_mpm =
true;
1194 jb_start_object(
ctx.js);
1195 jb_set_string(
ctx.js,
"name", name);
1196 const char *direction = app->
dir == 0 ?
"toserver" :
"toclient";
1197 jb_set_string(
ctx.js,
"direction", direction);
1198 jb_set_bool(
ctx.js,
"is_mpm", app->
mpm);
1203 jb_open_array(
ctx.js,
"transforms");
1205 jb_start_object(
ctx.js);
1206 jb_set_string(
ctx.js,
"name",
1220 if (has_stream && has_client_body_mpm)
1221 AnalyzerNote(&
ctx, (
char *)
"mpm in http_client_body combined with stream match leads to stream buffering");
1222 if (has_stream && has_file_data_mpm)
1223 AnalyzerNote(&
ctx, (
char *)
"mpm in file_data combined with stream match leads to stream buffering");
1226 jb_open_object(
ctx.js,
"lists");
1236 if (pkt_mpm || app_mpm) {
1237 jb_open_object(
ctx.js,
"mpm");
1245 jb_set_string(
ctx.js,
"buffer", name);
1252 switch (smd->
type) {
1256 DumpContent(
ctx.js, cd);
1268 jb_open_object(
ctx.js,
"prefilter");
1275 jb_set_string(
ctx.js,
"buffer", name);
1277 jb_set_string(
ctx.js,
"name", mname);
1281 if (
ctx.js_warnings) {
1282 jb_close(
ctx.js_warnings);
1283 jb_set_object(
ctx.js,
"warnings",
ctx.js_warnings);
1284 jb_free(
ctx.js_warnings);
1285 ctx.js_warnings = NULL;
1288 jb_close(
ctx.js_notes);
1289 jb_set_object(
ctx.js,
"notes",
ctx.js_notes);
1290 jb_free(
ctx.js_notes);
1291 ctx.js_notes = NULL;
1295 const char *filename =
"rules.json";
1297 char json_path[PATH_MAX] =
"";
1298 snprintf(json_path,
sizeof(json_path),
"%s/%s%s", log_dir,
1302 FILE *fp = fopen(json_path,
"a");
1304 fwrite(jb_ptr(
ctx.js), jb_len(
ctx.js), 1, fp);
1318 JsonBuilder *root_jb = jb_new_object();
1322 jb_open_array(root_jb,
"buffers");
1326 char str[1024] =
"";
1330 JsonBuilder *jb = arrays[p->
sm_list];
1331 if (arrays[p->
sm_list] == NULL) {
1332 jb = arrays[p->
sm_list] = jb_new_object();
1338 jb_set_string(jb,
"name", name);
1339 jb_set_uint(jb,
"list_id", p->
sm_list);
1341 jb_open_array(jb,
"patterns");
1344 jb_start_object(jb);
1345 jb_set_string(jb,
"pattern",
str);
1347 jb_set_uint(jb,
"cnt", p->
cnt);
1348 jb_set_uint(jb,
"mpm", p->
mpm);
1349 jb_open_object(jb,
"flags");
1360 JsonBuilder *jb = arrays[i];
1367 jb_append_object(root_jb, jb);
1373 const char *filename =
"patterns.json";
1375 char json_path[PATH_MAX] =
"";
1376 snprintf(json_path,
sizeof(json_path),
"%s/%s%s", log_dir,
1380 FILE *fp = fopen(json_path,
"a");
1382 fwrite(jb_ptr(root_jb), jb_len(root_jb), 1, fp);
1403 EngineAnalysisItemsReset(ea_ctx);
1411 FatalError(
"Unable to allocate analysis scratch pad");
1421 analyzer_item->
item_id = (uint16_t)item_id;
1422 if (analyzer_item->
item_id == -1) {
1424 FatalError(
"unable to initialize engine-analysis table: detect buffer \"%s\" not "
1457 uint32_t rule_bidirectional = 0;
1458 uint32_t rule_pcre = 0;
1459 uint32_t rule_pcre_http = 0;
1460 uint32_t rule_content = 0;
1461 uint32_t rule_flow = 0;
1462 uint32_t rule_flags = 0;
1463 uint32_t rule_flow_toserver = 0;
1464 uint32_t rule_flow_toclient = 0;
1465 uint32_t rule_flow_nostream = 0;
1466 uint32_t rule_ipv4_only = 0;
1467 uint32_t rule_ipv6_only = 0;
1468 uint32_t rule_flowbits = 0;
1469 uint32_t rule_flowint = 0;
1470 uint32_t rule_content_http = 0;
1471 uint32_t rule_content_offset_depth = 0;
1472 int32_t list_id = 0;
1473 uint32_t rule_warning = 0;
1474 uint32_t stream_buf = 0;
1475 uint32_t packet_buf = 0;
1476 uint32_t file_store = 0;
1477 uint32_t warn_pcre_no_content = 0;
1478 uint32_t warn_pcre_http_content = 0;
1479 uint32_t warn_pcre_http = 0;
1480 uint32_t warn_content_http_content = 0;
1481 uint32_t warn_content_http = 0;
1482 uint32_t warn_tcp_no_flow = 0;
1483 uint32_t warn_client_ports = 0;
1484 uint32_t warn_direction = 0;
1485 uint32_t warn_method_toclient = 0;
1486 uint32_t warn_method_serverbody = 0;
1487 uint32_t warn_pcre_method = 0;
1488 uint32_t warn_encoding_norm_http_buf = 0;
1489 uint32_t warn_file_store_not_present = 0;
1490 uint32_t warn_offset_depth_pkt_stream = 0;
1491 uint32_t warn_offset_depth_alproto = 0;
1492 uint32_t warn_non_alproto_fp_for_alproto_sig = 0;
1493 uint32_t warn_no_direction = 0;
1494 uint32_t warn_both_direction = 0;
1496 EngineAnalysisItemsInit(
de_ctx->
ea);
1502 rule_bidirectional = 1;
1516 rule_ipv4_only += 1;
1519 rule_ipv6_only += 1;
1527 if (item_slot == -1) {
1535 if (item_slot == -1) {
1540 rule_content_offset_depth++;
1546 rule_content_http++;
1553 warn_encoding_norm_http_buf += 1;
1560 rule_flow_toserver = 1;
1563 rule_flow_toclient = 1;
1568 rule_flow_nostream = 1;
1593 warn_file_store_not_present = 1;
1596 if (rule_pcre > 0 && rule_content == 0 && rule_content_http == 0) {
1598 warn_pcre_no_content = 1;
1601 if (rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0) {
1603 warn_pcre_http_content = 1;
1609 if (rule_content > 0 && rule_content_http > 0) {
1611 warn_content_http_content = 1;
1615 warn_content_http = 1;
1617 if (rule_content == 1) {
1622 (rule_content || rule_content_http || rule_pcre || rule_pcre_http || rule_flowbits ||
1625 warn_tcp_no_flow = 1;
1627 if (rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1632 warn_client_ports = 1;
1635 if (rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)) {
1640 if (*http_method_item_seen_ptr) {
1641 if (rule_flow && rule_flow_toclient) {
1643 warn_method_toclient = 1;
1645 if (*http_server_body_item_seen_ptr) {
1647 warn_method_serverbody = 1;
1649 if (rule_content == 0 && rule_content_http == 0 && (rule_pcre > 0 || rule_pcre_http > 0)) {
1651 warn_pcre_method = 1;
1654 if (rule_content_offset_depth > 0 && stream_buf && packet_buf) {
1656 warn_offset_depth_pkt_stream = 1;
1660 warn_offset_depth_alproto = 1;
1665 warn_non_alproto_fp_for_alproto_sig = 1;
1669 warn_no_direction += 1;
1676 warn_both_direction += 1;
1681 if (!rule_warnings_only || (rule_warnings_only && rule_warning > 0)) {
1683 fprintf(fp,
"== Sid: %u ==\n", s->
id);
1684 fprintf(fp,
"%s\n", line);
1690 fprintf(fp,
" Rule is ip only.\n");
1693 fprintf(fp,
" Rule is like ip only.\n");
1696 fprintf(fp,
" Rule is PD only.\n");
1699 fprintf(fp,
" Rule is DE only.\n");
1702 fprintf(fp,
" Rule is packet inspecting.\n");
1705 fprintf(fp,
" Rule is packet and stream inspecting.\n");
1708 fprintf(fp,
" Rule is stream inspecting.\n");
1711 fprintf(fp,
" Rule is app-layer inspecting.\n");
1714 fprintf(fp,
" Rule is App-layer TX inspecting.\n");
1720 fprintf(fp,
" Rule is IPv6 only.\n");
1722 fprintf(fp,
" Rule is IPv4 only.\n");
1724 fprintf(fp,
" Rule matches on packets.\n");
1725 if (!rule_flow_nostream && stream_buf &&
1726 (rule_flow || rule_flowbits || rule_flowint || rule_content || rule_pcre)) {
1727 fprintf(fp,
" Rule matches on reassembled stream.\n");
1732 fprintf(fp,
" Rule matches on %s buffer.\n", ai->
display_name);
1738 if (rule_content || rule_content_http || rule_pcre || rule_pcre_http) {
1740 " Rule contains %u content options, %u http content options, %u pcre "
1741 "options, and %u pcre options with http modifiers.\n",
1742 rule_content, rule_content_http, rule_pcre, rule_pcre_http);
1747 fprintf(fp,
" Prefilter on: %s.\n",
1750 EngineAnalysisRulesPrintFP(
de_ctx, s);
1754 if (warn_pcre_no_content ) {
1755 fprintf(fp,
" Warning: Rule uses pcre without a content option present.\n"
1756 " -Consider adding a content to improve performance of this "
1759 if (warn_pcre_http_content ) {
1760 fprintf(fp,
" Warning: Rule uses content options with http_* and pcre options "
1761 "without http modifiers.\n"
1762 " -Consider adding http pcre modifier.\n");
1764 else if (warn_pcre_http ) {
1765 fprintf(fp,
" Warning: Rule app layer protocol is http, but pcre options do not "
1766 "have http modifiers.\n"
1767 " -Consider adding http pcre modifiers.\n");
1769 if (warn_content_http_content ) {
1771 " Warning: Rule contains content with http_* and content without http_*.\n"
1772 " -Consider adding http content modifiers.\n");
1774 if (warn_content_http ) {
1775 fprintf(fp,
" Warning: Rule app layer protocol is http, but content options do not "
1776 "have http_* modifiers.\n"
1777 " -Consider adding http content modifiers.\n");
1779 if (rule_content == 1) {
1782 if (warn_encoding_norm_http_buf) {
1783 fprintf(fp,
" Warning: Rule may contain percent encoded content for a normalized "
1784 "http buffer match.\n");
1786 if (warn_tcp_no_flow
1788 fprintf(fp,
" Warning: TCP rule without a flow or flags option.\n"
1789 " -Consider adding flow or flags to improve performance of "
1792 if (warn_client_ports
1797 " Warning: Rule contains ports or port variables only on the client side.\n"
1798 " -Flow direction possibly inconsistent with rule.\n");
1800 if (warn_direction ) {
1801 fprintf(fp,
" Warning: Rule is bidirectional and has a flow option with a specific "
1804 if (warn_method_toclient ) {
1805 fprintf(fp,
" Warning: Rule uses content or pcre for http_method with "
1806 "flow:to_client or from_server\n");
1808 if (warn_method_serverbody ) {
1809 fprintf(fp,
" Warning: Rule uses content or pcre for http_method with content or "
1810 "pcre for http_server_body.\n");
1812 if (warn_pcre_method
1814 fprintf(fp,
" Warning: Rule uses pcre with only a http_method content; possible "
1815 "performance issue.\n");
1817 if (warn_offset_depth_pkt_stream) {
1818 fprintf(fp,
" Warning: Rule has depth"
1819 "/offset with raw content keywords. Please note the "
1820 "offset/depth will be checked against both packet "
1821 "payloads and stream. If you meant to have the offset/"
1822 "depth checked against just the payload, you can update "
1823 "the signature as \"alert tcp-pkt...\"\n");
1825 if (warn_offset_depth_alproto) {
1827 " Warning: Rule has "
1828 "offset/depth set along with a match on a specific "
1829 "app layer protocol - %d. This can lead to FNs if we "
1830 "have a offset/depth content match on a packet payload "
1831 "before we can detect the app layer protocol for the "
1835 if (warn_non_alproto_fp_for_alproto_sig) {
1836 fprintf(fp,
" Warning: Rule app layer "
1837 "protocol is http, but the fast_pattern is set on the raw "
1838 "stream. Consider adding fast_pattern over a http "
1839 "buffer for increased performance.");
1841 if (warn_no_direction) {
1842 fprintf(fp,
" Warning: Rule has no direction indicator.\n");
1844 if (warn_both_direction) {
1845 fprintf(fp,
" Warning: Rule is inspecting both the request and the response.\n");
1847 if (warn_file_store_not_present) {
1848 fprintf(fp,
" Warning: Rule requires file-store but the output file-store is not "
1851 if (rule_warning == 0) {
1852 fprintf(fp,
" No warnings for this rule.\n");