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));
244 SCLogDebug(
"replace: looks like a second run");
267 printf(
"relative next flag set on final match which is content: ");
281 SCLogDebug(
"replace: no alert on sig %d", sid);
308 static int DetectReplaceLongPatternMatchTestWrp(
const char *sig, uint32_t sid,
const char *sig_rep, uint32_t sid_rep)
316 uint8_t raw_eth_pkt[] = {
317 0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,
318 0x00,0x00,0x00,0x00,0x08,0x00,0x45,0x00,
319 0x00,0x85,0x00,0x01,0x00,0x00,0x40,0x06,
320 0x7c,0x70,0x7f,0x00,0x00,0x01,0x7f,0x00,
321 0x00,0x01,0x00,0x14,0x00,0x50,0x00,0x00,
322 0x00,0x00,0x00,0x00,0x00,0x00,0x50,0x02,
323 0x20,0x00,0xc9,0xad,0x00,0x00,0x48,0x69,
324 0x2c,0x20,0x74,0x68,0x69,0x73,0x20,0x69,
325 0x73,0x20,0x61,0x20,0x62,0x69,0x67,0x20,
326 0x74,0x65,0x73,0x74,0x20,0x74,0x6f,0x20,
327 0x63,0x68,0x65,0x63,0x6b,0x20,0x63,0x6f,
328 0x6e,0x74,0x65,0x6e,0x74,0x20,0x6d,0x61,
329 0x74,0x63,0x68,0x65,0x73,0x20,0x6f,0x66,
330 0x20,0x73,0x70,0x6c,0x69,0x74,0x74,0x65,
331 0x64,0x20,0x70,0x61,0x74,0x74,0x65,0x72,
332 0x6e,0x73,0x20,0x62,0x65,0x74,0x77,0x65,
333 0x65,0x6e,0x20,0x6d,0x75,0x6c,0x74,0x69,
334 0x70,0x6c,0x65,0x20,0x63,0x68,0x75,0x6e,
336 uint8_t p[
sizeof(raw_eth_pkt)];
337 uint16_t psize =
sizeof(raw_eth_pkt);
342 ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
343 sig, sid, p, &psize);
346 ret = DetectReplaceLongPatternMatchTest(p, psize, sig_rep, sid_rep, NULL, NULL);
356 static int DetectReplaceLongPatternMatchTestUDPWrp(
const char *sig, uint32_t sid,
const char *sig_rep, uint32_t sid_rep)
361 uint8_t raw_eth_pkt[] = {
362 0x8c, 0xa9, 0x82, 0x75, 0x5d, 0x62, 0xb4, 0x07,
363 0xf9, 0xf3, 0xc7, 0x0a, 0x08, 0x00, 0x45, 0x00,
364 0x00, 0x3a, 0x92, 0x4f, 0x40, 0x00, 0x40, 0x11,
365 0x31, 0x1a, 0xc0, 0xa8, 0x00, 0x02, 0xc1, 0xbd,
366 0xf4, 0xe1, 0x3b, 0x7e, 0x00, 0x35, 0x00, 0x26,
367 0xcb, 0x81, 0x37, 0x62, 0x01, 0x00, 0x00, 0x01,
368 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x61,
369 0x31, 0x05, 0x74, 0x77, 0x69, 0x6d, 0x67, 0x03,
370 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01 };
372 uint8_t p[
sizeof(raw_eth_pkt)];
373 uint16_t psize =
sizeof(raw_eth_pkt);
377 ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)
sizeof(raw_eth_pkt),
378 sig, sid, p, &psize);
380 SCLogDebug(
"replace: test1 phase1 ok: %" PRIuMAX
" vs %d",(uintmax_t)
sizeof(raw_eth_pkt),psize);
381 ret = DetectReplaceLongPatternMatchTest(p, psize, sig_rep, sid_rep, NULL, NULL);
390 static int DetectReplaceMatchTest01(
void)
392 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
393 " content:\"big\"; replace:\"pig\"; sid:1;)";
394 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
395 " content:\"this is a pig test\"; sid:2;)";
396 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
403 static int DetectReplaceMatchTest02(
void)
405 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
406 " content:\"th\"; offset: 4; replace:\"TH\"; sid:1;)";
407 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
408 " content:\"THis\"; offset:4; sid:2;)";
409 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
416 static int DetectReplaceMatchTest03(
void)
418 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
419 " content:\"th\"; replace:\"TH\"; offset: 4; sid:1;)";
420 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
421 " content:\"THis\"; offset:4; sid:2;)";
422 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
429 static int DetectReplaceMatchTest04(
void)
431 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
432 " content:\"th\"; replace:\"TH\"; content:\"patter\"; replace:\"matter\"; sid:1;)";
433 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
434 " content:\"THis\"; content:\"matterns\"; sid:2;)";
435 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
442 static int DetectReplaceMatchTest05(
void)
444 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
445 " content:\"th\"; replace:\"TH\"; content:\"nutella\"; sid:1;)";
446 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
447 " content:\"TH\"; sid:2;)";
448 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
456 static int DetectReplaceMatchTest06(
void)
458 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
459 " content:\"nutella\"; replace:\"commode\"; content:\"this is\"; sid:1;)";
460 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
461 " content:\"commode\"; sid:2;)";
462 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
469 static int DetectReplaceMatchTest07(
void)
471 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
472 " content:\"BiG\"; nocase; replace:\"pig\"; sid:1;)";
473 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
474 " content:\"this is a pig test\"; sid:2;)";
475 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
482 static int DetectReplaceMatchTest08(
void)
484 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
485 " content:\"big\"; depth:17; replace:\"pig\"; sid:1;)";
486 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
487 " content:\"this is a pig test\"; sid:2;)";
488 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
495 static int DetectReplaceMatchTest09(
void)
497 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
498 " content:\"big\"; depth:16; replace:\"pig\"; sid:1;)";
499 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
500 " content:\"this is a pig test\"; sid:2;)";
501 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
508 static int DetectReplaceMatchTest10(
void)
510 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
511 " content:\"big\"; depth:17; replace:\"pig\"; offset: 14; sid:1;)";
512 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
513 " content:\"pig\"; depth:17; offset:14; sid:2;)";
514 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
521 static int DetectReplaceMatchTest11(
void)
523 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
524 " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 11; sid:1;)";
525 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
526 " content:\"pig\"; depth:17; offset:14; sid:2;)";
528 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
535 static int DetectReplaceMatchTest12(
void)
537 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
538 " content:\"big\"; replace:\"pig\"; content:\"to\"; within: 4; sid:1;)";
539 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
540 " content:\"pig\"; depth:17; offset:14; sid:2;)";
541 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
548 static int DetectReplaceMatchTest13(
void)
550 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
551 " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 1; sid:1;)";
552 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
553 " content:\"pig\"; depth:17; offset:14; sid:2;)";
554 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
561 static int DetectReplaceMatchTest14(
void)
563 const char *sig =
"alert tcp any any -> any any (msg:\"Nothing..\";"
564 " content:\"big\"; replace:\"pig\"; content:\"test\"; distance: 2; sid:1;)";
565 const char *sig_rep =
"alert tcp any any -> any any (msg:\"replace worked\";"
566 " content:\"pig\"; depth:17; offset:14; sid:2;)";
567 FAIL_IF(DetectReplaceLongPatternMatchTestWrp(sig, 1, sig_rep, 2));
574 static int DetectReplaceMatchTest15(
void)
576 const char *sig =
"alert udp any any -> any any (msg:\"Nothing..\";"
577 " content:\"com\"; replace:\"org\"; sid:1;)";
578 const char *sig_rep =
"alert udp any any -> any any (msg:\"replace worked\";"
579 " content:\"twimg|03|org\"; sid:2;)";
580 FAIL_IF_NOT(DetectReplaceLongPatternMatchTestUDPWrp(sig, 1, sig_rep, 2));
588 static int DetectReplaceParseTest01(
void)
598 "alert udp any any -> any any "
599 "(msg:\"test\"; content:\"doh\"; replace:\"; sid:238012;)"));
609 static int DetectReplaceParseTest02(
void)
619 "alert http any any -> any any "
620 "(msg:\"test\"; content:\"doh\"; replace:\"bon\"; sid:238012;)"));
631 static int DetectReplaceParseTest03(
void)
642 "alert tcp any any -> any any "
643 "(msg:\"test\"; content:\"doh\"; replace:\"don\"; http_header; sid:238012;)"));
653 static int DetectReplaceParseTest04(
void)
663 "(msg:\"test\"; replace:\"don\"; sid:238012;)"));
673 static int DetectReplaceParseTest05(
void)
683 "alert tcp any any -> any any "
684 "(msg:\"test\"; replace:\"don\"; content:\"doh\"; sid:238012;)"));
694 static int DetectReplaceParseTest06(
void)
704 "alert tcp any any -> any any "
705 "(msg:\"test\"; content:\"don\"; replace:\"donut\"; sid:238012;)"));
715 static int DetectReplaceParseTest07(
void)
726 "(msg:\"test\"; content:\"don\"; replace:\"dou\"; "
727 "content:\"jpg\"; http_header; sid:238012;)"));
737 void DetectReplaceRegisterTests(
void)
740 UtRegisterTest(
"DetectReplaceMatchTest01", DetectReplaceMatchTest01);
741 UtRegisterTest(
"DetectReplaceMatchTest02", DetectReplaceMatchTest02);
742 UtRegisterTest(
"DetectReplaceMatchTest03", DetectReplaceMatchTest03);
743 UtRegisterTest(
"DetectReplaceMatchTest04", DetectReplaceMatchTest04);
744 UtRegisterTest(
"DetectReplaceMatchTest05", DetectReplaceMatchTest05);
745 UtRegisterTest(
"DetectReplaceMatchTest06", DetectReplaceMatchTest06);
746 UtRegisterTest(
"DetectReplaceMatchTest07", DetectReplaceMatchTest07);
747 UtRegisterTest(
"DetectReplaceMatchTest08", DetectReplaceMatchTest08);
748 UtRegisterTest(
"DetectReplaceMatchTest09", DetectReplaceMatchTest09);
749 UtRegisterTest(
"DetectReplaceMatchTest10", DetectReplaceMatchTest10);
750 UtRegisterTest(
"DetectReplaceMatchTest11", DetectReplaceMatchTest11);
751 UtRegisterTest(
"DetectReplaceMatchTest12", DetectReplaceMatchTest12);
752 UtRegisterTest(
"DetectReplaceMatchTest13", DetectReplaceMatchTest13);
753 UtRegisterTest(
"DetectReplaceMatchTest14", DetectReplaceMatchTest14);
754 UtRegisterTest(
"DetectReplaceMatchTest15", DetectReplaceMatchTest15);
756 UtRegisterTest(
"DetectReplaceParseTest01", DetectReplaceParseTest01);
757 UtRegisterTest(
"DetectReplaceParseTest02", DetectReplaceParseTest02);
758 UtRegisterTest(
"DetectReplaceParseTest03", DetectReplaceParseTest03);
759 UtRegisterTest(
"DetectReplaceParseTest04", DetectReplaceParseTest04);
760 UtRegisterTest(
"DetectReplaceParseTest05", DetectReplaceParseTest05);
761 UtRegisterTest(
"DetectReplaceParseTest06", DetectReplaceParseTest06);
762 UtRegisterTest(
"DetectReplaceParseTest07", DetectReplaceParseTest07);