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));
65 memset(&f, 0,
sizeof(f));
66 memset(&ssn, 0,
sizeof(ssn));
73 f.
proto = IPPROTO_TCP;
93 "(msg:\"http stat code test\"; "
94 "content:\"200\"; http_stat_code; "
129 static int DetectEngineHttpStatCodeTest02(
void)
135 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
136 "Host: www.openinfosecfoundation.org\r\n"
137 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
138 "Gecko/20091221 Firefox/3.5.7\r\n"
140 uint32_t http_len1 =
sizeof(http_buf1) - 1;
141 uint8_t http_buf2[] =
"HTTP/1.0 2000123 xxxxABC\r\n"
142 "Content-Type: text/html\r\n"
143 "Content-Length: 7\r\n"
146 uint32_t http_len2 =
sizeof(http_buf2) - 1;
149 memset(&th_v, 0,
sizeof(th_v));
150 memset(&f, 0,
sizeof(f));
151 memset(&ssn, 0,
sizeof(ssn));
157 f.
proto = IPPROTO_TCP;
173 "(msg:\"http stat code test\"; "
174 "content:\"123\"; http_stat_code; offset:4; "
205 static int DetectEngineHttpStatCodeTest03(
void)
211 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
212 "Host: www.openinfosecfoundation.org\r\n"
213 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
214 "Gecko/20091221 Firefox/3.5.7\r\n"
216 uint32_t http_len1 =
sizeof(http_buf1) - 1;
217 uint8_t http_buf2[] =
"HTTP/1.0 123";
218 uint32_t http_len2 =
sizeof(http_buf2) - 1;
219 uint8_t http_buf3[] =
"456789\r\n"
220 "Content-Type: text/html\r\n"
221 "Content-Length: 17\r\n"
224 uint32_t http_len3 =
sizeof(http_buf3) - 1;
227 memset(&th_v, 0,
sizeof(th_v));
228 memset(&f, 0,
sizeof(f));
229 memset(&ssn, 0,
sizeof(ssn));
236 f.
proto = IPPROTO_TCP;
256 "(msg:\"http stat code test\"; "
257 "content:\"789\"; http_stat_code; offset:5; "
296 static int DetectEngineHttpStatCodeTest04(
void)
302 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
303 "Host: www.openinfosecfoundation.org\r\n"
304 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
305 "Gecko/20091221 Firefox/3.5.7\r\n"
307 uint32_t http_len1 =
sizeof(http_buf1) - 1;
308 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
309 "Content-Type: text/html\r\n"
310 "Content-Length: 6\r\n"
313 uint32_t http_len2 =
sizeof(http_buf2) - 1;
316 memset(&th_v, 0,
sizeof(th_v));
317 memset(&f, 0,
sizeof(f));
318 memset(&ssn, 0,
sizeof(ssn));
325 f.
proto = IPPROTO_TCP;
345 "(msg:\"http stat code test\"; "
346 "content:!\"200\"; http_stat_code; offset:3; "
381 static int DetectEngineHttpStatCodeTest05(
void)
387 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
388 "Host: www.openinfosecfoundation.org\r\n"
389 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
390 "Gecko/20091221 Firefox/3.5.7\r\n"
392 uint32_t http_len1 =
sizeof(http_buf1) - 1;
393 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
394 "Content-Type: text/html\r\n"
395 "Content-Length: 6\r\n"
398 uint32_t http_len2 =
sizeof(http_buf2) - 1;
401 memset(&th_v, 0,
sizeof(th_v));
402 memset(&f, 0,
sizeof(f));
403 memset(&ssn, 0,
sizeof(ssn));
410 f.
proto = IPPROTO_TCP;
430 "(msg:\"http stat code test\"; "
431 "content:\"200\"; http_stat_code; depth:3; "
466 static int DetectEngineHttpStatCodeTest06(
void)
472 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
473 "Host: www.openinfosecfoundation.org\r\n"
474 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
475 "Gecko/20091221 Firefox/3.5.7\r\n"
477 uint32_t http_len1 =
sizeof(http_buf1) - 1;
478 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
479 "Content-Type: text/html\r\n"
480 "Content-Length: 6\r\n"
483 uint32_t http_len2 =
sizeof(http_buf2) - 1;
486 memset(&th_v, 0,
sizeof(th_v));
487 memset(&f, 0,
sizeof(f));
488 memset(&ssn, 0,
sizeof(ssn));
495 f.
proto = IPPROTO_TCP;
515 "(msg:\"http stat code test\"; "
516 "content:!\"123\"; http_stat_code; depth:3; "
551 static int DetectEngineHttpStatCodeTest07(
void)
557 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
558 "Host: www.openinfosecfoundation.org\r\n"
559 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
560 "Gecko/20091221 Firefox/3.5.7\r\n"
562 uint32_t http_len1 =
sizeof(http_buf1) - 1;
563 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
564 "Content-Type: text/html\r\n"
565 "Content-Length: 6\r\n"
568 uint32_t http_len2 =
sizeof(http_buf2) - 1;
571 memset(&th_v, 0,
sizeof(th_v));
572 memset(&f, 0,
sizeof(f));
573 memset(&ssn, 0,
sizeof(ssn));
580 f.
proto = IPPROTO_TCP;
600 "(msg:\"http stat code test\"; "
601 "content:!\"123\"; http_stat_code; offset:3; "
636 static int DetectEngineHttpStatCodeTest08(
void)
642 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
643 "Host: www.openinfosecfoundation.org\r\n"
644 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
645 "Gecko/20091221 Firefox/3.5.7\r\n"
647 uint32_t http_len1 =
sizeof(http_buf1) - 1;
648 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
649 "Content-Type: text/html\r\n"
650 "Content-Length: 6\r\n"
653 uint32_t http_len2 =
sizeof(http_buf2) - 1;
656 memset(&th_v, 0,
sizeof(th_v));
657 memset(&f, 0,
sizeof(f));
658 memset(&ssn, 0,
sizeof(ssn));
665 f.
proto = IPPROTO_TCP;
685 "(msg:\"http stat code test\"; "
686 "content:!\"200\"; http_stat_code; depth:3; "
721 static int DetectEngineHttpStatCodeTest09(
void)
727 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
728 "Host: www.openinfosecfoundation.org\r\n"
729 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
730 "Gecko/20091221 Firefox/3.5.7\r\n"
732 uint32_t http_len1 =
sizeof(http_buf1) - 1;
733 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
734 "Content-Type: text/html\r\n"
735 "Content-Length: 6\r\n"
738 uint32_t http_len2 =
sizeof(http_buf2) - 1;
741 memset(&th_v, 0,
sizeof(th_v));
742 memset(&f, 0,
sizeof(f));
743 memset(&ssn, 0,
sizeof(ssn));
750 f.
proto = IPPROTO_TCP;
770 "(msg:\"http stat code test\"; "
771 "content:\"200\"; http_stat_code; depth:3; "
772 "content:\"123\"; http_stat_code; within:3; "
807 static int DetectEngineHttpStatCodeTest10(
void)
813 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
814 "Host: www.openinfosecfoundation.org\r\n"
815 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
816 "Gecko/20091221 Firefox/3.5.7\r\n"
818 uint32_t http_len1 =
sizeof(http_buf1) - 1;
819 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
820 "Content-Type: text/html\r\n"
821 "Content-Length: 6\r\n"
824 uint32_t http_len2 =
sizeof(http_buf2) - 1;
827 memset(&th_v, 0,
sizeof(th_v));
828 memset(&f, 0,
sizeof(f));
829 memset(&ssn, 0,
sizeof(ssn));
836 f.
proto = IPPROTO_TCP;
856 "(msg:\"http stat code test\"; "
857 "content:\"200\"; http_stat_code; depth:3; "
858 "content:!\"124\"; http_stat_code; within:3; "
893 static int DetectEngineHttpStatCodeTest11(
void)
899 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
900 "Host: www.openinfosecfoundation.org\r\n"
901 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
902 "Gecko/20091221 Firefox/3.5.7\r\n"
904 uint32_t http_len1 =
sizeof(http_buf1) - 1;
905 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
906 "Content-Type: text/html\r\n"
907 "Content-Length: 6\r\n"
910 uint32_t http_len2 =
sizeof(http_buf2) - 1;
913 memset(&th_v, 0,
sizeof(th_v));
914 memset(&f, 0,
sizeof(f));
915 memset(&ssn, 0,
sizeof(ssn));
922 f.
proto = IPPROTO_TCP;
942 "(msg:\"http stat code test\"; "
943 "content:\"200\"; http_stat_code; depth:3; "
944 "content:\"124\"; http_stat_code; within:3; "
979 static int DetectEngineHttpStatCodeTest12(
void)
985 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
986 "Host: www.openinfosecfoundation.org\r\n"
987 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
988 "Gecko/20091221 Firefox/3.5.7\r\n"
990 uint32_t http_len1 =
sizeof(http_buf1) - 1;
991 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
992 "Content-Type: text/html\r\n"
993 "Content-Length: 6\r\n"
996 uint32_t http_len2 =
sizeof(http_buf2) - 1;
999 memset(&th_v, 0,
sizeof(th_v));
1000 memset(&f, 0,
sizeof(f));
1001 memset(&ssn, 0,
sizeof(ssn));
1008 f.
proto = IPPROTO_TCP;
1028 "(msg:\"http stat code test\"; "
1029 "content:\"20\"; http_stat_code; depth:2; "
1030 "content:\"23\"; http_stat_code; distance:2; "
1065 static int DetectEngineHttpStatCodeTest13(
void)
1071 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
1072 "Host: www.openinfosecfoundation.org\r\n"
1073 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
1074 "Gecko/20091221 Firefox/3.5.7\r\n"
1076 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1077 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
1078 "Content-Type: text/html\r\n"
1079 "Content-Length: 6\r\n"
1082 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1085 memset(&th_v, 0,
sizeof(th_v));
1086 memset(&f, 0,
sizeof(f));
1087 memset(&ssn, 0,
sizeof(ssn));
1094 f.
proto = IPPROTO_TCP;
1114 "(msg:\"http stat code test\"; "
1115 "content:\"20\"; http_stat_code; depth:3; "
1116 "content:!\"25\"; http_stat_code; distance:2; "
1151 static int DetectEngineHttpStatCodeTest14(
void)
1157 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
1158 "Host: www.openinfosecfoundation.org\r\n"
1159 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
1160 "Gecko/20091221 Firefox/3.5.7\r\n"
1162 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1163 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
1164 "Content-Type: text/html\r\n"
1165 "Content-Length: 6\r\n"
1168 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1171 memset(&th_v, 0,
sizeof(th_v));
1172 memset(&f, 0,
sizeof(f));
1173 memset(&ssn, 0,
sizeof(ssn));
1180 f.
proto = IPPROTO_TCP;
1200 "(msg:\"http stat code test\"; "
1202 "content:\"23\"; http_stat_code; distance:2; "
1237 static int DetectEngineHttpStatCodeTest15(
void)
1243 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
1244 "Host: www.openinfosecfoundation.org\r\n"
1245 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
1246 "Gecko/20091221 Firefox/3.5.7\r\n"
1248 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1249 uint8_t http_buf2[] =
"HTTP/1.0 200123 abcdef\r\n"
1250 "Content-Type: text/html\r\n"
1251 "Content-Length: 6\r\n"
1254 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1257 memset(&th_v, 0,
sizeof(th_v));
1258 memset(&f, 0,
sizeof(f));
1259 memset(&ssn, 0,
sizeof(ssn));
1266 f.
proto = IPPROTO_TCP;
1287 "(msg:\"http stat code test\"; "
1289 "content:!\"124\"; http_stat_code; distance:0; within:3; "
1325 static int DetectHttpStatCodeSigTest01(
void)
1328 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1329 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1330 uint8_t httpbuf2[] =
"HTTP/1.0 200 OK\r\n\r\n";
1331 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1337 memset(&th_v, 0,
sizeof(th_v));
1338 memset(&f, 0,
sizeof(f));
1339 memset(&ssn, 0,
sizeof(ssn));
1345 f.
proto = IPPROTO_TCP;
1361 "alert http any any -> any any (msg:"
1362 "\"HTTP status code\"; content:\"200\"; http_stat_code; sid:1;)");
1392 static int DetectHttpStatCodeSigTest02(
void)
1395 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1396 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1397 uint8_t httpbuf2[] =
"HTTP/1.0 200 OK\r\n\r\n";
1398 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1404 memset(&th_v, 0,
sizeof(th_v));
1405 memset(&f, 0,
sizeof(f));
1406 memset(&ssn, 0,
sizeof(ssn));
1412 f.
proto = IPPROTO_TCP;
1428 "\"HTTP status code\"; content:\"no\"; "
1429 "http_stat_code; sid:1;)");
1433 "Status code\"; content:\"100\";"
1434 "http_stat_code; sid:2;)");
1466 static int DetectHttpStatCodeSigTest03(
void)
1469 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1470 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1471 uint8_t httpbuf2[] =
"HTTP/1.0 FAIL OK\r\n\r\n";
1472 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1478 memset(&th_v, 0,
sizeof(th_v));
1479 memset(&f, 0,
sizeof(f));
1480 memset(&ssn, 0,
sizeof(ssn));
1486 f.
proto = IPPROTO_TCP;
1502 "\"HTTP status code\"; content:\"FAIL\"; "
1503 "http_stat_code; sid:1;)");
1507 "Status code nocase\"; content:\"fail\"; nocase; "
1508 "http_stat_code; sid:2;)");
1540 static int DetectHttpStatCodeSigTest04(
void)
1543 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1544 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1545 uint8_t httpbuf2[] =
"HTTP/1.0 200 OK\r\n\r\n";
1546 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1552 memset(&th_v, 0,
sizeof(th_v));
1553 memset(&f, 0,
sizeof(f));
1554 memset(&ssn, 0,
sizeof(ssn));
1560 f.
proto = IPPROTO_TCP;
1576 "\"HTTP status code\"; content:\"200\"; "
1577 "http_stat_code; sid:1;)");
1581 "Status code negation\"; content:!\"100\"; nocase; "
1582 "http_stat_code; sid:2;)");
1618 UtRegisterTest(
"DetectEngineHttpStatCodeTest01", DetectEngineHttpStatCodeTest01);
1619 UtRegisterTest(
"DetectEngineHttpStatCodeTest02", DetectEngineHttpStatCodeTest02);
1620 UtRegisterTest(
"DetectEngineHttpStatCodeTest03", DetectEngineHttpStatCodeTest03);
1621 UtRegisterTest(
"DetectEngineHttpStatCodeTest04", DetectEngineHttpStatCodeTest04);
1622 UtRegisterTest(
"DetectEngineHttpStatCodeTest05", DetectEngineHttpStatCodeTest05);
1623 UtRegisterTest(
"DetectEngineHttpStatCodeTest06", DetectEngineHttpStatCodeTest06);
1624 UtRegisterTest(
"DetectEngineHttpStatCodeTest07", DetectEngineHttpStatCodeTest07);
1625 UtRegisterTest(
"DetectEngineHttpStatCodeTest08", DetectEngineHttpStatCodeTest08);
1626 UtRegisterTest(
"DetectEngineHttpStatCodeTest09", DetectEngineHttpStatCodeTest09);
1627 UtRegisterTest(
"DetectEngineHttpStatCodeTest10", DetectEngineHttpStatCodeTest10);
1628 UtRegisterTest(
"DetectEngineHttpStatCodeTest11", DetectEngineHttpStatCodeTest11);
1629 UtRegisterTest(
"DetectEngineHttpStatCodeTest12", DetectEngineHttpStatCodeTest12);
1630 UtRegisterTest(
"DetectEngineHttpStatCodeTest13", DetectEngineHttpStatCodeTest13);
1631 UtRegisterTest(
"DetectEngineHttpStatCodeTest14", DetectEngineHttpStatCodeTest14);
1632 UtRegisterTest(
"DetectEngineHttpStatCodeTest15", DetectEngineHttpStatCodeTest15);
1634 UtRegisterTest(
"DetectHttpStatCodeSigTest01", DetectHttpStatCodeSigTest01);
1635 UtRegisterTest(
"DetectHttpStatCodeSigTest02", DetectHttpStatCodeSigTest02);
1636 UtRegisterTest(
"DetectHttpStatCodeSigTest03", DetectHttpStatCodeSigTest03);
1637 UtRegisterTest(
"DetectHttpStatCodeSigTest04", DetectHttpStatCodeSigTest04);