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 char *fcap = strstr(regexstr,
"flow:");
420 char *pcap = strstr(regexstr,
"pkt:");
421 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;
713 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
715 opts &= ~PCRE2_NO_AUTO_CAPTURE;
717 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
720 PCRE2_UCHAR errbuffer[256];
721 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
722 SCLogError(
"pcre2 compile of \"%s\" failed at "
724 regexstr, (
int)eo2, errbuffer);
728 #ifdef PCRE2_HAVE_JIT
735 SCLogDebug(
"PCRE2 JIT compiler does not support: %s. "
736 "Falling back to regular PCRE2 handling (%s:%d)",
744 SCLogError(
"pcre2 could not create match context");
748 if (apply_match_limit) {
749 if (pcre_match_limit >= -1) {
752 if (pcre_match_limit_recursion >= -1) {
761 pcre2_match_data_free(match);
765 pcre2_match_data_free(match);
766 DetectPcreFree(
de_ctx, pd);
776 int ret = 0, res = 0;
777 char type_str[16] =
"";
778 const char *orig_right_edge = regexstr + strlen(regexstr);
784 pcre2_match_data *match = NULL;
786 SCLogDebug(
"regexstr %s, pd %p", regexstr, pd);
788 ret = pcre2_pattern_info(pd->
parse_regex.
regex, PCRE2_INFO_CAPTURECOUNT, &capture_cnt);
789 SCLogDebug(
"ret %d capture_cnt %d", ret, capture_cnt);
790 if (ret == 0 && capture_cnt && strlen(capture_names) > 0)
793 while ((name_array[name_idx] = strtok_r(name_idx == 0 ? capture_names : NULL,
" ,", &ptr))){
794 if (name_idx > (capture_cnt - 1)) {
796 "var capture names than capturing substrings");
799 SCLogDebug(
"name '%s'", name_array[name_idx]);
801 if (strcmp(name_array[name_idx],
"pkt:key") == 0) {
809 }
else if (key == 1 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
814 }
else if (key == 0 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
816 }
else if (key == 1) {
819 }
else if (strncmp(name_array[name_idx],
"flow:", 5) == 0) {
820 uint32_t varname_id =
828 }
else if (strncmp(name_array[name_idx],
"pkt:", 4) == 0) {
829 uint32_t varname_id =
838 }
else if (strncmp(name_array[name_idx],
"alert:", 6) == 0) {
839 uint32_t varname_id =
849 "var capture names must start with 'pkt:' or 'flow:'");
861 size_t cap_buffer_len = strlen(regexstr) + 1;
863 char capture_str[cap_buffer_len];
864 memset(capture_str, 0x00, cap_buffer_len);
874 pcre2_match_data_free(match);
877 copylen =
sizeof(type_str);
878 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)type_str, ©len);
880 SCLogError(
"pcre2_substring_copy_bynumber failed");
883 cap_buffer_len = strlen(regexstr) + 1;
884 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)capture_str, &cap_buffer_len);
886 SCLogError(
"pcre2_substring_copy_bynumber failed");
889 if (strlen(capture_str) == 0 || strlen(type_str) == 0) {
897 SCLogError(
"rule can have maximally %d pkt/flow "
900 pcre2_match_data_free(match);
904 if (strcmp(type_str,
"pkt") == 0) {
912 }
else if (strcmp(type_str,
"flow") == 0) {
919 }
else if (strcmp(type_str,
"alert") == 0) {
929 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
932 pcre2_match_data_free(match);
935 if (regexstr >= orig_right_edge)
941 pcre2_match_data_free(match);
945 static void *DetectPcreThreadInit(
void *data)
948 pcre2_match_data *match = pcre2_match_data_create_from_pattern(pd->
parse_regex.
regex, NULL);
952 static void DetectPcreThreadFree(
void *
ctx)
955 pcre2_match_data *match = (pcre2_match_data *)
ctx;
956 pcre2_match_data_free(match);
965 char capture_names[1024] =
"";
968 pd = DetectPcreParse(
de_ctx, regexstr, &parsed_sm_list,
973 if (DetectPcreParseCapture(regexstr,
de_ctx, pd, capture_names) < 0)
977 de_ctx,
"pcre", DetectPcreThreadInit, (
void *)pd, DetectPcreThreadFree, 0);
984 SCLogError(
"Expression seen with a sticky buffer still set; either (1) reset sticky "
985 "buffer with pkt_data or (2) use a sticky buffer providing \"%s\".",
994 switch (parsed_sm_list) {
1008 sm_list = parsed_sm_list;
1021 for (uint8_t x = 0; x < pd->
idx; x++) {
1035 "preceding match in the same buffer");
1038 }
else if (prev_pm == NULL) {
1052 DetectPcreFree(
de_ctx, pd);
1066 for (uint8_t i = 0; i < pd->
idx; i++) {
1074 static int g_file_data_buffer_id = 0;
1075 static int g_http_header_buffer_id = 0;
1076 static int g_dce_stub_data_buffer_id = 0;
1081 static int DetectPcreParseTest01 (
void)
1084 const char *teststring =
"/blah/7";
1090 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1100 static int DetectPcreParseTest02 (
void)
1103 const char *teststring =
"/blah/Ui$";
1109 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1120 static int DetectPcreParseTest03 (
void)
1123 const char *teststring =
"/blah/UNi";
1129 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1139 static int DetectPcreParseTest04 (
void)
1142 const char *teststring =
"/b\\\"lah/i";
1148 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1152 DetectPcreFree(
de_ctx, pd);
1160 static int DetectPcreParseTest05 (
void)
1163 const char *teststring =
"/b(l|a)h/";
1169 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1173 DetectPcreFree(
de_ctx, pd);
1181 static int DetectPcreParseTest06 (
void)
1184 const char *teststring =
"/b(l|a)h/smi";
1190 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1194 DetectPcreFree(
de_ctx, pd);
1202 static int DetectPcreParseTest07 (
void)
1205 const char *teststring =
"/blah/Ui";
1211 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1215 DetectPcreFree(
de_ctx, pd);
1223 static int DetectPcreParseTest08 (
void)
1226 const char *teststring =
"/b(l|a)h/O";
1232 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1236 DetectPcreFree(
de_ctx, pd);
1245 static int DetectPcreParseTest09 (
void)
1248 const char *teststring =
"/lala\\\\/";
1254 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1257 DetectPcreFree(
de_ctx, pd);
1265 static int DetectPcreParseTest10(
void)
1295 static int DetectPcreParseTest15(
void)
1302 "alert tcp any any -> any any "
1303 "(msg:\"Testing pcre relative http_method\"; "
1305 "http_method; pcre:\"/abc/RM\"; sid:1;)");
1315 static int DetectPcreParseTest16(
void)
1322 "alert tcp any any -> any any "
1323 "(msg:\"Testing pcre relative http_cookie\"; "
1324 "content:\"test\"; "
1325 "http_cookie; pcre:\"/abc/RC\"; sid:1;)");
1334 static int DetectPcreParseTest17(
void)
1341 "alert tcp any any -> any any "
1342 "(msg:\"Testing pcre relative http_raw_header\"; "
1343 "flow:to_server; content:\"test\"; "
1344 "http_raw_header; pcre:\"/abc/RD\"; sid:1;)");
1353 static int DetectPcreParseTest18(
void)
1360 "alert tcp any any -> any any "
1361 "(msg:\"Testing pcre relative http_header\"; "
1362 "content:\"test\"; "
1363 "http_header; pcre:\"/abc/RH\"; sid:1;)");
1372 static int DetectPcreParseTest19(
void)
1379 "alert tcp any any -> any any "
1380 "(msg:\"Testing pcre relative http_client_body\"; "
1381 "content:\"test\"; "
1382 "http_client_body; pcre:\"/abc/RP\"; sid:1;)");
1391 static int DetectPcreParseTest20(
void)
1399 "alert tcp any any -> any any "
1400 "(msg:\"Testing http_raw_uri\"; "
1401 "content:\"test\"; "
1402 "http_raw_uri; pcre:\"/abc/RI\"; sid:1;)");
1411 static int DetectPcreParseTest21(
void)
1419 "alert tcp any any -> any any "
1420 "(msg:\"Testing pcre relative uricontent\"; "
1421 "uricontent:\"test\"; "
1422 "pcre:\"/abc/RU\"; sid:1;)");
1431 static int DetectPcreParseTest22(
void)
1439 "alert tcp any any -> any any "
1440 "(msg:\"Testing pcre relative http_uri\"; "
1441 "content:\"test\"; "
1442 "http_uri; pcre:\"/abc/RU\"; sid:1;)");
1451 static int DetectPcreParseTest23(
void)
1459 "alert tcp any any -> any any "
1460 "(msg:\"Testing inconsistent pcre relative\"; "
1462 "http_cookie; pcre:\"/abc/RM\"; sid:1;)");
1471 static int DetectPcreParseTest24(
void)
1479 "alert tcp any any -> any any "
1480 "(msg:\"Testing inconsistent pcre modifiers\"; "
1481 "pcre:\"/abc/UI\"; sid:1;)");
1490 static int DetectPcreParseTest25(
void)
1498 "alert tcp any any -> any any "
1499 "(msg:\"Testing inconsistent pcre modifiers\"; "
1500 "pcre:\"/abc/DH\"; sid:1;)");
1509 static int DetectPcreParseTest26(
void)
1517 "alert http any any -> any any "
1518 "(msg:\"Testing inconsistent pcre modifiers\"; "
1519 "pcre:\"/abc/F\"; sid:1;)");
1528 static int DetectPcreParseTest27(
void)
1536 "(content:\"baduricontent\"; http_raw_uri; "
1537 "pcre:\"/^[a-z]{5}\\.html/R\"; sid:2; rev:2;)");
1546 static int DetectPcreParseTest28(
void)
1554 "(content:\"|2E|suricata\"; http_host; pcre:\"/\\x2Esuricata$/W\"; "
1562 static int DetectPcreTestSig01(
void)
1564 uint8_t *buf = (uint8_t *)
"lalala lalala\\ lala\n";
1565 uint16_t buflen = strlen((
char *)buf);
1568 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; pcre:\"/ "
1569 "lalala\\\\/\"; sid:1;)";
1577 static int DetectPcreTestSig02(
void)
1579 uint8_t *buf = (uint8_t *)
"lalala\n";
1580 uint16_t buflen = strlen((
char *)buf);
1583 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1584 "pcre:\"/^(la)+$/\"; sid:1;)";
1592 static int DetectPcreTestSig03(
void)
1595 uint8_t *buf = (uint8_t *)
"lalala";
1596 uint16_t buflen = strlen((
char *)buf);
1599 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1600 "pcre:\"/^(la)+$/\"; sid:1;)";
1609 static int DetectPcreTxBodyChunksTest01(
void)
1614 uint8_t httpbuf1[] =
"GET / HTTP/1.1\r\n";
1615 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1616 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1617 uint8_t httpbuf4[] =
"Body one!!";
1618 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1619 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1620 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1621 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1622 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1623 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1624 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1625 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1626 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1627 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1630 memset(&f, 0,
sizeof(f));
1631 memset(&ssn, 0,
sizeof(ssn));
1637 f.
proto = IPPROTO_TCP;
1707 static int DetectPcreTxBodyChunksTest02(
void)
1715 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1716 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1717 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1718 uint8_t httpbuf4[] =
"Body one!!";
1719 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1720 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1721 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1722 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1723 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1724 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1725 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1726 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1727 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1728 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1731 memset(&th_v, 0,
sizeof(th_v));
1733 memset(&f, 0,
sizeof(f));
1734 memset(&ssn, 0,
sizeof(ssn));
1740 f.
proto = IPPROTO_TCP;
1756 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;)");
1758 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;)");
1857 static int DetectPcreTxBodyChunksTest03(
void)
1865 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1866 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1867 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1868 uint8_t httpbuf4[] =
"Body one!!";
1869 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1870 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1871 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1872 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1873 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1874 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1875 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1876 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1877 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1878 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1881 memset(&th_v, 0,
sizeof(th_v));
1883 memset(&f, 0,
sizeof(f));
1884 memset(&ssn, 0,
sizeof(ssn));
1890 f.
proto = IPPROTO_TCP;
1906 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;)");
1908 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;)");
1992 static int DetectPcreParseHttpHost(
void)
2000 DetectPcreData *pd = DetectPcreParse(
de_ctx,
"/domain\\.com/W", &list, NULL, 0,
false, &alproto);
2002 DetectPcreFree(
de_ctx, pd);
2005 pd = DetectPcreParse(
de_ctx,
"/dOmain\\.com/W", &list, NULL, 0,
false, &alproto);
2010 pd = DetectPcreParse(
de_ctx,
"/domain\\D+\\.com/W", &list, NULL, 0,
false, &alproto);
2012 DetectPcreFree(
de_ctx, pd);
2017 pd = DetectPcreParse(
de_ctx,
"/\\\\Ddomain\\.com/W", &list, NULL, 0,
false, &alproto);
2027 static int DetectPcreParseCaptureTest(
void)
2033 "(content:\"Server: \"; http_header; pcre:\"/(.*)\\r\\n/HR, flow:somecapture\"; content:\"xyz\"; http_header; sid:1;)");
2036 "(content:\"Server: \"; http_header; pcre:\"/(flow:.*)\\r\\n/HR\"; content:\"xyz\"; http_header; sid:2;)");
2039 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)([0-9]+)\\r\\n/HR, flow:somecapture, pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2042 "alert http any any -> any any "
2043 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)\\r\\n/HR, flow:somecapture, "
2044 "pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2062 static void DetectPcreRegisterTests(
void)
2094 UtRegisterTest(
"DetectPcreTestSig02 -- anchored pcre", DetectPcreTestSig02);
2095 UtRegisterTest(
"DetectPcreTestSig03 -- anchored pcre", DetectPcreTestSig03);
2098 DetectPcreTxBodyChunksTest01);
2099 UtRegisterTest(
"DetectPcreTxBodyChunksTest02 -- modifier P, body chunks per tx",
2100 DetectPcreTxBodyChunksTest02);
2101 UtRegisterTest(
"DetectPcreTxBodyChunksTest03 -- modifier P, body chunks per tx",
2102 DetectPcreTxBodyChunksTest03);
2104 UtRegisterTest(
"DetectPcreParseHttpHost", DetectPcreParseHttpHost);
2105 UtRegisterTest(
"DetectPcreParseCaptureTest", DetectPcreParseCaptureTest);