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++) {
283 const char *pcre2_str_ptr = NULL;
284 ret = pcre2_substring_get_bynumber(
285 match, x + 1, (PCRE2_UCHAR8 **)&pcre2_str_ptr, &capture_len);
287 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
291 capture_len = (capture_len < 0xffff) ? (uint16_t)capture_len : 0xffff;
292 uint8_t *str_ptr =
SCMalloc(capture_len);
294 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
297 memcpy(str_ptr, pcre2_str_ptr, capture_len);
298 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
305 const char *pcre2_str_ptr2 = NULL;
307 uint16_t key_len = (capture_len < 0xff) ? (uint16_t)capture_len : 0xff;
308 int ret2 = pcre2_substring_get_bynumber(
309 match, x + 2, (PCRE2_UCHAR8 **)&pcre2_str_ptr2, &capture_len);
313 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
316 capture_len = (capture_len < 0xffff) ? (uint16_t)capture_len : 0xffff;
317 uint8_t *str_ptr2 =
SCMalloc(capture_len);
320 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
323 memcpy(str_ptr2, pcre2_str_ptr2, capture_len);
324 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
327 (uint8_t *)str_ptr2, (uint16_t)capture_len,
339 (void)DetectAlertStoreMatch(det_ctx, s, pe->
capids[x], (uint8_t *)str_ptr,
340 (uint16_t)capture_len);
349 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
351 det_ctx->
buffer_offset = (uint32_t)((ptr + ov[1]) - payload);
364 static int DetectPcreSetList(
int list,
int set)
367 SCLogError(
"only one pcre option to specify a buffer type is allowed");
373 static bool DetectPcreHasUnicodeCluster(
const char *re)
375 return strstr(re,
"\\X") != NULL;
378 static int DetectPcreHasUpperCase(
const char *re)
380 size_t len = strlen(re);
381 bool is_meta =
false;
382 bool is_meta_hex =
false;
383 int meta_hex_cnt = 0;
385 for (
size_t i = 0; i <
len; i++) {
389 if (meta_hex_cnt == 2) {
393 }
else if (is_meta) {
400 else if (re[i] ==
'\\') {
403 else if (isupper((
unsigned char)re[i])) {
412 const char *regexstr,
int *sm_list,
char *capture_names,
413 size_t capture_names_size,
bool negate,
AppProto *alproto)
415 pcre2_match_data *match = NULL;
421 int ret = 0, res = 0;
422 int check_host_header = 0;
423 char op_str[64] =
"";
425 bool apply_match_limit =
false;
428 const char *fcap = strstr(regexstr,
"flow:");
429 const char *pcap = strstr(regexstr,
"pkt:");
430 const char *acap = strstr(regexstr,
"alert:");
433 size_t slen = strlen(regexstr) + 1;
434 if (fcap || pcap || acap) {
441 cut_capture = (int)(fcap - regexstr);
445 cut_capture = (int)
MIN(cut_capture, (pcap - regexstr));
447 cut_capture = (int)(pcap - regexstr);
453 cut_capture =
MIN(cut_capture, (
int)(acap - regexstr));
455 cut_capture = (int)(acap - regexstr);
460 if (cut_capture > 1) {
461 int offset = cut_capture - 1;
464 if (regexstr[
offset] ==
',' || regexstr[
offset] ==
' ') {
471 if (cut_capture == (
offset + 1)) {
472 SCLogDebug(
"missing separators, assume it's part of the regex");
475 strlcpy(capture_names, regexstr+cut_capture, capture_names_size);
476 if (capture_names[strlen(capture_names)-1] ==
'"')
477 capture_names[strlen(capture_names)-1] =
'\0';
485 match = pcre2_match_data_create_from_pattern(parse_regex->
regex, NULL);
490 ret = pcre2_match(parse_regex->
regex, (PCRE2_SPTR8)regexstr, slen, 0, 0, match, NULL);
496 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)re, &slen);
498 SCLogError(
"pcre2_substring_copy_bynumber failed");
499 pcre2_match_data_free(match);
504 size_t copylen =
sizeof(op_str);
505 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)op_str, ©len);
507 SCLogError(
"pcre2_substring_copy_bynumber failed");
508 pcre2_match_data_free(match);
528 opts |= PCRE2_ANCHORED;
531 opts |= PCRE2_DOLLAR_ENDONLY;
534 opts |= PCRE2_UNGREEDY;
538 opts |= PCRE2_CASELESS;
542 opts |= PCRE2_MULTILINE;
545 opts |= PCRE2_DOTALL;
548 opts |= PCRE2_EXTENDED;
552 apply_match_limit =
true;
557 SCLogError(
"regex modifier 'B' inconsistent with chosen buffer");
570 SCLogError(
"regex modifier 'U' inconsistent with 'B'");
574 *sm_list = DetectPcreSetList(*sm_list, list);
580 SCLogError(
"regex modifier 'V' inconsistent with 'B'");
584 *sm_list = DetectPcreSetList(*sm_list, list);
590 SCLogError(
"regex modifier 'W' inconsistent with 'B'");
594 *sm_list = DetectPcreSetList(*sm_list, list);
596 check_host_header = 1;
601 SCLogError(
"regex modifier 'Z' inconsistent with 'B'");
605 *sm_list = DetectPcreSetList(*sm_list, list);
611 SCLogError(
"regex modifier 'H' inconsistent with 'B'");
615 *sm_list = DetectPcreSetList(*sm_list, list);
620 SCLogError(
"regex modifier 'I' inconsistent with 'B'");
624 *sm_list = DetectPcreSetList(*sm_list, list);
630 *sm_list = DetectPcreSetList(*sm_list, list);
636 SCLogError(
"regex modifier 'M' inconsistent with 'B'");
640 *sm_list = DetectPcreSetList(*sm_list, list);
646 SCLogError(
"regex modifier 'C' inconsistent with 'B'");
650 *sm_list = DetectPcreSetList(*sm_list, list);
657 *sm_list = DetectPcreSetList(*sm_list, list);
664 *sm_list = DetectPcreSetList(*sm_list, list);
671 *sm_list = DetectPcreSetList(*sm_list, list);
678 *sm_list = DetectPcreSetList(*sm_list, list);
683 SCLogError(
"unknown regex modifier '%c'", *op);
695 if (check_host_header) {
698 "specified along with \"i(caseless)\" modifier. "
699 "Since the hostname buffer we match against "
700 "is actually lowercase, having a "
701 "nocase is redundant.");
703 else if (DetectPcreHasUpperCase(re)) {
705 "specified has an uppercase char. "
706 "Since the hostname buffer we match against "
707 "is actually lowercase, please specify an "
708 "all lowercase based pcre.");
718 if (capture_names == NULL || strlen(capture_names) == 0)
719 opts |= PCRE2_NO_AUTO_CAPTURE;
722 if (DetectPcreHasUnicodeCluster(re)) {
723 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
731 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
733 opts &= ~PCRE2_NO_AUTO_CAPTURE;
735 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
738 PCRE2_UCHAR errbuffer[256];
739 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
740 SCLogError(
"pcre2 compile of \"%s\" failed at "
742 regexstr, (
int)eo2, errbuffer);
746 #ifdef PCRE2_HAVE_JIT
753 SCLogDebug(
"PCRE2 JIT compiler does not support: %s. "
754 "Falling back to regular PCRE2 handling (%s:%d)",
762 SCLogError(
"pcre2 could not create match context");
766 if (apply_match_limit) {
767 if (pcre_match_limit >= -1) {
770 if (pcre_match_limit_recursion >= -1) {
779 pcre2_match_data_free(match);
783 pcre2_match_data_free(match);
784 DetectPcreFree(
de_ctx, pd);
794 int ret = 0, res = 0;
795 char type_str[16] =
"";
796 const char *orig_right_edge = regexstr + strlen(regexstr);
802 pcre2_match_data *match = NULL;
804 SCLogDebug(
"regexstr %s, pd %p", regexstr, pd);
806 ret = pcre2_pattern_info(pd->
parse_regex.
regex, PCRE2_INFO_CAPTURECOUNT, &capture_cnt);
807 SCLogDebug(
"ret %d capture_cnt %d", ret, capture_cnt);
808 if (ret == 0 && capture_cnt && strlen(capture_names) > 0)
811 while ((name_array[name_idx] = strtok_r(name_idx == 0 ? capture_names : NULL,
" ,", &ptr))){
812 if (name_idx > (capture_cnt - 1)) {
814 "var capture names than capturing substrings");
817 SCLogDebug(
"name '%s'", name_array[name_idx]);
819 if (strcmp(name_array[name_idx],
"pkt:key") == 0) {
827 }
else if (key == 1 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
832 }
else if (key == 0 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
834 }
else if (key == 1) {
837 }
else if (strncmp(name_array[name_idx],
"flow:", 5) == 0) {
838 uint32_t varname_id =
846 }
else if (strncmp(name_array[name_idx],
"pkt:", 4) == 0) {
847 uint32_t varname_id =
856 }
else if (strncmp(name_array[name_idx],
"alert:", 6) == 0) {
857 uint32_t varname_id =
867 "var capture names must start with 'pkt:' or 'flow:'");
879 size_t cap_buffer_len = strlen(regexstr) + 1;
881 char capture_str[cap_buffer_len];
882 memset(capture_str, 0x00, cap_buffer_len);
892 pcre2_match_data_free(match);
895 copylen =
sizeof(type_str);
896 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)type_str, ©len);
898 SCLogError(
"pcre2_substring_copy_bynumber failed");
901 cap_buffer_len = strlen(regexstr) + 1;
902 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)capture_str, &cap_buffer_len);
904 SCLogError(
"pcre2_substring_copy_bynumber failed");
907 if (strlen(capture_str) == 0 || strlen(type_str) == 0) {
915 SCLogError(
"rule can have maximally %d pkt/flow "
918 pcre2_match_data_free(match);
922 if (strcmp(type_str,
"pkt") == 0) {
930 }
else if (strcmp(type_str,
"flow") == 0) {
937 }
else if (strcmp(type_str,
"alert") == 0) {
947 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
950 pcre2_match_data_free(match);
953 if (regexstr >= orig_right_edge)
959 pcre2_match_data_free(match);
963 static void *DetectPcreThreadInit(
void *data)
966 pcre2_match_data *match = pcre2_match_data_create_from_pattern(pd->
parse_regex.
regex, NULL);
970 static void DetectPcreThreadFree(
void *
ctx)
973 pcre2_match_data *match = (pcre2_match_data *)
ctx;
974 pcre2_match_data_free(match);
983 char capture_names[1024] =
"";
986 pd = DetectPcreParse(
de_ctx, regexstr, &parsed_sm_list,
991 if (DetectPcreParseCapture(regexstr,
de_ctx, pd, capture_names) < 0)
995 de_ctx,
"pcre", DetectPcreThreadInit, (
void *)pd, DetectPcreThreadFree, 0);
1002 SCLogError(
"Expression seen with a sticky buffer still set; either (1) reset sticky "
1003 "buffer with pkt_data or (2) use a sticky buffer providing \"%s\".",
1012 switch (parsed_sm_list) {
1026 sm_list = parsed_sm_list;
1039 for (uint8_t x = 0; x < pd->
idx; x++) {
1053 "preceding match in the same buffer");
1056 }
else if (prev_pm == NULL) {
1070 DetectPcreFree(
de_ctx, pd);
1084 for (uint8_t i = 0; i < pd->
idx; i++) {
1092 static int g_file_data_buffer_id = 0;
1093 static int g_http_header_buffer_id = 0;
1094 static int g_dce_stub_data_buffer_id = 0;
1099 static int DetectPcreParseTest01 (
void)
1102 const char *teststring =
"/blah/7";
1108 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1118 static int DetectPcreParseTest02 (
void)
1121 const char *teststring =
"/blah/Ui$";
1127 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1138 static int DetectPcreParseTest03 (
void)
1141 const char *teststring =
"/blah/UNi";
1147 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1157 static int DetectPcreParseTest04 (
void)
1160 const char *teststring =
"/b\\\"lah/i";
1166 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1170 DetectPcreFree(
de_ctx, pd);
1178 static int DetectPcreParseTest05 (
void)
1181 const char *teststring =
"/b(l|a)h/";
1187 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1191 DetectPcreFree(
de_ctx, pd);
1199 static int DetectPcreParseTest06 (
void)
1202 const char *teststring =
"/b(l|a)h/smi";
1208 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1212 DetectPcreFree(
de_ctx, pd);
1220 static int DetectPcreParseTest07 (
void)
1223 const char *teststring =
"/blah/Ui";
1229 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1233 DetectPcreFree(
de_ctx, pd);
1241 static int DetectPcreParseTest08 (
void)
1244 const char *teststring =
"/b(l|a)h/O";
1250 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1254 DetectPcreFree(
de_ctx, pd);
1263 static int DetectPcreParseTest09 (
void)
1266 const char *teststring =
"/lala\\\\/";
1272 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1275 DetectPcreFree(
de_ctx, pd);
1283 static int DetectPcreParseTest10(
void)
1313 static int DetectPcreParseTest15(
void)
1320 "alert tcp any any -> any any "
1321 "(msg:\"Testing pcre relative http_method\"; "
1323 "http_method; pcre:\"/abc/RM\"; sid:1;)");
1333 static int DetectPcreParseTest16(
void)
1340 "alert tcp any any -> any any "
1341 "(msg:\"Testing pcre relative http_cookie\"; "
1342 "content:\"test\"; "
1343 "http_cookie; pcre:\"/abc/RC\"; sid:1;)");
1352 static int DetectPcreParseTest17(
void)
1359 "alert tcp any any -> any any "
1360 "(msg:\"Testing pcre relative http_raw_header\"; "
1361 "flow:to_server; content:\"test\"; "
1362 "http_raw_header; pcre:\"/abc/RD\"; sid:1;)");
1371 static int DetectPcreParseTest18(
void)
1378 "alert tcp any any -> any any "
1379 "(msg:\"Testing pcre relative http_header\"; "
1380 "content:\"test\"; "
1381 "http_header; pcre:\"/abc/RH\"; sid:1;)");
1390 static int DetectPcreParseTest19(
void)
1397 "alert tcp any any -> any any "
1398 "(msg:\"Testing pcre relative http_client_body\"; "
1399 "content:\"test\"; "
1400 "http_client_body; pcre:\"/abc/RP\"; sid:1;)");
1409 static int DetectPcreParseTest20(
void)
1417 "alert tcp any any -> any any "
1418 "(msg:\"Testing http_raw_uri\"; "
1419 "content:\"test\"; "
1420 "http_raw_uri; pcre:\"/abc/RI\"; sid:1;)");
1429 static int DetectPcreParseTest21(
void)
1437 "alert tcp any any -> any any "
1438 "(msg:\"Testing pcre relative uricontent\"; "
1439 "uricontent:\"test\"; "
1440 "pcre:\"/abc/RU\"; sid:1;)");
1449 static int DetectPcreParseTest22(
void)
1457 "alert tcp any any -> any any "
1458 "(msg:\"Testing pcre relative http_uri\"; "
1459 "content:\"test\"; "
1460 "http_uri; pcre:\"/abc/RU\"; sid:1;)");
1469 static int DetectPcreParseTest23(
void)
1477 "alert tcp any any -> any any "
1478 "(msg:\"Testing inconsistent pcre relative\"; "
1480 "http_cookie; pcre:\"/abc/RM\"; sid:1;)");
1489 static int DetectPcreParseTest24(
void)
1497 "alert tcp any any -> any any "
1498 "(msg:\"Testing inconsistent pcre modifiers\"; "
1499 "pcre:\"/abc/UI\"; sid:1;)");
1508 static int DetectPcreParseTest25(
void)
1516 "alert tcp any any -> any any "
1517 "(msg:\"Testing inconsistent pcre modifiers\"; "
1518 "pcre:\"/abc/DH\"; sid:1;)");
1527 static int DetectPcreParseTest26(
void)
1535 "alert http any any -> any any "
1536 "(msg:\"Testing inconsistent pcre modifiers\"; "
1537 "pcre:\"/abc/F\"; sid:1;)");
1546 static int DetectPcreParseTest27(
void)
1554 "(content:\"baduricontent\"; http_raw_uri; "
1555 "pcre:\"/^[a-z]{5}\\.html/R\"; sid:2; rev:2;)");
1564 static int DetectPcreParseTest28(
void)
1572 "(content:\"|2E|suricata\"; http_host; pcre:\"/\\x2Esuricata$/W\"; "
1580 static int DetectPcreTestSig01(
void)
1582 uint8_t *buf = (uint8_t *)
"lalala lalala\\ lala\n";
1583 uint16_t buflen = strlen((
char *)buf);
1586 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; pcre:\"/ "
1587 "lalala\\\\/\"; sid:1;)";
1595 static int DetectPcreTestSig02(
void)
1597 uint8_t *buf = (uint8_t *)
"lalala\n";
1598 uint16_t buflen = strlen((
char *)buf);
1601 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1602 "pcre:\"/^(la)+$/\"; sid:1;)";
1610 static int DetectPcreTestSig03(
void)
1613 uint8_t *buf = (uint8_t *)
"lalala";
1614 uint16_t buflen = strlen((
char *)buf);
1617 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1618 "pcre:\"/^(la)+$/\"; sid:1;)";
1627 static int DetectPcreTxBodyChunksTest01(
void)
1632 uint8_t httpbuf1[] =
"GET / HTTP/1.1\r\n";
1633 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1634 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1635 uint8_t httpbuf4[] =
"Body one!!";
1636 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1637 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1638 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1639 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1640 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1641 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1642 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1643 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1644 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1645 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1648 memset(&
f, 0,
sizeof(
f));
1649 memset(&
ssn, 0,
sizeof(
ssn));
1725 static int DetectPcreTxBodyChunksTest02(
void)
1733 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1734 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1735 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1736 uint8_t httpbuf4[] =
"Body one!!";
1737 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1738 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1739 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1740 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1741 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1742 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1743 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1744 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1745 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1746 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1751 memset(&
f, 0,
sizeof(
f));
1752 memset(&
ssn, 0,
sizeof(
ssn));
1774 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;)");
1776 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;)");
1875 static int DetectPcreTxBodyChunksTest03(
void)
1883 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1884 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1885 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1886 uint8_t httpbuf4[] =
"Body one!!";
1887 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1888 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1889 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1890 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1891 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1892 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1893 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1894 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1895 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1896 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1901 memset(&
f, 0,
sizeof(
f));
1902 memset(&
ssn, 0,
sizeof(
ssn));
1924 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;)");
1926 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;)");
2010 static int DetectPcreParseHttpHost(
void)
2018 DetectPcreData *pd = DetectPcreParse(
de_ctx,
"/domain\\.com/W", &list, NULL, 0,
false, &alproto);
2020 DetectPcreFree(
de_ctx, pd);
2023 pd = DetectPcreParse(
de_ctx,
"/dOmain\\.com/W", &list, NULL, 0,
false, &alproto);
2028 pd = DetectPcreParse(
de_ctx,
"/domain\\D+\\.com/W", &list, NULL, 0,
false, &alproto);
2030 DetectPcreFree(
de_ctx, pd);
2035 pd = DetectPcreParse(
de_ctx,
"/\\\\Ddomain\\.com/W", &list, NULL, 0,
false, &alproto);
2045 static int DetectPcreParseCaptureTest(
void)
2051 "(content:\"Server: \"; http_header; pcre:\"/(.*)\\r\\n/HR, flow:somecapture\"; content:\"xyz\"; http_header; sid:1;)");
2054 "(content:\"Server: \"; http_header; pcre:\"/(flow:.*)\\r\\n/HR\"; content:\"xyz\"; http_header; sid:2;)");
2057 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)([0-9]+)\\r\\n/HR, flow:somecapture, pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2060 "alert http any any -> any any "
2061 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)\\r\\n/HR, flow:somecapture, "
2062 "pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2080 static void DetectPcreRegisterTests(
void)
2112 UtRegisterTest(
"DetectPcreTestSig02 -- anchored pcre", DetectPcreTestSig02);
2113 UtRegisterTest(
"DetectPcreTestSig03 -- anchored pcre", DetectPcreTestSig03);
2116 DetectPcreTxBodyChunksTest01);
2117 UtRegisterTest(
"DetectPcreTxBodyChunksTest02 -- modifier P, body chunks per tx",
2118 DetectPcreTxBodyChunksTest02);
2119 UtRegisterTest(
"DetectPcreTxBodyChunksTest03 -- modifier P, body chunks per tx",
2120 DetectPcreTxBodyChunksTest03);
2122 UtRegisterTest(
"DetectPcreParseHttpHost", DetectPcreParseHttpHost);
2123 UtRegisterTest(
"DetectPcreParseCaptureTest", DetectPcreParseCaptureTest);