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));
66 memset(&f, 0,
sizeof(f));
67 memset(&ssn, 0,
sizeof(ssn));
86 f.
proto = IPPROTO_TCP;
100 while (b->
input != NULL) {
143 static int DetectEngineHttpMethodTest01(
void)
146 { (
const uint8_t *)
"GET /index.html HTTP/1.1\r\n"
147 "Host: www.openinfosecfoundation.org\r\n"
149 0, STREAM_TOSERVER, 1 },
153 const char *sig =
"alert http any any -> any any (content:\"GET\"; http_method; sid:1;)";
154 return RunTest(steps, sig, NULL);
157 static int DetectEngineHttpMethodTest02(
void)
160 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
161 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
162 0, STREAM_TOSERVER, 1 },
167 "alert http any any -> any any (content:\"CO\"; depth:4; http_method; sid:1;)";
168 return RunTest(steps, sig, NULL);
171 static int DetectEngineHttpMethodTest03(
void)
174 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
175 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
176 0, STREAM_TOSERVER, 1 },
181 "alert http any any -> any any (content:!\"ECT\"; depth:4; http_method; sid:1;)";
182 return RunTest(steps, sig, NULL);
185 static int DetectEngineHttpMethodTest04(
void)
188 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
189 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
190 0, STREAM_TOSERVER, 0 },
195 "alert http any any -> any any (content:\"ECT\"; depth:4; http_method; sid:1;)";
196 return RunTest(steps, sig, NULL);
199 static int DetectEngineHttpMethodTest05(
void)
202 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
203 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
204 0, STREAM_TOSERVER, 0 },
209 "alert http any any -> any any (content:!\"CON\"; depth:4; http_method; sid:1;)";
210 return RunTest(steps, sig, NULL);
213 static int DetectEngineHttpMethodTest06(
void)
216 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
217 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
218 0, STREAM_TOSERVER, 1 },
223 "alert http any any -> any any (content:\"ECT\"; offset:3; http_method; sid:1;)";
224 return RunTest(steps, sig, NULL);
227 static int DetectEngineHttpMethodTest07(
void)
230 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
231 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
232 0, STREAM_TOSERVER, 1 },
237 "alert http any any -> any any (content:!\"CO\"; offset:3; http_method; sid:1;)";
238 return RunTest(steps, sig, NULL);
241 static int DetectEngineHttpMethodTest08(
void)
244 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
245 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
246 0, STREAM_TOSERVER, 0 },
251 "alert http any any -> any any (content:!\"ECT\"; offset:3; http_method; sid:1;)";
252 return RunTest(steps, sig, NULL);
255 static int DetectEngineHttpMethodTest09(
void)
258 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
259 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
260 0, STREAM_TOSERVER, 0 },
265 "alert http any any -> any any (content:\"CON\"; offset:3; http_method; sid:1;)";
266 return RunTest(steps, sig, NULL);
269 static int DetectEngineHttpMethodTest10(
void)
272 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
273 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
274 0, STREAM_TOSERVER, 1 },
278 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; content:\"EC\"; "
279 "within:4; http_method; sid:1;)";
280 return RunTest(steps, sig, NULL);
283 static int DetectEngineHttpMethodTest11(
void)
286 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
287 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
288 0, STREAM_TOSERVER, 1 },
292 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; "
293 "content:!\"EC\"; within:3; http_method; sid:1;)";
294 return RunTest(steps, sig, NULL);
297 static int DetectEngineHttpMethodTest12(
void)
300 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
301 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
302 0, STREAM_TOSERVER, 0 },
306 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; content:\"EC\"; "
307 "within:3; http_method; sid:1;)";
308 return RunTest(steps, sig, NULL);
311 static int DetectEngineHttpMethodTest13(
void)
314 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
315 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
316 0, STREAM_TOSERVER, 0 },
320 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; "
321 "content:!\"EC\"; within:4; http_method; sid:1;)";
322 return RunTest(steps, sig, NULL);
325 static int DetectEngineHttpMethodTest14(
void)
328 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
329 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
330 0, STREAM_TOSERVER, 1 },
334 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; content:\"EC\"; "
335 "distance:2; http_method; sid:1;)";
336 return RunTest(steps, sig, NULL);
339 static int DetectEngineHttpMethodTest15(
void)
342 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
343 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
344 0, STREAM_TOSERVER, 1 },
348 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; "
349 "content:!\"EC\"; distance:3; http_method; sid:1;)";
350 return RunTest(steps, sig, NULL);
353 static int DetectEngineHttpMethodTest16(
void)
356 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
357 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
358 0, STREAM_TOSERVER, 0 },
362 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; content:\"EC\"; "
363 "distance:3; http_method; sid:1;)";
364 return RunTest(steps, sig, NULL);
367 static int DetectEngineHttpMethodTest17(
void)
370 { (
const uint8_t *)
"CONNECT /index.html HTTP/1.0\r\n"
371 "Host: www.onetwothreefourfivesixseven.org\r\n\r\n",
372 0, STREAM_TOSERVER, 0 },
376 const char *sig =
"alert http any any -> any any (content:\"CO\"; http_method; "
377 "content:!\"EC\"; distance:2; http_method; sid:1;)";
378 return RunTest(steps, sig, NULL);
382 static int DetectHttpMethodTest01(
void)
388 "(msg:\"Testing http_method\"; "
390 "http_method; sid:1;)");
397 static int DetectHttpMethodTest02(
void)
403 "(msg:\"Testing http_method\"; "
404 "http_method; sid:1;)");
411 static int DetectHttpMethodTest03(
void)
417 "(msg:\"Testing http_method\"; "
418 "content:\"foobar\"; "
419 "http_method:\"GET\"; sid:1;)");
426 static int DetectHttpMethodTest04(
void)
432 "(msg:\"Testing http_method\"; "
435 "http_method; sid:1;)");
442 static int DetectHttpMethodTest05(
void)
448 "(msg:\"Testing http_method\"; "
451 "http_method; sid:1;)");
458 static int DetectHttpMethodSigTest01(
void)
461 uint8_t httpbuf1[] =
"GET / HTTP/1.0\r\n"
462 "Host: foo.bar.tld\r\n"
464 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
471 memset(&th_v, 0,
sizeof(th_v));
472 memset(&f, 0,
sizeof(f));
473 memset(&ssn, 0,
sizeof(ssn));
479 f.
proto = IPPROTO_TCP;
495 "(msg:\"Testing http_method\"; "
497 "http_method; sid:1;)");
500 "(msg:\"Testing http_method\"; "
502 "http_method; sid:2;)");
532 static int DetectHttpMethodSigTest02(
void)
535 uint8_t httpbuf1[] =
"FOO / HTTP/1.0\r\n"
536 "Host: foo.bar.tld\r\n"
538 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
545 memset(&th_v, 0,
sizeof(th_v));
546 memset(&f, 0,
sizeof(f));
547 memset(&ssn, 0,
sizeof(ssn));
553 f.
proto = IPPROTO_TCP;
569 "(msg:\"Testing http_method\"; "
571 "http_method; sid:1;)");
574 "(msg:\"Testing http_method\"; "
576 "http_method; sid:2;)");
604 static int DetectHttpMethodSigTest03(
void)
607 uint8_t httpbuf1[] =
" ";
608 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
616 memset(&th_v, 0,
sizeof(th_v));
617 memset(&f, 0,
sizeof(f));
618 memset(&ssn, 0,
sizeof(ssn));
624 f.
proto = IPPROTO_TCP;
640 "(msg:\"Testing http_method\"; "
642 "http_method; sid:1;)");
668 static int DetectHttpMethodSigTest04(
void)
671 uint8_t httpbuf1[] =
"GET / HTTP/1.0\r\n"
672 "Host: foo.bar.tld\r\n"
674 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
682 memset(&th_v, 0,
sizeof(th_v));
683 memset(&f, 0,
sizeof(f));
684 memset(&ssn, 0,
sizeof(ssn));
690 f.
proto = IPPROTO_TCP;
706 "alert tcp any any -> any any (msg:\"Testing http_method\"; "
707 "content:\"GET\"; http_method; sid:1;)");
711 "content:!\"GET\"; http_method; sid:2;)");
739 static int DetectHttpMethodIsdataatParseTest(
void)
746 "alert tcp any any -> any any ("
747 "content:\"one\"; http_method; "
748 "isdataat:!4,relative; sid:1;)");
774 UtRegisterTest(
"DetectHttpMethodSigTest01", DetectHttpMethodSigTest01);
775 UtRegisterTest(
"DetectHttpMethodSigTest02", DetectHttpMethodSigTest02);
776 UtRegisterTest(
"DetectHttpMethodSigTest03", DetectHttpMethodSigTest03);
777 UtRegisterTest(
"DetectHttpMethodSigTest04", DetectHttpMethodSigTest04);
780 DetectHttpMethodIsdataatParseTest);
782 DetectEngineHttpMethodTest01);
784 DetectEngineHttpMethodTest02);
786 DetectEngineHttpMethodTest03);
788 DetectEngineHttpMethodTest04);
790 DetectEngineHttpMethodTest05);
792 DetectEngineHttpMethodTest06);
794 DetectEngineHttpMethodTest07);
796 DetectEngineHttpMethodTest08);
798 DetectEngineHttpMethodTest09);
800 DetectEngineHttpMethodTest10);
802 DetectEngineHttpMethodTest11);
804 DetectEngineHttpMethodTest12);
806 DetectEngineHttpMethodTest13);
808 DetectEngineHttpMethodTest14);
810 DetectEngineHttpMethodTest15);
812 DetectEngineHttpMethodTest16);
814 DetectEngineHttpMethodTest17);