53 static void DetectReplaceRegisterTests(
void);
83 uint8_t *content = NULL;
87 SCLogError(
"Can't negate replacement string: %s", replacestr);
110 "preceding content option for raw sig");
124 "negated keyword set along with a replacement");
129 "length different from replace length");
177 newlist->
found = found;
180 newlist->
next = replist;
195 replist = replist->
next;
207 replist = replist->
next;
226 int DetectReplaceLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize,
227 const char *sig, uint32_t sid, uint8_t *pp,
243 SCLogDebug(
"replace: looks like a second run");
248 memset(&th_v, 0,
sizeof(th_v));
271 printf(
"relative next flag set on final match which is content: ");
284 SCLogDebug(
"replace: no alert on sig %d", sid);
314 static int DetectReplaceLongPatternMatchTestWrp(
const char *sig, uint32_t sid,
const char *sig_rep, uint32_t sid_rep)
322 uint8_t raw_eth_pkt[] = {
323 0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
324 0x00,0x00,0x00,0x00,0x08,0x00,0x45,0x00,
325 0x00,0x85,0x00,0x01,0x00,0x00,0x40,0x06,
326 0x7c,0x70,0x7f,0x00,0x00,0x01,0x7f,0x00,
327 0x00,0x01,0x00,0x14,0x00,0x50,0x00,0x00,
328 0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x02,
329 0x20,0x00,0xc9,0xad,0x00,0x00,0x48,0x69,
330 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
331 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
332 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
333 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
334 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
335 0x74,0x63,0x68,0x65,0x73,0x20,0x6f,0x66,
336 0x20,0x73,0x70,0x6c,0x69,0x74,0x74,0x65,
337 0x64,0x20,0x70,0x61,0x74,0x74,0x65,0x72,
338 0x6e,0x73,0x20,0x62,0x65,0x74,0x77,0x65,
339 0x65,0x6e,0x20,0x6d,0x75,0x6c,0x74,0x69,
340 0x70,0x6c,0x65,0x20,0x63,0x68,0x75,0x6e,
342 uint8_t p[
sizeof(raw_eth_pkt)];
343 uint16_t psize =
sizeof(raw_eth_pkt);
348 ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
349 sig, sid, p, &psize);
352 ret = DetectReplaceLongPatternMatchTest(p, psize, sig_rep, sid_rep, NULL, NULL);
362 static int DetectReplaceLongPatternMatchTestUDPWrp(
const char *sig, uint32_t sid,
const char *sig_rep, uint32_t sid_rep)
367 uint8_t raw_eth_pkt[] = {
368 0x8c, 0xa9, 0x82, 0x75, 0x5d, 0x62, 0xb4, 0x07,
369 0xf9, 0xf3, 0xc7, 0x0a, 0x08, 0x00, 0x45, 0x00,
370 0x00, 0x3a, 0x92, 0x4f, 0x40, 0x00, 0x40, 0x11,
371 0x31, 0x1a, 0xc0, 0xa8, 0x00, 0x02, 0xc1, 0xbd,
372 0xf4, 0xe1, 0x3b, 0x7e, 0x00, 0x35, 0x00, 0x26,
373 0xcb, 0x81, 0x37, 0x62, 0x01, 0x00, 0x00, 0x01,
374 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x61,
375 0x31, 0x05, 0x74, 0x77, 0x69, 0x6d, 0x67, 0x03,
376 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01 };
378 uint8_t p[
sizeof(raw_eth_pkt)];
379 uint16_t psize =
sizeof(raw_eth_pkt);
383 ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
384 sig, sid, p, &psize);
386 SCLogDebug(
"replace: test1 phase1 ok: %" PRIuMAX
" vs %d",(uintmax_t)
sizeof(raw_eth_pkt),psize);
387 ret = DetectReplaceLongPatternMatchTest(p, psize, sig_rep, sid_rep, NULL, NULL);
396 static int DetectReplaceMatchTest01(
void)
398 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
399 " content:\"big\"; replace:\"pig\"; sid:1;)";
400 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
401 " content:\"this is a pig test\"; sid:2;)";
402 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
409 static int DetectReplaceMatchTest02(
void)
411 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
412 " content:\"th\"; offset: 4; replace:\"TH\"; sid:1;)";
413 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
414 " content:\"THis\"; offset:4; sid:2;)";
415 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
422 static int DetectReplaceMatchTest03(
void)
424 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
425 " content:\"th\"; replace:\"TH\"; offset: 4; sid:1;)";
426 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
427 " content:\"THis\"; offset:4; sid:2;)";
428 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
435 static int DetectReplaceMatchTest04(
void)
437 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
438 " content:\"th\"; replace:\"TH\"; content:\"patter\"; replace:\"matter\"; sid:1;)";
439 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
440 " content:\"THis\"; content:\"matterns\"; sid:2;)";
441 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
448 static int DetectReplaceMatchTest05(
void)
450 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
451 " content:\"th\"; replace:\"TH\"; content:\"nutella\"; sid:1;)";
452 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
453 " content:\"TH\"; sid:2;)";
454 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
462 static int DetectReplaceMatchTest06(
void)
464 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
465 " content:\"nutella\"; replace:\"commode\"; content:\"this is\"; sid:1;)";
466 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
467 " content:\"commode\"; sid:2;)";
468 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
475 static int DetectReplaceMatchTest07(
void)
477 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
478 " content:\"BiG\"; nocase; replace:\"pig\"; sid:1;)";
479 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
480 " content:\"this is a pig test\"; sid:2;)";
481 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
488 static int DetectReplaceMatchTest08(
void)
490 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
491 " content:\"big\"; depth:17; replace:\"pig\"; sid:1;)";
492 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
493 " content:\"this is a pig test\"; sid:2;)";
494 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
501 static int DetectReplaceMatchTest09(
void)
503 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
504 " content:\"big\"; depth:16; replace:\"pig\"; sid:1;)";
505 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
506 " content:\"this is a pig test\"; sid:2;)";
507 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
514 static int DetectReplaceMatchTest10(
void)
516 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
517 " content:\"big\"; depth:17; replace:\"pig\"; offset: 14; sid:1;)";
518 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
519 " content:\"pig\"; depth:17; offset:14; sid:2;)";
520 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
527 static int DetectReplaceMatchTest11(
void)
529 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
530 " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 11; sid:1;)";
531 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
532 " content:\"pig\"; depth:17; offset:14; sid:2;)";
534 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
541 static int DetectReplaceMatchTest12(
void)
543 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
544 " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 4; sid:1;)";
545 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
546 " content:\"pig\"; depth:17; offset:14; sid:2;)";
547 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
554 static int DetectReplaceMatchTest13(
void)
556 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
557 " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 1; sid:1;)";
558 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
559 " content:\"pig\"; depth:17; offset:14; sid:2;)";
560 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
567 static int DetectReplaceMatchTest14(
void)
569 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
570 " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 2; sid:1;)";
571 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
572 " content:\"pig\"; depth:17; offset:14; sid:2;)";
573 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
580 static int DetectReplaceMatchTest15(
void)
582 const char *sig =
"alert udp any any -> any any (msg:\"Nothing..\";"
583 " content:\"com\"; replace:\"org\"; sid:1;)";
584 const char *sig_rep =
"alert udp any any -> any any (msg:\"replace worked\";"
585 " content:\"twimg|03|org\"; sid:2;)";
586 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestUDPWrp(sig, 1, sig_rep, 2));
594 static int DetectReplaceParseTest01(
void)
604 "alert udp any any -> any any "
605 "(msg:\"test\"; content:\"doh\"; replace:\"; sid:238012;)"));
615 static int DetectReplaceParseTest02(
void)
625 "alert http any any -> any any "
626 "(msg:\"test\"; content:\"doh\"; replace:\"bon\"; sid:238012;)"));
637 static int DetectReplaceParseTest03(
void)
648 "alert tcp any any -> any any "
649 "(msg:\"test\"; content:\"doh\"; replace:\"don\"; http_header; sid:238012;)"));
659 static int DetectReplaceParseTest04(
void)
669 "(msg:\"test\"; replace:\"don\"; sid:238012;)"));
679 static int DetectReplaceParseTest05(
void)
689 "alert tcp any any -> any any "
690 "(msg:\"test\"; replace:\"don\"; content:\"doh\"; sid:238012;)"));
700 static int DetectReplaceParseTest06(
void)
710 "alert tcp any any -> any any "
711 "(msg:\"test\"; content:\"don\"; replace:\"donut\"; sid:238012;)"));
721 static int DetectReplaceParseTest07(
void)
732 "(msg:\"test\"; content:\"don\"; replace:\"dou\"; "
733 "content:\"jpg\"; http_header; sid:238012;)"));
743 void DetectReplaceRegisterTests(
void)
746 UtRegisterTest(
"DetectReplaceMatchTest01", DetectReplaceMatchTest01);
747 UtRegisterTest(
"DetectReplaceMatchTest02", DetectReplaceMatchTest02);
748 UtRegisterTest(
"DetectReplaceMatchTest03", DetectReplaceMatchTest03);
749 UtRegisterTest(
"DetectReplaceMatchTest04", DetectReplaceMatchTest04);
750 UtRegisterTest(
"DetectReplaceMatchTest05", DetectReplaceMatchTest05);
751 UtRegisterTest(
"DetectReplaceMatchTest06", DetectReplaceMatchTest06);
752 UtRegisterTest(
"DetectReplaceMatchTest07", DetectReplaceMatchTest07);
753 UtRegisterTest(
"DetectReplaceMatchTest08", DetectReplaceMatchTest08);
754 UtRegisterTest(
"DetectReplaceMatchTest09", DetectReplaceMatchTest09);
755 UtRegisterTest(
"DetectReplaceMatchTest10", DetectReplaceMatchTest10);
756 UtRegisterTest(
"DetectReplaceMatchTest11", DetectReplaceMatchTest11);
757 UtRegisterTest(
"DetectReplaceMatchTest12", DetectReplaceMatchTest12);
758 UtRegisterTest(
"DetectReplaceMatchTest13", DetectReplaceMatchTest13);
759 UtRegisterTest(
"DetectReplaceMatchTest14", DetectReplaceMatchTest14);
760 UtRegisterTest(
"DetectReplaceMatchTest15", DetectReplaceMatchTest15);
762 UtRegisterTest(
"DetectReplaceParseTest01", DetectReplaceParseTest01);
763 UtRegisterTest(
"DetectReplaceParseTest02", DetectReplaceParseTest02);
764 UtRegisterTest(
"DetectReplaceParseTest03", DetectReplaceParseTest03);
765 UtRegisterTest(
"DetectReplaceParseTest04", DetectReplaceParseTest04);
766 UtRegisterTest(
"DetectReplaceParseTest05", DetectReplaceParseTest05);
767 UtRegisterTest(
"DetectReplaceParseTest06", DetectReplaceParseTest06);
768 UtRegisterTest(
"DetectReplaceParseTest07", DetectReplaceParseTest07);