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 DetectEngineHttpStatMsgTest01(
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 msg test\"; "
95 "content:\"message\"; http_stat_msg; "
133 static int DetectEngineHttpStatMsgTest02(
void)
139 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
140 "Host: www.openinfosecfoundation.org\r\n"
141 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
142 "Gecko/20091221 Firefox/3.5.7\r\n"
144 uint32_t http_len1 =
sizeof(http_buf1) - 1;
145 uint8_t http_buf2[] =
"HTTP/1.0 200 xxxxABC\r\n"
146 "Content-Type: text/html\r\n"
147 "Content-Length: 7\r\n"
150 uint32_t http_len2 =
sizeof(http_buf2) - 1;
153 memset(&th_v, 0,
sizeof(th_v));
155 memset(&f, 0,
sizeof(f));
156 memset(&ssn, 0,
sizeof(ssn));
162 f.
proto = IPPROTO_TCP;
178 "(msg:\"http stat msg test\"; "
179 "content:\"ABC\"; http_stat_msg; offset:4; "
211 static int DetectEngineHttpStatMsgTest03(
void)
217 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
218 "Host: www.openinfosecfoundation.org\r\n"
219 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
220 "Gecko/20091221 Firefox/3.5.7\r\n"
222 uint32_t http_len1 =
sizeof(http_buf1) - 1;
223 uint8_t http_buf2[] =
"HTTP/1.0 200 1234567";
224 uint32_t http_len2 =
sizeof(http_buf2) - 1;
225 uint8_t http_buf3[] =
"8901234ABC\r\n"
226 "Content-Type: text/html\r\n"
227 "Content-Length: 17\r\n"
230 uint32_t http_len3 =
sizeof(http_buf3) - 1;
233 memset(&th_v, 0,
sizeof(th_v));
235 memset(&f, 0,
sizeof(f));
236 memset(&ssn, 0,
sizeof(ssn));
243 f.
proto = IPPROTO_TCP;
263 "(msg:\"http stat msg test\"; "
264 "content:\"ABC\"; http_stat_msg; offset:14; "
303 static int DetectEngineHttpStatMsgTest04(
void)
309 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
310 "Host: www.openinfosecfoundation.org\r\n"
311 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
312 "Gecko/20091221 Firefox/3.5.7\r\n"
314 uint32_t http_len1 =
sizeof(http_buf1) - 1;
315 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
316 "Content-Type: text/html\r\n"
317 "Content-Length: 6\r\n"
320 uint32_t http_len2 =
sizeof(http_buf2) - 1;
323 memset(&th_v, 0,
sizeof(th_v));
325 memset(&f, 0,
sizeof(f));
326 memset(&ssn, 0,
sizeof(ssn));
333 f.
proto = IPPROTO_TCP;
353 "(msg:\"http stat msg test\"; "
354 "content:!\"abc\"; http_stat_msg; offset:3; "
389 static int DetectEngineHttpStatMsgTest05(
void)
395 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
396 "Host: www.openinfosecfoundation.org\r\n"
397 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
398 "Gecko/20091221 Firefox/3.5.7\r\n"
400 uint32_t http_len1 =
sizeof(http_buf1) - 1;
401 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
402 "Content-Type: text/html\r\n"
403 "Content-Length: 6\r\n"
406 uint32_t http_len2 =
sizeof(http_buf2) - 1;
409 memset(&th_v, 0,
sizeof(th_v));
411 memset(&f, 0,
sizeof(f));
412 memset(&ssn, 0,
sizeof(ssn));
419 f.
proto = IPPROTO_TCP;
439 "(msg:\"http stat msg test\"; "
440 "content:\"abc\"; http_stat_msg; depth:3; "
475 static int DetectEngineHttpStatMsgTest06(
void)
481 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
482 "Host: www.openinfosecfoundation.org\r\n"
483 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
484 "Gecko/20091221 Firefox/3.5.7\r\n"
486 uint32_t http_len1 =
sizeof(http_buf1) - 1;
487 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
488 "Content-Type: text/html\r\n"
489 "Content-Length: 6\r\n"
492 uint32_t http_len2 =
sizeof(http_buf2) - 1;
495 memset(&th_v, 0,
sizeof(th_v));
497 memset(&f, 0,
sizeof(f));
498 memset(&ssn, 0,
sizeof(ssn));
505 f.
proto = IPPROTO_TCP;
525 "(msg:\"http stat msg test\"; "
526 "content:!\"def\"; http_stat_msg; depth:3; "
561 static int DetectEngineHttpStatMsgTest07(
void)
567 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
568 "Host: www.openinfosecfoundation.org\r\n"
569 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
570 "Gecko/20091221 Firefox/3.5.7\r\n"
572 uint32_t http_len1 =
sizeof(http_buf1) - 1;
573 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
574 "Content-Type: text/html\r\n"
575 "Content-Length: 6\r\n"
578 uint32_t http_len2 =
sizeof(http_buf2) - 1;
581 memset(&th_v, 0,
sizeof(th_v));
583 memset(&f, 0,
sizeof(f));
584 memset(&ssn, 0,
sizeof(ssn));
591 f.
proto = IPPROTO_TCP;
611 "(msg:\"http stat msg test\"; "
612 "content:!\"def\"; http_stat_msg; offset:3; "
647 static int DetectEngineHttpStatMsgTest08(
void)
653 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
654 "Host: www.openinfosecfoundation.org\r\n"
655 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
656 "Gecko/20091221 Firefox/3.5.7\r\n"
658 uint32_t http_len1 =
sizeof(http_buf1) - 1;
659 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
660 "Content-Type: text/html\r\n"
661 "Content-Length: 6\r\n"
664 uint32_t http_len2 =
sizeof(http_buf2) - 1;
667 memset(&th_v, 0,
sizeof(th_v));
669 memset(&f, 0,
sizeof(f));
670 memset(&ssn, 0,
sizeof(ssn));
677 f.
proto = IPPROTO_TCP;
697 "(msg:\"http stat msg test\"; "
698 "content:!\"abc\"; http_stat_msg; depth:3; "
733 static int DetectEngineHttpStatMsgTest09(
void)
739 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
740 "Host: www.openinfosecfoundation.org\r\n"
741 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
742 "Gecko/20091221 Firefox/3.5.7\r\n"
744 uint32_t http_len1 =
sizeof(http_buf1) - 1;
745 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
746 "Content-Type: text/html\r\n"
747 "Content-Length: 6\r\n"
750 uint32_t http_len2 =
sizeof(http_buf2) - 1;
753 memset(&th_v, 0,
sizeof(th_v));
755 memset(&f, 0,
sizeof(f));
756 memset(&ssn, 0,
sizeof(ssn));
763 f.
proto = IPPROTO_TCP;
783 "(msg:\"http stat msg test\"; "
784 "content:\"abc\"; http_stat_msg; depth:3; "
785 "content:\"def\"; http_stat_msg; within:3; "
820 static int DetectEngineHttpStatMsgTest10(
void)
826 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
827 "Host: www.openinfosecfoundation.org\r\n"
828 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
829 "Gecko/20091221 Firefox/3.5.7\r\n"
831 uint32_t http_len1 =
sizeof(http_buf1) - 1;
832 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
833 "Content-Type: text/html\r\n"
834 "Content-Length: 6\r\n"
837 uint32_t http_len2 =
sizeof(http_buf2) - 1;
840 memset(&th_v, 0,
sizeof(th_v));
842 memset(&f, 0,
sizeof(f));
843 memset(&ssn, 0,
sizeof(ssn));
850 f.
proto = IPPROTO_TCP;
870 "(msg:\"http stat msg test\"; "
871 "content:\"abc\"; http_stat_msg; depth:3; "
872 "content:!\"xyz\"; http_stat_msg; within:3; "
907 static int DetectEngineHttpStatMsgTest11(
void)
913 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
914 "Host: www.openinfosecfoundation.org\r\n"
915 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
916 "Gecko/20091221 Firefox/3.5.7\r\n"
918 uint32_t http_len1 =
sizeof(http_buf1) - 1;
919 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
920 "Content-Type: text/html\r\n"
921 "Content-Length: 6\r\n"
924 uint32_t http_len2 =
sizeof(http_buf2) - 1;
927 memset(&th_v, 0,
sizeof(th_v));
929 memset(&f, 0,
sizeof(f));
930 memset(&ssn, 0,
sizeof(ssn));
937 f.
proto = IPPROTO_TCP;
957 "(msg:\"http stat msg test\"; "
958 "content:\"abc\"; http_stat_msg; depth:3; "
959 "content:\"xyz\"; http_stat_msg; within:3; "
994 static int DetectEngineHttpStatMsgTest12(
void)
1000 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
1001 "Host: www.openinfosecfoundation.org\r\n"
1002 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
1003 "Gecko/20091221 Firefox/3.5.7\r\n"
1005 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1006 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
1007 "Content-Type: text/html\r\n"
1008 "Content-Length: 6\r\n"
1011 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1014 memset(&th_v, 0,
sizeof(th_v));
1016 memset(&f, 0,
sizeof(f));
1017 memset(&ssn, 0,
sizeof(ssn));
1024 f.
proto = IPPROTO_TCP;
1044 "(msg:\"http stat msg test\"; "
1045 "content:\"ab\"; http_stat_msg; depth:2; "
1046 "content:\"ef\"; http_stat_msg; distance:2; "
1082 static int DetectEngineHttpStatMsgTest13(
void)
1088 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
1089 "Host: www.openinfosecfoundation.org\r\n"
1090 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
1091 "Gecko/20091221 Firefox/3.5.7\r\n"
1093 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1094 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
1095 "Content-Type: text/html\r\n"
1096 "Content-Length: 6\r\n"
1099 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1102 memset(&th_v, 0,
sizeof(th_v));
1104 memset(&f, 0,
sizeof(f));
1105 memset(&ssn, 0,
sizeof(ssn));
1112 f.
proto = IPPROTO_TCP;
1132 "(msg:\"http stat msg test\"; "
1133 "content:\"ab\"; http_stat_msg; depth:3; "
1134 "content:!\"yz\"; http_stat_msg; distance:2; "
1169 static int DetectEngineHttpStatMsgTest14(
void)
1175 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
1176 "Host: www.openinfosecfoundation.org\r\n"
1177 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
1178 "Gecko/20091221 Firefox/3.5.7\r\n"
1180 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1181 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
1182 "Content-Type: text/html\r\n"
1183 "Content-Length: 6\r\n"
1186 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1189 memset(&th_v, 0,
sizeof(th_v));
1191 memset(&f, 0,
sizeof(f));
1192 memset(&ssn, 0,
sizeof(ssn));
1199 f.
proto = IPPROTO_TCP;
1219 "(msg:\"http stat msg test\"; "
1221 "content:\"ef\"; http_stat_msg; distance:2; "
1256 static int DetectEngineHttpStatMsgTest15(
void)
1262 uint8_t http_buf1[] =
"GET /index.html HTTP/1.0\r\n"
1263 "Host: www.openinfosecfoundation.org\r\n"
1264 "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) "
1265 "Gecko/20091221 Firefox/3.5.7\r\n"
1267 uint32_t http_len1 =
sizeof(http_buf1) - 1;
1268 uint8_t http_buf2[] =
"HTTP/1.0 200 abcdef\r\n"
1269 "Content-Type: text/html\r\n"
1270 "Content-Length: 6\r\n"
1273 uint32_t http_len2 =
sizeof(http_buf2) - 1;
1276 memset(&th_v, 0,
sizeof(th_v));
1278 memset(&f, 0,
sizeof(f));
1279 memset(&ssn, 0,
sizeof(ssn));
1286 f.
proto = IPPROTO_TCP;
1307 "(msg:\"http stat msg test\"; "
1309 "content:!\"xyz\"; http_stat_msg; distance:0; within:3; "
1345 static int DetectHttpStatMsgSigTest01(
void)
1348 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1349 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1350 uint8_t httpbuf2[] =
"HTTP/1.0 200 OK\r\n\r\n";
1351 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1357 memset(&th_v, 0,
sizeof(th_v));
1359 memset(&f, 0,
sizeof(f));
1360 memset(&ssn, 0,
sizeof(ssn));
1366 f.
proto = IPPROTO_TCP;
1382 "\"HTTP status message\"; content:\"OK\"; "
1383 "http_stat_msg; sid:1;)");
1387 "Status message nocase\"; content:\"ok\"; nocase; "
1388 "http_stat_msg; sid:2;)");
1419 static int DetectHttpStatMsgSigTest02(
void)
1422 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1423 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1424 uint8_t httpbuf2[] =
"HTTP/1.0 200 OK\r\n\r\n";
1425 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1431 memset(&th_v, 0,
sizeof(th_v));
1433 memset(&f, 0,
sizeof(f));
1434 memset(&ssn, 0,
sizeof(ssn));
1440 f.
proto = IPPROTO_TCP;
1456 "\"HTTP status message\"; content:\"no\"; "
1457 "http_stat_msg; sid:1;)");
1488 static int DetectHttpStatMsgSigTest03(
void)
1491 uint8_t httpbuf1[] =
"POST / HTTP/1.0\r\nUser-Agent: Mozilla/1.0\r\n\r\n";
1492 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1493 uint8_t httpbuf2[] =
"HTTP/1.0 200 OK\r\n\r\n";
1494 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1500 memset(&th_v, 0,
sizeof(th_v));
1502 memset(&f, 0,
sizeof(f));
1503 memset(&ssn, 0,
sizeof(ssn));
1509 f.
proto = IPPROTO_TCP;
1525 "\"HTTP status message\"; content:\"ok\"; "
1526 "nocase; http_stat_msg; sid:1;)");
1530 "Status message nocase\"; content:!\"Not\"; "
1531 "http_stat_msg; sid:2;)");
1567 UtRegisterTest(
"DetectHttpStatMsgSigTest01", DetectHttpStatMsgSigTest01);
1568 UtRegisterTest(
"DetectHttpStatMsgSigTest02", DetectHttpStatMsgSigTest02);
1569 UtRegisterTest(
"DetectHttpStatMsgSigTest03", DetectHttpStatMsgSigTest03);
1571 UtRegisterTest(
"DetectEngineHttpStatMsgTest01", DetectEngineHttpStatMsgTest01);
1572 UtRegisterTest(
"DetectEngineHttpStatMsgTest02", DetectEngineHttpStatMsgTest02);
1573 UtRegisterTest(
"DetectEngineHttpStatMsgTest03", DetectEngineHttpStatMsgTest03);
1574 UtRegisterTest(
"DetectEngineHttpStatMsgTest04", DetectEngineHttpStatMsgTest04);
1575 UtRegisterTest(
"DetectEngineHttpStatMsgTest05", DetectEngineHttpStatMsgTest05);
1576 UtRegisterTest(
"DetectEngineHttpStatMsgTest06", DetectEngineHttpStatMsgTest06);
1577 UtRegisterTest(
"DetectEngineHttpStatMsgTest07", DetectEngineHttpStatMsgTest07);
1578 UtRegisterTest(
"DetectEngineHttpStatMsgTest08", DetectEngineHttpStatMsgTest08);
1579 UtRegisterTest(
"DetectEngineHttpStatMsgTest09", DetectEngineHttpStatMsgTest09);
1580 UtRegisterTest(
"DetectEngineHttpStatMsgTest10", DetectEngineHttpStatMsgTest10);
1581 UtRegisterTest(
"DetectEngineHttpStatMsgTest11", DetectEngineHttpStatMsgTest11);
1582 UtRegisterTest(
"DetectEngineHttpStatMsgTest12", DetectEngineHttpStatMsgTest12);
1583 UtRegisterTest(
"DetectEngineHttpStatMsgTest13", DetectEngineHttpStatMsgTest13);
1584 UtRegisterTest(
"DetectEngineHttpStatMsgTest14", DetectEngineHttpStatMsgTest14);
1585 UtRegisterTest(
"DetectEngineHttpStatMsgTest15", DetectEngineHttpStatMsgTest15);