34 #include "../suricata-common.h"
35 #include "../suricata.h"
36 #include "../decode.h"
38 #include "../detect.h"
39 #include "../detect-engine.h"
40 #include "../detect-isdataat.h"
41 #include "../detect-pcre.h"
42 #include "../detect-engine-build.h"
43 #include "../detect-engine-alert.h"
45 #include "../stream-tcp.h"
46 #include "../app-layer.h"
47 #include "../app-layer-htp.h"
48 #include "../app-layer-protos.h"
49 #include "../app-layer-parser.h"
51 #include "../util-unittest.h"
52 #include "../util-unittest-helper.h"
53 #include "../util-validate.h"
62 static int DetectHttpRawHeaderParserTest01(
void)
65 FAIL_IF_NOT(
UTHParseSignature(
"alert http any any -> any any (flow:to_server; content:\"abc\"; nocase; http_raw_header; sid:1;)",
true));
66 FAIL_IF_NOT(
UTHParseSignature(
"alert http any any -> any any (flow:to_server; content:\"abc\"; endswith; http_raw_header; sid:1;)",
true));
67 FAIL_IF_NOT(
UTHParseSignature(
"alert http any any -> any any (flow:to_server; content:\"abc\"; startswith; http_raw_header; sid:1;)",
true));
68 FAIL_IF_NOT(
UTHParseSignature(
"alert http any any -> any any (flow:to_server; content:\"abc\"; startswith; endswith; http_raw_header; sid:1;)",
true));
70 FAIL_IF_NOT(
UTHParseSignature(
"alert http any any -> any any (flow:to_server; content:\"abc\"; rawbytes; http_raw_header; sid:1;)",
false));
79 static int DetectHttpRawHeaderParserTest02(
void)
82 FAIL_IF_NOT(
UTHParseSignature(
"alert http any any -> any any (flow:to_server; http.header.raw; content:\"abc\"; nocase; sid:1;)",
true));
83 FAIL_IF_NOT(
UTHParseSignature(
"alert http any any -> any any (flow:to_server; http.header.raw; content:\"abc\"; endswith; sid:1;)",
true));
84 FAIL_IF_NOT(
UTHParseSignature(
"alert http any any -> any any (flow:to_server; http.header.raw; content:\"abc\"; startswith; sid:1;)",
true));
85 FAIL_IF_NOT(
UTHParseSignature(
"alert http any any -> any any (flow:to_server; http.header.raw; content:\"abc\"; startswith; endswith; sid:1;)",
true));
88 FAIL_IF_NOT(
UTHParseSignature(
"alert http any any -> any any (flow:to_server; http.header.raw; content:\"abc\"; rawbytes; sid:1;)",
false));
98 static int DetectEngineHttpRawHeaderTest01(
void)
108 "GET /index.html HTTP/1.0\r\n"
109 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
110 uint32_t http_len =
sizeof(http_buf) - 1;
114 memset(&th_v, 0,
sizeof(th_v));
115 memset(&f, 0,
sizeof(f));
116 memset(&ssn, 0,
sizeof(ssn));
122 f.
proto = IPPROTO_TCP;
139 "(msg:\"http header test\"; flow:to_server; "
140 "content:\"one\"; http_raw_header; "
151 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
157 if (http_state == NULL) {
158 printf(
"no http state: ");
167 printf(
"sid 1 didn't match but should have: ");
188 static int DetectEngineHttpRawHeaderTest02(
void)
198 "GET /index.html HTTP/1.0\r\n"
199 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
200 uint32_t http_len =
sizeof(http_buf) - 1;
204 memset(&th_v, 0,
sizeof(th_v));
205 memset(&f, 0,
sizeof(f));
206 memset(&ssn, 0,
sizeof(ssn));
212 f.
proto = IPPROTO_TCP;
229 "(msg:\"http header test\"; flow:to_server; "
230 "content:\"one\"; depth:15; http_raw_header; "
241 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
247 if (http_state == NULL) {
248 printf(
"no http state: ");
257 printf(
"sid 1 didn't match but should have: ");
278 static int DetectEngineHttpRawHeaderTest03(
void)
288 "GET /index.html HTTP/1.0\r\n"
289 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
290 uint32_t http_len =
sizeof(http_buf) - 1;
294 memset(&th_v, 0,
sizeof(th_v));
295 memset(&f, 0,
sizeof(f));
296 memset(&ssn, 0,
sizeof(ssn));
302 f.
proto = IPPROTO_TCP;
319 "(msg:\"http header test\"; flow:to_server; "
320 "content:!\"one\"; depth:5; http_raw_header; "
331 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
337 if (http_state == NULL) {
338 printf(
"no http state: ");
347 printf(
"sid 1 didn't match but should have: ");
368 static int DetectEngineHttpRawHeaderTest04(
void)
378 "GET /index.html HTTP/1.0\r\n"
379 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
380 uint32_t http_len =
sizeof(http_buf) - 1;
384 memset(&th_v, 0,
sizeof(th_v));
385 memset(&f, 0,
sizeof(f));
386 memset(&ssn, 0,
sizeof(ssn));
392 f.
proto = IPPROTO_TCP;
409 "(msg:\"http header test\"; flow:to_server; "
410 "content:\"one\"; depth:5; http_raw_header; "
421 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
427 if (http_state == NULL) {
428 printf(
"no http state: ");
437 printf(
"sid 1 matched but shouldn't have: ");
458 static int DetectEngineHttpRawHeaderTest05(
void)
468 "GET /index.html HTTP/1.0\r\n"
469 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
470 uint32_t http_len =
sizeof(http_buf) - 1;
474 memset(&th_v, 0,
sizeof(th_v));
475 memset(&f, 0,
sizeof(f));
476 memset(&ssn, 0,
sizeof(ssn));
482 f.
proto = IPPROTO_TCP;
499 "(msg:\"http header test\"; flow:to_server; "
500 "content:!\"one\"; depth:15; http_raw_header; "
511 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
517 if (http_state == NULL) {
518 printf(
"no http state: ");
527 printf(
"sid 1 matched but shouldn't have: ");
548 static int DetectEngineHttpRawHeaderTest06(
void)
558 "GET /index.html HTTP/1.0\r\n"
559 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
560 uint32_t http_len =
sizeof(http_buf) - 1;
564 memset(&th_v, 0,
sizeof(th_v));
565 memset(&f, 0,
sizeof(f));
566 memset(&ssn, 0,
sizeof(ssn));
572 f.
proto = IPPROTO_TCP;
589 "(msg:\"http header test\"; flow:to_server; "
590 "content:\"one\"; offset:10; http_raw_header; "
601 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
607 if (http_state == NULL) {
608 printf(
"no http state: ");
617 printf(
"sid 1 didn't match but should have: ");
638 static int DetectEngineHttpRawHeaderTest07(
void)
648 "GET /index.html HTTP/1.0\r\n"
649 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
650 uint32_t http_len =
sizeof(http_buf) - 1;
654 memset(&th_v, 0,
sizeof(th_v));
655 memset(&f, 0,
sizeof(f));
656 memset(&ssn, 0,
sizeof(ssn));
662 f.
proto = IPPROTO_TCP;
679 "(msg:\"http header test\"; flow:to_server; "
680 "content:!\"one\"; offset:15; http_raw_header; "
691 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
697 if (http_state == NULL) {
698 printf(
"no http state: ");
707 printf(
"sid 1 didn't match but should have: ");
728 static int DetectEngineHttpRawHeaderTest08(
void)
738 "GET /index.html HTTP/1.0\r\n"
739 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
740 uint32_t http_len =
sizeof(http_buf) - 1;
744 memset(&th_v, 0,
sizeof(th_v));
745 memset(&f, 0,
sizeof(f));
746 memset(&ssn, 0,
sizeof(ssn));
752 f.
proto = IPPROTO_TCP;
769 "(msg:\"http header test\"; flow:to_server; "
770 "content:\"one\"; offset:15; http_raw_header; "
781 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
787 if (http_state == NULL) {
788 printf(
"no http state: ");
797 printf(
"sid 1 matched but shouldn't have: ");
818 static int DetectEngineHttpRawHeaderTest09(
void)
828 "GET /index.html HTTP/1.0\r\n"
829 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
830 uint32_t http_len =
sizeof(http_buf) - 1;
834 memset(&th_v, 0,
sizeof(th_v));
835 memset(&f, 0,
sizeof(f));
836 memset(&ssn, 0,
sizeof(ssn));
842 f.
proto = IPPROTO_TCP;
859 "(msg:\"http header test\"; flow:to_server; "
860 "content:!\"one\"; offset:10; http_raw_header; "
871 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
877 if (http_state == NULL) {
878 printf(
"no http state: ");
887 printf(
"sid 1 matched but shouldn't have: ");
908 static int DetectEngineHttpRawHeaderTest10(
void)
918 "GET /index.html HTTP/1.0\r\n"
919 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
920 uint32_t http_len =
sizeof(http_buf) - 1;
924 memset(&th_v, 0,
sizeof(th_v));
925 memset(&f, 0,
sizeof(f));
926 memset(&ssn, 0,
sizeof(ssn));
932 f.
proto = IPPROTO_TCP;
949 "(msg:\"http header test\"; flow:to_server; "
950 "content:\"one\"; http_raw_header; content:\"three\"; http_raw_header; within:10; "
961 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
967 if (http_state == NULL) {
968 printf(
"no http state: ");
977 printf(
"sid 1 didn't match but should have: ");
998 static int DetectEngineHttpRawHeaderTest11(
void)
1007 uint8_t http_buf[] =
1008 "GET /index.html HTTP/1.0\r\n"
1009 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1010 uint32_t http_len =
sizeof(http_buf) - 1;
1014 memset(&th_v, 0,
sizeof(th_v));
1015 memset(&f, 0,
sizeof(f));
1016 memset(&ssn, 0,
sizeof(ssn));
1022 f.
proto = IPPROTO_TCP;
1039 "(msg:\"http header test\"; flow:to_server; "
1040 "content:\"one\"; http_raw_header; content:!\"three\"; http_raw_header; within:5; "
1051 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1057 if (http_state == NULL) {
1058 printf(
"no http state: ");
1067 printf(
"sid 1 didn't match but should have: ");
1088 static int DetectEngineHttpRawHeaderTest12(
void)
1097 uint8_t http_buf[] =
1098 "GET /index.html HTTP/1.0\r\n"
1099 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1100 uint32_t http_len =
sizeof(http_buf) - 1;
1104 memset(&th_v, 0,
sizeof(th_v));
1105 memset(&f, 0,
sizeof(f));
1106 memset(&ssn, 0,
sizeof(ssn));
1112 f.
proto = IPPROTO_TCP;
1129 "(msg:\"http header test\"; flow:to_server; "
1130 "content:\"one\"; http_raw_header; content:!\"three\"; http_raw_header; within:10; "
1141 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1147 if (http_state == NULL) {
1148 printf(
"no http state: ");
1157 printf(
"sid 1 matched but shouldn't have: ");
1178 static int DetectEngineHttpRawHeaderTest13(
void)
1187 uint8_t http_buf[] =
1188 "GET /index.html HTTP/1.0\r\n"
1189 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1190 uint32_t http_len =
sizeof(http_buf) - 1;
1194 memset(&th_v, 0,
sizeof(th_v));
1195 memset(&f, 0,
sizeof(f));
1196 memset(&ssn, 0,
sizeof(ssn));
1202 f.
proto = IPPROTO_TCP;
1219 "(msg:\"http header test\"; flow:to_server; "
1220 "content:\"one\"; http_raw_header; content:\"three\"; http_raw_header; within:5; "
1231 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1237 if (http_state == NULL) {
1238 printf(
"no http state: ");
1247 printf(
"sid 1 matched but shouldn't have: ");
1268 static int DetectEngineHttpRawHeaderTest14(
void)
1277 uint8_t http_buf[] =
1278 "GET /index.html HTTP/1.0\r\n"
1279 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1280 uint32_t http_len =
sizeof(http_buf) - 1;
1284 memset(&th_v, 0,
sizeof(th_v));
1285 memset(&f, 0,
sizeof(f));
1286 memset(&ssn, 0,
sizeof(ssn));
1292 f.
proto = IPPROTO_TCP;
1309 "(msg:\"http header test\"; flow:to_server; "
1310 "content:\"one\"; http_raw_header; content:\"five\"; http_raw_header; distance:7; "
1321 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1327 if (http_state == NULL) {
1328 printf(
"no http state: ");
1337 printf(
"sid 1 didn't match but should have: ");
1358 static int DetectEngineHttpRawHeaderTest15(
void)
1367 uint8_t http_buf[] =
1368 "GET /index.html HTTP/1.0\r\n"
1369 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1370 uint32_t http_len =
sizeof(http_buf) - 1;
1374 memset(&th_v, 0,
sizeof(th_v));
1375 memset(&f, 0,
sizeof(f));
1376 memset(&ssn, 0,
sizeof(ssn));
1382 f.
proto = IPPROTO_TCP;
1399 "(msg:\"http header test\"; flow:to_server; "
1400 "content:\"one\"; http_raw_header; content:!\"five\"; http_raw_header; distance:15; "
1411 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1417 if (http_state == NULL) {
1418 printf(
"no http state: ");
1427 printf(
"sid 1 didn't match but should have: ");
1448 static int DetectEngineHttpRawHeaderTest16(
void)
1457 uint8_t http_buf[] =
1458 "GET /index.html HTTP/1.0\r\n"
1459 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1460 uint32_t http_len =
sizeof(http_buf) - 1;
1464 memset(&th_v, 0,
sizeof(th_v));
1465 memset(&f, 0,
sizeof(f));
1466 memset(&ssn, 0,
sizeof(ssn));
1472 f.
proto = IPPROTO_TCP;
1489 "(msg:\"http header test\"; flow:to_server; "
1490 "content:\"one\"; http_raw_header; content:!\"five\"; http_raw_header; distance:7; "
1501 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1507 if (http_state == NULL) {
1508 printf(
"no http state: ");
1517 printf(
"sid 1 matched but shouldn't have: ");
1538 static int DetectEngineHttpRawHeaderTest17(
void)
1547 uint8_t http_buf[] =
1548 "GET /index.html HTTP/1.0\r\n"
1549 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1550 uint32_t http_len =
sizeof(http_buf) - 1;
1554 memset(&th_v, 0,
sizeof(th_v));
1555 memset(&f, 0,
sizeof(f));
1556 memset(&ssn, 0,
sizeof(ssn));
1562 f.
proto = IPPROTO_TCP;
1579 "(msg:\"http header test\"; flow:to_server; "
1580 "content:\"one\"; http_raw_header; content:\"five\"; http_raw_header; distance:15; "
1591 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1597 if (http_state == NULL) {
1598 printf(
"no http state: ");
1607 printf(
"sid 1 matched but shouldn't have: ");
1624 static int DetectEngineHttpRawHeaderTest20(
void)
1630 uint8_t http1_buf[] =
1631 "GET /index.html HTTP/1.0\r\n"
1632 "Host: This_is_dummy_body1";
1633 uint8_t http2_buf[] =
1634 "This_is_dummy_message_body2\r\n"
1636 uint32_t http1_len =
sizeof(http1_buf) - 1;
1637 uint32_t http2_len =
sizeof(http2_buf) - 1;
1641 memset(&th_v, 0,
sizeof(th_v));
1642 memset(&f, 0,
sizeof(f));
1643 memset(&ssn, 0,
sizeof(ssn));
1652 f.
proto = IPPROTO_TCP;
1672 "(flow:to_server; pcre:/body1/D; "
1673 "content:!\"dummy\"; http_raw_header; within:7; "
1712 static int DetectEngineHttpRawHeaderTest21(
void)
1722 uint8_t http1_buf[] =
1723 "GET /index.html HTTP/1.0\r\n"
1724 "Host: This_is_dummy_body1";
1725 uint8_t http2_buf[] =
1726 "This_is_dummy_message_body2\r\n"
1728 uint32_t http1_len =
sizeof(http1_buf) - 1;
1729 uint32_t http2_len =
sizeof(http2_buf) - 1;
1733 memset(&th_v, 0,
sizeof(th_v));
1734 memset(&f, 0,
sizeof(f));
1735 memset(&ssn, 0,
sizeof(ssn));
1742 f.
proto = IPPROTO_TCP;
1764 "(msg:\"http client body test\"; flow:to_server; "
1766 "content:!\"dummy\"; within:7; http_raw_header; "
1777 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1783 if (http_state == NULL) {
1784 printf(
"no http state: \n");
1793 printf(
"sid 1 matched but shouldn't have\n");
1800 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
1809 printf(
"sid 1 didn't match but shouldn't have");
1828 static int DetectEngineHttpRawHeaderTest22(
void)
1838 uint8_t http1_buf[] =
1839 "GET /index.html HTTP/1.0\r\n"
1840 "Host: This_is_dummy_body1";
1841 uint8_t http2_buf[] =
1842 "This_is_dummy_message_body2\r\n"
1844 uint32_t http1_len =
sizeof(http1_buf) - 1;
1845 uint32_t http2_len =
sizeof(http2_buf) - 1;
1849 memset(&th_v, 0,
sizeof(th_v));
1850 memset(&f, 0,
sizeof(f));
1851 memset(&ssn, 0,
sizeof(ssn));
1858 f.
proto = IPPROTO_TCP;
1880 "(msg:\"http client body test\"; flow:to_server; "
1882 "content:!\"dummy\"; distance:3; http_raw_header; "
1893 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1899 if (http_state == NULL) {
1900 printf(
"no http state: \n");
1909 printf(
"sid 1 matched but shouldn't have\n");
1916 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
1925 printf(
"sid 1 matched but shouldn't have");
1944 static int DetectEngineHttpRawHeaderTest23(
void)
1954 uint8_t http1_buf[] =
1955 "GET /index.html HTTP/1.0\r\n"
1956 "Host: This_is_dummy_body1";
1957 uint8_t http2_buf[] =
1958 "This_is_dummy_message_body2\r\n"
1960 uint32_t http1_len =
sizeof(http1_buf) - 1;
1961 uint32_t http2_len =
sizeof(http2_buf) - 1;
1965 memset(&th_v, 0,
sizeof(th_v));
1966 memset(&f, 0,
sizeof(f));
1967 memset(&ssn, 0,
sizeof(ssn));
1974 f.
proto = IPPROTO_TCP;
1996 "(msg:\"http client body test\"; flow:to_server; "
1998 "content:!\"dummy\"; distance:13; http_raw_header; "
2009 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2015 if (http_state == NULL) {
2016 printf(
"no http state: \n");
2025 printf(
"sid 1 matched but shouldn't have\n");
2032 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
2041 printf(
"sid 1 didn't match but should have");
2060 static int DetectEngineHttpRawHeaderTest24(
void)
2070 uint8_t http1_buf[] =
2071 "GET /index.html HTTP/1.0\r\n"
2072 "Host: This_is_dummy_body1";
2073 uint8_t http2_buf[] =
2074 "This_is_dummy_message_body2\r\n"
2076 uint32_t http1_len =
sizeof(http1_buf) - 1;
2077 uint32_t http2_len =
sizeof(http2_buf) - 1;
2081 memset(&th_v, 0,
sizeof(th_v));
2082 memset(&f, 0,
sizeof(f));
2083 memset(&ssn, 0,
sizeof(ssn));
2090 f.
proto = IPPROTO_TCP;
2112 "(msg:\"http client body test\"; flow:to_server; "
2114 "content:\"dummy\"; within:15; http_raw_header; "
2125 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2131 if (http_state == NULL) {
2132 printf(
"no http state: \n");
2141 printf(
"sid 1 matched but shouldn't have\n");
2148 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
2157 printf(
"sid 1 didn't match but should have");
2176 static int DetectEngineHttpRawHeaderTest25(
void)
2186 uint8_t http1_buf[] =
2187 "GET /index.html HTTP/1.0\r\n"
2188 "Host: This_is_dummy_body1";
2189 uint8_t http2_buf[] =
2190 "This_is_dummy_message_body2\r\n"
2192 uint32_t http1_len =
sizeof(http1_buf) - 1;
2193 uint32_t http2_len =
sizeof(http2_buf) - 1;
2197 memset(&th_v, 0,
sizeof(th_v));
2198 memset(&f, 0,
sizeof(f));
2199 memset(&ssn, 0,
sizeof(ssn));
2206 f.
proto = IPPROTO_TCP;
2228 "(msg:\"http client body test\"; flow:to_server; "
2230 "content:\"dummy\"; within:10; http_raw_header; "
2241 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2247 if (http_state == NULL) {
2248 printf(
"no http state: \n");
2257 printf(
"sid 1 matched but shouldn't have\n");
2264 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
2273 printf(
"sid 1 matched but shouldn't have");
2292 static int DetectEngineHttpRawHeaderTest26(
void)
2302 uint8_t http1_buf[] =
2303 "GET /index.html HTTP/1.0\r\n"
2304 "Host: This_is_dummy_body1";
2305 uint8_t http2_buf[] =
2306 "This_is_dummy_message_body2\r\n"
2308 uint32_t http1_len =
sizeof(http1_buf) - 1;
2309 uint32_t http2_len =
sizeof(http2_buf) - 1;
2313 memset(&th_v, 0,
sizeof(th_v));
2314 memset(&f, 0,
sizeof(f));
2315 memset(&ssn, 0,
sizeof(ssn));
2322 f.
proto = IPPROTO_TCP;
2344 "(msg:\"http client body test\"; flow:to_server; "
2346 "content:\"dummy\"; distance:8; http_raw_header; "
2357 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2363 if (http_state == NULL) {
2364 printf(
"no http state: \n");
2373 printf(
"sid 1 matched but shouldn't have\n");
2380 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
2389 printf(
"sid 1 didn't match but should have");
2406 static int DetectEngineHttpRawHeaderTest27(
void)
2416 uint8_t http1_buf[] =
2417 "GET /index.html HTTP/1.0\r\n"
2418 "Host: This_is_dummy_body1";
2419 uint8_t http2_buf[] =
2420 "This_is_dummy_message_body2\r\n"
2422 uint32_t http1_len =
sizeof(http1_buf) - 1;
2423 uint32_t http2_len =
sizeof(http2_buf) - 1;
2427 memset(&th_v, 0,
sizeof(th_v));
2428 memset(&f, 0,
sizeof(f));
2429 memset(&ssn, 0,
sizeof(ssn));
2436 f.
proto = IPPROTO_TCP;
2458 "(msg:\"http client body test\"; flow:to_server; "
2460 "content:\"dummy\"; distance:14; http_raw_header; "
2471 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2477 if (http_state == NULL) {
2478 printf(
"no http state: \n");
2487 printf(
"sid 1 matched but shouldn't have\n");
2494 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
2503 printf(
"sid 1 matched but shouldn't have");
2522 static int DetectEngineHttpRawHeaderTest28(
void)
2532 uint8_t http_buf1[] =
2533 "GET /index.html HTTP/1.0\r\n"
2534 "Host: www.openinfosecfoundation.org\r\n"
2535 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
2537 uint32_t http_buf1_len =
sizeof(http_buf1) - 1;
2538 uint8_t http_buf2[] =
2539 "HTTP/1.0 200 ok\r\n"
2540 "Content-Type: text/html\r\n"
2541 "Content-Length: 6\r\n"
2544 uint32_t http_buf2_len =
sizeof(http_buf2) - 1;
2548 memset(&th_v, 0,
sizeof(th_v));
2549 memset(&f, 0,
sizeof(f));
2550 memset(&ssn, 0,
sizeof(ssn));
2557 f.
proto = IPPROTO_TCP;
2579 "(msg:\"http header test\"; flow:to_client; "
2580 "content:\"Content-Length: 6\"; http_raw_header; "
2591 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2597 if (http_state == NULL) {
2598 printf(
"no http state: \n");
2607 printf(
"sid 1 matched but shouldn't have\n");
2614 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
2623 printf(
"sid 1 didn't match but should have");
2642 static int DetectEngineHttpRawHeaderTest29(
void)
2652 uint8_t http_buf1[] =
2653 "GET /index.html HTTP/1.0\r\n"
2654 "Host: www.openinfosecfoundation.org\r\n"
2655 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
2657 uint32_t http_buf1_len =
sizeof(http_buf1) - 1;
2658 uint8_t http_buf2[] =
2659 "HTTP/1.0 200 ok\r\n"
2660 "Content-Type: text/html\r\n"
2661 "Content-Length: 6\r\n"
2664 uint32_t http_buf2_len =
sizeof(http_buf2) - 1;
2668 memset(&th_v, 0,
sizeof(th_v));
2669 memset(&f, 0,
sizeof(f));
2670 memset(&ssn, 0,
sizeof(ssn));
2677 f.
proto = IPPROTO_TCP;
2699 "(msg:\"http header test\"; flow:to_client; "
2700 "content:\"Content-Length: 7\"; http_raw_header; "
2711 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2717 if (http_state == NULL) {
2718 printf(
"no http state: \n");
2727 printf(
"sid 1 matched but shouldn't have\n");
2734 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
2743 printf(
"sid 1 matched but shouldn't have");
2764 static int DetectEngineHttpRawHeaderTest30(
void)
2774 "(msg:\"http header test\"; "
2775 "content:\"Content-Length: 6\"; http_raw_header; "
2776 "content:\"User-Agent: Mozilla\"; http_raw_header; "
2797 static int DetectEngineHttpRawHeaderTest31(
void)
2806 uint8_t http1_buf[] =
2807 "GET /index.html HTTP/1.0\r\n"
2809 "Transfer-Encoding: chunked\r\n"
2812 "This is dummy body1\r\n"
2814 "Dummy-Header: kaboom\r\n"
2816 uint32_t http1_len =
sizeof(http1_buf) - 1;
2820 memset(&th_v, 0,
sizeof(th_v));
2821 memset(&f, 0,
sizeof(f));
2822 memset(&ssn, 0,
sizeof(ssn));
2828 f.
proto = IPPROTO_TCP;
2847 "content:\"Dummy\"; http_raw_header; "
2858 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2864 if (http_state == NULL) {
2865 printf(
"no http state: \n");
2874 printf(
"sid 1 didn't match but should have: ");
2895 static int DetectEngineHttpRawHeaderTest32(
void)
2905 uint8_t http1_buf[] =
2906 "GET /index.html HTTP/1.0\r\n"
2908 "Transfer-Encoding: chunked\r\n"
2911 "This is dummy body1\r\n"
2913 uint8_t http2_buf[] =
2914 "Dummy-Header: kaboom\r\n"
2916 uint32_t http1_len =
sizeof(http1_buf) - 1;
2917 uint32_t http2_len =
sizeof(http2_buf) - 1;
2921 memset(&th_v, 0,
sizeof(th_v));
2922 memset(&f, 0,
sizeof(f));
2923 memset(&ssn, 0,
sizeof(ssn));
2930 f.
proto = IPPROTO_TCP;
2953 "content:\"Dummy\"; http_raw_header; "
2964 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2970 if (http_state == NULL) {
2971 printf(
"no http state: \n");
2980 printf(
"sid 1 matched but shouldn't have\n");
2987 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
2996 printf(
"sid 1 didn't match but should have\n");
3019 static int DetectHttpRawHeaderTest06(
void)
3028 uint8_t http_buf[] =
3029 "GET /index.html HTTP/1.0\r\n"
3030 "Host: www.openinfosecfoundation.org\r\n"
3031 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
3032 "Content-Type: text/html\r\n"
3033 "Content-Length: 26\r\n"
3035 "This is dummy message body\r\n";
3036 uint32_t http_len =
sizeof(http_buf) - 1;
3040 memset(&th_v, 0,
sizeof(th_v));
3041 memset(&f, 0,
sizeof(f));
3042 memset(&ssn, 0,
sizeof(ssn));
3048 f.
proto = IPPROTO_TCP;
3065 "(msg:\"http header test\"; flow:to_server; "
3066 "content:\"Content-Type: text/html\"; http_raw_header; "
3077 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3083 if (http_state == NULL) {
3084 printf(
"no http state: ");
3093 printf(
"sid 1 didn't match but should have: ");
3114 static int DetectHttpRawHeaderTest07(
void)
3124 uint8_t http1_buf[] =
3125 "GET /index.html HTTP/1.0\r\n"
3126 "Host: www.openinfosecfoundation.org\r\n"
3128 uint8_t http2_buf[] =
3129 "lla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\nContent-Type: text/html\r\n"
3130 "Content-Length: 67\r\n"
3132 "This is dummy message body1";
3133 uint32_t http1_len =
sizeof(http1_buf) - 1;
3134 uint32_t http2_len =
sizeof(http2_buf) - 1;
3138 memset(&th_v, 0,
sizeof(th_v));
3139 memset(&f, 0,
sizeof(f));
3140 memset(&ssn, 0,
sizeof(ssn));
3147 f.
proto = IPPROTO_TCP;
3168 "(msg:\"http header test\"; flow:to_server; "
3169 "content:\"Mozilla\"; http_raw_header; "
3180 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3186 if (http_state == NULL) {
3187 printf(
"no http state: ");
3196 printf(
"sid 1 matched but shouldn't have: ");
3203 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3212 printf(
"sid 1 didn't match but should have: ");
3234 static int DetectHttpRawHeaderTest08(
void)
3244 uint8_t http1_buf[] =
3245 "GET /index.html HTTP/1.0\r\n"
3246 "Host: www.openinfosecfoundation.org\r\n";
3247 uint8_t http2_buf[] =
3248 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
3249 "Content-Type: text/html\r\n"
3250 "Content-Length: 67\r\n"
3252 uint32_t http1_len =
sizeof(http1_buf) - 1;
3253 uint32_t http2_len =
sizeof(http2_buf) - 1;
3257 memset(&th_v, 0,
sizeof(th_v));
3258 memset(&f, 0,
sizeof(f));
3259 memset(&ssn, 0,
sizeof(ssn));
3266 f.
proto = IPPROTO_TCP;
3287 "(msg:\"http header test\"; flow:to_server; "
3288 "content:\"Gecko/20091221 Firefox/3.5.7\"; http_raw_header; "
3299 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3305 if (http_state == NULL) {
3306 printf(
"no http state: ");
3315 printf(
"sid 1 didn't match but should have: ");
3322 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3331 printf(
"sid 1 didn't match but should have: ");
3353 static int DetectHttpRawHeaderTest09(
void)
3363 uint8_t http1_buf[] =
3364 "GET /index.html HTTP/1.0\r\n"
3365 "Host: www.openinfosecfoundation.org\r\n"
3366 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n";
3367 uint8_t http2_buf[] =
3368 "Content-Type: text/html\r\n"
3369 "Content-Length: 67\r\n"
3371 "This is dummy body\r\n";
3372 uint32_t http1_len =
sizeof(http1_buf) - 1;
3373 uint32_t http2_len =
sizeof(http2_buf) - 1;
3377 memset(&th_v, 0,
sizeof(th_v));
3378 memset(&f, 0,
sizeof(f));
3379 memset(&ssn, 0,
sizeof(ssn));
3386 f.
proto = IPPROTO_TCP;
3407 "(msg:\"http header test\"; flow:to_server; "
3408 "content:\"Firefox/3.5.7|0D 0A|Content\"; http_raw_header; "
3419 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3425 if (http_state == NULL) {
3426 printf(
"no http state: ");
3435 printf(
"sid 1 didn't match but should have: ");
3442 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3451 printf(
"sid 1 didn't match but should have: ");
3473 static int DetectHttpRawHeaderTest10(
void)
3483 uint8_t http1_buf[] =
3484 "GET /index.html HTTP/1.0\r\n"
3485 "Host: www.openinfosecfoundation.org\r\n"
3486 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n";
3487 uint8_t http2_buf[] =
3488 "Content-Type: text/html\r\n"
3489 "Content-Length: 67\r\n"
3491 "This is dummy body";
3492 uint32_t http1_len =
sizeof(http1_buf) - 1;
3493 uint32_t http2_len =
sizeof(http2_buf) - 1;
3497 memset(&th_v, 0,
sizeof(th_v));
3498 memset(&f, 0,
sizeof(f));
3499 memset(&ssn, 0,
sizeof(ssn));
3506 f.
proto = IPPROTO_TCP;
3527 "(msg:\"http header test\"; flow:to_server; "
3528 "content:\"firefox/3.5.7|0D 0A|content\"; nocase; http_raw_header;"
3539 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3545 if (http_state == NULL) {
3546 printf(
"no http state: ");
3555 printf(
"sid 1 didn't match but should have: ");
3562 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3571 printf(
"sid 1 didn't match but should have: ");
3593 static int DetectHttpRawHeaderTest11(
void)
3602 uint8_t http_buf[] =
3603 "GET /index.html HTTP/1.0\r\n"
3604 "Host: www.openinfosecfoundation.org\r\n"
3605 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
3606 "Content-Type: text/html\r\n"
3607 "Content-Length: 26\r\n"
3609 "This is dummy message body\r\n";
3610 uint32_t http_len =
sizeof(http_buf) - 1;
3614 memset(&th_v, 0,
sizeof(th_v));
3615 memset(&f, 0,
sizeof(f));
3616 memset(&ssn, 0,
sizeof(ssn));
3622 f.
proto = IPPROTO_TCP;
3639 "(msg:\"http header test\"; flow:to_server; "
3640 "content:!\"lalalalala\"; http_raw_header; "
3651 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3657 if (http_state == NULL) {
3658 printf(
"no http state: ");
3667 printf(
"sid 1 didn't match but should have: ");
3688 static int DetectHttpRawHeaderTest12(
void)
3697 uint8_t http_buf[] =
3698 "GET /index.html HTTP/1.0\r\n"
3699 "Host: www.openinfosecfoundation.org\r\n"
3700 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
3701 "Content-Type: text/html\r\n"
3702 "Content-Length: 26\r\n"
3704 "This is dummy message body\r\n";
3705 uint32_t http_len =
sizeof(http_buf) - 1;
3709 memset(&th_v, 0,
sizeof(th_v));
3710 memset(&f, 0,
sizeof(f));
3711 memset(&ssn, 0,
sizeof(ssn));
3717 f.
proto = IPPROTO_TCP;
3734 "(msg:\"http header test\"; flow:to_server; "
3735 "content:!\"User-Agent: Mozilla/5.0 \"; http_raw_header; "
3746 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3752 if (http_state == NULL) {
3753 printf(
"no http state: ");
3762 printf(
"sid 1 didn't match but should have: ");
3783 static int DetectHttpRawHeaderTest13(
void)
3792 uint8_t http_buf[] =
3793 "GET /index.html HTTP/1.0\r\n"
3794 "Host: www.openinfosecfoundation.org\r\n"
3795 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
3796 "Content-Type: text/html\r\n"
3797 "Content-Length: 100\r\n"
3799 "longbufferabcdefghijklmnopqrstuvwxyz0123456789bufferend\r\n";
3800 uint32_t http_len =
sizeof(http_buf) - 1;
3804 memset(&th_v, 0,
sizeof(th_v));
3805 memset(&f, 0,
sizeof(f));
3806 memset(&ssn, 0,
sizeof(ssn));
3812 f.
proto = IPPROTO_TCP;
3830 "(msg:\"http header test\"; flow:to_server; "
3831 "content:\"Host: www.openinfosecfoundation.org\"; http_raw_header; "
3842 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3848 if (http_state == NULL) {
3849 printf(
"no http state: ");
3858 printf(
"sid 1 didn't match but should have: ");
3879 DetectHttpRawHeaderParserTest01);
3881 DetectHttpRawHeaderParserTest02);
3884 DetectEngineHttpRawHeaderTest01);
3886 DetectEngineHttpRawHeaderTest02);
3888 DetectEngineHttpRawHeaderTest03);
3890 DetectEngineHttpRawHeaderTest04);
3892 DetectEngineHttpRawHeaderTest05);
3894 DetectEngineHttpRawHeaderTest06);
3896 DetectEngineHttpRawHeaderTest07);
3898 DetectEngineHttpRawHeaderTest08);
3900 DetectEngineHttpRawHeaderTest09);
3902 DetectEngineHttpRawHeaderTest10);
3904 DetectEngineHttpRawHeaderTest11);
3906 DetectEngineHttpRawHeaderTest12);
3908 DetectEngineHttpRawHeaderTest13);
3910 DetectEngineHttpRawHeaderTest14);
3912 DetectEngineHttpRawHeaderTest15);
3914 DetectEngineHttpRawHeaderTest16);
3916 DetectEngineHttpRawHeaderTest17);
3918 DetectEngineHttpRawHeaderTest20);
3920 DetectEngineHttpRawHeaderTest21);
3922 DetectEngineHttpRawHeaderTest22);
3924 DetectEngineHttpRawHeaderTest23);
3926 DetectEngineHttpRawHeaderTest24);
3928 DetectEngineHttpRawHeaderTest25);
3930 DetectEngineHttpRawHeaderTest26);
3932 DetectEngineHttpRawHeaderTest27);
3934 DetectEngineHttpRawHeaderTest28);
3936 DetectEngineHttpRawHeaderTest29);
3939 DetectEngineHttpRawHeaderTest30, 1);
3942 DetectEngineHttpRawHeaderTest31);
3944 DetectEngineHttpRawHeaderTest32);
3946 UtRegisterTest(
"DetectHttpRawHeaderTest06", DetectHttpRawHeaderTest06);
3947 UtRegisterTest(
"DetectHttpRawHeaderTest07", DetectHttpRawHeaderTest07);
3948 UtRegisterTest(
"DetectHttpRawHeaderTest08", DetectHttpRawHeaderTest08);
3949 UtRegisterTest(
"DetectHttpRawHeaderTest09", DetectHttpRawHeaderTest09);
3950 UtRegisterTest(
"DetectHttpRawHeaderTest10", DetectHttpRawHeaderTest10);
3951 UtRegisterTest(
"DetectHttpRawHeaderTest11", DetectHttpRawHeaderTest11);
3952 UtRegisterTest(
"DetectHttpRawHeaderTest12", DetectHttpRawHeaderTest12);
3953 UtRegisterTest(
"DetectHttpRawHeaderTest13", DetectHttpRawHeaderTest13);