53 #define PARSE_REGEX "^\\s*!?([^\\s,]+)\\s*(,\\s*relative)?\\s*(,\\s*rawbytes\\s*)?\\s*$"
59 static void DetectIsdataatRegisterTests(
void);
60 static void DetectAbsentRegisterTests(
void);
84 }
else if (strcmp(optstr,
"or_else") == 0) {
87 SCLogError(
"unhandled value for absent keyword: %s", optstr);
91 SCLogError(
"unspected buffer for absent keyword");
96 SCLogError(
"absent does not work with frames");
100 SCLogError(
"absent must come first right after buffer");
111 DetectAbsentFree(
de_ctx, dad);
119 bool has_other =
false;
120 bool only_absent =
false;
121 bool has_absent =
false;
134 SCLogError(
"signature can't have absent and fast_pattern on the same buffer");
141 if (only_absent && has_other) {
142 SCLogError(
"signature can't have a buffer tested absent and tested with other keywords "
145 }
else if (has_absent && !only_absent && !has_other) {
147 "signature with absent: or_else expects other keywords to test on such as content");
199 char *args[3] = {NULL,NULL,NULL};
204 pcre2_match_data *match = NULL;
206 if (ret < 1 || ret > 4) {
207 SCLogError(
"pcre_exec parse error, ret %" PRId32
", string %s", ret, isdataatstr);
213 res = pcre2_substring_get_bynumber(match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
215 SCLogError(
"pcre2_substring_get_bynumber failed");
218 args[0] = (
char *)str_ptr;
222 res = pcre2_substring_get_bynumber(match, 2, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
224 SCLogError(
"pcre2_substring_get_bynumber failed");
227 args[1] = (
char *)str_ptr;
230 res = pcre2_substring_get_bynumber(match, 3, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
232 SCLogError(
"pcre2_substring_get_bynumber failed");
235 args[2] = (
char *)str_ptr;
245 if (args[0][0] !=
'-' && isalpha((
unsigned char)args[0][0])) {
248 "var name for offset. \"offset\" argument supplied to "
249 "this function has to be non-NULL");
257 strlen(args[0]), args[0]) < 0 ) {
265 if (args[1] !=NULL) {
272 if (isdataatstr[0] ==
'!') {
276 for (i = 0; i < (ret -1); i++) {
278 pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
281 pcre2_match_data_free(match);
288 pcre2_match_data_free(match);
290 for (i = 0; i < (ret -1) && i < 3; i++){
292 pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
318 idad = DetectIsdataatParse(
de_ctx, isdataatstr, &
offset);
351 "seen in isdataat - %s\n",
383 if (prev_pm == NULL) {
426 "preceding content option");
441 static int g_dce_stub_data_buffer_id = 0;
447 static int DetectIsdataatTestParse01 (
void)
451 idad = DetectIsdataatParse(NULL,
"30 ", NULL);
464 static int DetectIsdataatTestParse02 (
void)
468 idad = DetectIsdataatParse(NULL,
"30 , relative", NULL);
481 static int DetectIsdataatTestParse03 (
void)
485 idad = DetectIsdataatParse(NULL,
"30,relative, rawbytes ", NULL);
497 static int DetectIsdataatTestParse04(
void)
523 static int DetectIsdataatTestParse06(
void)
530 "(msg:\"Testing bytejump_body\"; "
532 "isdataat:!4,relative; sid:1;)");
546 "(msg:\"Testing bytejump_body\"; "
548 "isdataat: !4,relative; sid:2;)");
568 static int DetectIsdataatTestPacket01 (
void)
571 uint8_t *buf = (uint8_t *)
"Hi all!";
572 uint16_t buflen = strlen((
char *)buf);
578 if (p[0] == NULL || p[1] == NULL ||p[2] == NULL)
582 sigs[0]=
"alert ip any any -> any any (msg:\"Testing window 1\"; isdataat:6; sid:1;)";
583 sigs[1]=
"alert ip any any -> any any (msg:\"Testing window 2\"; content:\"all\"; isdataat:1, relative; isdataat:6; sid:2;)";
584 sigs[2]=
"alert ip any any -> any any (msg:\"Testing window 3\"; isdataat:8; sid:3;)";
585 sigs[3]=
"alert ip any any -> any any (msg:\"Testing window 4\"; content:\"Hi\"; isdataat:5, relative; sid:4;)";
586 sigs[4]=
"alert ip any any -> any any (msg:\"Testing window 4\"; content:\"Hi\"; isdataat:6, relative; sid:5;)";
588 uint32_t sid[5] = {1, 2, 3, 4, 5};
590 uint32_t results[3][5] = {
598 result =
UTHGenericTest(p, 3, sigs, sid, (uint32_t *) results, 5);
610 static int DetectIsdataatTestPacket02 (
void)
613 uint8_t *buf = (uint8_t *)
"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
614 "User-Agent: Wget/1.11.4"
616 "Host: www.google.com"
617 "Connection: Keep-Alive"
618 "Date: Mon, 04 Jan 2010 17:29:39 GMT";
619 uint16_t buflen = strlen((
char *)buf);
626 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with"
627 " isdataat + relative\"; pcre:\"/A(ll|pp)WorkAndNoPlayMakesWillA"
628 "DullBoy/\"; isdataat:96,relative; sid:1;)";
642 static int DetectIsdataatTestPacket03 (
void)
645 uint8_t *buf = (uint8_t *)
"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
646 "User-Agent: Wget/1.11.4"
648 "Host: www.google.com"
649 "Connection: Keep-Alive"
650 "Date: Mon, 04 Jan 2010 17:29:39 GMT";
651 uint16_t buflen = strlen((
char *)buf);
658 char sig[] =
"alert tcp any any -> any any (msg:\"byte_jump match = 0 "
659 "with distance content HTTP/1. relative against HTTP/1.0\"; byte_jump:1,"
660 "46,string,dec; isdataat:87,relative; sid:109; rev:1;)";
672 void DetectIsdataatRegisterTests(
void)
676 UtRegisterTest(
"DetectIsdataatTestParse01", DetectIsdataatTestParse01);
677 UtRegisterTest(
"DetectIsdataatTestParse02", DetectIsdataatTestParse02);
678 UtRegisterTest(
"DetectIsdataatTestParse03", DetectIsdataatTestParse03);
679 UtRegisterTest(
"DetectIsdataatTestParse04", DetectIsdataatTestParse04);
680 UtRegisterTest(
"DetectIsdataatTestParse06", DetectIsdataatTestParse06);
682 UtRegisterTest(
"DetectIsdataatTestPacket01", DetectIsdataatTestPacket01);
683 UtRegisterTest(
"DetectIsdataatTestPacket02", DetectIsdataatTestPacket02);
684 UtRegisterTest(
"DetectIsdataatTestPacket03", DetectIsdataatTestPacket03);
687 static int DetectAbsentTestParse01(
void)
694 "alert http any any -> any any "
695 "(msg:\"invalid absent only with negated content\"; http.user_agent; "
696 "absent; content:!\"one\"; sid:2;)");
699 "(msg:\"invalid absent\"; http.user_agent; "
700 "content:!\"one\"; absent; sid:2;)");
703 "(msg:\"invalid absent\"; http.user_agent; "
704 "content:\"one\"; absent: or_else; sid:2;)");
707 "(msg:\"absent without sticky buffer\"; "
708 "content:!\"one\"; absent: or_else; sid:2;)");
711 "alert websocket any any -> any any "
712 "(msg:\"absent with frame\"; "
713 "frame: websocket.pdu; absent: or_else; content:!\"one\"; sid:2;)");
719 void DetectAbsentRegisterTests(
void)
721 UtRegisterTest(
"DetectAbsentTestParse01", DetectAbsentTestParse01);