58 static int rule_warnings_only = 0;
114 { 0,
false,
false,
true,
"http_uri",
"http uri" },
115 { 0,
false,
false,
false,
"http_raw_uri",
"http raw uri" },
116 { 0,
false,
true,
false,
"http_method",
"http method" },
117 { 0,
false,
false,
false,
"http_request_line",
"http request line" },
118 { 0,
false,
false,
false,
"http_client_body",
"http client body" },
119 { 0,
false,
false,
true,
"http_header",
"http header" },
120 { 0,
false,
false,
false,
"http_raw_header",
"http raw header" },
121 { 0,
false,
false,
true,
"http_cookie",
"http cookie" },
122 { 0,
false,
false,
false,
"http_user_agent",
"http user agent" },
123 { 0,
false,
false,
false,
"http_host",
"http host" },
124 { 0,
false,
false,
false,
"http_raw_host",
"http raw host" },
125 { 0,
false,
false,
false,
"http_accept_enc",
"http accept enc" },
126 { 0,
false,
false,
false,
"http_referer",
"http referer" },
127 { 0,
false,
false,
false,
"http_content_type",
"http content type" },
128 { 0,
false,
false,
false,
"http_header_names",
"http header names" },
131 { 0,
false,
false,
false,
"http_stat_msg",
"http stat msg" },
132 { 0,
false,
false,
false,
"http_stat_code",
"http stat code" },
133 { 0,
false,
true,
false,
"file_data",
"http server body" },
136 { 0,
false,
false,
false,
"http_request_line",
"http request line" },
137 { 0,
false,
false,
false,
"http_accept",
"http accept" },
138 { 0,
false,
false,
false,
"http_accept_lang",
"http accept lang" },
139 { 0,
false,
false,
false,
"http_connection",
"http connection" },
140 { 0,
false,
false,
false,
"http_content_len",
"http content len" },
141 { 0,
false,
false,
false,
"http_protocol",
"http protocol" },
142 { 0,
false,
false,
false,
"http_start",
"http start" },
145 { 0,
false,
false,
false,
"http_response_line",
"http response line" },
146 { 0,
false,
false,
false,
"http.server",
"http server" },
147 { 0,
false,
false,
false,
"http.location",
"http location" },
150 static void FpPatternStatsAdd(
FpPatternStats *fp,
int list, uint16_t patlen)
159 else if (patlen < f->min)
171 int fast_pattern_set = 0;
172 int fast_pattern_only_set = 0;
173 int fast_pattern_chop_set = 0;
178 if (mpm_sm != NULL) {
181 fast_pattern_set = 1;
183 fast_pattern_only_set = 1;
185 fast_pattern_chop_set = 1;
191 fprintf(fp,
"== Sid: %u ==\n", s->
id);
192 fprintf(fp,
"%s\n", line);
194 fprintf(fp,
" Fast Pattern analysis:\n");
196 fprintf(fp,
" Prefilter on: %s\n",
203 fprintf(fp,
" No content present\n");
208 fprintf(fp,
" Fast pattern matcher: ");
209 int list_type = mpm_sm_list;
211 fprintf(fp,
"content\n");
216 fprintf(fp,
"%s (%s)\n", desc,
name);
221 fprintf(fp,
" Flags:");
223 fprintf(fp,
" Offset");
226 fprintf(fp,
" Depth");
230 fprintf(fp,
" Within");
234 fprintf(fp,
" Distance");
238 fprintf(fp,
" Nocase");
242 fprintf(fp,
" Negated");
246 fprintf(fp,
" None");
249 fprintf(fp,
" Fast pattern set: %s\n", fast_pattern_set ?
"yes" :
"no");
250 fprintf(fp,
" Fast pattern only set: %s\n", fast_pattern_only_set ?
"yes" :
"no");
251 fprintf(fp,
" Fast pattern chop set: %s\n", fast_pattern_chop_set ?
"yes" :
"no");
252 if (fast_pattern_chop_set) {
253 fprintf(fp,
" Fast pattern offset, length: %u, %u\n", fp_cd->
fp_chop_offset,
264 fprintf(fp,
" Original content: ");
268 if (fast_pattern_chop_set) {
277 fprintf(fp,
" Final content: ");
283 fprintf(fp,
" Final content: ");
302 int fp_engine_analysis_set = 0;
304 if ((
ConfGetBool(
"engine-analysis.rules-fast-pattern",
305 &fp_engine_analysis_set)) == 0) {
309 if (fp_engine_analysis_set == 0)
313 char *log_path =
SCMalloc(PATH_MAX);
314 if (log_path == NULL) {
315 FatalError(
"Unable to allocate scratch memory for rule filename");
317 snprintf(log_path, PATH_MAX,
"%s/%s%s", log_dir,
320 FILE *fp = fopen(log_path,
"w");
322 SCLogError(
"failed to open %s: %s", log_path, strerror(errno));
329 SCLogInfo(
"Engine-Analysis for fast_pattern printed to file - %s",
334 gettimeofday(&tval, NULL);
336 struct tm *tms =
SCLocalTime(tval.tv_sec, &local_tm);
337 fprintf(fp,
"----------------------------------------------"
338 "---------------------\n");
340 "Date: %" PRId32
"/%" PRId32
"/%04d -- "
342 tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min,
344 fprintf(fp,
"----------------------------------------------"
345 "---------------------\n");
358 #define DETECT_PERCENT_ENCODING_REGEX "%[0-9|a-f|A-F]{2}"
364 PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
366 PCRE2_UCHAR errbuffer[256];
367 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
388 }
else if (value && strcasecmp(value,
"warnings-only") == 0) {
390 rule_warnings_only = 1;
395 char log_path[PATH_MAX];
396 snprintf(log_path,
sizeof(log_path),
"%s/%s%s", log_dir,
400 SCLogError(
"failed to open %s: %s", log_path, strerror(errno));
404 SCLogInfo(
"Engine-Analysis for rules printed to file - %s",
408 gettimeofday(&tval, NULL);
410 struct tm *tms =
SCLocalTime(tval.tv_sec, &local_tm);
412 "----------------------------------------------"
413 "---------------------\n");
415 "Date: %" PRId32
"/%" PRId32
"/%04d -- "
417 tms->tm_mday, tms->tm_mon + 1, tms->tm_year + 1900, tms->tm_hour, tms->tm_min,
420 "----------------------------------------------"
421 "---------------------\n");
424 if (!PerCentEncodingSetup(
de_ctx->
ea)) {
426 "Error compiling regex; can't check for percent encoding in normalized "
432 SCLogInfo(
"Conf parameter \"engine-analysis.rules\" not found. "
433 "Defaulting to not printing the rules analysis report.");
436 SCLogInfo(
"Engine-Analysis for rules disabled in conf file.");
445 fprintf(fp,
"============\n"
446 "Summary:\n============\n");
454 "%s, smallest pattern %u byte(s), longest pattern %u byte(s), number of patterns "
455 "%u, avg pattern len %.2f byte(s)\n",
457 (
float)((
double)f->
tot / (
float)f->
cnt));
477 *fp_analysis =
false;
478 *rule_analysis =
false;
482 FatalError(
"Unable to allocate per-engine analysis context");
487 if (cfg_prefix_len > 0) {
491 FatalError(
"Unable to allocate per-engine analysis context name buffer");
499 *fp_analysis = SetupFPAnalyzer(
de_ctx);
500 *rule_analysis = SetupRuleAnalyzer(
de_ctx);
502 if (!(*fp_analysis || *rule_analysis)) {
514 CleanupRuleAnalyzer(
de_ctx);
515 CleanupFPAnalyzer(
de_ctx);
532 static int PerCentEncodingMatch(
EngineAnalysisCtx *ea_ctx, uint8_t *content, uint16_t content_len)
536 pcre2_match_data *match = pcre2_match_data_create_from_pattern(ea_ctx->
percent_re, NULL);
537 ret = pcre2_match(ea_ctx->
percent_re, (PCRE2_SPTR8)content, content_len, 0, 0, match, NULL);
540 }
else if (ret < -1) {
541 SCLogError(
"Error parsing content - %s; error code is %d", content, ret);
544 pcre2_match_data_free(match);
554 if (mpm_sm != NULL) {
592 const int list_type = mpm_sm_list;
601 payload ? (stream ?
"payload and reassembled stream" :
"payload")
602 :
"reassembled stream");
609 }
else if (desc ||
name) {
646 vsnprintf(
str,
sizeof(
str), fmt, ap);
650 ctx->js_notes = jb_new_array();
652 jb_append_string(
ctx->js_notes,
str);
661 vsnprintf(
str,
sizeof(
str), fmt, ap);
664 if (!
ctx->js_warnings)
665 ctx->js_warnings = jb_new_array();
666 if (
ctx->js_warnings)
667 jb_append_string(
ctx->js_warnings,
str);
670 #define CHECK(pat) if (strlen((pat)) <= len && memcmp((pat), buf, MIN(len, strlen((pat)))) == 0) return true;
672 static bool LooksLikeHTTPMethod(
const uint8_t *buf, uint16_t
len)
681 static bool LooksLikeHTTPUA(
const uint8_t *buf, uint16_t
len)
683 CHECK(
"User-Agent: ");
684 CHECK(
"\nUser-Agent: ");
690 char pattern_str[1024] =
"";
693 jb_set_string(js,
"pattern", pattern_str);
702 jb_set_uint(js,
"offset", cd->
offset);
705 jb_set_uint(js,
"depth", cd->
depth);
708 jb_set_int(js,
"distance", cd->
distance);
711 jb_set_int(js,
"within", cd->
within);
730 jb_open_array(js,
"matches");
734 jb_set_string(js,
"name", mname);
740 jb_open_object(js,
"content");
743 AnalyzerNote(
ctx, (
char *)
"'fast_pattern:only' option is silently ignored and "
744 "is interpreted as regular 'fast_pattern'");
748 (
char *)
"pattern looks like it inspects HTTP, use http.request_line or "
749 "http.method and http.uri instead for improved performance");
753 (
char *)
"pattern looks like it inspects HTTP, use http.user_agent "
754 "or http.header for improved performance");
757 AnalyzerNote(
ctx, (
char *)
"'within' option for pattern w/o previous content "
758 "was converted to 'depth'");
761 AnalyzerNote(
ctx, (
char *)
"'distance' option for pattern w/o previous content "
762 "was converted to 'offset'");
770 jb_open_object(js,
"pcre");
775 (
char *)
"'/B' (rawbytes) option is a no-op and is silently ignored");
782 jb_open_object(js,
"byte_jump");
783 jb_set_uint(js,
"nbytes", cd->
nbytes);
784 jb_set_int(js,
"offset", cd->
offset);
785 jb_set_uint(js,
"multiplier", cd->
multiplier);
789 jb_set_string(js,
"base",
"unset");
792 jb_set_string(js,
"base",
"oct");
795 jb_set_string(js,
"base",
"dec");
798 jb_set_string(js,
"base",
"hex");
801 jb_open_array(js,
"flags");
803 jb_append_string(js,
"from_beginning");
805 jb_append_string(js,
"little_endian");
807 jb_append_string(js,
"big_endian");
809 jb_append_string(js,
"string");
811 jb_append_string(js,
"relative");
813 jb_append_string(js,
"align");
815 jb_append_string(js,
"dce");
817 jb_append_string(js,
"offset_be");
819 jb_append_string(js,
"from_end");
827 jb_open_object(js,
"byte_test");
828 jb_set_uint(js,
"nbytes", cd->
nbytes);
829 jb_set_int(js,
"offset", cd->
offset);
832 jb_set_string(js,
"base",
"unset");
835 jb_set_string(js,
"base",
"oct");
838 jb_set_string(js,
"base",
"dec");
841 jb_set_string(js,
"base",
"hex");
844 jb_open_array(js,
"flags");
846 jb_append_string(js,
"little_endian");
848 jb_append_string(js,
"big_endian");
850 jb_append_string(js,
"string");
852 jb_append_string(js,
"relative");
854 jb_append_string(js,
"dce");
861 jb_open_object(js,
"absent");
862 jb_set_bool(js,
"or_else", dad->
or_else);
870 jb_open_object(js,
"ipopts");
872 jb_set_string(js,
"option", flag);
879 jb_open_object(js,
"flowbits");
882 jb_set_string(js,
"cmd",
"isset");
885 jb_set_string(js,
"cmd",
"isnotset");
888 jb_set_string(js,
"cmd",
"set");
891 jb_set_string(js,
"cmd",
"unset");
894 jb_set_string(js,
"cmd",
"toggle");
898 jb_open_array(js,
"names");
904 const char *varname =
906 jb_append_string(js, varname);
911 jb_set_string(js,
"operator",
"or");
919 jb_open_object(js,
"ack");
920 jb_set_uint(js,
"number", cd->
ack);
926 jb_open_object(js,
"seq");
927 jb_set_uint(js,
"number", cd->
seq);
933 jb_open_object(js,
"tcp_mss");
934 SCDetectU16ToJson(js, cd);
940 jb_open_object(js,
"id");
941 jb_set_uint(js,
"number",
SCNtohs(cd->
id));
947 jb_open_object(js,
"window");
948 jb_set_uint(js,
"size", wd->
size);
949 jb_set_bool(js,
"negated", wd->
negated);
955 jb_open_object(js,
"flow_age");
956 SCDetectU32ToJson(js, cd);
977 ctx.js = jb_new_object();
982 jb_set_uint(
ctx.js,
"id", s->
id);
983 jb_set_uint(
ctx.js,
"gid", s->
gid);
984 jb_set_uint(
ctx.js,
"rev", s->
rev);
985 jb_set_string(
ctx.js,
"msg", s->
msg);
988 jb_set_string(
ctx.js,
"app_proto", alproto);
990 jb_open_array(
ctx.js,
"requirements");
992 jb_append_string(
ctx.js,
"payload");
995 jb_append_string(
ctx.js,
"no_payload");
998 jb_append_string(
ctx.js,
"flow");
1001 jb_append_string(
ctx.js,
"tcp_flags_init_deinit");
1004 jb_append_string(
ctx.js,
"tcp_flags_unusual");
1007 jb_append_string(
ctx.js,
"engine_event");
1010 jb_append_string(
ctx.js,
"real_pkt");
1016 jb_set_string(
ctx.js,
"type",
"unset");
1019 jb_set_string(
ctx.js,
"type",
"ip_only");
1022 jb_set_string(
ctx.js,
"type",
"like_ip_only");
1025 jb_set_string(
ctx.js,
"type",
"pd_only");
1028 jb_set_string(
ctx.js,
"type",
"de_only");
1031 jb_set_string(
ctx.js,
"type",
"pkt");
1034 jb_set_string(
ctx.js,
"type",
"pkt_stream");
1037 jb_set_string(
ctx.js,
"type",
"stream");
1040 jb_set_string(
ctx.js,
"type",
"app_layer");
1043 jb_set_string(
ctx.js,
"type",
"app_tx");
1046 jb_set_string(
ctx.js,
"type",
"error");
1050 jb_open_array(
ctx.js,
"flags");
1052 jb_append_string(
ctx.js,
"src_any");
1055 jb_append_string(
ctx.js,
"dst_any");
1058 jb_append_string(
ctx.js,
"sp_any");
1061 jb_append_string(
ctx.js,
"dp_any");
1064 jb_append_string(
ctx.js,
"noalert");
1067 jb_append_string(
ctx.js,
"dsize");
1070 jb_append_string(
ctx.js,
"applayer");
1073 jb_append_string(
ctx.js,
"need_packet");
1076 jb_append_string(
ctx.js,
"need_stream");
1079 jb_append_string(
ctx.js,
"negated_mpm");
1082 jb_append_string(
ctx.js,
"flush");
1085 jb_append_string(
ctx.js,
"need_flowvar");
1088 jb_append_string(
ctx.js,
"filestore");
1091 jb_append_string(
ctx.js,
"toserver");
1094 jb_append_string(
ctx.js,
"toclient");
1097 jb_append_string(
ctx.js,
"tlsstore");
1100 jb_append_string(
ctx.js,
"bypass");
1103 jb_append_string(
ctx.js,
"prefilter");
1106 jb_append_string(
ctx.js,
"src_is_target");
1109 jb_append_string(
ctx.js,
"dst_is_target");
1116 jb_open_array(
ctx.js,
"pkt_engines");
1118 for ( ; pkt != NULL; pkt = pkt->
next) {
1133 jb_start_object(
ctx.js);
1134 jb_set_string(
ctx.js,
"name",
name);
1135 jb_set_bool(
ctx.js,
"is_mpm", pkt->
mpm);
1137 jb_open_array(
ctx.js,
"transforms");
1139 jb_start_object(
ctx.js);
1140 jb_set_string(
ctx.js,
"name",
1153 jb_open_array(
ctx.js,
"frame_engines");
1155 for (; frame != NULL; frame = frame->
next) {
1157 jb_start_object(
ctx.js);
1158 jb_set_string(
ctx.js,
"name",
name);
1159 jb_set_bool(
ctx.js,
"is_mpm", frame->
mpm);
1161 jb_open_array(
ctx.js,
"transforms");
1163 jb_start_object(
ctx.js);
1164 jb_set_string(
ctx.js,
"name",
1176 bool has_stream =
false;
1177 bool has_client_body_mpm =
false;
1178 bool has_file_data_mpm =
false;
1180 jb_open_array(
ctx.js,
"engines");
1182 for ( ; app != NULL; app = app->
next) {
1197 }
else if (app->
mpm && strcmp(
name,
"http_client_body") == 0) {
1198 has_client_body_mpm =
true;
1199 }
else if (app->
mpm && strcmp(
name,
"file_data") == 0) {
1200 has_file_data_mpm =
true;
1203 jb_start_object(
ctx.js);
1204 jb_set_string(
ctx.js,
"name",
name);
1205 const char *direction = app->
dir == 0 ?
"toserver" :
"toclient";
1206 jb_set_string(
ctx.js,
"direction", direction);
1207 jb_set_bool(
ctx.js,
"is_mpm", app->
mpm);
1212 jb_open_array(
ctx.js,
"transforms");
1214 jb_start_object(
ctx.js);
1215 jb_set_string(
ctx.js,
"name",
1229 if (has_stream && has_client_body_mpm)
1230 AnalyzerNote(&
ctx, (
char *)
"mpm in http_client_body combined with stream match leads to stream buffering");
1231 if (has_stream && has_file_data_mpm)
1232 AnalyzerNote(&
ctx, (
char *)
"mpm in file_data combined with stream match leads to stream buffering");
1235 jb_open_object(
ctx.js,
"lists");
1245 if (pkt_mpm || app_mpm) {
1246 jb_open_object(
ctx.js,
"mpm");
1254 jb_set_string(
ctx.js,
"buffer",
name);
1261 switch (smd->
type) {
1265 DumpContent(
ctx.js, cd);
1277 jb_open_object(
ctx.js,
"prefilter");
1284 jb_set_string(
ctx.js,
"buffer",
name);
1286 jb_set_string(
ctx.js,
"name", mname);
1290 if (
ctx.js_warnings) {
1291 jb_close(
ctx.js_warnings);
1292 jb_set_object(
ctx.js,
"warnings",
ctx.js_warnings);
1293 jb_free(
ctx.js_warnings);
1294 ctx.js_warnings = NULL;
1297 jb_close(
ctx.js_notes);
1298 jb_set_object(
ctx.js,
"notes",
ctx.js_notes);
1299 jb_free(
ctx.js_notes);
1300 ctx.js_notes = NULL;
1304 const char *filename =
"rules.json";
1306 char json_path[PATH_MAX] =
"";
1307 snprintf(json_path,
sizeof(json_path),
"%s/%s%s", log_dir,
1311 FILE *fp = fopen(json_path,
"a");
1313 fwrite(jb_ptr(
ctx.js), jb_len(
ctx.js), 1, fp);
1327 JsonBuilder *root_jb = jb_new_object();
1331 jb_open_array(root_jb,
"buffers");
1335 char str[1024] =
"";
1339 JsonBuilder *jb = arrays[p->
sm_list];
1340 if (arrays[p->
sm_list] == NULL) {
1341 jb = arrays[p->
sm_list] = jb_new_object();
1347 jb_set_string(jb,
"name",
name);
1348 jb_set_uint(jb,
"list_id", p->
sm_list);
1350 jb_open_array(jb,
"patterns");
1353 jb_start_object(jb);
1354 jb_set_string(jb,
"pattern",
str);
1356 jb_set_uint(jb,
"cnt", p->
cnt);
1357 jb_set_uint(jb,
"mpm", p->
mpm);
1358 jb_open_object(jb,
"flags");
1369 JsonBuilder *jb = arrays[i];
1376 jb_append_object(root_jb, jb);
1382 const char *filename =
"patterns.json";
1384 char json_path[PATH_MAX] =
"";
1385 snprintf(json_path,
sizeof(json_path),
"%s/%s%s", log_dir,
1389 FILE *fp = fopen(json_path,
"a");
1391 fwrite(jb_ptr(root_jb), jb_len(root_jb), 1, fp);
1412 EngineAnalysisItemsReset(ea_ctx);
1420 FatalError(
"Unable to allocate analysis scratch pad");
1430 analyzer_item->
item_id = (uint16_t)item_id;
1431 if (analyzer_item->
item_id == -1) {
1433 FatalError(
"unable to initialize engine-analysis table: detect buffer \"%s\" not "
1466 uint32_t rule_bidirectional = 0;
1467 uint32_t rule_pcre = 0;
1468 uint32_t rule_pcre_http = 0;
1469 uint32_t rule_content = 0;
1470 uint32_t rule_flow = 0;
1471 uint32_t rule_flags = 0;
1472 uint32_t rule_flow_toserver = 0;
1473 uint32_t rule_flow_toclient = 0;
1474 uint32_t rule_flow_nostream = 0;
1475 uint32_t rule_ipv4_only = 0;
1476 uint32_t rule_ipv6_only = 0;
1477 uint32_t rule_flowbits = 0;
1478 uint32_t rule_flowint = 0;
1479 uint32_t rule_content_http = 0;
1480 uint32_t rule_content_offset_depth = 0;
1481 int32_t list_id = 0;
1482 uint32_t rule_warning = 0;
1483 uint32_t stream_buf = 0;
1484 uint32_t packet_buf = 0;
1485 uint32_t file_store = 0;
1486 uint32_t warn_pcre_no_content = 0;
1487 uint32_t warn_pcre_http_content = 0;
1488 uint32_t warn_pcre_http = 0;
1489 uint32_t warn_content_http_content = 0;
1490 uint32_t warn_content_http = 0;
1491 uint32_t warn_tcp_no_flow = 0;
1492 uint32_t warn_client_ports = 0;
1493 uint32_t warn_direction = 0;
1494 uint32_t warn_method_toclient = 0;
1495 uint32_t warn_method_serverbody = 0;
1496 uint32_t warn_pcre_method = 0;
1497 uint32_t warn_encoding_norm_http_buf = 0;
1498 uint32_t warn_file_store_not_present = 0;
1499 uint32_t warn_offset_depth_pkt_stream = 0;
1500 uint32_t warn_offset_depth_alproto = 0;
1501 uint32_t warn_non_alproto_fp_for_alproto_sig = 0;
1502 uint32_t warn_no_direction = 0;
1503 uint32_t warn_both_direction = 0;
1505 EngineAnalysisItemsInit(
de_ctx->
ea);
1511 rule_bidirectional = 1;
1525 rule_ipv4_only += 1;
1528 rule_ipv6_only += 1;
1536 if (item_slot == -1) {
1544 if (item_slot == -1) {
1549 rule_content_offset_depth++;
1555 rule_content_http++;
1562 warn_encoding_norm_http_buf += 1;
1569 rule_flow_toserver = 1;
1572 rule_flow_toclient = 1;
1577 rule_flow_nostream = 1;
1602 warn_file_store_not_present = 1;
1605 if (rule_pcre > 0 && rule_content == 0 && rule_content_http == 0) {
1607 warn_pcre_no_content = 1;
1610 if (rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0) {
1612 warn_pcre_http_content = 1;
1618 if (rule_content > 0 && rule_content_http > 0) {
1620 warn_content_http_content = 1;
1624 warn_content_http = 1;
1626 if (rule_content == 1) {
1631 (rule_content || rule_content_http || rule_pcre || rule_pcre_http || rule_flowbits ||
1634 warn_tcp_no_flow = 1;
1636 if (rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1641 warn_client_ports = 1;
1644 if (rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)) {
1649 if (*http_method_item_seen_ptr) {
1650 if (rule_flow && rule_flow_toclient) {
1652 warn_method_toclient = 1;
1654 if (*http_server_body_item_seen_ptr) {
1656 warn_method_serverbody = 1;
1658 if (rule_content == 0 && rule_content_http == 0 && (rule_pcre > 0 || rule_pcre_http > 0)) {
1660 warn_pcre_method = 1;
1663 if (rule_content_offset_depth > 0 && stream_buf && packet_buf) {
1665 warn_offset_depth_pkt_stream = 1;
1669 warn_offset_depth_alproto = 1;
1674 warn_non_alproto_fp_for_alproto_sig = 1;
1678 warn_no_direction += 1;
1685 warn_both_direction += 1;
1690 if (!rule_warnings_only || (rule_warnings_only && rule_warning > 0)) {
1692 fprintf(fp,
"== Sid: %u ==\n", s->
id);
1693 fprintf(fp,
"%s\n", line);
1699 fprintf(fp,
" Rule is ip only.\n");
1702 fprintf(fp,
" Rule is like ip only.\n");
1705 fprintf(fp,
" Rule is PD only.\n");
1708 fprintf(fp,
" Rule is DE only.\n");
1711 fprintf(fp,
" Rule is packet inspecting.\n");
1714 fprintf(fp,
" Rule is packet and stream inspecting.\n");
1717 fprintf(fp,
" Rule is stream inspecting.\n");
1720 fprintf(fp,
" Rule is app-layer inspecting.\n");
1723 fprintf(fp,
" Rule is App-layer TX inspecting.\n");
1729 fprintf(fp,
" Rule is IPv6 only.\n");
1731 fprintf(fp,
" Rule is IPv4 only.\n");
1733 fprintf(fp,
" Rule matches on packets.\n");
1734 if (!rule_flow_nostream && stream_buf &&
1735 (rule_flow || rule_flowbits || rule_flowint || rule_content || rule_pcre)) {
1736 fprintf(fp,
" Rule matches on reassembled stream.\n");
1741 fprintf(fp,
" Rule matches on %s buffer.\n", ai->
display_name);
1747 if (rule_content || rule_content_http || rule_pcre || rule_pcre_http) {
1749 " Rule contains %u content options, %u http content options, %u pcre "
1750 "options, and %u pcre options with http modifiers.\n",
1751 rule_content, rule_content_http, rule_pcre, rule_pcre_http);
1756 fprintf(fp,
" Prefilter on: %s.\n",
1759 EngineAnalysisRulesPrintFP(
de_ctx, s);
1763 if (warn_pcre_no_content ) {
1764 fprintf(fp,
" Warning: Rule uses pcre without a content option present.\n"
1765 " -Consider adding a content to improve performance of this "
1768 if (warn_pcre_http_content ) {
1769 fprintf(fp,
" Warning: Rule uses content options with http_* and pcre options "
1770 "without http modifiers.\n"
1771 " -Consider adding http pcre modifier.\n");
1773 else if (warn_pcre_http ) {
1774 fprintf(fp,
" Warning: Rule app layer protocol is http, but pcre options do not "
1775 "have http modifiers.\n"
1776 " -Consider adding http pcre modifiers.\n");
1778 if (warn_content_http_content ) {
1780 " Warning: Rule contains content with http_* and content without http_*.\n"
1781 " -Consider adding http content modifiers.\n");
1783 if (warn_content_http ) {
1784 fprintf(fp,
" Warning: Rule app layer protocol is http, but content options do not "
1785 "have http_* modifiers.\n"
1786 " -Consider adding http content modifiers.\n");
1788 if (rule_content == 1) {
1791 if (warn_encoding_norm_http_buf) {
1792 fprintf(fp,
" Warning: Rule may contain percent encoded content for a normalized "
1793 "http buffer match.\n");
1795 if (warn_tcp_no_flow
1797 fprintf(fp,
" Warning: TCP rule without a flow or flags option.\n"
1798 " -Consider adding flow or flags to improve performance of "
1801 if (warn_client_ports
1806 " Warning: Rule contains ports or port variables only on the client side.\n"
1807 " -Flow direction possibly inconsistent with rule.\n");
1809 if (warn_direction ) {
1810 fprintf(fp,
" Warning: Rule is bidirectional and has a flow option with a specific "
1813 if (warn_method_toclient ) {
1814 fprintf(fp,
" Warning: Rule uses content or pcre for http_method with "
1815 "flow:to_client or from_server\n");
1817 if (warn_method_serverbody ) {
1818 fprintf(fp,
" Warning: Rule uses content or pcre for http_method with content or "
1819 "pcre for http_server_body.\n");
1821 if (warn_pcre_method
1823 fprintf(fp,
" Warning: Rule uses pcre with only a http_method content; possible "
1824 "performance issue.\n");
1826 if (warn_offset_depth_pkt_stream) {
1827 fprintf(fp,
" Warning: Rule has depth"
1828 "/offset with raw content keywords. Please note the "
1829 "offset/depth will be checked against both packet "
1830 "payloads and stream. If you meant to have the offset/"
1831 "depth checked against just the payload, you can update "
1832 "the signature as \"alert tcp-pkt...\"\n");
1834 if (warn_offset_depth_alproto) {
1836 " Warning: Rule has "
1837 "offset/depth set along with a match on a specific "
1838 "app layer protocol - %d. This can lead to FNs if we "
1839 "have a offset/depth content match on a packet payload "
1840 "before we can detect the app layer protocol for the "
1844 if (warn_non_alproto_fp_for_alproto_sig) {
1845 fprintf(fp,
" Warning: Rule app layer "
1846 "protocol is http, but the fast_pattern is set on the raw "
1847 "stream. Consider adding fast_pattern over a http "
1848 "buffer for increased performance.");
1850 if (warn_no_direction) {
1851 fprintf(fp,
" Warning: Rule has no direction indicator.\n");
1853 if (warn_both_direction) {
1854 fprintf(fp,
" Warning: Rule is inspecting both the request and the response.\n");
1856 if (warn_file_store_not_present) {
1857 fprintf(fp,
" Warning: Rule requires file-store but the output file-store is not "
1860 if (rule_warning == 0) {
1861 fprintf(fp,
" No warnings for this rule.\n");