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 = InspectionBufferGet(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  InspectionBufferSetupAndApplyTransforms(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 = InspectionBufferGet(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 = InspectionBufferGet(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";
373  "/rules/http-keywords.html#http-header-and-http-raw-header";
374  sigmatch_table[DETECT_HTTP_HEADER_CM].Setup = DetectHttpHeaderSetup;
375 #ifdef UNITTESTS
377 #endif
381 
382  /* http.header sticky buffer */
383  sigmatch_table[DETECT_HTTP_HEADER].name = "http.header";
384  sigmatch_table[DETECT_HTTP_HEADER].desc = "sticky buffer to match on the normalized HTTP header-buffer";
385  sigmatch_table[DETECT_HTTP_HEADER].url = "/rules/http-keywords.html#http-header-and-http-raw-header";
386  sigmatch_table[DETECT_HTTP_HEADER].Setup = DetectHttpHeaderSetupSticky;
389 
391  HTP_REQUEST_PROGRESS_HEADERS, DetectEngineInspectBufferGeneric, GetData1);
393  PrefilterMpmHttpHeaderRequestRegister, NULL, ALPROTO_HTTP1,
394  0); /* not used, registered twice: HEADERS/TRAILER */
395 
397  HTP_RESPONSE_PROGRESS_HEADERS, DetectEngineInspectBufferGeneric, GetData1);
399  PrefilterMpmHttpHeaderResponseRegister, NULL, ALPROTO_HTTP1,
400  0); /* not used, registered twice: HEADERS/TRAILER */
401 
403  HTTP2StateDataClient, DetectEngineInspectBufferGeneric, GetBuffer2ForTX);
405  GetBuffer2ForTX, ALPROTO_HTTP2, HTTP2StateDataClient);
406 
408  HTTP2StateDataServer, DetectEngineInspectBufferGeneric, GetBuffer2ForTX);
410  GetBuffer2ForTX, ALPROTO_HTTP2, HTTP2StateDataServer);
411 
413  "http headers");
414 
415  g_http_header_buffer_id = DetectBufferTypeGetByName("http_header");
416 
417  g_keyword_thread_id = DetectRegisterThreadCtxGlobalFuncs("http_header",
419  g_http2_thread_id = DetectRegisterThreadCtxGlobalFuncs(
420  "http2.header", SCHttp2ThreadBufDataInit, NULL, SCHttp2ThreadBufDataFree);
421 }
422 
423 static int g_http_request_header_buffer_id = 0;
424 static int g_http_response_header_buffer_id = 0;
425 static int g_request_header_thread_id = 0;
426 static int g_response_header_thread_id = 0;
427 static int g_h2_request_header_thread_id = 0;
428 static int g_h2_response_header_thread_id = 0;
429 
430 typedef struct HttpMultiBufItem {
431  uint8_t *buffer;
432  uint32_t len;
434 
436  // array of items, being defined as a buffer with its length just above
438  // capacity of items (size of allocation)
439  size_t cap;
440  // length of items (number in use)
441  size_t len;
443 
444 static void *HttpMultiBufHeaderThreadDataInit(void *data)
445 {
446  HttpMultiBufHeaderThreadData *td = SCCalloc(1, sizeof(*td));
447 
448  /* This return value check to satisfy our Cocci malloc checks. */
449  if (td == NULL) {
450  SCLogError("failed to allocate %" PRIuMAX " bytes: %s", (uintmax_t)sizeof(*td),
451  strerror(errno));
452  return NULL;
453  }
454  return td;
455 }
456 
457 static void HttpMultiBufHeaderThreadDataFree(void *data)
458 {
459  HttpMultiBufHeaderThreadData *td = data;
460  for (size_t i = 0; i < td->cap; i++) {
461  SCFree(td->items[i].buffer);
462  }
463  SCFree(td->items);
464  SCFree(td);
465 }
466 
467 static bool GetHttp2HeaderData(DetectEngineThreadCtx *det_ctx, const void *txv, const uint8_t flags,
468  uint32_t local_id, const uint8_t **buf, uint32_t *buf_len)
469 {
470  int kw_thread_id;
471  if (flags & STREAM_TOSERVER) {
472  kw_thread_id = g_h2_request_header_thread_id;
473  } else {
474  kw_thread_id = g_h2_response_header_thread_id;
475  }
476  void *hdr_td = DetectThreadCtxGetGlobalKeywordThreadCtx(det_ctx, kw_thread_id);
477  if (unlikely(hdr_td == NULL)) {
478  return false;
479  }
480  return SCHttp2TxGetHeader(hdr_td, txv, flags, local_id, buf, buf_len);
481 }
482 
483 static bool GetHttp1HeaderData(DetectEngineThreadCtx *det_ctx, const void *txv, const uint8_t flags,
484  uint32_t local_id, const uint8_t **buf, uint32_t *buf_len)
485 {
486  SCEnter();
487 
488  int kw_thread_id;
489  if (flags & STREAM_TOSERVER) {
490  kw_thread_id = g_request_header_thread_id;
491  } else {
492  kw_thread_id = g_response_header_thread_id;
493  }
495  DetectThreadCtxGetGlobalKeywordThreadCtx(det_ctx, kw_thread_id);
496  if (unlikely(hdr_td == NULL)) {
497  return false;
498  }
499 
500  htp_tx_t *tx = (htp_tx_t *)txv;
501  const htp_headers_t *headers;
502  if (flags & STREAM_TOSERVER) {
503  headers = htp_tx_request_headers(tx);
504  } else {
505  headers = htp_tx_response_headers(tx);
506  }
507  size_t no_of_headers = htp_headers_size(headers);
508  if (local_id == 0) {
509  // We initialize a big buffer on first item
510  // Then, we will just use parts of it
511  hdr_td->len = 0;
512  if (hdr_td->cap < no_of_headers) {
513  void *new_buffer = SCRealloc(hdr_td->items, no_of_headers * sizeof(HttpMultiBufItem));
514  if (unlikely(new_buffer == NULL)) {
515  return NULL;
516  }
517  hdr_td->items = new_buffer;
518  // zeroes the new part of the items
519  memset(hdr_td->items + hdr_td->cap, 0,
520  (no_of_headers - hdr_td->cap) * sizeof(HttpMultiBufItem));
521  hdr_td->cap = no_of_headers;
522  }
523  for (size_t i = 0; i < no_of_headers; i++) {
524  const htp_header_t *h = htp_headers_get_index(headers, i);
525  uint32_t size1 = (uint32_t)htp_header_name_len(h);
526  uint32_t size2 = (uint32_t)htp_header_value_len(h);
527  uint32_t size = size1 + size2 + 2;
528  if (hdr_td->items[i].len < size) {
529  // Use realloc, as this pointer is not freed until HttpMultiBufHeaderThreadDataFree
530  void *tmp = SCRealloc(hdr_td->items[i].buffer, size);
531  if (unlikely(tmp == NULL)) {
532  return NULL;
533  }
534  hdr_td->items[i].buffer = tmp;
535  }
536  memcpy(hdr_td->items[i].buffer, htp_header_name_ptr(h), size1);
537  hdr_td->items[i].buffer[size1] = ':';
538  hdr_td->items[i].buffer[size1 + 1] = ' ';
539  memcpy(hdr_td->items[i].buffer + size1 + 2, htp_header_value_ptr(h), size2);
540  hdr_td->items[i].len = size;
541  }
542  hdr_td->len = no_of_headers;
543  }
544 
545  // cbdata->local_id is the index of the requested header buffer
546  // hdr_td->len is the number of header buffers
547  if (local_id < hdr_td->len) {
548  // we have one valid header buffer
549  *buf = hdr_td->items[local_id].buffer;
550  *buf_len = hdr_td->items[local_id].len;
551  return true;
552  } // else there are no more header buffer to get
553  return false;
554 }
555 
556 static int DetectHTTPRequestHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
557 {
558  if (SCDetectBufferSetActiveList(de_ctx, s, g_http_request_header_buffer_id) < 0)
559  return -1;
560 
562  return -1;
563 
564  return 0;
565 }
566 
568 {
569  sigmatch_table[DETECT_HTTP_REQUEST_HEADER].name = "http.request_header";
571  "sticky buffer to match on only one HTTP header name and value";
572  sigmatch_table[DETECT_HTTP_REQUEST_HEADER].url = "/rules/http-keywords.html#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";
607  sigmatch_table[DETECT_HTTP_RESPONSE_HEADER].url = "/rules/http2-keywords.html#response_header";
608  sigmatch_table[DETECT_HTTP_RESPONSE_HEADER].Setup = DetectHTTPResponseHeaderSetup;
611 
613  HTTP2StateOpen, GetHttp2HeaderData, 2);
615  HTP_RESPONSE_PROGRESS_HEADERS, GetHttp1HeaderData, 2);
616 
617  DetectBufferTypeSetDescriptionByName("http_response_header", "HTTP header name and value");
618  g_http_response_header_buffer_id = DetectBufferTypeGetByName("http_response_header");
619  DetectBufferTypeSupportsMultiInstance("http_response_header");
620  g_response_header_thread_id = DetectRegisterThreadCtxGlobalFuncs("http_response_header",
621  HttpMultiBufHeaderThreadDataInit, NULL, HttpMultiBufHeaderThreadDataFree);
622  g_h2_response_header_thread_id = DetectRegisterThreadCtxGlobalFuncs("http2_response_header",
623  SCHttp2ThreadMultiBufDataInit, NULL, SCHttp2ThreadMultiBufDataFree);
624 }
625 
626 /************************************Unittests*********************************/
627 
628 #ifdef UNITTESTS
630 #endif
631 
632 /**
633  * @}
634  */
SigTableElmt_::url
const char * url
Definition: detect.h:1464
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_INFO_STICKY_BUFFER
#define SIGMATCH_INFO_STICKY_BUFFER
Definition: detect.h:1678
SigTableElmt_::desc
const char * desc
Definition: detect.h:1463
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
SIGMATCH_INFO_CONTENT_MODIFIER
#define SIGMATCH_INFO_CONTENT_MODIFIER
Definition: detect.h:1676
SigTableElmt_::name
const char * name
Definition: detect.h:1461
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1631
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms
Definition: detect.h:390
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1452
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
DetectHttpRequestHeaderRegister
void DetectHttpRequestHeaderRegister(void)
Definition: detect-http-header.c:567
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:1351
ctx
struct Thresholds ctx
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:933
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:763
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:2236
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
InspectionBufferGet
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
Definition: detect-engine-inspect-buffer.c:56
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1443
detect-pcre.h
DetectBufferMpmRegistry_::transforms
DetectEngineTransforms transforms
Definition: detect.h:776
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
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:441
decode.h
DetectBufferMpmRegistry_::pname
char pname[DETECT_PROFILE_NAME_LEN]
Definition: detect.h:765
util-debug.h
AppLayerTxData
Definition: app-layer-parser.h:177
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:19
DetectEngineThreadCtx_
Definition: detect.h:1245
HttpMultiBufHeaderThreadData::items
HttpMultiBufItem * items
Definition: detect-http-header.c:437
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:435
PrefilterGenericMpmRegister
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
Definition: detect-engine-prefilter.c:1577
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1459
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
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:439
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:430
DetectEngineThreadCtx_::mtc
MpmThreadCtx mtc
Definition: detect.h:1347
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:432
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:352
HtpTxUserData_
Definition: app-layer-htp.h:152
SIGMATCH_INFO_MULTI_BUFFER
#define SIGMATCH_INFO_MULTI_BUFFER
Definition: detect.h:1688
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:3849
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:668
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition: app-layer-protos.h:76
InspectionBufferSetupAndApplyTransforms
void InspectionBufferSetupAndApplyTransforms(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
mpm_table
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.c:47
SIGMATCH_NOOPT
#define SIGMATCH_NOOPT
Definition: detect.h:1653
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:431
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:3805
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1450
app-layer.h