suricata
detect-http-header.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \ingroup httplayer
20  *
21  * @{
22  */
23 
24 
25 /**
26  * \file
27  *
28  * \author Pablo Rincon <pablo.rincon.crespo@gmail.com>
29  *
30  * Implements support for http_header keyword.
31  */
32 
33 #include "suricata-common.h"
34 #include "threads.h"
35 #include "decode.h"
36 
37 #include "detect.h"
38 #include "detect-parse.h"
39 #include "detect-engine.h"
40 #include "detect-engine-buffer.h"
41 #include "detect-engine-mpm.h"
42 #include "detect-engine-state.h"
45 #include "detect-content.h"
46 #include "detect-pcre.h"
47 
48 #include "util-debug.h"
49 #include "util-print.h"
50 #include "util-memcmp.h"
51 #include "util-profiling.h"
52 #include "util-validate.h"
53 
54 #include "app-layer.h"
55 #include "app-layer-parser.h"
56 
57 #include "app-layer-htp.h"
58 #include "detect-http-header.h"
60 
61 static int DetectHttpHeaderSetup(DetectEngineCtx *, Signature *, const char *);
62 #ifdef UNITTESTS
63 static void DetectHttpHeaderRegisterTests(void);
64 #endif
65 static int g_http_header_buffer_id = 0;
66 static int g_keyword_thread_id = 0;
67 static int g_http2_thread_id = 0;
68 
69 #define BUFFER_SIZE_STEP 1024
71 
72 static uint8_t *GetBufferForTX(
73  htp_tx_t *tx, DetectEngineThreadCtx *det_ctx, uint8_t flags, uint32_t *buffer_len)
74 {
75  *buffer_len = 0;
76 
77  HttpHeaderThreadData *hdr_td = NULL;
78  HttpHeaderBuffer *buf = HttpHeaderGetBufferSpace(det_ctx, flags, g_keyword_thread_id, &hdr_td);
79  if (unlikely(buf == NULL)) {
80  return NULL;
81  }
82 
83  const htp_headers_t *headers;
84  if (flags & STREAM_TOSERVER) {
85  if (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP1, tx, flags) <=
86  HTP_REQUEST_PROGRESS_HEADERS)
87  return NULL;
88  headers = htp_tx_request_headers(tx);
89  } else {
90  if (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP1, tx, flags) <=
91  HTP_RESPONSE_PROGRESS_HEADERS)
92  return NULL;
93  headers = htp_tx_response_headers(tx);
94  }
95  if (headers == NULL)
96  return NULL;
97 
98  size_t i = 0;
99  size_t no_of_headers = htp_headers_size(headers);
100  for (; i < no_of_headers; i++) {
101  const htp_header_t *h = htp_headers_get_index(headers, i);
102  size_t size1 = htp_header_name_len(h);
103  size_t size2 = htp_header_value_len(h);
104 
105  if (flags & STREAM_TOSERVER) {
106  if (size1 == 6 && SCMemcmpLowercase("cookie", htp_header_name_ptr(h), 6) == 0) {
107  continue;
108  }
109  } else {
110  if (size1 == 10 && SCMemcmpLowercase("set-cookie", htp_header_name_ptr(h), 10) == 0) {
111  continue;
112  }
113  }
114 
115  size_t size = size1 + size2 + 4;
116 #if 0
117  if (i + 1 == no_of_headers)
118  size += 2;
119 #endif
120  if (size + buf->len > buf->size) {
121  if (HttpHeaderExpandBuffer(hdr_td, buf, size) != 0) {
122  return NULL;
123  }
124  }
125 
126  memcpy(buf->buffer + buf->len, htp_header_name_ptr(h), htp_header_name_len(h));
127  buf->len += htp_header_name_len(h);
128  buf->buffer[buf->len++] = ':';
129  buf->buffer[buf->len++] = ' ';
130  memcpy(buf->buffer + buf->len, htp_header_value_ptr(h), htp_header_value_len(h));
131  buf->len += htp_header_value_len(h);
132  buf->buffer[buf->len++] = '\r';
133  buf->buffer[buf->len++] = '\n';
134 #if 0 // looks like this breaks existing rules
135  if (i + 1 == no_of_headers) {
136  buf->buffer[buf->len++] = '\r';
137  buf->buffer[buf->len++] = '\n';
138  }
139 #endif
140  }
141 
142  *buffer_len = buf->len;
143  return buf->buffer;
144 }
145 
146 static InspectionBuffer *GetBuffer2ForTX(DetectEngineThreadCtx *det_ctx,
147  const DetectEngineTransforms *transforms, Flow *_f, const uint8_t flow_flags, void *txv,
148  const int list_id)
149 {
150  InspectionBuffer *buffer = SCInspectionBufferGet(det_ctx, list_id);
151  if (buffer->inspect == NULL) {
152  uint32_t b_len = 0;
153  const uint8_t *b = NULL;
154 
155  void *thread_buf = DetectThreadCtxGetGlobalKeywordThreadCtx(det_ctx, g_http2_thread_id);
156  if (thread_buf == NULL)
157  return NULL;
158  if (SCHttp2TxGetHeaders(txv, flow_flags, &b, &b_len, thread_buf) != 1)
159  return NULL;
160  if (b == NULL || b_len == 0)
161  return NULL;
162 
163  SCInspectionBufferSetupAndApplyTransforms(det_ctx, list_id, buffer, b, b_len, transforms);
164  }
165 
166  return buffer;
167 }
168 
169 static InspectionBuffer *GetData1(DetectEngineThreadCtx *det_ctx,
170  const DetectEngineTransforms *transforms, Flow *_f, const uint8_t flags, void *txv,
171  const int list_id)
172 {
173  InspectionBuffer *buffer = SCInspectionBufferGet(det_ctx, list_id);
174  if (buffer->inspect == NULL) {
175  uint32_t data_len = 0;
176  uint8_t *data = GetBufferForTX(txv, det_ctx, flags, &data_len);
178  det_ctx, list_id, buffer, data, data_len, transforms);
179  }
180 
181  return buffer;
182 }
183 
185  int list_id;
186  const MpmCtx *mpm_ctx;
189 
190 /** \brief Generic Mpm prefilter callback
191  *
192  * \param det_ctx detection engine thread ctx
193  * \param p packet to inspect
194  * \param f flow to inspect
195  * \param txv tx to inspect
196  * \param pectx inspection context
197  */
198 static void PrefilterMpmHttpHeader(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p,
199  Flow *f, void *txv, const uint64_t idx, const AppLayerTxData *_txd, const uint8_t flags)
200 {
201  SCEnter();
202 
203  const PrefilterMpmHttpHeaderCtx *ctx = pectx;
204  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
205  SCLogDebug("running on list %d", ctx->list_id);
206 
207  const int list_id = ctx->list_id;
208  InspectionBuffer *buffer = SCInspectionBufferGet(det_ctx, list_id);
209  if (buffer->inspect == NULL) {
210  uint32_t rawdata_len = 0;
211  uint8_t *rawdata = GetBufferForTX(txv, det_ctx, flags, &rawdata_len);
212  if (rawdata_len == 0)
213  return;
214 
215  /* setup buffer and apply transforms */
217  det_ctx, list_id, buffer, rawdata, rawdata_len, ctx->transforms);
218  }
219 
220  const uint32_t data_len = buffer->inspect_len;
221  const uint8_t *data = buffer->inspect;
222 
223  SCLogDebug("mpm'ing buffer:");
224  //PrintRawDataFp(stdout, data, data_len);
225 
226  if (data != NULL && data_len >= mpm_ctx->minlen) {
227  (void)mpm_table[mpm_ctx->mpm_type].Search(
228  mpm_ctx, &det_ctx->mtc, &det_ctx->pmq, data, data_len);
229  PREFILTER_PROFILING_ADD_BYTES(det_ctx, data_len);
230  }
231 }
232 
233 static void PrefilterMpmHttpTrailer(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p,
234  Flow *f, void *txv, const uint64_t idx, const AppLayerTxData *_txd, const uint8_t flags)
235 {
236  SCEnter();
237 
238  htp_tx_t *tx = txv;
239  const HtpTxUserData *htud = (const HtpTxUserData *)htp_tx_get_user_data(tx);
240  /* if the request wasn't flagged as having a trailer, we skip */
241  if (((flags & STREAM_TOSERVER) && !htud->request_has_trailers) ||
242  ((flags & STREAM_TOCLIENT) && !htud->response_has_trailers)) {
243  SCReturn;
244  }
245  PrefilterMpmHttpHeader(det_ctx, pectx, p, f, txv, idx, _txd, flags);
246  SCReturn;
247 }
248 
249 static void PrefilterMpmHttpHeaderFree(void *ptr)
250 {
251  SCFree(ptr);
252 }
253 
254 static int PrefilterMpmHttpHeaderRequestRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh,
255  MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
256 {
257  SCEnter();
258 
259  /* header */
260  PrefilterMpmHttpHeaderCtx *pectx = SCCalloc(1, sizeof(*pectx));
261  if (pectx == NULL)
262  return -1;
263  pectx->list_id = list_id;
264  pectx->mpm_ctx = mpm_ctx;
265  pectx->transforms = &mpm_reg->transforms;
266 
267  int r = PrefilterAppendTxEngine(de_ctx, sgh, PrefilterMpmHttpHeader, mpm_reg->app_v2.alproto,
268  HTP_REQUEST_PROGRESS_HEADERS, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->pname);
269  if (r != 0) {
270  SCFree(pectx);
271  return r;
272  }
273 
274  /* trailer */
275  pectx = SCCalloc(1, sizeof(*pectx));
276  if (pectx == NULL)
277  return -1;
278  pectx->list_id = list_id;
279  pectx->mpm_ctx = mpm_ctx;
280  pectx->transforms = &mpm_reg->transforms;
281 
282  r = PrefilterAppendTxEngine(de_ctx, sgh, PrefilterMpmHttpTrailer, mpm_reg->app_v2.alproto,
283  HTP_REQUEST_PROGRESS_TRAILER, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->pname);
284  if (r != 0) {
285  SCFree(pectx);
286  }
287  return r;
288 }
289 
290 static int PrefilterMpmHttpHeaderResponseRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh,
291  MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
292 {
293  SCEnter();
294 
295  /* header */
296  PrefilterMpmHttpHeaderCtx *pectx = SCCalloc(1, sizeof(*pectx));
297  if (pectx == NULL)
298  return -1;
299  pectx->list_id = list_id;
300  pectx->mpm_ctx = mpm_ctx;
301  pectx->transforms = &mpm_reg->transforms;
302 
303  int r = PrefilterAppendTxEngine(de_ctx, sgh, PrefilterMpmHttpHeader, mpm_reg->app_v2.alproto,
304  HTP_RESPONSE_PROGRESS_HEADERS, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->pname);
305  if (r != 0) {
306  SCFree(pectx);
307  return r;
308  }
309 
310  /* trailer */
311  pectx = SCCalloc(1, sizeof(*pectx));
312  if (pectx == NULL)
313  return -1;
314  pectx->list_id = list_id;
315  pectx->mpm_ctx = mpm_ctx;
316  pectx->transforms = &mpm_reg->transforms;
317 
318  r = PrefilterAppendTxEngine(de_ctx, sgh, PrefilterMpmHttpTrailer, mpm_reg->app_v2.alproto,
319  HTP_RESPONSE_PROGRESS_TRAILER, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->pname);
320  if (r != 0) {
321  SCFree(pectx);
322  }
323  return r;
324 }
325 
326 /**
327  * \brief The setup function for the http_header keyword for a signature.
328  *
329  * \param de_ctx Pointer to the detection engine context.
330  * \param s Pointer to signature for the current Signature being parsed
331  * from the rules.
332  * \param m Pointer to the head of the SigMatchs for the current rule
333  * being parsed.
334  * \param arg Pointer to the string holding the keyword value.
335  *
336  * \retval 0 On success.
337  * \retval -1 On failure.
338  */
339 static int DetectHttpHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
340 {
342  de_ctx, s, arg, DETECT_HTTP_HEADER_CM, g_http_header_buffer_id, ALPROTO_HTTP1);
343 }
344 
345 /**
346  * \brief this function setup the http.header keyword used in the rule
347  *
348  * \param de_ctx Pointer to the Detection Engine Context
349  * \param s Pointer to the Signature to which the current keyword belongs
350  * \param str Should hold an empty string always
351  *
352  * \retval 0 On success
353  */
354 static int DetectHttpHeaderSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str)
355 {
356  if (SCDetectBufferSetActiveList(de_ctx, s, g_http_header_buffer_id) < 0)
357  return -1;
359  return -1;
360  return 0;
361 }
362 
363 /**
364  * \brief Registers the keyword handlers for the "http_header" keyword.
365  */
367 {
368  /* http_header content modifier */
369  sigmatch_table[DETECT_HTTP_HEADER_CM].name = "http_header";
371  "content modifier to match only on the HTTP header-buffer";
372  // no doc url for this obsolete keyword, see http.header
373  sigmatch_table[DETECT_HTTP_HEADER_CM].Setup = DetectHttpHeaderSetup;
374 #ifdef UNITTESTS
376 #endif
380 
381  /* http.header sticky buffer */
382  sigmatch_table[DETECT_HTTP_HEADER].name = "http.header";
383  sigmatch_table[DETECT_HTTP_HEADER].desc = "sticky buffer to match on the normalized HTTP header-buffer";
384  sigmatch_table[DETECT_HTTP_HEADER].url = "/rules/http-keywords.html#http-header";
385  sigmatch_table[DETECT_HTTP_HEADER].Setup = DetectHttpHeaderSetupSticky;
388 
390  HTP_REQUEST_PROGRESS_HEADERS, DetectEngineInspectBufferGeneric, GetData1);
392  PrefilterMpmHttpHeaderRequestRegister, NULL, ALPROTO_HTTP1,
393  0); /* not used, registered twice: HEADERS/TRAILER */
394 
396  HTP_RESPONSE_PROGRESS_HEADERS, DetectEngineInspectBufferGeneric, GetData1);
398  PrefilterMpmHttpHeaderResponseRegister, NULL, ALPROTO_HTTP1,
399  0); /* not used, registered twice: HEADERS/TRAILER */
400 
402  HTTP2StateOpen, DetectEngineInspectBufferGeneric, GetBuffer2ForTX);
404  GetBuffer2ForTX, ALPROTO_HTTP2, HTTP2StateOpen);
405 
407  HTTP2StateDataServer, DetectEngineInspectBufferGeneric, GetBuffer2ForTX);
409  GetBuffer2ForTX, ALPROTO_HTTP2, HTTP2StateDataServer);
410 
412  "http headers");
413 
414  g_http_header_buffer_id = DetectBufferTypeGetByName("http_header");
415 
416  g_keyword_thread_id = DetectRegisterThreadCtxGlobalFuncs("http_header",
418  g_http2_thread_id = DetectRegisterThreadCtxGlobalFuncs(
419  "http2.header", SCHttp2ThreadBufDataInit, NULL, SCHttp2ThreadBufDataFree);
420 }
421 
422 static int g_http_request_header_buffer_id = 0;
423 static int g_http_response_header_buffer_id = 0;
424 static int g_request_header_thread_id = 0;
425 static int g_response_header_thread_id = 0;
426 static int g_h2_request_header_thread_id = 0;
427 static int g_h2_response_header_thread_id = 0;
428 
429 typedef struct HttpMultiBufItem {
430  uint8_t *buffer;
431  uint32_t len;
433 
435  // array of items, being defined as a buffer with its length just above
437  // capacity of items (size of allocation)
438  size_t cap;
439  // length of items (number in use)
440  size_t len;
442 
443 static void *HttpMultiBufHeaderThreadDataInit(void *data)
444 {
445  HttpMultiBufHeaderThreadData *td = SCCalloc(1, sizeof(*td));
446 
447  /* This return value check to satisfy our Cocci malloc checks. */
448  if (td == NULL) {
449  SCLogError("failed to allocate %" PRIuMAX " bytes: %s", (uintmax_t)sizeof(*td),
450  strerror(errno));
451  return NULL;
452  }
453  return td;
454 }
455 
456 static void HttpMultiBufHeaderThreadDataFree(void *data)
457 {
458  HttpMultiBufHeaderThreadData *td = data;
459  for (size_t i = 0; i < td->cap; i++) {
460  SCFree(td->items[i].buffer);
461  }
462  SCFree(td->items);
463  SCFree(td);
464 }
465 
466 static bool GetHttp2HeaderData(DetectEngineThreadCtx *det_ctx, const void *txv, const uint8_t flags,
467  uint32_t local_id, const uint8_t **buf, uint32_t *buf_len)
468 {
469  int kw_thread_id;
470  if (flags & STREAM_TOSERVER) {
471  kw_thread_id = g_h2_request_header_thread_id;
472  } else {
473  kw_thread_id = g_h2_response_header_thread_id;
474  }
475  void *hdr_td = DetectThreadCtxGetGlobalKeywordThreadCtx(det_ctx, kw_thread_id);
476  if (unlikely(hdr_td == NULL)) {
477  return false;
478  }
479  return SCHttp2TxGetHeader(hdr_td, txv, flags, local_id, buf, buf_len);
480 }
481 
482 static bool GetHttp1HeaderData(DetectEngineThreadCtx *det_ctx, const void *txv, const uint8_t flags,
483  uint32_t local_id, const uint8_t **buf, uint32_t *buf_len)
484 {
485  SCEnter();
486 
487  int kw_thread_id;
488  if (flags & STREAM_TOSERVER) {
489  kw_thread_id = g_request_header_thread_id;
490  } else {
491  kw_thread_id = g_response_header_thread_id;
492  }
494  DetectThreadCtxGetGlobalKeywordThreadCtx(det_ctx, kw_thread_id);
495  if (unlikely(hdr_td == NULL)) {
496  return false;
497  }
498 
499  htp_tx_t *tx = (htp_tx_t *)txv;
500  const htp_headers_t *headers;
501  if (flags & STREAM_TOSERVER) {
502  headers = htp_tx_request_headers(tx);
503  } else {
504  headers = htp_tx_response_headers(tx);
505  }
506  size_t no_of_headers = htp_headers_size(headers);
507  if (local_id == 0) {
508  // We initialize a big buffer on first item
509  // Then, we will just use parts of it
510  hdr_td->len = 0;
511  if (hdr_td->cap < no_of_headers) {
512  void *new_buffer = SCRealloc(hdr_td->items, no_of_headers * sizeof(HttpMultiBufItem));
513  if (unlikely(new_buffer == NULL)) {
514  return NULL;
515  }
516  hdr_td->items = new_buffer;
517  // zeroes the new part of the items
518  memset(hdr_td->items + hdr_td->cap, 0,
519  (no_of_headers - hdr_td->cap) * sizeof(HttpMultiBufItem));
520  hdr_td->cap = no_of_headers;
521  }
522  for (size_t i = 0; i < no_of_headers; i++) {
523  const htp_header_t *h = htp_headers_get_index(headers, i);
524  uint32_t size1 = (uint32_t)htp_header_name_len(h);
525  uint32_t size2 = (uint32_t)htp_header_value_len(h);
526  uint32_t size = size1 + size2 + 2;
527  if (hdr_td->items[i].len < size) {
528  // Use realloc, as this pointer is not freed until HttpMultiBufHeaderThreadDataFree
529  void *tmp = SCRealloc(hdr_td->items[i].buffer, size);
530  if (unlikely(tmp == NULL)) {
531  return NULL;
532  }
533  hdr_td->items[i].buffer = tmp;
534  }
535  memcpy(hdr_td->items[i].buffer, htp_header_name_ptr(h), size1);
536  hdr_td->items[i].buffer[size1] = ':';
537  hdr_td->items[i].buffer[size1 + 1] = ' ';
538  memcpy(hdr_td->items[i].buffer + size1 + 2, htp_header_value_ptr(h), size2);
539  hdr_td->items[i].len = size;
540  }
541  hdr_td->len = no_of_headers;
542  }
543 
544  // cbdata->local_id is the index of the requested header buffer
545  // hdr_td->len is the number of header buffers
546  if (local_id < hdr_td->len) {
547  // we have one valid header buffer
548  *buf = hdr_td->items[local_id].buffer;
549  *buf_len = hdr_td->items[local_id].len;
550  return true;
551  } // else there are no more header buffer to get
552  return false;
553 }
554 
555 static int DetectHTTPRequestHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
556 {
557  if (SCDetectBufferSetActiveList(de_ctx, s, g_http_request_header_buffer_id) < 0)
558  return -1;
559 
561  return -1;
562 
563  return 0;
564 }
565 
567 {
568  sigmatch_table[DETECT_HTTP_REQUEST_HEADER].name = "http.request_header";
570  "sticky buffer to match on only one HTTP header name and value";
572  "/rules/http-keywords.html#http-request-header";
573  sigmatch_table[DETECT_HTTP_REQUEST_HEADER].Setup = DetectHTTPRequestHeaderSetup;
576 
578  HTTP2StateOpen, GetHttp2HeaderData, 2);
580  HTP_REQUEST_PROGRESS_HEADERS, GetHttp1HeaderData, 2);
581 
582  DetectBufferTypeSetDescriptionByName("http_request_header", "HTTP header name and value");
583  g_http_request_header_buffer_id = DetectBufferTypeGetByName("http_request_header");
584  DetectBufferTypeSupportsMultiInstance("http_request_header");
585  g_request_header_thread_id = DetectRegisterThreadCtxGlobalFuncs("http_request_header",
586  HttpMultiBufHeaderThreadDataInit, NULL, HttpMultiBufHeaderThreadDataFree);
587  g_h2_request_header_thread_id = DetectRegisterThreadCtxGlobalFuncs("http2_request_header",
588  SCHttp2ThreadMultiBufDataInit, NULL, SCHttp2ThreadMultiBufDataFree);
589 }
590 
591 static int DetectHTTPResponseHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
592 {
593  if (SCDetectBufferSetActiveList(de_ctx, s, g_http_response_header_buffer_id) < 0)
594  return -1;
595 
597  return -1;
598 
599  return 0;
600 }
601 
603 {
604  sigmatch_table[DETECT_HTTP_RESPONSE_HEADER].name = "http.response_header";
606  "sticky buffer to match on only one HTTP header name and value";
608  "/rules/http-keywords.html#http-response-header";
609  sigmatch_table[DETECT_HTTP_RESPONSE_HEADER].Setup = DetectHTTPResponseHeaderSetup;
612 
614  HTTP2StateOpen, GetHttp2HeaderData, 2);
616  HTP_RESPONSE_PROGRESS_HEADERS, GetHttp1HeaderData, 2);
617 
618  DetectBufferTypeSetDescriptionByName("http_response_header", "HTTP header name and value");
619  g_http_response_header_buffer_id = DetectBufferTypeGetByName("http_response_header");
620  DetectBufferTypeSupportsMultiInstance("http_response_header");
621  g_response_header_thread_id = DetectRegisterThreadCtxGlobalFuncs("http_response_header",
622  HttpMultiBufHeaderThreadDataInit, NULL, HttpMultiBufHeaderThreadDataFree);
623  g_h2_response_header_thread_id = DetectRegisterThreadCtxGlobalFuncs("http2_response_header",
624  SCHttp2ThreadMultiBufDataInit, NULL, SCHttp2ThreadMultiBufDataFree);
625 }
626 
627 /************************************Unittests*********************************/
628 
629 #ifdef UNITTESTS
631 #endif
632 
633 /**
634  * @}
635  */
SigTableElmt_::url
const char * url
Definition: detect.h:1503
BUFFER_SIZE_STEP
#define BUFFER_SIZE_STEP
Definition: detect-http-header.c:69
detect-content.h
len
uint8_t len
Definition: app-layer-dnp3.h:2
MpmCtx_::mpm_type
uint8_t mpm_type
Definition: util-mpm.h:99
detect-engine.h
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect-engine-register.h:306
SigTableElmt_::desc
const char * desc
Definition: detect.h:1502
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:79
DetectEngineInspectBufferGeneric
uint8_t DetectEngineInspectBufferGeneric(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:2049
SCInspectionBufferGet
InspectionBuffer * SCInspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine-inspect-buffer.c:56
SigTableElmt_::name
const char * name
Definition: detect.h:1500
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1670
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms
Definition: detect.h:391
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1491
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
DetectHttpRequestHeaderRegister
void DetectHttpRequestHeaderRegister(void)
Definition: detect-http-header.c:566
DetectBufferMpmRegistry_::app_v2
struct DetectBufferMpmRegistry_::@90::@92 app_v2
HttpHeaderBuffer_::len
uint32_t len
Definition: detect-http-header-common.h:30
AppLayerParserGetStateProgress
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t flags)
get the progress value for a tx/protocol
Definition: app-layer-parser.c:1111
InspectionBuffer
Definition: detect-engine-inspect-buffer.h:34
threads.h
Flow_
Flow data structure.
Definition: flow.h:347
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1390
ctx
struct Thresholds ctx
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:966
SCInspectionBufferSetupAndApplyTransforms
void SCInspectionBufferSetupAndApplyTransforms(DetectEngineThreadCtx *det_ctx, const int list_id, InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len, const DetectEngineTransforms *transforms)
setup the buffer with our initial data
Definition: detect-engine-inspect-buffer.c:197
HttpHeaderGetBufferSpace
HttpHeaderBuffer * HttpHeaderGetBufferSpace(DetectEngineThreadCtx *det_ctx, uint8_t flags, const int keyword_id, HttpHeaderThreadData **ret_hdr_td)
Definition: detect-http-header-common.c:99
DetectBufferTypeSupportsMultiInstance
void DetectBufferTypeSupportsMultiInstance(const char *name)
Definition: detect-engine.c:1228
detect-http-header.h
DetectBufferMpmRegistry_
one time registration of keywords at start up
Definition: detect.h:767
SCDetectBufferSetActiveList
int SCDetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
Definition: detect-engine-buffer.c:29
SCDetectSignatureSetAppProto
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:2277
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:271
HttpHeaderExpandBuffer
int HttpHeaderExpandBuffer(HttpHeaderThreadData *td, HttpHeaderBuffer *buf, size_t size)
Definition: detect-http-header-common.c:81
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1482
detect-pcre.h
DetectBufferMpmRegistry_::transforms
DetectEngineTransforms transforms
Definition: detect.h:780
detect-engine-prefilter.h
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1278
util-memcmp.h
DetectHttpResponseHeaderRegister
void DetectHttpResponseHeaderRegister(void)
Definition: detect-http-header.c:602
SIGMATCH_INFO_MULTI_BUFFER
#define SIGMATCH_INFO_MULTI_BUFFER
Definition: detect-engine-register.h:338
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:270
app-layer-htp.h
HttpMultiBufHeaderThreadData::len
size_t len
Definition: detect-http-header.c:440
decode.h
DetectBufferMpmRegistry_::pname
char pname[DETECT_PROFILE_NAME_LEN]
Definition: detect.h:769
util-debug.h
AppLayerTxData
Definition: app-layer-parser.h:162
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:19
DetectEngineThreadCtx_
Definition: detect.h:1284
HttpMultiBufHeaderThreadData::items
HttpMultiBufItem * items
Definition: detect-http-header.c:436
util-print.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:284
detect-engine-mpm.h
detect.h
HtpTxUserData_::response_has_trailers
uint8_t response_has_trailers
Definition: app-layer-htp.h:158
DETECT_HTTP_REQUEST_HEADER
@ DETECT_HTTP_REQUEST_HEADER
Definition: detect-engine-register.h:209
HttpMultiBufHeaderThreadData
Definition: detect-http-header.c:434
PrefilterGenericMpmRegister
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
Definition: detect-engine-prefilter.c:1580
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1498
DetectAppLayerMpmRegister
void DetectAppLayerMpmRegister(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionBufferGetDataPtr GetData, AppProto alproto, int tx_min_progress)
register an app layer keyword for mpm
Definition: detect-engine-mpm.c:152
app-layer-parser.h
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:108
HttpMultiBufItem
struct HttpMultiBufItem HttpMultiBufItem
HtpTxUserData_::request_has_trailers
uint8_t request_has_trailers
Definition: app-layer-htp.h:157
util-profiling.h
SCReturn
#define SCReturn
Definition: util-debug.h:286
SIGMATCH_INFO_CONTENT_MODIFIER
#define SIGMATCH_INFO_CONTENT_MODIFIER
Definition: detect-engine-register.h:326
DetectEngineContentModifierBufferSetup
int DetectEngineContentModifierBufferSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg, int sm_type, int sm_list, AppProto alproto)
Definition: detect-parse.c:146
detect-http-header.c
Packet_
Definition: decode.h:505
detect-http-header-common.h
HttpMultiBufHeaderThreadData
struct HttpMultiBufHeaderThreadData HttpMultiBufHeaderThreadData
HttpHeaderThreadConfig_
Definition: detect-http-header-common.h:33
HttpHeaderBuffer_::buffer
uint8_t * buffer
Definition: detect-http-header-common.h:28
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
ALPROTO_HTTP2
@ ALPROTO_HTTP2
Definition: app-layer-protos.h:69
HttpMultiBufHeaderThreadData::cap
size_t cap
Definition: detect-http-header.c:438
MpmTableElmt_::Search
uint32_t(* Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint32_t)
Definition: util-mpm.h:186
HttpMultiBufItem
Definition: detect-http-header.c:429
DetectEngineThreadCtx_::mtc
MpmThreadCtx mtc
Definition: detect.h:1386
SCRealloc
#define SCRealloc(ptr, sz)
Definition: util-mem.h:50
detect-engine-content-inspection.h
HttpHeaderThreadDataInit
void * HttpHeaderThreadDataInit(void *data)
Definition: detect-http-header-common.c:57
PREFILTER_PROFILING_ADD_BYTES
#define PREFILTER_PROFILING_ADD_BYTES(det_ctx, bytes)
Definition: util-profiling.h:286
flags
uint8_t flags
Definition: decode-gre.h:0
PrefilterMpmHttpHeaderCtx::list_id
int list_id
Definition: detect-http-header.c:185
HttpMultiBufItem::len
uint32_t len
Definition: detect-http-header.c:431
PrefilterMpmHttpHeaderCtx
Definition: detect-http-header.c:184
DetectHttpHeaderRegister
void DetectHttpHeaderRegister(void)
Registers the keyword handlers for the "http_header" keyword.
Definition: detect-http-header.c:366
suricata-common.h
DETECT_HTTP_HEADER
@ DETECT_HTTP_HEADER
Definition: detect-engine-register.h:165
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:36
detect-engine-buffer.h
HttpHeaderBuffer_::size
uint32_t size
Definition: detect-http-header-common.h:29
PrefilterAppendTxEngine
int PrefilterAppendTxEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterTxFn PrefilterTxFunc, AppProto alproto, int tx_min_progress, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
Definition: detect-engine-prefilter.c:355
HtpTxUserData_
Definition: app-layer-htp.h:152
util-validate.h
PrefilterMpmHttpHeaderCtx::transforms
const DetectEngineTransforms * transforms
Definition: detect-http-header.c:187
PrefilterMpmHttpHeaderCtx
struct PrefilterMpmHttpHeaderCtx PrefilterMpmHttpHeaderCtx
InspectionBuffer::inspect_len
uint32_t inspect_len
Definition: detect-engine-inspect-buffer.h:37
InspectionBuffer::inspect
const uint8_t * inspect
Definition: detect-engine-inspect-buffer.h:35
PrefilterMpmHttpHeaderCtx::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-http-header.c:186
str
#define str(s)
Definition: suricata-common.h:308
DetectThreadCtxGetGlobalKeywordThreadCtx
void * DetectThreadCtxGetGlobalKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
Definition: detect-engine.c:3818
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DETECT_HTTP_HEADER_CM
@ DETECT_HTTP_HEADER_CM
Definition: detect-engine-register.h:164
detect-parse.h
Signature_
Signature container.
Definition: detect.h:672
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition: app-layer-protos.h:76
SIGMATCH_INFO_STICKY_BUFFER
#define SIGMATCH_INFO_STICKY_BUFFER
Definition: detect-engine-register.h:328
mpm_table
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.c:47
DetectAppLayerInspectEngineRegister
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
Definition: detect-engine.c:273
DetectBufferTypeSetDescriptionByName
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
Definition: detect-engine.c:1375
DetectAppLayerMultiRegister
void DetectAppLayerMultiRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectionMultiBufferGetDataPtr GetData, int priority)
Definition: detect-engine.c:2099
MpmCtx_
Definition: util-mpm.h:97
HttpHeaderBuffer_
Definition: detect-http-header-common.h:27
DETECT_HTTP_RESPONSE_HEADER
@ DETECT_HTTP_RESPONSE_HEADER
Definition: detect-engine-register.h:210
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
DetectHttpHeaderRegisterTests
void DetectHttpHeaderRegisterTests(void)
Definition: detect-http-header.c:4769
HttpMultiBufItem::buffer
uint8_t * buffer
Definition: detect-http-header.c:430
HttpHeaderThreadData_
Definition: detect-http-header-common.h:37
HttpHeaderThreadDataFree
void HttpHeaderThreadDataFree(void *data)
Definition: detect-http-header-common.c:74
DetectRegisterThreadCtxGlobalFuncs
int DetectRegisterThreadCtxGlobalFuncs(const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *))
Register Thread keyword context Funcs (Global)
Definition: detect-engine.c:3774
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1489
app-layer.h