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);
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) {
176 SCJsonBuilder *js = SCJbNewObject();
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++) {
278 const char *pcre2_str_ptr = NULL;
279 ret = pcre2_substring_get_bynumber(
280 match, x + 1, (PCRE2_UCHAR8 **)&pcre2_str_ptr, &capture_len);
282 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
286 capture_len = (capture_len < 0xffff) ? (uint16_t)capture_len : 0xffff;
287 uint8_t *str_ptr =
SCMalloc(capture_len);
289 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
292 memcpy(str_ptr, pcre2_str_ptr, capture_len);
293 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
300 const char *pcre2_str_ptr2 = NULL;
302 uint16_t key_len = (capture_len < 0xff) ? (uint16_t)capture_len : 0xff;
303 int ret2 = pcre2_substring_get_bynumber(
304 match, x + 2, (PCRE2_UCHAR8 **)&pcre2_str_ptr2, &capture_len);
308 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
311 capture_len = (capture_len < 0xffff) ? (uint16_t)capture_len : 0xffff;
312 uint8_t *str_ptr2 =
SCMalloc(capture_len);
315 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
318 memcpy(str_ptr2, pcre2_str_ptr2, capture_len);
319 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
322 (uint8_t *)str_ptr2, (uint16_t)capture_len,
334 (void)DetectAlertStoreMatch(det_ctx, s, pe->
capids[x], (uint8_t *)str_ptr,
335 (uint16_t)capture_len);
344 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
346 det_ctx->
buffer_offset = (uint32_t)((ptr + ov[1]) - payload);
359 static int DetectPcreSetList(
int list,
int set)
362 SCLogError(
"only one pcre option to specify a buffer type is allowed");
368 static int DetectPcreHasUpperCase(
const char *re)
370 size_t len = strlen(re);
371 bool is_meta =
false;
372 bool is_meta_hex =
false;
373 int meta_hex_cnt = 0;
375 for (
size_t i = 0; i <
len; i++) {
379 if (meta_hex_cnt == 2) {
383 }
else if (is_meta) {
390 else if (re[i] ==
'\\') {
393 else if (isupper((
unsigned char)re[i])) {
402 const char *regexstr,
int *sm_list,
char *capture_names,
403 size_t capture_names_size,
bool negate,
AppProto *alproto)
405 pcre2_match_data *match = NULL;
411 int ret = 0, res = 0;
412 int check_host_header = 0;
413 char op_str[64] =
"";
415 bool apply_match_limit =
false;
418 char *fcap = strstr(regexstr,
"flow:");
419 char *pcap = strstr(regexstr,
"pkt:");
420 char *acap = strstr(regexstr,
"alert:");
423 size_t slen = strlen(regexstr) + 1;
424 if (fcap || pcap || acap) {
431 cut_capture = (int)(fcap - regexstr);
435 cut_capture = (int)
MIN(cut_capture, (pcap - regexstr));
437 cut_capture = (int)(pcap - regexstr);
443 cut_capture =
MIN(cut_capture, (
int)(acap - regexstr));
445 cut_capture = (int)(acap - regexstr);
450 if (cut_capture > 1) {
451 int offset = cut_capture - 1;
454 if (regexstr[
offset] ==
',' || regexstr[
offset] ==
' ') {
461 if (cut_capture == (
offset + 1)) {
462 SCLogDebug(
"missing separators, assume it's part of the regex");
465 strlcpy(capture_names, regexstr+cut_capture, capture_names_size);
466 if (capture_names[strlen(capture_names)-1] ==
'"')
467 capture_names[strlen(capture_names)-1] =
'\0';
475 match = pcre2_match_data_create_from_pattern(parse_regex->
regex, NULL);
480 ret = pcre2_match(parse_regex->
regex, (PCRE2_SPTR8)regexstr, slen, 0, 0, match, NULL);
486 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)re, &slen);
488 SCLogError(
"pcre2_substring_copy_bynumber failed");
489 pcre2_match_data_free(match);
494 size_t copylen =
sizeof(op_str);
495 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)op_str, ©len);
497 SCLogError(
"pcre2_substring_copy_bynumber failed");
498 pcre2_match_data_free(match);
518 opts |= PCRE2_ANCHORED;
521 opts |= PCRE2_DOLLAR_ENDONLY;
524 opts |= PCRE2_UNGREEDY;
528 opts |= PCRE2_CASELESS;
532 opts |= PCRE2_MULTILINE;
535 opts |= PCRE2_DOTALL;
538 opts |= PCRE2_EXTENDED;
542 apply_match_limit =
true;
547 SCLogError(
"regex modifier 'B' inconsistent with chosen buffer");
560 SCLogError(
"regex modifier 'U' inconsistent with 'B'");
564 *sm_list = DetectPcreSetList(*sm_list, list);
570 SCLogError(
"regex modifier 'V' inconsistent with 'B'");
574 *sm_list = DetectPcreSetList(*sm_list, list);
580 SCLogError(
"regex modifier 'W' inconsistent with 'B'");
584 *sm_list = DetectPcreSetList(*sm_list, list);
586 check_host_header = 1;
591 SCLogError(
"regex modifier 'Z' inconsistent with 'B'");
595 *sm_list = DetectPcreSetList(*sm_list, list);
601 SCLogError(
"regex modifier 'H' inconsistent with 'B'");
605 *sm_list = DetectPcreSetList(*sm_list, list);
610 SCLogError(
"regex modifier 'I' inconsistent with 'B'");
614 *sm_list = DetectPcreSetList(*sm_list, list);
620 *sm_list = DetectPcreSetList(*sm_list, list);
626 SCLogError(
"regex modifier 'M' inconsistent with 'B'");
630 *sm_list = DetectPcreSetList(*sm_list, list);
636 SCLogError(
"regex modifier 'C' inconsistent with 'B'");
640 *sm_list = DetectPcreSetList(*sm_list, list);
647 *sm_list = DetectPcreSetList(*sm_list, list);
654 *sm_list = DetectPcreSetList(*sm_list, list);
661 *sm_list = DetectPcreSetList(*sm_list, list);
668 *sm_list = DetectPcreSetList(*sm_list, list);
673 SCLogError(
"unknown regex modifier '%c'", *op);
685 if (check_host_header) {
688 "specified along with \"i(caseless)\" modifier. "
689 "Since the hostname buffer we match against "
690 "is actually lowercase, having a "
691 "nocase is redundant.");
693 else if (DetectPcreHasUpperCase(re)) {
695 "specified has an uppercase char. "
696 "Since the hostname buffer we match against "
697 "is actually lowercase, please specify an "
698 "all lowercase based pcre.");
708 if (capture_names == NULL || strlen(capture_names) == 0)
709 opts |= PCRE2_NO_AUTO_CAPTURE;
712 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
714 opts &= ~PCRE2_NO_AUTO_CAPTURE;
716 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
719 PCRE2_UCHAR errbuffer[256];
720 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
721 SCLogError(
"pcre2 compile of \"%s\" failed at "
723 regexstr, (
int)eo2, errbuffer);
727 #ifdef PCRE2_HAVE_JIT
734 SCLogDebug(
"PCRE2 JIT compiler does not support: %s. "
735 "Falling back to regular PCRE2 handling (%s:%d)",
743 SCLogError(
"pcre2 could not create match context");
747 if (apply_match_limit) {
748 if (pcre_match_limit >= -1) {
751 if (pcre_match_limit_recursion >= -1) {
760 pcre2_match_data_free(match);
764 pcre2_match_data_free(match);
765 DetectPcreFree(
de_ctx, pd);
775 int ret = 0, res = 0;
776 char type_str[16] =
"";
777 const char *orig_right_edge = regexstr + strlen(regexstr);
783 pcre2_match_data *match = NULL;
785 SCLogDebug(
"regexstr %s, pd %p", regexstr, pd);
787 ret = pcre2_pattern_info(pd->
parse_regex.
regex, PCRE2_INFO_CAPTURECOUNT, &capture_cnt);
788 SCLogDebug(
"ret %d capture_cnt %d", ret, capture_cnt);
789 if (ret == 0 && capture_cnt && strlen(capture_names) > 0)
792 while ((name_array[name_idx] = strtok_r(name_idx == 0 ? capture_names : NULL,
" ,", &ptr))){
793 if (name_idx > (capture_cnt - 1)) {
795 "var capture names than capturing substrings");
798 SCLogDebug(
"name '%s'", name_array[name_idx]);
800 if (strcmp(name_array[name_idx],
"pkt:key") == 0) {
808 }
else if (key == 1 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
813 }
else if (key == 0 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
815 }
else if (key == 1) {
818 }
else if (strncmp(name_array[name_idx],
"flow:", 5) == 0) {
819 uint32_t varname_id =
827 }
else if (strncmp(name_array[name_idx],
"pkt:", 4) == 0) {
828 uint32_t varname_id =
837 }
else if (strncmp(name_array[name_idx],
"alert:", 6) == 0) {
838 uint32_t varname_id =
848 "var capture names must start with 'pkt:' or 'flow:'");
860 size_t cap_buffer_len = strlen(regexstr) + 1;
862 char capture_str[cap_buffer_len];
863 memset(capture_str, 0x00, cap_buffer_len);
873 pcre2_match_data_free(match);
876 copylen =
sizeof(type_str);
877 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)type_str, ©len);
879 SCLogError(
"pcre2_substring_copy_bynumber failed");
882 cap_buffer_len = strlen(regexstr) + 1;
883 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)capture_str, &cap_buffer_len);
885 SCLogError(
"pcre2_substring_copy_bynumber failed");
888 if (strlen(capture_str) == 0 || strlen(type_str) == 0) {
896 SCLogError(
"rule can have maximally %d pkt/flow "
899 pcre2_match_data_free(match);
903 if (strcmp(type_str,
"pkt") == 0) {
911 }
else if (strcmp(type_str,
"flow") == 0) {
918 }
else if (strcmp(type_str,
"alert") == 0) {
928 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
931 pcre2_match_data_free(match);
934 if (regexstr >= orig_right_edge)
940 pcre2_match_data_free(match);
944 static void *DetectPcreThreadInit(
void *data)
947 pcre2_match_data *match = pcre2_match_data_create_from_pattern(pd->
parse_regex.
regex, NULL);
951 static void DetectPcreThreadFree(
void *
ctx)
954 pcre2_match_data *match = (pcre2_match_data *)
ctx;
955 pcre2_match_data_free(match);
964 char capture_names[1024] =
"";
967 pd = DetectPcreParse(
de_ctx, regexstr, &parsed_sm_list,
972 if (DetectPcreParseCapture(regexstr,
de_ctx, pd, capture_names) < 0)
976 de_ctx,
"pcre", DetectPcreThreadInit, (
void *)pd, DetectPcreThreadFree, 0);
983 SCLogError(
"Expression seen with a sticky buffer still set; either (1) reset sticky "
984 "buffer with pkt_data or (2) use a sticky buffer providing \"%s\".",
993 switch (parsed_sm_list) {
1007 sm_list = parsed_sm_list;
1020 for (uint8_t x = 0; x < pd->
idx; x++) {
1034 "preceding match in the same buffer");
1037 }
else if (prev_pm == NULL) {
1051 DetectPcreFree(
de_ctx, pd);
1065 for (uint8_t i = 0; i < pd->
idx; i++) {
1073 static int g_file_data_buffer_id = 0;
1074 static int g_http_header_buffer_id = 0;
1075 static int g_dce_stub_data_buffer_id = 0;
1080 static int DetectPcreParseTest01 (
void)
1083 const char *teststring =
"/blah/7";
1089 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1099 static int DetectPcreParseTest02 (
void)
1102 const char *teststring =
"/blah/Ui$";
1108 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1119 static int DetectPcreParseTest03 (
void)
1122 const char *teststring =
"/blah/UNi";
1128 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1138 static int DetectPcreParseTest04 (
void)
1141 const char *teststring =
"/b\\\"lah/i";
1147 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1151 DetectPcreFree(
de_ctx, pd);
1159 static int DetectPcreParseTest05 (
void)
1162 const char *teststring =
"/b(l|a)h/";
1168 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1172 DetectPcreFree(
de_ctx, pd);
1180 static int DetectPcreParseTest06 (
void)
1183 const char *teststring =
"/b(l|a)h/smi";
1189 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1193 DetectPcreFree(
de_ctx, pd);
1201 static int DetectPcreParseTest07 (
void)
1204 const char *teststring =
"/blah/Ui";
1210 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1214 DetectPcreFree(
de_ctx, pd);
1222 static int DetectPcreParseTest08 (
void)
1225 const char *teststring =
"/b(l|a)h/O";
1231 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1235 DetectPcreFree(
de_ctx, pd);
1244 static int DetectPcreParseTest09 (
void)
1247 const char *teststring =
"/lala\\\\/";
1253 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1256 DetectPcreFree(
de_ctx, pd);
1264 static int DetectPcreParseTest10(
void)
1294 static int DetectPcreParseTest15(
void)
1301 "alert tcp any any -> any any "
1302 "(msg:\"Testing pcre relative http_method\"; "
1304 "http_method; pcre:\"/abc/RM\"; sid:1;)");
1314 static int DetectPcreParseTest16(
void)
1321 "alert tcp any any -> any any "
1322 "(msg:\"Testing pcre relative http_cookie\"; "
1323 "content:\"test\"; "
1324 "http_cookie; pcre:\"/abc/RC\"; sid:1;)");
1333 static int DetectPcreParseTest17(
void)
1340 "alert tcp any any -> any any "
1341 "(msg:\"Testing pcre relative http_raw_header\"; "
1342 "flow:to_server; content:\"test\"; "
1343 "http_raw_header; pcre:\"/abc/RD\"; sid:1;)");
1352 static int DetectPcreParseTest18(
void)
1359 "alert tcp any any -> any any "
1360 "(msg:\"Testing pcre relative http_header\"; "
1361 "content:\"test\"; "
1362 "http_header; pcre:\"/abc/RH\"; sid:1;)");
1371 static int DetectPcreParseTest19(
void)
1378 "alert tcp any any -> any any "
1379 "(msg:\"Testing pcre relative http_client_body\"; "
1380 "content:\"test\"; "
1381 "http_client_body; pcre:\"/abc/RP\"; sid:1;)");
1390 static int DetectPcreParseTest20(
void)
1398 "alert tcp any any -> any any "
1399 "(msg:\"Testing http_raw_uri\"; "
1400 "content:\"test\"; "
1401 "http_raw_uri; pcre:\"/abc/RI\"; sid:1;)");
1410 static int DetectPcreParseTest21(
void)
1418 "alert tcp any any -> any any "
1419 "(msg:\"Testing pcre relative uricontent\"; "
1420 "uricontent:\"test\"; "
1421 "pcre:\"/abc/RU\"; sid:1;)");
1430 static int DetectPcreParseTest22(
void)
1438 "alert tcp any any -> any any "
1439 "(msg:\"Testing pcre relative http_uri\"; "
1440 "content:\"test\"; "
1441 "http_uri; pcre:\"/abc/RU\"; sid:1;)");
1450 static int DetectPcreParseTest23(
void)
1458 "alert tcp any any -> any any "
1459 "(msg:\"Testing inconsistent pcre relative\"; "
1461 "http_cookie; pcre:\"/abc/RM\"; sid:1;)");
1470 static int DetectPcreParseTest24(
void)
1478 "alert tcp any any -> any any "
1479 "(msg:\"Testing inconsistent pcre modifiers\"; "
1480 "pcre:\"/abc/UI\"; sid:1;)");
1489 static int DetectPcreParseTest25(
void)
1497 "alert tcp any any -> any any "
1498 "(msg:\"Testing inconsistent pcre modifiers\"; "
1499 "pcre:\"/abc/DH\"; sid:1;)");
1508 static int DetectPcreParseTest26(
void)
1516 "alert http any any -> any any "
1517 "(msg:\"Testing inconsistent pcre modifiers\"; "
1518 "pcre:\"/abc/F\"; sid:1;)");
1527 static int DetectPcreParseTest27(
void)
1535 "(content:\"baduricontent\"; http_raw_uri; "
1536 "pcre:\"/^[a-z]{5}\\.html/R\"; sid:2; rev:2;)");
1545 static int DetectPcreParseTest28(
void)
1553 "(content:\"|2E|suricata\"; http_host; pcre:\"/\\x2Esuricata$/W\"; "
1561 static int DetectPcreTestSig01(
void)
1563 uint8_t *buf = (uint8_t *)
"lalala lalala\\ lala\n";
1564 uint16_t buflen = strlen((
char *)buf);
1567 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; pcre:\"/ "
1568 "lalala\\\\/\"; sid:1;)";
1576 static int DetectPcreTestSig02(
void)
1578 uint8_t *buf = (uint8_t *)
"lalala\n";
1579 uint16_t buflen = strlen((
char *)buf);
1582 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1583 "pcre:\"/^(la)+$/\"; sid:1;)";
1591 static int DetectPcreTestSig03(
void)
1594 uint8_t *buf = (uint8_t *)
"lalala";
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;)";
1608 static int DetectPcreTxBodyChunksTest01(
void)
1613 uint8_t httpbuf1[] =
"GET / HTTP/1.1\r\n";
1614 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1615 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1616 uint8_t httpbuf4[] =
"Body one!!";
1617 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1618 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1619 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1620 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1621 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1622 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1623 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1624 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1625 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1626 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1629 memset(&f, 0,
sizeof(f));
1630 memset(&ssn, 0,
sizeof(ssn));
1636 f.
proto = IPPROTO_TCP;
1706 static int DetectPcreTxBodyChunksTest02(
void)
1714 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1715 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1716 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1717 uint8_t httpbuf4[] =
"Body one!!";
1718 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1719 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1720 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1721 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1722 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1723 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1724 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1725 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1726 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1727 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1730 memset(&th_v, 0,
sizeof(th_v));
1732 memset(&f, 0,
sizeof(f));
1733 memset(&ssn, 0,
sizeof(ssn));
1739 f.
proto = IPPROTO_TCP;
1755 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;)");
1757 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;)");
1856 static int DetectPcreTxBodyChunksTest03(
void)
1864 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1865 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1866 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1867 uint8_t httpbuf4[] =
"Body one!!";
1868 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1869 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1870 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1871 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1872 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1873 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1874 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1875 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1876 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1877 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1880 memset(&th_v, 0,
sizeof(th_v));
1882 memset(&f, 0,
sizeof(f));
1883 memset(&ssn, 0,
sizeof(ssn));
1889 f.
proto = IPPROTO_TCP;
1905 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;)");
1907 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;)");
1991 static int DetectPcreParseHttpHost(
void)
1999 DetectPcreData *pd = DetectPcreParse(
de_ctx,
"/domain\\.com/W", &list, NULL, 0,
false, &alproto);
2001 DetectPcreFree(
de_ctx, pd);
2004 pd = DetectPcreParse(
de_ctx,
"/dOmain\\.com/W", &list, NULL, 0,
false, &alproto);
2009 pd = DetectPcreParse(
de_ctx,
"/domain\\D+\\.com/W", &list, NULL, 0,
false, &alproto);
2011 DetectPcreFree(
de_ctx, pd);
2016 pd = DetectPcreParse(
de_ctx,
"/\\\\Ddomain\\.com/W", &list, NULL, 0,
false, &alproto);
2026 static int DetectPcreParseCaptureTest(
void)
2032 "(content:\"Server: \"; http_header; pcre:\"/(.*)\\r\\n/HR, flow:somecapture\"; content:\"xyz\"; http_header; sid:1;)");
2035 "(content:\"Server: \"; http_header; pcre:\"/(flow:.*)\\r\\n/HR\"; content:\"xyz\"; http_header; sid:2;)");
2038 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)([0-9]+)\\r\\n/HR, flow:somecapture, pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2041 "alert http any any -> any any "
2042 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)\\r\\n/HR, flow:somecapture, "
2043 "pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2061 static void DetectPcreRegisterTests(
void)
2093 UtRegisterTest(
"DetectPcreTestSig02 -- anchored pcre", DetectPcreTestSig02);
2094 UtRegisterTest(
"DetectPcreTestSig03 -- anchored pcre", DetectPcreTestSig03);
2097 DetectPcreTxBodyChunksTest01);
2098 UtRegisterTest(
"DetectPcreTxBodyChunksTest02 -- modifier P, body chunks per tx",
2099 DetectPcreTxBodyChunksTest02);
2100 UtRegisterTest(
"DetectPcreTxBodyChunksTest03 -- modifier P, body chunks per tx",
2101 DetectPcreTxBodyChunksTest03);
2103 UtRegisterTest(
"DetectPcreParseHttpHost", DetectPcreParseHttpHost);
2104 UtRegisterTest(
"DetectPcreParseCaptureTest", DetectPcreParseCaptureTest);