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 = SCDetectThreadCtxGetGlobalKeywordThreadCtx(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 
401  /* header is for stream TX type */
403  HTTP2TxTypeStream, HTTP2ProgHeaders, DetectEngineInspectBufferGeneric, GetBuffer2ForTX);
405  PrefilterGenericMpmRegister, GetBuffer2ForTX, ALPROTO_HTTP2, HTTP2TxTypeStream,
406  HTTP2ProgHeaders);
407 
409  HTTP2TxTypeStream, HTTP2ProgHeaders, DetectEngineInspectBufferGeneric, GetBuffer2ForTX);
411  PrefilterGenericMpmRegister, GetBuffer2ForTX, ALPROTO_HTTP2, HTTP2TxTypeStream,
412  HTTP2ProgHeaders);
413 
415  "http headers");
416 
417  g_http_header_buffer_id = DetectBufferTypeGetByName("http_header");
418 
419  g_keyword_thread_id = SCDetectRegisterThreadCtxGlobalFuncs(
420  "http_header", HttpHeaderThreadDataInit, &g_td_config, HttpHeaderThreadDataFree);
421  g_http2_thread_id = SCDetectRegisterThreadCtxGlobalFuncs(
422  "http2.header", SCDetectThreadBufDataInit, NULL, SCDetectThreadBufDataFree);
423 }
424 
425 static int g_http_request_header_buffer_id = 0;
426 static int g_http_response_header_buffer_id = 0;
427 static int g_request_header_thread_id = 0;
428 static int g_response_header_thread_id = 0;
429 static int g_h2_request_header_thread_id = 0;
430 static int g_h2_response_header_thread_id = 0;
431 
432 typedef struct HttpMultiBufItem {
433  uint8_t *buffer;
434  uint32_t len;
436 
438  // array of items, being defined as a buffer with its length just above
440  // capacity of items (size of allocation)
441  size_t cap;
442  // length of items (number in use)
443  size_t len;
445 
446 static void *HttpMultiBufHeaderThreadDataInit(void *data)
447 {
448  HttpMultiBufHeaderThreadData *td = SCCalloc(1, sizeof(*td));
449 
450  /* This return value check to satisfy our Cocci malloc checks. */
451  if (td == NULL) {
452  SCLogError("failed to allocate %" PRIuMAX " bytes: %s", (uintmax_t)sizeof(*td),
453  strerror(errno));
454  return NULL;
455  }
456  return td;
457 }
458 
459 static void HttpMultiBufHeaderThreadDataFree(void *data)
460 {
461  HttpMultiBufHeaderThreadData *td = data;
462  for (size_t i = 0; i < td->cap; i++) {
463  SCFree(td->items[i].buffer);
464  }
465  SCFree(td->items);
466  SCFree(td);
467 }
468 
469 static bool GetHttp2HeaderData(DetectEngineThreadCtx *det_ctx, const void *txv, const uint8_t flags,
470  uint32_t local_id, const uint8_t **buf, uint32_t *buf_len)
471 {
472  int kw_thread_id;
473  if (flags & STREAM_TOSERVER) {
474  kw_thread_id = g_h2_request_header_thread_id;
475  } else {
476  kw_thread_id = g_h2_response_header_thread_id;
477  }
478  void *hdr_td = SCDetectThreadCtxGetGlobalKeywordThreadCtx(det_ctx, kw_thread_id);
479  if (unlikely(hdr_td == NULL)) {
480  return false;
481  }
482  return SCHttp2TxGetHeader(hdr_td, txv, flags, local_id, buf, buf_len);
483 }
484 
485 static bool GetHttp1HeaderData(DetectEngineThreadCtx *det_ctx, const void *txv, const uint8_t flags,
486  uint32_t local_id, const uint8_t **buf, uint32_t *buf_len)
487 {
488  SCEnter();
489 
490  int kw_thread_id;
491  if (flags & STREAM_TOSERVER) {
492  kw_thread_id = g_request_header_thread_id;
493  } else {
494  kw_thread_id = g_response_header_thread_id;
495  }
497  SCDetectThreadCtxGetGlobalKeywordThreadCtx(det_ctx, kw_thread_id);
498  if (unlikely(hdr_td == NULL)) {
499  return false;
500  }
501 
502  htp_tx_t *tx = (htp_tx_t *)txv;
503  const htp_headers_t *headers;
504  if (flags & STREAM_TOSERVER) {
505  headers = htp_tx_request_headers(tx);
506  } else {
507  headers = htp_tx_response_headers(tx);
508  }
509  size_t no_of_headers = htp_headers_size(headers);
510  if (local_id == 0) {
511  // We initialize a big buffer on first item
512  // Then, we will just use parts of it
513  hdr_td->len = 0;
514  if (hdr_td->cap < no_of_headers) {
515  void *new_buffer = SCRealloc(hdr_td->items, no_of_headers * sizeof(HttpMultiBufItem));
516  if (unlikely(new_buffer == NULL)) {
517  return NULL;
518  }
519  hdr_td->items = new_buffer;
520  // zeroes the new part of the items
521  memset(hdr_td->items + hdr_td->cap, 0,
522  (no_of_headers - hdr_td->cap) * sizeof(HttpMultiBufItem));
523  hdr_td->cap = no_of_headers;
524  }
525  for (size_t i = 0; i < no_of_headers; i++) {
526  const htp_header_t *h = htp_headers_get_index(headers, i);
527  uint32_t size1 = (uint32_t)htp_header_name_len(h);
528  uint32_t size2 = (uint32_t)htp_header_value_len(h);
529  uint32_t size = size1 + size2 + 2;
530  if (hdr_td->items[i].len < size) {
531  // Use realloc, as this pointer is not freed until HttpMultiBufHeaderThreadDataFree
532  void *tmp = SCRealloc(hdr_td->items[i].buffer, size);
533  if (unlikely(tmp == NULL)) {
534  return NULL;
535  }
536  hdr_td->items[i].buffer = tmp;
537  }
538  memcpy(hdr_td->items[i].buffer, htp_header_name_ptr(h), size1);
539  hdr_td->items[i].buffer[size1] = ':';
540  hdr_td->items[i].buffer[size1 + 1] = ' ';
541  memcpy(hdr_td->items[i].buffer + size1 + 2, htp_header_value_ptr(h), size2);
542  hdr_td->items[i].len = size;
543  }
544  hdr_td->len = no_of_headers;
545  }
546 
547  // cbdata->local_id is the index of the requested header buffer
548  // hdr_td->len is the number of header buffers
549  if (local_id < hdr_td->len) {
550  // we have one valid header buffer
551  *buf = hdr_td->items[local_id].buffer;
552  *buf_len = hdr_td->items[local_id].len;
553  return true;
554  } // else there are no more header buffer to get
555  return false;
556 }
557 
558 static int DetectHTTPRequestHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
559 {
560  if (SCDetectBufferSetActiveList(de_ctx, s, g_http_request_header_buffer_id) < 0)
561  return -1;
562 
564  return -1;
565 
566  return 0;
567 }
568 
570 {
571  sigmatch_table[DETECT_HTTP_REQUEST_HEADER].name = "http.request_header";
573  "sticky buffer to match on only one HTTP header name and value";
575  "/rules/http-keywords.html#http-request-header";
576  sigmatch_table[DETECT_HTTP_REQUEST_HEADER].Setup = DetectHTTPRequestHeaderSetup;
579 
581  HTTP2TxTypeStream, HTTP2ProgHeaders, GetHttp2HeaderData, 2);
582 
584  HTP_REQUEST_PROGRESS_HEADERS, GetHttp1HeaderData, 2);
585 
586  DetectBufferTypeSetDescriptionByName("http_request_header", "HTTP header name and value");
587  g_http_request_header_buffer_id = DetectBufferTypeGetByName("http_request_header");
588  DetectBufferTypeSupportsMultiInstance("http_request_header");
589  g_request_header_thread_id = SCDetectRegisterThreadCtxGlobalFuncs("http_request_header",
590  HttpMultiBufHeaderThreadDataInit, NULL, HttpMultiBufHeaderThreadDataFree);
591  g_h2_request_header_thread_id = SCDetectRegisterThreadCtxGlobalFuncs("http2_request_header",
592  SCHttp2ThreadMultiBufDataInit, NULL, SCHttp2ThreadMultiBufDataFree);
593 }
594 
595 static int DetectHTTPResponseHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
596 {
597  if (SCDetectBufferSetActiveList(de_ctx, s, g_http_response_header_buffer_id) < 0)
598  return -1;
599 
601  return -1;
602 
603  return 0;
604 }
605 
607 {
608  sigmatch_table[DETECT_HTTP_RESPONSE_HEADER].name = "http.response_header";
610  "sticky buffer to match on only one HTTP header name and value";
612  "/rules/http-keywords.html#http-response-header";
613  sigmatch_table[DETECT_HTTP_RESPONSE_HEADER].Setup = DetectHTTPResponseHeaderSetup;
616 
618  HTTP2TxTypeStream, HTTP2ProgHeaders, GetHttp2HeaderData, 2);
620  HTP_RESPONSE_PROGRESS_HEADERS, GetHttp1HeaderData, 2);
621 
622  DetectBufferTypeSetDescriptionByName("http_response_header", "HTTP header name and value");
623  g_http_response_header_buffer_id = DetectBufferTypeGetByName("http_response_header");
624  DetectBufferTypeSupportsMultiInstance("http_response_header");
625  g_response_header_thread_id = SCDetectRegisterThreadCtxGlobalFuncs("http_response_header",
626  HttpMultiBufHeaderThreadDataInit, NULL, HttpMultiBufHeaderThreadDataFree);
627  g_h2_response_header_thread_id = SCDetectRegisterThreadCtxGlobalFuncs("http2_response_header",
628  SCHttp2ThreadMultiBufDataInit, NULL, SCHttp2ThreadMultiBufDataFree);
629 }
630 
631 /************************************Unittests*********************************/
632 
633 #ifdef UNITTESTS
635 #endif
636 
637 /**
638  * @}
639  */
SigTableElmt_::url
const char * url
Definition: detect.h:1521
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:1520
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:2226
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:1518
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1693
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms
Definition: detect.h:391
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1509
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
DetectHttpRequestHeaderRegister
void DetectHttpRequestHeaderRegister(void)
Definition: detect-http-header.c:569
SCDetectThreadCtxGetGlobalKeywordThreadCtx
void * SCDetectThreadCtxGetGlobalKeywordThreadCtx(DetectEngineThreadCtx *det_ctx, int id)
Retrieve thread local keyword ctx by id.
Definition: detect-engine.c:4057
DetectBufferMpmRegistry_::app_v2
struct DetectBufferMpmRegistry_::@90::@92 app_v2
HttpHeaderBuffer_::len
uint32_t len
Definition: detect-http-header-common.h:30
InspectionBuffer
Definition: detect-engine-inspect-buffer.h:34
threads.h
Flow_
Flow data structure.
Definition: flow.h:354
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1408
ctx
struct Thresholds ctx
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:981
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:100
DetectBufferTypeSupportsMultiInstance
void DetectBufferTypeSupportsMultiInstance(const char *name)
Definition: detect-engine.c:1405
detect-http-header.h
DetectAppLayerMultiRegisterSubState
void DetectAppLayerMultiRegisterSubState(const char *name, AppProto alproto, uint32_t dir, uint8_t sub_state, uint8_t progress, InspectionMultiBufferGetDataPtr GetData, int priority)
Definition: detect-engine.c:2276
DetectBufferMpmRegistry_
one time registration of keywords at start up
Definition: detect.h:777
SCDetectBufferSetActiveList
int SCDetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
Definition: detect-engine-buffer.c:29
p
Packet * p
Definition: fuzz_iprep.c:21
SCDetectSignatureSetAppProto
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:2461
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:82
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1500
detect-pcre.h
DetectBufferMpmRegistry_::transforms
DetectEngineTransforms transforms
Definition: detect.h:790
DetectAppLayerMpmRegisterSubState
void DetectAppLayerMpmRegisterSubState(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionBufferGetDataPtr GetData, AppProto alproto, uint8_t sub_state, uint8_t tx_min_progress)
Definition: detect-engine-mpm.c:167
detect-engine-prefilter.h
DetectAppLayerInspectEngineRegister
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, uint8_t progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
Definition: detect-engine.c:276
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1455
util-memcmp.h
DetectHttpResponseHeaderRegister
void DetectHttpResponseHeaderRegister(void)
Definition: detect-http-header.c:606
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:443
decode.h
DetectBufferMpmRegistry_::pname
char pname[DETECT_PROFILE_NAME_LEN]
Definition: detect.h:779
util-debug.h
AppLayerTxData
Definition: app-layer-parser.h:166
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
DetectEngineThreadCtx_
Definition: detect.h:1300
HttpMultiBufHeaderThreadData::items
HttpMultiBufItem * items
Definition: detect-http-header.c:439
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:159
DETECT_HTTP_REQUEST_HEADER
@ DETECT_HTTP_REQUEST_HEADER
Definition: detect-engine-register.h:214
HttpMultiBufHeaderThreadData
Definition: detect-http-header.c:437
PrefilterGenericMpmRegister
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
Definition: detect-engine-prefilter.c:1674
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1516
app-layer-parser.h
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:108
HttpMultiBufItem
struct HttpMultiBufItem HttpMultiBufItem
AppLayerParserGetStateProgress
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *tx, uint8_t flags)
get the progress value for a tx/protocol
Definition: app-layer-parser.c:1225
HtpTxUserData_::request_has_trailers
uint8_t request_has_trailers
Definition: app-layer-htp.h:158
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:516
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:441
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:432
DetectEngineThreadCtx_::mtc
MpmThreadCtx mtc
Definition: detect.h:1404
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:58
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
DetectAppLayerMultiRegister
void DetectAppLayerMultiRegister(const char *name, AppProto alproto, uint32_t dir, uint8_t progress, InspectionMultiBufferGetDataPtr GetData, int priority)
Definition: detect-engine.c:2288
PrefilterMpmHttpHeaderCtx::list_id
int list_id
Definition: detect-http-header.c:185
HttpMultiBufItem::len
uint32_t len
Definition: detect-http-header.c:434
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:170
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:36
DetectAppLayerMpmRegister
void DetectAppLayerMpmRegister(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionBufferGetDataPtr GetData, AppProto alproto, uint8_t tx_min_progress)
register an app layer keyword for mpm
Definition: detect-engine-mpm.c:159
detect-engine-buffer.h
HttpHeaderBuffer_::size
uint32_t size
Definition: detect-http-header-common.h:29
HtpTxUserData_
Definition: app-layer-htp.h:153
DetectAppLayerInspectEngineRegisterSubState
void DetectAppLayerInspectEngineRegisterSubState(const char *name, AppProto alproto, uint32_t dir, uint8_t sub_state, uint8_t progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
register an app inspection engine for a tx type
Definition: detect-engine.c:299
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:316
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:169
detect-parse.h
Signature_
Signature container.
Definition: detect.h:682
ALPROTO_HTTP
@ ALPROTO_HTTP
Definition: app-layer-protos.h:77
PrefilterAppendTxEngine
int PrefilterAppendTxEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterTxFn PrefilterTxFunc, AppProto alproto, const int8_t tx_min_progress, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
Definition: detect-engine-prefilter.c:412
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
DetectBufferTypeSetDescriptionByName
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
Definition: detect-engine.c:1552
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:215
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCDetectRegisterThreadCtxGlobalFuncs
int SCDetectRegisterThreadCtxGlobalFuncs(const char *name, void *(*InitFunc)(void *), void *data, void(*FreeFunc)(void *))
Register Thread keyword context Funcs (Global)
Definition: detect-engine.c:4013
DetectHttpHeaderRegisterTests
void DetectHttpHeaderRegisterTests(void)
Definition: detect-http-header.c:4769
HttpMultiBufItem::buffer
uint8_t * buffer
Definition: detect-http-header.c:433
HttpHeaderThreadData_
Definition: detect-http-header-common.h:37
HttpHeaderThreadDataFree
void HttpHeaderThreadDataFree(void *data)
Definition: detect-http-header-common.c:75
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1507
app-layer.h