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);
113 SCLogDebug(
"Using PCRE match-limit setting of: %i", pcre_match_limit);
116 pcre_match_limit = 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 (!
ConfGetInt(
"pcre.match-limit-recursion", &val)) {
128 SCLogDebug(
"Using PCRE match-limit-recursion setting of: %i", pcre_match_limit_recursion);
131 pcre_match_limit_recursion = 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");
179 const uint8_t *ptr = NULL;
181 PCRE2_SIZE capture_len = 0;
193 int start_offset = 0;
199 pcre2_match_data *match =
202 ret = DetectPcreExec(det_ctx, pe, (
char *)ptr,
len, start_offset, 0, match);
205 if (ret == PCRE2_ERROR_NOMATCH) {
213 }
else if (ret >= 0) {
225 if (ret > 1 && pe->
idx != 0) {
227 for (x = 0; x < pe->
idx; x++) {
229 const char *pcre2_str_ptr = NULL;
230 ret = pcre2_substring_get_bynumber(
231 match, x + 1, (PCRE2_UCHAR8 **)&pcre2_str_ptr, &capture_len);
233 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
237 capture_len = (capture_len < 0xffff) ? (uint16_t)capture_len : 0xffff;
238 uint8_t *str_ptr =
SCMalloc(capture_len);
240 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
243 memcpy(str_ptr, pcre2_str_ptr, capture_len);
244 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr);
251 const char *pcre2_str_ptr2 = NULL;
253 uint16_t key_len = (capture_len < 0xff) ? (uint16_t)capture_len : 0xff;
254 int ret2 = pcre2_substring_get_bynumber(
255 match, x + 2, (PCRE2_UCHAR8 **)&pcre2_str_ptr2, &capture_len);
259 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
262 capture_len = (capture_len < 0xffff) ? (uint16_t)capture_len : 0xffff;
263 uint8_t *str_ptr2 =
SCMalloc(capture_len);
266 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
269 memcpy(str_ptr2, pcre2_str_ptr2, capture_len);
270 pcre2_substring_free((PCRE2_UCHAR8 *)pcre2_str_ptr2);
273 (uint8_t *)str_ptr2, (uint16_t)capture_len,
290 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
305 static int DetectPcreSetList(
int list,
int set)
308 SCLogError(
"only one pcre option to specify a buffer type is allowed");
314 static int DetectPcreHasUpperCase(
const char *re)
316 size_t len = strlen(re);
317 bool is_meta =
false;
318 bool is_meta_hex =
false;
319 int meta_hex_cnt = 0;
321 for (
size_t i = 0; i <
len; i++) {
325 if (meta_hex_cnt == 2) {
329 }
else if (is_meta) {
336 else if (re[i] ==
'\\') {
339 else if (isupper((
unsigned char)re[i])) {
348 const char *regexstr,
int *sm_list,
char *capture_names,
349 size_t capture_names_size,
bool negate,
AppProto *alproto)
351 pcre2_match_data *match = NULL;
357 int ret = 0, res = 0;
358 int check_host_header = 0;
359 char op_str[64] =
"";
361 bool apply_match_limit =
false;
364 char *fcap = strstr(regexstr,
"flow:");
365 char *pcap = strstr(regexstr,
"pkt:");
368 size_t slen = strlen(regexstr) + 1;
373 cut_capture = fcap - regexstr;
374 else if (pcap && !fcap)
375 cut_capture = pcap - regexstr;
379 cut_capture =
MIN((pcap - regexstr), (fcap - regexstr));
384 if (cut_capture > 1) {
385 int offset = cut_capture - 1;
388 if (regexstr[
offset] ==
',' || regexstr[
offset] ==
' ') {
395 if (cut_capture == (
offset + 1)) {
396 SCLogDebug(
"missing separators, assume it's part of the regex");
399 strlcpy(capture_names, regexstr+cut_capture, capture_names_size);
400 if (capture_names[strlen(capture_names)-1] ==
'"')
401 capture_names[strlen(capture_names)-1] =
'\0';
408 match = pcre2_match_data_create_from_pattern(parse_regex->
regex, NULL);
413 ret = pcre2_match(parse_regex->
regex, (PCRE2_SPTR8)regexstr, slen, 0, 0, match, NULL);
419 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)re, &slen);
421 SCLogError(
"pcre2_substring_copy_bynumber failed");
422 pcre2_match_data_free(match);
427 size_t copylen =
sizeof(op_str);
428 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)op_str, ©len);
430 SCLogError(
"pcre2_substring_copy_bynumber failed");
431 pcre2_match_data_free(match);
451 opts |= PCRE2_ANCHORED;
454 opts |= PCRE2_DOLLAR_ENDONLY;
457 opts |= PCRE2_UNGREEDY;
461 opts |= PCRE2_CASELESS;
465 opts |= PCRE2_MULTILINE;
468 opts |= PCRE2_DOTALL;
471 opts |= PCRE2_EXTENDED;
475 apply_match_limit =
true;
480 SCLogError(
"regex modifier 'B' inconsistent with chosen buffer");
493 SCLogError(
"regex modifier 'U' inconsistent with 'B'");
497 *sm_list = DetectPcreSetList(*sm_list, list);
503 SCLogError(
"regex modifier 'V' inconsistent with 'B'");
507 *sm_list = DetectPcreSetList(*sm_list, list);
513 SCLogError(
"regex modifier 'W' inconsistent with 'B'");
517 *sm_list = DetectPcreSetList(*sm_list, list);
519 check_host_header = 1;
524 SCLogError(
"regex modifier 'Z' inconsistent with 'B'");
528 *sm_list = DetectPcreSetList(*sm_list, list);
534 SCLogError(
"regex modifier 'H' inconsistent with 'B'");
538 *sm_list = DetectPcreSetList(*sm_list, list);
543 SCLogError(
"regex modifier 'I' inconsistent with 'B'");
547 *sm_list = DetectPcreSetList(*sm_list, list);
553 *sm_list = DetectPcreSetList(*sm_list, list);
559 SCLogError(
"regex modifier 'M' inconsistent with 'B'");
563 *sm_list = DetectPcreSetList(*sm_list, list);
569 SCLogError(
"regex modifier 'C' inconsistent with 'B'");
573 *sm_list = DetectPcreSetList(*sm_list, list);
580 *sm_list = DetectPcreSetList(*sm_list, list);
587 *sm_list = DetectPcreSetList(*sm_list, list);
594 *sm_list = DetectPcreSetList(*sm_list, list);
601 *sm_list = DetectPcreSetList(*sm_list, list);
606 SCLogError(
"unknown regex modifier '%c'", *op);
618 if (check_host_header) {
621 "specified along with \"i(caseless)\" modifier. "
622 "Since the hostname buffer we match against "
623 "is actually lowercase, having a "
624 "nocase is redundant.");
626 else if (DetectPcreHasUpperCase(re)) {
628 "specified has an uppercase char. "
629 "Since the hostname buffer we match against "
630 "is actually lowercase, please specify an "
631 "all lowercase based pcre.");
641 if (capture_names == NULL || strlen(capture_names) == 0)
642 opts |= PCRE2_NO_AUTO_CAPTURE;
645 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
647 opts &= ~PCRE2_NO_AUTO_CAPTURE;
649 pcre2_compile((PCRE2_SPTR8)re, PCRE2_ZERO_TERMINATED, opts, &en, &eo2, NULL);
652 PCRE2_UCHAR errbuffer[256];
653 pcre2_get_error_message(en, errbuffer,
sizeof(errbuffer));
654 SCLogError(
"pcre2 compile of \"%s\" failed at "
656 regexstr, (
int)eo2, errbuffer);
660 #ifdef PCRE2_HAVE_JIT
667 SCLogDebug(
"PCRE2 JIT compiler does not support: %s. "
668 "Falling back to regular PCRE2 handling (%s:%d)",
676 SCLogError(
"pcre2 could not create match context");
680 if (apply_match_limit) {
681 if (pcre_match_limit >= -1) {
684 if (pcre_match_limit_recursion >= -1) {
693 pcre2_match_data_free(match);
697 pcre2_match_data_free(match);
698 DetectPcreFree(
de_ctx, pd);
708 int ret = 0, res = 0;
709 char type_str[16] =
"";
710 const char *orig_right_edge = regexstr + strlen(regexstr);
716 pcre2_match_data *match = NULL;
718 SCLogDebug(
"regexstr %s, pd %p", regexstr, pd);
720 ret = pcre2_pattern_info(pd->
parse_regex.
regex, PCRE2_INFO_CAPTURECOUNT, &capture_cnt);
721 SCLogDebug(
"ret %d capture_cnt %d", ret, capture_cnt);
722 if (ret == 0 && capture_cnt && strlen(capture_names) > 0)
725 while ((name_array[name_idx] = strtok_r(name_idx == 0 ? capture_names : NULL,
" ,", &ptr))){
726 if (name_idx > (capture_cnt - 1)) {
728 "var capture names than capturing substrings");
731 SCLogDebug(
"name '%s'", name_array[name_idx]);
733 if (strcmp(name_array[name_idx],
"pkt:key") == 0) {
741 }
else if (key == 1 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
746 }
else if (key == 0 && strcmp(name_array[name_idx],
"pkt:value") == 0) {
748 }
else if (key == 1) {
751 }
else if (strncmp(name_array[name_idx],
"flow:", 5) == 0) {
757 }
else if (strncmp(name_array[name_idx],
"pkt:", 4) == 0) {
766 "var capture names must start with 'pkt:' or 'flow:'");
778 size_t cap_buffer_len = strlen(regexstr) + 1;
779 char capture_str[cap_buffer_len];
780 memset(capture_str, 0x00, cap_buffer_len);
790 pcre2_match_data_free(match);
793 copylen =
sizeof(type_str);
794 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)type_str, ©len);
796 SCLogError(
"pcre2_substring_copy_bynumber failed");
799 cap_buffer_len = strlen(regexstr) + 1;
800 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)capture_str, &cap_buffer_len);
802 SCLogError(
"pcre2_substring_copy_bynumber failed");
805 if (strlen(capture_str) == 0 || strlen(type_str) == 0) {
813 SCLogError(
"rule can have maximally %d pkt/flow "
816 pcre2_match_data_free(match);
820 if (strcmp(type_str,
"pkt") == 0) {
825 }
else if (strcmp(type_str,
"flow") == 0) {
832 PCRE2_SIZE *ov = pcre2_get_ovector_pointer(match);
835 pcre2_match_data_free(match);
838 if (regexstr >= orig_right_edge)
844 pcre2_match_data_free(match);
848 static void *DetectPcreThreadInit(
void *data)
851 pcre2_match_data *match = pcre2_match_data_create_from_pattern(pd->
parse_regex.
regex, NULL);
855 static void DetectPcreThreadFree(
void *
ctx)
858 pcre2_match_data *match = (pcre2_match_data *)
ctx;
859 pcre2_match_data_free(match);
868 char capture_names[1024] =
"";
871 pd = DetectPcreParse(
de_ctx, regexstr, &parsed_sm_list,
876 if (DetectPcreParseCapture(regexstr,
de_ctx, pd, capture_names) < 0)
880 de_ctx,
"pcre", DetectPcreThreadInit, (
void *)pd, DetectPcreThreadFree, 0);
887 SCLogError(
"Expression seen with a sticky buffer still set; either (1) reset sticky "
888 "buffer with pkt_data or (2) use a sticky buffer providing \"%s\".",
897 switch (parsed_sm_list) {
911 sm_list = parsed_sm_list;
924 for (uint8_t x = 0; x < pd->
idx; x++) {
938 "preceding match in the same buffer");
941 }
else if (prev_pm == NULL) {
955 DetectPcreFree(
de_ctx, pd);
969 for (uint8_t i = 0; i < pd->
idx; i++) {
977 static int g_file_data_buffer_id = 0;
978 static int g_http_header_buffer_id = 0;
979 static int g_dce_stub_data_buffer_id = 0;
984 static int DetectPcreParseTest01 (
void)
988 const char *teststring =
"/blah/7";
994 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1004 static int DetectPcreParseTest02 (
void)
1008 const char *teststring =
"/blah/Ui$";
1014 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1025 static int DetectPcreParseTest03 (
void)
1029 const char *teststring =
"/blah/UNi";
1035 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1045 static int DetectPcreParseTest04 (
void)
1049 const char *teststring =
"/b\\\"lah/i";
1055 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1059 DetectPcreFree(
de_ctx, pd);
1067 static int DetectPcreParseTest05 (
void)
1071 const char *teststring =
"/b(l|a)h/";
1077 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1081 DetectPcreFree(
de_ctx, pd);
1089 static int DetectPcreParseTest06 (
void)
1093 const char *teststring =
"/b(l|a)h/smi";
1099 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1103 DetectPcreFree(
de_ctx, pd);
1111 static int DetectPcreParseTest07 (
void)
1115 const char *teststring =
"/blah/Ui";
1121 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1125 DetectPcreFree(
de_ctx, pd);
1133 static int DetectPcreParseTest08 (
void)
1137 const char *teststring =
"/b(l|a)h/O";
1143 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1147 DetectPcreFree(
de_ctx, pd);
1156 static int DetectPcreParseTest09 (
void)
1159 const char *teststring =
"/lala\\\\/";
1165 pd = DetectPcreParse(
de_ctx, teststring, &list, NULL, 0,
false, &alproto);
1168 DetectPcreFree(
de_ctx, pd);
1176 static int DetectPcreParseTest10(
void)
1205 static int DetectPcreParseTest15(
void)
1213 "alert tcp any any -> any any "
1214 "(msg:\"Testing pcre relative http_method\"; "
1216 "http_method; pcre:\"/abc/RM\"; sid:1;)");
1228 static int DetectPcreParseTest16(
void)
1236 "alert tcp any any -> any any "
1237 "(msg:\"Testing pcre relative http_cookie\"; "
1238 "content:\"test\"; "
1239 "http_cookie; pcre:\"/abc/RC\"; sid:1;)");
1250 static int DetectPcreParseTest17(
void)
1258 "alert tcp any any -> any any "
1259 "(msg:\"Testing pcre relative http_raw_header\"; "
1260 "flow:to_server; content:\"test\"; "
1261 "http_raw_header; pcre:\"/abc/RD\"; sid:1;)");
1272 static int DetectPcreParseTest18(
void)
1280 "alert tcp any any -> any any "
1281 "(msg:\"Testing pcre relative http_header\"; "
1282 "content:\"test\"; "
1283 "http_header; pcre:\"/abc/RH\"; sid:1;)");
1294 static int DetectPcreParseTest19(
void)
1302 "alert tcp any any -> any any "
1303 "(msg:\"Testing pcre relative http_client_body\"; "
1304 "content:\"test\"; "
1305 "http_client_body; pcre:\"/abc/RP\"; sid:1;)");
1316 static int DetectPcreParseTest20(
void)
1324 "alert tcp any any -> any any "
1325 "(msg:\"Testing http_raw_uri\"; "
1326 "content:\"test\"; "
1327 "http_raw_uri; pcre:\"/abc/RI\"; sid:1;)");
1338 static int DetectPcreParseTest21(
void)
1346 "alert tcp any any -> any any "
1347 "(msg:\"Testing pcre relative uricontent\"; "
1348 "uricontent:\"test\"; "
1349 "pcre:\"/abc/RU\"; sid:1;)");
1360 static int DetectPcreParseTest22(
void)
1368 "alert tcp any any -> any any "
1369 "(msg:\"Testing pcre relative http_uri\"; "
1370 "content:\"test\"; "
1371 "http_uri; pcre:\"/abc/RU\"; sid:1;)");
1382 static int DetectPcreParseTest23(
void)
1390 "alert tcp any any -> any any "
1391 "(msg:\"Testing inconsistent pcre relative\"; "
1393 "http_cookie; pcre:\"/abc/RM\"; sid:1;)");
1404 static int DetectPcreParseTest24(
void)
1412 "alert tcp any any -> any any "
1413 "(msg:\"Testing inconsistent pcre modifiers\"; "
1414 "pcre:\"/abc/UI\"; sid:1;)");
1425 static int DetectPcreParseTest25(
void)
1433 "alert tcp any any -> any any "
1434 "(msg:\"Testing inconsistent pcre modifiers\"; "
1435 "pcre:\"/abc/DH\"; sid:1;)");
1446 static int DetectPcreParseTest26(
void)
1454 "alert http any any -> any any "
1455 "(msg:\"Testing inconsistent pcre modifiers\"; "
1456 "pcre:\"/abc/F\"; sid:1;)");
1467 static int DetectPcreParseTest27(
void)
1475 "(content:\"baduricontent\"; http_raw_uri; "
1476 "pcre:\"/^[a-z]{5}\\.html/R\"; sid:2; rev:2;)");
1487 static int DetectPcreParseTest28(
void)
1495 "(content:\"|2E|suricata\"; http_host; pcre:\"/\\x2Esuricata$/W\"; "
1503 static int DetectPcreTestSig01(
void)
1505 uint8_t *buf = (uint8_t *)
"lalala lalala\\ lala\n";
1506 uint16_t buflen = strlen((
char *)buf);
1510 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; pcre:\"/ "
1511 "lalala\\\\/\"; sid:1;)";
1524 static int DetectPcreTestSig02(
void)
1526 uint8_t *buf = (uint8_t *)
"lalala\n";
1527 uint16_t buflen = strlen((
char *)buf);
1530 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1531 "pcre:\"/^(la)+$/\"; sid:1;)";
1540 static int DetectPcreTestSig03(
void)
1543 uint8_t *buf = (uint8_t *)
"lalala";
1544 uint16_t buflen = strlen((
char *)buf);
1547 char sig[] =
"alert tcp any any -> any any (msg:\"pcre with an ending slash\"; "
1548 "pcre:\"/^(la)+$/\"; sid:1;)";
1558 static int DetectPcreTxBodyChunksTest01(
void)
1563 uint8_t httpbuf1[] =
"GET / HTTP/1.1\r\n";
1564 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1565 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1566 uint8_t httpbuf4[] =
"Body one!!";
1567 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1568 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1569 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1570 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1571 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1572 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1573 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1574 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1575 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1576 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1579 memset(&f, 0,
sizeof(f));
1580 memset(&ssn, 0,
sizeof(ssn));
1586 f.
proto = IPPROTO_TCP;
1657 static int DetectPcreTxBodyChunksTest02(
void)
1665 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1666 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1667 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1668 uint8_t httpbuf4[] =
"Body one!!";
1669 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1670 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1671 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1672 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1673 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1674 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1675 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1676 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1677 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1678 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1681 memset(&th_v, 0,
sizeof(th_v));
1682 memset(&f, 0,
sizeof(f));
1683 memset(&ssn, 0,
sizeof(ssn));
1689 f.
proto = IPPROTO_TCP;
1705 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;)");
1707 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;)");
1797 if (det_ctx != NULL) {
1812 static int DetectPcreTxBodyChunksTest03(
void)
1820 uint8_t httpbuf1[] =
"POST / HTTP/1.1\r\n";
1821 uint8_t httpbuf2[] =
"User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1822 uint8_t httpbuf3[] =
"Cookie: dummy\r\n\r\n";
1823 uint8_t httpbuf4[] =
"Body one!!";
1824 uint32_t httplen1 =
sizeof(httpbuf1) - 1;
1825 uint32_t httplen2 =
sizeof(httpbuf2) - 1;
1826 uint32_t httplen3 =
sizeof(httpbuf3) - 1;
1827 uint32_t httplen4 =
sizeof(httpbuf4) - 1;
1828 uint8_t httpbuf5[] =
"GET /?var=val HTTP/1.1\r\n";
1829 uint8_t httpbuf6[] =
"User-Agent: Firefox/1.0\r\n";
1830 uint8_t httpbuf7[] =
"Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1831 uint32_t httplen5 =
sizeof(httpbuf5) - 1;
1832 uint32_t httplen6 =
sizeof(httpbuf6) - 1;
1833 uint32_t httplen7 =
sizeof(httpbuf7) - 1;
1836 memset(&th_v, 0,
sizeof(th_v));
1837 memset(&f, 0,
sizeof(f));
1838 memset(&ssn, 0,
sizeof(ssn));
1844 f.
proto = IPPROTO_TCP;
1860 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;)");
1862 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;)");
1934 if (det_ctx != NULL) {
1951 static int DetectPcreParseHttpHost(
void)
1959 DetectPcreData *pd = DetectPcreParse(
de_ctx,
"/domain\\.com/W", &list, NULL, 0,
false, &alproto);
1961 DetectPcreFree(
de_ctx, pd);
1964 pd = DetectPcreParse(
de_ctx,
"/dOmain\\.com/W", &list, NULL, 0,
false, &alproto);
1969 pd = DetectPcreParse(
de_ctx,
"/domain\\D+\\.com/W", &list, NULL, 0,
false, &alproto);
1971 DetectPcreFree(
de_ctx, pd);
1976 pd = DetectPcreParse(
de_ctx,
"/\\\\Ddomain\\.com/W", &list, NULL, 0,
false, &alproto);
1986 static int DetectPcreParseCaptureTest(
void)
1992 "(content:\"Server: \"; http_header; pcre:\"/(.*)\\r\\n/HR, flow:somecapture\"; content:\"xyz\"; http_header; sid:1;)");
1995 "(content:\"Server: \"; http_header; pcre:\"/(flow:.*)\\r\\n/HR\"; content:\"xyz\"; http_header; sid:2;)");
1998 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)([0-9]+)\\r\\n/HR, flow:somecapture, pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2001 "alert http any any -> any any "
2002 "(content:\"Server: \"; http_header; pcre:\"/([a-z]+)\\r\\n/HR, flow:somecapture, "
2003 "pkt:anothercap\"; content:\"xyz\"; http_header; sid:3;)");
2021 static void DetectPcreRegisterTests(
void)
2053 UtRegisterTest(
"DetectPcreTestSig02 -- anchored pcre", DetectPcreTestSig02);
2054 UtRegisterTest(
"DetectPcreTestSig03 -- anchored pcre", DetectPcreTestSig03);
2057 DetectPcreTxBodyChunksTest01);
2058 UtRegisterTest(
"DetectPcreTxBodyChunksTest02 -- modifier P, body chunks per tx",
2059 DetectPcreTxBodyChunksTest02);
2060 UtRegisterTest(
"DetectPcreTxBodyChunksTest03 -- modifier P, body chunks per tx",
2061 DetectPcreTxBodyChunksTest03);
2063 UtRegisterTest(
"DetectPcreParseHttpHost", DetectPcreParseHttpHost);
2064 UtRegisterTest(
"DetectPcreParseCaptureTest", DetectPcreParseCaptureTest);