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)
744 const uint8_t *pat,
const uint16_t pat_len,
char *
str,
size_t str_len)
747 for (uint16_t i = 0; i < pat_len; i++) {
748 if (NeedsAsHex(pat[i])) {
750 snprintf(hex_str,
sizeof(hex_str),
"%s%02X", !hex ?
"|" :
" ", pat[i]);
755 snprintf(p_str,
sizeof(p_str),
"%s%c", hex ?
"|" :
"", pat[i]);
768 SCLogError(
"can't use multiple nocase modifiers with the same content");
792 static bool TestLastContent(
const Signature *s, uint16_t o, uint16_t d)
808 if (d != cd->
depth) {
815 #define TEST_RUN(sig, o, d) \
817 SCLogDebug("TEST_RUN start: '%s'", (sig)); \
818 DetectEngineCtx *de_ctx = DetectEngineCtxInit(); \
819 FAIL_IF_NULL(de_ctx); \
820 de_ctx->flags |= DE_QUIET; \
822 snprintf(rule, sizeof(rule), "alert tcp any any -> any any (%s sid:1; rev:1;)", (sig)); \
823 Signature *s = DetectEngineAppendSig(de_ctx, rule); \
825 SigPrepareStage1(de_ctx); \
826 bool res = TestLastContent(s, (o), (d)); \
828 DetectEngineCtxFree(de_ctx); \
835 static int DetectContentDepthTest01(
void)
838 TEST_RUN(
"content:\"abc\"; offset:1; depth:3;", 1, 4);
840 TEST_RUN(
"dsize:10; content:\"abc\";", 0, 10);
841 TEST_RUN(
"dsize:<10; content:\"abc\";", 0, 10);
842 TEST_RUN(
"dsize:5<>10; content:\"abc\";", 0, 10);
845 TEST_RUN(
"content:\"abc\"; depth:3; content:\"xyz\"; distance:0; within:3; ", 3, 6);
847 TEST_RUN(
"content:\"abc\"; offset:3; depth:3; content:\"xyz\"; distance:0; within:3; ", 6, 9);
848 TEST_RUN(
"content:\"abc\"; depth:6; content:\"xyz\"; distance:0; within:3; ", 3, 9);
851 TEST_RUN(
"content:\"abc\"; depth:3; content:\"klm\"; distance:0; within:3; content:\"xyz\"; distance:0; within:3; ", 6, 9);
853 TEST_RUN(
"content:\"abc\"; depth:3; content:\"klm\"; content:\"xyz\"; distance:0; within:3; ", 3, 0);
855 TEST_RUN(
"content:\"abc\"; depth:3; pcre:/\"klm\"/; content:\"xyz\"; distance:0; within:3; ", 0, 0);
857 TEST_RUN(
"content:\"abc\"; depth:3; pcre:/\"klm\"/R; content:\"xyz\"; distance:0; within:3; ", 3, 0);
858 TEST_RUN(
"content:\"abc\"; offset:3; depth:3; pcre:/\"klm\"/R; content:\"xyz\"; distance:0; within:3; ", 6, 0);
860 TEST_RUN(
"content:\"abc\"; depth:3; content:\"klm\"; within:3; content:\"xyz\"; within:3; ", 0, 9);
862 TEST_RUN(
"content:\"abc\"; depth:3; content:\"klm\"; distance:0; content:\"xyz\"; distance:0; ", 6, 0);
865 TEST_RUN(
"content:\"abc\"; depth:6; isdataat:!1,relative; content:\"klm\";", 0, 6);
866 TEST_RUN(
"content:\"abc\"; depth:3; content:\"klm\"; within:3; content:\"xyz\"; within:3; isdataat:!1,relative; content:\"def\"; ", 0, 9);
868 TEST_RUN(
"content:\"|03|\"; depth:1; content:\"|e0|\"; distance:4; within:1;", 5, 6);
869 TEST_RUN(
"content:\"|03|\"; depth:1; content:\"|e0|\"; distance:4; within:1; content:\"Cookie|3a|\"; distance:5; within:7;", 11, 18);
871 TEST_RUN(
"content:\"this\"; content:\"is\"; within:6; content:\"big\"; within:8; content:\"string\"; within:8;", 0, 0);
873 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);
874 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);
876 TEST_RUN(
"content:\"|0d 0a 0d 0a|\"; content:\"code=\"; distance:0;", 4, 0);
877 TEST_RUN(
"content:\"|0d 0a 0d 0a|\"; content:\"code=\"; distance:0; content:\"xploit.class\"; distance:2; within:18;", 11, 0);
879 TEST_RUN(
"content:\"|16 03|\"; depth:2; content:\"|55 04 0a|\"; distance:0;", 2, 0);
880 TEST_RUN(
"content:\"|16 03|\"; depth:2; content:\"|55 04 0a|\"; distance:0; content:\"|0d|LogMeIn, Inc.\"; distance:1; within:14;", 6, 0);
881 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);
883 TEST_RUN(
"content:\"=\"; offset:4; depth:9;", 4, 13);
886 TEST_RUN(
"content:\"=\"; offset:4; depth:9; content:\"=&\"; distance:55; within:2;", 60, 70);
889 TEST_RUN(
"content:\"0123456789\"; content:\"abcdef\"; distance:1048576;", 0, 0);
892 TEST_RUN(
"content:\"SMB\"; depth:8; content:\"|09 00|\"; distance:8; within:2;", 11, 18);
893 TEST_RUN(
"content:\"SMB\"; depth:8; content:\"|09 00|\"; distance:8; within:2; content:\"|05 "
894 "00 00|\"; distance:0;",
896 TEST_RUN(
"content:\"SMB\"; depth:8; content:\"|09 00|\"; distance:8; within:2; content:\"|05 "
897 "00 00|\"; distance:0; content:\"|0c 00|\"; distance:19; within:2;",
899 TEST_RUN(
"content:\"SMB\"; depth:8; content:\"|09 00|\"; distance:8; within:2; content:\"|05 "
900 "00 00|\"; distance:0; content:\"|0c 00|\"; distance:19; within:2; content:\"|15 00 "
901 "00 00|\"; distance:20; within:4;",
912 static void DetectContentPrintAll(
SigMatch *sm)
924 for (; first_sm != NULL; first_sm = first_sm->
next) {
926 SCLogDebug(
"Printing SigMatch DETECT_CONTENT %d", ++i);
934 static int g_file_data_buffer_id = 0;
935 static int g_dce_stub_data_buffer_id = 0;
940 static int DetectContentParseTest01 (
void)
942 const char *teststring =
"abc\\:def";
943 const char *teststringparsed =
"abc:def";
946 FAIL_IF(spm_global_thread_ctx == NULL);
949 FAIL_IF(memcmp(cd->
content, teststringparsed, strlen(teststringparsed)) != 0);
958 static int DetectContentParseTest02 (
void)
960 const char *teststring =
"abc\\;def";
961 const char *teststringparsed =
"abc;def";
964 FAIL_IF(spm_global_thread_ctx == NULL);
967 FAIL_IF(memcmp(cd->
content, teststringparsed, strlen(teststringparsed)) != 0);
976 static int DetectContentParseTest03 (
void)
978 const char *teststring =
"abc\\\"def";
979 const char *teststringparsed =
"abc\"def";
982 FAIL_IF(spm_global_thread_ctx == NULL);
985 FAIL_IF(memcmp(cd->
content, teststringparsed, strlen(teststringparsed)) != 0);
994 static int DetectContentParseTest04 (
void)
996 const char *teststring =
"abc\\\\def";
997 const char *teststringparsed =
"abc\\def";
1000 FAIL_IF(spm_global_thread_ctx == NULL);
1013 static int DetectContentParseTest05 (
void)
1015 const char *teststring =
"abc\\def";
1018 FAIL_IF(spm_global_thread_ctx == NULL);
1029 static int DetectContentParseTest06 (
void)
1031 const char *teststring =
"a|42|c|44|e|46|";
1032 const char *teststringparsed =
"abcdef";
1036 FAIL_IF(spm_global_thread_ctx == NULL);
1049 static int DetectContentParseTest07 (
void)
1051 const char *teststring =
"";
1054 FAIL_IF(spm_global_thread_ctx == NULL);
1065 static int DetectContentParseTest08 (
void)
1067 const char *teststring =
"";
1070 FAIL_IF(spm_global_thread_ctx == NULL);
1087 static int DetectContentLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize,
const char *sig,
1097 memset(&th_v, 0,
sizeof(th_v));
1117 SCLogDebug(
"---DetectContentLongPatternMatchTest---");
1137 static int DetectContentLongPatternMatchTestWrp(
const char *sig, uint32_t sid)
1144 uint8_t raw_eth_pkt[] = {
1145 0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
1146 0x00,0x00,0x00,0x00,0x08,0x00,0x45,0x00,
1147 0x00,0x85,0x00,0x01,0x00,0x00,0x40,0x06,
1148 0x7c,0x70,0x7f,0x00,0x00,0x01,0x7f,0x00,
1149 0x00,0x01,0x00,0x14,0x00,0x50,0x00,0x00,
1150 0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x02,
1151 0x20,0x00,0xc9,0xad,0x00,0x00,0x48,0x69,
1152 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
1153 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
1154 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
1155 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
1156 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
1157 0x74,0x63,0x68,0x65,0x73,0x20,0x6f,0x66,
1158 0x20,0x73,0x70,0x6c,0x69,0x74,0x74,0x65,
1159 0x64,0x20,0x70,0x61,0x74,0x74,0x65,0x72,
1160 0x6e,0x73,0x20,0x62,0x65,0x74,0x77,0x65,
1161 0x65,0x6e,0x20,0x6d,0x75,0x6c,0x74,0x69,
1162 0x70,0x6c,0x65,0x20,0x63,0x68,0x75,0x6e,
1165 return DetectContentLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
1172 static int DetectContentLongPatternMatchTest01(
void)
1174 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
1175 " content:\"Hi, this is a big test\"; sid:1;)";
1176 return DetectContentLongPatternMatchTestWrp(sig, 1);
1182 static int DetectContentLongPatternMatchTest02(
void)
1184 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
1185 " content:\"Hi, this is a big test to check content matches of"
1186 " splitted patterns between multiple chunks!\"; sid:1;)";
1187 return DetectContentLongPatternMatchTestWrp(sig, 1);
1194 static int DetectContentLongPatternMatchTest03(
void)
1197 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
1198 " content:\"Hi, this is a big test to check content matches of"
1199 " splitted patterns between multiple splitted chunks!\"; sid:1;)";
1200 return (DetectContentLongPatternMatchTestWrp(sig, 1) == 0) ? 1: 0;
1206 static int DetectContentLongPatternMatchTest04(
void)
1208 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1209 " content:\"Hi, this is\"; depth:15 ;content:\"a big test\"; "
1210 " within:15; content:\"to check content matches of\"; "
1211 " within:30; content:\"splitted patterns\"; distance:1; "
1214 return DetectContentLongPatternMatchTestWrp(sig, 1);
1222 static int DetectContentLongPatternMatchTest05(
void)
1224 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1225 " content:\"Hi, this is a big\"; depth:17; "
1226 " isdataat:30, relative; "
1227 " content:\"test\"; within: 5; distance:1; "
1228 " isdataat:15, relative; "
1229 " content:\"of splitted\"; within:37; distance:15; "
1230 " isdataat:20,relative; "
1231 " content:\"patterns\"; within:9; distance:1; "
1232 " isdataat:10, relative; "
1234 return DetectContentLongPatternMatchTestWrp(sig, 1);
1242 static int DetectContentLongPatternMatchTest06(
void)
1244 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1245 " content:\"Hi, this is a big test to check cont\"; depth:36;"
1246 " content:\"ent matches\"; within:11; distance:0; "
1247 " content:\"of splitted patterns between multiple\"; "
1248 " within:38; distance:1; "
1249 " content:\"chunks!\"; within: 8; distance:1; "
1251 return DetectContentLongPatternMatchTestWrp(sig, 1);
1258 static int DetectContentLongPatternMatchTest07(
void)
1260 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1261 " content:\"chunks!\"; "
1262 " content:\"content matches\"; offset:32; depth:47; "
1263 " content:\"of splitted patterns between multiple\"; "
1264 " content:\"Hi, this is a big\"; offset:0; depth:17; "
1266 return DetectContentLongPatternMatchTestWrp(sig, 1);
1273 static int DetectContentLongPatternMatchTest08(
void)
1275 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1276 " content:\"ent matches\"; "
1277 " content:\"of splitted patterns between multiple\"; "
1278 " within:38; distance:1; "
1279 " content:\"chunks!\"; within: 8; distance:1; "
1280 " content:\"Hi, this is a big test to check cont\"; depth:36;"
1282 return DetectContentLongPatternMatchTestWrp(sig, 1);
1289 static int DetectContentLongPatternMatchTest09(
void)
1291 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1292 " content:\"ent matches\"; "
1293 " content:\"of splitted patterns between multiple\"; "
1294 " offset:47; depth:85; "
1295 " content:\"chunks!\"; within: 8; distance:1; "
1296 " content:\"Hi, this is a big test to chec\"; depth:36;"
1297 " content:\"k cont\"; distance:0; within:6;"
1299 return DetectContentLongPatternMatchTestWrp(sig, 1);
1305 static int DetectContentLongPatternMatchTest10(
void)
1307 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1308 " content:\"Hi, this is a big test to check \"; "
1309 " content:\"con\"; "
1311 return DetectContentLongPatternMatchTestWrp(sig, 1);
1317 static int DetectContentLongPatternMatchTest11(
void)
1319 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\"; "
1323 return DetectContentLongPatternMatchTestWrp(sig, 1);
1326 static int DetectContentParseTest09(
void)
1329 const char *teststring =
"boo";
1333 FAIL_IF(spm_global_thread_ctx == NULL);
1346 static int DetectContentParseTest17(
void)
1349 const char *sigstr =
"alert tcp any any -> any any (msg:\"Dummy\"; "
1350 "content:\"one\"; content:\"two\"; within:2; sid:1;)";
1372 static int DetectContentParseTest18(
void)
1400 static int DetectContentParseTest19(
void)
1409 "(msg:\"Testing dce iface, stub_data with content\"; "
1410 "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
1412 "content:\"one\"; distance:0; sid:1;)");
1424 "alert tcp any any -> any any "
1425 "(msg:\"Testing dce iface, stub_data with contents & distance, within\"; "
1426 "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
1428 "content:\"one\"; distance:0; content:\"two\"; within:10; sid:2;)");
1443 "alert tcp any any -> any any "
1444 "(msg:\"Testing dce iface, stub with contents, distance, within\"; "
1445 "dce_iface:3919286a-b10c-11d0-9ba8-00c04fd92ef5; "
1447 "content:\"one\"; distance:0; "
1448 "content:\"two\"; within:10; distance:2; sid:3;)");
1463 "(msg:\"Testing content\"; "
1464 "content:\"one\"; sid:4;)");
1476 static int DetectContentParseTest20(
void)
1487 "alert udp any any -> any any "
1488 "(msg:\"test\"; content:\"\"; sid:238012;)");
1502 static int DetectContentParseTest21(
void)
1513 "alert udp any any -> any any "
1514 "(msg:\"test\"; content:\"; sid:238012;)");
1528 static int DetectContentParseTest22(
void)
1539 "alert udp any any -> any any "
1540 "(msg:\"test\"; content:\"boo; sid:238012;)");
1554 static int DetectContentParseTest23(
void)
1565 "alert udp any any -> any any "
1566 "(msg:\"test\"; content:boo\"; sid:238012;)");
1580 static int DetectContentParseTest24(
void)
1593 "alert udp any any -> any any "
1594 "(msg:\"test\"; content: !\"boo\"; sid:238012;)");
1596 printf(
"de_ctx->sig_list == NULL: ");
1603 printf(
"de_ctx->pmatch_tail == NULL || de_ctx->pmatch_tail->ctx == NULL: ");
1619 static int DetectContentParseTest25(
void)
1630 "alert udp any any -> any any "
1631 "(msg:\"test\"; content:\"|\"; sid:1;)");
1645 static int DetectContentParseTest26(
void)
1656 "alert udp any any -> any any "
1657 "(msg:\"test\"; content:\"|af\"; sid:1;)");
1671 static int DetectContentParseTest27(
void)
1682 "alert udp any any -> any any "
1683 "(msg:\"test\"; content:\"af|\"; sid:1;)");
1697 static int DetectContentParseTest28(
void)
1708 "alert udp any any -> any any "
1709 "(msg:\"test\"; content:\"|af|\"; sid:1;)");
1723 static int DetectContentParseTest29(
void)
1734 "alert udp any any -> any any "
1735 "(msg:\"test\"; content:\"aast|\"; sid:1;)");
1749 static int DetectContentParseTest30(
void)
1760 "alert udp any any -> any any "
1761 "(msg:\"test\"; content:\"aast|af\"; sid:1;)");
1775 static int DetectContentParseTest31(
void)
1786 "alert udp any any -> any any "
1787 "(msg:\"test\"; content:\"aast|af|\"; sid:1;)");
1801 static int DetectContentParseTest32(
void)
1812 "alert udp any any -> any any "
1813 "(msg:\"test\"; content:\"|af|asdf\"; sid:1;)");
1827 static int DetectContentParseTest33(
void)
1838 "alert udp any any -> any any "
1839 "(msg:\"test\"; content:\"|af|af|\"; sid:1;)");
1853 static int DetectContentParseTest34(
void)
1864 "alert udp any any -> any any "
1865 "(msg:\"test\"; content:\"|af|af|af\"; sid:1;)");
1879 static int DetectContentParseTest35(
void)
1890 "alert udp any any -> any any "
1891 "(msg:\"test\"; content:\"|af|af|af|\"; sid:1;)");
1902 static int SigTestPositiveTestContent(
const char *rule, uint8_t *buf)
1904 uint16_t buflen = strlen((
char *)buf);
1908 memset(&th_v, 0,
sizeof(th_v));
1935 static int DetectContentParseTest41(
void)
1940 char *teststring =
SCMalloc(
sizeof(
char) * (patlen + 1));
1944 for (
int i = 0; i < patlen; idx++, i++) {
1945 teststring[idx] =
'a';
1947 teststring[idx++] =
'\0';
1951 FAIL_IF(spm_global_thread_ctx == NULL);
1968 static int DetectContentParseTest42(
void)
1973 char *teststring =
SCMalloc(
sizeof(
char) * (patlen + 1));
1977 for (
int i = 0; i < patlen; idx++, i++) {
1978 teststring[idx] =
'a';
1980 teststring[idx++] =
'\0';
1984 FAIL_IF(spm_global_thread_ctx == NULL);
1998 static int DetectContentParseTest43(
void)
2003 char *teststring =
SCMalloc(
sizeof(
char) * (patlen + 1));
2007 teststring[idx++] =
'|';
2008 teststring[idx++] =
'4';
2009 teststring[idx++] =
'6';
2010 teststring[idx++] =
'|';
2011 for (
int i = 0; i < (patlen - 4); idx++, i++) {
2012 teststring[idx] =
'a';
2014 teststring[idx++] =
'\0';
2018 FAIL_IF(spm_global_thread_ctx == NULL);
2035 static int DetectContentParseTest44(
void)
2040 char *teststring =
SCMalloc(
sizeof(
char) * (patlen + 1));
2044 teststring[idx++] =
'|';
2045 teststring[idx++] =
'4';
2046 teststring[idx++] =
'6';
2047 teststring[idx++] =
'|';
2048 for (
int i = 0; i < (patlen - 4); idx++, i++) {
2049 teststring[idx] =
'a';
2051 teststring[idx++] =
'\0';
2055 FAIL_IF(spm_global_thread_ctx == NULL);
2072 static int DetectContentParseTest45(
void)
2081 "alert tcp any any -> any any "
2082 "(msg:\"test\"; content:\"|ff|\" content:\"TEST\"; sid:1;)");
2090 static int SigTestNegativeTestContent(
const char *rule, uint8_t *buf)
2092 uint16_t buflen = strlen((
char *)buf);
2097 memset(&th_v, 0,
sizeof(th_v));
2124 if (det_ctx != NULL) {
2138 static int SigTest41TestNegatedContent(
void)
2140 return SigTestPositiveTestContent(
"alert tcp any any -> any any "
2141 "(msg:\"HTTP URI cap\"; content:!\"GES\"; sid:1;)",
2143 (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\n"
2144 "GET /two/ HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2152 static int SigTest41aTestNegatedContent(
void)
2154 (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");
2163 static int SigTest42TestNegatedContent(
void)
2165 return SigTestPositiveTestContent(
2166 "alert tcp any any -> any any (content:!\"eeeeeeeeeee\"; depth:22; offset:35; sid:1;)",
2167 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2177 static int SigTest43TestNegatedContent(
void)
2179 return SigTestNegativeTestContent(
2180 "alert tcp any any -> any any (content:!\"eeeeeeeeeee\"; depth:34; offset:23; sid:1;)",
2181 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2189 static int SigTest44TestNegatedContent(
void)
2191 return SigTestPositiveTestContent(
2192 "alert tcp any any -> any any (content:!\"eeeeeeeeeee\"; offset:40; depth:35; sid:1;)",
2193 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2200 static int SigTest45TestNegatedContent(
void)
2202 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:5; "
2203 "content:!\"eeeeeeeeeee\"; depth:23; sid:1;)",
2204 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2211 static int SigTest46TestNegatedContent(
void)
2213 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaaE\"; "
2214 "content:!\"eeeeeeeeeee\"; depth:23; sid:1;)",
2215 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2223 static int SigTest47TestNegatedContent(
void)
2225 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; offset:5; "
2226 "content:!\"eeeeeeeeeee\"; depth:23; sid:1;)",
2227 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2234 static int SigTest48TestNegatedContent(
void)
2236 return SigTestPositiveTestContent(
2237 "alert tcp any any -> any any (content:\"GET\"; content:!\"GES\"; within:26; sid:1;)",
2238 (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\nGET /two/ "
2239 "HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2246 static int SigTest49TestNegatedContent(
void)
2248 return SigTestNegativeTestContent(
2249 "alert tcp any any -> any any (content:\"GET\"; content:!\"Host\"; within:26; sid:1;)",
2250 (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\nGET /two/ "
2251 "HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2258 static int SigTest50TestNegatedContent(
void)
2260 return SigTestPositiveTestContent(
2261 "alert tcp any any -> any any (content:\"GET\"; content:!\"GES\"; distance:25; sid:1;)",
2262 (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\nGET /two/ "
2263 "HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2273 static int SigTest51TestNegatedContent(
void)
2275 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");
2282 static int SigTest52TestNegatedContent(
void)
2284 return SigTestNegativeTestContent(
2285 "alert tcp any any -> any any (content:\"GES\"; content:!\"BOO\"; sid:1;)",
2286 (uint8_t *)
"GET /one/ HTTP/1.1\r\n Host: one.example.org\r\n\r\n\r\nGET /two/ "
2287 "HTTP/1.1\r\nHost: two.example.org\r\n\r\n\r\n");
2294 static int SigTest53TestNegatedContent(
void)
2296 return SigTestNegativeTestContent(
2297 "alert tcp any any -> any any (content:\"aaa\"; content:!\"Ggggg\"; within:56; sid:1;)",
2298 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2305 static int SigTest54TestNegatedContent(
void)
2307 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2308 "content:!\"gggggg\"; within:20; sid:1;)",
2309 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff ggggggggg hhhhhhhh");
2316 static int SigTest55TestNegatedContent(
void)
2318 return SigTestNegativeTestContent(
2319 "alert tcp any any -> any any (content:!\"aaa\"; depth:5; sid:1;)",
2320 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff gggggggg hhhhhhhh");
2327 static int SigTest56TestNegatedContent(
void)
2329 return SigTestPositiveTestContent(
2330 "alert tcp any any -> any any (content:\"aaa\"; content:\"Ggggg\"; within:56; sid:1;)",
2331 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Gggggggg hhhhhhhh");
2338 static int SigTest57TestNegatedContent(
void)
2340 return SigTestNegativeTestContent(
2341 "alert tcp any any -> any any (content:\"aaa\"; content:!\"Ggggg\"; within:56; sid:1;)",
2342 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2349 static int SigTest58TestNegatedContent(
void)
2351 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2352 "content:!\"Ggggg\"; distance:57; sid:1;)",
2353 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2360 static int SigTest59TestNegatedContent(
void)
2362 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2363 "content:!\"Gggg\"; distance:30; sid:1;)",
2364 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2367 static int SigTest60TestNegatedContent(
void)
2369 return SigTestNegativeTestContent(
2370 "alert tcp any any -> any any (content:!\"aaa\"; content:\"Ggggg\"; sid:1;)",
2371 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2374 static int SigTest61TestNegatedContent(
void)
2376 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2377 "content:!\"Ggggg\"; within:30; sid:1;)",
2378 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2388 static int SigTest62TestNegatedContent(
void)
2390 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2391 "content:!\"Gggggg\"; within:49; sid:1;)",
2392 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2395 static int SigTest63TestNegatedContent(
void)
2397 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2398 "content:!\"Gggggg\"; within:56; sid:1;)",
2399 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2402 static int SigTest64TestNegatedContent(
void)
2404 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2405 "content:!\"Gggggg\"; within:30; sid:1;)",
2406 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2416 static int SigTest65TestNegatedContent(
void)
2418 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2419 "content:!\"Gggggg\"; distance:0; within:49; sid:1;)",
2420 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2423 static int SigTest66TestNegatedContent(
void)
2425 return SigTestPositiveTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2426 "content:!\"Gggggg\"; within:30; sid:1;)",
2427 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2430 static int SigTest67TestNegatedContent(
void)
2432 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:10; "
2433 "content:!\"XXXX\"; within:56; sid:1;)",
2434 (uint8_t *)
"aaa bbbb cccc XXXXdddd eeeeeeeeeee ffffffffff XXXXggggg hhhhhhhh");
2437 static int SigTest68TestNegatedContent(
void)
2439 return SigTestPositiveTestContent(
2440 "alert tcp any any -> any any (content:\"aaa\"; depth:10; content:\"cccc\"; offset:8; "
2441 "content:!\"Gggggg\"; within:28; content:\"hhhhhhhh\"; sid:1;)",
2442 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2445 static int SigTest69TestNegatedContent(
void)
2447 return SigTestNegativeTestContent(
2448 "alert tcp any any -> any any (content:\"aaa\"; depth:10; content:\"cccc\"; offset:8; "
2449 "content:!\"Gggggg\"; within:48; content:\"hhhhhhhh\"; sid:1;)",
2450 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2453 static int SigTest70TestNegatedContent(
void)
2455 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2456 "content:!\"Gggggg\"; within:52; sid:1;)",
2457 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2461 static int SigTest71TestNegatedContent(
void)
2463 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2464 "content:!\"Gggggg\"; within:40; distance:43; sid:1;)",
2465 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2468 static int SigTest72TestNegatedContent(
void)
2470 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; "
2471 "content:!\"Gggggg\"; within:49; distance:43; sid:1;)",
2472 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff Ggggggggg hhhhhhhh");
2475 static int SigTest73TestNegatedContent(
void)
2477 return SigTestNegativeTestContent(
"alert tcp any any -> any any (content:\"aaa\"; depth:5; "
2478 "content:!\"eeeeeeeeeee\"; depth:35; sid:1;)",
2479 (uint8_t *)
"aaa bbbb cccc dddddddd eeeeeeeeeee ffffffffff ggggggggg hhhhhhhh");
2482 static int SigTest74TestNegatedContent(
void)
2484 return SigTestPositiveTestContent(
"alert tcp any any -> any any (msg:\"HTTP URI cap\"; content:\"USER\"; content:!\"PASS\"; sid:1;)", (uint8_t *)
"USER apple");
2487 static int SigTest75TestNegatedContent(
void)
2489 return SigTestPositiveTestContent(
"alert tcp any any -> any any (msg:\"HTTP URI cap\"; content:\"USER\"; content:\"!PASS\"; sid:1;)", (uint8_t *)
"USER !PASS");
2492 static int SigTest76TestBug134(
void)
2494 uint8_t *buf = (uint8_t *)
"test detect ${IFS} in traffic";
2495 uint16_t buflen = strlen((
char *)buf);
2500 memset(&f, 0,
sizeof(
Flow));
2509 char sig[] =
"alert tcp any any -> any 515 "
2510 "(msg:\"detect IFS\"; flow:to_server,established; content:\"${IFS}\";"
2511 " depth:50; offset:0; sid:900091; rev:1;)";
2526 static int SigTest77TestBug139(
void)
2529 0x12, 0x23, 0x34, 0x35, 0x52, 0x52, 0x24, 0x42, 0x22, 0x24,
2530 0x52, 0x24, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x34 };
2531 uint16_t buflen =
sizeof(buf);
2536 char sig[] =
"alert udp any any -> any 53 (msg:\"dns testing\";"
2537 " content:\"|00 00|\"; depth:5; offset:13; sid:9436601;"
2551 static int DetectLongContentTestCommon(
const char *sig, uint32_t sid)
2554 static uint8_t pkt[739] = {
2555 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2556 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x45, 0x00,
2557 0x02, 0xd5, 0x4a, 0x18, 0x40, 0x00, 0x40, 0x06,
2558 0xd7, 0xd6, 0x0a, 0x10, 0x01, 0x0b, 0x0a, 0x10,
2559 0x01, 0x0a, 0xdb, 0x36, 0x00, 0x50, 0xca, 0xc5,
2560 0xcc, 0xd1, 0x95, 0x77, 0x0f, 0x7d, 0x80, 0x18,
2561 0x00, 0xe5, 0x77, 0x9d, 0x00, 0x00, 0x01, 0x01,
2562 0x08, 0x0a, 0x1d, 0xe0, 0x86, 0xc6, 0xfc, 0x73,
2563 0x49, 0xf3, 0x50, 0x4f, 0x53, 0x54, 0x20, 0x2f,
2564 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e,
2565 0x31, 0x0d, 0x0a, 0x55, 0x73, 0x65, 0x72, 0x2d,
2566 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20, 0x63,
2567 0x75, 0x72, 0x6c, 0x2f, 0x37, 0x2e, 0x33, 0x37,
2568 0x2e, 0x30, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74,
2569 0x3a, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x36, 0x2e,
2570 0x31, 0x2e, 0x31, 0x30, 0x0d, 0x0a, 0x41, 0x63,
2571 0x63, 0x65, 0x70, 0x74, 0x3a, 0x20, 0x2a, 0x2f,
2572 0x2a, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65,
2573 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74,
2574 0x68, 0x3a, 0x20, 0x35, 0x32, 0x38, 0x0d, 0x0a,
2575 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d,
2576 0x54, 0x79, 0x70, 0x65, 0x3a, 0x20, 0x61, 0x70,
2577 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
2578 0x6e, 0x2f, 0x78, 0x2d, 0x77, 0x77, 0x77, 0x2d,
2579 0x66, 0x6f, 0x72, 0x6d, 0x2d, 0x75, 0x72, 0x6c,
2580 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x64, 0x0d,
2581 0x0a, 0x0d, 0x0a, 0x58, 0x58, 0x58, 0x58, 0x58,
2582 0x58, 0x58, 0x58, 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, 0x41, 0x41, 0x41, 0x41, 0x41,
2646 0x41, 0x41, 0x41, 0x58, 0x58, 0x58, 0x58, 0x58,
2650 return DetectContentLongPatternMatchTest(pkt, (uint16_t)
sizeof(pkt), sig,
2654 static int DetectLongContentTest1(
void)
2657 const char *sig =
"alert tcp any any -> any any (msg:\"Test Rule\"; content:\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"; sid:1;)";
2659 return DetectLongContentTestCommon(sig, 1);
2662 static int DetectLongContentTest2(
void)
2665 const char *sig =
"alert tcp any any -> any any (msg:\"Test Rule\"; content:\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"; sid:1;)";
2667 return DetectLongContentTestCommon(sig, 1);
2670 static int DetectLongContentTest3(
void)
2673 const char *sig =
"alert tcp any any -> any any (msg:\"Test Rule\"; content:\"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\"; sid:1;)";
2675 return !DetectLongContentTestCommon(sig, 1);
2678 static int DetectBadBinContent(
void)
2685 de_ctx,
"alert tcp any any -> any any (msg:\"test\"; content:\"|a|\"; sid:1;)"));
2687 de_ctx,
"alert tcp any any -> any any (msg:\"test\"; content:\"|aa b|\"; sid:1;)"));
2689 de_ctx,
"alert tcp any any -> any any (msg:\"test\"; content:\"|aa bz|\"; sid:1;)"));
2692 de_ctx,
"alert tcp any any -> any any (msg:\"test\"; content:\"|22 2 22|\"; sid:1;)"));
2700 static void DetectContentRegisterTests(
void)
2705 UtRegisterTest(
"DetectContentDepthTest01", DetectContentDepthTest01);
2707 UtRegisterTest(
"DetectContentParseTest01", DetectContentParseTest01);
2708 UtRegisterTest(
"DetectContentParseTest02", DetectContentParseTest02);
2709 UtRegisterTest(
"DetectContentParseTest03", DetectContentParseTest03);
2710 UtRegisterTest(
"DetectContentParseTest04", DetectContentParseTest04);
2711 UtRegisterTest(
"DetectContentParseTest05", DetectContentParseTest05);
2712 UtRegisterTest(
"DetectContentParseTest06", DetectContentParseTest06);
2713 UtRegisterTest(
"DetectContentParseTest07", DetectContentParseTest07);
2714 UtRegisterTest(
"DetectContentParseTest08", DetectContentParseTest08);
2715 UtRegisterTest(
"DetectContentParseTest09", DetectContentParseTest09);
2716 UtRegisterTest(
"DetectContentParseTest17", DetectContentParseTest17);
2717 UtRegisterTest(
"DetectContentParseTest18", DetectContentParseTest18);
2718 UtRegisterTest(
"DetectContentParseTest19", DetectContentParseTest19);
2719 UtRegisterTest(
"DetectContentParseTest20", DetectContentParseTest20);
2720 UtRegisterTest(
"DetectContentParseTest21", DetectContentParseTest21);
2721 UtRegisterTest(
"DetectContentParseTest22", DetectContentParseTest22);
2722 UtRegisterTest(
"DetectContentParseTest23", DetectContentParseTest23);
2723 UtRegisterTest(
"DetectContentParseTest24", DetectContentParseTest24);
2724 UtRegisterTest(
"DetectContentParseTest25", DetectContentParseTest25);
2725 UtRegisterTest(
"DetectContentParseTest26", DetectContentParseTest26);
2726 UtRegisterTest(
"DetectContentParseTest27", DetectContentParseTest27);
2727 UtRegisterTest(
"DetectContentParseTest28", DetectContentParseTest28);
2728 UtRegisterTest(
"DetectContentParseTest29", DetectContentParseTest29);
2729 UtRegisterTest(
"DetectContentParseTest30", DetectContentParseTest30);
2730 UtRegisterTest(
"DetectContentParseTest31", DetectContentParseTest31);
2731 UtRegisterTest(
"DetectContentParseTest32", DetectContentParseTest32);
2732 UtRegisterTest(
"DetectContentParseTest33", DetectContentParseTest33);
2733 UtRegisterTest(
"DetectContentParseTest34", DetectContentParseTest34);
2734 UtRegisterTest(
"DetectContentParseTest35", DetectContentParseTest35);
2735 UtRegisterTest(
"DetectContentParseTest41", DetectContentParseTest41);
2736 UtRegisterTest(
"DetectContentParseTest42", DetectContentParseTest42);
2737 UtRegisterTest(
"DetectContentParseTest43", DetectContentParseTest43);
2738 UtRegisterTest(
"DetectContentParseTest44", DetectContentParseTest44);
2739 UtRegisterTest(
"DetectContentParseTest45", DetectContentParseTest45);
2743 DetectContentLongPatternMatchTest01);
2745 DetectContentLongPatternMatchTest02);
2747 DetectContentLongPatternMatchTest03);
2749 DetectContentLongPatternMatchTest04);
2751 DetectContentLongPatternMatchTest05);
2753 DetectContentLongPatternMatchTest06);
2755 DetectContentLongPatternMatchTest07);
2757 DetectContentLongPatternMatchTest08);
2759 DetectContentLongPatternMatchTest09);
2761 DetectContentLongPatternMatchTest10);
2763 DetectContentLongPatternMatchTest11);
2766 UtRegisterTest(
"SigTest41TestNegatedContent", SigTest41TestNegatedContent);
2768 SigTest41aTestNegatedContent);
2769 UtRegisterTest(
"SigTest42TestNegatedContent", SigTest42TestNegatedContent);
2770 UtRegisterTest(
"SigTest43TestNegatedContent", SigTest43TestNegatedContent);
2771 UtRegisterTest(
"SigTest44TestNegatedContent", SigTest44TestNegatedContent);
2772 UtRegisterTest(
"SigTest45TestNegatedContent", SigTest45TestNegatedContent);
2773 UtRegisterTest(
"SigTest46TestNegatedContent", SigTest46TestNegatedContent);
2774 UtRegisterTest(
"SigTest47TestNegatedContent", SigTest47TestNegatedContent);
2775 UtRegisterTest(
"SigTest48TestNegatedContent", SigTest48TestNegatedContent);
2776 UtRegisterTest(
"SigTest49TestNegatedContent", SigTest49TestNegatedContent);
2777 UtRegisterTest(
"SigTest50TestNegatedContent", SigTest50TestNegatedContent);
2778 UtRegisterTest(
"SigTest51TestNegatedContent", SigTest51TestNegatedContent);
2779 UtRegisterTest(
"SigTest52TestNegatedContent", SigTest52TestNegatedContent);
2780 UtRegisterTest(
"SigTest53TestNegatedContent", SigTest53TestNegatedContent);
2781 UtRegisterTest(
"SigTest54TestNegatedContent", SigTest54TestNegatedContent);
2782 UtRegisterTest(
"SigTest55TestNegatedContent", SigTest55TestNegatedContent);
2783 UtRegisterTest(
"SigTest56TestNegatedContent", SigTest56TestNegatedContent);
2784 UtRegisterTest(
"SigTest57TestNegatedContent", SigTest57TestNegatedContent);
2785 UtRegisterTest(
"SigTest58TestNegatedContent", SigTest58TestNegatedContent);
2786 UtRegisterTest(
"SigTest59TestNegatedContent", SigTest59TestNegatedContent);
2787 UtRegisterTest(
"SigTest60TestNegatedContent", SigTest60TestNegatedContent);
2788 UtRegisterTest(
"SigTest61TestNegatedContent", SigTest61TestNegatedContent);
2789 UtRegisterTest(
"SigTest62TestNegatedContent", SigTest62TestNegatedContent);
2790 UtRegisterTest(
"SigTest63TestNegatedContent", SigTest63TestNegatedContent);
2791 UtRegisterTest(
"SigTest64TestNegatedContent", SigTest64TestNegatedContent);
2792 UtRegisterTest(
"SigTest65TestNegatedContent", SigTest65TestNegatedContent);
2793 UtRegisterTest(
"SigTest66TestNegatedContent", SigTest66TestNegatedContent);
2794 UtRegisterTest(
"SigTest67TestNegatedContent", SigTest67TestNegatedContent);
2795 UtRegisterTest(
"SigTest68TestNegatedContent", SigTest68TestNegatedContent);
2796 UtRegisterTest(
"SigTest69TestNegatedContent", SigTest69TestNegatedContent);
2797 UtRegisterTest(
"SigTest70TestNegatedContent", SigTest70TestNegatedContent);
2798 UtRegisterTest(
"SigTest71TestNegatedContent", SigTest71TestNegatedContent);
2799 UtRegisterTest(
"SigTest72TestNegatedContent", SigTest72TestNegatedContent);
2800 UtRegisterTest(
"SigTest73TestNegatedContent", SigTest73TestNegatedContent);
2801 UtRegisterTest(
"SigTest74TestNegatedContent", SigTest74TestNegatedContent);
2802 UtRegisterTest(
"SigTest75TestNegatedContent", SigTest75TestNegatedContent);
2807 UtRegisterTest(
"DetectLongContentTest1", DetectLongContentTest1);
2808 UtRegisterTest(
"DetectLongContentTest2", DetectLongContentTest2);
2809 UtRegisterTest(
"DetectLongContentTest3", DetectLongContentTest3);