53 static void DetectReplaceRegisterTests(
void);
62 "only to be used in IPS-mode. Change the following content into another"
63 "Banned from firewall rules & firewall mode usage.";
86 uint8_t *content = NULL;
90 SCLogError(
"Can't negate replacement string: %s", replacestr);
113 "preceding content option for raw sig");
127 "negated keyword set along with a replacement");
132 "length different from replace length");
181 newlist->
found = found;
184 newlist->
next = replist;
199 replist = replist->
next;
211 replist = replist->
next;
230 int DetectReplaceLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize,
231 const char *sig, uint32_t sid, uint8_t *pp,
248 SCLogDebug(
"replace: looks like a second run");
271 printf(
"relative next flag set on final match which is content: ");
285 SCLogDebug(
"replace: no alert on sig %d", sid);
312 static int DetectReplaceLongPatternMatchTestWrp(
const char *sig, uint32_t sid,
const char *sig_rep, uint32_t sid_rep)
320 uint8_t raw_eth_pkt[] = {
321 0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
322 0x00,0x00,0x00,0x00,0x08,0x00,0x45,0x00,
323 0x00,0x85,0x00,0x01,0x00,0x00,0x40,0x06,
324 0x7c,0x70,0x7f,0x00,0x00,0x01,0x7f,0x00,
325 0x00,0x01,0x00,0x14,0x00,0x50,0x00,0x00,
326 0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x02,
327 0x20,0x00,0xc9,0xad,0x00,0x00,0x48,0x69,
328 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
329 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
330 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
331 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
332 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
333 0x74,0x63,0x68,0x65,0x73,0x20,0x6f,0x66,
334 0x20,0x73,0x70,0x6c,0x69,0x74,0x74,0x65,
335 0x64,0x20,0x70,0x61,0x74,0x74,0x65,0x72,
336 0x6e,0x73,0x20,0x62,0x65,0x74,0x77,0x65,
337 0x65,0x6e,0x20,0x6d,0x75,0x6c,0x74,0x69,
338 0x70,0x6c,0x65,0x20,0x63,0x68,0x75,0x6e,
340 uint8_t
p[
sizeof(raw_eth_pkt)];
341 uint16_t psize =
sizeof(raw_eth_pkt);
346 ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
347 sig, sid,
p, &psize);
350 ret = DetectReplaceLongPatternMatchTest(
p, psize, sig_rep, sid_rep, NULL, NULL);
360 static int DetectReplaceLongPatternMatchTestUDPWrp(
const char *sig, uint32_t sid,
const char *sig_rep, uint32_t sid_rep)
365 uint8_t raw_eth_pkt[] = {
366 0x8c, 0xa9, 0x82, 0x75, 0x5d, 0x62, 0xb4, 0x07,
367 0xf9, 0xf3, 0xc7, 0x0a, 0x08, 0x00, 0x45, 0x00,
368 0x00, 0x3a, 0x92, 0x4f, 0x40, 0x00, 0x40, 0x11,
369 0x31, 0x1a, 0xc0, 0xa8, 0x00, 0x02, 0xc1, 0xbd,
370 0xf4, 0xe1, 0x3b, 0x7e, 0x00, 0x35, 0x00, 0x26,
371 0xcb, 0x81, 0x37, 0x62, 0x01, 0x00, 0x00, 0x01,
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x61,
373 0x31, 0x05, 0x74, 0x77, 0x69, 0x6d, 0x67, 0x03,
374 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01 };
376 uint8_t
p[
sizeof(raw_eth_pkt)];
377 uint16_t psize =
sizeof(raw_eth_pkt);
381 ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
382 sig, sid,
p, &psize);
384 SCLogDebug(
"replace: test1 phase1 ok: %" PRIuMAX
" vs %d",(uintmax_t)
sizeof(raw_eth_pkt),psize);
385 ret = DetectReplaceLongPatternMatchTest(
p, psize, sig_rep, sid_rep, NULL, NULL);
394 static int DetectReplaceMatchTest01(
void)
396 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
397 " content:\"big\"; replace:\"pig\"; sid:1;)";
398 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
399 " content:\"this is a pig test\"; sid:2;)";
400 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
407 static int DetectReplaceMatchTest02(
void)
409 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
410 " content:\"th\"; offset: 4; replace:\"TH\"; sid:1;)";
411 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
412 " content:\"THis\"; offset:4; sid:2;)";
413 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
420 static int DetectReplaceMatchTest03(
void)
422 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
423 " content:\"th\"; replace:\"TH\"; offset: 4; sid:1;)";
424 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
425 " content:\"THis\"; offset:4; sid:2;)";
426 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
433 static int DetectReplaceMatchTest04(
void)
435 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
436 " content:\"th\"; replace:\"TH\"; content:\"patter\"; replace:\"matter\"; sid:1;)";
437 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
438 " content:\"THis\"; content:\"matterns\"; sid:2;)";
439 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
446 static int DetectReplaceMatchTest05(
void)
448 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
449 " content:\"th\"; replace:\"TH\"; content:\"nutella\"; sid:1;)";
450 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
451 " content:\"TH\"; sid:2;)";
452 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
460 static int DetectReplaceMatchTest06(
void)
462 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
463 " content:\"nutella\"; replace:\"commode\"; content:\"this is\"; sid:1;)";
464 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
465 " content:\"commode\"; sid:2;)";
466 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
473 static int DetectReplaceMatchTest07(
void)
475 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
476 " content:\"BiG\"; nocase; replace:\"pig\"; sid:1;)";
477 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
478 " content:\"this is a pig test\"; sid:2;)";
479 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
486 static int DetectReplaceMatchTest08(
void)
488 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
489 " content:\"big\"; depth:17; replace:\"pig\"; sid:1;)";
490 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
491 " content:\"this is a pig test\"; sid:2;)";
492 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
499 static int DetectReplaceMatchTest09(
void)
501 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
502 " content:\"big\"; depth:16; replace:\"pig\"; sid:1;)";
503 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
504 " content:\"this is a pig test\"; sid:2;)";
505 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
512 static int DetectReplaceMatchTest10(
void)
514 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
515 " content:\"big\"; depth:17; replace:\"pig\"; offset: 14; sid:1;)";
516 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
517 " content:\"pig\"; depth:17; offset:14; sid:2;)";
518 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
525 static int DetectReplaceMatchTest11(
void)
527 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
528 " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 11; sid:1;)";
529 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
530 " content:\"pig\"; depth:17; offset:14; sid:2;)";
532 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
539 static int DetectReplaceMatchTest12(
void)
541 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
542 " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 4; sid:1;)";
543 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
544 " content:\"pig\"; depth:17; offset:14; sid:2;)";
545 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
552 static int DetectReplaceMatchTest13(
void)
554 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
555 " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 1; sid:1;)";
556 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
557 " content:\"pig\"; depth:17; offset:14; sid:2;)";
558 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
565 static int DetectReplaceMatchTest14(
void)
567 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
568 " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 2; sid:1;)";
569 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
570 " content:\"pig\"; depth:17; offset:14; sid:2;)";
571 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
578 static int DetectReplaceMatchTest15(
void)
580 const char *sig =
"alert udp any any -> any any (msg:\"Nothing..\";"
581 " content:\"com\"; replace:\"org\"; sid:1;)";
582 const char *sig_rep =
"alert udp any any -> any any (msg:\"replace worked\";"
583 " content:\"twimg|03|org\"; sid:2;)";
584 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestUDPWrp(sig, 1, sig_rep, 2));
592 static int DetectReplaceParseTest01(
void)
602 "alert udp any any -> any any "
603 "(msg:\"test\"; content:\"doh\"; replace:\"; sid:238012;)"));
613 static int DetectReplaceParseTest02(
void)
623 "alert http any any -> any any "
624 "(msg:\"test\"; content:\"doh\"; replace:\"bon\"; sid:238012;)"));
635 static int DetectReplaceParseTest03(
void)
646 "alert tcp any any -> any any "
647 "(msg:\"test\"; content:\"doh\"; replace:\"don\"; http_header; sid:238012;)"));
657 static int DetectReplaceParseTest04(
void)
667 "(msg:\"test\"; replace:\"don\"; sid:238012;)"));
677 static int DetectReplaceParseTest05(
void)
687 "alert tcp any any -> any any "
688 "(msg:\"test\"; replace:\"don\"; content:\"doh\"; sid:238012;)"));
698 static int DetectReplaceParseTest06(
void)
708 "alert tcp any any -> any any "
709 "(msg:\"test\"; content:\"don\"; replace:\"donut\"; sid:238012;)"));
719 static int DetectReplaceParseTest07(
void)
730 "(msg:\"test\"; content:\"don\"; replace:\"dou\"; "
731 "content:\"jpg\"; http_header; sid:238012;)"));
741 void DetectReplaceRegisterTests(
void)
744 UtRegisterTest(
"DetectReplaceMatchTest01", DetectReplaceMatchTest01);
745 UtRegisterTest(
"DetectReplaceMatchTest02", DetectReplaceMatchTest02);
746 UtRegisterTest(
"DetectReplaceMatchTest03", DetectReplaceMatchTest03);
747 UtRegisterTest(
"DetectReplaceMatchTest04", DetectReplaceMatchTest04);
748 UtRegisterTest(
"DetectReplaceMatchTest05", DetectReplaceMatchTest05);
749 UtRegisterTest(
"DetectReplaceMatchTest06", DetectReplaceMatchTest06);
750 UtRegisterTest(
"DetectReplaceMatchTest07", DetectReplaceMatchTest07);
751 UtRegisterTest(
"DetectReplaceMatchTest08", DetectReplaceMatchTest08);
752 UtRegisterTest(
"DetectReplaceMatchTest09", DetectReplaceMatchTest09);
753 UtRegisterTest(
"DetectReplaceMatchTest10", DetectReplaceMatchTest10);
754 UtRegisterTest(
"DetectReplaceMatchTest11", DetectReplaceMatchTest11);
755 UtRegisterTest(
"DetectReplaceMatchTest12", DetectReplaceMatchTest12);
756 UtRegisterTest(
"DetectReplaceMatchTest13", DetectReplaceMatchTest13);
757 UtRegisterTest(
"DetectReplaceMatchTest14", DetectReplaceMatchTest14);
758 UtRegisterTest(
"DetectReplaceMatchTest15", DetectReplaceMatchTest15);
760 UtRegisterTest(
"DetectReplaceParseTest01", DetectReplaceParseTest01);
761 UtRegisterTest(
"DetectReplaceParseTest02", DetectReplaceParseTest02);
762 UtRegisterTest(
"DetectReplaceParseTest03", DetectReplaceParseTest03);
763 UtRegisterTest(
"DetectReplaceParseTest04", DetectReplaceParseTest04);
764 UtRegisterTest(
"DetectReplaceParseTest05", DetectReplaceParseTest05);
765 UtRegisterTest(
"DetectReplaceParseTest06", DetectReplaceParseTest06);
766 UtRegisterTest(
"DetectReplaceParseTest07", DetectReplaceParseTest07);