52 static void DetectReplaceRegisterTests(
void);
61 "only to be used in IPS-mode. Change the following content into another"
62 "Banned from firewall rules & firewall mode usage.";
85 uint8_t *content = NULL;
89 SCLogError(
"Can't negate replacement string: %s", replacestr);
112 "preceding content option for raw sig");
126 "negated keyword set along with a replacement");
131 "length different from replace length");
180 newlist->
found = found;
183 newlist->
next = replist;
198 replist = replist->
next;
210 replist = replist->
next;
229 int DetectReplaceLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize,
230 const char *sig, uint32_t sid, uint8_t *pp,
247 SCLogDebug(
"replace: looks like a second run");
270 printf(
"relative next flag set on final match which is content: ");
284 SCLogDebug(
"replace: no alert on sig %d", sid);
311 static int DetectReplaceLongPatternMatchTestWrp(
const char *sig, uint32_t sid,
const char *sig_rep, uint32_t sid_rep)
319 uint8_t raw_eth_pkt[] = {
320 0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
321 0x00,0x00,0x00,0x00,0x08,0x00,0x45,0x00,
322 0x00,0x85,0x00,0x01,0x00,0x00,0x40,0x06,
323 0x7c,0x70,0x7f,0x00,0x00,0x01,0x7f,0x00,
324 0x00,0x01,0x00,0x14,0x00,0x50,0x00,0x00,
325 0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x02,
326 0x20,0x00,0xc9,0xad,0x00,0x00,0x48,0x69,
327 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
328 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
329 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
330 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
331 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
332 0x74,0x63,0x68,0x65,0x73,0x20,0x6f,0x66,
333 0x20,0x73,0x70,0x6c,0x69,0x74,0x74,0x65,
334 0x64,0x20,0x70,0x61,0x74,0x74,0x65,0x72,
335 0x6e,0x73,0x20,0x62,0x65,0x74,0x77,0x65,
336 0x65,0x6e,0x20,0x6d,0x75,0x6c,0x74,0x69,
337 0x70,0x6c,0x65,0x20,0x63,0x68,0x75,0x6e,
339 uint8_t
p[
sizeof(raw_eth_pkt)];
340 uint16_t psize =
sizeof(raw_eth_pkt);
345 ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
346 sig, sid,
p, &psize);
349 ret = DetectReplaceLongPatternMatchTest(
p, psize, sig_rep, sid_rep, NULL, NULL);
359 static int DetectReplaceLongPatternMatchTestUDPWrp(
const char *sig, uint32_t sid,
const char *sig_rep, uint32_t sid_rep)
364 uint8_t raw_eth_pkt[] = {
365 0x8c, 0xa9, 0x82, 0x75, 0x5d, 0x62, 0xb4, 0x07,
366 0xf9, 0xf3, 0xc7, 0x0a, 0x08, 0x00, 0x45, 0x00,
367 0x00, 0x3a, 0x92, 0x4f, 0x40, 0x00, 0x40, 0x11,
368 0x31, 0x1a, 0xc0, 0xa8, 0x00, 0x02, 0xc1, 0xbd,
369 0xf4, 0xe1, 0x3b, 0x7e, 0x00, 0x35, 0x00, 0x26,
370 0xcb, 0x81, 0x37, 0x62, 0x01, 0x00, 0x00, 0x01,
371 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x61,
372 0x31, 0x05, 0x74, 0x77, 0x69, 0x6d, 0x67, 0x03,
373 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01 };
375 uint8_t
p[
sizeof(raw_eth_pkt)];
376 uint16_t psize =
sizeof(raw_eth_pkt);
380 ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
381 sig, sid,
p, &psize);
383 SCLogDebug(
"replace: test1 phase1 ok: %" PRIuMAX
" vs %d",(uintmax_t)
sizeof(raw_eth_pkt),psize);
384 ret = DetectReplaceLongPatternMatchTest(
p, psize, sig_rep, sid_rep, NULL, NULL);
393 static int DetectReplaceMatchTest01(
void)
395 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
396 " content:\"big\"; replace:\"pig\"; sid:1;)";
397 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
398 " content:\"this is a pig test\"; sid:2;)";
399 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
406 static int DetectReplaceMatchTest02(
void)
408 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
409 " content:\"th\"; offset: 4; replace:\"TH\"; sid:1;)";
410 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
411 " content:\"THis\"; offset:4; sid:2;)";
412 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
419 static int DetectReplaceMatchTest03(
void)
421 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
422 " content:\"th\"; replace:\"TH\"; offset: 4; sid:1;)";
423 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
424 " content:\"THis\"; offset:4; sid:2;)";
425 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
432 static int DetectReplaceMatchTest04(
void)
434 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
435 " content:\"th\"; replace:\"TH\"; content:\"patter\"; replace:\"matter\"; sid:1;)";
436 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
437 " content:\"THis\"; content:\"matterns\"; sid:2;)";
438 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
445 static int DetectReplaceMatchTest05(
void)
447 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
448 " content:\"th\"; replace:\"TH\"; content:\"nutella\"; sid:1;)";
449 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
450 " content:\"TH\"; sid:2;)";
451 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
459 static int DetectReplaceMatchTest06(
void)
461 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
462 " content:\"nutella\"; replace:\"commode\"; content:\"this is\"; sid:1;)";
463 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
464 " content:\"commode\"; sid:2;)";
465 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
472 static int DetectReplaceMatchTest07(
void)
474 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
475 " content:\"BiG\"; nocase; replace:\"pig\"; sid:1;)";
476 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
477 " content:\"this is a pig test\"; sid:2;)";
478 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
485 static int DetectReplaceMatchTest08(
void)
487 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
488 " content:\"big\"; depth:17; replace:\"pig\"; sid:1;)";
489 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
490 " content:\"this is a pig test\"; sid:2;)";
491 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
498 static int DetectReplaceMatchTest09(
void)
500 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
501 " content:\"big\"; depth:16; replace:\"pig\"; sid:1;)";
502 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
503 " content:\"this is a pig test\"; sid:2;)";
504 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
511 static int DetectReplaceMatchTest10(
void)
513 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
514 " content:\"big\"; depth:17; replace:\"pig\"; offset: 14; sid:1;)";
515 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
516 " content:\"pig\"; depth:17; offset:14; sid:2;)";
517 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
524 static int DetectReplaceMatchTest11(
void)
526 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
527 " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 11; sid:1;)";
528 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
529 " content:\"pig\"; depth:17; offset:14; sid:2;)";
531 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
538 static int DetectReplaceMatchTest12(
void)
540 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
541 " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 4; sid:1;)";
542 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
543 " content:\"pig\"; depth:17; offset:14; sid:2;)";
544 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
551 static int DetectReplaceMatchTest13(
void)
553 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
554 " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 1; sid:1;)";
555 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
556 " content:\"pig\"; depth:17; offset:14; sid:2;)";
557 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
564 static int DetectReplaceMatchTest14(
void)
566 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
567 " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 2; sid:1;)";
568 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
569 " content:\"pig\"; depth:17; offset:14; sid:2;)";
570 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
577 static int DetectReplaceMatchTest15(
void)
579 const char *sig =
"alert udp any any -> any any (msg:\"Nothing..\";"
580 " content:\"com\"; replace:\"org\"; sid:1;)";
581 const char *sig_rep =
"alert udp any any -> any any (msg:\"replace worked\";"
582 " content:\"twimg|03|org\"; sid:2;)";
583 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestUDPWrp(sig, 1, sig_rep, 2));
591 static int DetectReplaceParseTest01(
void)
601 "alert udp any any -> any any "
602 "(msg:\"test\"; content:\"doh\"; replace:\"; sid:238012;)"));
612 static int DetectReplaceParseTest02(
void)
622 "alert http any any -> any any "
623 "(msg:\"test\"; content:\"doh\"; replace:\"bon\"; sid:238012;)"));
634 static int DetectReplaceParseTest03(
void)
645 "alert tcp any any -> any any "
646 "(msg:\"test\"; content:\"doh\"; replace:\"don\"; http_header; sid:238012;)"));
656 static int DetectReplaceParseTest04(
void)
666 "(msg:\"test\"; replace:\"don\"; sid:238012;)"));
676 static int DetectReplaceParseTest05(
void)
686 "alert tcp any any -> any any "
687 "(msg:\"test\"; replace:\"don\"; content:\"doh\"; sid:238012;)"));
697 static int DetectReplaceParseTest06(
void)
707 "alert tcp any any -> any any "
708 "(msg:\"test\"; content:\"don\"; replace:\"donut\"; sid:238012;)"));
718 static int DetectReplaceParseTest07(
void)
729 "(msg:\"test\"; content:\"don\"; replace:\"dou\"; "
730 "content:\"jpg\"; http_header; sid:238012;)"));
740 void DetectReplaceRegisterTests(
void)
743 UtRegisterTest(
"DetectReplaceMatchTest01", DetectReplaceMatchTest01);
744 UtRegisterTest(
"DetectReplaceMatchTest02", DetectReplaceMatchTest02);
745 UtRegisterTest(
"DetectReplaceMatchTest03", DetectReplaceMatchTest03);
746 UtRegisterTest(
"DetectReplaceMatchTest04", DetectReplaceMatchTest04);
747 UtRegisterTest(
"DetectReplaceMatchTest05", DetectReplaceMatchTest05);
748 UtRegisterTest(
"DetectReplaceMatchTest06", DetectReplaceMatchTest06);
749 UtRegisterTest(
"DetectReplaceMatchTest07", DetectReplaceMatchTest07);
750 UtRegisterTest(
"DetectReplaceMatchTest08", DetectReplaceMatchTest08);
751 UtRegisterTest(
"DetectReplaceMatchTest09", DetectReplaceMatchTest09);
752 UtRegisterTest(
"DetectReplaceMatchTest10", DetectReplaceMatchTest10);
753 UtRegisterTest(
"DetectReplaceMatchTest11", DetectReplaceMatchTest11);
754 UtRegisterTest(
"DetectReplaceMatchTest12", DetectReplaceMatchTest12);
755 UtRegisterTest(
"DetectReplaceMatchTest13", DetectReplaceMatchTest13);
756 UtRegisterTest(
"DetectReplaceMatchTest14", DetectReplaceMatchTest14);
757 UtRegisterTest(
"DetectReplaceMatchTest15", DetectReplaceMatchTest15);
759 UtRegisterTest(
"DetectReplaceParseTest01", DetectReplaceParseTest01);
760 UtRegisterTest(
"DetectReplaceParseTest02", DetectReplaceParseTest02);
761 UtRegisterTest(
"DetectReplaceParseTest03", DetectReplaceParseTest03);
762 UtRegisterTest(
"DetectReplaceParseTest04", DetectReplaceParseTest04);
763 UtRegisterTest(
"DetectReplaceParseTest05", DetectReplaceParseTest05);
764 UtRegisterTest(
"DetectReplaceParseTest06", DetectReplaceParseTest06);
765 UtRegisterTest(
"DetectReplaceParseTest07", DetectReplaceParseTest07);