66 static void DetectDnsQueryRegisterTests(
void);
68 static int g_dns_query_buffer_id = 0;
72 int list_id, uint32_t local_id)
84 if (SCDnsTxGetQueryName(txv,
false, local_id, &data, &data_len) == 0) {
114 "dns request query");
156 static int DetectDnsQueryTest01(
void)
159 uint8_t buf[] = { 0x10, 0x32, 0x01, 0x00, 0x00, 0x01,
160 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
161 0x06, 0x67, 0x6F, 0x6F, 0x67, 0x6C,
162 0x65, 0x03, 0x63, 0x6F, 0x6D, 0x00,
163 0x00, 0x10, 0x00, 0x01, };
165 void *dns_state = NULL;
173 memset(&f, 0,
sizeof(
Flow));
176 "192.168.1.5",
"192.168.1.1",
181 f.
proto = IPPROTO_UDP;
195 "(msg:\"Test dns_query option\"; "
196 "dns_query; content:\"google\"; nocase; sid:1;)");
203 STREAM_TOSERVER, buf,
sizeof(buf));
205 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
216 printf(
"sig 1 didn't alert, but it should have: ");
235 static int DetectDnsQueryTest02(
void)
238 uint8_t buf1[] = { 0x10, 0x32, 0x01, 0x00, 0x00, 0x01,
239 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x06, 0x67, 0x6F, 0x6F, 0x67, 0x6C,
241 0x65, 0x03, 0x63, 0x6F, 0x6D, 0x00,
242 0x00, 0x01, 0x00, 0x01, };
244 uint8_t buf2[] = { 0x10, 0x32,
248 0x00, 0x00, 0x00, 0x00,
250 0x06, 0x67, 0x6F, 0x6F, 0x67, 0x6C,
251 0x65, 0x03, 0x63, 0x6F, 0x6D, 0x00,
252 0x00, 0x01, 0x00, 0x01,
255 0x00, 0x01, 0x00, 0x01,
256 0x00, 0x01, 0x40, 0xef,
258 0x01, 0x02, 0x03, 0x04 };
261 uint8_t buf3[] = { 0x11, 0x33, 0x01, 0x00, 0x00, 0x01,
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263 0x06, 0x67, 0x6F, 0x6F, 0x67, 0x6C,
264 0x65, 0x03, 0x6E, 0x65, 0x74, 0x00,
265 0x00, 0x10, 0x00, 0x01, };
267 void *dns_state = NULL;
268 Packet *p1 = NULL, *p2 = NULL, *p3 = NULL;
275 memset(&f, 0,
sizeof(
Flow));
278 "192.168.1.5",
"192.168.1.1",
281 "192.168.1.5",
"192.168.1.1",
284 "192.168.1.5",
"192.168.1.1",
289 f.
proto = IPPROTO_UDP;
314 "(msg:\"Test dns_query option\"; "
315 "dns_query; content:\"google.com\"; nocase; sid:1;)");
318 "(msg:\"Test dns_query option\"; "
319 "dns_query; content:\"google.net\"; nocase; sid:2;)");
326 STREAM_TOSERVER, buf1,
sizeof(buf1));
328 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
339 printf(
"(p1) sig 1 didn't alert, but it should have: ");
343 printf(
"(p1) sig 2 did alert, but it should not have: ");
350 printf(
"toserver client 1 returned %" PRId32
", expected 0: ", r);
358 printf(
"(p2) sig 1 alerted, but it should not have: ");
362 printf(
"(p2) sig 2 alerted, but it should not have: ");
369 printf(
"toserver chunk 3 returned %" PRId32
", expected 0: ", r);
377 printf(
"(p3) sig 1 alerted, but it should not have: ");
381 printf(
"(p3) sig 2 didn't alert, but it should have: ");
402 static int DetectDnsQueryTest03(
void)
405 uint8_t buf[] = { 0x00, 28,
406 0x10, 0x32, 0x01, 0x00, 0x00, 0x01,
407 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
408 0x06, 0x67, 0x6F, 0x6F, 0x67, 0x6C,
409 0x65, 0x03, 0x63, 0x6F, 0x6D, 0x00,
410 0x00, 0x10, 0x00, 0x01, };
412 void *dns_state = NULL;
421 memset(&f, 0,
sizeof(
Flow));
425 "192.168.1.5",
"192.168.1.1",
431 f.
proto = IPPROTO_TCP;
447 "(msg:\"Test dns_query option\"; "
448 "dns_query; content:\"google\"; nocase; sid:1;)");
455 STREAM_TOSERVER, buf,
sizeof(buf));
457 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
468 printf(
"sig 1 didn't alert, but it should have: ");
489 static int DetectDnsQueryTest04(
void)
492 uint8_t buf[] = { 0x10, 0x32, 0x01, 0x00, 0x00, 0x01,
493 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
494 0x06, 0x67, 0x6F, 0x6F, 0x67, 0x6C,
495 0x65, 0x03, 0x63, 0x6F, 0x6D, 0x00,
496 0x00, 0x10, 0x00, 0x01, };
498 void *dns_state = NULL;
506 memset(&f, 0,
sizeof(
Flow));
509 "192.168.1.5",
"192.168.1.1",
514 f.
proto = IPPROTO_UDP;
528 "(msg:\"Test dns_query option\"; "
529 "dns_query; content:\"google\"; nocase; "
530 "pcre:\"/google\\.com$/i\"; sid:1;)");
533 "(msg:\"Test dns_query option\"; "
534 "dns_query; content:\"google\"; nocase; "
535 "pcre:\"/^\\.[a-z]{2,3}$/iR\"; sid:2;)");
542 STREAM_TOSERVER, buf,
sizeof(buf));
544 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
555 printf(
"sig 1 didn't alert, but it should have: ");
559 printf(
"sig 2 didn't alert, but it should have: ");
579 static int DetectDnsQueryTest05(
void)
582 uint8_t buf1[] = { 0x10, 0x32, 0x01, 0x00, 0x00, 0x01,
583 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
584 0x06, 0x67, 0x6F, 0x6F, 0x67, 0x6C,
585 0x65, 0x03, 0x63, 0x6F, 0x6D, 0x00,
586 0x00, 0x01, 0x00, 0x01, };
588 uint8_t buf2[] = { 0x10, 0x32,
592 0x00, 0x00, 0x00, 0x00,
594 0x06, 0x67, 0x6F, 0x6F, 0x67, 0x6C,
595 0x65, 0x03, 0x63, 0x6F, 0x6D, 0x00,
596 0x00, 0x01, 0x00, 0x01,
599 0x00, 0x01, 0x00, 0x01,
600 0x00, 0x01, 0x40, 0xef,
602 0x01, 0x02, 0x03, 0x04 };
605 uint8_t buf3[] = { 0x11, 0x33, 0x01, 0x00, 0x00, 0x01,
606 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
607 0x06, 0x67, 0x6F, 0x6F, 0x67, 0x6C,
608 0x65, 0x03, 0x6E, 0x65, 0x74, 0x00,
609 0x00, 0x10, 0x00, 0x01, };
611 void *dns_state = NULL;
612 Packet *p1 = NULL, *p2 = NULL, *p3 = NULL;
619 memset(&f, 0,
sizeof(
Flow));
622 "192.168.1.5",
"192.168.1.1",
625 "192.168.1.5",
"192.168.1.1",
628 "192.168.1.5",
"192.168.1.1",
633 f.
proto = IPPROTO_UDP;
658 "(msg:\"Test dns_query option\"; "
659 "dns_query; content:\"google.com\"; nocase; sid:1;)");
662 "(msg:\"Test dns_query option\"; "
663 "dns_query; content:\"google.net\"; nocase; sid:2;)");
666 "(msg:\"Test Z flag event\"; "
667 "app-layer-event:dns.z_flag_set; sid:3;)");
674 STREAM_TOSERVER, buf1,
sizeof(buf1));
676 printf(
"toserver chunk 1 returned %" PRId32
", expected 0: ", r);
687 printf(
"(p1) sig 1 didn't alert, but it should have: ");
691 printf(
"(p1) sig 2 did alert, but it should not have: ");
698 printf(
"toserver client 1 returned %" PRId32
", expected 0\n", r);
706 printf(
"(p2) sig 1 alerted, but it should not have: ");
710 printf(
"(p2) sig 2 alerted, but it should not have: ");
714 printf(
"(p2) sig 3 didn't alert, but it should have: ");
721 printf(
"toserver chunk 3 returned %" PRId32
", expected 0: ", r);
729 printf(
"(p3) sig 1 alerted, but it should not have: ");
733 printf(
"(p3) sig 2 didn't alert, but it should have: ");
759 static void DetectDnsQueryRegisterTests(
void)
763 UtRegisterTest(
"DetectDnsQueryTest03 -- tcp", DetectDnsQueryTest03);
764 UtRegisterTest(
"DetectDnsQueryTest04 -- pcre", DetectDnsQueryTest04);
765 UtRegisterTest(
"DetectDnsQueryTest05 -- app layer event", DetectDnsQueryTest05);