56 static void DetectContentRegisterTests(
void);
86 uint8_t **pstr, uint16_t *plen)
88 size_t slen = strlen(contentstr);
106 uint8_t binstr[3] =
"";
108 uint16_t bin_count = 0;
110 for (i = 0, x = 0; i < slen; i++) {
116 SCLogError(
"Incomplete hex code in content - %s. Invalidating signature.",
124 }
else if(!escape &&
str[i] ==
'\\') {
128 if (isdigit((
unsigned char)
str[i]) ||
129 str[i] ==
'A' ||
str[i] ==
'a' ||
130 str[i] ==
'B' ||
str[i] ==
'b' ||
131 str[i] ==
'C' ||
str[i] ==
'c' ||
132 str[i] ==
'D' ||
str[i] ==
'd' ||
133 str[i] ==
'E' ||
str[i] ==
'e' ||
134 str[i] ==
'F' ||
str[i] ==
'f')
138 binstr[binpos] = (char)
str[i];
142 uint8_t c = strtol((
char *)binstr, (
char **) NULL, 16) & 0xFF;
148 }
else if (
str[i] ==
' ') {
151 else if (
str[i] !=
',') {
153 "content - %s, hex %c. Invalidating signature.",
171 }
else if (
str[i] ==
'"') {
172 SCLogError(
"Invalid unescaped double quote within content section.");
181 if (bin_count % 2 != 0) {
183 "%s - %s. Invalidating signature.",
184 keyword, contentstr);
194 *plen = (uint16_t)slen;
195 *pstr = (uint8_t *)
str;
207 const char *contentstr)
210 uint8_t *content = NULL;
231 spm_global_thread_ctx);
249 const char *contentstr)
261 SCLogDebug(
"DetectContentData \"cd\" is NULL");
265 if (tmpstr != NULL) {
294 if (tmprstr != NULL) {
346 SCLogError(
"content string \"%s\" incompatible with %s transform", contentstr, tstr);
408 int max_offset = 0, total_len = 0;
412 for (; sm != NULL; sm = sm->
next) {
418 SCLogDebug(
"content_len %d; negated: %s; distance: %d, offset: %d, depth: %d",
430 if (max_size < (uint64_t)check) {
441 max_offset =
MAX(max_offset, cd->
offset);
459 uint16_t max_right_edge_i;
463 uint32_t max_right_edge = max_right_edge_i;
466 if (min_dsize_required >= 0) {
467 SCLogDebug(
"min_dsize %d; max_right_edge %d", min_dsize_required, max_right_edge);
468 if ((uint32_t)min_dsize_required > max_right_edge) {
469 SCLogError(
"signature can't match as required content length %d exceeds dsize value %d",
470 min_dsize_required, max_right_edge);
493 #define VALIDATE(e) \
498 uint16_t offset_plus_pat = 0;
500 bool has_active_depth_chain =
false;
502 bool has_depth =
false;
503 bool has_ends_with =
false;
504 uint16_t ends_with_depth = 0;
506 for (
SigMatch *sm = sm_head; sm != NULL; sm = sm->
next) {
515 has_active_depth_chain =
false;
518 if (sm->prev == NULL) {
543 has_active_depth_chain =
false;
549 has_active_depth_chain =
true;
552 SCLogDebug(
"sm %p depth %u offset %u distance %d within %d", sm, cd->
depth,
561 has_active_depth_chain =
false;
565 SCLogDebug(
"no distance, reset offset_plus_pat & offset");
566 offset_plus_pat =
offset = 0;
569 SCLogDebug(
"stored: offset %u depth %u offset_plus_pat %u "
570 "has_active_depth_chain %s",
571 offset, depth, offset_plus_pat, has_active_depth_chain ?
"true" :
"false");
579 if (abs(cd->
distance) > offset_plus_pat)
588 if (has_active_depth_chain) {
590 if (depth && depth > offset_plus_pat) {
595 "distance to add: %u. depth + dist %u", dist, depth + dist);
599 depth + cd->
within + dist <= UINT16_MAX);
600 depth = cd->
depth = (uint16_t)(depth + cd->
within + dist);
609 if (cd->
depth == 0 && depth != 0) {
614 offset_plus_pat + cd->
distance <= UINT16_MAX);
620 depth + cd->
within <= UINT16_MAX);
621 depth = cd->
depth = (uint16_t)(cd->
within + depth);
625 has_ends_with =
true;
626 if (ends_with_depth == 0)
627 ends_with_depth = depth;
628 ends_with_depth =
MIN(ends_with_depth, depth);
636 cd->
offset = offset_plus_pat;
665 has_ends_with =
true;
666 if (ends_with_depth == 0)
667 ends_with_depth = depth;
668 ends_with_depth =
MIN(ends_with_depth, depth);
672 has_active_depth_chain =
false;
683 SCLogDebug(
"non-anchored PCRE not supported, reset offset_plus_pat & offset");
684 offset_plus_pat =
offset = depth = 0;
686 has_active_depth_chain =
false;
690 SCLogDebug(
"keyword not supported, reset offset_plus_pat & offset");
691 offset_plus_pat =
offset = depth = 0;
692 has_active_depth_chain =
false;
697 if (has_depth && has_ends_with) {
698 for (
SigMatch *sm = sm_head; sm != NULL; sm = sm->
next) {
703 cd->
depth = ends_with_depth;
723 static inline bool NeedsAsHex(uint8_t c)
747 if (NeedsAsHex(cd->
content[i])) {
749 snprintf(hex_str,
sizeof(hex_str),
"%s%02X", !hex ?
"|" :
" ", cd->
content[i]);
754 snprintf(p_str,
sizeof(p_str),
"%s%c", hex ?
"|" :
"", cd->
content[i]);
767 SCLogError(
"can't use multiple nocase modifiers with the same content");
791 static bool TestLastContent(
const Signature *s, uint16_t o, uint16_t d)
807 if (d != cd->
depth) {
814 #define TEST_RUN(sig, o, d) \
816 SCLogDebug("TEST_RUN start: '%s'", (sig)); \
817 DetectEngineCtx *de_ctx = DetectEngineCtxInit(); \
818 FAIL_IF_NULL(de_ctx); \
819 de_ctx->flags |= DE_QUIET; \
821 snprintf(rule, sizeof(rule), "alert tcp any any -> any any (%s sid:1; rev:1;)", (sig)); \
822 Signature *s = DetectEngineAppendSig(de_ctx, rule); \
824 SigPrepareStage1(de_ctx); \
825 bool res = TestLastContent(s, (o), (d)); \
827 DetectEngineCtxFree(de_ctx); \
834 static int DetectContentDepthTest01(
void)
837 TEST_RUN(
"content:\"abc\"; offset:1; depth:3;", 1, 4);
839 TEST_RUN(
"dsize:10; content:\"abc\";", 0, 10);
840 TEST_RUN(
"dsize:<10; content:\"abc\";", 0, 10);
841 TEST_RUN(
"dsize:5<>10; content:\"abc\";", 0, 10);
844 TEST_RUN(
"content:\"abc\"; depth:3; content:\"xyz\"; distance:0; within:3; ", 3, 6);
846 TEST_RUN(
"content:\"abc\"; offset:3; depth:3; content:\"xyz\"; distance:0; within:3; ", 6, 9);
847 TEST_RUN(
"content:\"abc\"; depth:6; content:\"xyz\"; distance:0; within:3; ", 3, 9);
850 TEST_RUN(
"content:\"abc\"; depth:3; content:\"klm\"; distance:0; within:3; content:\"xyz\"; distance:0; within:3; ", 6, 9);
852 TEST_RUN(
"content:\"abc\"; depth:3; content:\"klm\"; content:\"xyz\"; distance:0; within:3; ", 3, 0);
854 TEST_RUN(
"content:\"abc\"; depth:3; pcre:/\"klm\"/; content:\"xyz\"; distance:0; within:3; ", 0, 0);
856 TEST_RUN(
"content:\"abc\"; depth:3; pcre:/\"klm\"/R; content:\"xyz\"; distance:0; within:3; ", 3, 0);
857 TEST_RUN(
"content:\"abc\"; offset:3; depth:3; pcre:/\"klm\"/R; content:\"xyz\"; distance:0; within:3; ", 6, 0);
859 TEST_RUN(
"content:\"abc\"; depth:3; content:\"klm\"; within:3; content:\"xyz\"; within:3; ", 0, 9);
861 TEST_RUN(
"content:\"abc\"; depth:3; content:\"klm\"; distance:0; content:\"xyz\"; distance:0; ", 6, 0);
864 TEST_RUN(
"content:\"abc\"; depth:6; isdataat:!1,relative; content:\"klm\";", 0, 6);
865 TEST_RUN(
"content:\"abc\"; depth:3; content:\"klm\"; within:3; content:\"xyz\"; within:3; isdataat:!1,relative; content:\"def\"; ", 0, 9);
867 TEST_RUN(
"content:\"|03|\"; depth:1; content:\"|e0|\"; distance:4; within:1;", 5, 6);
868 TEST_RUN(
"content:\"|03|\"; depth:1; content:\"|e0|\"; distance:4; within:1; content:\"Cookie|3a|\"; distance:5; within:7;", 11, 18);
870 TEST_RUN(
"content:\"this\"; content:\"is\"; within:6; content:\"big\"; within:8; content:\"string\"; within:8;", 0, 0);
872 TEST_RUN(
"dsize:<80; content:!\"|00 22 02 00|\"; depth: 4; content:\"|00 00 04|\"; distance:8; within:3; content:\"|00 00 00 00 00|\"; distance:6; within:5;", 17, 80);
873 TEST_RUN(
"content:!\"|00 22 02 00|\"; depth: 4; content:\"|00 00 04|\"; distance:8; within:3; content:\"|00 00 00 00 00|\"; distance:6; within:5;", 17, 0);
875 TEST_RUN(
"content:\"|0d 0a 0d 0a|\"; content:\"code=\"; distance:0;", 4, 0);
876 TEST_RUN(
"content:\"|0d 0a 0d 0a|\"; content:\"code=\"; distance:0; content:\"xploit.class\"; distance:2; within:18;", 11, 0);
878 TEST_RUN(
"content:\"|16 03|\"; depth:2; content:\"|55 04 0a|\"; distance:0;", 2, 0);
879 TEST_RUN(
"content:\"|16 03|\"; depth:2; content:\"|55 04 0a|\"; distance:0; content:\"|0d|LogMeIn, Inc.\"; distance:1; within:14;", 6, 0);
880 TEST_RUN(
"content:\"|16 03|\"; depth:2; content:\"|55 04 0a|\"; distance:0; content:\"|0d|LogMeIn, Inc.\"; distance:1; within:14; content:\".app\";", 0, 0);
882 TEST_RUN(
"content:\"=\"; offset:4; depth:9;", 4, 13);
885 TEST_RUN(
"content:\"=\"; offset:4; depth:9; content:\"=&\"; distance:55; within:2;", 60, 70);
888 TEST_RUN(
"content:\"0123456789\"; content:\"abcdef\"; distance:1048576;", 0, 0);
891 TEST_RUN(
"content:\"SMB\"; depth:8; content:\"|09 00|\"; distance:8; within:2;", 11, 18);
892 TEST_RUN(
"content:\"SMB\"; depth:8; content:\"|09 00|\"; distance:8; within:2; content:\"|05 "
893 "00 00|\"; distance:0;",
895 TEST_RUN(
"content:\"SMB\"; depth:8; content:\"|09 00|\"; distance:8; within:2; content:\"|05 "
896 "00 00|\"; distance:0; content:\"|0c 00|\"; distance:19; within:2;",
898 TEST_RUN(
"content:\"SMB\"; depth:8; content:\"|09 00|\"; distance:8; within:2; content:\"|05 "
899 "00 00|\"; distance:0; content:\"|0c 00|\"; distance:19; within:2; content:\"|15 00 "
900 "00 00|\"; distance:20; within:4;",
911 static void DetectContentPrintAll(
SigMatch *sm)
923 for (; first_sm != NULL; first_sm = first_sm->
next) {
925 SCLogDebug(
"Printing SigMatch DETECT_CONTENT %d", ++i);
933 static int g_file_data_buffer_id = 0;
934 static int g_dce_stub_data_buffer_id = 0;
939 static int DetectContentParseTest01 (
void)
941 const char *teststring =
"abc\\:def";
942 const char *teststringparsed =
"abc:def";
945 FAIL_IF(spm_global_thread_ctx == NULL);
948 FAIL_IF(memcmp(cd->
content, teststringparsed, strlen(teststringparsed)) != 0);
957 static int DetectContentParseTest02 (
void)
959 const char *teststring =
"abc\\;def";
960 const char *teststringparsed =
"abc;def";
963 FAIL_IF(spm_global_thread_ctx == NULL);
966 FAIL_IF(memcmp(cd->
content, teststringparsed, strlen(teststringparsed)) != 0);
975 static int DetectContentParseTest03 (
void)
977 const char *teststring =
"abc\\\"def";
978 const char *teststringparsed =
"abc\"def";
981 FAIL_IF(spm_global_thread_ctx == NULL);
984 FAIL_IF(memcmp(cd->
content, teststringparsed, strlen(teststringparsed)) != 0);
993 static int DetectContentParseTest04 (
void)
995 const char *teststring =
"abc\\\\def";
996 const char *teststringparsed =
"abc\\def";
999 FAIL_IF(spm_global_thread_ctx == NULL);
1012 static int DetectContentParseTest05 (
void)
1014 const char *teststring =
"abc\\def";
1017 FAIL_IF(spm_global_thread_ctx == NULL);
1028 static int DetectContentParseTest06 (
void)
1030 const char *teststring =
"a|42|c|44|e|46|";
1031 const char *teststringparsed =
"abcdef";
1035 FAIL_IF(spm_global_thread_ctx == NULL);
1048 static int DetectContentParseTest07 (
void)
1050 const char *teststring =
"";
1053 FAIL_IF(spm_global_thread_ctx == NULL);
1064 static int DetectContentParseTest08 (
void)
1066 const char *teststring =
"";
1069 FAIL_IF(spm_global_thread_ctx == NULL);
1086 static int DetectContentLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize,
const char *sig,
1096 memset(&th_v, 0,
sizeof(th_v));
1116 SCLogDebug(
"---DetectContentLongPatternMatchTest---");
1136 static int DetectContentLongPatternMatchTestWrp(
const char *sig, uint32_t sid)
1143 uint8_t raw_eth_pkt[] = {
1144 0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
1145 0x00,0x00,0x00,0x00,0x08,0x00,0x45,0x00,
1146 0x00,0x85,0x00,0x01,0x00,0x00,0x40,0x06,
1147 0x7c,0x70,0x7f,0x00,0x00,0x01,0x7f,0x00,
1148 0x00,0x01,0x00,0x14,0x00,0x50,0x00,0x00,
1149 0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x02,
1150 0x20,0x00,0xc9,0xad,0x00,0x00,0x48,0x69,
1151 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
1152 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
1153 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
1154 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
1155 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
1156 0x74,0x63,0x68,0x65,0x73,0x20,0x6f,0x66,
1157 0x20,0x73,0x70,0x6c,0x69,0x74,0x74,0x65,
1158 0x64,0x20,0x70,0x61,0x74,0x74,0x65,0x72,
1159 0x6e,0x73,0x20,0x62,0x65,0x74,0x77,0x65,
1160 0x65,0x6e,0x20,0x6d,0x75,0x6c,0x74,0x69,
1161 0x70,0x6c,0x65,0x20,0x63,0x68,0x75,0x6e,
1164 return DetectContentLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
1171 static int DetectContentLongPatternMatchTest01(
void)
1173 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
1174 " content:\"Hi, this is a big test\"; sid:1;)";
1175 return DetectContentLongPatternMatchTestWrp(sig, 1);
1181 static int DetectContentLongPatternMatchTest02(
void)
1183 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
1184 " content:\"Hi, this is a big test to check content matches of"
1185 " splitted patterns between multiple chunks!\"; sid:1;)";
1186 return DetectContentLongPatternMatchTestWrp(sig, 1);
1193 static int DetectContentLongPatternMatchTest03(
void)
1196 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
1197 " content:\"Hi, this is a big test to check content matches of"
1198 " splitted patterns between multiple splitted chunks!\"; sid:1;)";
1199 return (DetectContentLongPatternMatchTestWrp(sig, 1) == 0) ? 1: 0;
1205 static int DetectContentLongPatternMatchTest04(
void)
1207 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1208 " content:\"Hi, this is\"; depth:15 ;content:\"a big test\"; "
1209 " within:15; content:\"to check content matches of\"; "
1210 " within:30; content:\"splitted patterns\"; distance:1; "
1213 return DetectContentLongPatternMatchTestWrp(sig, 1);
1221 static int DetectContentLongPatternMatchTest05(
void)
1223 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1224 " content:\"Hi, this is a big\"; depth:17; "
1225 " isdataat:30, relative; "
1226 " content:\"test\"; within: 5; distance:1; "
1227 " isdataat:15, relative; "
1228 " content:\"of splitted\"; within:37; distance:15; "
1229 " isdataat:20,relative; "
1230 " content:\"patterns\"; within:9; distance:1; "
1231 " isdataat:10, relative; "
1233 return DetectContentLongPatternMatchTestWrp(sig, 1);
1241 static int DetectContentLongPatternMatchTest06(
void)
1243 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1244 " content:\"Hi, this is a big test to check cont\"; depth:36;"
1245 " content:\"ent matches\"; within:11; distance:0; "
1246 " content:\"of splitted patterns between multiple\"; "
1247 " within:38; distance:1; "
1248 " content:\"chunks!\"; within: 8; distance:1; "
1250 return DetectContentLongPatternMatchTestWrp(sig, 1);
1257 static int DetectContentLongPatternMatchTest07(
void)
1259 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1260 " content:\"chunks!\"; "
1261 " content:\"content matches\"; offset:32; depth:47; "
1262 " content:\"of splitted patterns between multiple\"; "
1263 " content:\"Hi, this is a big\"; offset:0; depth:17; "
1265 return DetectContentLongPatternMatchTestWrp(sig, 1);
1272 static int DetectContentLongPatternMatchTest08(
void)
1274 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1275 " content:\"ent matches\"; "
1276 " content:\"of splitted patterns between multiple\"; "
1277 " within:38; distance:1; "
1278 " content:\"chunks!\"; within: 8; distance:1; "
1279 " content:\"Hi, this is a big test to check cont\"; depth:36;"
1281 return DetectContentLongPatternMatchTestWrp(sig, 1);
1288 static int DetectContentLongPatternMatchTest09(
void)
1290 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1291 " content:\"ent matches\"; "
1292 " content:\"of splitted patterns between multiple\"; "
1293 " offset:47; depth:85; "
1294 " content:\"chunks!\"; within: 8; distance:1; "
1295 " content:\"Hi, this is a big test to chec\"; depth:36;"
1296 " content:\"k cont\"; distance:0; within:6;"
1298 return DetectContentLongPatternMatchTestWrp(sig, 1);
1304 static int DetectContentLongPatternMatchTest10(
void)
1306 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1307 " content:\"Hi, this is a big test to check \"; "
1308 " content:\"con\"; "
1310 return DetectContentLongPatternMatchTestWrp(sig, 1);
1316 static int DetectContentLongPatternMatchTest11(
void)
1318 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1322 return DetectContentLongPatternMatchTestWrp(sig, 1);
1325 static int DetectContentParseTest09(
void)
1328 const char *teststring =
"boo";
1332 FAIL_IF(spm_global_thread_ctx == NULL);
1345 static int DetectContentParseTest17(
void)
1348 const char *sigstr =
"alert tcp any any -> any any (msg:\"Dummy\"; "
1349 "content:\"one\"; content:\"two\"; within:2; sid:1;)";
1371 static int DetectContentParseTest18(
void)
1399 static int DetectContentParseTest19(
void)
1408 "(msg:\"Testing dce iface, stub_data with content\"; "
1409 "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
1411 "content:\"one\"; distance:0; sid:1;)");
1423 "alert tcp any any -> any any "
1424 "(msg:\"Testing dce iface, stub_data with contents & distance, within\"; "
1425 "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
1427 "content:\"one\"; distance:0; content:\"two\"; within:10; sid:2;)");
1442 "alert tcp any any -> any any "
1443 "(msg:\"Testing dce iface, stub with contents, distance, within\"; "
1444 "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
1446 "content:\"one\"; distance:0; "
1447 "content:\"two\"; within:10; distance:2; sid:3;)");
1462 "(msg:\"Testing content\"; "
1463 "content:\"one\"; sid:4;)");
1475 static int DetectContentParseTest20(
void)
1486 "alert udp any any -> any any "
1487 "(msg:\"test\"; content:\"\"; sid:238012;)");
1501 static int DetectContentParseTest21(
void)
1512 "alert udp any any -> any any "
1513 "(msg:\"test\"; content:\"; sid:238012;)");
1527 static int DetectContentParseTest22(
void)
1538 "alert udp any any -> any any "
1539 "(msg:\"test\"; content:\"boo; sid:238012;)");
1553 static int DetectContentParseTest23(
void)
1564 "alert udp any any -> any any "
1565 "(msg:\"test\"; content:boo\"; sid:238012;)");
1579 static int DetectContentParseTest24(
void)
1592 "alert udp any any -> any any "
1593 "(msg:\"test\"; content: !\"boo\"; sid:238012;)");
1595 printf(
"de_ctx->sig_list == NULL: ");
1602 printf(
"de_ctx->pmatch_tail == NULL || de_ctx->pmatch_tail->ctx == NULL: ");
1618 static int DetectContentParseTest25(
void)
1629 "alert udp any any -> any any "
1630 "(msg:\"test\"; content:\"|\"; sid:1;)");
1644 static int DetectContentParseTest26(
void)
1655 "alert udp any any -> any any "
1656 "(msg:\"test\"; content:\"|af\"; sid:1;)");
1670 static int DetectContentParseTest27(
void)
1681 "alert udp any any -> any any "
1682 "(msg:\"test\"; content:\"af|\"; sid:1;)");
1696 static int DetectContentParseTest28(
void)
1707 "alert udp any any -> any any "
1708 "(msg:\"test\"; content:\"|af|\"; sid:1;)");
1722 static int DetectContentParseTest29(
void)
1733 "alert udp any any -> any any "
1734 "(msg:\"test\"; content:\"aast|\"; sid:1;)");
1748 static int DetectContentParseTest30(
void)
1759 "alert udp any any -> any any "
1760 "(msg:\"test\"; content:\"aast|af\"; sid:1;)");
1774 static int DetectContentParseTest31(
void)
1785 "alert udp any any -> any any "
1786 "(msg:\"test\"; content:\"aast|af|\"; sid:1;)");
1800 static int DetectContentParseTest32(
void)
1811 "alert udp any any -> any any "
1812 "(msg:\"test\"; content:\"|af|asdf\"; sid:1;)");
1826 static int DetectContentParseTest33(
void)
1837 "alert udp any any -> any any "
1838 "(msg:\"test\"; content:\"|af|af|\"; sid:1;)");
1852 static int DetectContentParseTest34(
void)
1863 "alert udp any any -> any any "
1864 "(msg:\"test\"; content:\"|af|af|af\"; sid:1;)");
1878 static int DetectContentParseTest35(
void)
1889 "alert udp any any -> any any "
1890 "(msg:\"test\"; content:\"|af|af|af|\"; sid:1;)");
1901 static int SigTestPositiveTestContent(
const char *rule, uint8_t *buf)
1903 uint16_t buflen = strlen((
char *)buf);
1907 memset(&th_v, 0,
sizeof(th_v));
1934 static int DetectContentParseTest41(
void)
1939 char *teststring =
SCMalloc(
sizeof(
char) * (patlen + 1));
1943 for (
int i = 0; i < patlen; idx++, i++) {
1944 teststring[idx] =
'a';
1946 teststring[idx++] =
'\0';
1950 FAIL_IF(spm_global_thread_ctx == NULL);
1967 static int DetectContentParseTest42(
void)
1972 char *teststring =
SCMalloc(
sizeof(
char) * (patlen + 1));
1976 for (
int i = 0; i < patlen; idx++, i++) {
1977 teststring[idx] =
'a';
1979 teststring[idx++] =
'\0';
1983 FAIL_IF(spm_global_thread_ctx == NULL);
1997 static int DetectContentParseTest43(
void)
2002 char *teststring =
SCMalloc(
sizeof(
char) * (patlen + 1));
2006 teststring[idx++] =
'|';
2007 teststring[idx++] =
'4';
2008 teststring[idx++] =
'6';
2009 teststring[idx++] =
'|';
2010 for (
int i = 0; i < (patlen - 4); idx++, i++) {
2011 teststring[idx] =
'a';
2013 teststring[idx++] =
'\0';
2017 FAIL_IF(spm_global_thread_ctx == NULL);
2034 static int DetectContentParseTest44(
void)
2039 char *teststring =
SCMalloc(
sizeof(
char) * (patlen + 1));
2043 teststring[idx++] =
'|';
2044 teststring[idx++] =
'4';
2045 teststring[idx++] =
'6';
2046 teststring[idx++] =
'|';
2047 for (
int i = 0; i < (patlen - 4); idx++, i++) {
2048 teststring[idx] =
'a';
2050 teststring[idx++] =
'\0';
2054 FAIL_IF(spm_global_thread_ctx == NULL);
2071 static int DetectContentParseTest45(
void)
2080 "alert tcp any any -> any any "
2081 "(msg:\"test\"; content:\"|ff|\" content:\"TEST\"; sid:1;)");
2089 static int SigTestNegativeTestContent(
const char *rule, uint8_t *buf)
2091 uint16_t buflen = strlen((
char *)buf);
2096 memset(&th_v, 0,
sizeof(th_v));
2123 if (det_ctx != NULL) {
2137 static int SigTest41TestNegatedContent(
void)
2139 return SigTestPositiveTestContent(
"alert tcp any any -> any any "
2140 "(msg:\"HTTP URI cap\"; content:!\"GES\"; sid:1;)",
2142 (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\n"
2143 "GET /two/ HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2151 static int SigTest41aTestNegatedContent(
void)
2153 (void)SigTestPositiveTestContent(
"alert tcp any any -> any any (msg:\"HTTP URI cap\"; flow:to_server; content:\"GET\"; sid:1;)", (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\nGET /two/ HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2162 static int SigTest42TestNegatedContent(
void)
2164 return SigTestPositiveTestContent(
2165 "alert tcp any any -> any any (content:!\"eeeeeeeeeee\"; depth:22; offset:35; sid:1;)",
2166 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2176 static int SigTest43TestNegatedContent(
void)
2178 return SigTestNegativeTestContent(
2179 "alert tcp any any -> any any (content:!\"eeeeeeeeeee\"; depth:34; offset:23; sid:1;)",
2180 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2188 static int SigTest44TestNegatedContent(
void)
2190 return SigTestPositiveTestContent(
2191 "alert tcp any any -> any any (content:!\"eeeeeeeeeee\"; offset:40; depth:35; sid:1;)",
2192 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2199 static int SigTest45TestNegatedContent(
void)
2201 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:5; "
2202 "content:!\"eeeeeeeeeee\"; depth:23; sid:1;)",
2203 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2210 static int SigTest46TestNegatedContent(
void)
2212 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaaE\"; "
2213 "content:!\"eeeeeeeeeee\"; depth:23; sid:1;)",
2214 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2222 static int SigTest47TestNegatedContent(
void)
2224 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; offset:5; "
2225 "content:!\"eeeeeeeeeee\"; depth:23; sid:1;)",
2226 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2233 static int SigTest48TestNegatedContent(
void)
2235 return SigTestPositiveTestContent(
2236 "alert tcp any any -> any any (content:\"GET\"; content:!\"GES\"; within:26; sid:1;)",
2237 (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\nGET /two/ "
2238 "HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2245 static int SigTest49TestNegatedContent(
void)
2247 return SigTestNegativeTestContent(
2248 "alert tcp any any -> any any (content:\"GET\"; content:!\"Host\"; within:26; sid:1;)",
2249 (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\nGET /two/ "
2250 "HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2257 static int SigTest50TestNegatedContent(
void)
2259 return SigTestPositiveTestContent(
2260 "alert tcp any any -> any any (content:\"GET\"; content:!\"GES\"; distance:25; sid:1;)",
2261 (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\nGET /two/ "
2262 "HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2272 static int SigTest51TestNegatedContent(
void)
2274 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"GET\"; content:!\"Host\"; distance:17; sid:1;)", (uint8_t *)
"GET /one/ HTTP/1.1\r\nHost: one.example.org\r\n\r\n\r\nGET /two/ HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2281 static int SigTest52TestNegatedContent(
void)
2283 return SigTestNegativeTestContent(
2284 "alert tcp any any -> any any (content:\"GES\"; content:!\"BOO\"; sid:1;)",
2285 (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\nGET /two/ "
2286 "HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2293 static int SigTest53TestNegatedContent(
void)
2295 return SigTestNegativeTestContent(
2296 "alert tcp any any -> any any (content:\"aaa\"; content:!\"Ggggg\"; within:56; sid:1;)",
2297 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2304 static int SigTest54TestNegatedContent(
void)
2306 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2307 "content:!\"gggggg\"; within:20; sid:1;)",
2308 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff ggggggggg hhhhhhhh");
2315 static int SigTest55TestNegatedContent(
void)
2317 return SigTestNegativeTestContent(
2318 "alert tcp any any -> any any (content:!\"aaa\"; depth:5; sid:1;)",
2319 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2326 static int SigTest56TestNegatedContent(
void)
2328 return SigTestPositiveTestContent(
2329 "alert tcp any any -> any any (content:\"aaa\"; content:\"Ggggg\"; within:56; sid:1;)",
2330 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Gggggggg hhhhhhhh");
2337 static int SigTest57TestNegatedContent(
void)
2339 return SigTestNegativeTestContent(
2340 "alert tcp any any -> any any (content:\"aaa\"; content:!\"Ggggg\"; within:56; sid:1;)",
2341 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2348 static int SigTest58TestNegatedContent(
void)
2350 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2351 "content:!\"Ggggg\"; distance:57; sid:1;)",
2352 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2359 static int SigTest59TestNegatedContent(
void)
2361 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2362 "content:!\"Gggg\"; distance:30; sid:1;)",
2363 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2366 static int SigTest60TestNegatedContent(
void)
2368 return SigTestNegativeTestContent(
2369 "alert tcp any any -> any any (content:!\"aaa\"; content:\"Ggggg\"; sid:1;)",
2370 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2373 static int SigTest61TestNegatedContent(
void)
2375 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2376 "content:!\"Ggggg\"; within:30; sid:1;)",
2377 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2387 static int SigTest62TestNegatedContent(
void)
2389 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2390 "content:!\"Gggggg\"; within:49; sid:1;)",
2391 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2394 static int SigTest63TestNegatedContent(
void)
2396 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2397 "content:!\"Gggggg\"; within:56; sid:1;)",
2398 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2401 static int SigTest64TestNegatedContent(
void)
2403 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2404 "content:!\"Gggggg\"; within:30; sid:1;)",
2405 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2415 static int SigTest65TestNegatedContent(
void)
2417 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2418 "content:!\"Gggggg\"; distance:0; within:49; sid:1;)",
2419 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2422 static int SigTest66TestNegatedContent(
void)
2424 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2425 "content:!\"Gggggg\"; within:30; sid:1;)",
2426 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2429 static int SigTest67TestNegatedContent(
void)
2431 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2432 "content:!\"XXXX\"; within:56; sid:1;)",
2433 (uint8_t *)
"aaa bbbb cccc XXXXdddd eeeeeeeeeee ffffffffff XXXXggggg hhhhhhhh");
2436 static int SigTest68TestNegatedContent(
void)
2438 return SigTestPositiveTestContent(
2439 "alert tcp any any -> any any (content:\"aaa\"; depth:10; content:\"cccc\"; offset:8; "
2440 "content:!\"Gggggg\"; within:28; content:\"hhhhhhhh\"; sid:1;)",
2441 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2444 static int SigTest69TestNegatedContent(
void)
2446 return SigTestNegativeTestContent(
2447 "alert tcp any any -> any any (content:\"aaa\"; depth:10; content:\"cccc\"; offset:8; "
2448 "content:!\"Gggggg\"; within:48; content:\"hhhhhhhh\"; sid:1;)",
2449 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2452 static int SigTest70TestNegatedContent(
void)
2454 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2455 "content:!\"Gggggg\"; within:52; sid:1;)",
2456 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2460 static int SigTest71TestNegatedContent(
void)
2462 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2463 "content:!\"Gggggg\"; within:40; distance:43; sid:1;)",
2464 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2467 static int SigTest72TestNegatedContent(
void)
2469 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2470 "content:!\"Gggggg\"; within:49; distance:43; sid:1;)",
2471 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2474 static int SigTest73TestNegatedContent(
void)
2476 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:5; "
2477 "content:!\"eeeeeeeeeee\"; depth:35; sid:1;)",
2478 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff ggggggggg hhhhhhhh");
2481 static int SigTest74TestNegatedContent(
void)
2483 return SigTestPositiveTestContent(
"alert tcp any any -> any any (msg:\"HTTP URI cap\"; content:\"USER\"; content:!\"PASS\"; sid:1;)", (uint8_t *)
"USER apple");
2486 static int SigTest75TestNegatedContent(
void)
2488 return SigTestPositiveTestContent(
"alert tcp any any -> any any (msg:\"HTTP URI cap\"; content:\"USER\"; content:\"!PASS\"; sid:1;)", (uint8_t *)
"USER !PASS");
2491 static int SigTest76TestBug134(
void)
2493 uint8_t *buf = (uint8_t *)
"test detect ${IFS} in traffic";
2494 uint16_t buflen = strlen((
char *)buf);
2499 memset(&f, 0,
sizeof(
Flow));
2508 char sig[] =
"alert tcp any any -> any 515 "
2509 "(msg:\"detect IFS\"; flow:to_server,established; content:\"${IFS}\";"
2510 " depth:50; offset:0; sid:900091; rev:1;)";
2525 static int SigTest77TestBug139(
void)
2528 0x12, 0x23, 0x34, 0x35, 0x52, 0x52, 0x24, 0x42, 0x22, 0x24,
2529 0x52, 0x24, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x34 };
2530 uint16_t buflen =
sizeof(buf);
2535 char sig[] =
"alert udp any any -> any 53 (msg:\"dns testing\";"
2536 " content:\"|00 00|\"; depth:5; offset:13; sid:9436601;"
2550 static int DetectLongContentTestCommon(
const char *sig, uint32_t sid)
2553 static uint8_t pkt[739] = {
2554 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2555 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
2556 0x02, 0xd5, 0x4a, 0x18, 0x40, 0x00, 0x40, 0x06,
2557 0xd7, 0xd6, 0x0a, 0x10, 0x01, 0x0b, 0x0a, 0x10,
2558 0x01, 0x0a, 0xdb, 0x36, 0x00, 0x50, 0xca, 0xc5,
2559 0xcc, 0xd1, 0x95, 0x77, 0x0f, 0x7d, 0x80, 0x18,
2560 0x00, 0xe5, 0x77, 0x9d, 0x00, 0x00, 0x01, 0x01,
2561 0x08, 0x0a, 0x1d, 0xe0, 0x86, 0xc6, 0xfc, 0x73,
2562 0x49, 0xf3, 0x50, 0x4f, 0x53, 0x54, 0x20, 0x2f,
2563 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e,
2564 0x31, 0x0d, 0x0a, 0x55, 0x73, 0x65, 0x72, 0x2d,
2565 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20, 0x63,
2566 0x75, 0x72, 0x6c, 0x2f, 0x37, 0x2e, 0x33, 0x37,
2567 0x2e, 0x30, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74,
2568 0x3a, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x36, 0x2e,
2569 0x31, 0x2e, 0x31, 0x30, 0x0d, 0x0a, 0x41, 0x63,
2570 0x63, 0x65, 0x70, 0x74, 0x3a, 0x20, 0x2a, 0x2f,
2571 0x2a, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65,
2572 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74,
2573 0x68, 0x3a, 0x20, 0x35, 0x32, 0x38, 0x0d, 0x0a,
2574 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d,
2575 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70,
2576 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
2577 0x6e, 0x2f, 0x78, 0x2d, 0x77, 0x77, 0x77, 0x2d,
2578 0x66, 0x6f, 0x72, 0x6d, 0x2d, 0x75, 0x72, 0x6c,
2579 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x64, 0x0d,
2580 0x0a, 0x0d, 0x0a, 0x58, 0x58, 0x58, 0x58, 0x58,
2581 0x58, 0x58, 0x58, 0x41, 0x41, 0x41, 0x41, 0x41,
2582 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2583 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2584 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2585 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2586 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2587 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2588 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2589 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2590 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2591 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2592 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2593 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2594 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2595 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2596 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2597 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2598 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2599 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2600 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2601 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2602 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2603 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2604 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2605 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2606 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2607 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2608 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2609 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2610 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2611 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2612 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2613 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2614 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2615 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2616 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2617 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2618 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2619 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2620 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2621 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2622 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2623 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2624 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2625 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2626 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2627 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2628 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2629 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2630 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2631 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2632 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2633 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2634 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2635 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2636 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2637 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2638 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2639 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2640 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2641 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2642 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2643 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2644 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
2645 0x41, 0x41, 0x41, 0x58, 0x58, 0x58, 0x58, 0x58,
2649 return DetectContentLongPatternMatchTest(pkt, (uint16_t)
sizeof(pkt), sig,
2653 static int DetectLongContentTest1(
void)
2656 const char *sig =
"alert tcp any any -> any any (msg:\"Test Rule\"; content:\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"; sid:1;)";
2658 return DetectLongContentTestCommon(sig, 1);
2661 static int DetectLongContentTest2(
void)
2664 const char *sig =
"alert tcp any any -> any any (msg:\"Test Rule\"; content:\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"; sid:1;)";
2666 return DetectLongContentTestCommon(sig, 1);
2669 static int DetectLongContentTest3(
void)
2672 const char *sig =
"alert tcp any any -> any any (msg:\"Test Rule\"; content:\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"; sid:1;)";
2674 return !DetectLongContentTestCommon(sig, 1);
2677 static int DetectBadBinContent(
void)
2684 de_ctx,
"alert tcp any any -> any any (msg:\"test\"; content:\"|a|\"; sid:1;)"));
2686 de_ctx,
"alert tcp any any -> any any (msg:\"test\"; content:\"|aa b|\"; sid:1;)"));
2688 de_ctx,
"alert tcp any any -> any any (msg:\"test\"; content:\"|aa bz|\"; sid:1;)"));
2691 de_ctx,
"alert tcp any any -> any any (msg:\"test\"; content:\"|22 2 22|\"; sid:1;)"));
2699 static void DetectContentRegisterTests(
void)
2704 UtRegisterTest(
"DetectContentDepthTest01", DetectContentDepthTest01);
2706 UtRegisterTest(
"DetectContentParseTest01", DetectContentParseTest01);
2707 UtRegisterTest(
"DetectContentParseTest02", DetectContentParseTest02);
2708 UtRegisterTest(
"DetectContentParseTest03", DetectContentParseTest03);
2709 UtRegisterTest(
"DetectContentParseTest04", DetectContentParseTest04);
2710 UtRegisterTest(
"DetectContentParseTest05", DetectContentParseTest05);
2711 UtRegisterTest(
"DetectContentParseTest06", DetectContentParseTest06);
2712 UtRegisterTest(
"DetectContentParseTest07", DetectContentParseTest07);
2713 UtRegisterTest(
"DetectContentParseTest08", DetectContentParseTest08);
2714 UtRegisterTest(
"DetectContentParseTest09", DetectContentParseTest09);
2715 UtRegisterTest(
"DetectContentParseTest17", DetectContentParseTest17);
2716 UtRegisterTest(
"DetectContentParseTest18", DetectContentParseTest18);
2717 UtRegisterTest(
"DetectContentParseTest19", DetectContentParseTest19);
2718 UtRegisterTest(
"DetectContentParseTest20", DetectContentParseTest20);
2719 UtRegisterTest(
"DetectContentParseTest21", DetectContentParseTest21);
2720 UtRegisterTest(
"DetectContentParseTest22", DetectContentParseTest22);
2721 UtRegisterTest(
"DetectContentParseTest23", DetectContentParseTest23);
2722 UtRegisterTest(
"DetectContentParseTest24", DetectContentParseTest24);
2723 UtRegisterTest(
"DetectContentParseTest25", DetectContentParseTest25);
2724 UtRegisterTest(
"DetectContentParseTest26", DetectContentParseTest26);
2725 UtRegisterTest(
"DetectContentParseTest27", DetectContentParseTest27);
2726 UtRegisterTest(
"DetectContentParseTest28", DetectContentParseTest28);
2727 UtRegisterTest(
"DetectContentParseTest29", DetectContentParseTest29);
2728 UtRegisterTest(
"DetectContentParseTest30", DetectContentParseTest30);
2729 UtRegisterTest(
"DetectContentParseTest31", DetectContentParseTest31);
2730 UtRegisterTest(
"DetectContentParseTest32", DetectContentParseTest32);
2731 UtRegisterTest(
"DetectContentParseTest33", DetectContentParseTest33);
2732 UtRegisterTest(
"DetectContentParseTest34", DetectContentParseTest34);
2733 UtRegisterTest(
"DetectContentParseTest35", DetectContentParseTest35);
2734 UtRegisterTest(
"DetectContentParseTest41", DetectContentParseTest41);
2735 UtRegisterTest(
"DetectContentParseTest42", DetectContentParseTest42);
2736 UtRegisterTest(
"DetectContentParseTest43", DetectContentParseTest43);
2737 UtRegisterTest(
"DetectContentParseTest44", DetectContentParseTest44);
2738 UtRegisterTest(
"DetectContentParseTest45", DetectContentParseTest45);
2742 DetectContentLongPatternMatchTest01);
2744 DetectContentLongPatternMatchTest02);
2746 DetectContentLongPatternMatchTest03);
2748 DetectContentLongPatternMatchTest04);
2750 DetectContentLongPatternMatchTest05);
2752 DetectContentLongPatternMatchTest06);
2754 DetectContentLongPatternMatchTest07);
2756 DetectContentLongPatternMatchTest08);
2758 DetectContentLongPatternMatchTest09);
2760 DetectContentLongPatternMatchTest10);
2762 DetectContentLongPatternMatchTest11);
2765 UtRegisterTest(
"SigTest41TestNegatedContent", SigTest41TestNegatedContent);
2767 SigTest41aTestNegatedContent);
2768 UtRegisterTest(
"SigTest42TestNegatedContent", SigTest42TestNegatedContent);
2769 UtRegisterTest(
"SigTest43TestNegatedContent", SigTest43TestNegatedContent);
2770 UtRegisterTest(
"SigTest44TestNegatedContent", SigTest44TestNegatedContent);
2771 UtRegisterTest(
"SigTest45TestNegatedContent", SigTest45TestNegatedContent);
2772 UtRegisterTest(
"SigTest46TestNegatedContent", SigTest46TestNegatedContent);
2773 UtRegisterTest(
"SigTest47TestNegatedContent", SigTest47TestNegatedContent);
2774 UtRegisterTest(
"SigTest48TestNegatedContent", SigTest48TestNegatedContent);
2775 UtRegisterTest(
"SigTest49TestNegatedContent", SigTest49TestNegatedContent);
2776 UtRegisterTest(
"SigTest50TestNegatedContent", SigTest50TestNegatedContent);
2777 UtRegisterTest(
"SigTest51TestNegatedContent", SigTest51TestNegatedContent);
2778 UtRegisterTest(
"SigTest52TestNegatedContent", SigTest52TestNegatedContent);
2779 UtRegisterTest(
"SigTest53TestNegatedContent", SigTest53TestNegatedContent);
2780 UtRegisterTest(
"SigTest54TestNegatedContent", SigTest54TestNegatedContent);
2781 UtRegisterTest(
"SigTest55TestNegatedContent", SigTest55TestNegatedContent);
2782 UtRegisterTest(
"SigTest56TestNegatedContent", SigTest56TestNegatedContent);
2783 UtRegisterTest(
"SigTest57TestNegatedContent", SigTest57TestNegatedContent);
2784 UtRegisterTest(
"SigTest58TestNegatedContent", SigTest58TestNegatedContent);
2785 UtRegisterTest(
"SigTest59TestNegatedContent", SigTest59TestNegatedContent);
2786 UtRegisterTest(
"SigTest60TestNegatedContent", SigTest60TestNegatedContent);
2787 UtRegisterTest(
"SigTest61TestNegatedContent", SigTest61TestNegatedContent);
2788 UtRegisterTest(
"SigTest62TestNegatedContent", SigTest62TestNegatedContent);
2789 UtRegisterTest(
"SigTest63TestNegatedContent", SigTest63TestNegatedContent);
2790 UtRegisterTest(
"SigTest64TestNegatedContent", SigTest64TestNegatedContent);
2791 UtRegisterTest(
"SigTest65TestNegatedContent", SigTest65TestNegatedContent);
2792 UtRegisterTest(
"SigTest66TestNegatedContent", SigTest66TestNegatedContent);
2793 UtRegisterTest(
"SigTest67TestNegatedContent", SigTest67TestNegatedContent);
2794 UtRegisterTest(
"SigTest68TestNegatedContent", SigTest68TestNegatedContent);
2795 UtRegisterTest(
"SigTest69TestNegatedContent", SigTest69TestNegatedContent);
2796 UtRegisterTest(
"SigTest70TestNegatedContent", SigTest70TestNegatedContent);
2797 UtRegisterTest(
"SigTest71TestNegatedContent", SigTest71TestNegatedContent);
2798 UtRegisterTest(
"SigTest72TestNegatedContent", SigTest72TestNegatedContent);
2799 UtRegisterTest(
"SigTest73TestNegatedContent", SigTest73TestNegatedContent);
2800 UtRegisterTest(
"SigTest74TestNegatedContent", SigTest74TestNegatedContent);
2801 UtRegisterTest(
"SigTest75TestNegatedContent", SigTest75TestNegatedContent);
2806 UtRegisterTest(
"DetectLongContentTest1", DetectLongContentTest1);
2807 UtRegisterTest(
"DetectLongContentTest2", DetectLongContentTest2);
2808 UtRegisterTest(
"DetectLongContentTest3", DetectLongContentTest3);