65 #define PARSE_CAPTURE_REGEX "\\(\\?P\\<([A-z]+)\\_([A-z0-9_]+)\\>"
66 #define PARSE_REGEX "(?<!\\\\)/(.*(?<!(?<!\\\\)\\\\))/([^\"]*)"
68 static int pcre_match_limit = 0;
69 static int pcre_match_limit_recursion = 0;
75 static int pcre2_use_jit = 1;
83 const char *
str,
const size_t strlen,
int start_offset,
int options,
84 pcre2_match_data *match)
93 static void DetectPcreRegisterTests(
void);
114 SCLogDebug(
"Using PCRE match-limit setting of: %i", pcre_match_limit);
116 pcre_match_limit = (int)val;
118 SCLogInfo(
"Using PCRE match-limit setting of: %i", pcre_match_limit);
120 SCLogDebug(
"Using PCRE match-limit setting of: %i", pcre_match_limit);
126 if (!
SCConfGetInt(
"pcre.match-limit-recursion", &val)) {
128 SCLogDebug(
"Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion);
130 pcre_match_limit_recursion = (int)val;
132 SCLogInfo(
"Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion);
134 SCLogDebug(
"Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion);
139 if (parse_regex == NULL) {
140 FatalError(
"pcre2 compile failed for parse_regex");
146 if (parse_capture_regex == NULL) {
147 FatalError(
"pcre2 compile failed for parse_capture_regex");
150 #ifdef PCRE2_HAVE_JIT
152 SCLogConfig(
"PCRE2 won't use JIT as OS doesn't allow RWX pages");
159 uint8_t *str_ptr, uint16_t capture_len)
164 if (json_key == NULL) {
181 SCJbSetStringFromBytes(js, json_key, str_ptr, capture_len);
182 uint32_t js_len = (uint32_t)SCJbLen(js);
184 SCLogDebug(
"Captured length is too long for JSON.");
190 SCLogDebug(
"Captured length is zero for JSON.");
228 const uint8_t *ptr = NULL;
230 PCRE2_SIZE capture_len = 0;
242 int start_offset = 0;
248 pcre2_match_data *match =
251 ret = DetectPcreExec(det_ctx, pe, (
char *)ptr,
len, start_offset, 0, match);
254 if (ret == PCRE2_ERROR_NOMATCH) {
262 }
else if (ret >= 0) {
274 if (ret > 1 && pe->
idx != 0) {
276 for (x = 0; x < pe->
idx; x++) {
282 const char *pcre2_str_ptr = NULL;
283 ret = pcre2_substring_get_bynumber(
284 match, x + 1, (PCRE2_UCHAR8 **)&pcre2_str_ptr, &capture_len);
286 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
290 capture_len = (capture_len < 0xffff) ? (uint16_t)capture_len : 0xffff;
291 uint8_t *str_ptr =
SCMalloc(capture_len);
293 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
296 memcpy(str_ptr, pcre2_str_ptr, capture_len);
297 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
304 const char *pcre2_str_ptr2 = NULL;
306 uint16_t key_len = (capture_len < 0xff) ? (uint16_t)capture_len : 0xff;
307 int ret2 = pcre2_substring_get_bynumber(
308 match, x + 2, (PCRE2_UCHAR8 **)&pcre2_str_ptr2, &capture_len);
312 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
315 capture_len = (capture_len < 0xffff) ? (uint16_t)capture_len : 0xffff;
316 uint8_t *str_ptr2 =
SCMalloc(capture_len);
319 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
322 memcpy(str_ptr2, pcre2_str_ptr2, capture_len);
323 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
326 (uint8_t *)str_ptr2, (uint16_t)capture_len,
338 (void)DetectAlertStoreMatch(det_ctx, s, pe->
capids[x], (uint8_t *)str_ptr,
339 (uint16_t)capture_len);
348 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
350 det_ctx->
buffer_offset = (uint32_t)((ptr + ov[1]) - payload);
363 static int DetectPcreSetList(
int list,
int set)
366 SCLogError(
"only one pcre option to specify a buffer type is allowed");
372 static bool DetectPcreHasUnicodeCluster(
const char *re)
374 return strstr(re,
"\\X") != NULL;
377 static int DetectPcreHasUpperCase(
const char *re)
379 size_t len = strlen(re);
380 bool is_meta =
false;
381 bool is_meta_hex =
false;
382 int meta_hex_cnt = 0;
384 for (
size_t i = 0; i <
len; i++) {
388 if (meta_hex_cnt == 2) {
392 }
else if (is_meta) {
399 else if (re[i] ==
'\\') {
402 else if (isupper((
unsigned char)re[i])) {
411 const char *regexstr,
int *sm_list,
char *capture_names,
412 size_t capture_names_size,
bool negate,
AppProto *alproto)
414 pcre2_match_data *match = NULL;
420 int ret = 0, res = 0;
421 int check_host_header = 0;
422 char op_str[64] =
"";
424 bool apply_match_limit =
false;
427 const char *fcap = strstr(regexstr,
"flow:");
428 const char *pcap = strstr(regexstr,
"pkt:");
429 const char *acap = strstr(regexstr,
"alert:");
432 size_t slen = strlen(regexstr) + 1;
433 if (fcap || pcap || acap) {
440 cut_capture = (int)(fcap - regexstr);
444 cut_capture = (int)
MIN(cut_capture, (pcap - regexstr));
446 cut_capture = (int)(pcap - regexstr);
452 cut_capture =
MIN(cut_capture, (
int)(acap - regexstr));
454 cut_capture = (int)(acap - regexstr);
459 if (cut_capture > 1) {
460 int offset = cut_capture - 1;
463 if (regexstr[
offset] ==
',' || regexstr[
offset] ==
' ') {
470 if (cut_capture == (
offset + 1)) {
471 SCLogDebug(
"missing separators, assume it's part of the regex");
474 strlcpy(capture_names, regexstr+cut_capture, capture_names_size);
475 if (capture_names[strlen(capture_names)-1] ==
'"')
476 capture_names[strlen(capture_names)-1] =
'\0';
484 match = pcre2_match_data_create_from_pattern(parse_regex->
regex, NULL);
489 ret = pcre2_match(parse_regex->
regex, (PCRE2_SPTR8)regexstr, slen, 0, 0, match, NULL);
495 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)re, &slen);
497 SCLogError(
"pcre2_substring_copy_bynumber failed");
498 pcre2_match_data_free(match);
503 size_t copylen =
sizeof(op_str);
504 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)op_str, ©len);
506 SCLogError(
"pcre2_substring_copy_bynumber failed");
507 pcre2_match_data_free(match);
527 opts |= PCRE2_ANCHORED;
530 opts |= PCRE2_DOLLAR_ENDONLY;
533 opts |= PCRE2_UNGREEDY;
537 opts |= PCRE2_CASELESS;
541 opts |= PCRE2_MULTILINE;
544 opts |= PCRE2_DOTALL;
547 opts |= PCRE2_EXTENDED;
551 apply_match_limit =
true;
556 SCLogError(
"regex modifier 'B' inconsistent with chosen buffer");
569 SCLogError(
"regex modifier 'U' inconsistent with 'B'");
573 *sm_list = DetectPcreSetList(*sm_list, list);
579 SCLogError(
"regex modifier 'V' inconsistent with 'B'");
583 *sm_list = DetectPcreSetList(*sm_list, list);
589 SCLogError(
"regex modifier 'W' inconsistent with 'B'");
593 *sm_list = DetectPcreSetList(*sm_list, list);
595 check_host_header = 1;
600 SCLogError(
"regex modifier 'Z' inconsistent with 'B'");
604 *sm_list = DetectPcreSetList(*sm_list, list);
610 SCLogError(
"regex modifier 'H' inconsistent with 'B'");
614 *sm_list = DetectPcreSetList(*sm_list, list);
619 SCLogError(
"regex modifier 'I' inconsistent with 'B'");
623 *sm_list = DetectPcreSetList(*sm_list, list);
629 *sm_list = DetectPcreSetList(*sm_list, list);
635 SCLogError(
"regex modifier 'M' inconsistent with 'B'");
639 *sm_list = DetectPcreSetList(*sm_list, list);
645 SCLogError(
"regex modifier 'C' inconsistent with 'B'");
649 *sm_list = DetectPcreSetList(*sm_list, list);
656 *sm_list = DetectPcreSetList(*sm_list, list);
663 *sm_list = DetectPcreSetList(*sm_list, list);
670 *sm_list = DetectPcreSetList(*sm_list, list);
677 *sm_list = DetectPcreSetList(*sm_list, list);
682 SCLogError(
"unknown regex modifier '%c'", *op);
694 if (check_host_header) {
697 "specified along with \"i(caseless)\" modifier. "
698 "Since the hostname buffer we match against "
699 "is actually lowercase, having a "
700 "nocase is redundant.");
702 else if (DetectPcreHasUpperCase(re)) {
704 "specified has an uppercase char. "
705 "Since the hostname buffer we match against "
706 "is actually lowercase, please specify an "
707 "all lowercase based pcre.");
717 if (capture_names == NULL || strlen(capture_names) == 0)
718 opts |= PCRE2_NO_AUTO_CAPTURE;
721 if (DetectPcreHasUnicodeCluster(re)) {
722 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
730 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
732 opts &= ~PCRE2_NO_AUTO_CAPTURE;
734 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
737 PCRE2_UCHAR errbuffer[256];
738 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
739 SCLogError(
"pcre2 compile of \"%s\" failed at "
741 regexstr, (
int)eo2, errbuffer);
745 #ifdef PCRE2_HAVE_JIT
752 SCLogDebug(
"PCRE2 JIT compiler does not support: %s. "
753 "Falling back to regular PCRE2 handling (%s:%d)",
761 SCLogError(
"pcre2 could not create match context");
765 if (apply_match_limit) {
766 if (pcre_match_limit >= -1) {
769 if (pcre_match_limit_recursion >= -1) {
778 pcre2_match_data_free(match);
782 pcre2_match_data_free(match);
783 DetectPcreFree(
de_ctx, pd);
793 int ret = 0, res = 0;
794 char type_str[16] =
"";
795 const char *orig_right_edge = regexstr + strlen(regexstr);
801 pcre2_match_data *match = NULL;
803 SCLogDebug(
"regexstr %s, pd %p", regexstr, pd);
805 ret = pcre2_pattern_info(pd->
parse_regex.
regex, PCRE2_INFO_CAPTURECOUNT, &capture_cnt);
806 SCLogDebug(
"ret %d capture_cnt %d", ret, capture_cnt);
807 if (ret == 0 && capture_cnt && strlen(capture_names) > 0)
810 while ((name_array[name_idx] = strtok_r(name_idx == 0 ? capture_names : NULL,
" ,", &ptr))){
811 if (name_idx > (capture_cnt - 1)) {
813 "var capture names than capturing substrings");
816 SCLogDebug(
"name '%s'", name_array[name_idx]);
818 if (strcmp(name_array[name_idx],
"pkt:key") == 0) {
826 }
else if (key == 1 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
831 }
else if (key == 0 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
833 }
else if (key == 1) {
836 }
else if (strncmp(name_array[name_idx],
"flow:", 5) == 0) {
837 uint32_t varname_id =
845 }
else if (strncmp(name_array[name_idx],
"pkt:", 4) == 0) {
846 uint32_t varname_id =
855 }
else if (strncmp(name_array[name_idx],
"alert:", 6) == 0) {
856 uint32_t varname_id =
866 "var capture names must start with 'pkt:' or 'flow:'");
878 size_t cap_buffer_len = strlen(regexstr) + 1;
880 char capture_str[cap_buffer_len];
881 memset(capture_str, 0x00, cap_buffer_len);
891 pcre2_match_data_free(match);
894 copylen =
sizeof(type_str);
895 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)type_str, ©len);
897 SCLogError(
"pcre2_substring_copy_bynumber failed");
900 cap_buffer_len = strlen(regexstr) + 1;
901 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)capture_str, &cap_buffer_len);
903 SCLogError(
"pcre2_substring_copy_bynumber failed");
906 if (strlen(capture_str) == 0 || strlen(type_str) == 0) {
914 SCLogError(
"rule can have maximally %d pkt/flow "
917 pcre2_match_data_free(match);
921 if (strcmp(type_str,
"pkt") == 0) {
929 }
else if (strcmp(type_str,
"flow") == 0) {
936 }
else if (strcmp(type_str,
"alert") == 0) {
946 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
949 pcre2_match_data_free(match);
952 if (regexstr >= orig_right_edge)
958 pcre2_match_data_free(match);
962 static void *DetectPcreThreadInit(
void *data)
965 pcre2_match_data *match = pcre2_match_data_create_from_pattern(pd->
parse_regex.
regex, NULL);
969 static void DetectPcreThreadFree(
void *
ctx)
972 pcre2_match_data *match = (pcre2_match_data *)
ctx;
973 pcre2_match_data_free(match);
982 char capture_names[1024] =
"";
985 pd = DetectPcreParse(
de_ctx, regexstr, &parsed_sm_list,
990 if (DetectPcreParseCapture(regexstr,
de_ctx, pd, capture_names) < 0)
994 de_ctx,
"pcre", DetectPcreThreadInit, (
void *)pd, DetectPcreThreadFree, 0);
1001 SCLogError(
"Expression seen with a sticky buffer still set; either (1) reset sticky "
1002 "buffer with pkt_data or (2) use a sticky buffer providing \"%s\".",
1011 switch (parsed_sm_list) {
1025 sm_list = parsed_sm_list;
1038 for (uint8_t x = 0; x < pd->
idx; x++) {
1052 "preceding match in the same buffer");
1055 }
else if (prev_pm == NULL) {
1069 DetectPcreFree(
de_ctx, pd);
1083 for (uint8_t i = 0; i < pd->
idx; i++) {
1091 static int g_file_data_buffer_id = 0;
1092 static int g_http_header_buffer_id = 0;
1093 static int g_dce_stub_data_buffer_id = 0;
1098 static int DetectPcreParseTest01 (
void)
1101 const char *teststring =
"/blah/7";
1107 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1117 static int DetectPcreParseTest02 (
void)
1120 const char *teststring =
"/blah/Ui$";
1126 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1137 static int DetectPcreParseTest03 (
void)
1140 const char *teststring =
"/blah/UNi";
1146 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1156 static int DetectPcreParseTest04 (
void)
1159 const char *teststring =
"/b\\\"lah/i";
1165 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1169 DetectPcreFree(
de_ctx, pd);
1177 static int DetectPcreParseTest05 (
void)
1180 const char *teststring =
"/b(l|a)h/";
1186 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1190 DetectPcreFree(
de_ctx, pd);
1198 static int DetectPcreParseTest06 (
void)
1201 const char *teststring =
"/b(l|a)h/smi";
1207 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1211 DetectPcreFree(
de_ctx, pd);
1219 static int DetectPcreParseTest07 (
void)
1222 const char *teststring =
"/blah/Ui";
1228 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1232 DetectPcreFree(
de_ctx, pd);
1240 static int DetectPcreParseTest08 (
void)
1243 const char *teststring =
"/b(l|a)h/O";
1249 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1253 DetectPcreFree(
de_ctx, pd);
1262 static int DetectPcreParseTest09 (
void)
1265 const char *teststring =
"/lala\\\\/";
1271 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1274 DetectPcreFree(
de_ctx, pd);
1282 static int DetectPcreParseTest10(
void)
1312 static int DetectPcreParseTest15(
void)
1319 "alert tcp any any -> any any "
1320 "(msg:\"Testing pcre relative http_method\"; "
1322 "http_method; pcre:\"/abc/RM\"; sid:1;)");
1332 static int DetectPcreParseTest16(
void)
1339 "alert tcp any any -> any any "
1340 "(msg:\"Testing pcre relative http_cookie\"; "
1341 "content:\"test\"; "
1342 "http_cookie; pcre:\"/abc/RC\"; sid:1;)");
1351 static int DetectPcreParseTest17(
void)
1358 "alert tcp any any -> any any "
1359 "(msg:\"Testing pcre relative http_raw_header\"; "
1360 "flow:to_server; content:\"test\"; "
1361 "http_raw_header; pcre:\"/abc/RD\"; sid:1;)");
1370 static int DetectPcreParseTest18(
void)
1377 "alert tcp any any -> any any "
1378 "(msg:\"Testing pcre relative http_header\"; "
1379 "content:\"test\"; "
1380 "http_header; pcre:\"/abc/RH\"; sid:1;)");
1389 static int DetectPcreParseTest19(
void)
1396 "alert tcp any any -> any any "
1397 "(msg:\"Testing pcre relative http_client_body\"; "
1398 "content:\"test\"; "
1399 "http_client_body; pcre:\"/abc/RP\"; sid:1;)");
1408 static int DetectPcreParseTest20(
void)
1416 "alert tcp any any -> any any "
1417 "(msg:\"Testing http_raw_uri\"; "
1418 "content:\"test\"; "
1419 "http_raw_uri; pcre:\"/abc/RI\"; sid:1;)");
1428 static int DetectPcreParseTest21(
void)
1436 "alert tcp any any -> any any "
1437 "(msg:\"Testing pcre relative uricontent\"; "
1438 "uricontent:\"test\"; "
1439 "pcre:\"/abc/RU\"; sid:1;)");
1448 static int DetectPcreParseTest22(
void)
1456 "alert tcp any any -> any any "
1457 "(msg:\"Testing pcre relative http_uri\"; "
1458 "content:\"test\"; "
1459 "http_uri; pcre:\"/abc/RU\"; sid:1;)");
1468 static int DetectPcreParseTest23(
void)
1476 "alert tcp any any -> any any "
1477 "(msg:\"Testing inconsistent pcre relative\"; "
1479 "http_cookie; pcre:\"/abc/RM\"; sid:1;)");
1488 static int DetectPcreParseTest24(
void)
1496 "alert tcp any any -> any any "
1497 "(msg:\"Testing inconsistent pcre modifiers\"; "
1498 "pcre:\"/abc/UI\"; sid:1;)");
1507 static int DetectPcreParseTest25(
void)
1515 "alert tcp any any -> any any "
1516 "(msg:\"Testing inconsistent pcre modifiers\"; "
1517 "pcre:\"/abc/DH\"; sid:1;)");
1526 static int DetectPcreParseTest26(
void)
1534 "alert http any any -> any any "
1535 "(msg:\"Testing inconsistent pcre modifiers\"; "
1536 "pcre:\"/abc/F\"; sid:1;)");
1545 static int DetectPcreParseTest27(
void)
1553 "(content:\"baduricontent\"; http_raw_uri; "
1554 "pcre:\"/^[a-z]{5}\\.html/R\"; sid:2; rev:2;)");
1563 static int DetectPcreParseTest28(
void)
1571 "(content:\"|2E|suricata\"; http_host; pcre:\"/\\x2Esuricata$/W\"; "
1579 static int DetectPcreTestSig01(
void)
1581 uint8_t *buf = (uint8_t *)
"lalala lalala\\ lala\n";
1582 uint16_t buflen = strlen((
char *)buf);
1585 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; pcre:\"/ "
1586 "lalala\\\\/\"; sid:1;)";
1594 static int DetectPcreTestSig02(
void)
1596 uint8_t *buf = (uint8_t *)
"lalala\n";
1597 uint16_t buflen = strlen((
char *)buf);
1600 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1601 "pcre:\"/^(la)+$/\"; sid:1;)";
1609 static int DetectPcreTestSig03(
void)
1612 uint8_t *buf = (uint8_t *)
"lalala";
1613 uint16_t buflen = strlen((
char *)buf);
1616 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1617 "pcre:\"/^(la)+$/\"; sid:1;)";
1626 static int DetectPcreTxBodyChunksTest01(
void)
1631 uint8_t httpbuf1[] =
"GET / HTTP/1.1\r\n";
1632 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1633 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1634 uint8_t httpbuf4[] =
"Body one!!";
1635 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1636 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1637 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1638 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1639 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1640 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1641 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1642 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1643 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1644 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1647 memset(&
f, 0,
sizeof(
f));
1648 memset(&
ssn, 0,
sizeof(
ssn));
1724 static int DetectPcreTxBodyChunksTest02(
void)
1732 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1733 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1734 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1735 uint8_t httpbuf4[] =
"Body one!!";
1736 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1737 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1738 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1739 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1740 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1741 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1742 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1743 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1744 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1745 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1750 memset(&
f, 0,
sizeof(
f));
1751 memset(&
ssn, 0,
sizeof(
ssn));
1773 s =
DetectEngineAppendSig(
de_ctx,
"alert tcp any any -> any any (content:\"POST\"; http_method; content:\"Mozilla\"; http_header; content:\"dummy\"; http_cookie; pcre:\"/one/P\"; sid:1; rev:1;)");
1775 s =
DetectEngineAppendSig(
de_ctx,
"alert tcp any any -> any any (content:\"GET\"; http_method; content:\"Firefox\"; http_header; content:\"dummy2\"; http_cookie; pcre:\"/two/P\"; sid:2; rev:1;)");
1874 static int DetectPcreTxBodyChunksTest03(
void)
1882 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1883 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1884 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1885 uint8_t httpbuf4[] =
"Body one!!";
1886 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1887 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1888 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1889 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1890 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1891 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1892 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1893 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1894 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1895 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1900 memset(&
f, 0,
sizeof(
f));
1901 memset(&
ssn, 0,
sizeof(
ssn));
1923 s =
DetectEngineAppendSig(
de_ctx,
"alert tcp any any -> any any (content:\"POST\"; http_method; content:\"Mozilla\"; http_header; content:\"dummy\"; http_cookie; pcre:\"/one/P\"; sid:1; rev:1;)");
1925 s =
DetectEngineAppendSig(
de_ctx,
"alert tcp any any -> any any (content:\"GET\"; http_method; content:\"Firefox\"; http_header; content:\"dummy2\"; http_cookie; pcre:\"/two/P\"; sid:2; rev:1;)");
2009 static int DetectPcreParseHttpHost(
void)
2017 DetectPcreData *pd = DetectPcreParse(
de_ctx,
"/domain\\.com/W", &list, NULL, 0,
false, &alproto);
2019 DetectPcreFree(
de_ctx, pd);
2022 pd = DetectPcreParse(
de_ctx,
"/dOmain\\.com/W", &list, NULL, 0,
false, &alproto);
2027 pd = DetectPcreParse(
de_ctx,
"/domain\\D+\\.com/W", &list, NULL, 0,
false, &alproto);
2029 DetectPcreFree(
de_ctx, pd);
2034 pd = DetectPcreParse(
de_ctx,
"/\\\\Ddomain\\.com/W", &list, NULL, 0,
false, &alproto);
2044 static int DetectPcreParseCaptureTest(
void)
2050 "(content:\"Server: \"; http_header; pcre:\"/(.*)\\r\\n/HR, flow:somecapture\"; content:\"xyz\"; http_header; sid:1;)");
2053 "(content:\"Server: \"; http_header; pcre:\"/(flow:.*)\\r\\n/HR\"; content:\"xyz\"; http_header; sid:2;)");
2056 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)([0-9]+)\\r\\n/HR, flow:somecapture, pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2059 "alert http any any -> any any "
2060 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)\\r\\n/HR, flow:somecapture, "
2061 "pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2079 static void DetectPcreRegisterTests(
void)
2111 UtRegisterTest(
"DetectPcreTestSig02 -- anchored pcre", DetectPcreTestSig02);
2112 UtRegisterTest(
"DetectPcreTestSig03 -- anchored pcre", DetectPcreTestSig03);
2115 DetectPcreTxBodyChunksTest01);
2116 UtRegisterTest(
"DetectPcreTxBodyChunksTest02 -- modifier P, body chunks per tx",
2117 DetectPcreTxBodyChunksTest02);
2118 UtRegisterTest(
"DetectPcreTxBodyChunksTest03 -- modifier P, body chunks per tx",
2119 DetectPcreTxBodyChunksTest03);
2121 UtRegisterTest(
"DetectPcreParseHttpHost", DetectPcreParseHttpHost);
2122 UtRegisterTest(
"DetectPcreParseCaptureTest", DetectPcreParseCaptureTest);