20 #include "../app-layer-htp.h"
21 #include "../conf-yaml-loader.h"
22 #include "../detect-parse.h"
23 #include "../detect-engine-content-inspection.h"
24 #include "../detect-engine-build.h"
25 #include "../pkt-var.h"
26 #include "../flow-util.h"
27 #include "../stream-tcp-reassemble.h"
28 #include "../util-unittest.h"
29 #include "../util-var-name.h"
30 #include "../util-unittest-helper.h"
32 static const char *dummy_conf_string =
36 "default-log-dir: /var/log/suricata\n"
40 " default-log-level: debug\n"
42 " default-format: \"<%t> - <%l>\"\n"
44 " default-startup-message: Your IDS has started.\n"
46 " default-output-filter:\n"
50 " - interface: console\n"
53 " - interface: file\n"
54 " filename: /var/log/suricata.log\n"
56 " - interface: syslog\n"
70 " HOME_NET: \"[192.168.0.0/16,10.8.0.0/16,127.0.0.1,2001:888:"
71 "13c5:5AFE::/64,2001:888:13c5:CAFE::/64]\"\n"
73 " EXTERNAL_NET: \"[!192.168.0.0/16,2000::/3]\"\n"
75 " HTTP_SERVERS: \"!192.168.0.0/16\"\n"
77 " SMTP_SERVERS: \"!192.168.0.0/16\"\n"
79 " SQL_SERVERS: \"!192.168.0.0/16\"\n"
83 " TELNET_SERVERS: any\n"
89 " HTTP_PORTS: \"80:81,88\"\n"
91 " SHELLCODE_PORTS: 80\n"
93 " ORACLE_PORTS: 1521\n"
98 static int SigTest01 (
void)
100 uint8_t *buf = (uint8_t *)
101 "GET /one/ HTTP/1.1\r\n"
102 "Host: one.example.org\r\n"
104 "GET /two/ HTTP/1.1\r\n"
105 "Host: two.example.org\r\n"
107 uint16_t buflen = strlen((
char *)buf);
111 char sig[] =
"alert tcp any any -> any any (msg:\"HTTP URI cap\"; content:\"GET \"; depth:4; pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/\\d\\.\\d\\r\\n/G\"; sid:1;)";
118 static int SigTest02 (
void)
120 uint8_t *buf = (uint8_t *)
121 "GET /one/ HTTP/1.1\r\n"
122 "Host: one.example.org\r\n"
124 "GET /two/ HTTP/1.1\r\n"
125 "Host: two.example.org\r\n"
127 uint16_t buflen = strlen((
char *)buf);
129 char sig[] =
"alert tcp any any -> any any (msg:\"HTTP TEST\"; content:\"Host: one.example.org\"; offset:20; depth:41; sid:1;)";
135 static int SigTest03 (
void)
137 uint8_t *buf = (uint8_t *)
138 "GET /one/ HTTP/1.1\r\n"
139 "Host: one.example.org\r\n"
141 "GET /two/ HTTP/1.1\r\n"
142 "Host: two.example.org\r\n"
144 uint16_t buflen = strlen((
char *)buf);
154 "alert tcp any any -> any any (msg:\"HTTP TEST\"; content:\"Host: "
155 "one.example.org\"; offset:20; depth:39; sid:1;)");
169 static int SigTest04 (
void)
171 uint8_t *buf = (uint8_t *)
172 "GET /one/ HTTP/1.1\r\n"
173 "Host: one.example.org\r\n"
175 "GET /two/ HTTP/1.1\r\n"
176 "Host: two.example.org\r\n"
178 uint16_t buflen = strlen((
char *)buf);
188 "alert tcp any any -> any any (msg:\"HTTP TEST\"; content:\"Host:\"; "
189 "offset:20; depth:25; content:\"Host:\"; distance:42; within:47; sid:1;)");
203 static int SigTest05 (
void)
205 uint8_t *buf = (uint8_t *)
206 "GET /one/ HTTP/1.1\r\n"
207 "Host: one.example.org\r\n"
209 "GET /two/ HTTP/1.1\r\n"
210 "Host: two.example.org\r\n"
212 uint16_t buflen = strlen((
char *)buf);
222 "alert tcp any any -> any any (msg:\"HTTP TEST\"; content:\"Host:\"; "
223 "offset:20; depth:25; content:\"Host:\"; distance:48; within:52; sid:1;)");
237 static int SigTest06 (
void)
239 uint8_t *buf = (uint8_t *)
240 "GET /one/ HTTP/1.1\r\n"
241 "Host: one.example.org\r\n"
243 "GET /two/ HTTP/1.1\r\n"
244 "Host: two.example.org\r\n"
246 uint16_t buflen = strlen((
char *)buf);
257 memset(&f, 0,
sizeof(f));
258 memset(&ssn, 0,
sizeof(ssn));
266 f.
proto = IPPROTO_TCP;
279 Signature *s =
DetectEngineAppendSig(
de_ctx,
"alert tcp any any -> any any (msg:\"HTTP URI cap\"; content:\"GET \"; depth:4; pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/\\d\\.\\d\\r\\n/G\"; sid:1;)");
306 static int SigTest07 (
void)
308 uint8_t *buf = (uint8_t *)
309 "GET /one/ HTTP/1.1\r\n"
310 "Host: one.example.org\r\n"
312 "GET /two/ HTTP/1.1\r\n"
313 "Host: two.example.org\r\n"
315 uint16_t buflen = strlen((
char *)buf);
325 memset(&f, 0,
sizeof(f));
326 memset(&ssn, 0,
sizeof(ssn));
332 f.
proto = IPPROTO_TCP;
346 "alert tcp any any -> any any (msg:\"HTTP URI cap\"; content:\"GET \"; depth:4; "
347 "pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/\\d\\.\\d\\r\\n/G\"; sid:1;)");
350 "alert tcp any any -> any any (msg:\"HTTP URI test\"; uricontent:\"three\"; sid:2;)");
374 static int SigTest08 (
void)
376 uint8_t *buf = (uint8_t *)
377 "GET /one/ HTTP/1.0\r\n"
378 "Host: one.example.org\r\n"
380 "GET /two/ HTTP/1.0\r\n"
381 "Host: two.example.org\r\n"
383 uint16_t buflen = strlen((
char *)buf);
390 memset(&f, 0,
sizeof(
Flow));
393 memset(&ssn, 0,
sizeof(ssn));
401 f.
proto = IPPROTO_TCP;
415 "alert tcp any any -> any any (msg:\"HTTP URI cap\"; content:\"GET \"; "
416 "depth:4; pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/1\\.0\\r\\n/G\"; sid:1;)");
419 "alert tcp any any -> any any (msg:\"HTTP URI test\"; uricontent:\"one\"; sid:2;)");
443 static int SigTest09 (
void)
445 uint8_t *buf = (uint8_t *)
446 "GET /one/ HTTP/1.0\r\n"
447 "Host: one.example.org\r\n"
449 "GET /two/ HTTP/1.0\r\n"
450 "Host: two.example.org\r\n"
452 uint16_t buflen = strlen((
char *)buf);
461 memset(&f, 0,
sizeof(f));
462 memset(&ssn, 0,
sizeof(ssn));
470 f.
proto = IPPROTO_TCP;
484 "alert tcp any any -> any any (msg:\"HTTP URI cap\"; content:\"GET \"; "
485 "depth:4; pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/1\\.0\\r\\n/G\"; sid:1;)");
488 "alert tcp any any -> any any (msg:\"HTTP URI test\"; uricontent:\"two\"; sid:2;)");
512 static int SigTest10 (
void)
514 uint8_t *buf = (uint8_t *)
"ABC";
515 uint16_t buflen = strlen((
char *)buf);
524 memset(&f, 0,
sizeof(f));
525 memset(&ssn, 0,
sizeof(ssn));
532 f.
proto = IPPROTO_TCP;
546 "test (1)\"; content:\"ABCD\"; depth:4; sid:1;");
549 "(2)\"; content:\"VWXYZ\"; sid:2;");
572 static int SigTest11 (
void)
574 uint8_t *buf = (uint8_t *)
575 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";
576 uint16_t buflen = strlen((
char *)buf);
586 memset(&f, 0,
sizeof(f));
587 memset(&ssn, 0,
sizeof(ssn));
593 f.
proto = IPPROTO_TCP;
609 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (content:\"ABCDEFGHIJ\"; content:\"klmnop\"; content:\"1234\"; sid:1;)");
637 static int SigTest12 (
void)
639 uint8_t *buf = (uint8_t *)
640 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";
641 uint16_t buflen = strlen((
char *)buf);
650 memset(&f, 0,
sizeof(
Flow));
665 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"Content order test\"; content:\"ABCDEFGHIJ\"; content:\"klmnop\"; content:\"1234\"; sid:1;)");
692 static int SigTest13 (
void)
694 uint8_t *buf = (uint8_t *)
695 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";
696 uint16_t buflen = strlen((
char *)buf);
705 memset(&f, 0,
sizeof(
Flow));
720 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"Content order test\"; content:\"ABCDEFGHIJ\"; content:\"1234\"; content:\"klmnop\"; sid:1;)");
744 static int SigTest14 (
void)
746 uint8_t *buf = (uint8_t *)
747 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";
748 uint16_t buflen = strlen((
char *)buf);
766 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"Content order test\"; content:\"ABCDEFGHIJ\"; content:\"1234\"; content:\"klmnop\"; distance:0; sid:1;)");
789 static int SigTest15 (
void)
791 uint8_t *buf = (uint8_t *)
792 "CONNECT 213.92.8.7:31204 HTTP/1.1";
793 uint16_t buflen = strlen((
char *)buf);
821 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any !$HTTP_PORTS (msg:\"ET POLICY Inbound HTTP CONNECT Attempt on Off-Port\"; content:\"CONNECT \"; nocase; depth:8; content:\" HTTP/1.\"; nocase; within:1000; sid:2008284; rev:2;)");
846 static int SigTest16 (
void)
848 uint8_t *buf = (uint8_t *)
849 "CONNECT 213.92.8.7:31204 HTTP/1.1";
850 uint16_t buflen = strlen((
char *)buf);
858 memset(&
p, 0,
sizeof(
p));
873 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any !$HTTP_PORTS (msg:\"ET POLICY Inbound HTTP CONNECT Attempt on Off-Port\"; content:\"CONNECT \"; nocase; depth:8; content:\" HTTP/1.\"; nocase; within:1000; sid:2008284; rev:2;)");
897 static int SigTest17 (
void)
899 uint8_t *buf = (uint8_t *)
900 "GET /one/ HTTP/1.1\r\n"
901 "Host: one.example.org\r\n"
903 "GET /two/ HTTP/1.1\r\n"
904 "Host: two.example.org\r\n"
906 uint16_t buflen = strlen((
char *)buf);
924 Signature *s =
DetectEngineAppendSig(
de_ctx,
"alert tcp any any -> any $HTTP_PORTS (msg:\"HTTP host cap\"; content:\"Host:\"; pcre:\"/^Host: (?P<pkt_http_host>.*)\\r\\n/m\"; noalert; sid:1;)");
947 static int SigTest18 (
void)
949 uint8_t *buf = (uint8_t *)
950 "220 (vsFTPd 2.0.5)\r\n";
951 uint16_t buflen = strlen((
char *)buf);
976 de_ctx->
sig_list =
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;)");
989 printf(
"signature shouldn't match, but did: ");
999 static int SigTest19 (
void)
1001 uint8_t *buf = (uint8_t *)
1002 "220 (vsFTPd 2.0.5)\r\n";
1003 uint16_t buflen = strlen((
char *)buf);
1048 printf(
"signature didn't match, but should have: ");
1060 static int SigTest20 (
void)
1062 uint8_t *buf = (uint8_t *)
1063 "220 (vsFTPd 2.0.5)\r\n";
1064 uint16_t buflen = strlen((
char *)buf);
1096 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert ip $HOME_NET any -> [99.99.99.99,1.2.3.0/24,1.1.1.1,3.0.0.0/8] any (msg:\"IP-ONLY test (2)\"; sid:999; rev:1;)");
1109 printf(
"signature didn't match, but should have: ");
1121 static int SigTest21 (
void)
1130 memset(&f, 0,
sizeof(f));
1134 uint8_t *buf1 = (uint8_t *)
"GET /one/ HTTP/1.0\r\n"
1136 uint16_t buf1len = strlen((
char *)buf1);
1139 uint8_t *buf2 = (uint8_t *)
"GET /two/ HTTP/1.0\r\n"
1141 uint16_t buf2len = strlen((
char *)buf2);
1158 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"FLOWBIT SET\"; content:\"/one/\"; flowbits:set,TEST.one; flowbits:noalert; sid:1;)");
1174 printf(
"sid 1 alerted, but shouldn't: ");
1179 printf(
"sid 2 didn't alert, but should have: ");
1186 if (det_ctx != NULL) {
1198 static int SigTest22 (
void)
1207 memset(&f, 0,
sizeof(f));
1211 uint8_t *buf1 = (uint8_t *)
"GET /one/ HTTP/1.0\r\n"
1213 uint16_t buf1len = strlen((
char *)buf1);
1221 uint8_t *buf2 = (uint8_t *)
"GET /two/ HTTP/1.0\r\n"
1223 uint16_t buf2len = strlen((
char *)buf2);
1237 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"FLOWBIT SET\"; content:\"/one/\"; flowbits:set,TEST.one; flowbits:noalert; sid:1;)");
1253 printf(
"sid 1 alerted, but shouldn't: ");
1260 printf(
"sid 2 alerted, but shouldn't: ");
1272 static int SigTest23 (
void)
1281 memset(&f, 0,
sizeof(f));
1285 uint8_t *buf1 = (uint8_t *)
"GET /one/ HTTP/1.0\r\n"
1287 uint16_t buf1len = strlen((
char *)buf1);
1295 uint8_t *buf2 = (uint8_t *)
"GET /two/ HTTP/1.0\r\n"
1297 uint16_t buf2len = strlen((
char *)buf2);
1312 SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"FLOWBIT SET\"; content:\"/one/\"; "
1313 "flowbits:set,TEST.one; flowbits:noalert; sid:1;)");
1329 printf(
"sid 1 alerted, but shouldn't: ");
1336 printf(
"sid 2 didn't alert, but should have: ");
1348 static int SigTest24IPV4Keyword(
void)
1350 uint8_t valid_raw_ipv4[] = {
1351 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1352 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1353 0xc0, 0xa8, 0x01, 0x03};
1355 uint8_t invalid_raw_ipv4[] = {
1356 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1357 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1358 0xc0, 0xa8, 0x01, 0x06};
1372 uint8_t *buf = (uint8_t *)
"GET /one/ HTTP/1.0\r\n"
1374 uint16_t buflen = strlen((
char *)buf);
1379 PacketSetIPV4(p1, valid_raw_ipv4);
1384 p1->
proto = IPPROTO_TCP;
1386 PacketSetIPV4(p2, invalid_raw_ipv4);
1391 p2->
proto = IPPROTO_TCP;
1401 "alert ip any any -> any any "
1402 "(content:\"/one/\"; ipv4-csum:valid; "
1403 "msg:\"ipv4-csum keyword check(1)\"; sid:1;)");
1405 printf(
"sig 1 parse: ");
1410 "alert ip any any -> any any "
1411 "(content:\"/one/\"; ipv4-csum:invalid; "
1412 "msg:\"ipv4-csum keyword check(1)\"; "
1415 printf(
"sig 2 parse: ");
1424 printf(
"signature 1 didn't match, but should have: ");
1430 printf(
"signature 2 didn't match, but should have: ");
1436 if (det_ctx != NULL) {
1446 static int SigTest25NegativeIPV4Keyword(
void)
1448 uint8_t valid_raw_ipv4[] = {
1449 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1450 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1451 0xc0, 0xa8, 0x01, 0x03};
1453 uint8_t invalid_raw_ipv4[] = {
1454 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
1455 0x40, 0x01, 0xb7, 0x52, 0xc0, 0xa8, 0x01, 0x03,
1456 0xc0, 0xa8, 0x01, 0x06};
1470 uint8_t *buf = (uint8_t *)
"GET /one/ HTTP/1.0\r\n"
1472 uint16_t buflen = strlen((
char *)buf);
1477 PacketSetIPV4(p1, valid_raw_ipv4);
1482 p1->
proto = IPPROTO_TCP;
1484 PacketSetIPV4(p2, invalid_raw_ipv4);
1489 p2->
proto = IPPROTO_TCP;
1499 "alert ip any any -> any any "
1500 "(content:\"/one/\"; ipv4-csum:invalid; "
1501 "msg:\"ipv4-csum keyword check(1)\"; sid:1;)");
1508 "alert ip any any -> any any "
1509 "(content:\"/one/\"; ipv4-csum:valid; "
1510 "msg:\"ipv4-csum keyword check(1)\"; "
1541 static int SigTest26TCPV4Keyword(
void)
1543 uint8_t raw_ipv4[] = {
1544 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1545 0x00, 0x00, 0x00, 0x00, 0x40, 0x8e, 0x7e, 0xb2,
1546 0xc0, 0xa8, 0x01, 0x03};
1548 uint8_t valid_raw_tcp[] = {
1549 0x00, 0x50, 0x8e, 0x16, 0x0d, 0x59, 0xcd, 0x3c,
1550 0xcf, 0x0d, 0x21, 0x80, 0x50, 0x12, 0x16, 0xa0,
1551 0x4A, 0x04, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
1552 0x04, 0x02, 0x08, 0x0a, 0x6e, 0x18, 0x78, 0x73,
1553 0x01, 0x71, 0x74, 0xde, 0x01, 0x03, 0x03, 0x02};
1555 uint8_t invalid_raw_tcp[] = {
1556 0x00, 0x50, 0x8e, 0x16, 0x0d, 0x59, 0xcd, 0x3c,
1557 0xcf, 0x0d, 0x21, 0x80, 0x50, 0x12, 0x16, 0xa0,
1558 0xfa, 0x03, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
1559 0x04, 0x02, 0x08, 0x0a, 0x6e, 0x18, 0x78, 0x73,
1560 0x01, 0x71, 0x74, 0xde, 0x01, 0x03, 0x03, 0x03};
1585 PacketSetTCP(p1, (
GET_PKT_DATA(p1) +
sizeof(raw_ipv4)));
1590 p1->
proto = IPPROTO_TCP;
1593 PacketSetTCP(p2, (
GET_PKT_DATA(p2) +
sizeof(raw_ipv4)));
1598 p2->
proto = IPPROTO_TCP;
1606 "alert ip any any -> any any "
1607 "(content:\"|DE 01 03|\"; tcpv4-csum:valid; dsize:20; "
1608 "msg:\"tcpv4-csum keyword check(1)\"; sid:1;)");
1612 "alert ip any any -> any any "
1613 "(content:\"|DE 01 03|\"; tcpv4-csum:invalid; "
1614 "msg:\"tcpv4-csum keyword check(1)\"; "
1636 static int SigTest26TCPV4AndNegativeIPV4Keyword(
void)
1638 uint8_t raw_ipv4[] = {
1639 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1640 0x00, 0x00, 0x00, 0x00, 0x40, 0x8e, 0x7e, 0xb2,
1641 0xc0, 0xa8, 0x01, 0x03};
1643 uint8_t valid_raw_tcp[] = {
1644 0x00, 0x50, 0x8e, 0x16, 0x0d, 0x59, 0xcd, 0x3c,
1645 0xcf, 0x0d, 0x21, 0x80, 0x50, 0x12, 0x16, 0xa0,
1646 0x4A, 0x04, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
1647 0x04, 0x02, 0x08, 0x0a, 0x6e, 0x18, 0x78, 0x73,
1648 0x01, 0x71, 0x74, 0xde, 0x01, 0x03, 0x03, 0x02};
1650 uint8_t invalid_raw_tcp[] = {
1651 0x00, 0x50, 0x8e, 0x16, 0x0d, 0x59, 0xcd, 0x3c,
1652 0xcf, 0x0d, 0x21, 0x80, 0x50, 0x12, 0x16, 0xa0,
1653 0xfa, 0x03, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
1654 0x04, 0x02, 0x08, 0x0a, 0x6e, 0x18, 0x78, 0x73,
1655 0x01, 0x71, 0x74, 0xde, 0x01, 0x03, 0x03, 0x03};
1681 PacketSetTCP(p1, (
GET_PKT_DATA(p1) +
sizeof(raw_ipv4)));
1686 p1->
proto = IPPROTO_TCP;
1689 PacketSetTCP(p2, (
GET_PKT_DATA(p2) +
sizeof(raw_ipv4)));
1694 p2->
proto = IPPROTO_TCP;
1704 "alert ip any any -> any any "
1705 "(content:\"|DE 01 03|\"; tcpv4-csum:valid; dsize:20; "
1706 "ipv4-csum:invalid; "
1707 "msg:\"tcpv4-csum and ipv4-csum keyword check(1)\"; sid:1;)");
1713 "alert ip any any -> any any "
1714 "(content:\"|DE 01 03|\"; tcpv4-csum:invalid; "
1715 "ipv4-csum:invalid; "
1716 "msg:\"tcpv4-csum keyword check(1)\"; "
1727 printf(
"sig 1 didn't match: ");
1733 printf(
"sig 2 didn't match: ");
1748 static int SigTest26TCPV4AndIPV4Keyword(
void)
1753 uint8_t raw_ipv4[] = {
1754 0x45, 0x00, 0x00, 0x40, 0x9b, 0xa4, 0x40, 0x00,
1755 0x40, 0x06, 0xbd, 0x0a, 0xc0, 0xa8, 0xb0, 0x43,
1756 0xc0, 0xa8, 0xb0, 0x74};
1763 uint8_t valid_raw_tcp[] = {
1764 0xc1, 0x6d, 0x01, 0xbd, 0x03, 0x10, 0xd3, 0xc9,
1765 0x00, 0x00, 0x00, 0x00, 0xb0, 0x02, 0xff, 0xff,
1766 0x20, 0x09, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
1767 0x01, 0x03, 0x03, 0x04, 0x01, 0x01, 0x08, 0x0a,
1768 0x19, 0x69, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00,
1769 0x04, 0x02, 0x00, 0x00};
1771 uint8_t invalid_raw_tcp[] = {
1772 0xc1, 0x6d, 0x01, 0xbd, 0x03, 0x10, 0xd3, 0xc9,
1773 0x00, 0x00, 0x00, 0x00, 0xb0, 0x02, 0xff, 0xff,
1774 0x20, 0x09, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
1775 0x01, 0x03, 0x03, 0x04, 0x01, 0x01, 0x08, 0x0a,
1776 0x19, 0x69, 0x81, 0x7e, 0xFF, 0xAA, 0x00, 0x00,
1777 0x04, 0x02, 0x00, 0x00};
1803 PacketSetTCP(p1, (
GET_PKT_DATA(p1) +
sizeof(raw_ipv4)));
1808 p1->
proto = IPPROTO_TCP;
1811 PacketSetTCP(p2, (
GET_PKT_DATA(p2) +
sizeof(raw_ipv4)));
1816 p2->
proto = IPPROTO_TCP;
1826 "alert ip any any -> any any "
1827 "(tcpv4-csum:valid; "
1829 "msg:\"tcpv4-csum and ipv4-csum keyword check(1)\"; sid:1;)");
1835 "alert ip any any -> any any "
1836 "(tcpv4-csum:invalid; "
1838 "msg:\"tcpv4-csum and ipv4-csum keyword check(1)\"; "
1849 printf(
"sig 1 didn't match: ");
1855 printf(
"sig 2 didn't match: ");
1869 static int SigTest27NegativeTCPV4Keyword(
void)
1871 uint8_t raw_ipv4[] = {
1872 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1873 0x00, 0x00, 0x00, 0x00, 0x40, 0x8e, 0x7e, 0xb2,
1874 0xc0, 0xa8, 0x01, 0x03};
1876 uint8_t valid_raw_tcp[] = {
1877 0x00, 0x50, 0x8e, 0x16, 0x0d, 0x59, 0xcd, 0x3c,
1878 0xcf, 0x0d, 0x21, 0x80, 0x50, 0x12, 0x16, 0xa0,
1879 0xfa, 0x03, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
1880 0x04, 0x02, 0x08, 0x0a, 0x6e, 0x18, 0x78, 0x73,
1881 0x01, 0x71, 0x74, 0xde, 0x01, 0x03, 0x03, 0x02};
1883 uint8_t invalid_raw_tcp[] = {
1884 0x00, 0x50, 0x8e, 0x16, 0x0d, 0x59, 0xcd, 0x3c,
1885 0xcf, 0x0d, 0x21, 0x80, 0x50, 0x12, 0x16, 0xa0,
1886 0xfa, 0x03, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4,
1887 0x04, 0x02, 0x08, 0x0a, 0x6e, 0x18, 0x78, 0x73,
1888 0x01, 0x71, 0x74, 0xde, 0x01, 0x03, 0x03, 0x03};
1912 PacketSetTCP(p1, (
GET_PKT_DATA(p1) +
sizeof(raw_ipv4)));
1917 p1->
proto = IPPROTO_TCP;
1920 PacketSetTCP(p2, (
GET_PKT_DATA(p2) +
sizeof(raw_ipv4)));
1925 p2->
proto = IPPROTO_TCP;
1935 "alert tcp any any -> any any "
1936 "(content:\"|DE 01 03|\"; tcpv4-csum:invalid; dsize:20; "
1937 "msg:\"tcpv4-csum keyword check(1)\"; sid:1;)");
1943 "alert tcp any any -> any any "
1944 "(content:\"|DE 01 03|\"; tcpv4-csum:valid; dsize:20; "
1945 "msg:\"tcpv4-csum keyword check(2)\"; "
1956 printf(
"sig 1 didn't match on p1: ");
1962 printf(
"sig 2 matched on p2: ");
1976 static int SigTest28TCPV6Keyword(
void)
1978 static uint8_t valid_raw_ipv6[] = {
1979 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
1980 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd,
1982 0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x06, 0x40,
1983 0x3f, 0xfe, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01,
1984 0x02, 0x00, 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda,
1985 0x3f, 0xfe, 0x05, 0x01, 0x04, 0x10, 0x00, 0x00,
1986 0x02, 0xc0, 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e,
1988 0x03, 0xfe, 0x00, 0x16, 0xd6, 0x76, 0xf5, 0x2d,
1989 0x0c, 0x7a, 0x08, 0x77, 0x50, 0x10, 0x21, 0x5c,
1990 0xf2, 0xf1, 0x00, 0x00,
1992 0x01, 0x01, 0x08, 0x0a, 0x00, 0x08, 0xca, 0x5a,
1993 0x00, 0x01, 0x69, 0x27};
1995 static uint8_t invalid_raw_ipv6[] = {
1996 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
1997 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd,
1999 0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x06, 0x40,
2000 0x3f, 0xfe, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01,
2001 0x02, 0x00, 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda,
2002 0x3f, 0xfe, 0x05, 0x01, 0x04, 0x10, 0x00, 0x00,
2003 0x02, 0xc0, 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e,
2005 0x03, 0xfe, 0x00, 0x16, 0xd6, 0x76, 0xf5, 0x2d,
2006 0x0c, 0x7a, 0x08, 0x77, 0x50, 0x10, 0x21, 0x5c,
2007 0xc2, 0xf1, 0x00, 0x00,
2009 0x01, 0x01, 0x08, 0x0a, 0x00, 0x08, 0xca, 0x5a,
2010 0x00, 0x01, 0x69, 0x28};
2027 PacketSetIPV6(p1, valid_raw_ipv6 + 14);
2028 PacketSetTCP(p1, (valid_raw_ipv6 + 54));
2031 p1->
payload = valid_raw_ipv6 + 54 + 20;
2033 p1->
proto = IPPROTO_TCP;
2039 PacketSetIPV6(p2, invalid_raw_ipv6 + 14);
2040 PacketSetTCP(p2, (invalid_raw_ipv6 + 54));
2043 p2->
payload = invalid_raw_ipv6 + 54 + 20;
2045 p2->
proto = IPPROTO_TCP;
2059 "alert tcp any any -> any any "
2060 "(content:\"|00 01 69|\"; tcpv6-csum:valid; dsize:12; "
2061 "msg:\"tcpv6-csum keyword check(1)\"; sid:1;)");
2067 "alert tcp any any -> any any "
2068 "(content:\"|00 01 69|\"; tcpv6-csum:invalid; dsize:12; "
2069 "msg:\"tcpv6-csum keyword check(1)\"; "
2080 printf(
"sid 1 didn't match on p1: ");
2086 printf(
"sid 2 didn't match on p2: ");
2100 static int SigTest29NegativeTCPV6Keyword(
void)
2102 static uint8_t valid_raw_ipv6[] = {
2103 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
2104 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd,
2106 0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x06, 0x40,
2107 0x3f, 0xfe, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01,
2108 0x02, 0x00, 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda,
2109 0x3f, 0xfe, 0x05, 0x01, 0x04, 0x10, 0x00, 0x00,
2110 0x02, 0xc0, 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e,
2112 0x03, 0xfe, 0x00, 0x16, 0xd6, 0x76, 0xf5, 0x2d,
2113 0x0c, 0x7a, 0x08, 0x77, 0x50, 0x10, 0x21, 0x5c,
2114 0xf2, 0xf1, 0x00, 0x00,
2116 0x01, 0x01, 0x08, 0x0a, 0x00, 0x08, 0xca, 0x5a,
2117 0x00, 0x01, 0x69, 0x27};
2119 static uint8_t invalid_raw_ipv6[] = {
2120 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
2121 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd,
2123 0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x06, 0x40,
2124 0x3f, 0xfe, 0x05, 0x07, 0x00, 0x00, 0x00, 0x01,
2125 0x02, 0x00, 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda,
2126 0x3f, 0xfe, 0x05, 0x01, 0x04, 0x10, 0x00, 0x00,
2127 0x02, 0xc0, 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e,
2129 0x03, 0xfe, 0x00, 0x16, 0xd6, 0x76, 0xf5, 0x2d,
2130 0x0c, 0x7a, 0x08, 0x77, 0x50, 0x10, 0x21, 0x5c,
2131 0xc2, 0xf1, 0x00, 0x00,
2133 0x01, 0x01, 0x08, 0x0a, 0x00, 0x08, 0xca, 0x5a,
2134 0x00, 0x01, 0x69, 0x28};
2151 PacketSetIPV6(p1, valid_raw_ipv6 + 14);
2152 PacketSetTCP(p1, valid_raw_ipv6 + 54);
2155 p1->
payload = valid_raw_ipv6 + 54 + 20;
2157 p1->
proto = IPPROTO_TCP;
2163 PacketSetIPV6(p2, invalid_raw_ipv6 + 14);
2164 PacketSetTCP(p2, invalid_raw_ipv6 + 54);
2167 p2->
payload = invalid_raw_ipv6 + 54 + 20;
2169 p2->
proto = IPPROTO_TCP;
2181 "alert tcp any any -> any any "
2182 "(content:\"|00 01 69|\"; tcpv6-csum:invalid; dsize:12; "
2183 "msg:\"tcpv6-csum keyword check(1)\"; "
2190 "alert tcp any any -> any any "
2191 "(content:\"|00 01 69|\"; tcpv6-csum:valid; dsize:12; "
2192 "msg:\"tcpv6-csum keyword check(1)\"; "
2211 if (det_ctx != NULL)
2220 static int SigTest30UDPV4Keyword(
void)
2222 uint8_t raw_ipv4[] = {
2223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2224 0x00, 0x11, 0x00, 0x00, 0xd0, 0x43, 0xdc, 0xdc,
2225 0xc0, 0xa8, 0x01, 0x03};
2227 uint8_t valid_raw_udp[] = {
2228 0x00, 0x35, 0xcf, 0x34, 0x00, 0x55, 0x6c, 0xe0,
2229 0x83, 0xfc, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
2230 0x00, 0x00, 0x00, 0x00, 0x07, 0x70, 0x61, 0x67,
2231 0x65, 0x61, 0x64, 0x32, 0x11, 0x67, 0x6f, 0x6f,
2232 0x67, 0x6c, 0x65, 0x73, 0x79, 0x6e, 0x64, 0x69,
2233 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x03, 0x63,
2234 0x6f, 0x6d, 0x00, 0x00, 0x1c, 0x00, 0x01, 0xc0,
2235 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x4b,
2236 0x50, 0x00, 0x12, 0x06, 0x70, 0x61, 0x67, 0x65,
2237 0x61, 0x64, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f,
2238 0x67, 0x6c, 0x65, 0xc0, 0x26};
2240 uint8_t invalid_raw_udp[] = {
2241 0x00, 0x35, 0xcf, 0x34, 0x00, 0x55, 0x6c, 0xe0,
2242 0x83, 0xfc, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
2243 0x00, 0x00, 0x00, 0x00, 0x07, 0x70, 0x61, 0x67,
2244 0x65, 0x61, 0x64, 0x32, 0x11, 0x67, 0x6f, 0x6f,
2245 0x67, 0x6c, 0x65, 0x73, 0x79, 0x6e, 0x64, 0x69,
2246 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x03, 0x63,
2247 0x6f, 0x6d, 0x00, 0x00, 0x1c, 0x00, 0x01, 0xc0,
2248 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x4b,
2249 0x50, 0x00, 0x12, 0x06, 0x70, 0x61, 0x67, 0x65,
2250 0x61, 0x64, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f,
2251 0x67, 0x6c, 0x65, 0xc0, 0x27};
2261 uint8_t *buf = (uint8_t *)
"GET /one/ HTTP/1.0yyyyyyyyyyyyyyyy\r\n"
2262 "\r\n\r\nyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
2267 PacketSetIPV4(p1, raw_ipv4);
2268 PacketSetUDP(p1, valid_raw_udp);
2273 p1->
proto = IPPROTO_UDP;
2275 PacketSetIPV4(p2, raw_ipv4);
2276 PacketSetUDP(p2, invalid_raw_udp);
2281 p2->
proto = IPPROTO_UDP;
2289 "alert udp any any -> any any "
2290 "(content:\"/one/\"; udpv4-csum:valid; "
2291 "msg:\"udpv4-csum keyword check(1)\"; "
2296 "alert udp any any -> any any "
2297 "(content:\"/one/\"; udpv4-csum:invalid; "
2298 "msg:\"udpv4-csum keyword check(1)\"; "
2311 if (det_ctx != NULL)
2320 static int SigTest31NegativeUDPV4Keyword(
void)
2322 uint8_t raw_ipv4[] = {
2323 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2324 0x00, 0x00, 0x00, 0x00, 0xd0, 0x43, 0xdc, 0xdc,
2325 0xc0, 0xa8, 0x01, 0x03};
2327 uint8_t valid_raw_udp[] = {
2328 0x00, 0x35, 0xcf, 0x34, 0x00, 0x55, 0x6c, 0xe0,
2329 0x83, 0xfc, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
2330 0x00, 0x00, 0x00, 0x00, 0x07, 0x70, 0x61, 0x67,
2331 0x65, 0x61, 0x64, 0x32, 0x11, 0x67, 0x6f, 0x6f,
2332 0x67, 0x6c, 0x65, 0x73, 0x79, 0x6e, 0x64, 0x69,
2333 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x03, 0x63,
2334 0x6f, 0x6d, 0x00, 0x00, 0x1c, 0x00, 0x01, 0xc0,
2335 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x4b,
2336 0x50, 0x00, 0x12, 0x06, 0x70, 0x61, 0x67, 0x65,
2337 0x61, 0x64, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f,
2338 0x67, 0x6c, 0x65, 0xc0, 0x26};
2340 uint8_t invalid_raw_udp[] = {
2341 0x00, 0x35, 0xcf, 0x34, 0x00, 0x55, 0x6c, 0xe0,
2342 0x83, 0xfc, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
2343 0x00, 0x00, 0x00, 0x00, 0x07, 0x70, 0x61, 0x67,
2344 0x65, 0x61, 0x64, 0x32, 0x11, 0x67, 0x6f, 0x6f,
2345 0x67, 0x6c, 0x65, 0x73, 0x79, 0x6e, 0x64, 0x69,
2346 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x03, 0x63,
2347 0x6f, 0x6d, 0x00, 0x00, 0x1c, 0x00, 0x01, 0xc0,
2348 0x0c, 0x00, 0x05, 0x00, 0x01, 0x00, 0x01, 0x4b,
2349 0x50, 0x00, 0x12, 0x06, 0x70, 0x61, 0x67, 0x65,
2350 0x61, 0x64, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f,
2351 0x67, 0x6c, 0x65, 0xc0, 0x27};
2365 uint8_t *buf = (uint8_t *)
"GET /one/ HTTP/1.0yyyyyyyyyyyyyyyy\r\n"
2366 "\r\n\r\nyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
2371 PacketSetIPV4(p1, raw_ipv4);
2372 PacketSetUDP(p1, valid_raw_udp);
2377 p1->
proto = IPPROTO_UDP;
2379 PacketSetIPV4(p2, raw_ipv4);
2380 PacketSetUDP(p2, invalid_raw_udp);
2385 p2->
proto = IPPROTO_UDP;
2395 "alert udp any any -> any any "
2396 "(content:\"/one/\"; udpv4-csum:invalid; "
2397 "msg:\"udpv4-csum keyword check(1)\"; sid:1;)");
2404 "alert udp any any -> any any "
2405 "(content:\"/one/\"; udpv4-csum:valid; "
2406 "msg:\"udpv4-csum keyword check(1)\"; "
2429 if (det_ctx != NULL)
2440 static int SigTest32UDPV6Keyword(
void)
2442 static uint8_t valid_raw_ipv6[] = {
2443 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
2444 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd, 0x60, 0x00,
2445 0x00, 0x00, 0x00, 0x14, 0x11, 0x02, 0x3f, 0xfe,
2446 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
2447 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
2448 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
2449 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
2450 0x82, 0xa0, 0x00, 0x14, 0x1a, 0xc3, 0x06, 0x02,
2451 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0x57, 0xb0,
2454 static uint8_t invalid_raw_ipv6[] = {
2455 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
2456 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd, 0x60, 0x00,
2457 0x00, 0x00, 0x00, 0x14, 0x11, 0x02, 0x3f, 0xfe,
2458 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
2459 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
2460 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
2461 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
2462 0x82, 0xa0, 0x00, 0x14, 0x1a, 0xc3, 0x06, 0x02,
2463 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0x57, 0xb0,
2474 uint8_t *buf = (uint8_t *)
"GET /one/ HTTP\r\n"
2480 PacketSetIPV6(p1, valid_raw_ipv6 + 14);
2481 PacketSetUDP(p1, valid_raw_ipv6 + 54);
2486 p1->
proto = IPPROTO_UDP;
2488 PacketSetIPV6(p2, invalid_raw_ipv6 + 14);
2489 PacketSetUDP(p2, invalid_raw_ipv6 + 54);
2494 p2->
proto = IPPROTO_UDP;
2502 "alert udp any any -> any any "
2503 "(content:\"/one/\"; udpv6-csum:valid; "
2504 "msg:\"udpv6-csum keyword check(1)\"; sid:1;)");
2508 "alert udp any any -> any any "
2509 "(content:\"/one/\"; udpv6-csum:invalid; "
2510 "msg:\"udpv6-csum keyword check(1)\"; "
2523 if (det_ctx != NULL)
2533 static int SigTest33NegativeUDPV6Keyword(
void)
2535 static uint8_t valid_raw_ipv6[] = {
2536 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
2537 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd, 0x60, 0x00,
2538 0x00, 0x00, 0x00, 0x14, 0x11, 0x02, 0x3f, 0xfe,
2539 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
2540 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
2541 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
2542 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
2543 0x82, 0xa0, 0x00, 0x14, 0x1a, 0xc3, 0x06, 0x02,
2544 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0x57, 0xb0,
2547 static uint8_t invalid_raw_ipv6[] = {
2548 0x00, 0x60, 0x97, 0x07, 0x69, 0xea, 0x00, 0x00,
2549 0x86, 0x05, 0x80, 0xda, 0x86, 0xdd, 0x60, 0x00,
2550 0x00, 0x00, 0x00, 0x14, 0x11, 0x02, 0x3f, 0xfe,
2551 0x05, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00,
2552 0x86, 0xff, 0xfe, 0x05, 0x80, 0xda, 0x3f, 0xfe,
2553 0x05, 0x01, 0x04, 0x10, 0x00, 0x00, 0x02, 0xc0,
2554 0xdf, 0xff, 0xfe, 0x47, 0x03, 0x3e, 0xa0, 0x75,
2555 0x82, 0xa0, 0x00, 0x14, 0x1a, 0xc3, 0x06, 0x02,
2556 0x00, 0x00, 0xf9, 0xc8, 0xe7, 0x36, 0x57, 0xb0,
2571 uint8_t *buf = (uint8_t *)
"GET /one/ HTTP\r\n"
2577 PacketSetIPV6(p1, valid_raw_ipv6 + 14);
2578 PacketSetUDP(p1, valid_raw_ipv6 + 54);
2583 p1->
proto = IPPROTO_UDP;
2585 PacketSetIPV6(p2, invalid_raw_ipv6 + 14);
2586 PacketSetUDP(p2, invalid_raw_ipv6 + 54);
2591 p2->
proto = IPPROTO_UDP;
2601 "alert udp any any -> any any "
2602 "(content:\"/one/\"; udpv6-csum:invalid; "
2603 "msg:\"udpv6-csum keyword check(1)\"; sid:1;)");
2610 "alert udp any any -> any any "
2611 "(content:\"/one/\"; udpv6-csum:valid; "
2612 "msg:\"udpv6-csum keyword check(1)\"; "
2634 if (det_ctx != NULL)
2644 static int SigTest34ICMPV4Keyword(
void)
2646 uint8_t valid_raw_ipv4[] = {
2647 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
2648 0x40, 0x01, 0x3c, 0xa7, 0x7f, 0x00, 0x00, 0x01,
2649 0x7f, 0x00, 0x00, 0x01, 0x08, 0x00, 0xc3, 0x01,
2650 0x2b, 0x36, 0x00, 0x01, 0x3f, 0x16, 0x9a, 0x4a,
2651 0x41, 0x63, 0x04, 0x00, 0x08, 0x09, 0x0a, 0x0b,
2652 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
2653 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
2654 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
2655 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
2656 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
2657 0x34, 0x35, 0x36, 0x37};
2659 uint8_t invalid_raw_ipv4[] = {
2660 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
2661 0x40, 0x01, 0x3c, 0xa7, 0x7f, 0x00, 0x00, 0x01,
2662 0x7f, 0x00, 0x00, 0x01, 0x08, 0x00, 0xc3, 0x01,
2663 0x2b, 0x36, 0x00, 0x01, 0x3f, 0x16, 0x9a, 0x4a,
2664 0x41, 0x63, 0x04, 0x00, 0x08, 0x09, 0x0a, 0x0b,
2665 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
2666 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
2667 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
2668 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
2669 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
2670 0x34, 0x35, 0x36, 0x38};
2684 uint8_t *buf = (uint8_t *)
"GET /one/ HTTP/1.0\r\n"
2686 uint16_t buflen = strlen((
char *)buf);
2691 IPV4Hdr *ip4h = PacketSetIPV4(p1, valid_raw_ipv4);
2698 p1->
proto = IPPROTO_ICMP;
2700 ip4h = PacketSetIPV4(p2, invalid_raw_ipv4);
2707 p2->
proto = IPPROTO_ICMP;
2717 "alert icmp any any -> any any "
2718 "(content:\"/one/\"; icmpv4-csum:valid; "
2719 "msg:\"icmpv4-csum keyword check(1)\"; sid:1;)");
2726 "alert icmp any any -> any any "
2727 "(content:\"/one/\"; icmpv4-csum:invalid; "
2728 "msg:\"icmpv4-csum keyword check(1)\"; "
2750 if (det_ctx != NULL)
2760 static int SigTest35NegativeICMPV4Keyword(
void)
2762 uint8_t valid_raw_ipv4[] = {
2763 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
2764 0x40, 0x01, 0x3c, 0xa7, 0x7f, 0x00, 0x00, 0x01,
2765 0x7f, 0x00, 0x00, 0x01, 0x08, 0x00, 0xc3, 0x01,
2766 0x2b, 0x36, 0x00, 0x01, 0x3f, 0x16, 0x9a, 0x4a,
2767 0x41, 0x63, 0x04, 0x00, 0x08, 0x09, 0x0a, 0x0b,
2768 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
2769 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
2770 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
2771 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
2772 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
2773 0x34, 0x35, 0x36, 0x37};
2775 uint8_t invalid_raw_ipv4[] = {
2776 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
2777 0x40, 0x01, 0x3c, 0xa7, 0x7f, 0x00, 0x00, 0x01,
2778 0x7f, 0x00, 0x00, 0x01, 0x08, 0x00, 0xc3, 0x01,
2779 0x2b, 0x36, 0x00, 0x01, 0x3f, 0x16, 0x9a, 0x4a,
2780 0x41, 0x63, 0x04, 0x00, 0x08, 0x09, 0x0a, 0x0b,
2781 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
2782 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
2783 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
2784 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
2785 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
2786 0x34, 0x35, 0x36, 0x38};
2800 uint8_t *buf = (uint8_t *)
"GET /one/ HTTP/1.0\r\n"
2802 uint16_t buflen = strlen((
char *)buf);
2807 IPV4Hdr *ip4h = PacketSetIPV4(p1, valid_raw_ipv4);
2814 p1->
proto = IPPROTO_ICMP;
2816 ip4h = PacketSetIPV4(p2, invalid_raw_ipv4);
2823 p2->
proto = IPPROTO_ICMP;
2833 "alert icmp any any -> any any "
2834 "(content:\"/one/\"; icmpv4-csum:invalid; "
2835 "msg:\"icmpv4-csum keyword check(1)\"; sid:1;)");
2842 "alert icmp any any -> any any "
2843 "(content:\"/one/\"; icmpv4-csum:valid; "
2844 "msg:\"icmpv4-csum keyword check(1)\"; "
2867 if (det_ctx != NULL)
2877 static int SigTest38(
void)
2885 uint8_t raw_eth[] = {
2886 0x00, 0x00, 0x03, 0x04, 0x00, 0x06, 0x00,
2887 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2890 uint8_t raw_ipv4[] = {
2891 0x45, 0x00, 0x00, 0x7d, 0xd8, 0xf3, 0x40, 0x00,
2892 0x40, 0x06, 0x63, 0x85, 0x7f, 0x00, 0x00, 0x01,
2893 0x7f, 0x00, 0x00, 0x01
2895 uint8_t raw_tcp[] = {
2896 0xad, 0x22, 0x04, 0x00, 0x16, 0x39, 0x72,
2897 0xe2, 0x16, 0x1f, 0x79, 0x84, 0x80, 0x18,
2898 0x01, 0x01, 0xfe, 0x71, 0x00, 0x00, 0x01,
2899 0x01, 0x08, 0x0a, 0x00, 0x22, 0xaa, 0x10,
2900 0x00, 0x22, 0xaa, 0x10
2903 0x00, 0x00, 0x00, 0x08, 0x62, 0x6f, 0x6f, 0x65,
2904 0x65, 0x6b, 0x0d, 0x0a, 0x4c, 0x45, 0x4e, 0x31,
2905 0x20, 0x38, 0x0d, 0x0a, 0x66, 0x6f, 0x30, 0x30,
2906 0x30, 0x38, 0x0d, 0x0a, 0x4c, 0x45, 0x4e, 0x32,
2907 0x20, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
2908 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
2909 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
2910 0x39, 0x39, 0x39, 0x0d, 0x0a, 0x41, 0x41, 0x41,
2911 0x41, 0x41, 0x41, 0x0d, 0x0a, 0x0d, 0x0a, 0x0d,
2914 uint16_t ethlen =
sizeof(raw_eth);
2915 uint16_t ipv4len =
sizeof(raw_ipv4);
2916 uint16_t tcplen =
sizeof(raw_tcp);
2917 uint16_t buflen =
sizeof(buf);
2939 SET_PKT_LEN(p1, ethlen + ipv4len + tcplen + buflen);
2941 PacketSetEthernet(p1, raw_eth);
2942 PacketSetIPV4(p1, raw_ipv4);
2943 PacketSetTCP(p1, raw_tcp);
2948 p1->
proto = IPPROTO_TCP;
2957 "alert tcp any any -> any any "
2958 "(content:\"LEN1|20|\"; "
2959 "byte_test:4,=,8,0; "
2960 "msg:\"byte_test keyword check(1)\"; sid:1;)");
2966 "alert tcp any any -> any any "
2967 "(content:\"LEN1|20|\"; "
2968 "byte_test:4,=,8,5,relative,string,dec; "
2969 "msg:\"byte_test keyword check(2)\"; sid:2;)");
2983 printf(
"sid 1 didn't alert, but should have: ");
2990 printf(
"sid 2 didn't alert, but should have: ");
2995 if (det_ctx != NULL)
3005 static int SigTest39(
void)
3009 uint8_t raw_eth[] = {
3010 0x00, 0x00, 0x03, 0x04, 0x00, 0x06, 0x00,
3011 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3014 uint8_t raw_ipv4[] = {
3015 0x45, 0x00, 0x00, 0x7d, 0xd8, 0xf3, 0x40, 0x00,
3016 0x40, 0x06, 0x63, 0x85, 0x7f, 0x00, 0x00, 0x01,
3017 0x7f, 0x00, 0x00, 0x01
3019 uint8_t raw_tcp[] = {
3020 0xad, 0x22, 0x04, 0x00, 0x16, 0x39, 0x72,
3021 0xe2, 0x16, 0x1f, 0x79, 0x84, 0x80, 0x18,
3022 0x01, 0x01, 0xfe, 0x71, 0x00, 0x00, 0x01,
3023 0x01, 0x08, 0x0a, 0x00, 0x22, 0xaa, 0x10,
3024 0x00, 0x22, 0xaa, 0x10
3027 0x00, 0x00, 0x00, 0x08, 0x62, 0x6f, 0x6f, 0x65,
3028 0x65, 0x6b, 0x0d, 0x0a, 0x4c, 0x45, 0x4e, 0x31,
3029 0x20, 0x38, 0x0d, 0x0a, 0x66, 0x30, 0x30, 0x30,
3030 0x38, 0x72, 0x0d, 0x0a, 0x4c, 0x45, 0x4e, 0x32,
3031 0x20, 0x39, 0x39, 0x4c, 0x45, 0x4e, 0x32, 0x39,
3032 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
3033 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39,
3034 0x39, 0x39, 0x39, 0x0d, 0x0a, 0x41, 0x41, 0x41,
3035 0x41, 0x41, 0x41, 0x0d, 0x0a, 0x0d, 0x0a, 0x0d,
3038 uint16_t ethlen =
sizeof(raw_eth);
3039 uint16_t ipv4len =
sizeof(raw_ipv4);
3040 uint16_t tcplen =
sizeof(raw_tcp);
3041 uint16_t buflen =
sizeof(buf);
3053 SET_PKT_LEN(p1, ethlen + ipv4len + tcplen + buflen);
3055 PacketSetEthernet(p1, raw_eth);
3056 PacketSetIPV4(p1, raw_ipv4);
3057 PacketSetTCP(p1, raw_tcp);
3062 p1->
proto = IPPROTO_TCP;
3069 "(content:\"LEN1|20|\"; "
3070 "byte_test:4,=,8,0; "
3072 "byte_test:6,=,0x4c454e312038,0,relative; "
3073 "msg:\"byte_jump keyword check(1)\"; sid:1;)");
3076 "(content:\"LEN1|20|\"; "
3077 "byte_test:4,=,8,4,relative,string,dec; "
3078 "byte_jump:4,4,relative,string,dec,post_offset 2; "
3079 "byte_test:4,=,0x4c454e32,0,relative; "
3080 "msg:\"byte_jump keyword check(2)\"; sid:2;)");
3103 static int SigTest36ContentAndIsdataatKeywords01 (
void)
3106 uint8_t raw_eth [] = {
3107 0x00,0x25,0x00,0x9e,0xfa,0xfe,0x00,0x02,0xcf,0x74,0xfe,0xe1,0x08,0x00,0x45,0x00
3108 ,0x01,0xcc,0xcb,0x91,0x00,0x00,0x34,0x06,0xdf,0xa8,0xd1,0x55,0xe3,0x67,0xc0,0xa8
3109 ,0x64,0x8c,0x00,0x50,0xc0,0xb7,0xd1,0x11,0xed,0x63,0x81,0xa9,0x9a,0x05,0x80,0x18
3110 ,0x00,0x75,0x0a,0xdd,0x00,0x00,0x01,0x01,0x08,0x0a,0x09,0x8a,0x06,0xd0,0x12,0x21
3111 ,0x2a,0x3b,0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x31,0x20,0x33,0x30,0x32,0x20,0x46
3112 ,0x6f,0x75,0x6e,0x64,0x0d,0x0a,0x4c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x3a,0x20
3113 ,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x77,0x77,0x2e,0x67,0x6f,0x6f,0x67,0x6c
3114 ,0x65,0x2e,0x65,0x73,0x2f,0x0d,0x0a,0x43,0x61,0x63,0x68,0x65,0x2d,0x43,0x6f,0x6e
3115 ,0x74,0x72,0x6f,0x6c,0x3a,0x20,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x0d,0x0a,0x43
3116 ,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x74,0x65,0x78
3117 ,0x74,0x2f,0x68,0x74,0x6d,0x6c,0x3b,0x20,0x63,0x68,0x61,0x72,0x73,0x65,0x74,0x3d
3118 ,0x55,0x54,0x46,0x2d,0x38,0x0d,0x0a,0x44,0x61,0x74,0x65,0x3a,0x20,0x4d,0x6f,0x6e
3119 ,0x2c,0x20,0x31,0x34,0x20,0x53,0x65,0x70,0x20,0x32,0x30,0x30,0x39,0x20,0x30,0x38
3120 ,0x3a,0x34,0x38,0x3a,0x33,0x31,0x20,0x47,0x4d,0x54,0x0d,0x0a,0x53,0x65,0x72,0x76
3121 ,0x65,0x72,0x3a,0x20,0x67,0x77,0x73,0x0d,0x0a,0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74
3122 ,0x2d,0x4c,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,0x32,0x31,0x38,0x0d,0x0a,0x0d,0x0a
3123 ,0x3c,0x48,0x54,0x4d,0x4c,0x3e,0x3c,0x48,0x45,0x41,0x44,0x3e,0x3c,0x6d,0x65,0x74
3124 ,0x61,0x20,0x68,0x74,0x74,0x70,0x2d,0x65,0x71,0x75,0x69,0x76,0x3d,0x22,0x63,0x6f
3125 ,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x74,0x79,0x70,0x65,0x22,0x20,0x63,0x6f,0x6e,0x74
3126 ,0x65,0x6e,0x74,0x3d,0x22,0x74,0x65,0x78,0x74,0x2f,0x68,0x74,0x6d,0x6c,0x3b,0x63
3127 ,0x68,0x61,0x72,0x73,0x65,0x74,0x3d,0x75,0x74,0x66,0x2d,0x38,0x22,0x3e,0x0a,0x3c
3128 ,0x54,0x49,0x54,0x4c,0x45,0x3e,0x33,0x30,0x32,0x20,0x4d,0x6f,0x76,0x65,0x64,0x3c
3129 ,0x2f,0x54,0x49,0x54,0x4c,0x45,0x3e,0x3c,0x2f,0x48,0x45,0x41,0x44,0x3e,0x3c,0x42
3130 ,0x4f,0x44,0x59,0x3e,0x0a,0x3c,0x48,0x31,0x3e,0x33,0x30,0x32,0x20,0x4d,0x6f,0x76
3131 ,0x65,0x64,0x3c,0x2f,0x48,0x31,0x3e,0x0a,0x54,0x68,0x65,0x20,0x64,0x6f,0x63,0x75
3132 ,0x6d,0x65,0x6e,0x74,0x20,0x68,0x61,0x73,0x20,0x6d,0x6f,0x76,0x65,0x64,0x0a,0x3c
3133 ,0x41,0x20,0x48,0x52,0x45,0x46,0x3d,0x22,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77
3134 ,0x77,0x77,0x2e,0x67,0x6f,0x6f,0x67,0x6c,0x65,0x2e,0x65,0x73,0x2f,0x22,0x3e,0x68
3135 ,0x65,0x72,0x65,0x3c,0x2f,0x41,0x3e,0x2e,0x0d,0x0a,0x3c,0x2f,0x42,0x4f,0x44,0x59
3136 ,0x3e,0x3c,0x2f,0x48,0x54,0x4d,0x4c,0x3e,0x0d,0x0a };
3157 "alert tcp any any -> any any (content:\"HTTP\"; isdataat:404, relative; sid:101;)");
3180 static int SigTest37ContentAndIsdataatKeywords02 (
void)
3186 uint8_t raw_eth [] = {
3187 0x00,0x25,0x00,0x9e,0xfa,0xfe,0x00,0x02,0xcf,0x74,0xfe,0xe1,0x08,0x00,0x45,0x00
3188 ,0x01,0xcc,0xcb,0x91,0x00,0x00,0x34,0x06,0xdf,0xa8,0xd1,0x55,0xe3,0x67,0xc0,0xa8
3189 ,0x64,0x8c,0x00,0x50,0xc0,0xb7,0xd1,0x11,0xed,0x63,0x81,0xa9,0x9a,0x05,0x80,0x18
3190 ,0x00,0x75,0x0a,0xdd,0x00,0x00,0x01,0x01,0x08,0x0a,0x09,0x8a,0x06,0xd0,0x12,0x21
3191 ,0x2a,0x3b,0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x31,0x20,0x33,0x30,0x32,0x20,0x46
3192 ,0x6f,0x75,0x6e,0x64,0x0d,0x0a,0x4c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x3a,0x20
3193 ,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,0x77,0x77,0x2e,0x67,0x6f,0x6f,0x67,0x6c
3194 ,0x65,0x2e,0x65,0x73,0x2f,0x0d,0x0a,0x43,0x61,0x63,0x68,0x65,0x2d,0x43,0x6f,0x6e
3195 ,0x74,0x72,0x6f,0x6c,0x3a,0x20,0x70,0x72,0x69,0x76,0x61,0x74,0x65,0x0d,0x0a,0x43
3196 ,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x74,0x65,0x78
3197 ,0x74,0x2f,0x68,0x74,0x6d,0x6c,0x3b,0x20,0x63,0x68,0x61,0x72,0x73,0x65,0x74,0x3d
3198 ,0x55,0x54,0x46,0x2d,0x38,0x0d,0x0a,0x44,0x61,0x74,0x65,0x3a,0x20,0x4d,0x6f,0x6e
3199 ,0x2c,0x20,0x31,0x34,0x20,0x53,0x65,0x70,0x20,0x32,0x30,0x30,0x39,0x20,0x30,0x38
3200 ,0x3a,0x34,0x38,0x3a,0x33,0x31,0x20,0x47,0x4d,0x54,0x0d,0x0a,0x53,0x65,0x72,0x76
3201 ,0x65,0x72,0x3a,0x20,0x67,0x77,0x73,0x0d,0x0a,0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74
3202 ,0x2d,0x4c,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,0x32,0x31,0x38,0x0d,0x0a,0x0d,0x0a
3203 ,0x3c,0x48,0x54,0x4d,0x4c,0x3e,0x3c,0x48,0x45,0x41,0x44,0x3e,0x3c,0x6d,0x65,0x74
3204 ,0x61,0x20,0x68,0x74,0x74,0x70,0x2d,0x65,0x71,0x75,0x69,0x76,0x3d,0x22,0x63,0x6f
3205 ,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x74,0x79,0x70,0x65,0x22,0x20,0x63,0x6f,0x6e,0x74
3206 ,0x65,0x6e,0x74,0x3d,0x22,0x74,0x65,0x78,0x74,0x2f,0x68,0x74,0x6d,0x6c,0x3b,0x63
3207 ,0x68,0x61,0x72,0x73,0x65,0x74,0x3d,0x75,0x74,0x66,0x2d,0x38,0x22,0x3e,0x0a,0x3c
3208 ,0x54,0x49,0x54,0x4c,0x45,0x3e,0x33,0x30,0x32,0x20,0x4d,0x6f,0x76,0x65,0x64,0x3c
3209 ,0x2f,0x54,0x49,0x54,0x4c,0x45,0x3e,0x3c,0x2f,0x48,0x45,0x41,0x44,0x3e,0x3c,0x42
3210 ,0x4f,0x44,0x59,0x3e,0x0a,0x3c,0x48,0x31,0x3e,0x33,0x30,0x32,0x20,0x4d,0x6f,0x76
3211 ,0x65,0x64,0x3c,0x2f,0x48,0x31,0x3e,0x0a,0x54,0x68,0x65,0x20,0x64,0x6f,0x63,0x75
3212 ,0x6d,0x65,0x6e,0x74,0x20,0x68,0x61,0x73,0x20,0x6d,0x6f,0x76,0x65,0x64,0x0a,0x3c
3213 ,0x41,0x20,0x48,0x52,0x45,0x46,0x3d,0x22,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77
3214 ,0x77,0x77,0x2e,0x67,0x6f,0x6f,0x67,0x6c,0x65,0x2e,0x65,0x73,0x2f,0x22,0x3e,0x68
3215 ,0x65,0x72,0x65,0x3c,0x2f,0x41,0x3e,0x2e,0x0d,0x0a,0x3c,0x2f,0x42,0x4f,0x44,0x59
3216 ,0x3e,0x3c,0x2f,0x48,0x54,0x4d,0x4c,0x3e,0x0d,0x0a };
3241 Signature *s =
de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"SigTest37ContentAndIsdataatKeywords01 \"; content:\"HTTP\"; isdataat:500, relative; sid:101;)");
3243 printf(
"sig parse failed: ");
3249 printf(
"type not content: ");
3260 printf(
"sig matched, but should not have: ");
3295 static int SigTest40NoPacketInspection01(
void)
3298 uint8_t *buf = (uint8_t *)
3299 "220 (vsFTPd 2.0.5)\r\n";
3300 uint16_t buflen = strlen((
char *)buf);
3313 memset(&pq, 0,
sizeof(pq));
3314 memset(&f, 0,
sizeof(f));
3315 memset(&tcphdr, 0,
sizeof(tcphdr));
3328 PacketSetTCP(
p, (uint8_t *)&tcphdr);
3340 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> 1.2.3.4 any (msg:\"No Packet Inspection Test\"; flow:to_server; sid:2; rev:1;)");
3369 static int SigTest40NoPayloadInspection02(
void)
3372 uint8_t *buf = (uint8_t *)
3373 "220 (vsFTPd 2.0.5)\r\n";
3374 uint16_t buflen = strlen((
char *)buf);
3395 "alert tcp any any -> any any (msg:\"No Payload TEST\"; content:\"220 (vsFTPd 2.0.5)\"; sid:1;)");
3412 static int SigTestMemory01 (
void)
3414 uint8_t *buf = (uint8_t *)
3415 "GET /one/ HTTP/1.1\r\n"
3416 "Host: one.example.org\r\n"
3418 "GET /two/ HTTP/1.1\r\n"
3419 "Host: two.example.org\r\n"
3421 uint16_t buflen = strlen((
char *)buf);
3444 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"HTTP URI cap\"; content:\"GET \"; depth:4; pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/\\d\\.\\d\\r\\n/G\"; sid:1;)");
3463 static int SigTestMemory02 (
void)
3477 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any 456 (msg:\"HTTP URI cap\"; content:\"GET \"; depth:4; pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/\\d\\.\\d\\r\\n/G\"; sid:1;)");
3482 de_ctx->
sig_list->
next =
SigInit(
de_ctx,
"alert tcp any any -> any 1:1000 (msg:\"HTTP URI cap\"; content:\"GET \"; depth:4; pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/\\d\\.\\d\\r\\n/G\"; sid:2;)");
3498 static int SigTestMemory03 (
void)
3512 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> 1.2.3.4 456 (msg:\"HTTP URI cap\"; content:\"GET \"; depth:4; pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/\\d\\.\\d\\r\\n/G\"; sid:1;)");
3517 de_ctx->
sig_list->
next =
SigInit(
de_ctx,
"alert tcp any any -> 1.2.3.3-1.2.3.6 1:1000 (msg:\"HTTP URI cap\"; content:\"GET \"; depth:4; pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/\\d\\.\\d\\r\\n/G\"; sid:2;)");
3522 de_ctx->
sig_list->
next->
next =
SigInit(
de_ctx,
"alert tcp any any -> !1.2.3.5 1:990 (msg:\"HTTP URI cap\"; content:\"GET \"; depth:4; pcre:\"/GET (?P<pkt_http_uri>.*) HTTP\\/\\d\\.\\d\\r\\n/G\"; sid:3;)");
3538 static int SigTestContent01 (
void)
3540 uint8_t *buf = (uint8_t *)
"01234567890123456789012345678901";
3541 uint16_t buflen = strlen((
char *)buf);
3558 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"Test 32\"; content:\"01234567890123456789012345678901\"; sid:1;)");
3571 printf(
"sig 1 didn't match: ");
3581 static int SigTestContent02 (
void)
3583 uint8_t *buf = (uint8_t *)
"01234567890123456789012345678901";
3584 uint16_t buflen = strlen((
char *)buf);
3600 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"Test 32\"; content:\"01234567890123456789012345678901\"; sid:1;)");
3620 printf(
"sig 2 didn't match: ");
3623 printf(
"sig 1 didn't match: ");
3633 static int SigTestContent03 (
void)
3635 uint8_t *buf = (uint8_t *)
"01234567890123456789012345678901abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
3636 uint16_t buflen = strlen((
char *)buf);
3653 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"Test 32\"; content:\"01234567890123456789012345678901\"; content:\"abcdefghijklmnopqrstuvwxyzABCDEF\"; distance:0; sid:1;)");
3666 printf(
"sig 1 didn't match: ");
3676 static int SigTestContent04 (
void)
3678 uint8_t *buf = (uint8_t *)
"01234567890123456789012345678901abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
3679 uint16_t buflen = strlen((
char *)buf);
3697 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"Test 32\"; content:\"01234567890123456789012345678901\"; content:\"abcdefghijklmnopqrstuvwxyzABCDEF\"; distance:0; within:32; sid:1;)");
3710 printf(
"sig 1 didn't match: ");
3721 static int SigTestContent05 (
void)
3723 uint8_t *buf = (uint8_t *)
"01234567890123456789012345678901PADabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
3724 uint16_t buflen = strlen((
char *)buf);
3736 printf(
"de_ctx == NULL: ");
3742 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"Test 32\"; content:\"01234567890123456789012345678901\"; content:\"abcdefghijklmnopqrstuvwxyzABCDEF\"; distance:0; within:32; sid:1;)");
3744 printf(
"sig1 parse failed: ");
3747 de_ctx->
sig_list->
next =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"Test 32\"; content:\"01234567890123456789012345678901\"; content:\"abcdefghijklmnopqrstuvwxyzABCDEF\"; distance:1; within:32; sid:2;)");
3749 printf(
"sig2 parse failed: ");
3759 printf(
"sig 1 matched but shouldn't: ");
3764 printf(
"sig 2 matched but shouldn't: ");
3771 if (det_ctx != NULL) {
3781 static int SigTestContent06 (
void)
3783 uint8_t *buf = (uint8_t *)
"01234567890123456789012345678901abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
3784 uint16_t buflen = strlen((
char *)buf);
3801 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert ip any any -> any any (msg:\"Test 32 sig1\"; content:\"01234567890123456789012345678901\"; content:\"abcdefghijklmnopqrstuvwxyzABCDEF\"; distance:0; within:32; sid:1;)");
3806 de_ctx->
sig_list->
next =
SigInit(
de_ctx,
"alert ip any any -> any any (msg:\"Test 32 sig2\"; content:\"01234567890123456789012345678901\"; content:\"abcdefg\"; sid:2;)");
3819 printf(
"sig 1 didn't match: ");
3826 printf(
"sig 2 didn't match: ");
3838 static int SigTestWithin01 (
void)
3842 uint8_t rawpkt1[] = {
3843 0x00,0x04,0x76,0xd3,0xd8,0x6a,0x00,0x24,
3844 0xe8,0x29,0xfa,0x4f,0x08,0x00,0x45,0x00,
3845 0x00,0x8c,0x95,0x50,0x00,0x00,0x40,0x06,
3846 0x2d,0x45,0xc0,0xa8,0x02,0x03,0xd0,0x45,
3847 0x24,0xe6,0x06,0xcc,0x03,0x09,0x18,0x72,
3848 0xd0,0xe3,0x1a,0xab,0x7c,0x98,0x50,0x00,
3849 0x02,0x00,0x46,0xa0,0x00,0x00,0x48,0x69,
3850 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
3851 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
3852 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
3853 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
3854 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
3855 0x74,0x63,0x68,0x65,0x73,0x0a,0x00,0x00,
3856 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3857 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3858 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3859 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3860 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3861 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3864 uint8_t rawpkt2[] = {
3865 0x00,0x04,0x76,0xd3,0xd8,0x6a,0x00,0x24,
3866 0xe8,0x29,0xfa,0x4f,0x08,0x00,0x45,0x00,
3867 0x00,0x8c,0x30,0x87,0x00,0x00,0x40,0x06,
3868 0x92,0x0e,0xc0,0xa8,0x02,0x03,0xd0,0x45,
3869 0x24,0xe6,0x06,0xcd,0x03,0x09,0x73,0xec,
3870 0xd5,0x35,0x14,0x7d,0x7c,0x12,0x50,0x00,
3871 0x02,0x00,0xed,0x86,0x00,0x00,0x48,0x69,
3872 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
3873 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
3874 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
3875 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
3876 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
3877 0x74,0x63,0x68,0x65,0x73,0x0a,0x00,0x00,
3878 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3879 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3880 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3881 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3882 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3883 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3886 uint8_t rawpkt3[] = {
3887 0x00,0x04,0x76,0xd3,0xd8,0x6a,0x00,0x24,
3888 0xe8,0x29,0xfa,0x4f,0x08,0x00,0x45,0x00,
3889 0x00,0x8c,0x57,0xd8,0x00,0x00,0x40,0x06,
3890 0x6a,0xbd,0xc0,0xa8,0x02,0x03,0xd0,0x45,
3891 0x24,0xe6,0x06,0xce,0x03,0x09,0x06,0x3d,
3892 0x02,0x22,0x2f,0x9b,0x6f,0x8f,0x50,0x00,
3893 0x02,0x00,0x1f,0xae,0x00,0x00,0x48,0x69,
3894 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
3895 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
3896 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
3897 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
3898 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
3899 0x74,0x63,0x68,0x65,0x73,0x0a,0x00,0x00,
3900 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3901 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3902 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3903 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3904 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3905 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3908 uint8_t rawpkt4[] = {
3909 0x00,0x04,0x76,0xd3,0xd8,0x6a,0x00,0x24,
3910 0xe8,0x29,0xfa,0x4f,0x08,0x00,0x45,0x00,
3911 0x00,0x8c,0xa7,0x2e,0x00,0x00,0x40,0x06,
3912 0x1b,0x67,0xc0,0xa8,0x02,0x03,0xd0,0x45,
3913 0x24,0xe6,0x06,0xcf,0x03,0x09,0x00,0x0e,
3914 0xdf,0x72,0x3d,0xc2,0x21,0xce,0x50,0x00,
3915 0x02,0x00,0x88,0x25,0x00,0x00,0x48,0x69,
3916 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
3917 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
3918 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
3919 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
3920 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
3921 0x74,0x63,0x68,0x65,0x73,0x0a,0x00,0x00,
3922 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3923 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3924 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3925 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3926 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3927 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
3943 "alert tcp any any -> any any (msg:\"within test\"; content:\"Hi, this is a big test "
3944 "to check \"; content:\"content matches\"; distance:0; within:15; sid:556;)");
3979 uint8_t *p5buf = (uint8_t *)
"Hi, this is a big test to check content matches";
3980 uint16_t p5buflen = strlen((
char *)p5buf);
3999 static int SigTestDepthOffset01 (
void)
4001 uint8_t *buf = (uint8_t *)
"01234567890123456789012345678901abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
4002 uint16_t buflen = strlen((
char *)buf);
4020 de_ctx->
sig_list =
SigInit(
de_ctx,
"alert tcp any any -> any any (msg:\"depth offset\"; content:\"456\"; offset:4; depth:3; sid:1;)");
4041 static int SigTestDetectAlertCounter(
void)
4046 memset(&
tv, 0,
sizeof(
tv));
4054 "content:\"boo\"; sid:1;)");
4076 p =
UTHBuildPacket((uint8_t *)
"laboosa", strlen(
"laboosa"), IPPROTO_TCP);
4089 static int SigTestDropFlow01(
void)
4093 uint8_t http_buf1[] =
"POST /one HTTP/1.0\r\n"
4094 "User-Agent: Mozilla/1.0\r\n"
4095 "Cookie: hellocatch\r\n\r\n";
4096 uint32_t http_buf1_len =
sizeof(http_buf1) - 1;
4106 memset(&f, 0,
sizeof(
Flow));
4113 f.
proto = IPPROTO_TCP;
4129 "(msg:\"Test proto match\"; "
4164 static int SigTestDropFlow02(
void)
4169 uint8_t http_buf1[] =
"POST /one HTTP/1.0\r\n"
4170 "User-Agent: Mozilla/1.0\r\n"
4171 "Cookie: hellocatch\r\n\r\n";
4172 uint32_t http_buf1_len =
sizeof(http_buf1) - 1;
4182 memset(&f, 0,
sizeof(
Flow));
4189 f.
proto = IPPROTO_TCP;
4207 "(msg:\"Test proto match\"; uricontent:\"one\";"
4219 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
4224 if (http_state == NULL) {
4225 printf(
"no http state: ");
4233 printf(
"sig 1 didn't alert, but it should: ");
4238 printf(
"sig 1 alerted but flow was not flagged correctly: ");
4250 if (det_ctx != NULL)
4266 static int SigTestDropFlow03(
void)
4270 uint8_t http_buf1[] =
"POST /one HTTP/1.0\r\n"
4271 "User-Agent: Mozilla/1.0\r\n"
4272 "Cookie: hellocatch\r\n\r\n";
4273 uint32_t http_buf1_len =
sizeof(http_buf1) - 1;
4275 uint8_t http_buf2[] =
"POST /two HTTP/1.0\r\n"
4276 "User-Agent: Mozilla/1.0\r\n"
4277 "Cookie: hellocatch\r\n\r\n";
4278 uint32_t http_buf2_len =
sizeof(http_buf1) - 1;
4292 memset(&f, 0,
sizeof(
Flow));
4300 f.
proto = IPPROTO_TCP;
4321 "(msg:\"Test proto match\"; uricontent:\"one\";"
4328 "(msg:\"Test proto match\"; uricontent:\"two\";"
4350 SCLogDebug(
"This flow/stream triggered a drop rule");
4351 DecodeSetNoPacketInspectionFlag(p2);
4388 static int SigTestPorts01(
void)
4395 uint8_t payload[] =
"AAAAAAAAAAAAAAAAAA";
4409 "(content:\"AAA\"; sid:1;)");
4421 printf(
"sig 1 alerted on p1, but it should not: ");
4427 if (det_ctx != NULL)
4438 static int SigTestBug01(
void)
4442 uint8_t payload[] =
"!mymy";
4452 "(content:\"Omymy\"; nocase; sid:1;)");
4455 "(content:\"!mymy\"; nocase; sid:2;)");
4469 static const char *dummy_conf_string2 =
4474 " address-groups:\n"
4476 " HOME_NET: \"[10.10.10.0/24, !10.10.10.247]\"\n"
4478 " EXTERNAL_NET: \"any\"\n"
4482 " HTTP_PORTS: \"80:81,88\"\n"
4485 static int DetectAddressYamlParsing01 (
void)
4516 static const char *dummy_conf_string3 =
4521 " address-groups:\n"
4523 " HOME_NET: \"[10.10.10.0/24, !10.10.10.247/32]\"\n"
4525 " EXTERNAL_NET: \"any\"\n"
4529 " HTTP_PORTS: \"80:81,88\"\n"
4532 static int DetectAddressYamlParsing02 (
void)
4563 static const char *dummy_conf_string4 =
4568 " address-groups:\n"
4570 " HOME_NET: \"[10.10.10.0/24, !10.10.10.247/32]\"\n"
4572 " EXTERNAL_NET: \"any\"\n"
4576 " HTTP_PORTS: \"80:81,88\"\n"
4579 static int DetectAddressYamlParsing03 (
void)
4597 static const char *dummy_conf_string5 =
4602 " address-groups:\n"
4604 " HOME_NET: \"[10.196.0.0/24, !10.196.0.15]\"\n"
4606 " EXTERNAL_NET: \"any\"\n"
4610 " HTTP_PORTS: \"80:81,88\"\n"
4614 static int DetectAddressYamlParsing04 (
void)
4641 UtRegisterTest(
"SigTest05 -- distance/within mismatch", SigTest05);
4642 UtRegisterTest(
"SigTest06 -- uricontent HTTP/1.1 match test", SigTest06);
4645 UtRegisterTest(
"SigTest08 -- uricontent HTTP/1.0 match test", SigTest08);
4648 UtRegisterTest(
"SigTest10 -- long content match, longer than pkt",
4651 UtRegisterTest(
"SigTest12 -- content order matching, normal", SigTest12);
4652 UtRegisterTest(
"SigTest13 -- content order matching, diff order",
4654 UtRegisterTest(
"SigTest14 -- content order matching, distance 0",
4656 UtRegisterTest(
"SigTest15 -- port negation sig (no match)", SigTest15);
4657 UtRegisterTest(
"SigTest16 -- port negation sig (match)", SigTest16);
4658 UtRegisterTest(
"SigTest17 -- HTTP Host Pkt var capture", SigTest17);
4668 SigTest25NegativeIPV4Keyword);
4672 SigTest26TCPV4AndNegativeIPV4Keyword);
4674 SigTest26TCPV4AndIPV4Keyword);
4676 SigTest27NegativeTCPV4Keyword);
4680 SigTest29NegativeTCPV6Keyword);
4684 SigTest31NegativeUDPV4Keyword);
4688 SigTest33NegativeUDPV6Keyword);
4690 UtRegisterTest(
"SigTest34ICMPV4Keyword", SigTest34ICMPV4Keyword);
4692 SigTest35NegativeICMPV4Keyword);
4694 SigTest36ContentAndIsdataatKeywords01);
4696 SigTest37ContentAndIsdataatKeywords02);
4703 SigTest40NoPacketInspection01);
4705 SigTest40NoPayloadInspection02);
4711 UtRegisterTest(
"SigTestContent01 -- 32 byte pattern", SigTestContent01);
4712 UtRegisterTest(
"SigTestContent02 -- 32+31 byte pattern", SigTestContent02);
4713 UtRegisterTest(
"SigTestContent03 -- 32 byte pattern, x2 + distance",
4715 UtRegisterTest(
"SigTestContent04 -- 32 byte pattern, x2 + distance/within",
4717 UtRegisterTest(
"SigTestContent05 -- distance/within", SigTestContent05);
4724 UtRegisterTest(
"SigTestDetectAlertCounter", SigTestDetectAlertCounter);
4730 UtRegisterTest(
"DetectAddressYamlParsing01", DetectAddressYamlParsing01);
4731 UtRegisterTest(
"DetectAddressYamlParsing02", DetectAddressYamlParsing02);
4732 UtRegisterTest(
"DetectAddressYamlParsing03", DetectAddressYamlParsing03);
4733 UtRegisterTest(
"DetectAddressYamlParsing04", DetectAddressYamlParsing04);