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) {
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");
862 jb_open_object(js,
"absent");
863 jb_set_bool(js,
"or_else", dad->
or_else);
871 jb_open_object(js,
"ipopts");
873 jb_set_string(js,
"option", flag);
880 jb_open_object(js,
"flowbits");
883 jb_set_string(js,
"cmd",
"isset");
886 jb_set_string(js,
"cmd",
"isnotset");
889 jb_set_string(js,
"cmd",
"set");
892 jb_set_string(js,
"cmd",
"unset");
895 jb_set_string(js,
"cmd",
"toggle");
899 jb_open_array(js,
"names");
905 const char *varname =
907 jb_append_string(js, varname);
912 jb_set_string(js,
"operator",
"or");
920 jb_open_object(js,
"ack");
921 jb_set_uint(js,
"number", cd->
ack);
927 jb_open_object(js,
"seq");
928 jb_set_uint(js,
"number", cd->
seq);
934 jb_open_object(js,
"tcp_mss");
935 SCDetectU16ToJson(js, cd);
941 jb_open_object(js,
"id");
942 jb_set_uint(js,
"number",
SCNtohs(cd->
id));
948 jb_open_object(js,
"window");
949 jb_set_uint(js,
"size", wd->
size);
950 jb_set_bool(js,
"negated", wd->
negated);
956 jb_open_object(js,
"flow_age");
957 SCDetectU32ToJson(js, cd);
978 ctx.js = jb_new_object();
983 jb_set_uint(
ctx.js,
"id", s->
id);
984 jb_set_uint(
ctx.js,
"gid", s->
gid);
985 jb_set_uint(
ctx.js,
"rev", s->
rev);
986 jb_set_string(
ctx.js,
"msg", s->
msg);
989 jb_set_string(
ctx.js,
"app_proto", alproto);
991 jb_open_array(
ctx.js,
"requirements");
993 jb_append_string(
ctx.js,
"payload");
996 jb_append_string(
ctx.js,
"no_payload");
999 jb_append_string(
ctx.js,
"flow");
1002 jb_append_string(
ctx.js,
"tcp_flags_init_deinit");
1005 jb_append_string(
ctx.js,
"tcp_flags_unusual");
1008 jb_append_string(
ctx.js,
"engine_event");
1011 jb_append_string(
ctx.js,
"real_pkt");
1015 jb_open_object(
ctx.js,
"match_policy");
1016 jb_open_array(
ctx.js,
"actions");
1018 jb_append_string(
ctx.js,
"alert");
1021 jb_append_string(
ctx.js,
"drop");
1024 jb_append_string(
ctx.js,
"reject");
1027 jb_append_string(
ctx.js,
"reject_dst");
1030 jb_append_string(
ctx.js,
"reject_both");
1033 jb_append_string(
ctx.js,
"config");
1036 jb_append_string(
ctx.js,
"pass");
1040 switch (flow_action) {
1042 jb_set_string(
ctx.js,
"scope",
"packet");
1045 jb_set_string(
ctx.js,
"scope",
"flow");
1048 jb_set_string(
ctx.js,
"scope",
"flow_if_stateful");
1055 jb_set_string(
ctx.js,
"type",
"unset");
1058 jb_set_string(
ctx.js,
"type",
"ip_only");
1061 jb_set_string(
ctx.js,
"type",
"like_ip_only");
1064 jb_set_string(
ctx.js,
"type",
"pd_only");
1067 jb_set_string(
ctx.js,
"type",
"de_only");
1070 jb_set_string(
ctx.js,
"type",
"pkt");
1073 jb_set_string(
ctx.js,
"type",
"pkt_stream");
1076 jb_set_string(
ctx.js,
"type",
"stream");
1079 jb_set_string(
ctx.js,
"type",
"app_layer");
1082 jb_set_string(
ctx.js,
"type",
"app_tx");
1085 jb_set_string(
ctx.js,
"type",
"error");
1091 jb_open_object(
ctx.js,
"dependencies");
1092 jb_open_object(
ctx.js,
"flowbits");
1093 jb_open_object(
ctx.js,
"upstream");
1095 jb_open_object(
ctx.js,
"state_modifying_rules");
1096 jb_open_array(
ctx.js,
"sids");
1101 jb_open_array(
ctx.js,
"names");
1104 jb_append_string(
ctx.js,
1117 jb_open_array(
ctx.js,
"flags");
1119 jb_append_string(
ctx.js,
"src_any");
1122 jb_append_string(
ctx.js,
"dst_any");
1125 jb_append_string(
ctx.js,
"sp_any");
1128 jb_append_string(
ctx.js,
"dp_any");
1131 jb_append_string(
ctx.js,
"noalert");
1134 jb_append_string(
ctx.js,
"dsize");
1137 jb_append_string(
ctx.js,
"applayer");
1140 jb_append_string(
ctx.js,
"need_packet");
1143 jb_append_string(
ctx.js,
"need_stream");
1146 jb_append_string(
ctx.js,
"negated_mpm");
1149 jb_append_string(
ctx.js,
"flush");
1152 jb_append_string(
ctx.js,
"need_flowvar");
1155 jb_append_string(
ctx.js,
"filestore");
1158 jb_append_string(
ctx.js,
"toserver");
1161 jb_append_string(
ctx.js,
"toclient");
1164 jb_append_string(
ctx.js,
"tlsstore");
1167 jb_append_string(
ctx.js,
"bypass");
1170 jb_append_string(
ctx.js,
"prefilter");
1173 jb_append_string(
ctx.js,
"src_is_target");
1176 jb_append_string(
ctx.js,
"dst_is_target");
1183 jb_open_array(
ctx.js,
"pkt_engines");
1185 for ( ; pkt != NULL; pkt = pkt->
next) {
1200 jb_start_object(
ctx.js);
1201 jb_set_string(
ctx.js,
"name",
name);
1202 jb_set_bool(
ctx.js,
"is_mpm", pkt->
mpm);
1204 jb_open_array(
ctx.js,
"transforms");
1206 jb_start_object(
ctx.js);
1207 jb_set_string(
ctx.js,
"name",
1220 jb_open_array(
ctx.js,
"frame_engines");
1222 for (; frame != NULL; frame = frame->
next) {
1224 jb_start_object(
ctx.js);
1225 jb_set_string(
ctx.js,
"name",
name);
1226 jb_set_bool(
ctx.js,
"is_mpm", frame->
mpm);
1228 jb_open_array(
ctx.js,
"transforms");
1230 jb_start_object(
ctx.js);
1231 jb_set_string(
ctx.js,
"name",
1243 bool has_stream =
false;
1244 bool has_client_body_mpm =
false;
1245 bool has_file_data_mpm =
false;
1247 jb_open_array(
ctx.js,
"engines");
1249 for ( ; app != NULL; app = app->
next) {
1264 }
else if (app->
mpm && strcmp(
name,
"http_client_body") == 0) {
1265 has_client_body_mpm =
true;
1266 }
else if (app->
mpm && strcmp(
name,
"file_data") == 0) {
1267 has_file_data_mpm =
true;
1270 jb_start_object(
ctx.js);
1271 jb_set_string(
ctx.js,
"name",
name);
1272 const char *direction = app->
dir == 0 ?
"toserver" :
"toclient";
1273 jb_set_string(
ctx.js,
"direction", direction);
1274 jb_set_bool(
ctx.js,
"is_mpm", app->
mpm);
1279 jb_open_array(
ctx.js,
"transforms");
1281 jb_start_object(
ctx.js);
1282 jb_set_string(
ctx.js,
"name",
1296 if (has_stream && has_client_body_mpm)
1297 AnalyzerNote(&
ctx, (
char *)
"mpm in http_client_body combined with stream match leads to stream buffering");
1298 if (has_stream && has_file_data_mpm)
1299 AnalyzerNote(&
ctx, (
char *)
"mpm in file_data combined with stream match leads to stream buffering");
1302 jb_open_object(
ctx.js,
"lists");
1312 if (pkt_mpm || app_mpm) {
1313 jb_open_object(
ctx.js,
"mpm");
1321 jb_set_string(
ctx.js,
"buffer",
name);
1328 switch (smd->
type) {
1332 DumpContent(
ctx.js, cd);
1344 jb_open_object(
ctx.js,
"prefilter");
1351 jb_set_string(
ctx.js,
"buffer",
name);
1353 jb_set_string(
ctx.js,
"name", mname);
1357 if (
ctx.js_warnings) {
1358 jb_close(
ctx.js_warnings);
1359 jb_set_object(
ctx.js,
"warnings",
ctx.js_warnings);
1360 jb_free(
ctx.js_warnings);
1361 ctx.js_warnings = NULL;
1364 jb_close(
ctx.js_notes);
1365 jb_set_object(
ctx.js,
"notes",
ctx.js_notes);
1366 jb_free(
ctx.js_notes);
1367 ctx.js_notes = NULL;
1371 const char *filename =
"rules.json";
1373 char json_path[PATH_MAX] =
"";
1374 snprintf(json_path,
sizeof(json_path),
"%s/%s%s", log_dir,
1378 FILE *fp = fopen(json_path,
"a");
1380 fwrite(jb_ptr(
ctx.js), jb_len(
ctx.js), 1, fp);
1394 JsonBuilder *root_jb = jb_new_object();
1398 jb_open_array(root_jb,
"buffers");
1402 char str[1024] =
"";
1406 JsonBuilder *jb = arrays[p->
sm_list];
1407 if (arrays[p->
sm_list] == NULL) {
1408 jb = arrays[p->
sm_list] = jb_new_object();
1414 jb_set_string(jb,
"name",
name);
1415 jb_set_uint(jb,
"list_id", p->
sm_list);
1417 jb_open_array(jb,
"patterns");
1420 jb_start_object(jb);
1421 jb_set_string(jb,
"pattern",
str);
1423 jb_set_uint(jb,
"cnt", p->
cnt);
1424 jb_set_uint(jb,
"mpm", p->
mpm);
1425 jb_open_object(jb,
"flags");
1436 JsonBuilder *jb = arrays[i];
1443 jb_append_object(root_jb, jb);
1449 const char *filename =
"patterns.json";
1451 char json_path[PATH_MAX] =
"";
1452 snprintf(json_path,
sizeof(json_path),
"%s/%s%s", log_dir,
1456 FILE *fp = fopen(json_path,
"a");
1458 fwrite(jb_ptr(root_jb), jb_len(root_jb), 1, fp);
1479 EngineAnalysisItemsReset(ea_ctx);
1487 FatalError(
"Unable to allocate analysis scratch pad");
1497 analyzer_item->
item_id = (uint16_t)item_id;
1498 if (analyzer_item->
item_id == -1) {
1500 FatalError(
"unable to initialize engine-analysis table: detect buffer \"%s\" not "
1533 uint32_t rule_bidirectional = 0;
1534 uint32_t rule_pcre = 0;
1535 uint32_t rule_pcre_http = 0;
1536 uint32_t rule_content = 0;
1537 uint32_t rule_flow = 0;
1538 uint32_t rule_flags = 0;
1539 uint32_t rule_flow_toserver = 0;
1540 uint32_t rule_flow_toclient = 0;
1541 uint32_t rule_flow_nostream = 0;
1542 uint32_t rule_ipv4_only = 0;
1543 uint32_t rule_ipv6_only = 0;
1544 uint32_t rule_flowbits = 0;
1545 uint32_t rule_flowint = 0;
1546 uint32_t rule_content_http = 0;
1547 uint32_t rule_content_offset_depth = 0;
1548 int32_t list_id = 0;
1549 uint32_t rule_warning = 0;
1550 uint32_t stream_buf = 0;
1551 uint32_t packet_buf = 0;
1552 uint32_t file_store = 0;
1553 uint32_t warn_pcre_no_content = 0;
1554 uint32_t warn_pcre_http_content = 0;
1555 uint32_t warn_pcre_http = 0;
1556 uint32_t warn_content_http_content = 0;
1557 uint32_t warn_content_http = 0;
1558 uint32_t warn_tcp_no_flow = 0;
1559 uint32_t warn_client_ports = 0;
1560 uint32_t warn_direction = 0;
1561 uint32_t warn_method_toclient = 0;
1562 uint32_t warn_method_serverbody = 0;
1563 uint32_t warn_pcre_method = 0;
1564 uint32_t warn_encoding_norm_http_buf = 0;
1565 uint32_t warn_file_store_not_present = 0;
1566 uint32_t warn_offset_depth_pkt_stream = 0;
1567 uint32_t warn_offset_depth_alproto = 0;
1568 uint32_t warn_non_alproto_fp_for_alproto_sig = 0;
1569 uint32_t warn_no_direction = 0;
1570 uint32_t warn_both_direction = 0;
1572 EngineAnalysisItemsInit(
de_ctx->
ea);
1578 rule_bidirectional = 1;
1592 rule_ipv4_only += 1;
1595 rule_ipv6_only += 1;
1603 if (item_slot == -1) {
1611 if (item_slot == -1) {
1616 rule_content_offset_depth++;
1622 rule_content_http++;
1629 warn_encoding_norm_http_buf += 1;
1636 rule_flow_toserver = 1;
1639 rule_flow_toclient = 1;
1644 rule_flow_nostream = 1;
1669 warn_file_store_not_present = 1;
1672 if (rule_pcre > 0 && rule_content == 0 && rule_content_http == 0) {
1674 warn_pcre_no_content = 1;
1677 if (rule_content_http > 0 && rule_pcre > 0 && rule_pcre_http == 0) {
1679 warn_pcre_http_content = 1;
1685 if (rule_content > 0 && rule_content_http > 0) {
1687 warn_content_http_content = 1;
1691 warn_content_http = 1;
1693 if (rule_content == 1) {
1698 (rule_content || rule_content_http || rule_pcre || rule_pcre_http || rule_flowbits ||
1701 warn_tcp_no_flow = 1;
1703 if (rule_flow && !rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)
1708 warn_client_ports = 1;
1711 if (rule_flow && rule_bidirectional && (rule_flow_toserver || rule_flow_toclient)) {
1716 if (*http_method_item_seen_ptr) {
1717 if (rule_flow && rule_flow_toclient) {
1719 warn_method_toclient = 1;
1721 if (*http_server_body_item_seen_ptr) {
1723 warn_method_serverbody = 1;
1725 if (rule_content == 0 && rule_content_http == 0 && (rule_pcre > 0 || rule_pcre_http > 0)) {
1727 warn_pcre_method = 1;
1730 if (rule_content_offset_depth > 0 && stream_buf && packet_buf) {
1732 warn_offset_depth_pkt_stream = 1;
1736 warn_offset_depth_alproto = 1;
1741 warn_non_alproto_fp_for_alproto_sig = 1;
1745 warn_no_direction += 1;
1752 warn_both_direction += 1;
1757 if (!rule_warnings_only || (rule_warnings_only && rule_warning > 0)) {
1759 fprintf(fp,
"== Sid: %u ==\n", s->
id);
1760 fprintf(fp,
"%s\n", line);
1766 fprintf(fp,
" Rule is ip only.\n");
1769 fprintf(fp,
" Rule is like ip only.\n");
1772 fprintf(fp,
" Rule is PD only.\n");
1775 fprintf(fp,
" Rule is DE only.\n");
1778 fprintf(fp,
" Rule is packet inspecting.\n");
1781 fprintf(fp,
" Rule is packet and stream inspecting.\n");
1784 fprintf(fp,
" Rule is stream inspecting.\n");
1787 fprintf(fp,
" Rule is app-layer inspecting.\n");
1790 fprintf(fp,
" Rule is App-layer TX inspecting.\n");
1796 fprintf(fp,
" Rule is IPv6 only.\n");
1798 fprintf(fp,
" Rule is IPv4 only.\n");
1800 fprintf(fp,
" Rule matches on packets.\n");
1801 if (!rule_flow_nostream && stream_buf &&
1802 (rule_flow || rule_flowbits || rule_flowint || rule_content || rule_pcre)) {
1803 fprintf(fp,
" Rule matches on reassembled stream.\n");
1808 fprintf(fp,
" Rule matches on %s buffer.\n", ai->
display_name);
1814 if (rule_content || rule_content_http || rule_pcre || rule_pcre_http) {
1816 " Rule contains %u content options, %u http content options, %u pcre "
1817 "options, and %u pcre options with http modifiers.\n",
1818 rule_content, rule_content_http, rule_pcre, rule_pcre_http);
1823 fprintf(fp,
" Prefilter on: %s.\n",
1826 EngineAnalysisRulesPrintFP(
de_ctx, s);
1830 if (warn_pcre_no_content ) {
1831 fprintf(fp,
" Warning: Rule uses pcre without a content option present.\n"
1832 " -Consider adding a content to improve performance of this "
1835 if (warn_pcre_http_content ) {
1836 fprintf(fp,
" Warning: Rule uses content options with http_* and pcre options "
1837 "without http modifiers.\n"
1838 " -Consider adding http pcre modifier.\n");
1840 else if (warn_pcre_http ) {
1841 fprintf(fp,
" Warning: Rule app layer protocol is http, but pcre options do not "
1842 "have http modifiers.\n"
1843 " -Consider adding http pcre modifiers.\n");
1845 if (warn_content_http_content ) {
1847 " Warning: Rule contains content with http_* and content without http_*.\n"
1848 " -Consider adding http content modifiers.\n");
1850 if (warn_content_http ) {
1851 fprintf(fp,
" Warning: Rule app layer protocol is http, but content options do not "
1852 "have http_* modifiers.\n"
1853 " -Consider adding http content modifiers.\n");
1855 if (rule_content == 1) {
1858 if (warn_encoding_norm_http_buf) {
1859 fprintf(fp,
" Warning: Rule may contain percent encoded content for a normalized "
1860 "http buffer match.\n");
1862 if (warn_tcp_no_flow
1864 fprintf(fp,
" Warning: TCP rule without a flow or flags option.\n"
1865 " -Consider adding flow or flags to improve performance of "
1868 if (warn_client_ports
1873 " Warning: Rule contains ports or port variables only on the client side.\n"
1874 " -Flow direction possibly inconsistent with rule.\n");
1876 if (warn_direction ) {
1877 fprintf(fp,
" Warning: Rule is bidirectional and has a flow option with a specific "
1880 if (warn_method_toclient ) {
1881 fprintf(fp,
" Warning: Rule uses content or pcre for http_method with "
1882 "flow:to_client or from_server\n");
1884 if (warn_method_serverbody ) {
1885 fprintf(fp,
" Warning: Rule uses content or pcre for http_method with content or "
1886 "pcre for http_server_body.\n");
1888 if (warn_pcre_method
1890 fprintf(fp,
" Warning: Rule uses pcre with only a http_method content; possible "
1891 "performance issue.\n");
1893 if (warn_offset_depth_pkt_stream) {
1894 fprintf(fp,
" Warning: Rule has depth"
1895 "/offset with raw content keywords. Please note the "
1896 "offset/depth will be checked against both packet "
1897 "payloads and stream. If you meant to have the offset/"
1898 "depth checked against just the payload, you can update "
1899 "the signature as \"alert tcp-pkt...\"\n");
1901 if (warn_offset_depth_alproto) {
1903 " Warning: Rule has "
1904 "offset/depth set along with a match on a specific "
1905 "app layer protocol - %d. This can lead to FNs if we "
1906 "have a offset/depth content match on a packet payload "
1907 "before we can detect the app layer protocol for the "
1911 if (warn_non_alproto_fp_for_alproto_sig) {
1912 fprintf(fp,
" Warning: Rule app layer "
1913 "protocol is http, but the fast_pattern is set on the raw "
1914 "stream. Consider adding fast_pattern over a http "
1915 "buffer for increased performance.");
1917 if (warn_no_direction) {
1918 fprintf(fp,
" Warning: Rule has no direction indicator.\n");
1920 if (warn_both_direction) {
1921 fprintf(fp,
" Warning: Rule is inspecting both the request and the response.\n");
1923 if (warn_file_store_not_present) {
1924 fprintf(fp,
" Warning: Rule requires file-store but the output file-store is not "
1927 if (rule_warning == 0) {
1928 fprintf(fp,
" No warnings for this rule.\n");