89 #define ALPROTO_WITHFILES_MAX 16
99 .to_client_progress = HTP_RESPONSE_PROGRESS_BODY,
100 .to_server_progress = HTP_REQUEST_PROGRESS_BODY },
103 .to_client_progress = HTTP2StateDataServer,
104 .to_server_progress = HTTP2StateDataClient },
109 AppProto alproto,
int direction,
int to_client_progress,
int to_server_progress)
159 static void SigMatchTransferSigMatchAcrossLists(
SigMatch *sm,
190 #define CASE_CODE_STRING(E, S) case E: return S; break
201 #undef CASE_CODE_STRING
205 #define CASE_CODE(E) case E: return #E
223 Signature *s,
const char *arg,
int sm_type,
int sm_list,
229 if (arg != NULL && strcmp(arg,
"") != 0) {
238 "with a sticky buffer still set. Reset sticky buffer "
239 "with pkt_data before using the modifier.",
253 "found inside the rule without a content context. "
254 "Please use a \"content\" keyword before using the "
262 "be used with the rawbytes rule keyword",
268 "be used with the replace rule keyword",
307 bool reuse_buffer =
false;
320 SCLogError(
"failed to expand rule buffer array");
329 SCLogDebug(
"idx %u list %d set up curbuf %p s->init_data->buffer_index %u",
370 if (sm->
ctx != NULL) {
381 ptrdiff_t
offset = e - table;
395 if (st->
name != NULL) {
428 if (strcmp(
str,
"all") == 0) {
440 char *xsaveptr = NULL;
441 char *key = strtok_r(copy,
",", &xsaveptr);
442 while (key != NULL) {
448 "argument '%s' not found",
451 key = strtok_r(NULL,
",", &xsaveptr);
478 SCLogDebug(
"s:%p new:%p list:%d: %s, s->init_data->list_set %s s->init_data->list %d", s,
new,
512 SCLogDebug(
"reusing buffer %u as it isn't multi-capable", x);
522 SCLogError(
"failed to expand rule buffer array");
546 SCLogDebug(
"appended %s to list %d, rule pos %u (s->init_data->list %d)",
565 if (sm->
prev != NULL)
567 if (sm->
next != NULL)
609 if (sm_last == NULL || sm_new->
idx > sm_last->
idx)
621 if (sm_last == NULL || sm_new->
idx > sm_last->
idx)
643 SCLogDebug(
"skip x %u s->init_data->list %d (int)s->init_data->buffers[x].id %d", x,
652 for (sm_type = va_arg(ap,
int); sm_type != -1; sm_type = va_arg(ap,
int)) {
656 if (sm_last == NULL || sm_new->
idx > sm_last->
idx)
673 for (sm_type = va_arg(ap,
int); sm_type != -1; sm_type = va_arg(ap,
int))
678 if (sm_last == NULL || sm_new->
idx > sm_last->
idx)
703 va_start(ap, sm_list);
705 for (sm_type = va_arg(ap,
int); sm_type != -1; sm_type = va_arg(ap,
int))
707 sm_new = SigMatchGetLastSMByType(sm_list, sm_type);
710 if (sm_last == NULL || sm_new->
idx > sm_last->
idx)
741 va_start(ap, list_id);
743 for (sm_type = va_arg(ap,
int); sm_type != -1; sm_type = va_arg(ap,
int)) {
747 if (sm_last == NULL || sm_new->
idx > sm_last->
idx)
759 va_start(ap, list_id);
761 for (sm_type = va_arg(ap,
int); sm_type != -1; sm_type = va_arg(ap,
int)) {
762 sm_new = SigMatchGetLastSMByType(sm_list, sm_type);
765 if (sm_last == NULL || sm_new->
idx > sm_last->
idx)
788 if (sm_last == NULL || sm_new->
idx > sm_last->
idx)
796 if (sm_last == NULL || sm_new->
idx > sm_last->
idx)
803 static void SigMatchTransferSigMatchAcrossLists(
SigMatch *sm,
809 if (sm->
prev != NULL)
811 if (sm->
next != NULL)
814 if (sm == *src_sm_list)
815 *src_sm_list = sm->
next;
816 if (sm == *src_sm_list_tail)
817 *src_sm_list_tail = sm->
prev;
819 if (*dst_sm_list == NULL) {
821 *dst_sm_list_tail = sm;
829 *dst_sm_list_tail = sm;
856 SCLogError(
"Unable to find the sm in any of the "
862 size_t output_size,
bool requires)
865 char *optname = NULL;
866 char *optvalue = NULL;
869 while (isblank(*optstr)) {
874 char *optend = optstr;
876 optend = strchr(optend,
';');
877 if (optend == NULL) {
881 else if (optend > optstr && *(optend -1 ) ==
'\\') {
890 char *optvalptr = strchr(optstr,
':');
892 *(optvalptr++) =
'\0';
895 for (
size_t i = strlen(optvalptr); i > 0; i--) {
896 if (isblank(optvalptr[i - 1])) {
897 optvalptr[i - 1] =
'\0';
903 optvalue = optvalptr;
907 for (
size_t i = strlen(optstr); i > 0; i--) {
908 if (isblank(optstr[i - 1])) {
909 optstr[i - 1] =
'\0';
918 bool requires_only = strcasecmp(optname,
"requires") == 0 || strcasecmp(optname,
"sid") == 0;
919 if ((requires && !requires_only) || (!requires && requires_only)) {
924 st = SigTableGet(optname);
925 if (st == NULL || st->
Setup == NULL) {
926 SCLogError(
"unknown rule keyword '%s'.", optname);
931 if (optvalue == NULL || strlen(optvalue) == 0) {
933 "invalid formatting or malformed option to %s keyword: '%s'", optname, optstr);
937 if (optvalue && strlen(optvalue)) {
938 SCLogError(
"unexpected option to %s keyword: '%s'", optname, optstr);
948 #define URL "https://suricata.io/our-story/deprecation-policy/"
951 "and will be removed soon. See %s",
955 "and will be removed soon. Use '%s' instead. "
964 if (optvalue != NULL && strlen(optvalue) > 0) {
965 size_t ovlen = strlen(optvalue);
966 char *ptr = optvalue;
976 SCLogError(
"invalid formatting or malformed option to %s keyword: \'%s\'", optname,
982 SCLogWarning(
"keyword \'%s\' has not been tested for firewall rules", optname);
999 SCLogError(
"invalid formatting or malformed option to %s keyword: \'%s\'", optname,
1005 SCLogError(
"invalid formatting to %s keyword: "
1006 "value must be double quoted \'%s\'",
1012 && ovlen && *ptr ==
'"')
1014 for (; ovlen > 0; ovlen--) {
1015 if (isblank(ptr[ovlen - 1])) {
1016 ptr[ovlen - 1] =
'\0';
1021 if (ovlen && ptr[ovlen - 1] !=
'"') {
1022 SCLogError(
"bad option value formatting (possible missing semicolon) "
1023 "for keyword %s: \'%s\'",
1031 ptr[ovlen - 1] =
'\0';
1036 "for keyword %s: \'%s\'",
1043 "quotes on %s keyword that doesn't support them: \'%s\'", optname, optstr);
1053 if (setup_ret < 0) {
1057 if (setup_ret == -2) {
1069 if (strlen(optend) > 0) {
1070 strlcpy(output, optend, output_size);
1085 Signature *s,
const char *addrstr,
char flag)
1087 SCLogDebug(
"Address Group \"%s\" to be parsed now", addrstr);
1091 if (strcasecmp(addrstr,
"any") == 0)
1099 if (strcasecmp(addrstr,
"any") == 0)
1114 static bool IsBuiltIn(
const char *n)
1116 if (strcmp(n,
"request_started") == 0 || strcmp(n,
"response_started") == 0) {
1119 if (strcmp(n,
"request_complete") == 0 || strcmp(n,
"response_complete") == 0) {
1137 if (strcmp(alproto_name,
"http") == 0)
1138 alproto_name =
"http1";
1139 SCLogDebug(
"alproto %u/%s", a, alproto_name);
1141 const int max_progress_ts =
1143 const int max_progress_tc =
1146 char ts_tx_started[64];
1147 snprintf(ts_tx_started,
sizeof(ts_tx_started),
"%s:request_started:generic", alproto_name);
1150 SCLogDebug(
"- hook %s:%s list %s (%u)", alproto_name,
"request_name", ts_tx_started,
1151 (uint32_t)strlen(ts_tx_started));
1153 char tc_tx_started[64];
1154 snprintf(tc_tx_started,
sizeof(tc_tx_started),
"%s:response_started:generic", alproto_name);
1157 SCLogDebug(
"- hook %s:%s list %s (%u)", alproto_name,
"response_name", tc_tx_started,
1158 (uint32_t)strlen(tc_tx_started));
1160 char ts_tx_complete[64];
1161 snprintf(ts_tx_complete,
sizeof(ts_tx_complete),
"%s:request_complete:generic",
1165 SCLogDebug(
"- hook %s:%s list %s (%u)", alproto_name,
"request_name", ts_tx_complete,
1166 (uint32_t)strlen(ts_tx_complete));
1168 char tc_tx_complete[64];
1169 snprintf(tc_tx_complete,
sizeof(tc_tx_complete),
"%s:response_complete:generic",
1173 SCLogDebug(
"- hook %s:%s list %s (%u)", alproto_name,
"response_name", tc_tx_complete,
1174 (uint32_t)strlen(tc_tx_complete));
1176 for (
int p = 0; p <= max_progress_ts; p++) {
1178 IPPROTO_TCP , a, p, STREAM_TOSERVER);
1179 if (
name != NULL && !IsBuiltIn(
name)) {
1181 snprintf(list_name,
sizeof(list_name),
"%s:%s:generic", alproto_name,
name);
1182 SCLogDebug(
"- hook %s:%s list %s (%u)", alproto_name,
name, list_name,
1183 (uint32_t)strlen(list_name));
1189 for (
int p = 0; p <= max_progress_tc; p++) {
1191 IPPROTO_TCP , a, p, STREAM_TOCLIENT);
1192 if (
name != NULL && !IsBuiltIn(
name)) {
1194 snprintf(list_name,
sizeof(list_name),
"%s:%s:generic", alproto_name,
name);
1195 SCLogDebug(
"- hook %s:%s list %s (%u)", alproto_name,
name, list_name,
1196 (uint32_t)strlen(list_name));
1222 if (strcmp(
str,
"flow_start") == 0) {
1224 }
else if (strcmp(
str,
"all") == 0) {
1237 return "flow_start";
1249 .t.pkt.ph = HookPktFromString(hook_str),
1257 static int SigParseProtoHookPkt(
Signature *s,
const char *proto_hook,
const char *p,
const char *h)
1270 SCLogDebug(
"protocol:%s hook:%s: type:%s parsed hook:%s", p, h,
1280 .t.app.alproto = alproto,
1281 .t.app.app_progress = progress,
1289 static int SigParseProtoHookApp(
Signature *s,
const char *proto_hook,
const char *p,
const char *h)
1291 if (strcmp(h,
"request_started") == 0) {
1295 }
else if (strcmp(h,
"response_started") == 0) {
1299 }
else if (strcmp(h,
"request_complete") == 0) {
1303 }
else if (strcmp(h,
"response_complete") == 0) {
1309 IPPROTO_TCP , s->
alproto, h, STREAM_TOSERVER);
1310 if (progress_ts >= 0) {
1315 IPPROTO_TCP , s->
alproto, h, STREAM_TOCLIENT);
1316 if (progress_tc < 0) {
1324 char generic_hook_name[64];
1325 snprintf(generic_hook_name,
sizeof(generic_hook_name),
"%s:generic", proto_hook);
1328 SCLogError(
"no list registered as %s for hook %s", generic_hook_name, proto_hook);
1333 SCLogDebug(
"protocol:%s hook:%s: type:%s alproto:%u hook:%d", p, h,
1353 static int SigParseProto(
Signature *s,
const char *protostr)
1356 if (strlen(protostr) > 32)
1361 const char *p =
proto;
1362 const char *h = NULL;
1364 bool has_hook = strchr(
proto,
':') != NULL;
1366 char *xsaveptr = NULL;
1367 p = strtok_r(
proto,
":", &xsaveptr);
1368 h = strtok_r(NULL,
":", &xsaveptr);
1386 if (SigParseProtoHookApp(s, protostr, p, h) < 0) {
1387 SCLogError(
"protocol \"%s\" does not support hook \"%s\"", p, h);
1394 "in a signature. Either detection for this protocol "
1395 "is not yet supported OR detection has been disabled for "
1396 "protocol through the yaml option "
1397 "app-layer.protocols.%s.detection-enabled",
1401 }
else if (h != NULL) {
1402 SCLogDebug(
"non-app-layer rule with %s:%s", p, h);
1404 if (SigParseProtoHookPkt(s, protostr, p, h) < 0) {
1405 SCLogError(
"protocol \"%s\" does not support hook \"%s\"", p, h);
1434 Signature *s,
const char *portstr,
char flag)
1440 SCLogDebug(
"Port group \"%s\" to be parsed", portstr);
1443 if (strcasecmp(portstr,
"any") == 0)
1447 }
else if (flag == 1) {
1448 if (strcasecmp(portstr,
"any") == 0)
1463 static int SigParseActionRejectValidate(
const char *action)
1465 #ifdef HAVE_LIBNET11
1466 #if defined HAVE_LIBCAP_NG && !defined HAVE_LIBNET_CAPABILITIES
1469 "incompatible with POSIX based capabilities with privs dropping. "
1470 "For rejects to work, run as root/super user.");
1476 "required for action \"%s\" but is not compiled into Suricata",
1486 static uint8_t ActionStringToFlags(
const char *action)
1488 if (strcasecmp(action,
"alert") == 0) {
1490 }
else if (strcasecmp(action,
"drop") == 0) {
1492 }
else if (strcasecmp(action,
"pass") == 0) {
1494 }
else if (strcasecmp(action,
"reject") == 0 ||
1495 strcasecmp(action,
"rejectsrc") == 0)
1497 if (!(SigParseActionRejectValidate(action)))
1500 }
else if (strcasecmp(action,
"rejectdst") == 0) {
1501 if (!(SigParseActionRejectValidate(action)))
1504 }
else if (strcasecmp(action,
"rejectboth") == 0) {
1505 if (!(SigParseActionRejectValidate(action)))
1508 }
else if (strcasecmp(action,
"config") == 0) {
1510 }
else if (strcasecmp(action,
"accept") == 0) {
1513 SCLogError(
"An invalid action \"%s\" was given", action);
1529 static int SigParseAction(
Signature *s,
const char *action_in)
1532 strlcpy(action, action_in,
sizeof(action));
1533 const char *a = action;
1534 const char *o = NULL;
1536 bool has_scope = strchr(action,
':') != NULL;
1538 char *xsaveptr = NULL;
1539 a = strtok_r(action,
":", &xsaveptr);
1540 o = strtok_r(NULL,
":", &xsaveptr);
1544 SCLogError(
"invalid protocol specification '%s'", action_in);
1548 uint8_t
flags = ActionStringToFlags(a);
1554 uint8_t scope_flags = 0;
1556 if (strcmp(o,
"packet") == 0) {
1558 }
else if (strcmp(o,
"flow") == 0) {
1561 SCLogError(
"invalid action scope '%s' in action '%s': only 'packet' and 'flow' "
1568 if (strcmp(o,
"packet") == 0) {
1570 }
else if (strcmp(o,
"hook") == 0) {
1572 }
else if (strcmp(o,
"tx") == 0) {
1574 }
else if (strcmp(o,
"flow") == 0) {
1578 "invalid action scope '%s' in action '%s': only 'packet', 'flow', 'tx' and "
1585 SCLogError(
"invalid action scope '%s' in action '%s': scope only supported for actions "
1586 "'drop', 'pass' and 'reject'",
1594 SCLogError(
"firewall rules require setting an explicit action scope");
1599 SCLogError(
"'accept' action only supported for firewall rules");
1604 SCLogError(
"'pass' action not supported for firewall rules");
1623 static inline int SigParseToken(
char **input,
char *output,
1624 const size_t output_size)
1626 size_t len = *input == NULL ? 0 : strlen(*input);
1632 while (
len && isblank(**input)) {
1637 char *endptr = strpbrk(*input,
" \t\n\r");
1638 if (endptr != NULL) {
1641 strlcpy(output, *input, output_size);
1658 static inline int SigParseList(
char **input,
char *output,
1659 const size_t output_size)
1662 size_t len = *input != NULL ? strlen(*input) : 0;
1668 while (
len && isblank(**input)) {
1674 for (i = 0; i <
len; i++) {
1675 char c = (*input)[i];
1678 }
else if (c ==
']') {
1680 }
else if (c ==
' ') {
1691 strlcpy(output, *input, output_size);
1692 *input = *input + i + 1;
1712 SigParseToken(&index, parser->
action,
sizeof(parser->
action));
1718 SigParseList(&index, parser->
src,
sizeof(parser->
src));
1721 SigParseList(&index, parser->
sp,
sizeof(parser->
sp));
1727 SigParseList(&index, parser->
dst,
sizeof(parser->
dst));
1730 SigParseList(&index, parser->
dp,
sizeof(parser->
dp));
1733 if (index == NULL) {
1737 while (isspace(*index) || *index ==
'(') {
1740 for (
size_t i = strlen(index); i > 0; i--) {
1741 if (isspace(index[i - 1]) || index[i - 1] ==
')') {
1742 index[i - 1] =
'\0';
1754 if (SigParseAction(s, parser->
action) < 0)
1757 if (SigParseProto(s, parser->
protocol) < 0)
1760 if (strcmp(parser->
direction,
"<>") == 0) {
1762 }
else if (strcmp(parser->
direction,
"=>") == 0) {
1764 SCLogError(
"transactional bidirectional rules not supported for firewall rules");
1769 }
else if (strcmp(parser->
direction,
"->") != 0) {
1770 SCLogError(
"\"%s\" is not a valid direction modifier, "
1771 "\"->\" and \"<>\" are supported.",
1798 static inline bool CheckAscii(
const char *
str)
1800 for (
size_t i = 0; i < strlen(
str); i++) {
1801 if (
str[i] < 0x20) {
1803 if (
str[i] == 0x0a ||
str[i] == 0x0d ||
str[i] == 0x09) {
1807 }
else if (
str[i] == 0x7f) {
1831 if (!rs_check_utf8(sigstr)) {
1836 if (!CheckAscii(sigstr)) {
1837 SCLogError(
"rule contains invalid (control) characters");
1841 int ret = SigParseBasics(
de_ctx, s, sigstr, parser, addrs_direction, requires);
1848 if (strlen(parser->
opts) > 0) {
1849 size_t buffer_size = strlen(parser->
opts) + 1;
1850 char input[buffer_size];
1851 char output[buffer_size];
1852 memset(input, 0x00, buffer_size);
1853 memcpy(input, parser->
opts, strlen(parser->
opts) + 1);
1859 memset(output, 0x00, buffer_size);
1860 ret = SigParseOptions(
de_ctx, s, input, output, buffer_size, requires);
1862 memcpy(input, output, buffer_size);
1894 memset(b, 0,
sizeof(*b));
1942 static void SigMetadataFree(
Signature *s)
1949 if (s == NULL || s->
metadata == NULL) {
1956 next_mdata = mdata->
next;
1987 next_ref = ref->
next;
2041 while (sm != NULL) {
2050 while (sm != NULL) {
2071 if (s->
sp != NULL) {
2074 if (s->
dp != NULL) {
2112 SCLogError(
"transforms must directly follow stickybuffers");
2145 if (s->
alproto == *alprotos) {
2188 }
else if (i == 1) {
2220 if (!AppProtoIsValid(alproto)) {
2244 alproto = AppProtoCommon(s->
alproto, alproto);
2246 SCLogError(
"can't set rule app proto to %s: already set to %s",
2273 if (addr_match4 == NULL) {
2279 addr_match4[idx].
ip =
SCNtohl(da->ip.addr_data32[0]);
2280 addr_match4[idx].
ip2 =
SCNtohl(da->ip2.addr_data32[0]);
2299 if (addr_match6 == NULL) {
2305 addr_match6[idx].
ip[0] =
SCNtohl(da->ip.addr_data32[0]);
2306 addr_match6[idx].
ip[1] =
SCNtohl(da->ip.addr_data32[1]);
2307 addr_match6[idx].
ip[2] =
SCNtohl(da->ip.addr_data32[2]);
2308 addr_match6[idx].
ip[3] =
SCNtohl(da->ip.addr_data32[3]);
2309 addr_match6[idx].
ip2[0] =
SCNtohl(da->ip2.addr_data32[0]);
2310 addr_match6[idx].
ip2[1] =
SCNtohl(da->ip2.addr_data32[1]);
2311 addr_match6[idx].
ip2[2] =
SCNtohl(da->ip2.addr_data32[2]);
2312 addr_match6[idx].
ip2[3] =
SCNtohl(da->ip2.addr_data32[3]);
2325 static void SigBuildAddressMatchArray(
Signature *s)
2342 static int SigMatchListLen(
SigMatch *sm)
2345 for (; sm != NULL; sm = sm->
next)
2356 int len = SigMatchListLen(
head);
2362 FatalError(
"initializing the detection engine failed");
2368 for (; sm != NULL; sm = sm->
next, smd++) {
2408 SCLogDebug(
"s %u: no mpm; prefilter? de_ctx->prefilter_setting %u "
2409 "s->init_data->has_possible_prefilter %s",
2423 prefilter_list =
MIN(prefilter_list, sm->
type);
2433 if (sm->
type == prefilter_list) {
2450 SCLogError(
"rule %u is loaded as a firewall rule, but does not specify an "
2458 static void DetectFirewallRuleSetTable(
Signature *s)
2494 if (!DetectFirewallRuleValidate(
de_ctx, s))
2498 uint32_t sig_flags = 0;
2503 nlists += (nlists > 0);
2507 SCLogError(
"rule %u setup buffer %s but didn't add matches to it", s->
id,
2512 bool has_frame =
false;
2513 bool has_app =
false;
2514 bool has_pkt =
false;
2515 bool has_pmatch =
false;
2525 struct BufferVsDir {
2528 } bufdir[nlists + 1];
2529 memset(&bufdir, 0, (nlists + 1) *
sizeof(
struct BufferVsDir));
2546 if (b->
head == NULL) {
2551 has_frame |= bt->
frame;
2557 "specific matches (like dsize, flags, ttl) with stream / "
2558 "state matching by matching on app layer proto (like using "
2559 "http_* keywords).");
2564 for (; app != NULL; app = app->
next) {
2579 bufdir[b->
id].ts += (app->
dir == 0);
2580 bufdir[b->
id].tc += (app->
dir == 1);
2594 SCLogError(
"engine progress value doesn't match hook");
2614 for (
int x = 0; x < nlists; x++) {
2615 if (bufdir[x].
ts == 0 && bufdir[x].tc == 0)
2617 ts_excl += (bufdir[x].ts > 0 && bufdir[x].tc == 0);
2618 tc_excl += (bufdir[x].ts == 0 && bufdir[x].tc > 0);
2619 dir_amb += (bufdir[x].ts > 0 && bufdir[x].tc > 0);
2625 if (!ts_excl || !tc_excl) {
2626 SCLogError(
"rule %u should use both directions, but does not", s->
id);
2630 SCLogError(
"rule %u means to use both directions, cannot have keywords ambiguous about "
2635 }
else if (ts_excl && tc_excl) {
2637 "rule %u mixes keywords with conflicting directions, a transactional rule with => "
2641 }
else if (ts_excl) {
2642 SCLogDebug(
"%u: implied rule direction is toserver", s->
id);
2644 SCLogError(
"rule %u mixes keywords with conflicting directions", s->
id);
2647 }
else if (tc_excl) {
2648 SCLogDebug(
"%u: implied rule direction is toclient", s->
id);
2650 SCLogError(
"rule %u mixes keywords with conflicting directions", s->
id);
2653 }
else if (dir_amb) {
2654 SCLogDebug(
"%u: rule direction cannot be deduced from keywords", s->
id);
2660 "tcp-stream or flow:only_stream. Invalidating signature.");
2665 SCLogError(
"You seem to have mixed keywords "
2666 "that require inspection in both directions. Atm we only "
2667 "support keywords in one direction within a rule.");
2671 if (has_pmatch && has_frame) {
2672 SCLogError(
"can't mix pure content and frame inspection");
2675 if (has_app && has_frame) {
2676 SCLogError(
"can't mix app-layer buffer and frame inspection");
2679 if (has_pkt && has_frame) {
2680 SCLogError(
"can't mix pkt buffer and frame inspection");
2688 if (s->
proto.
proto[IPPROTO_TCP / 8] & (1 << (IPPROTO_TCP % 8))) {
2719 "support file matching",
2734 SCLogError(
"No protocol support file matching");
2739 SCLogError(
"protocol HTTP2 doesn't support file name matching");
2759 memset(&parser, 0x00,
sizeof(parser));
2764 if (firewall_rule) {
2781 int ret = SigParse(
de_ctx, sig, sigstr, dir, &parser,
true);
2788 }
else if (ret < 0) {
2794 SCLogError(
"Signature missing required value \"sid\".");
2799 ret = SigParse(
de_ctx, sig, sigstr, dir, &parser,
false);
2805 }
else if (ret == -2) {
2808 }
else if (ret < 0) {
2813 if (sig->
prio == -1)
2820 int override_needed = 0;
2824 override_needed = 1;
2826 override_needed = 1;
2828 for (s = 0; s <
sizeof(sig->
proto.
proto); s++) {
2830 override_needed = 0;
2839 if (override_needed)
2849 for ( ; sm != NULL; sm = sm->
next) {
2873 SCLogDebug(
"sig %"PRIu32
" SIG_FLAG_APPLAYER: %s, SIG_FLAG_PACKET: %s",
2877 SigBuildAddressMatchArray(sig);
2888 SigSetupPrefilter(
de_ctx, sig);
2891 if (SigValidate(
de_ctx, sig) == 0) {
2899 DetectFirewallRuleSetTable(sig);
2925 static bool SigHasSameSourceAndDestination(
const Signature *s)
2967 if (SigHasSameSourceAndDestination(sig)) {
2968 SCLogInfo(
"Rule with ID %u is bidirectional, but source and destination are the same, "
2969 "treating the rule as unidirectional", sig->
id);
2974 if (sig->
next == NULL) {
3004 return SigInitDo(
de_ctx, sigstr,
false);
3009 return SigInitDo(
de_ctx, sigstr,
true);
3018 static void DetectParseDupSigFreeFunc(
void *data)
3034 static uint32_t DetectParseDupSigHashFunc(
HashListTable *ht,
void *data, uint16_t datalen)
3053 static char DetectParseDupSigCompareFunc(
void *data1, uint16_t len1,
void *data2,
3059 if (sw1 == NULL || sw2 == NULL ||
3060 sw1->
s == NULL || sw2->
s == NULL)
3064 if (sw1->
s->
id == sw2->
s->
id && sw1->
s->
gid == sw2->
s->
gid)
return 1;
3080 DetectParseDupSigHashFunc,
3081 DetectParseDupSigCompareFunc,
3082 DetectParseDupSigFreeFunc);
3143 if (sw_dup == NULL) {
3156 (
void *)&sw_tmp, 0);
3168 if (sw->
s->
rev <= sw_dup->
s->
rev) {
3177 if (sw_dup->
s_prev == NULL) {
3185 sw_temp.
s = sw_dup->
s->
next;
3189 if (sw_temp.
s != NULL) {
3191 (
void *)&sw_temp, 0);
3211 sw_temp.
s = sw_dup->
s->
next;
3219 if (sw_temp.
s != NULL) {
3221 (
void *)&sw_temp, 0);
3236 (
void *)&sw_tmp, 0);
3237 if (sw_old->
s != sw_dup->
s) {
3280 int dup_sig = DetectEngineSignatureIsDuplicate(
de_ctx, sig);
3284 SCLogError(
"Duplicate signature \"%s\"", sigstr);
3286 }
else if (dup_sig == 2) {
3288 " so the older sig replaced by this new signature \"%s\"",
3293 if (sig->
next != NULL) {
3310 return (dup_sig == 0 || dup_sig == 2) ? sig : NULL;
3314 if (sig != NULL && sig->
next != NULL) {
3352 int dup_sig = DetectEngineSignatureIsDuplicate(
de_ctx, sig);
3356 SCLogError(
"Duplicate signature \"%s\"", sigstr);
3358 }
else if (dup_sig == 2) {
3360 " so the older sig replaced by this new signature \"%s\"",
3365 if (sig->
next != NULL) {
3382 return (dup_sig == 0 || dup_sig == 2) ? sig : NULL;
3386 if (sig != NULL && sig->
next != NULL) {
3399 int start_offset,
int options)
3401 *match = pcre2_match_data_create_from_pattern(parse_regex->
regex, NULL);
3403 return pcre2_match(parse_regex->
regex, (PCRE2_SPTR8)
str, strlen(
str), options, start_offset,
3404 *match, parse_regex->
context);
3411 pcre2_code_free(r->
regex);
3414 pcre2_match_context_free(r->
context);
3429 g_detect_parse_regex_list = NULL;
3438 FatalError(
"failed to alloc memory for pcre free list");
3441 r->
next = g_detect_parse_regex_list;
3442 g_detect_parse_regex_list = r;
3450 detect_parse->
regex =
3451 pcre2_compile((PCRE2_SPTR8)parse_str, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
3452 if (detect_parse->
regex == NULL) {
3453 PCRE2_UCHAR errbuffer[256];
3454 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
3455 SCLogError(
"pcre compile of \"%s\" failed at "
3457 parse_str, en, errbuffer);
3460 detect_parse->
context = pcre2_match_context_create(NULL);
3461 if (detect_parse->
context == NULL) {
3462 SCLogError(
"pcre2 could not create match context");
3463 pcre2_code_free(detect_parse->
regex);
3464 detect_parse->
regex = NULL;
3479 if (detect_parse == NULL) {
3483 detect_parse->
regex =
3484 pcre2_compile((PCRE2_SPTR8)parse_str, PCRE2_ZERO_TERMINATED, opts, &en, &eo, NULL);
3485 if (detect_parse->
regex == NULL) {
3486 PCRE2_UCHAR errbuffer[256];
3487 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
3488 SCLogError(
"pcre2 compile of \"%s\" failed at "
3490 parse_str, (
int)eo, errbuffer);
3495 detect_parse->
next = g_detect_parse_regex_list;
3496 g_detect_parse_regex_list = detect_parse;
3497 return detect_parse;
3501 pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen)
3503 int r = pcre2_substring_copy_bynumber(match_data, number, buffer, bufflen);
3504 if (r == PCRE2_ERROR_UNSET) {
3513 pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr, PCRE2_SIZE *bufflen)
3515 int r = pcre2_substring_get_bynumber(match_data, number, bufferptr, bufflen);
3516 if (r == PCRE2_ERROR_UNSET) {
3542 if (strcmp(
str,
"to_client") == 0) {
3551 }
else if (strcmp(
str,
"to_server") == 0) {
3561 SCLogError(
"unknown option: only accepts to_server or to_client");
3576 static int SigParseTest01 (
void)
3585 sig =
SigInit(
de_ctx,
"alert tcp 1.2.3.4 any -> !1.2.3.4 any (msg:\"SigParseTest01\"; sid:1;)");
3595 static int SigParseTest02 (
void)
3609 sig =
SigInit(
de_ctx,
"alert tcp any !21:902 -> any any (msg:\"ET MALWARE Suspicious 220 Banner on Local Port\"; content:\"220\"; offset:0; depth:4; pcre:\"/220[- ]/\"; sid:2003055; rev:4;)");
3637 static int SigParseTest03 (
void)
3646 sig =
SigInit(
de_ctx,
"alert tcp 1.2.3.4 any <- !1.2.3.4 any (msg:\"SigParseTest03\"; sid:1;)");
3649 printf(
"expected NULL got sig ptr %p: ",sig);
3658 static int SigParseTest04 (
void)
3667 sig =
SigInit(
de_ctx,
"alert tcp 1.2.3.4 1024: -> !1.2.3.4 1024: (msg:\"SigParseTest04\"; sid:1;)");
3678 static int SigParseTest05 (
void)
3687 sig =
SigInit(
de_ctx,
"alert tcp 1.2.3.4 1024:65536 -> !1.2.3.4 any (msg:\"SigParseTest05\"; sid:1;)");
3691 printf(
"signature didn't fail to parse as we expected: ");
3701 static int SigParseTest06 (
void)
3710 sig =
SigInit(
de_ctx,
"alert tcp any any -> any any (flow:to_server; content:\"GET\"; nocase; http_method; uricontent:\"/uri/\"; nocase; content:\"Host|3A| abc\"; nocase; sid:1; rev:1;)");
3714 printf(
"signature failed to parse: ");
3728 static int SigParseTest07(
void)
3750 static int SigParseTest08(
void)
3773 static int SigParseTest09(
void)
3824 static int SigParseTest10(
void)
3856 static int SigParseTest11(
void)
3867 "drop tcp any any -> any 80 (msg:\"Snort_Inline is blocking the http link\"; sid:1;) ");
3869 printf(
"sig 1 didn't parse: ");
3874 "the http link\"; sid:2;) ");
3876 printf(
"sig 2 didn't parse: ");
3890 static int SigParseTest12(
void)
3902 printf(
"sig 1 should have given an error: ");
3916 static int SigParseTest13(
void)
3928 printf(
"sig 1 invalidated: failure");
3933 printf(
"sig doesn't have stream flag set\n");
3938 printf(
"sig has packet flag set\n");
3953 static int SigParseTest14(
void)
3965 printf(
"sig 1 invalidated: failure");
3970 printf(
"sig doesn't have packet flag set\n");
3975 printf(
"sig has stream flag set\n");
3990 static int SigParseTest15(
void)
4002 printf(
"sig 1 invalidated: failure");
4007 printf(
"sig doesn't have packet flag set\n");
4012 printf(
"sig doesn't have stream flag set\n");
4027 static int SigParseTest16(
void)
4039 printf(
"sig 1 invalidated: failure");
4044 printf(
"sig doesn't have packet flag set\n");
4049 printf(
"sig doesn't have stream flag set\n");
4064 static int SigParseTest17(
void)
4076 printf(
"sig 1 invalidated: failure");
4081 printf(
"sig doesn't have packet flag set\n");
4086 printf(
"sig doesn't have stream flag set\n");
4099 static int SigParseTest18 (
void)
4107 if (
DetectEngineAppendSig(
de_ctx,
"alert tcp 1.2.3.4 any -> !1.2.3.4 any (msg:\"SigParseTest01\"; sid:99999999999999999999;)") != NULL)
4118 static int SigParseTest19 (
void)
4126 if (
DetectEngineAppendSig(
de_ctx,
"alert tcp 1.2.3.4 any -> !1.2.3.4 any (msg:\"SigParseTest01\"; sid:1; gid:99999999999999999999;)") != NULL)
4137 static int SigParseTest20 (
void)
4145 if (
DetectEngineAppendSig(
de_ctx,
"alert tcp 1.2.3.4 any -> !1.2.3.4 any (msg:\"SigParseTest01\"; sid:1; rev:99999999999999999999;)") != NULL)
4156 static int SigParseTest21 (
void)
4175 static int SigParseTest22 (
void)
4183 if (
DetectEngineAppendSig(
de_ctx,
"alert tcp [10.10.10.0/24, !10.10.10.247] any -> [10.10.10.0/24, !10.10.10.247] any (sid:1;)") == NULL)
4196 static int SigParseTest23(
void)
4211 static int SigParseBidirecTest06 (
void)
4231 static int SigParseBidirecTest07 (
void)
4251 static int SigParseBidirecTest08 (
void)
4271 static int SigParseBidirecTest09 (
void)
4291 static int SigParseBidirecTest10 (
void)
4311 static int SigParseBidirecTest11 (
void)
4331 static int SigParseBidirecTest12 (
void)
4351 static int SigParseBidirecTest13 (
void)
4370 static int SigParseBidirecTest14 (
void)
4391 static int SigTestBidirec01 (
void)
4403 if (sig->
next != NULL)
4422 static int SigTestBidirec02 (
void)
4441 if (sig->
next == NULL)
4446 if (copy->
next != NULL)
4467 static int SigTestBidirec03 (
void)
4479 const char *sigs[3];
4480 sigs[0] =
"alert tcp any any -> 192.168.1.1 any (msg:\"SigTestBidirec03 sid 1\"; sid:1;)";
4481 sigs[1] =
"alert tcp any any <> 192.168.1.1 any (msg:\"SigTestBidirec03 sid 2 bidirectional\"; sid:2;)";
4482 sigs[2] =
"alert tcp any any -> 192.168.1.1 any (msg:\"SigTestBidirec03 sid 3\"; sid:3;)";
4489 if (sig->
next == NULL)
4500 uint8_t rawpkt1_ether[] = {
4501 0x00,0x50,0x56,0xea,0x00,0xbd,0x00,0x0c,
4502 0x29,0x40,0xc8,0xb5,0x08,0x00,0x45,0x00,
4503 0x01,0xa8,0xb9,0xbb,0x40,0x00,0x40,0x06,
4504 0xe0,0xbf,0xc0,0xa8,0x1c,0x83,0xc0,0xa8,
4505 0x01,0x01,0xb9,0x0a,0x00,0x50,0x6f,0xa2,
4506 0x92,0xed,0x7b,0xc1,0xd3,0x4d,0x50,0x18,
4507 0x16,0xd0,0xa0,0x6f,0x00,0x00,0x47,0x45,
4508 0x54,0x20,0x2f,0x20,0x48,0x54,0x54,0x50,
4509 0x2f,0x31,0x2e,0x31,0x0d,0x0a,0x48,0x6f,
4510 0x73,0x74,0x3a,0x20,0x31,0x39,0x32,0x2e,
4511 0x31,0x36,0x38,0x2e,0x31,0x2e,0x31,0x0d,
4512 0x0a,0x55,0x73,0x65,0x72,0x2d,0x41,0x67,
4513 0x65,0x6e,0x74,0x3a,0x20,0x4d,0x6f,0x7a,
4514 0x69,0x6c,0x6c,0x61,0x2f,0x35,0x2e,0x30,
4515 0x20,0x28,0x58,0x31,0x31,0x3b,0x20,0x55,
4516 0x3b,0x20,0x4c,0x69,0x6e,0x75,0x78,0x20,
4517 0x78,0x38,0x36,0x5f,0x36,0x34,0x3b,0x20,
4518 0x65,0x6e,0x2d,0x55,0x53,0x3b,0x20,0x72,
4519 0x76,0x3a,0x31,0x2e,0x39,0x2e,0x30,0x2e,
4520 0x31,0x34,0x29,0x20,0x47,0x65,0x63,0x6b,
4521 0x6f,0x2f,0x32,0x30,0x30,0x39,0x30,0x39,
4522 0x30,0x32,0x31,0x37,0x20,0x55,0x62,0x75,
4523 0x6e,0x74,0x75,0x2f,0x39,0x2e,0x30,0x34,
4524 0x20,0x28,0x6a,0x61,0x75,0x6e,0x74,0x79,
4525 0x29,0x20,0x46,0x69,0x72,0x65,0x66,0x6f,
4526 0x78,0x2f,0x33,0x2e,0x30,0x2e,0x31,0x34,
4527 0x0d,0x0a,0x41,0x63,0x63,0x65,0x70,0x74,
4528 0x3a,0x20,0x74,0x65,0x78,0x74,0x2f,0x68,
4529 0x74,0x6d,0x6c,0x2c,0x61,0x70,0x70,0x6c,
4530 0x69,0x63,0x61,0x74,0x69,0x6f,0x6e,0x2f,
4531 0x78,0x68,0x74,0x6d,0x6c,0x2b,0x78,0x6d,
4532 0x6c,0x2c,0x61,0x70,0x70,0x6c,0x69,0x63,
4533 0x61,0x74,0x69,0x6f,0x6e,0x2f,0x78,0x6d,
4534 0x6c,0x3b,0x71,0x3d,0x30,0x2e,0x39,0x2c,
4535 0x2a,0x2f,0x2a,0x3b,0x71,0x3d,0x30,0x2e,
4536 0x38,0x0d,0x0a,0x41,0x63,0x63,0x65,0x70,
4537 0x74,0x2d,0x4c,0x61,0x6e,0x67,0x75,0x61,
4538 0x67,0x65,0x3a,0x20,0x65,0x6e,0x2d,0x75,
4539 0x73,0x2c,0x65,0x6e,0x3b,0x71,0x3d,0x30,
4540 0x2e,0x35,0x0d,0x0a,0x41,0x63,0x63,0x65,
4541 0x70,0x74,0x2d,0x45,0x6e,0x63,0x6f,0x64,
4542 0x69,0x6e,0x67,0x3a,0x20,0x67,0x7a,0x69,
4543 0x70,0x2c,0x64,0x65,0x66,0x6c,0x61,0x74,
4544 0x65,0x0d,0x0a,0x41,0x63,0x63,0x65,0x70,
4545 0x74,0x2d,0x43,0x68,0x61,0x72,0x73,0x65,
4546 0x74,0x3a,0x20,0x49,0x53,0x4f,0x2d,0x38,
4547 0x38,0x35,0x39,0x2d,0x31,0x2c,0x75,0x74,
4548 0x66,0x2d,0x38,0x3b,0x71,0x3d,0x30,0x2e,
4549 0x37,0x2c,0x2a,0x3b,0x71,0x3d,0x30,0x2e,
4550 0x37,0x0d,0x0a,0x4b,0x65,0x65,0x70,0x2d,
4551 0x41,0x6c,0x69,0x76,0x65,0x3a,0x20,0x33,
4552 0x30,0x30,0x0d,0x0a,0x43,0x6f,0x6e,0x6e,
4553 0x65,0x63,0x74,0x69,0x6f,0x6e,0x3a,0x20,
4554 0x6b,0x65,0x65,0x70,0x2d,0x61,0x6c,0x69,
4555 0x76,0x65,0x0d,0x0a,0x0d,0x0a };
4565 uint32_t sids[3] = {1, 2, 3};
4566 uint32_t results[3] = {1, 1, 1};
4582 static int SigTestBidirec04 (
void)
4597 sig =
DetectEngineAppendSig(
de_ctx,
"alert tcp 192.168.1.1 any <> any any (msg:\"SigTestBidirec03 sid 2 bidirectional\"; sid:2;)");
4602 if (sig->
next == NULL)
4614 if (sig->
next == NULL)
4625 uint8_t rawpkt1_ether[] = {
4626 0x00,0x50,0x56,0xea,0x00,0xbd,0x00,0x0c,
4627 0x29,0x40,0xc8,0xb5,0x08,0x00,0x45,0x00,
4628 0x01,0xa8,0xb9,0xbb,0x40,0x00,0x40,0x06,
4629 0xe0,0xbf,0xc0,0xa8,0x1c,0x83,0xc0,0xa8,
4630 0x01,0x01,0xb9,0x0a,0x00,0x50,0x6f,0xa2,
4631 0x92,0xed,0x7b,0xc1,0xd3,0x4d,0x50,0x18,
4632 0x16,0xd0,0xa0,0x6f,0x00,0x00,0x47,0x45,
4633 0x54,0x20,0x2f,0x20,0x48,0x54,0x54,0x50,
4634 0x2f,0x31,0x2e,0x31,0x0d,0x0a,0x48,0x6f,
4635 0x73,0x74,0x3a,0x20,0x31,0x39,0x32,0x2e,
4636 0x31,0x36,0x38,0x2e,0x31,0x2e,0x31,0x0d,
4637 0x0a,0x55,0x73,0x65,0x72,0x2d,0x41,0x67,
4638 0x65,0x6e,0x74,0x3a,0x20,0x4d,0x6f,0x7a,
4639 0x69,0x6c,0x6c,0x61,0x2f,0x35,0x2e,0x30,
4640 0x20,0x28,0x58,0x31,0x31,0x3b,0x20,0x55,
4641 0x3b,0x20,0x4c,0x69,0x6e,0x75,0x78,0x20,
4642 0x78,0x38,0x36,0x5f,0x36,0x34,0x3b,0x20,
4643 0x65,0x6e,0x2d,0x55,0x53,0x3b,0x20,0x72,
4644 0x76,0x3a,0x31,0x2e,0x39,0x2e,0x30,0x2e,
4645 0x31,0x34,0x29,0x20,0x47,0x65,0x63,0x6b,
4646 0x6f,0x2f,0x32,0x30,0x30,0x39,0x30,0x39,
4647 0x30,0x32,0x31,0x37,0x20,0x55,0x62,0x75,
4648 0x6e,0x74,0x75,0x2f,0x39,0x2e,0x30,0x34,
4649 0x20,0x28,0x6a,0x61,0x75,0x6e,0x74,0x79,
4650 0x29,0x20,0x46,0x69,0x72,0x65,0x66,0x6f,
4651 0x78,0x2f,0x33,0x2e,0x30,0x2e,0x31,0x34,
4652 0x0d,0x0a,0x41,0x63,0x63,0x65,0x70,0x74,
4653 0x3a,0x20,0x74,0x65,0x78,0x74,0x2f,0x68,
4654 0x74,0x6d,0x6c,0x2c,0x61,0x70,0x70,0x6c,
4655 0x69,0x63,0x61,0x74,0x69,0x6f,0x6e,0x2f,
4656 0x78,0x68,0x74,0x6d,0x6c,0x2b,0x78,0x6d,
4657 0x6c,0x2c,0x61,0x70,0x70,0x6c,0x69,0x63,
4658 0x61,0x74,0x69,0x6f,0x6e,0x2f,0x78,0x6d,
4659 0x6c,0x3b,0x71,0x3d,0x30,0x2e,0x39,0x2c,
4660 0x2a,0x2f,0x2a,0x3b,0x71,0x3d,0x30,0x2e,
4661 0x38,0x0d,0x0a,0x41,0x63,0x63,0x65,0x70,
4662 0x74,0x2d,0x4c,0x61,0x6e,0x67,0x75,0x61,
4663 0x67,0x65,0x3a,0x20,0x65,0x6e,0x2d,0x75,
4664 0x73,0x2c,0x65,0x6e,0x3b,0x71,0x3d,0x30,
4665 0x2e,0x35,0x0d,0x0a,0x41,0x63,0x63,0x65,
4666 0x70,0x74,0x2d,0x45,0x6e,0x63,0x6f,0x64,
4667 0x69,0x6e,0x67,0x3a,0x20,0x67,0x7a,0x69,
4668 0x70,0x2c,0x64,0x65,0x66,0x6c,0x61,0x74,
4669 0x65,0x0d,0x0a,0x41,0x63,0x63,0x65,0x70,
4670 0x74,0x2d,0x43,0x68,0x61,0x72,0x73,0x65,
4671 0x74,0x3a,0x20,0x49,0x53,0x4f,0x2d,0x38,
4672 0x38,0x35,0x39,0x2d,0x31,0x2c,0x75,0x74,
4673 0x66,0x2d,0x38,0x3b,0x71,0x3d,0x30,0x2e,
4674 0x37,0x2c,0x2a,0x3b,0x71,0x3d,0x30,0x2e,
4675 0x37,0x0d,0x0a,0x4b,0x65,0x65,0x70,0x2d,
4676 0x41,0x6c,0x69,0x76,0x65,0x3a,0x20,0x33,
4677 0x30,0x30,0x0d,0x0a,0x43,0x6f,0x6e,0x6e,
4678 0x65,0x63,0x74,0x69,0x6f,0x6e,0x3a,0x20,
4679 0x6b,0x65,0x65,0x70,0x2d,0x61,0x6c,0x69,
4680 0x76,0x65,0x0d,0x0a,0x0d,0x0a };
4689 memset(&th_v, 0,
sizeof(th_v));
4729 static int SigParseTestNegation01 (
void)
4743 static int SigParseTestNegation02 (
void)
4754 s =
SigInit(
de_ctx,
"alert tcp any !any -> any any (msg:\"SigTest41-02 src ip is !any \"; classtype:misc-activity; sid:410002; rev:1;)");
4769 static int SigParseTestNegation03 (
void)
4780 s =
SigInit(
de_ctx,
"alert tcp any any -> any [80:!80] (msg:\"SigTest41-03 dst port [80:!80] \"; classtype:misc-activity; sid:410003; rev:1;)");
4795 static int SigParseTestNegation04 (
void)
4806 s =
SigInit(
de_ctx,
"alert tcp any any -> any [80,!80] (msg:\"SigTest41-03 dst port [80:!80] \"; classtype:misc-activity; sid:410003; rev:1;)");
4821 static int SigParseTestNegation05 (
void)
4832 s =
SigInit(
de_ctx,
"alert tcp any any -> [192.168.0.2,!192.168.0.2] any (msg:\"SigTest41-04 dst ip [192.168.0.2,!192.168.0.2] \"; classtype:misc-activity; sid:410004; rev:1;)");
4847 static int SigParseTestNegation06 (
void)
4858 s =
SigInit(
de_ctx,
"alert tcp any any -> any [100:1000,!1:20000] (msg:\"SigTest41-05 dst port [100:1000,!1:20000] \"; classtype:misc-activity; sid:410005; rev:1;)");
4874 static int SigParseTestNegation07 (
void)
4880 de_ctx,
"alert tcp any any -> [192.168.0.2,!192.168.0.0/24] any (sid:410006;)");
4889 static int SigParseTestNegation08 (
void)
4900 s =
SigInit(
de_ctx,
"alert tcp any any -> [192.168.0.0/16,!192.168.0.0/24] any (sid:410006; rev:1;)");
4915 static int SigParseTestMpm01 (
void)
4924 sig =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"mpm test\"; content:\"abcd\"; sid:1;)");
4926 printf(
"sig failed to init: ");
4931 printf(
"sig doesn't have content list: ");
4946 static int SigParseTestMpm02 (
void)
4955 sig =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"mpm test\"; content:\"abcd\"; content:\"abcdef\"; sid:1;)");
4957 printf(
"sig failed to init: ");
4962 printf(
"sig doesn't have content list: ");
4977 static int SigParseTestAppLayerTLS01(
void)
4988 s =
SigInit(
de_ctx,
"alert tls any any -> any any (msg:\"SigParseTestAppLayerTLS01 \"; sid:410006; rev:1;)");
4990 printf(
"parsing sig failed: ");
4995 printf(
"alproto not set: ");
5012 static int SigParseTestAppLayerTLS02(
void)
5023 s =
SigInit(
de_ctx,
"alert tls any any -> any any (msg:\"SigParseTestAppLayerTLS02 \"; tls.version:1.0; sid:410006; rev:1;)");
5025 printf(
"parsing sig failed: ");
5030 printf(
"alproto not set: ");
5046 static int SigParseTestAppLayerTLS03(
void)
5057 s =
SigInit(
de_ctx,
"alert tls any any -> any any (msg:\"SigParseTestAppLayerTLS03 \"; tls.version:2.5; sid:410006; rev:1;)");
5070 static int SigParseTestUnbalancedQuotes01(
void)
5080 "alert http any any -> any any (msg:\"SigParseTestUnbalancedQuotes01\"; "
5081 "pcre:\"/\\/[a-z]+\\.php\\?[a-z]+?=\\d{7}&[a-z]+?=\\d{7,8}$/U\" "
5082 "flowbits:set,et.exploitkitlanding; classtype:trojan-activity; sid:2017078; rev:5;)");
5088 static int SigParseTestContentGtDsize01(
void)
5095 "alert http any any -> any any ("
5096 "dsize:21; content:\"0123456789001234567890|00 00|\"; "
5103 static int SigParseTestContentGtDsize02(
void)
5110 "alert http any any -> any any ("
5111 "dsize:21; content:\"0123456789|00 00|\"; offset:10; "
5128 static int SigParseBidirWithSameSrcAndDest01(
void)
5145 "alert tcp [1.2.3.4, 5.6.7.8] [80, 81] <> [5.6.7.8, 1.2.3.4] [81, 80] (sid:3;)");
5154 static int SigParseBidirWithSameSrcAndDest02(
void)
5162 de_ctx,
"alert tcp 1.2.3.4 any <> [1.2.3.4, 5.6.7.8, ::1] any (sid:1;)");
5169 de_ctx,
"alert tcp [1.2.3.4, ::1] [80, 81, 82] <> [1.2.3.4, ::1] [80, 81] (sid:2;)");
5176 "alert tcp [1.2.3.4, ::1, ABCD:AAAA::1] [80] <> [1.2.3.4, ::1] [80, 81] (sid:3;)");
5183 de_ctx,
"alert tcp [!1.2.3.4, 1.2.3.0/24] any <> [1.2.3.0/24, !1.2.3.4] any (sid:4;)");
5190 de_ctx,
"alert tcp [1.2.3.4, 1.2.3.0/24] any <> [1.2.3.0/24, !1.2.3.4] any (sid:5;)");
5199 static int SigParseTestActionReject(
void)
5205 de_ctx,
"reject tcp 1.2.3.4 any -> !1.2.3.4 any (msg:\"SigParseTest01\"; sid:1;)");
5206 #ifdef HAVE_LIBNET11
5217 static int SigParseTestActionDrop(
void)
5223 de_ctx,
"drop tcp 1.2.3.4 any -> !1.2.3.4 any (msg:\"SigParseTest01\"; sid:1;)");
5231 static int SigSetMultiAppProto(
void)
5338 UtRegisterTest(
"SigParseTest21 -- address with space", SigParseTest21);
5339 UtRegisterTest(
"SigParseTest22 -- address with space", SigParseTest22);
5340 UtRegisterTest(
"SigParseTest23 -- carriage return", SigParseTest23);
5355 UtRegisterTest(
"SigParseTestNegation01", SigParseTestNegation01);
5356 UtRegisterTest(
"SigParseTestNegation02", SigParseTestNegation02);
5357 UtRegisterTest(
"SigParseTestNegation03", SigParseTestNegation03);
5358 UtRegisterTest(
"SigParseTestNegation04", SigParseTestNegation04);
5359 UtRegisterTest(
"SigParseTestNegation05", SigParseTestNegation05);
5360 UtRegisterTest(
"SigParseTestNegation06", SigParseTestNegation06);
5361 UtRegisterTest(
"SigParseTestNegation07", SigParseTestNegation07);
5362 UtRegisterTest(
"SigParseTestNegation08", SigParseTestNegation08);
5365 UtRegisterTest(
"SigParseTestAppLayerTLS01", SigParseTestAppLayerTLS01);
5366 UtRegisterTest(
"SigParseTestAppLayerTLS02", SigParseTestAppLayerTLS02);
5367 UtRegisterTest(
"SigParseTestAppLayerTLS03", SigParseTestAppLayerTLS03);
5368 UtRegisterTest(
"SigParseTestUnbalancedQuotes01", SigParseTestUnbalancedQuotes01);
5371 SigParseTestContentGtDsize01);
5373 SigParseTestContentGtDsize02);
5376 SigParseBidirWithSameSrcAndDest01);
5378 SigParseBidirWithSameSrcAndDest02);
5379 UtRegisterTest(
"SigParseTestActionReject", SigParseTestActionReject);
5380 UtRegisterTest(
"SigParseTestActionDrop", SigParseTestActionDrop);