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");
178 newlist->
found = found;
181 newlist->
next = replist;
196 replist = replist->
next;
208 replist = replist->
next;
227 int DetectReplaceLongPatternMatchTest(uint8_t *raw_eth_pkt, uint16_t pktsize,
228 const char *sig, uint32_t sid, uint8_t *pp,
240 memset(&th_v, 0,
sizeof(th_v));
245 SCLogDebug(
"replace: looks like a second run");
268 printf(
"relative next flag set on final match which is content: ");
282 SCLogDebug(
"replace: no alert on sig %d", sid);
309 static int DetectReplaceLongPatternMatchTestWrp(
const char *sig, uint32_t sid,
const char *sig_rep, uint32_t sid_rep)
317 uint8_t raw_eth_pkt[] = {
318 0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
319 0x00,0x00,0x00,0x00,0x08,0x00,0x45,0x00,
320 0x00,0x85,0x00,0x01,0x00,0x00,0x40,0x06,
321 0x7c,0x70,0x7f,0x00,0x00,0x01,0x7f,0x00,
322 0x00,0x01,0x00,0x14,0x00,0x50,0x00,0x00,
323 0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x02,
324 0x20,0x00,0xc9,0xad,0x00,0x00,0x48,0x69,
325 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
326 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
327 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
328 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
329 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
330 0x74,0x63,0x68,0x65,0x73,0x20,0x6f,0x66,
331 0x20,0x73,0x70,0x6c,0x69,0x74,0x74,0x65,
332 0x64,0x20,0x70,0x61,0x74,0x74,0x65,0x72,
333 0x6e,0x73,0x20,0x62,0x65,0x74,0x77,0x65,
334 0x65,0x6e,0x20,0x6d,0x75,0x6c,0x74,0x69,
335 0x70,0x6c,0x65,0x20,0x63,0x68,0x75,0x6e,
337 uint8_t p[
sizeof(raw_eth_pkt)];
338 uint16_t psize =
sizeof(raw_eth_pkt);
343 ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
344 sig, sid, p, &psize);
347 ret = DetectReplaceLongPatternMatchTest(p, psize, sig_rep, sid_rep, NULL, NULL);
357 static int DetectReplaceLongPatternMatchTestUDPWrp(
const char *sig, uint32_t sid,
const char *sig_rep, uint32_t sid_rep)
362 uint8_t raw_eth_pkt[] = {
363 0x8c, 0xa9, 0x82, 0x75, 0x5d, 0x62, 0xb4, 0x07,
364 0xf9, 0xf3, 0xc7, 0x0a, 0x08, 0x00, 0x45, 0x00,
365 0x00, 0x3a, 0x92, 0x4f, 0x40, 0x00, 0x40, 0x11,
366 0x31, 0x1a, 0xc0, 0xa8, 0x00, 0x02, 0xc1, 0xbd,
367 0xf4, 0xe1, 0x3b, 0x7e, 0x00, 0x35, 0x00, 0x26,
368 0xcb, 0x81, 0x37, 0x62, 0x01, 0x00, 0x00, 0x01,
369 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x61,
370 0x31, 0x05, 0x74, 0x77, 0x69, 0x6d, 0x67, 0x03,
371 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01 };
373 uint8_t p[
sizeof(raw_eth_pkt)];
374 uint16_t psize =
sizeof(raw_eth_pkt);
378 ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
379 sig, sid, p, &psize);
381 SCLogDebug(
"replace: test1 phase1 ok: %" PRIuMAX
" vs %d",(uintmax_t)
sizeof(raw_eth_pkt),psize);
382 ret = DetectReplaceLongPatternMatchTest(p, psize, sig_rep, sid_rep, NULL, NULL);
391 static int DetectReplaceMatchTest01(
void)
393 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
394 " content:\"big\"; replace:\"pig\"; sid:1;)";
395 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
396 " content:\"this is a pig test\"; sid:2;)";
397 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
404 static int DetectReplaceMatchTest02(
void)
406 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
407 " content:\"th\"; offset: 4; replace:\"TH\"; sid:1;)";
408 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
409 " content:\"THis\"; offset:4; sid:2;)";
410 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
417 static int DetectReplaceMatchTest03(
void)
419 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
420 " content:\"th\"; replace:\"TH\"; offset: 4; sid:1;)";
421 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
422 " content:\"THis\"; offset:4; sid:2;)";
423 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
430 static int DetectReplaceMatchTest04(
void)
432 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
433 " content:\"th\"; replace:\"TH\"; content:\"patter\"; replace:\"matter\"; sid:1;)";
434 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
435 " content:\"THis\"; content:\"matterns\"; sid:2;)";
436 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
443 static int DetectReplaceMatchTest05(
void)
445 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
446 " content:\"th\"; replace:\"TH\"; content:\"nutella\"; sid:1;)";
447 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
448 " content:\"TH\"; sid:2;)";
449 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
457 static int DetectReplaceMatchTest06(
void)
459 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
460 " content:\"nutella\"; replace:\"commode\"; content:\"this is\"; sid:1;)";
461 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
462 " content:\"commode\"; sid:2;)";
463 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
470 static int DetectReplaceMatchTest07(
void)
472 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
473 " content:\"BiG\"; nocase; replace:\"pig\"; sid:1;)";
474 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
475 " content:\"this is a pig test\"; sid:2;)";
476 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
483 static int DetectReplaceMatchTest08(
void)
485 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
486 " content:\"big\"; depth:17; replace:\"pig\"; sid:1;)";
487 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
488 " content:\"this is a pig test\"; sid:2;)";
489 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
496 static int DetectReplaceMatchTest09(
void)
498 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
499 " content:\"big\"; depth:16; replace:\"pig\"; sid:1;)";
500 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
501 " content:\"this is a pig test\"; sid:2;)";
502 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
509 static int DetectReplaceMatchTest10(
void)
511 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
512 " content:\"big\"; depth:17; replace:\"pig\"; offset: 14; sid:1;)";
513 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
514 " content:\"pig\"; depth:17; offset:14; sid:2;)";
515 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
522 static int DetectReplaceMatchTest11(
void)
524 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
525 " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 11; sid:1;)";
526 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
527 " content:\"pig\"; depth:17; offset:14; sid:2;)";
529 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
536 static int DetectReplaceMatchTest12(
void)
538 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
539 " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 4; sid:1;)";
540 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
541 " content:\"pig\"; depth:17; offset:14; sid:2;)";
542 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
549 static int DetectReplaceMatchTest13(
void)
551 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
552 " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 1; sid:1;)";
553 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
554 " content:\"pig\"; depth:17; offset:14; sid:2;)";
555 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
562 static int DetectReplaceMatchTest14(
void)
564 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
565 " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 2; sid:1;)";
566 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
567 " content:\"pig\"; depth:17; offset:14; sid:2;)";
568 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
575 static int DetectReplaceMatchTest15(
void)
577 const char *sig =
"alert udp any any -> any any (msg:\"Nothing..\";"
578 " content:\"com\"; replace:\"org\"; sid:1;)";
579 const char *sig_rep =
"alert udp any any -> any any (msg:\"replace worked\";"
580 " content:\"twimg|03|org\"; sid:2;)";
581 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestUDPWrp(sig, 1, sig_rep, 2));
589 static int DetectReplaceParseTest01(
void)
599 "alert udp any any -> any any "
600 "(msg:\"test\"; content:\"doh\"; replace:\"; sid:238012;)"));
610 static int DetectReplaceParseTest02(
void)
620 "alert http any any -> any any "
621 "(msg:\"test\"; content:\"doh\"; replace:\"bon\"; sid:238012;)"));
632 static int DetectReplaceParseTest03(
void)
643 "alert tcp any any -> any any "
644 "(msg:\"test\"; content:\"doh\"; replace:\"don\"; http_header; sid:238012;)"));
654 static int DetectReplaceParseTest04(
void)
664 "(msg:\"test\"; replace:\"don\"; sid:238012;)"));
674 static int DetectReplaceParseTest05(
void)
684 "alert tcp any any -> any any "
685 "(msg:\"test\"; replace:\"don\"; content:\"doh\"; sid:238012;)"));
695 static int DetectReplaceParseTest06(
void)
705 "alert tcp any any -> any any "
706 "(msg:\"test\"; content:\"don\"; replace:\"donut\"; sid:238012;)"));
716 static int DetectReplaceParseTest07(
void)
727 "(msg:\"test\"; content:\"don\"; replace:\"dou\"; "
728 "content:\"jpg\"; http_header; sid:238012;)"));
738 void DetectReplaceRegisterTests(
void)
741 UtRegisterTest(
"DetectReplaceMatchTest01", DetectReplaceMatchTest01);
742 UtRegisterTest(
"DetectReplaceMatchTest02", DetectReplaceMatchTest02);
743 UtRegisterTest(
"DetectReplaceMatchTest03", DetectReplaceMatchTest03);
744 UtRegisterTest(
"DetectReplaceMatchTest04", DetectReplaceMatchTest04);
745 UtRegisterTest(
"DetectReplaceMatchTest05", DetectReplaceMatchTest05);
746 UtRegisterTest(
"DetectReplaceMatchTest06", DetectReplaceMatchTest06);
747 UtRegisterTest(
"DetectReplaceMatchTest07", DetectReplaceMatchTest07);
748 UtRegisterTest(
"DetectReplaceMatchTest08", DetectReplaceMatchTest08);
749 UtRegisterTest(
"DetectReplaceMatchTest09", DetectReplaceMatchTest09);
750 UtRegisterTest(
"DetectReplaceMatchTest10", DetectReplaceMatchTest10);
751 UtRegisterTest(
"DetectReplaceMatchTest11", DetectReplaceMatchTest11);
752 UtRegisterTest(
"DetectReplaceMatchTest12", DetectReplaceMatchTest12);
753 UtRegisterTest(
"DetectReplaceMatchTest13", DetectReplaceMatchTest13);
754 UtRegisterTest(
"DetectReplaceMatchTest14", DetectReplaceMatchTest14);
755 UtRegisterTest(
"DetectReplaceMatchTest15", DetectReplaceMatchTest15);
757 UtRegisterTest(
"DetectReplaceParseTest01", DetectReplaceParseTest01);
758 UtRegisterTest(
"DetectReplaceParseTest02", DetectReplaceParseTest02);
759 UtRegisterTest(
"DetectReplaceParseTest03", DetectReplaceParseTest03);
760 UtRegisterTest(
"DetectReplaceParseTest04", DetectReplaceParseTest04);
761 UtRegisterTest(
"DetectReplaceParseTest05", DetectReplaceParseTest05);
762 UtRegisterTest(
"DetectReplaceParseTest06", DetectReplaceParseTest06);
763 UtRegisterTest(
"DetectReplaceParseTest07", DetectReplaceParseTest07);