52 #define PARSE_REGEX "^\\s*!?([^\\s,]+)\\s*(,\\s*relative)?\\s*(,\\s*rawbytes\\s*)?\\s*$"
58 static void DetectIsdataatRegisterTests(
void);
100 char *args[3] = {NULL,NULL,NULL};
105 pcre2_match_data *match = NULL;
107 if (ret < 1 || ret > 4) {
108 SCLogError(
"pcre_exec parse error, ret %" PRId32
", string %s", ret, isdataatstr);
114 res = pcre2_substring_get_bynumber(match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
116 SCLogError(
"pcre2_substring_get_bynumber failed");
119 args[0] = (
char *)str_ptr;
123 res = pcre2_substring_get_bynumber(match, 2, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
125 SCLogError(
"pcre2_substring_get_bynumber failed");
128 args[1] = (
char *)str_ptr;
131 res = pcre2_substring_get_bynumber(match, 3, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
133 SCLogError(
"pcre2_substring_get_bynumber failed");
136 args[2] = (
char *)str_ptr;
146 if (args[0][0] !=
'-' && isalpha((
unsigned char)args[0][0])) {
149 "var name for offset. \"offset\" argument supplied to "
150 "this function has to be non-NULL");
158 strlen(args[0]), args[0]) < 0 ) {
166 if (args[1] !=NULL) {
173 if (isdataatstr[0] ==
'!') {
177 for (i = 0; i < (ret -1); i++) {
179 pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
182 pcre2_match_data_free(match);
189 pcre2_match_data_free(match);
191 for (i = 0; i < (ret -1) && i < 3; i++){
193 pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
219 idad = DetectIsdataatParse(
de_ctx, isdataatstr, &
offset);
252 "seen in isdataat - %s\n",
284 if (prev_pm == NULL) {
327 "preceding content option");
342 static int g_dce_stub_data_buffer_id = 0;
348 static int DetectIsdataatTestParse01 (
void)
352 idad = DetectIsdataatParse(NULL,
"30 ", NULL);
365 static int DetectIsdataatTestParse02 (
void)
369 idad = DetectIsdataatParse(NULL,
"30 , relative", NULL);
382 static int DetectIsdataatTestParse03 (
void)
386 idad = DetectIsdataatParse(NULL,
"30,relative, rawbytes ", NULL);
398 static int DetectIsdataatTestParse04(
void)
424 static int DetectIsdataatTestParse06(
void)
431 "(msg:\"Testing bytejump_body\"; "
433 "isdataat:!4,relative; sid:1;)");
447 "(msg:\"Testing bytejump_body\"; "
449 "isdataat: !4,relative; sid:2;)");
469 static int DetectIsdataatTestPacket01 (
void)
472 uint8_t *buf = (uint8_t *)
"Hi all!";
473 uint16_t buflen = strlen((
char *)buf);
479 if (p[0] == NULL || p[1] == NULL ||p[2] == NULL)
483 sigs[0]=
"alert ip any any -> any any (msg:\"Testing window 1\"; isdataat:6; sid:1;)";
484 sigs[1]=
"alert ip any any -> any any (msg:\"Testing window 2\"; content:\"all\"; isdataat:1, relative; isdataat:6; sid:2;)";
485 sigs[2]=
"alert ip any any -> any any (msg:\"Testing window 3\"; isdataat:8; sid:3;)";
486 sigs[3]=
"alert ip any any -> any any (msg:\"Testing window 4\"; content:\"Hi\"; isdataat:5, relative; sid:4;)";
487 sigs[4]=
"alert ip any any -> any any (msg:\"Testing window 4\"; content:\"Hi\"; isdataat:6, relative; sid:5;)";
489 uint32_t sid[5] = {1, 2, 3, 4, 5};
491 uint32_t results[3][5] = {
499 result =
UTHGenericTest(p, 3, sigs, sid, (uint32_t *) results, 5);
511 static int DetectIsdataatTestPacket02 (
void)
514 uint8_t *buf = (uint8_t *)
"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
515 "User-Agent: Wget/1.11.4"
517 "Host: www.google.com"
518 "Connection: Keep-Alive"
519 "Date: Mon, 04 Jan 2010 17:29:39 GMT";
520 uint16_t buflen = strlen((
char *)buf);
527 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with"
528 " isdataat + relative\"; pcre:\"/A(ll|pp)WorkAndNoPlayMakesWillA"
529 "DullBoy/\"; isdataat:96,relative; sid:1;)";
543 static int DetectIsdataatTestPacket03 (
void)
546 uint8_t *buf = (uint8_t *)
"GET /AllWorkAndNoPlayMakesWillADullBoy HTTP/1.0"
547 "User-Agent: Wget/1.11.4"
549 "Host: www.google.com"
550 "Connection: Keep-Alive"
551 "Date: Mon, 04 Jan 2010 17:29:39 GMT";
552 uint16_t buflen = strlen((
char *)buf);
559 char sig[] =
"alert tcp any any -> any any (msg:\"byte_jump match = 0 "
560 "with distance content HTTP/1. relative against HTTP/1.0\"; byte_jump:1,"
561 "46,string,dec; isdataat:87,relative; sid:109; rev:1;)";
573 void DetectIsdataatRegisterTests(
void)
577 UtRegisterTest(
"DetectIsdataatTestParse01", DetectIsdataatTestParse01);
578 UtRegisterTest(
"DetectIsdataatTestParse02", DetectIsdataatTestParse02);
579 UtRegisterTest(
"DetectIsdataatTestParse03", DetectIsdataatTestParse03);
580 UtRegisterTest(
"DetectIsdataatTestParse04", DetectIsdataatTestParse04);
581 UtRegisterTest(
"DetectIsdataatTestParse06", DetectIsdataatTestParse06);
583 UtRegisterTest(
"DetectIsdataatTestPacket01", DetectIsdataatTestPacket01);
584 UtRegisterTest(
"DetectIsdataatTestPacket02", DetectIsdataatTestPacket02);
585 UtRegisterTest(
"DetectIsdataatTestPacket03", DetectIsdataatTestPacket03);