63 static int g_http_header_buffer_id = 0;
64 static int g_keyword_thread_id = 0;
66 #define BUFFER_SIZE_STEP 1024
69 static uint8_t *GetBufferForTX(
82 if (
flags & STREAM_TOSERVER) {
86 headers = tx->request_headers;
91 headers = tx->response_headers;
97 size_t no_of_headers = htp_table_size(headers);
98 for (; i < no_of_headers; i++) {
99 htp_header_t *h = htp_table_get_index(headers, i, NULL);
100 size_t size1 = bstr_size(h->name);
101 size_t size2 = bstr_size(h->value);
103 if (
flags & STREAM_TOSERVER) {
105 SCMemcmpLowercase(
"cookie", bstr_ptr(h->name), 6) == 0) {
110 SCMemcmpLowercase(
"set-cookie", bstr_ptr(h->name), 10) == 0) {
115 size_t size = size1 + size2 + 4;
117 if (i + 1 == no_of_headers)
120 if (size + buf->
len > buf->
size) {
126 memcpy(buf->
buffer + buf->
len, bstr_ptr(h->name), bstr_size(h->name));
127 buf->
len += bstr_size(h->name);
130 memcpy(buf->
buffer + buf->
len, bstr_ptr(h->value), bstr_size(h->value));
131 buf->
len += bstr_size(h->value);
134 #if 0 // looks like this breaks existing rules
135 if (i + 1 == no_of_headers) {
142 *buffer_len = buf->
len;
153 const uint8_t *b = NULL;
155 if (rs_http2_tx_get_headers(txv, flow_flags, &b, &b_len) != 1)
157 if (b == NULL || b_len == 0)
176 const int list_id = engine->
sm_list;
179 SCLogDebug(
"setting up inspect buffer %d", list_id);
187 uint32_t rawdata_len = 0;
188 uint8_t *rawdata = GetBufferForTX(txv, det_ctx, f,
flags, &rawdata_len);
189 if (rawdata_len == 0) {
199 const uint8_t *data = buffer->
inspect;
209 NULL, f, (uint8_t *)data, data_len,
offset,
216 if (
flags & STREAM_TOSERVER) {
222 HTP_RESPONSE_HEADERS)
251 const int list_id = ctx->
list_id;
254 uint32_t rawdata_len = 0;
255 uint8_t *rawdata = GetBufferForTX(txv, det_ctx, f,
flags, &rawdata_len);
256 if (rawdata_len == 0)
265 const uint8_t *data = buffer->
inspect;
270 if (data != NULL && data_len >= mpm_ctx->
minlen) {
272 &det_ctx->
mtcu, &det_ctx->
pmq, data, data_len);
290 PrefilterMpmHttpHeader(det_ctx, pectx, p, f, txv, idx, _txd,
flags);
294 static void PrefilterMpmHttpHeaderFree(
void *ptr)
313 mpm_reg->
app_v2.alproto, HTP_REQUEST_HEADERS,
314 pectx, PrefilterMpmHttpHeaderFree, mpm_reg->
pname);
321 pectx =
SCCalloc(1,
sizeof(*pectx));
329 mpm_reg->
app_v2.alproto, HTP_REQUEST_TRAILER,
330 pectx, PrefilterMpmHttpHeaderFree, mpm_reg->
pname);
351 mpm_reg->
app_v2.alproto, HTP_RESPONSE_HEADERS,
352 pectx, PrefilterMpmHttpHeaderFree, mpm_reg->
pname);
359 pectx =
SCCalloc(1,
sizeof(*pectx));
367 mpm_reg->
app_v2.alproto, HTP_RESPONSE_TRAILER,
368 pectx, PrefilterMpmHttpHeaderFree, mpm_reg->
pname);
438 HTP_REQUEST_HEADERS, DetectEngineInspectBufferHttpHeader, NULL);
444 HTP_RESPONSE_HEADERS, DetectEngineInspectBufferHttpHeader, NULL);
468 static int g_http_request_header_buffer_id = 0;
469 static int g_http_response_header_buffer_id = 0;
485 const uint8_t *b = NULL;
487 if (rs_http2_tx_get_header(cbdata->
txv,
flags, cbdata->
local_id, &b, &b_len) != 1) {
491 if (b == NULL || b_len == 0) {
508 const int list_id = ctx->
list_id;
510 uint32_t local_id = 0;
517 GetHttp2HeaderData(det_ctx,
flags, ctx->
transforms, f, &cbdata, list_id);
548 GetHttp2HeaderData(det_ctx,
flags, transforms, f, &cbdata, engine->
sm_list);
550 if (buffer == NULL || buffer->
inspect == NULL)
580 mpm_reg->
app_v2.tx_min_progress, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->
name);
603 htp_tx_t *tx = (htp_tx_t *)cbdata->
txv;
604 htp_table_t *headers;
605 if (
flags & STREAM_TOSERVER) {
606 headers = tx->request_headers;
608 headers = tx->response_headers;
610 if (cbdata->
local_id < htp_table_size(headers)) {
611 htp_header_t *h = htp_table_get_index(headers, cbdata->
local_id, NULL);
612 size_t size1 = bstr_size(h->name);
613 size_t size2 = bstr_size(h->value);
614 size_t b_len = size1 + 2 + size2;
615 if (b_len > buf->
size) {
620 memcpy(buf->
buffer, bstr_ptr(h->name), bstr_size(h->name));
622 buf->
buffer[size1 + 1] =
' ';
623 memcpy(buf->
buffer + size1 + 2, bstr_ptr(h->value), bstr_size(h->value));
646 const int list_id = ctx->
list_id;
655 GetHttp1HeaderData(det_ctx,
flags, ctx->
transforms, f, &cbdata, list_id);
680 mpm_reg->
app_v2.tx_min_progress, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->
name);
700 GetHttp1HeaderData(det_ctx,
flags, transforms, f, &cbdata, engine->
sm_list);
702 if (buffer == NULL || buffer->
inspect == NULL)
736 "sticky buffer to match on only one HTTP header name and value";
743 PrefilterMpmHttp2HeaderRegister, NULL,
ALPROTO_HTTP2, HTTP2StateOpen);
745 HTTP2StateOpen, DetectEngineInspectHttp2Header, NULL);
749 HTP_REQUEST_HEADERS, DetectEngineInspectHttp1Header, NULL);
771 "sticky buffer to match on only one HTTP header name and value";
778 PrefilterMpmHttp2HeaderRegister, NULL,
ALPROTO_HTTP2, HTTP2StateOpen);
780 HTTP2StateOpen, DetectEngineInspectHttp2Header, NULL);
784 HTP_RESPONSE_HEADERS, DetectEngineInspectHttp1Header, NULL);