66 #define PARSE_CAPTURE_REGEX "\\(\\?P\\<([A-z]+)\\_([A-z0-9_]+)\\>"
67 #define PARSE_REGEX "(?<!\\\\)/(.*(?<!(?<!\\\\)\\\\))/([^\"]*)"
69 static int pcre_match_limit = 0;
70 static int pcre_match_limit_recursion = 0;
76 static int pcre2_use_jit = 1;
84 const char *
str,
const size_t strlen,
int start_offset,
int options,
85 pcre2_match_data *match)
94 static void DetectPcreRegisterTests(
void);
115 SCLogDebug(
"Using PCRE match-limit setting of: %i", pcre_match_limit);
117 pcre_match_limit = (int)val;
119 SCLogInfo(
"Using PCRE match-limit setting of: %i", pcre_match_limit);
121 SCLogDebug(
"Using PCRE match-limit setting of: %i", pcre_match_limit);
127 if (!
SCConfGetInt(
"pcre.match-limit-recursion", &val)) {
129 SCLogDebug(
"Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion);
131 pcre_match_limit_recursion = (int)val;
133 SCLogInfo(
"Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion);
135 SCLogDebug(
"Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion);
140 if (parse_regex == NULL) {
141 FatalError(
"pcre2 compile failed for parse_regex");
147 if (parse_capture_regex == NULL) {
148 FatalError(
"pcre2 compile failed for parse_capture_regex");
151 #ifdef PCRE2_HAVE_JIT
153 SCLogConfig(
"PCRE2 won't use JIT as OS doesn't allow RWX pages");
160 uint8_t *str_ptr, uint16_t capture_len)
165 if (json_key == NULL) {
177 SCJsonBuilder *js = SCJbNewObject();
182 SCJbSetStringFromBytes(js, json_key, str_ptr, capture_len);
183 uint32_t js_len = (uint32_t)SCJbLen(js);
185 SCLogDebug(
"Captured length is too long for JSON.");
191 SCLogDebug(
"Captured length is zero for JSON.");
229 const uint8_t *ptr = NULL;
231 PCRE2_SIZE capture_len = 0;
243 int start_offset = 0;
249 pcre2_match_data *match =
252 ret = DetectPcreExec(det_ctx, pe, (
char *)ptr,
len, start_offset, 0, match);
255 if (ret == PCRE2_ERROR_NOMATCH) {
263 }
else if (ret >= 0) {
275 if (ret > 1 && pe->
idx != 0) {
277 for (x = 0; x < pe->
idx; x++) {
279 const char *pcre2_str_ptr = NULL;
280 ret = pcre2_substring_get_bynumber(
281 match, x + 1, (PCRE2_UCHAR8 **)&pcre2_str_ptr, &capture_len);
283 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
287 capture_len = (capture_len < 0xffff) ? (uint16_t)capture_len : 0xffff;
288 uint8_t *str_ptr =
SCMalloc(capture_len);
290 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
293 memcpy(str_ptr, pcre2_str_ptr, capture_len);
294 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
301 const char *pcre2_str_ptr2 = NULL;
303 uint16_t key_len = (capture_len < 0xff) ? (uint16_t)capture_len : 0xff;
304 int ret2 = pcre2_substring_get_bynumber(
305 match, x + 2, (PCRE2_UCHAR8 **)&pcre2_str_ptr2, &capture_len);
309 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
312 capture_len = (capture_len < 0xffff) ? (uint16_t)capture_len : 0xffff;
313 uint8_t *str_ptr2 =
SCMalloc(capture_len);
316 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
319 memcpy(str_ptr2, pcre2_str_ptr2, capture_len);
320 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
323 (uint8_t *)str_ptr2, (uint16_t)capture_len,
335 (void)DetectAlertStoreMatch(det_ctx, s, pe->
capids[x], (uint8_t *)str_ptr,
336 (uint16_t)capture_len);
345 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
347 det_ctx->
buffer_offset = (uint32_t)((ptr + ov[1]) - payload);
360 static int DetectPcreSetList(
int list,
int set)
363 SCLogError(
"only one pcre option to specify a buffer type is allowed");
369 static int DetectPcreHasUpperCase(
const char *re)
371 size_t len = strlen(re);
372 bool is_meta =
false;
373 bool is_meta_hex =
false;
374 int meta_hex_cnt = 0;
376 for (
size_t i = 0; i <
len; i++) {
380 if (meta_hex_cnt == 2) {
384 }
else if (is_meta) {
391 else if (re[i] ==
'\\') {
394 else if (isupper((
unsigned char)re[i])) {
403 const char *regexstr,
int *sm_list,
char *capture_names,
404 size_t capture_names_size,
bool negate,
AppProto *alproto)
406 pcre2_match_data *match = NULL;
412 int ret = 0, res = 0;
413 int check_host_header = 0;
414 char op_str[64] =
"";
416 bool apply_match_limit =
false;
419 const char *fcap = strstr(regexstr,
"flow:");
420 const char *pcap = strstr(regexstr,
"pkt:");
421 const char *acap = strstr(regexstr,
"alert:");
424 size_t slen = strlen(regexstr) + 1;
425 if (fcap || pcap || acap) {
432 cut_capture = (int)(fcap - regexstr);
436 cut_capture = (int)
MIN(cut_capture, (pcap - regexstr));
438 cut_capture = (int)(pcap - regexstr);
444 cut_capture =
MIN(cut_capture, (
int)(acap - regexstr));
446 cut_capture = (int)(acap - regexstr);
451 if (cut_capture > 1) {
452 int offset = cut_capture - 1;
455 if (regexstr[
offset] ==
',' || regexstr[
offset] ==
' ') {
462 if (cut_capture == (
offset + 1)) {
463 SCLogDebug(
"missing separators, assume it's part of the regex");
466 strlcpy(capture_names, regexstr+cut_capture, capture_names_size);
467 if (capture_names[strlen(capture_names)-1] ==
'"')
468 capture_names[strlen(capture_names)-1] =
'\0';
476 match = pcre2_match_data_create_from_pattern(parse_regex->
regex, NULL);
481 ret = pcre2_match(parse_regex->
regex, (PCRE2_SPTR8)regexstr, slen, 0, 0, match, NULL);
487 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)re, &slen);
489 SCLogError(
"pcre2_substring_copy_bynumber failed");
490 pcre2_match_data_free(match);
495 size_t copylen =
sizeof(op_str);
496 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)op_str, ©len);
498 SCLogError(
"pcre2_substring_copy_bynumber failed");
499 pcre2_match_data_free(match);
519 opts |= PCRE2_ANCHORED;
522 opts |= PCRE2_DOLLAR_ENDONLY;
525 opts |= PCRE2_UNGREEDY;
529 opts |= PCRE2_CASELESS;
533 opts |= PCRE2_MULTILINE;
536 opts |= PCRE2_DOTALL;
539 opts |= PCRE2_EXTENDED;
543 apply_match_limit =
true;
548 SCLogError(
"regex modifier 'B' inconsistent with chosen buffer");
561 SCLogError(
"regex modifier 'U' inconsistent with 'B'");
565 *sm_list = DetectPcreSetList(*sm_list, list);
571 SCLogError(
"regex modifier 'V' inconsistent with 'B'");
575 *sm_list = DetectPcreSetList(*sm_list, list);
581 SCLogError(
"regex modifier 'W' inconsistent with 'B'");
585 *sm_list = DetectPcreSetList(*sm_list, list);
587 check_host_header = 1;
592 SCLogError(
"regex modifier 'Z' inconsistent with 'B'");
596 *sm_list = DetectPcreSetList(*sm_list, list);
602 SCLogError(
"regex modifier 'H' inconsistent with 'B'");
606 *sm_list = DetectPcreSetList(*sm_list, list);
611 SCLogError(
"regex modifier 'I' inconsistent with 'B'");
615 *sm_list = DetectPcreSetList(*sm_list, list);
621 *sm_list = DetectPcreSetList(*sm_list, list);
627 SCLogError(
"regex modifier 'M' inconsistent with 'B'");
631 *sm_list = DetectPcreSetList(*sm_list, list);
637 SCLogError(
"regex modifier 'C' inconsistent with 'B'");
641 *sm_list = DetectPcreSetList(*sm_list, list);
648 *sm_list = DetectPcreSetList(*sm_list, list);
655 *sm_list = DetectPcreSetList(*sm_list, list);
662 *sm_list = DetectPcreSetList(*sm_list, list);
669 *sm_list = DetectPcreSetList(*sm_list, list);
674 SCLogError(
"unknown regex modifier '%c'", *op);
686 if (check_host_header) {
689 "specified along with \"i(caseless)\" modifier. "
690 "Since the hostname buffer we match against "
691 "is actually lowercase, having a "
692 "nocase is redundant.");
694 else if (DetectPcreHasUpperCase(re)) {
696 "specified has an uppercase char. "
697 "Since the hostname buffer we match against "
698 "is actually lowercase, please specify an "
699 "all lowercase based pcre.");
709 if (capture_names == NULL || strlen(capture_names) == 0)
710 opts |= PCRE2_NO_AUTO_CAPTURE;
712 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
715 for (
size_t i = 0; i < strlen(re); i++) {
721 }
else if (re[i] ==
'\\') {
728 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
730 opts &= ~PCRE2_NO_AUTO_CAPTURE;
732 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
735 PCRE2_UCHAR errbuffer[256];
736 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
737 SCLogError(
"pcre2 compile of \"%s\" failed at "
739 regexstr, (
int)eo2, errbuffer);
743 #ifdef PCRE2_HAVE_JIT
750 SCLogDebug(
"PCRE2 JIT compiler does not support: %s. "
751 "Falling back to regular PCRE2 handling (%s:%d)",
759 SCLogError(
"pcre2 could not create match context");
763 if (apply_match_limit) {
764 if (pcre_match_limit >= -1) {
767 if (pcre_match_limit_recursion >= -1) {
776 pcre2_match_data_free(match);
780 pcre2_match_data_free(match);
781 DetectPcreFree(
de_ctx, pd);
791 int ret = 0, res = 0;
792 char type_str[16] =
"";
793 const char *orig_right_edge = regexstr + strlen(regexstr);
799 pcre2_match_data *match = NULL;
801 SCLogDebug(
"regexstr %s, pd %p", regexstr, pd);
803 ret = pcre2_pattern_info(pd->
parse_regex.
regex, PCRE2_INFO_CAPTURECOUNT, &capture_cnt);
804 SCLogDebug(
"ret %d capture_cnt %d", ret, capture_cnt);
805 if (ret == 0 && capture_cnt && strlen(capture_names) > 0)
808 while ((name_array[name_idx] = strtok_r(name_idx == 0 ? capture_names : NULL,
" ,", &ptr))){
809 if (name_idx > (capture_cnt - 1)) {
811 "var capture names than capturing substrings");
814 SCLogDebug(
"name '%s'", name_array[name_idx]);
816 if (strcmp(name_array[name_idx],
"pkt:key") == 0) {
824 }
else if (key == 1 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
829 }
else if (key == 0 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
831 }
else if (key == 1) {
834 }
else if (strncmp(name_array[name_idx],
"flow:", 5) == 0) {
835 uint32_t varname_id =
843 }
else if (strncmp(name_array[name_idx],
"pkt:", 4) == 0) {
844 uint32_t varname_id =
853 }
else if (strncmp(name_array[name_idx],
"alert:", 6) == 0) {
854 uint32_t varname_id =
864 "var capture names must start with 'pkt:' or 'flow:'");
876 size_t cap_buffer_len = strlen(regexstr) + 1;
878 char capture_str[cap_buffer_len];
879 memset(capture_str, 0x00, cap_buffer_len);
889 pcre2_match_data_free(match);
892 copylen =
sizeof(type_str);
893 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)type_str, ©len);
895 SCLogError(
"pcre2_substring_copy_bynumber failed");
898 cap_buffer_len = strlen(regexstr) + 1;
899 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)capture_str, &cap_buffer_len);
901 SCLogError(
"pcre2_substring_copy_bynumber failed");
904 if (strlen(capture_str) == 0 || strlen(type_str) == 0) {
912 SCLogError(
"rule can have maximally %d pkt/flow "
915 pcre2_match_data_free(match);
919 if (strcmp(type_str,
"pkt") == 0) {
927 }
else if (strcmp(type_str,
"flow") == 0) {
934 }
else if (strcmp(type_str,
"alert") == 0) {
944 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
947 pcre2_match_data_free(match);
950 if (regexstr >= orig_right_edge)
956 pcre2_match_data_free(match);
960 static void *DetectPcreThreadInit(
void *data)
963 pcre2_match_data *match = pcre2_match_data_create_from_pattern(pd->
parse_regex.
regex, NULL);
967 static void DetectPcreThreadFree(
void *
ctx)
970 pcre2_match_data *match = (pcre2_match_data *)
ctx;
971 pcre2_match_data_free(match);
980 char capture_names[1024] =
"";
983 pd = DetectPcreParse(
de_ctx, regexstr, &parsed_sm_list,
988 if (DetectPcreParseCapture(regexstr,
de_ctx, pd, capture_names) < 0)
992 de_ctx,
"pcre", DetectPcreThreadInit, (
void *)pd, DetectPcreThreadFree, 0);
999 SCLogError(
"Expression seen with a sticky buffer still set; either (1) reset sticky "
1000 "buffer with pkt_data or (2) use a sticky buffer providing \"%s\".",
1009 switch (parsed_sm_list) {
1023 sm_list = parsed_sm_list;
1036 for (uint8_t x = 0; x < pd->
idx; x++) {
1050 "preceding match in the same buffer");
1053 }
else if (prev_pm == NULL) {
1067 DetectPcreFree(
de_ctx, pd);
1081 for (uint8_t i = 0; i < pd->
idx; i++) {
1089 static int g_file_data_buffer_id = 0;
1090 static int g_http_header_buffer_id = 0;
1091 static int g_dce_stub_data_buffer_id = 0;
1096 static int DetectPcreParseTest01 (
void)
1099 const char *teststring =
"/blah/7";
1105 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1115 static int DetectPcreParseTest02 (
void)
1118 const char *teststring =
"/blah/Ui$";
1124 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1135 static int DetectPcreParseTest03 (
void)
1138 const char *teststring =
"/blah/UNi";
1144 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1154 static int DetectPcreParseTest04 (
void)
1157 const char *teststring =
"/b\\\"lah/i";
1163 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1167 DetectPcreFree(
de_ctx, pd);
1175 static int DetectPcreParseTest05 (
void)
1178 const char *teststring =
"/b(l|a)h/";
1184 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1188 DetectPcreFree(
de_ctx, pd);
1196 static int DetectPcreParseTest06 (
void)
1199 const char *teststring =
"/b(l|a)h/smi";
1205 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1209 DetectPcreFree(
de_ctx, pd);
1217 static int DetectPcreParseTest07 (
void)
1220 const char *teststring =
"/blah/Ui";
1226 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1230 DetectPcreFree(
de_ctx, pd);
1238 static int DetectPcreParseTest08 (
void)
1241 const char *teststring =
"/b(l|a)h/O";
1247 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1251 DetectPcreFree(
de_ctx, pd);
1260 static int DetectPcreParseTest09 (
void)
1263 const char *teststring =
"/lala\\\\/";
1269 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1272 DetectPcreFree(
de_ctx, pd);
1280 static int DetectPcreParseTest10(
void)
1310 static int DetectPcreParseTest15(
void)
1317 "alert tcp any any -> any any "
1318 "(msg:\"Testing pcre relative http_method\"; "
1320 "http_method; pcre:\"/abc/RM\"; sid:1;)");
1330 static int DetectPcreParseTest16(
void)
1337 "alert tcp any any -> any any "
1338 "(msg:\"Testing pcre relative http_cookie\"; "
1339 "content:\"test\"; "
1340 "http_cookie; pcre:\"/abc/RC\"; sid:1;)");
1349 static int DetectPcreParseTest17(
void)
1356 "alert tcp any any -> any any "
1357 "(msg:\"Testing pcre relative http_raw_header\"; "
1358 "flow:to_server; content:\"test\"; "
1359 "http_raw_header; pcre:\"/abc/RD\"; sid:1;)");
1368 static int DetectPcreParseTest18(
void)
1375 "alert tcp any any -> any any "
1376 "(msg:\"Testing pcre relative http_header\"; "
1377 "content:\"test\"; "
1378 "http_header; pcre:\"/abc/RH\"; sid:1;)");
1387 static int DetectPcreParseTest19(
void)
1394 "alert tcp any any -> any any "
1395 "(msg:\"Testing pcre relative http_client_body\"; "
1396 "content:\"test\"; "
1397 "http_client_body; pcre:\"/abc/RP\"; sid:1;)");
1406 static int DetectPcreParseTest20(
void)
1414 "alert tcp any any -> any any "
1415 "(msg:\"Testing http_raw_uri\"; "
1416 "content:\"test\"; "
1417 "http_raw_uri; pcre:\"/abc/RI\"; sid:1;)");
1426 static int DetectPcreParseTest21(
void)
1434 "alert tcp any any -> any any "
1435 "(msg:\"Testing pcre relative uricontent\"; "
1436 "uricontent:\"test\"; "
1437 "pcre:\"/abc/RU\"; sid:1;)");
1446 static int DetectPcreParseTest22(
void)
1454 "alert tcp any any -> any any "
1455 "(msg:\"Testing pcre relative http_uri\"; "
1456 "content:\"test\"; "
1457 "http_uri; pcre:\"/abc/RU\"; sid:1;)");
1466 static int DetectPcreParseTest23(
void)
1474 "alert tcp any any -> any any "
1475 "(msg:\"Testing inconsistent pcre relative\"; "
1477 "http_cookie; pcre:\"/abc/RM\"; sid:1;)");
1486 static int DetectPcreParseTest24(
void)
1494 "alert tcp any any -> any any "
1495 "(msg:\"Testing inconsistent pcre modifiers\"; "
1496 "pcre:\"/abc/UI\"; sid:1;)");
1505 static int DetectPcreParseTest25(
void)
1513 "alert tcp any any -> any any "
1514 "(msg:\"Testing inconsistent pcre modifiers\"; "
1515 "pcre:\"/abc/DH\"; sid:1;)");
1524 static int DetectPcreParseTest26(
void)
1532 "alert http any any -> any any "
1533 "(msg:\"Testing inconsistent pcre modifiers\"; "
1534 "pcre:\"/abc/F\"; sid:1;)");
1543 static int DetectPcreParseTest27(
void)
1551 "(content:\"baduricontent\"; http_raw_uri; "
1552 "pcre:\"/^[a-z]{5}\\.html/R\"; sid:2; rev:2;)");
1561 static int DetectPcreParseTest28(
void)
1569 "(content:\"|2E|suricata\"; http_host; pcre:\"/\\x2Esuricata$/W\"; "
1577 static int DetectPcreTestSig01(
void)
1579 uint8_t *buf = (uint8_t *)
"lalala lalala\\ lala\n";
1580 uint16_t buflen = strlen((
char *)buf);
1583 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; pcre:\"/ "
1584 "lalala\\\\/\"; sid:1;)";
1592 static int DetectPcreTestSig02(
void)
1594 uint8_t *buf = (uint8_t *)
"lalala\n";
1595 uint16_t buflen = strlen((
char *)buf);
1598 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1599 "pcre:\"/^(la)+$/\"; sid:1;)";
1607 static int DetectPcreTestSig03(
void)
1610 uint8_t *buf = (uint8_t *)
"lalala";
1611 uint16_t buflen = strlen((
char *)buf);
1614 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1615 "pcre:\"/^(la)+$/\"; sid:1;)";
1624 static int DetectPcreTxBodyChunksTest01(
void)
1629 uint8_t httpbuf1[] =
"GET / HTTP/1.1\r\n";
1630 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1631 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1632 uint8_t httpbuf4[] =
"Body one!!";
1633 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1634 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1635 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1636 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1637 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1638 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1639 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1640 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1641 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1642 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1645 memset(&f, 0,
sizeof(f));
1646 memset(&ssn, 0,
sizeof(ssn));
1652 f.
proto = IPPROTO_TCP;
1722 static int DetectPcreTxBodyChunksTest02(
void)
1730 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1731 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1732 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1733 uint8_t httpbuf4[] =
"Body one!!";
1734 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1735 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1736 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1737 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1738 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1739 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1740 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1741 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1742 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1743 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1748 memset(&f, 0,
sizeof(f));
1749 memset(&ssn, 0,
sizeof(ssn));
1755 f.
proto = IPPROTO_TCP;
1771 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;)");
1773 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;)");
1872 static int DetectPcreTxBodyChunksTest03(
void)
1880 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1881 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1882 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1883 uint8_t httpbuf4[] =
"Body one!!";
1884 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1885 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1886 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1887 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1888 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1889 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1890 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1891 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1892 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1893 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1898 memset(&f, 0,
sizeof(f));
1899 memset(&ssn, 0,
sizeof(ssn));
1905 f.
proto = IPPROTO_TCP;
1921 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;)");
1923 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;)");
2007 static int DetectPcreParseHttpHost(
void)
2015 DetectPcreData *pd = DetectPcreParse(
de_ctx,
"/domain\\.com/W", &list, NULL, 0,
false, &alproto);
2017 DetectPcreFree(
de_ctx, pd);
2020 pd = DetectPcreParse(
de_ctx,
"/dOmain\\.com/W", &list, NULL, 0,
false, &alproto);
2025 pd = DetectPcreParse(
de_ctx,
"/domain\\D+\\.com/W", &list, NULL, 0,
false, &alproto);
2027 DetectPcreFree(
de_ctx, pd);
2032 pd = DetectPcreParse(
de_ctx,
"/\\\\Ddomain\\.com/W", &list, NULL, 0,
false, &alproto);
2042 static int DetectPcreParseCaptureTest(
void)
2048 "(content:\"Server: \"; http_header; pcre:\"/(.*)\\r\\n/HR, flow:somecapture\"; content:\"xyz\"; http_header; sid:1;)");
2051 "(content:\"Server: \"; http_header; pcre:\"/(flow:.*)\\r\\n/HR\"; content:\"xyz\"; http_header; sid:2;)");
2054 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)([0-9]+)\\r\\n/HR, flow:somecapture, pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2057 "alert http any any -> any any "
2058 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)\\r\\n/HR, flow:somecapture, "
2059 "pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2077 static void DetectPcreRegisterTests(
void)
2109 UtRegisterTest(
"DetectPcreTestSig02 -- anchored pcre", DetectPcreTestSig02);
2110 UtRegisterTest(
"DetectPcreTestSig03 -- anchored pcre", DetectPcreTestSig03);
2113 DetectPcreTxBodyChunksTest01);
2114 UtRegisterTest(
"DetectPcreTxBodyChunksTest02 -- modifier P, body chunks per tx",
2115 DetectPcreTxBodyChunksTest02);
2116 UtRegisterTest(
"DetectPcreTxBodyChunksTest03 -- modifier P, body chunks per tx",
2117 DetectPcreTxBodyChunksTest03);
2119 UtRegisterTest(
"DetectPcreParseHttpHost", DetectPcreParseHttpHost);
2120 UtRegisterTest(
"DetectPcreParseCaptureTest", DetectPcreParseCaptureTest);