33 #include "../suricata-common.h"
34 #include "../suricata.h"
35 #include "../flow-util.h"
37 #include "../app-layer-parser.h"
39 #include "../conf-yaml-loader.h"
40 #include "../util-unittest.h"
41 #include "../util-unittest-helper.h"
42 #include "../app-layer.h"
43 #include "../app-layer-htp.h"
44 #include "../app-layer-protos.h"
45 #include "../detect-isdataat.h"
46 #include "../detect-engine-build.h"
47 #include "../detect-engine-alert.h"
56 static int RunTest(
struct TestSteps *steps,
const char *sig,
const char *yaml)
65 memset(&th_v, 0,
sizeof(th_v));
67 memset(&f, 0,
sizeof(f));
68 memset(&ssn, 0,
sizeof(ssn));
87 f.
proto = IPPROTO_TCP;
101 while (b->
input != NULL) {
144 static int DetectEngineHttpMethodTest01(
void)
147 { (
const uint8_t *)
"GET /index.html HTTP/1.1\r\n"
148 "Host: www.openinfosecfoundation.org\r\n"
150 0, STREAM_TOSERVER, 1 },
154 const char *sig =
"alert http any any -> any any (content:\"GET\"; http_method; sid:1;)";
155 return RunTest(steps, sig, NULL);
158 static int DetectEngineHttpMethodTest02(
void)
161 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
162 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
163 0, STREAM_TOSERVER, 1 },
168 "alert http any any -> any any (content:\"CO\"; depth:4; http_method; sid:1;)";
169 return RunTest(steps, sig, NULL);
172 static int DetectEngineHttpMethodTest03(
void)
175 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
176 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
177 0, STREAM_TOSERVER, 1 },
182 "alert http any any -> any any (content:!\"ECT\"; depth:4; http_method; sid:1;)";
183 return RunTest(steps, sig, NULL);
186 static int DetectEngineHttpMethodTest04(
void)
189 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
190 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
191 0, STREAM_TOSERVER, 0 },
196 "alert http any any -> any any (content:\"ECT\"; depth:4; http_method; sid:1;)";
197 return RunTest(steps, sig, NULL);
200 static int DetectEngineHttpMethodTest05(
void)
203 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
204 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
205 0, STREAM_TOSERVER, 0 },
210 "alert http any any -> any any (content:!\"CON\"; depth:4; http_method; sid:1;)";
211 return RunTest(steps, sig, NULL);
214 static int DetectEngineHttpMethodTest06(
void)
217 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
218 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
219 0, STREAM_TOSERVER, 1 },
224 "alert http any any -> any any (content:\"ECT\"; offset:3; http_method; sid:1;)";
225 return RunTest(steps, sig, NULL);
228 static int DetectEngineHttpMethodTest07(
void)
231 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
232 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
233 0, STREAM_TOSERVER, 1 },
238 "alert http any any -> any any (content:!\"CO\"; offset:3; http_method; sid:1;)";
239 return RunTest(steps, sig, NULL);
242 static int DetectEngineHttpMethodTest08(
void)
245 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
246 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
247 0, STREAM_TOSERVER, 0 },
252 "alert http any any -> any any (content:!\"ECT\"; offset:3; http_method; sid:1;)";
253 return RunTest(steps, sig, NULL);
256 static int DetectEngineHttpMethodTest09(
void)
259 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
260 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
261 0, STREAM_TOSERVER, 0 },
266 "alert http any any -> any any (content:\"CON\"; offset:3; http_method; sid:1;)";
267 return RunTest(steps, sig, NULL);
270 static int DetectEngineHttpMethodTest10(
void)
273 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
274 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
275 0, STREAM_TOSERVER, 1 },
279 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; content:\"EC\"; "
280 "within:4; http_method; sid:1;)";
281 return RunTest(steps, sig, NULL);
284 static int DetectEngineHttpMethodTest11(
void)
287 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
288 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
289 0, STREAM_TOSERVER, 1 },
293 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; "
294 "content:!\"EC\"; within:3; http_method; sid:1;)";
295 return RunTest(steps, sig, NULL);
298 static int DetectEngineHttpMethodTest12(
void)
301 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
302 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
303 0, STREAM_TOSERVER, 0 },
307 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; content:\"EC\"; "
308 "within:3; http_method; sid:1;)";
309 return RunTest(steps, sig, NULL);
312 static int DetectEngineHttpMethodTest13(
void)
315 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
316 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
317 0, STREAM_TOSERVER, 0 },
321 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; "
322 "content:!\"EC\"; within:4; http_method; sid:1;)";
323 return RunTest(steps, sig, NULL);
326 static int DetectEngineHttpMethodTest14(
void)
329 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
330 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
331 0, STREAM_TOSERVER, 1 },
335 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; content:\"EC\"; "
336 "distance:2; http_method; sid:1;)";
337 return RunTest(steps, sig, NULL);
340 static int DetectEngineHttpMethodTest15(
void)
343 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
344 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
345 0, STREAM_TOSERVER, 1 },
349 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; "
350 "content:!\"EC\"; distance:3; http_method; sid:1;)";
351 return RunTest(steps, sig, NULL);
354 static int DetectEngineHttpMethodTest16(
void)
357 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
358 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
359 0, STREAM_TOSERVER, 0 },
363 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; content:\"EC\"; "
364 "distance:3; http_method; sid:1;)";
365 return RunTest(steps, sig, NULL);
368 static int DetectEngineHttpMethodTest17(
void)
371 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
372 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
373 0, STREAM_TOSERVER, 0 },
377 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; "
378 "content:!\"EC\"; distance:2; http_method; sid:1;)";
379 return RunTest(steps, sig, NULL);
383 static int DetectHttpMethodTest01(
void)
389 "(msg:\"Testing http_method\"; "
391 "http_method; sid:1;)");
398 static int DetectHttpMethodTest02(
void)
404 "(msg:\"Testing http_method\"; "
405 "http_method; sid:1;)");
412 static int DetectHttpMethodTest03(
void)
418 "(msg:\"Testing http_method\"; "
419 "content:\"foobar\"; "
420 "http_method:\"GET\"; sid:1;)");
427 static int DetectHttpMethodTest04(
void)
433 "(msg:\"Testing http_method\"; "
436 "http_method; sid:1;)");
443 static int DetectHttpMethodTest05(
void)
449 "(msg:\"Testing http_method\"; "
452 "http_method; sid:1;)");
459 static int DetectHttpMethodSigTest01(
void)
462 uint8_t httpbuf1[] =
"GET / HTTP/1.0\r\n"
463 "Host: foo.bar.tld\r\n"
465 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
472 memset(&th_v, 0,
sizeof(th_v));
474 memset(&f, 0,
sizeof(f));
475 memset(&ssn, 0,
sizeof(ssn));
481 f.
proto = IPPROTO_TCP;
497 "(msg:\"Testing http_method\"; "
499 "http_method; sid:1;)");
502 "(msg:\"Testing http_method\"; "
504 "http_method; sid:2;)");
534 static int DetectHttpMethodSigTest02(
void)
537 uint8_t httpbuf1[] =
"FOO / HTTP/1.0\r\n"
538 "Host: foo.bar.tld\r\n"
540 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
547 memset(&th_v, 0,
sizeof(th_v));
549 memset(&f, 0,
sizeof(f));
550 memset(&ssn, 0,
sizeof(ssn));
556 f.
proto = IPPROTO_TCP;
572 "(msg:\"Testing http_method\"; "
574 "http_method; sid:1;)");
577 "(msg:\"Testing http_method\"; "
579 "http_method; sid:2;)");
607 static int DetectHttpMethodSigTest03(
void)
610 uint8_t httpbuf1[] =
" ";
611 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
619 memset(&th_v, 0,
sizeof(th_v));
621 memset(&f, 0,
sizeof(f));
622 memset(&ssn, 0,
sizeof(ssn));
628 f.
proto = IPPROTO_TCP;
644 "(msg:\"Testing http_method\"; "
646 "http_method; sid:1;)");
672 static int DetectHttpMethodSigTest04(
void)
675 uint8_t httpbuf1[] =
"GET / HTTP/1.0\r\n"
676 "Host: foo.bar.tld\r\n"
678 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
686 memset(&th_v, 0,
sizeof(th_v));
688 memset(&f, 0,
sizeof(f));
689 memset(&ssn, 0,
sizeof(ssn));
695 f.
proto = IPPROTO_TCP;
711 "alert tcp any any -> any any (msg:\"Testing http_method\"; "
712 "content:\"GET\"; http_method; sid:1;)");
716 "content:!\"GET\"; http_method; sid:2;)");
744 static int DetectHttpMethodIsdataatParseTest(
void)
751 "alert tcp any any -> any any ("
752 "content:\"one\"; http_method; "
753 "isdataat:!4,relative; sid:1;)");
779 UtRegisterTest(
"DetectHttpMethodSigTest01", DetectHttpMethodSigTest01);
780 UtRegisterTest(
"DetectHttpMethodSigTest02", DetectHttpMethodSigTest02);
781 UtRegisterTest(
"DetectHttpMethodSigTest03", DetectHttpMethodSigTest03);
782 UtRegisterTest(
"DetectHttpMethodSigTest04", DetectHttpMethodSigTest04);
785 DetectHttpMethodIsdataatParseTest);
787 DetectEngineHttpMethodTest01);
789 DetectEngineHttpMethodTest02);
791 DetectEngineHttpMethodTest03);
793 DetectEngineHttpMethodTest04);
795 DetectEngineHttpMethodTest05);
797 DetectEngineHttpMethodTest06);
799 DetectEngineHttpMethodTest07);
801 DetectEngineHttpMethodTest08);
803 DetectEngineHttpMethodTest09);
805 DetectEngineHttpMethodTest10);
807 DetectEngineHttpMethodTest11);
809 DetectEngineHttpMethodTest12);
811 DetectEngineHttpMethodTest13);
813 DetectEngineHttpMethodTest14);
815 DetectEngineHttpMethodTest15);
817 DetectEngineHttpMethodTest16);
819 DetectEngineHttpMethodTest17);