33 #include "../suricata-common.h"
35 #include "../flow-var.h"
36 #include "../flow-util.h"
38 #include "../app-layer.h"
39 #include "../app-layer-parser.h"
41 #include "../app-layer-htp.h"
42 #include "../detect-http-header.h"
43 #include "../detect-http-header-common.h"
44 #include "../detect-engine-build.h"
45 #include "../detect-engine-alert.h"
47 #include "../detect-isdataat.h"
49 #include "../stream-tcp.h"
51 #include "../util-unittest.h"
52 #include "../util-unittest-helper.h"
57 static int DetectHttpHeaderParserTest01(
void)
74 static int DetectHttpHeaderParserTest02(
void)
93 static int DetectHttpHeaderTest06(
void)
103 "GET /index.html HTTP/1.0\r\n"
104 "Host: www.openinfosecfoundation.org\r\n"
105 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
106 "Content-Type: text/html\r\n"
107 "Content-Length: 26\r\n"
109 "This is dummy message body\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\"; "
140 "content:\"Content-Type: text/html\"; http_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 DetectHttpHeaderTest07(
void)
196 uint8_t http1_buf[] =
197 "GET /index.html HTTP/1.0\r\n"
198 "Host: www.openinfosecfoundation.org\r\n"
200 uint8_t http2_buf[] =
201 "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"
202 "Content-Length: 67\r\n"
204 "This is dummy message body1";
205 uint32_t http1_len =
sizeof(http1_buf) - 1;
206 uint32_t http2_len =
sizeof(http2_buf) - 1;
211 memset(&th_v, 0,
sizeof(th_v));
212 memset(&f, 0,
sizeof(f));
213 memset(&ssn, 0,
sizeof(ssn));
222 f.
proto = IPPROTO_TCP;
241 "(msg:\"http header test\"; "
242 "content:\"Mozilla\"; http_header; "
284 static int DetectHttpHeaderTest08(
void)
294 uint8_t http1_buf[] =
295 "GET /index.html HTTP/1.0\r\n"
296 "Host: www.openinfosecfoundation.org\r\n";
297 uint8_t http2_buf[] =
298 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
299 "Content-Type: text/html\r\n"
300 "Content-Length: 67\r\n"
302 uint32_t http1_len =
sizeof(http1_buf) - 1;
303 uint32_t http2_len =
sizeof(http2_buf) - 1;
307 memset(&th_v, 0,
sizeof(th_v));
308 memset(&f, 0,
sizeof(f));
309 memset(&ssn, 0,
sizeof(ssn));
316 f.
proto = IPPROTO_TCP;
337 "(msg:\"http header test\"; "
338 "content:\"Gecko/20091221 Firefox/3.5.7\"; http_header; "
349 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
355 if (http_state == NULL) {
356 printf(
"no http state: ");
365 printf(
"sid 1 didn't match but should have: ");
372 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
381 printf(
"sid 1 didn't match but should have: ");
403 static int DetectHttpHeaderTest09(
void)
413 uint8_t http1_buf[] =
414 "GET /index.html HTTP/1.0\r\n"
415 "Host: www.openinfosecfoundation.org\r\n"
416 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n";
417 uint8_t http2_buf[] =
418 "Content-Type: text/html\r\n"
419 "Content-Length: 67\r\n"
421 "This is dummy body\r\n";
422 uint32_t http1_len =
sizeof(http1_buf) - 1;
423 uint32_t http2_len =
sizeof(http2_buf) - 1;
427 memset(&th_v, 0,
sizeof(th_v));
428 memset(&f, 0,
sizeof(f));
429 memset(&ssn, 0,
sizeof(ssn));
436 f.
proto = IPPROTO_TCP;
458 "(msg:\"http header test\"; "
459 "content:\"Firefox/3.5.7|0D 0A|Content\"; http_header; "
470 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
476 if (http_state == NULL) {
477 printf(
"no http state: ");
486 printf(
"sid 1 matched but shouldn't have: ");
493 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
502 printf(
"sid 1 didn't match but should have: ");
524 static int DetectHttpHeaderTest10(
void)
534 uint8_t http1_buf[] =
535 "GET /index.html HTTP/1.0\r\n"
536 "Host: www.openinfosecfoundation.org\r\n"
537 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n";
538 uint8_t http2_buf[] =
539 "Content-Type: text/html\r\n"
540 "Content-Length: 67\r\n"
542 "This is dummy body";
543 uint32_t http1_len =
sizeof(http1_buf) - 1;
544 uint32_t http2_len =
sizeof(http2_buf) - 1;
548 memset(&th_v, 0,
sizeof(th_v));
549 memset(&f, 0,
sizeof(f));
550 memset(&ssn, 0,
sizeof(ssn));
557 f.
proto = IPPROTO_TCP;
578 "(msg:\"http header test\"; "
579 "content:\"firefox/3.5.7|0D 0A|content\"; nocase; http_header;"
590 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
596 if (http_state == NULL) {
597 printf(
"no http state: ");
606 printf(
"sid 1 didn't match but should have: ");
613 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
622 printf(
"sid 1 didn't match but should have: ");
644 static int DetectHttpHeaderTest11(
void)
654 "GET /index.html HTTP/1.0\r\n"
655 "Host: www.openinfosecfoundation.org\r\n"
656 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
657 "Content-Type: text/html\r\n"
658 "Content-Length: 26\r\n"
660 "This is dummy message body\r\n";
661 uint32_t http_len =
sizeof(http_buf) - 1;
665 memset(&th_v, 0,
sizeof(th_v));
666 memset(&f, 0,
sizeof(f));
667 memset(&ssn, 0,
sizeof(ssn));
673 f.
proto = IPPROTO_TCP;
690 "(msg:\"http header test\"; "
691 "content:!\"lalalalala\"; http_header; "
702 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
708 if (http_state == NULL) {
709 printf(
"no http state: ");
718 printf(
"sid 1 didn't match but should have: ");
739 static int DetectHttpHeaderTest12(
void)
749 "GET /index.html HTTP/1.0\r\n"
750 "Host: www.openinfosecfoundation.org\r\n"
751 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
752 "Content-Type: text/html\r\n"
753 "Content-Length: 26\r\n"
755 "This is dummy message body\r\n";
756 uint32_t http_len =
sizeof(http_buf) - 1;
760 memset(&th_v, 0,
sizeof(th_v));
761 memset(&f, 0,
sizeof(f));
762 memset(&ssn, 0,
sizeof(ssn));
768 f.
proto = IPPROTO_TCP;
785 "(msg:\"http header test\"; "
786 "content:!\"User-Agent: Mozilla/5.0 \"; http_header; "
797 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
803 if (http_state == NULL) {
804 printf(
"no http state: ");
813 printf(
"sid 1 didn't match but should have: ");
834 static int DetectHttpHeaderTest13(
void)
844 "GET /index.html HTTP/1.0\r\n"
845 "Host: www.openinfosecfoundation.org\r\n"
846 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
847 "Content-Type: text/html\r\n"
848 "Content-Length: 100\r\n"
850 "longbufferabcdefghijklmnopqrstuvwxyz0123456789bufferend\r\n";
851 uint32_t http_len =
sizeof(http_buf) - 1;
855 memset(&th_v, 0,
sizeof(th_v));
856 memset(&f, 0,
sizeof(f));
857 memset(&ssn, 0,
sizeof(ssn));
863 f.
proto = IPPROTO_TCP;
881 "(msg:\"http header test\"; "
882 "content:\"Host: www.openinfosecfoundation.org\"; http_header; "
893 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
899 if (http_state == NULL) {
900 printf(
"no http state: ");
909 printf(
"sid 1 didn't match but should have: ");
928 static int DetectHttpHeaderTest28(
void)
937 "POST http://xxx.intranet.local:8000/xxx HTTP/1.1\r\n"
938 "User-Agent: Mozilla/4.0 (Windows XP 5.1) Java/1.6.0_29\r\n"
939 "Host: xxx.intranet.local:8000\r\n"
941 uint32_t http_len =
sizeof(http_buf) - 1;
945 memset(&th_v, 0,
sizeof(th_v));
946 memset(&f, 0,
sizeof(f));
947 memset(&ssn, 0,
sizeof(ssn));
953 f.
proto = IPPROTO_TCP;
970 "(app-layer-event:http.host_header_ambiguous; "
981 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
990 printf(
"sid 1 matched but shouldnt have: ");
1009 static int DetectHttpHeaderTest29(
void)
1017 uint8_t http_buf[] =
1018 "POST http://xxx.intranet.local:8001/xxx HTTP/1.1\r\n"
1019 "User-Agent: Mozilla/4.0 (Windows XP 5.1) Java/1.6.0_29\r\n"
1020 "Host: xxx.intranet.local:8000\r\n"
1022 uint32_t http_len =
sizeof(http_buf) - 1;
1026 memset(&th_v, 0,
sizeof(th_v));
1027 memset(&f, 0,
sizeof(f));
1028 memset(&ssn, 0,
sizeof(ssn));
1034 f.
proto = IPPROTO_TCP;
1051 "(app-layer-event:http.host_header_ambiguous; "
1062 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1071 printf(
"sid 1 didn't match but should have: ");
1090 static int DetectHttpHeaderTest30(
void)
1098 uint8_t http_buf[] =
1099 "POST http://xxx.intranet.local:8000/xxx HTTP/1.1\r\n"
1100 "User-Agent: Mozilla/4.0 (Windows XP 5.1) Java/1.6.0_29\r\n"
1101 "Host: xyz.intranet.local:8000\r\n"
1103 uint32_t http_len =
sizeof(http_buf) - 1;
1107 memset(&th_v, 0,
sizeof(th_v));
1108 memset(&f, 0,
sizeof(f));
1109 memset(&ssn, 0,
sizeof(ssn));
1115 f.
proto = IPPROTO_TCP;
1132 "(app-layer-event:http.host_header_ambiguous; "
1143 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1152 printf(
"sid 1 didn't match but should have: ");
1169 static int DetectHttpHeaderIsdataatParseTest(
void)
1176 "alert tcp any any -> any any ("
1178 "content:\"one\"; http_header; "
1179 "isdataat:!4,relative; sid:1;)");
1199 static int DetectEngineHttpHeaderTest01(
void)
1208 uint8_t http_buf[] =
1209 "GET /index.html HTTP/1.0\r\n"
1210 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1211 uint32_t http_len =
sizeof(http_buf) - 1;
1215 memset(&th_v, 0,
sizeof(th_v));
1216 memset(&f, 0,
sizeof(f));
1217 memset(&ssn, 0,
sizeof(ssn));
1223 f.
proto = IPPROTO_TCP;
1240 "(msg:\"http header test\"; "
1241 "content:\"one\"; http_header; "
1252 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1258 if (http_state == NULL) {
1259 printf(
"no http state: ");
1268 printf(
"sid 1 didn't match but should have: ");
1289 static int DetectEngineHttpHeaderTest02(
void)
1298 uint8_t http_buf[] =
1299 "GET /index.html HTTP/1.0\r\n"
1300 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1301 uint32_t http_len =
sizeof(http_buf) - 1;
1305 memset(&th_v, 0,
sizeof(th_v));
1306 memset(&f, 0,
sizeof(f));
1307 memset(&ssn, 0,
sizeof(ssn));
1313 f.
proto = IPPROTO_TCP;
1330 "(msg:\"http header test\"; "
1331 "content:\"one\"; depth:15; http_header; "
1342 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1348 if (http_state == NULL) {
1349 printf(
"no http state: ");
1358 printf(
"sid 1 didn't match but should have: ");
1379 static int DetectEngineHttpHeaderTest03(
void)
1388 uint8_t http_buf[] =
1389 "GET /index.html HTTP/1.0\r\n"
1390 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1391 uint32_t http_len =
sizeof(http_buf) - 1;
1395 memset(&th_v, 0,
sizeof(th_v));
1396 memset(&f, 0,
sizeof(f));
1397 memset(&ssn, 0,
sizeof(ssn));
1403 f.
proto = IPPROTO_TCP;
1420 "(msg:\"http header test\"; "
1421 "content:!\"one\"; depth:5; http_header; "
1432 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1438 if (http_state == NULL) {
1439 printf(
"no http state: ");
1448 printf(
"sid 1 didn't match but should have: ");
1469 static int DetectEngineHttpHeaderTest04(
void)
1478 uint8_t http_buf[] =
1479 "GET /index.html HTTP/1.0\r\n"
1480 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1481 uint32_t http_len =
sizeof(http_buf) - 1;
1485 memset(&th_v, 0,
sizeof(th_v));
1486 memset(&f, 0,
sizeof(f));
1487 memset(&ssn, 0,
sizeof(ssn));
1493 f.
proto = IPPROTO_TCP;
1510 "(msg:\"http header test\"; "
1511 "content:\"one\"; depth:5; http_header; "
1522 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1528 if (http_state == NULL) {
1529 printf(
"no http state: ");
1538 printf(
"sid 1 matched but shouldn't have: ");
1559 static int DetectEngineHttpHeaderTest05(
void)
1568 uint8_t http_buf[] =
1569 "GET /index.html HTTP/1.0\r\n"
1570 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1571 uint32_t http_len =
sizeof(http_buf) - 1;
1575 memset(&th_v, 0,
sizeof(th_v));
1576 memset(&f, 0,
sizeof(f));
1577 memset(&ssn, 0,
sizeof(ssn));
1583 f.
proto = IPPROTO_TCP;
1600 "(msg:\"http header test\"; "
1601 "content:!\"one\"; depth:15; http_header; "
1612 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1618 if (http_state == NULL) {
1619 printf(
"no http state: ");
1628 printf(
"sid 1 matched but shouldn't have: ");
1649 static int DetectEngineHttpHeaderTest06(
void)
1658 uint8_t http_buf[] =
1659 "GET /index.html HTTP/1.0\r\n"
1660 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1661 uint32_t http_len =
sizeof(http_buf) - 1;
1665 memset(&th_v, 0,
sizeof(th_v));
1666 memset(&f, 0,
sizeof(f));
1667 memset(&ssn, 0,
sizeof(ssn));
1673 f.
proto = IPPROTO_TCP;
1690 "(msg:\"http header test\"; "
1691 "content:\"one\"; offset:10; http_header; "
1702 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1708 if (http_state == NULL) {
1709 printf(
"no http state: ");
1718 printf(
"sid 1 didn't match but should have: ");
1739 static int DetectEngineHttpHeaderTest07(
void)
1748 uint8_t http_buf[] =
1749 "GET /index.html HTTP/1.0\r\n"
1750 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1751 uint32_t http_len =
sizeof(http_buf) - 1;
1755 memset(&th_v, 0,
sizeof(th_v));
1756 memset(&f, 0,
sizeof(f));
1757 memset(&ssn, 0,
sizeof(ssn));
1763 f.
proto = IPPROTO_TCP;
1780 "(msg:\"http header test\"; "
1781 "content:!\"one\"; offset:15; http_header; "
1792 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1798 if (http_state == NULL) {
1799 printf(
"no http state: ");
1808 printf(
"sid 1 didn't match but should have: ");
1829 static int DetectEngineHttpHeaderTest08(
void)
1838 uint8_t http_buf[] =
1839 "GET /index.html HTTP/1.0\r\n"
1840 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1841 uint32_t http_len =
sizeof(http_buf) - 1;
1845 memset(&th_v, 0,
sizeof(th_v));
1846 memset(&f, 0,
sizeof(f));
1847 memset(&ssn, 0,
sizeof(ssn));
1853 f.
proto = IPPROTO_TCP;
1870 "(msg:\"http header test\"; "
1871 "content:\"one\"; offset:15; http_header; "
1882 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1888 if (http_state == NULL) {
1889 printf(
"no http state: ");
1898 printf(
"sid 1 matched but shouldn't have: ");
1919 static int DetectEngineHttpHeaderTest09(
void)
1928 uint8_t http_buf[] =
1929 "GET /index.html HTTP/1.0\r\n"
1930 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
1931 uint32_t http_len =
sizeof(http_buf) - 1;
1935 memset(&th_v, 0,
sizeof(th_v));
1936 memset(&f, 0,
sizeof(f));
1937 memset(&ssn, 0,
sizeof(ssn));
1943 f.
proto = IPPROTO_TCP;
1960 "(msg:\"http header test\"; "
1961 "content:!\"one\"; offset:10; http_header; "
1972 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
1978 if (http_state == NULL) {
1979 printf(
"no http state: ");
1988 printf(
"sid 1 matched but shouldn't have: ");
2009 static int DetectEngineHttpHeaderTest10(
void)
2018 uint8_t http_buf[] =
2019 "GET /index.html HTTP/1.0\r\n"
2020 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
2021 uint32_t http_len =
sizeof(http_buf) - 1;
2025 memset(&th_v, 0,
sizeof(th_v));
2026 memset(&f, 0,
sizeof(f));
2027 memset(&ssn, 0,
sizeof(ssn));
2033 f.
proto = IPPROTO_TCP;
2050 "(msg:\"http header test\"; "
2051 "content:\"one\"; http_header; content:\"three\"; http_header; within:10; "
2062 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2068 if (http_state == NULL) {
2069 printf(
"no http state: ");
2078 printf(
"sid 1 didn't match but should have: ");
2099 static int DetectEngineHttpHeaderTest11(
void)
2108 uint8_t http_buf[] =
2109 "GET /index.html HTTP/1.0\r\n"
2110 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
2111 uint32_t http_len =
sizeof(http_buf) - 1;
2115 memset(&th_v, 0,
sizeof(th_v));
2116 memset(&f, 0,
sizeof(f));
2117 memset(&ssn, 0,
sizeof(ssn));
2123 f.
proto = IPPROTO_TCP;
2140 "(msg:\"http header test\"; "
2141 "content:\"one\"; http_header; content:!\"three\"; http_header; within:5; "
2152 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2158 if (http_state == NULL) {
2159 printf(
"no http state: ");
2168 printf(
"sid 1 didn't match but should have: ");
2189 static int DetectEngineHttpHeaderTest12(
void)
2198 uint8_t http_buf[] =
2199 "GET /index.html HTTP/1.0\r\n"
2200 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
2201 uint32_t http_len =
sizeof(http_buf) - 1;
2205 memset(&th_v, 0,
sizeof(th_v));
2206 memset(&f, 0,
sizeof(f));
2207 memset(&ssn, 0,
sizeof(ssn));
2213 f.
proto = IPPROTO_TCP;
2230 "(msg:\"http header test\"; "
2231 "content:\"one\"; http_header; content:!\"three\"; http_header; within:10; "
2242 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2248 if (http_state == NULL) {
2249 printf(
"no http state: ");
2258 printf(
"sid 1 matched but shouldn't have: ");
2279 static int DetectEngineHttpHeaderTest13(
void)
2288 uint8_t http_buf[] =
2289 "GET /index.html HTTP/1.0\r\n"
2290 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
2291 uint32_t http_len =
sizeof(http_buf) - 1;
2295 memset(&th_v, 0,
sizeof(th_v));
2296 memset(&f, 0,
sizeof(f));
2297 memset(&ssn, 0,
sizeof(ssn));
2303 f.
proto = IPPROTO_TCP;
2320 "(msg:\"http header test\"; "
2321 "content:\"one\"; http_header; content:\"three\"; http_header; within:5; "
2332 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2338 if (http_state == NULL) {
2339 printf(
"no http state: ");
2348 printf(
"sid 1 matched but shouldn't have: ");
2369 static int DetectEngineHttpHeaderTest14(
void)
2378 uint8_t http_buf[] =
2379 "GET /index.html HTTP/1.0\r\n"
2380 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
2381 uint32_t http_len =
sizeof(http_buf) - 1;
2385 memset(&th_v, 0,
sizeof(th_v));
2386 memset(&f, 0,
sizeof(f));
2387 memset(&ssn, 0,
sizeof(ssn));
2393 f.
proto = IPPROTO_TCP;
2410 "(msg:\"http header test\"; "
2411 "content:\"one\"; http_header; content:\"five\"; http_header; distance:7; "
2422 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2428 if (http_state == NULL) {
2429 printf(
"no http state: ");
2438 printf(
"sid 1 didn't match but should have: ");
2459 static int DetectEngineHttpHeaderTest15(
void)
2468 uint8_t http_buf[] =
2469 "GET /index.html HTTP/1.0\r\n"
2470 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
2471 uint32_t http_len =
sizeof(http_buf) - 1;
2475 memset(&th_v, 0,
sizeof(th_v));
2476 memset(&f, 0,
sizeof(f));
2477 memset(&ssn, 0,
sizeof(ssn));
2483 f.
proto = IPPROTO_TCP;
2500 "(msg:\"http header test\"; "
2501 "content:\"one\"; http_header; content:!\"five\"; http_header; distance:15; "
2512 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2518 if (http_state == NULL) {
2519 printf(
"no http state: ");
2528 printf(
"sid 1 didn't match but should have: ");
2549 static int DetectEngineHttpHeaderTest16(
void)
2558 uint8_t http_buf[] =
2559 "GET /index.html HTTP/1.0\r\n"
2560 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
2561 uint32_t http_len =
sizeof(http_buf) - 1;
2565 memset(&th_v, 0,
sizeof(th_v));
2566 memset(&f, 0,
sizeof(f));
2567 memset(&ssn, 0,
sizeof(ssn));
2573 f.
proto = IPPROTO_TCP;
2590 "(msg:\"http header test\"; "
2591 "content:\"one\"; http_header; content:!\"five\"; http_header; distance:7; "
2602 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2608 if (http_state == NULL) {
2609 printf(
"no http state: ");
2618 printf(
"sid 1 matched but shouldn't have: ");
2639 static int DetectEngineHttpHeaderTest17(
void)
2648 uint8_t http_buf[] =
2649 "GET /index.html HTTP/1.0\r\n"
2650 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n";
2651 uint32_t http_len =
sizeof(http_buf) - 1;
2655 memset(&th_v, 0,
sizeof(th_v));
2656 memset(&f, 0,
sizeof(f));
2657 memset(&ssn, 0,
sizeof(ssn));
2663 f.
proto = IPPROTO_TCP;
2680 "(msg:\"http header test\"; "
2681 "content:\"one\"; http_header; content:\"five\"; http_header; distance:15; "
2692 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2698 if (http_state == NULL) {
2699 printf(
"no http state: ");
2708 printf(
"sid 1 matched but shouldn't have: ");
2725 static int DetectEngineHttpHeaderTest20(
void)
2735 uint8_t http1_buf[] =
2736 "GET /index.html HTTP/1.0\r\n"
2737 "Host: This_is_dummy_body1";
2738 uint8_t http2_buf[] =
2739 "This_is_dummy_message_body2\r\n"
2741 uint32_t http1_len =
sizeof(http1_buf) - 1;
2742 uint32_t http2_len =
sizeof(http2_buf) - 1;
2746 memset(&th_v, 0,
sizeof(th_v));
2747 memset(&f, 0,
sizeof(f));
2748 memset(&ssn, 0,
sizeof(ssn));
2755 f.
proto = IPPROTO_TCP;
2777 "(msg:\"http client body test\"; "
2779 "content:!\"dummy\"; http_header; within:7; "
2790 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2796 if (http_state == NULL) {
2797 printf(
"no http state: \n");
2806 printf(
"sid 1 matched but shouldn't have\n");
2813 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
2822 printf(
"sid 1 didn't match but shouldn't have");
2841 static int DetectEngineHttpHeaderTest21(
void)
2851 uint8_t http1_buf[] =
2852 "GET /index.html HTTP/1.0\r\n"
2853 "Host: This_is_dummy_body1";
2854 uint8_t http2_buf[] =
2855 "This_is_dummy_message_body2\r\n"
2857 uint32_t http1_len =
sizeof(http1_buf) - 1;
2858 uint32_t http2_len =
sizeof(http2_buf) - 1;
2862 memset(&th_v, 0,
sizeof(th_v));
2863 memset(&f, 0,
sizeof(f));
2864 memset(&ssn, 0,
sizeof(ssn));
2871 f.
proto = IPPROTO_TCP;
2893 "(msg:\"http client body test\"; "
2895 "content:!\"dummy\"; within:7; http_header; "
2906 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
2912 if (http_state == NULL) {
2913 printf(
"no http state: \n");
2922 printf(
"sid 1 matched but shouldn't have\n");
2929 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
2938 printf(
"sid 1 didn't match but shouldn't have");
2957 static int DetectEngineHttpHeaderTest22(
void)
2967 uint8_t http1_buf[] =
2968 "GET /index.html HTTP/1.0\r\n"
2969 "Host: This_is_dummy_body1";
2970 uint8_t http2_buf[] =
2971 "This_is_dummy_message_body2\r\n"
2973 uint32_t http1_len =
sizeof(http1_buf) - 1;
2974 uint32_t http2_len =
sizeof(http2_buf) - 1;
2978 memset(&th_v, 0,
sizeof(th_v));
2979 memset(&f, 0,
sizeof(f));
2980 memset(&ssn, 0,
sizeof(ssn));
2987 f.
proto = IPPROTO_TCP;
3009 "(msg:\"http client body test\"; "
3011 "content:!\"dummy\"; distance:3; http_header; "
3022 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3028 if (http_state == NULL) {
3029 printf(
"no http state: \n");
3038 printf(
"sid 1 matched but shouldn't have\n");
3045 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
3054 printf(
"sid 1 matched but shouldn't have");
3073 static int DetectEngineHttpHeaderTest23(
void)
3083 uint8_t http1_buf[] =
3084 "GET /index.html HTTP/1.0\r\n"
3085 "Host: This_is_dummy_body1";
3086 uint8_t http2_buf[] =
3087 "This_is_dummy_message_body2\r\n"
3089 uint32_t http1_len =
sizeof(http1_buf) - 1;
3090 uint32_t http2_len =
sizeof(http2_buf) - 1;
3094 memset(&th_v, 0,
sizeof(th_v));
3095 memset(&f, 0,
sizeof(f));
3096 memset(&ssn, 0,
sizeof(ssn));
3103 f.
proto = IPPROTO_TCP;
3125 "(msg:\"http client body test\"; "
3127 "content:!\"dummy\"; distance:13; http_header; "
3138 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3144 if (http_state == NULL) {
3145 printf(
"no http state: \n");
3154 printf(
"sid 1 matched but shouldn't have\n");
3161 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
3170 printf(
"sid 1 didn't match but should have");
3189 static int DetectEngineHttpHeaderTest24(
void)
3199 uint8_t http1_buf[] =
3200 "GET /index.html HTTP/1.0\r\n"
3201 "Host: This_is_dummy_body1";
3202 uint8_t http2_buf[] =
3203 "This_is_dummy_message_body2\r\n"
3205 uint32_t http1_len =
sizeof(http1_buf) - 1;
3206 uint32_t http2_len =
sizeof(http2_buf) - 1;
3210 memset(&th_v, 0,
sizeof(th_v));
3211 memset(&f, 0,
sizeof(f));
3212 memset(&ssn, 0,
sizeof(ssn));
3219 f.
proto = IPPROTO_TCP;
3241 "(msg:\"http client body test\"; "
3243 "content:\"dummy\"; within:15; http_header; "
3254 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3260 if (http_state == NULL) {
3261 printf(
"no http state: \n");
3270 printf(
"sid 1 matched but shouldn't have\n");
3277 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
3286 printf(
"sid 1 didn't match but should have");
3305 static int DetectEngineHttpHeaderTest25(
void)
3315 uint8_t http1_buf[] =
3316 "GET /index.html HTTP/1.0\r\n"
3317 "Host: This_is_dummy_body1";
3318 uint8_t http2_buf[] =
3319 "This_is_dummy_message_body2\r\n"
3321 uint32_t http1_len =
sizeof(http1_buf) - 1;
3322 uint32_t http2_len =
sizeof(http2_buf) - 1;
3326 memset(&th_v, 0,
sizeof(th_v));
3327 memset(&f, 0,
sizeof(f));
3328 memset(&ssn, 0,
sizeof(ssn));
3335 f.
proto = IPPROTO_TCP;
3357 "(msg:\"http client body test\"; "
3359 "content:\"dummy\"; within:10; http_header; "
3370 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3376 if (http_state == NULL) {
3377 printf(
"no http state: \n");
3386 printf(
"sid 1 matched but shouldn't have\n");
3393 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
3402 printf(
"sid 1 matched but shouldn't have");
3421 static int DetectEngineHttpHeaderTest26(
void)
3431 uint8_t http1_buf[] =
3432 "GET /index.html HTTP/1.0\r\n"
3433 "Host: This_is_dummy_body1";
3434 uint8_t http2_buf[] =
3435 "This_is_dummy_message_body2\r\n"
3437 uint32_t http1_len =
sizeof(http1_buf) - 1;
3438 uint32_t http2_len =
sizeof(http2_buf) - 1;
3442 memset(&th_v, 0,
sizeof(th_v));
3443 memset(&f, 0,
sizeof(f));
3444 memset(&ssn, 0,
sizeof(ssn));
3451 f.
proto = IPPROTO_TCP;
3473 "(msg:\"http client body test\"; "
3475 "content:\"dummy\"; distance:8; http_header; "
3486 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3492 if (http_state == NULL) {
3493 printf(
"no http state: \n");
3502 printf(
"sid 1 matched but shouldn't have\n");
3509 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
3518 printf(
"sid 1 didn't match but should have");
3537 static int DetectEngineHttpHeaderTest27(
void)
3547 uint8_t http1_buf[] =
3548 "GET /index.html HTTP/1.0\r\n"
3549 "Host: This_is_dummy_body1";
3550 uint8_t http2_buf[] =
3551 "This_is_dummy_message_body2\r\n"
3553 uint32_t http1_len =
sizeof(http1_buf) - 1;
3554 uint32_t http2_len =
sizeof(http2_buf) - 1;
3558 memset(&th_v, 0,
sizeof(th_v));
3559 memset(&f, 0,
sizeof(f));
3560 memset(&ssn, 0,
sizeof(ssn));
3567 f.
proto = IPPROTO_TCP;
3589 "(msg:\"http client body test\"; "
3591 "content:\"dummy\"; distance:14; http_header; "
3602 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3608 if (http_state == NULL) {
3609 printf(
"no http state: \n");
3618 printf(
"sid 1 matched but shouldn't have\n");
3625 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
3634 printf(
"sid 1 matched but shouldn't have");
3653 static int DetectEngineHttpHeaderTest28(
void)
3663 uint8_t http_buf1[] =
3664 "GET /index.html HTTP/1.0\r\n"
3665 "Host: www.openinfosecfoundation.org\r\n"
3666 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
3668 uint32_t http_buf1_len =
sizeof(http_buf1) - 1;
3669 uint8_t http_buf2[] =
3670 "HTTP/1.0 200 ok\r\n"
3671 "Content-Type: text/html\r\n"
3672 "Content-Length: 6\r\n"
3675 uint32_t http_buf2_len =
sizeof(http_buf2) - 1;
3679 memset(&th_v, 0,
sizeof(th_v));
3680 memset(&f, 0,
sizeof(f));
3681 memset(&ssn, 0,
sizeof(ssn));
3688 f.
proto = IPPROTO_TCP;
3710 "(msg:\"http header test\"; "
3711 "content:\"Content-Length: 6\"; http_header; "
3722 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3728 if (http_state == NULL) {
3729 printf(
"no http state: \n");
3738 printf(
"sid 1 matched but shouldn't have\n");
3745 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
3770 static int DetectEngineHttpHeaderTest29(
void)
3780 uint8_t http_buf1[] =
3781 "GET /index.html HTTP/1.0\r\n"
3782 "Host: www.openinfosecfoundation.org\r\n"
3783 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
3785 uint32_t http_buf1_len =
sizeof(http_buf1) - 1;
3786 uint8_t http_buf2[] =
3787 "HTTP/1.0 200 ok\r\n"
3788 "Content-Type: text/html\r\n"
3789 "Content-Length: 6\r\n"
3792 uint32_t http_buf2_len =
sizeof(http_buf2) - 1;
3796 memset(&th_v, 0,
sizeof(th_v));
3797 memset(&f, 0,
sizeof(f));
3798 memset(&ssn, 0,
sizeof(ssn));
3805 f.
proto = IPPROTO_TCP;
3827 "(msg:\"http header test\"; "
3828 "content:\"Content-Length: 7\"; http_header; "
3839 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3845 if (http_state == NULL) {
3846 printf(
"no http state: \n");
3855 printf(
"sid 1 matched but shouldn't have\n");
3862 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
3871 printf(
"sid 1 matched but shouldn't have");
3892 static int DetectEngineHttpHeaderTest30(
void)
3902 "(msg:\"http header test\"; "
3903 "content:\"Content-Length: 6\"; http_header; "
3904 "content:\"User-Agent: Mozilla\"; http_header; "
3920 static int DetectEngineHttpHeaderTest30(
void)
3930 uint8_t http_buf1[] =
3931 "GET /index.html HTTP/1.0\r\n"
3932 "Host: www.openinfosecfoundation.org\r\n"
3933 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
3935 uint32_t http_buf1_len =
sizeof(http_buf1) - 1;
3936 uint8_t http_buf2[] =
3937 "HTTP/1.0 200 ok\r\n"
3938 "Set-Cookie: dummycookieset\r\n"
3939 "Content-Type: text/html\r\n"
3940 "Content-Length: 6\r\n"
3943 uint32_t http_buf2_len =
sizeof(http_buf2) - 1;
3947 memset(&th_v, 0,
sizeof(th_v));
3948 memset(&f, 0,
sizeof(f));
3949 memset(&ssn, 0,
sizeof(ssn));
3956 f.
proto = IPPROTO_TCP;
3978 "(msg:\"http header test\"; "
3979 "content:\"dummycookieset\"; http_header; "
3990 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
3996 if (http_state == NULL) {
3997 printf(
"no http state: \n");
4006 printf(
"sid 1 matched but shouldn't have\n");
4013 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: \n", r);
4022 printf(
"sid 1 matched but shouldn't have\n");
4044 static int DetectEngineHttpHeaderTest31(
void)
4053 uint8_t http1_buf[] =
4054 "GET /index.html HTTP/1.0\r\n"
4058 "SixZix: blah\r\n\r\n";
4059 uint32_t http1_len =
sizeof(http1_buf) - 1;
4063 memset(&th_v, 0,
sizeof(th_v));
4064 memset(&f, 0,
sizeof(f));
4065 memset(&ssn, 0,
sizeof(ssn));
4071 f.
proto = IPPROTO_TCP;
4089 "(content:\"Accept|3a|\"; http_header; "
4090 "content:!\"Cookie|3a|\"; http_header; "
4091 "content:\"Crazy6|3a|\"; http_header; "
4092 "content:\"SixZix|3a|\"; http_header; "
4103 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
4109 if (http_state == NULL) {
4110 printf(
"no http state: \n");
4119 printf(
"sid 1 didn't match but should have: ");
4140 static int DetectEngineHttpHeaderTest32(
void)
4149 uint8_t http1_buf[] =
4150 "GET /index.html HTTP/1.0\r\n"
4152 "Transfer-Encoding: chunked\r\n"
4155 "This is dummy body1\r\n"
4157 "Dummy-Header: kaboom\r\n"
4159 uint32_t http1_len =
sizeof(http1_buf) - 1;
4163 memset(&th_v, 0,
sizeof(th_v));
4164 memset(&f, 0,
sizeof(f));
4165 memset(&ssn, 0,
sizeof(ssn));
4171 f.
proto = IPPROTO_TCP;
4189 "(content:\"Dummy\"; http_header; "
4200 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
4206 if (http_state == NULL) {
4207 printf(
"no http state: \n");
4216 printf(
"sid 1 didn't match but should have: ");
4237 static int DetectEngineHttpHeaderTest33(
void)
4247 uint8_t http1_buf[] =
4248 "GET /index.html HTTP/1.0\r\n"
4250 "Transfer-Encoding: chunked\r\n"
4253 "This is dummy body1\r\n"
4255 uint8_t http2_buf[] =
4256 "Dummy-Header: kaboom\r\n"
4258 uint32_t http1_len =
sizeof(http1_buf) - 1;
4259 uint32_t http2_len =
sizeof(http2_buf) - 1;
4264 memset(&th_v, 0,
sizeof(th_v));
4265 memset(&f, 0,
sizeof(f));
4266 memset(&ssn, 0,
sizeof(ssn));
4273 f.
proto = IPPROTO_TCP;
4293 "(content:\"Dummy\"; http_header; "
4334 static int DetectEngineHttpHeaderTest34(
void)
4342 uint8_t http1_buf[] =
4343 "GET /index.html HTTP/1.0\r\n"
4345 "Dummy-Header1: blah\r\n"
4346 "Transfer-Encoding: chunked\r\n"
4348 uint8_t http2_buf[] =
4350 "This is dummy body1\r\n"
4352 uint8_t http3_buf[] =
4353 "Dummy-Header2: kaboom\r\n"
4355 uint32_t http1_len =
sizeof(http1_buf) - 1;
4356 uint32_t http2_len =
sizeof(http2_buf) - 1;
4357 uint32_t http3_len =
sizeof(http3_buf) - 1;
4362 memset(&th_v, 0,
sizeof(th_v));
4363 memset(&f, 0,
sizeof(f));
4364 memset(&ssn, 0,
sizeof(ssn));
4372 f.
proto = IPPROTO_TCP;
4399 "(content:\"Dummy\"; http_header; content:\"Header2\"; http_header; within:8; "
4447 static int DetectEngineHttpHeaderTest35(
void)
4455 uint8_t http1_buf[] =
4456 "GET /index.html HTTP/1.0\r\n"
4458 "Dummy-Header1: blah\r\n"
4459 "Transfer-Encoding: chunked\r\n"
4461 uint8_t http2_buf[] =
4463 "This is dummy body1\r\n"
4465 uint8_t http3_buf[] =
4466 "Dummy-Header2: kaboom\r\n"
4468 uint32_t http1_len =
sizeof(http1_buf) - 1;
4469 uint32_t http2_len =
sizeof(http2_buf) - 1;
4470 uint32_t http3_len =
sizeof(http3_buf) - 1;
4475 memset(&th_v, 0,
sizeof(th_v));
4476 memset(&f, 0,
sizeof(f));
4477 memset(&ssn, 0,
sizeof(ssn));
4485 f.
proto = IPPROTO_TCP;
4512 "(content:\"Dummy\"; http_header; fast_pattern; content:\"Header2\"; http_header; within:8; "
4559 UtRegisterTest(
"DetectHttpHeaderParserTest01", DetectHttpHeaderParserTest01);
4560 UtRegisterTest(
"DetectHttpHeaderParserTest02", DetectHttpHeaderParserTest02);
4562 UtRegisterTest(
"DetectHttpHeaderTest06", DetectHttpHeaderTest06);
4563 UtRegisterTest(
"DetectHttpHeaderTest07", DetectHttpHeaderTest07);
4564 UtRegisterTest(
"DetectHttpHeaderTest08", DetectHttpHeaderTest08);
4565 UtRegisterTest(
"DetectHttpHeaderTest09", DetectHttpHeaderTest09);
4566 UtRegisterTest(
"DetectHttpHeaderTest10", DetectHttpHeaderTest10);
4567 UtRegisterTest(
"DetectHttpHeaderTest11", DetectHttpHeaderTest11);
4568 UtRegisterTest(
"DetectHttpHeaderTest12", DetectHttpHeaderTest12);
4569 UtRegisterTest(
"DetectHttpHeaderTest13", DetectHttpHeaderTest13);
4570 UtRegisterTest(
"DetectHttpHeaderTest28", DetectHttpHeaderTest28);
4571 UtRegisterTest(
"DetectHttpHeaderTest29", DetectHttpHeaderTest29);
4572 UtRegisterTest(
"DetectHttpHeaderTest30", DetectHttpHeaderTest30);
4575 DetectHttpHeaderIsdataatParseTest);
4578 DetectEngineHttpHeaderTest01);
4580 DetectEngineHttpHeaderTest02);
4582 DetectEngineHttpHeaderTest03);
4584 DetectEngineHttpHeaderTest04);
4586 DetectEngineHttpHeaderTest05);
4588 DetectEngineHttpHeaderTest06);
4590 DetectEngineHttpHeaderTest07);
4592 DetectEngineHttpHeaderTest08);
4594 DetectEngineHttpHeaderTest09);
4596 DetectEngineHttpHeaderTest10);
4598 DetectEngineHttpHeaderTest11);
4600 DetectEngineHttpHeaderTest12);
4602 DetectEngineHttpHeaderTest13);
4604 DetectEngineHttpHeaderTest14);
4606 DetectEngineHttpHeaderTest15);
4608 DetectEngineHttpHeaderTest16);
4610 DetectEngineHttpHeaderTest17);
4612 DetectEngineHttpHeaderTest20);
4614 DetectEngineHttpHeaderTest21);
4616 DetectEngineHttpHeaderTest22);
4618 DetectEngineHttpHeaderTest23);
4620 DetectEngineHttpHeaderTest24);
4622 DetectEngineHttpHeaderTest25);
4624 DetectEngineHttpHeaderTest26);
4626 DetectEngineHttpHeaderTest27);
4628 DetectEngineHttpHeaderTest28);
4630 DetectEngineHttpHeaderTest29);
4632 DetectEngineHttpHeaderTest30);
4634 DetectEngineHttpHeaderTest31);
4637 DetectEngineHttpHeaderTest30, 1);
4640 DetectEngineHttpHeaderTest32);
4642 DetectEngineHttpHeaderTest33);
4644 DetectEngineHttpHeaderTest34);
4646 DetectEngineHttpHeaderTest35);