65 static int g_http_header_buffer_id = 0;
66 static int g_keyword_thread_id = 0;
68 #define BUFFER_SIZE_STEP 1024
71 static uint8_t *GetBufferForTX(
82 const htp_headers_t *headers;
83 if (
flags & STREAM_TOSERVER) {
85 HTP_REQUEST_PROGRESS_HEADERS)
87 headers = htp_tx_request_headers(tx);
90 HTP_RESPONSE_PROGRESS_HEADERS)
92 headers = htp_tx_response_headers(tx);
98 size_t no_of_headers = htp_headers_size(headers);
99 for (; i < no_of_headers; i++) {
100 const htp_header_t *h = htp_headers_get_index(headers, i);
101 size_t size1 = htp_header_name_len(h);
102 size_t size2 = htp_header_value_len(h);
104 if (
flags & STREAM_TOSERVER) {
105 if (size1 == 6 && SCMemcmpLowercase(
"cookie", htp_header_name_ptr(h), 6) == 0) {
109 if (size1 == 10 && SCMemcmpLowercase(
"set-cookie", htp_header_name_ptr(h), 10) == 0) {
114 size_t size = size1 + size2 + 4;
116 if (i + 1 == no_of_headers)
119 if (size + buf->
len > buf->
size) {
125 memcpy(buf->
buffer + buf->
len, htp_header_name_ptr(h), htp_header_name_len(h));
126 buf->
len += htp_header_name_len(h);
129 memcpy(buf->
buffer + buf->
len, htp_header_value_ptr(h), htp_header_value_len(h));
130 buf->
len += htp_header_value_len(h);
133 #if 0 // looks like this breaks existing rules
134 if (i + 1 == no_of_headers) {
141 *buffer_len = buf->
len;
152 const uint8_t *b = NULL;
154 if (SCHttp2TxGetHeaders(txv, flow_flags, &b, &b_len) != 1)
156 if (b == NULL || b_len == 0)
171 uint32_t data_len = 0;
172 uint8_t *data = GetBufferForTX(txv, det_ctx,
flags, &data_len);
174 det_ctx, list_id, buffer, data, data_len, transforms);
203 const int list_id =
ctx->list_id;
206 uint32_t rawdata_len = 0;
207 uint8_t *rawdata = GetBufferForTX(txv, det_ctx,
flags, &rawdata_len);
208 if (rawdata_len == 0)
213 det_ctx, list_id, buffer, rawdata, rawdata_len,
ctx->transforms);
217 const uint8_t *data = buffer->
inspect;
222 if (data != NULL && data_len >= mpm_ctx->
minlen) {
224 mpm_ctx, &det_ctx->
mtc, &det_ctx->
pmq, data, data_len);
241 PrefilterMpmHttpHeader(det_ctx, pectx, p, f, txv, idx, _txd,
flags);
245 static void PrefilterMpmHttpHeaderFree(
void *ptr)
264 HTP_REQUEST_PROGRESS_HEADERS, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->
pname);
271 pectx =
SCCalloc(1,
sizeof(*pectx));
279 HTP_REQUEST_PROGRESS_TRAILER, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->
pname);
300 HTP_RESPONSE_PROGRESS_HEADERS, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->
pname);
307 pectx =
SCCalloc(1,
sizeof(*pectx));
315 HTP_RESPONSE_PROGRESS_TRAILER, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->
pname);
367 "content modifier to match only on the HTTP header-buffer";
369 "/rules/http-keywords.html#http-header-and-http-raw-header";
417 static int g_http_request_header_buffer_id = 0;
418 static int g_http_response_header_buffer_id = 0;
419 static int g_request_header_thread_id = 0;
420 static int g_response_header_thread_id = 0;
436 static void *HttpMultiBufHeaderThreadDataInit(
void *data)
442 SCLogError(
"failed to allocate %" PRIuMAX
" bytes: %s", (uintmax_t)
sizeof(*td),
449 static void HttpMultiBufHeaderThreadDataFree(
void *data)
452 for (
size_t i = 0; i < td->
cap; i++) {
460 uint32_t local_id,
const uint8_t **buf, uint32_t *buf_len)
465 if (
flags & STREAM_TOSERVER) {
466 kw_thread_id = g_request_header_thread_id;
468 kw_thread_id = g_response_header_thread_id;
476 htp_tx_t *tx = (htp_tx_t *)txv;
477 const htp_headers_t *headers;
478 if (
flags & STREAM_TOSERVER) {
479 headers = htp_tx_request_headers(tx);
481 headers = htp_tx_response_headers(tx);
483 size_t no_of_headers = htp_headers_size(headers);
488 if (hdr_td->
cap < no_of_headers) {
493 hdr_td->
items = new_buffer;
495 memset(hdr_td->
items + hdr_td->
cap, 0,
497 hdr_td->
cap = no_of_headers;
499 for (
size_t i = 0; i < no_of_headers; i++) {
500 const htp_header_t *h = htp_headers_get_index(headers, i);
501 uint32_t size1 = (uint32_t)htp_header_name_len(h);
502 uint32_t size2 = (uint32_t)htp_header_value_len(h);
503 uint32_t size = size1 + size2 + 2;
512 memcpy(hdr_td->
items[i].
buffer, htp_header_name_ptr(h), size1);
515 memcpy(hdr_td->
items[i].
buffer + size1 + 2, htp_header_value_ptr(h), size2);
518 hdr_td->
len = no_of_headers;
523 if (local_id < hdr_td->
len) {
526 *buf_len = hdr_td->
items[local_id].
len;
547 "sticky buffer to match on only one HTTP header name and value";
554 HTTP2StateOpen, SCHttp2TxGetHeader, 2);
556 HTP_REQUEST_PROGRESS_HEADERS, GetHttp1HeaderData, 2);
562 HttpMultiBufHeaderThreadDataInit, NULL, HttpMultiBufHeaderThreadDataFree);
580 "sticky buffer to match on only one HTTP header name and value";
587 HTTP2StateOpen, SCHttp2TxGetHeader, 2);
589 HTP_RESPONSE_PROGRESS_HEADERS, GetHttp1HeaderData, 2);
595 HttpMultiBufHeaderThreadDataInit, NULL, HttpMultiBufHeaderThreadDataFree);