31 #include "../suricata-common.h"
32 #include "../suricata.h"
33 #include "../flow-util.h"
35 #include "../app-layer-parser.h"
36 #include "../util-unittest.h"
37 #include "../util-unittest-helper.h"
38 #include "../app-layer.h"
39 #include "../app-layer-htp.h"
40 #include "../app-layer-protos.h"
41 #include "../detect-engine-build.h"
42 #include "../detect-engine-alert.h"
44 static int DetectEngineHttpStatCodeTest01(
void)
50 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
51 "Host: www.openinfosecfoundation.org\r\n"
52 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
53 "Gecko/20091221 Firefox/3.5.7\r\n"
55 uint32_t http_len1 =
sizeof(http_buf1) - 1;
56 uint8_t http_buf2[] =
"HTTP/1.0 200 message\r\n"
57 "Content-Type: text/html\r\n"
58 "Content-Length: 7\r\n"
61 uint32_t http_len2 =
sizeof(http_buf2) - 1;
64 memset(&th_v, 0,
sizeof(th_v));
66 memset(&f, 0,
sizeof(f));
67 memset(&ssn, 0,
sizeof(ssn));
74 f.
proto = IPPROTO_TCP;
94 "(msg:\"http stat code test\"; "
95 "content:\"200\"; http_stat_code; "
130 static int DetectEngineHttpStatCodeTest02(
void)
136 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
137 "Host: www.openinfosecfoundation.org\r\n"
138 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
139 "Gecko/20091221 Firefox/3.5.7\r\n"
141 uint32_t http_len1 =
sizeof(http_buf1) - 1;
142 uint8_t http_buf2[] =
"HTTP/1.0 2000123 xxxxABC\r\n"
143 "Content-Type: text/html\r\n"
144 "Content-Length: 7\r\n"
147 uint32_t http_len2 =
sizeof(http_buf2) - 1;
150 memset(&th_v, 0,
sizeof(th_v));
152 memset(&f, 0,
sizeof(f));
153 memset(&ssn, 0,
sizeof(ssn));
159 f.
proto = IPPROTO_TCP;
175 "(msg:\"http stat code test\"; "
176 "content:\"123\"; http_stat_code; offset:4; "
207 static int DetectEngineHttpStatCodeTest03(
void)
213 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
214 "Host: www.openinfosecfoundation.org\r\n"
215 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
216 "Gecko/20091221 Firefox/3.5.7\r\n"
218 uint32_t http_len1 =
sizeof(http_buf1) - 1;
219 uint8_t http_buf2[] =
"HTTP/1.0 123";
220 uint32_t http_len2 =
sizeof(http_buf2) - 1;
221 uint8_t http_buf3[] =
"456789\r\n"
222 "Content-Type: text/html\r\n"
223 "Content-Length: 17\r\n"
226 uint32_t http_len3 =
sizeof(http_buf3) - 1;
229 memset(&th_v, 0,
sizeof(th_v));
231 memset(&f, 0,
sizeof(f));
232 memset(&ssn, 0,
sizeof(ssn));
239 f.
proto = IPPROTO_TCP;
259 "(msg:\"http stat code test\"; "
260 "content:\"789\"; http_stat_code; offset:5; "
299 static int DetectEngineHttpStatCodeTest04(
void)
305 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
306 "Host: www.openinfosecfoundation.org\r\n"
307 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
308 "Gecko/20091221 Firefox/3.5.7\r\n"
310 uint32_t http_len1 =
sizeof(http_buf1) - 1;
311 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
312 "Content-Type: text/html\r\n"
313 "Content-Length: 6\r\n"
316 uint32_t http_len2 =
sizeof(http_buf2) - 1;
319 memset(&th_v, 0,
sizeof(th_v));
321 memset(&f, 0,
sizeof(f));
322 memset(&ssn, 0,
sizeof(ssn));
329 f.
proto = IPPROTO_TCP;
349 "(msg:\"http stat code test\"; "
350 "content:!\"200\"; http_stat_code; offset:3; "
385 static int DetectEngineHttpStatCodeTest05(
void)
391 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
392 "Host: www.openinfosecfoundation.org\r\n"
393 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
394 "Gecko/20091221 Firefox/3.5.7\r\n"
396 uint32_t http_len1 =
sizeof(http_buf1) - 1;
397 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
398 "Content-Type: text/html\r\n"
399 "Content-Length: 6\r\n"
402 uint32_t http_len2 =
sizeof(http_buf2) - 1;
405 memset(&th_v, 0,
sizeof(th_v));
407 memset(&f, 0,
sizeof(f));
408 memset(&ssn, 0,
sizeof(ssn));
415 f.
proto = IPPROTO_TCP;
435 "(msg:\"http stat code test\"; "
436 "content:\"200\"; http_stat_code; depth:3; "
471 static int DetectEngineHttpStatCodeTest06(
void)
477 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
478 "Host: www.openinfosecfoundation.org\r\n"
479 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
480 "Gecko/20091221 Firefox/3.5.7\r\n"
482 uint32_t http_len1 =
sizeof(http_buf1) - 1;
483 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
484 "Content-Type: text/html\r\n"
485 "Content-Length: 6\r\n"
488 uint32_t http_len2 =
sizeof(http_buf2) - 1;
491 memset(&th_v, 0,
sizeof(th_v));
493 memset(&f, 0,
sizeof(f));
494 memset(&ssn, 0,
sizeof(ssn));
501 f.
proto = IPPROTO_TCP;
521 "(msg:\"http stat code test\"; "
522 "content:!\"123\"; http_stat_code; depth:3; "
557 static int DetectEngineHttpStatCodeTest07(
void)
563 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
564 "Host: www.openinfosecfoundation.org\r\n"
565 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
566 "Gecko/20091221 Firefox/3.5.7\r\n"
568 uint32_t http_len1 =
sizeof(http_buf1) - 1;
569 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
570 "Content-Type: text/html\r\n"
571 "Content-Length: 6\r\n"
574 uint32_t http_len2 =
sizeof(http_buf2) - 1;
577 memset(&th_v, 0,
sizeof(th_v));
579 memset(&f, 0,
sizeof(f));
580 memset(&ssn, 0,
sizeof(ssn));
587 f.
proto = IPPROTO_TCP;
607 "(msg:\"http stat code test\"; "
608 "content:!\"123\"; http_stat_code; offset:3; "
643 static int DetectEngineHttpStatCodeTest08(
void)
649 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
650 "Host: www.openinfosecfoundation.org\r\n"
651 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
652 "Gecko/20091221 Firefox/3.5.7\r\n"
654 uint32_t http_len1 =
sizeof(http_buf1) - 1;
655 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
656 "Content-Type: text/html\r\n"
657 "Content-Length: 6\r\n"
660 uint32_t http_len2 =
sizeof(http_buf2) - 1;
663 memset(&th_v, 0,
sizeof(th_v));
665 memset(&f, 0,
sizeof(f));
666 memset(&ssn, 0,
sizeof(ssn));
673 f.
proto = IPPROTO_TCP;
693 "(msg:\"http stat code test\"; "
694 "content:!\"200\"; http_stat_code; depth:3; "
729 static int DetectEngineHttpStatCodeTest09(
void)
735 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
736 "Host: www.openinfosecfoundation.org\r\n"
737 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
738 "Gecko/20091221 Firefox/3.5.7\r\n"
740 uint32_t http_len1 =
sizeof(http_buf1) - 1;
741 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
742 "Content-Type: text/html\r\n"
743 "Content-Length: 6\r\n"
746 uint32_t http_len2 =
sizeof(http_buf2) - 1;
749 memset(&th_v, 0,
sizeof(th_v));
751 memset(&f, 0,
sizeof(f));
752 memset(&ssn, 0,
sizeof(ssn));
759 f.
proto = IPPROTO_TCP;
779 "(msg:\"http stat code test\"; "
780 "content:\"200\"; http_stat_code; depth:3; "
781 "content:\"123\"; http_stat_code; within:3; "
816 static int DetectEngineHttpStatCodeTest10(
void)
822 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
823 "Host: www.openinfosecfoundation.org\r\n"
824 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
825 "Gecko/20091221 Firefox/3.5.7\r\n"
827 uint32_t http_len1 =
sizeof(http_buf1) - 1;
828 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
829 "Content-Type: text/html\r\n"
830 "Content-Length: 6\r\n"
833 uint32_t http_len2 =
sizeof(http_buf2) - 1;
836 memset(&th_v, 0,
sizeof(th_v));
838 memset(&f, 0,
sizeof(f));
839 memset(&ssn, 0,
sizeof(ssn));
846 f.
proto = IPPROTO_TCP;
866 "(msg:\"http stat code test\"; "
867 "content:\"200\"; http_stat_code; depth:3; "
868 "content:!\"124\"; http_stat_code; within:3; "
903 static int DetectEngineHttpStatCodeTest11(
void)
909 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
910 "Host: www.openinfosecfoundation.org\r\n"
911 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
912 "Gecko/20091221 Firefox/3.5.7\r\n"
914 uint32_t http_len1 =
sizeof(http_buf1) - 1;
915 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
916 "Content-Type: text/html\r\n"
917 "Content-Length: 6\r\n"
920 uint32_t http_len2 =
sizeof(http_buf2) - 1;
923 memset(&th_v, 0,
sizeof(th_v));
925 memset(&f, 0,
sizeof(f));
926 memset(&ssn, 0,
sizeof(ssn));
933 f.
proto = IPPROTO_TCP;
953 "(msg:\"http stat code test\"; "
954 "content:\"200\"; http_stat_code; depth:3; "
955 "content:\"124\"; http_stat_code; within:3; "
990 static int DetectEngineHttpStatCodeTest12(
void)
996 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
997 "Host: www.openinfosecfoundation.org\r\n"
998 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
999 "Gecko/20091221 Firefox/3.5.7\r\n"
1001 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1002 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
1003 "Content-Type: text/html\r\n"
1004 "Content-Length: 6\r\n"
1007 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1010 memset(&th_v, 0,
sizeof(th_v));
1012 memset(&f, 0,
sizeof(f));
1013 memset(&ssn, 0,
sizeof(ssn));
1020 f.
proto = IPPROTO_TCP;
1040 "(msg:\"http stat code test\"; "
1041 "content:\"20\"; http_stat_code; depth:2; "
1042 "content:\"23\"; http_stat_code; distance:2; "
1077 static int DetectEngineHttpStatCodeTest13(
void)
1083 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
1084 "Host: www.openinfosecfoundation.org\r\n"
1085 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
1086 "Gecko/20091221 Firefox/3.5.7\r\n"
1088 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1089 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
1090 "Content-Type: text/html\r\n"
1091 "Content-Length: 6\r\n"
1094 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1097 memset(&th_v, 0,
sizeof(th_v));
1099 memset(&f, 0,
sizeof(f));
1100 memset(&ssn, 0,
sizeof(ssn));
1107 f.
proto = IPPROTO_TCP;
1127 "(msg:\"http stat code test\"; "
1128 "content:\"20\"; http_stat_code; depth:3; "
1129 "content:!\"25\"; http_stat_code; distance:2; "
1164 static int DetectEngineHttpStatCodeTest14(
void)
1170 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
1171 "Host: www.openinfosecfoundation.org\r\n"
1172 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
1173 "Gecko/20091221 Firefox/3.5.7\r\n"
1175 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1176 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
1177 "Content-Type: text/html\r\n"
1178 "Content-Length: 6\r\n"
1181 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1184 memset(&th_v, 0,
sizeof(th_v));
1186 memset(&f, 0,
sizeof(f));
1187 memset(&ssn, 0,
sizeof(ssn));
1194 f.
proto = IPPROTO_TCP;
1214 "(msg:\"http stat code test\"; "
1216 "content:\"23\"; http_stat_code; distance:2; "
1251 static int DetectEngineHttpStatCodeTest15(
void)
1257 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
1258 "Host: www.openinfosecfoundation.org\r\n"
1259 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
1260 "Gecko/20091221 Firefox/3.5.7\r\n"
1262 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1263 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
1264 "Content-Type: text/html\r\n"
1265 "Content-Length: 6\r\n"
1268 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1271 memset(&th_v, 0,
sizeof(th_v));
1273 memset(&f, 0,
sizeof(f));
1274 memset(&ssn, 0,
sizeof(ssn));
1281 f.
proto = IPPROTO_TCP;
1302 "(msg:\"http stat code test\"; "
1304 "content:!\"124\"; http_stat_code; distance:0; within:3; "
1340 static int DetectHttpStatCodeSigTest01(
void)
1343 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1344 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1345 uint8_t httpbuf2[] =
"HTTP/1.0 200 OK\r\n\r\n";
1346 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1352 memset(&th_v, 0,
sizeof(th_v));
1354 memset(&f, 0,
sizeof(f));
1355 memset(&ssn, 0,
sizeof(ssn));
1361 f.
proto = IPPROTO_TCP;
1377 "alert http any any -> any any (msg:"
1378 "\"HTTP status code\"; content:\"200\"; http_stat_code; sid:1;)");
1408 static int DetectHttpStatCodeSigTest02(
void)
1411 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1412 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1413 uint8_t httpbuf2[] =
"HTTP/1.0 200 OK\r\n\r\n";
1414 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1420 memset(&th_v, 0,
sizeof(th_v));
1422 memset(&f, 0,
sizeof(f));
1423 memset(&ssn, 0,
sizeof(ssn));
1429 f.
proto = IPPROTO_TCP;
1445 "\"HTTP status code\"; content:\"no\"; "
1446 "http_stat_code; sid:1;)");
1450 "Status code\"; content:\"100\";"
1451 "http_stat_code; sid:2;)");
1483 static int DetectHttpStatCodeSigTest03(
void)
1486 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1487 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1488 uint8_t httpbuf2[] =
"HTTP/1.0 FAIL OK\r\n\r\n";
1489 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1495 memset(&th_v, 0,
sizeof(th_v));
1497 memset(&f, 0,
sizeof(f));
1498 memset(&ssn, 0,
sizeof(ssn));
1504 f.
proto = IPPROTO_TCP;
1520 "\"HTTP status code\"; content:\"FAIL\"; "
1521 "http_stat_code; sid:1;)");
1525 "Status code nocase\"; content:\"fail\"; nocase; "
1526 "http_stat_code; sid:2;)");
1558 static int DetectHttpStatCodeSigTest04(
void)
1561 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1562 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1563 uint8_t httpbuf2[] =
"HTTP/1.0 200 OK\r\n\r\n";
1564 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1570 memset(&th_v, 0,
sizeof(th_v));
1572 memset(&f, 0,
sizeof(f));
1573 memset(&ssn, 0,
sizeof(ssn));
1579 f.
proto = IPPROTO_TCP;
1595 "\"HTTP status code\"; content:\"200\"; "
1596 "http_stat_code; sid:1;)");
1600 "Status code negation\"; content:!\"100\"; nocase; "
1601 "http_stat_code; sid:2;)");
1637 UtRegisterTest(
"DetectEngineHttpStatCodeTest01", DetectEngineHttpStatCodeTest01);
1638 UtRegisterTest(
"DetectEngineHttpStatCodeTest02", DetectEngineHttpStatCodeTest02);
1639 UtRegisterTest(
"DetectEngineHttpStatCodeTest03", DetectEngineHttpStatCodeTest03);
1640 UtRegisterTest(
"DetectEngineHttpStatCodeTest04", DetectEngineHttpStatCodeTest04);
1641 UtRegisterTest(
"DetectEngineHttpStatCodeTest05", DetectEngineHttpStatCodeTest05);
1642 UtRegisterTest(
"DetectEngineHttpStatCodeTest06", DetectEngineHttpStatCodeTest06);
1643 UtRegisterTest(
"DetectEngineHttpStatCodeTest07", DetectEngineHttpStatCodeTest07);
1644 UtRegisterTest(
"DetectEngineHttpStatCodeTest08", DetectEngineHttpStatCodeTest08);
1645 UtRegisterTest(
"DetectEngineHttpStatCodeTest09", DetectEngineHttpStatCodeTest09);
1646 UtRegisterTest(
"DetectEngineHttpStatCodeTest10", DetectEngineHttpStatCodeTest10);
1647 UtRegisterTest(
"DetectEngineHttpStatCodeTest11", DetectEngineHttpStatCodeTest11);
1648 UtRegisterTest(
"DetectEngineHttpStatCodeTest12", DetectEngineHttpStatCodeTest12);
1649 UtRegisterTest(
"DetectEngineHttpStatCodeTest13", DetectEngineHttpStatCodeTest13);
1650 UtRegisterTest(
"DetectEngineHttpStatCodeTest14", DetectEngineHttpStatCodeTest14);
1651 UtRegisterTest(
"DetectEngineHttpStatCodeTest15", DetectEngineHttpStatCodeTest15);
1653 UtRegisterTest(
"DetectHttpStatCodeSigTest01", DetectHttpStatCodeSigTest01);
1654 UtRegisterTest(
"DetectHttpStatCodeSigTest02", DetectHttpStatCodeSigTest02);
1655 UtRegisterTest(
"DetectHttpStatCodeSigTest03", DetectHttpStatCodeSigTest03);
1656 UtRegisterTest(
"DetectHttpStatCodeSigTest04", DetectHttpStatCodeSigTest04);