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 
68 #define BUFFER_SIZE_STEP 1024
70 
71 static uint8_t *GetBufferForTX(
72  htp_tx_t *tx, DetectEngineThreadCtx *det_ctx, uint8_t flags, uint32_t *buffer_len)
73 {
74  *buffer_len = 0;
75 
76  HttpHeaderThreadData *hdr_td = NULL;
77  HttpHeaderBuffer *buf = HttpHeaderGetBufferSpace(det_ctx, flags, g_keyword_thread_id, &hdr_td);
78  if (unlikely(buf == NULL)) {
79  return NULL;
80  }
81 
82  const htp_headers_t *headers;
83  if (flags & STREAM_TOSERVER) {
84  if (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP1, tx, flags) <=
85  HTP_REQUEST_PROGRESS_HEADERS)
86  return NULL;
87  headers = htp_tx_request_headers(tx);
88  } else {
89  if (AppLayerParserGetStateProgress(IPPROTO_TCP, ALPROTO_HTTP1, tx, flags) <=
90  HTP_RESPONSE_PROGRESS_HEADERS)
91  return NULL;
92  headers = htp_tx_response_headers(tx);
93  }
94  if (headers == NULL)
95  return NULL;
96 
97  size_t i = 0;
98  size_t no_of_headers = htp_headers_size(headers);
99  for (; i < no_of_headers; i++) {
100  const htp_header_t *h = htp_headers_get_index(headers, i);
101  size_t size1 = htp_header_name_len(h);
102  size_t size2 = htp_header_value_len(h);
103 
104  if (flags & STREAM_TOSERVER) {
105  if (size1 == 6 && SCMemcmpLowercase("cookie", htp_header_name_ptr(h), 6) == 0) {
106  continue;
107  }
108  } else {
109  if (size1 == 10 && SCMemcmpLowercase("set-cookie", htp_header_name_ptr(h), 10) == 0) {
110  continue;
111  }
112  }
113 
114  size_t size = size1 + size2 + 4;
115 #if 0
116  if (i + 1 == no_of_headers)
117  size += 2;
118 #endif
119  if (size + buf->len > buf->size) {
120  if (HttpHeaderExpandBuffer(hdr_td, buf, size) != 0) {
121  return NULL;
122  }
123  }
124 
125  memcpy(buf->buffer + buf->len, htp_header_name_ptr(h), htp_header_name_len(h));
126  buf->len += htp_header_name_len(h);
127  buf->buffer[buf->len++] = ':';
128  buf->buffer[buf->len++] = ' ';
129  memcpy(buf->buffer + buf->len, htp_header_value_ptr(h), htp_header_value_len(h));
130  buf->len += htp_header_value_len(h);
131  buf->buffer[buf->len++] = '\r';
132  buf->buffer[buf->len++] = '\n';
133 #if 0 // looks like this breaks existing rules
134  if (i + 1 == no_of_headers) {
135  buf->buffer[buf->len++] = '\r';
136  buf->buffer[buf->len++] = '\n';
137  }
138 #endif
139  }
140 
141  *buffer_len = buf->len;
142  return buf->buffer;
143 }
144 
145 static InspectionBuffer *GetBuffer2ForTX(DetectEngineThreadCtx *det_ctx,
146  const DetectEngineTransforms *transforms, Flow *_f, const uint8_t flow_flags, void *txv,
147  const int list_id)
148 {
149  InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
150  if (buffer->inspect == NULL) {
151  uint32_t b_len = 0;
152  const uint8_t *b = NULL;
153 
154  if (SCHttp2TxGetHeaders(txv, flow_flags, &b, &b_len) != 1)
155  return NULL;
156  if (b == NULL || b_len == 0)
157  return NULL;
158 
159  InspectionBufferSetupAndApplyTransforms(det_ctx, list_id, buffer, b, b_len, transforms);
160  }
161 
162  return buffer;
163 }
164 
165 static InspectionBuffer *GetData1(DetectEngineThreadCtx *det_ctx,
166  const DetectEngineTransforms *transforms, Flow *_f, const uint8_t flags, void *txv,
167  const int list_id)
168 {
169  InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
170  if (buffer->inspect == NULL) {
171  uint32_t data_len = 0;
172  uint8_t *data = GetBufferForTX(txv, det_ctx, flags, &data_len);
174  det_ctx, list_id, buffer, data, data_len, transforms);
175  }
176 
177  return buffer;
178 }
179 
181  int list_id;
182  const MpmCtx *mpm_ctx;
185 
186 /** \brief Generic Mpm prefilter callback
187  *
188  * \param det_ctx detection engine thread ctx
189  * \param p packet to inspect
190  * \param f flow to inspect
191  * \param txv tx to inspect
192  * \param pectx inspection context
193  */
194 static void PrefilterMpmHttpHeader(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p,
195  Flow *f, void *txv, const uint64_t idx, const AppLayerTxData *_txd, const uint8_t flags)
196 {
197  SCEnter();
198 
199  const PrefilterMpmHttpHeaderCtx *ctx = pectx;
200  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
201  SCLogDebug("running on list %d", ctx->list_id);
202 
203  const int list_id = ctx->list_id;
204  InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
205  if (buffer->inspect == NULL) {
206  uint32_t rawdata_len = 0;
207  uint8_t *rawdata = GetBufferForTX(txv, det_ctx, flags, &rawdata_len);
208  if (rawdata_len == 0)
209  return;
210 
211  /* setup buffer and apply transforms */
213  det_ctx, list_id, buffer, rawdata, rawdata_len, ctx->transforms);
214  }
215 
216  const uint32_t data_len = buffer->inspect_len;
217  const uint8_t *data = buffer->inspect;
218 
219  SCLogDebug("mpm'ing buffer:");
220  //PrintRawDataFp(stdout, data, data_len);
221 
222  if (data != NULL && data_len >= mpm_ctx->minlen) {
223  (void)mpm_table[mpm_ctx->mpm_type].Search(
224  mpm_ctx, &det_ctx->mtc, &det_ctx->pmq, data, data_len);
225  PREFILTER_PROFILING_ADD_BYTES(det_ctx, data_len);
226  }
227 }
228 
229 static void PrefilterMpmHttpTrailer(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p,
230  Flow *f, void *txv, const uint64_t idx, const AppLayerTxData *_txd, const uint8_t flags)
231 {
232  SCEnter();
233 
234  htp_tx_t *tx = txv;
235  const HtpTxUserData *htud = (const HtpTxUserData *)htp_tx_get_user_data(tx);
236  /* if the request wasn't flagged as having a trailer, we skip */
237  if (((flags & STREAM_TOSERVER) && !htud->request_has_trailers) ||
238  ((flags & STREAM_TOCLIENT) && !htud->response_has_trailers)) {
239  SCReturn;
240  }
241  PrefilterMpmHttpHeader(det_ctx, pectx, p, f, txv, idx, _txd, flags);
242  SCReturn;
243 }
244 
245 static void PrefilterMpmHttpHeaderFree(void *ptr)
246 {
247  SCFree(ptr);
248 }
249 
250 static int PrefilterMpmHttpHeaderRequestRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh,
251  MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
252 {
253  SCEnter();
254 
255  /* header */
256  PrefilterMpmHttpHeaderCtx *pectx = SCCalloc(1, sizeof(*pectx));
257  if (pectx == NULL)
258  return -1;
259  pectx->list_id = list_id;
260  pectx->mpm_ctx = mpm_ctx;
261  pectx->transforms = &mpm_reg->transforms;
262 
263  int r = PrefilterAppendTxEngine(de_ctx, sgh, PrefilterMpmHttpHeader, mpm_reg->app_v2.alproto,
264  HTP_REQUEST_PROGRESS_HEADERS, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->pname);
265  if (r != 0) {
266  SCFree(pectx);
267  return r;
268  }
269 
270  /* trailer */
271  pectx = SCCalloc(1, sizeof(*pectx));
272  if (pectx == NULL)
273  return -1;
274  pectx->list_id = list_id;
275  pectx->mpm_ctx = mpm_ctx;
276  pectx->transforms = &mpm_reg->transforms;
277 
278  r = PrefilterAppendTxEngine(de_ctx, sgh, PrefilterMpmHttpTrailer, mpm_reg->app_v2.alproto,
279  HTP_REQUEST_PROGRESS_TRAILER, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->pname);
280  if (r != 0) {
281  SCFree(pectx);
282  }
283  return r;
284 }
285 
286 static int PrefilterMpmHttpHeaderResponseRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh,
287  MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
288 {
289  SCEnter();
290 
291  /* header */
292  PrefilterMpmHttpHeaderCtx *pectx = SCCalloc(1, sizeof(*pectx));
293  if (pectx == NULL)
294  return -1;
295  pectx->list_id = list_id;
296  pectx->mpm_ctx = mpm_ctx;
297  pectx->transforms = &mpm_reg->transforms;
298 
299  int r = PrefilterAppendTxEngine(de_ctx, sgh, PrefilterMpmHttpHeader, mpm_reg->app_v2.alproto,
300  HTP_RESPONSE_PROGRESS_HEADERS, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->pname);
301  if (r != 0) {
302  SCFree(pectx);
303  return r;
304  }
305 
306  /* trailer */
307  pectx = SCCalloc(1, sizeof(*pectx));
308  if (pectx == NULL)
309  return -1;
310  pectx->list_id = list_id;
311  pectx->mpm_ctx = mpm_ctx;
312  pectx->transforms = &mpm_reg->transforms;
313 
314  r = PrefilterAppendTxEngine(de_ctx, sgh, PrefilterMpmHttpTrailer, mpm_reg->app_v2.alproto,
315  HTP_RESPONSE_PROGRESS_TRAILER, pectx, PrefilterMpmHttpHeaderFree, mpm_reg->pname);
316  if (r != 0) {
317  SCFree(pectx);
318  }
319  return r;
320 }
321 
322 /**
323  * \brief The setup function for the http_header keyword for a signature.
324  *
325  * \param de_ctx Pointer to the detection engine context.
326  * \param s Pointer to signature for the current Signature being parsed
327  * from the rules.
328  * \param m Pointer to the head of the SigMatchs for the current rule
329  * being parsed.
330  * \param arg Pointer to the string holding the keyword value.
331  *
332  * \retval 0 On success.
333  * \retval -1 On failure.
334  */
335 static int DetectHttpHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
336 {
338  de_ctx, s, arg, DETECT_HTTP_HEADER_CM, g_http_header_buffer_id, ALPROTO_HTTP1);
339 }
340 
341 /**
342  * \brief this function setup the http.header keyword used in the rule
343  *
344  * \param de_ctx Pointer to the Detection Engine Context
345  * \param s Pointer to the Signature to which the current keyword belongs
346  * \param str Should hold an empty string always
347  *
348  * \retval 0 On success
349  */
350 static int DetectHttpHeaderSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str)
351 {
352  if (SCDetectBufferSetActiveList(de_ctx, s, g_http_header_buffer_id) < 0)
353  return -1;
355  return -1;
356  return 0;
357 }
358 
359 /**
360  * \brief Registers the keyword handlers for the "http_header" keyword.
361  */
363 {
364  /* http_header content modifier */
365  sigmatch_table[DETECT_HTTP_HEADER_CM].name = "http_header";
367  "content modifier to match only on the HTTP header-buffer";
369  "/rules/http-keywords.html#http-header-and-http-raw-header";
370  sigmatch_table[DETECT_HTTP_HEADER_CM].Setup = DetectHttpHeaderSetup;
371 #ifdef UNITTESTS
373 #endif
377 
378  /* http.header sticky buffer */
379  sigmatch_table[DETECT_HTTP_HEADER].name = "http.header";
380  sigmatch_table[DETECT_HTTP_HEADER].desc = "sticky buffer to match on the normalized HTTP header-buffer";
381  sigmatch_table[DETECT_HTTP_HEADER].url = "/rules/http-keywords.html#http-header-and-http-raw-header";
382  sigmatch_table[DETECT_HTTP_HEADER].Setup = DetectHttpHeaderSetupSticky;
385 
387  HTP_REQUEST_PROGRESS_HEADERS, DetectEngineInspectBufferGeneric, GetData1);
389  PrefilterMpmHttpHeaderRequestRegister, NULL, ALPROTO_HTTP1,
390  0); /* not used, registered twice: HEADERS/TRAILER */
391 
393  HTP_RESPONSE_PROGRESS_HEADERS, DetectEngineInspectBufferGeneric, GetData1);
395  PrefilterMpmHttpHeaderResponseRegister, NULL, ALPROTO_HTTP1,
396  0); /* not used, registered twice: HEADERS/TRAILER */
397 
399  HTTP2StateDataClient, DetectEngineInspectBufferGeneric, GetBuffer2ForTX);
401  GetBuffer2ForTX, ALPROTO_HTTP2, HTTP2StateDataClient);
402 
404  HTTP2StateDataServer, DetectEngineInspectBufferGeneric, GetBuffer2ForTX);
406  GetBuffer2ForTX, ALPROTO_HTTP2, HTTP2StateDataServer);
407 
409  "http headers");
410 
411  g_http_header_buffer_id = DetectBufferTypeGetByName("http_header");
412 
413  g_keyword_thread_id = DetectRegisterThreadCtxGlobalFuncs("http_header",
415 }
416 
417 static int g_http_request_header_buffer_id = 0;
418 static int g_http_response_header_buffer_id = 0;
419 static int g_request_header_thread_id = 0;
420 static int g_response_header_thread_id = 0;
421 
422 typedef struct HttpMultiBufItem {
423  uint8_t *buffer;
424  uint32_t len;
426 
428  // array of items, being defined as a buffer with its length just above
430  // capacity of items (size of allocation)
431  size_t cap;
432  // length of items (number in use)
433  size_t len;
435 
436 static void *HttpMultiBufHeaderThreadDataInit(void *data)
437 {
438  HttpMultiBufHeaderThreadData *td = SCCalloc(1, sizeof(*td));
439 
440  /* This return value check to satisfy our Cocci malloc checks. */
441  if (td == NULL) {
442  SCLogError("failed to allocate %" PRIuMAX " bytes: %s", (uintmax_t)sizeof(*td),
443  strerror(errno));
444  return NULL;
445  }
446  return td;
447 }
448 
449 static void HttpMultiBufHeaderThreadDataFree(void *data)
450 {
451  HttpMultiBufHeaderThreadData *td = data;
452  for (size_t i = 0; i < td->cap; i++) {
453  SCFree(td->items[i].buffer);
454  }
455  SCFree(td->items);
456  SCFree(td);
457 }
458 
459 static bool GetHttp1HeaderData(DetectEngineThreadCtx *det_ctx, const void *txv, const uint8_t flags,
460  uint32_t local_id, const uint8_t **buf, uint32_t *buf_len)
461 {
462  SCEnter();
463 
464  int kw_thread_id;
465  if (flags & STREAM_TOSERVER) {
466  kw_thread_id = g_request_header_thread_id;
467  } else {
468  kw_thread_id = g_response_header_thread_id;
469  }
471  DetectThreadCtxGetGlobalKeywordThreadCtx(det_ctx, kw_thread_id);
472  if (unlikely(hdr_td == NULL)) {
473  return false;
474  }
475 
476  htp_tx_t *tx = (htp_tx_t *)txv;
477  const htp_headers_t *headers;
478  if (flags & STREAM_TOSERVER) {
479  headers = htp_tx_request_headers(tx);
480  } else {
481  headers = htp_tx_response_headers(tx);
482  }
483  size_t no_of_headers = htp_headers_size(headers);
484  if (local_id == 0) {
485  // We initialize a big buffer on first item
486  // Then, we will just use parts of it
487  hdr_td->len = 0;
488  if (hdr_td->cap < no_of_headers) {
489  void *new_buffer = SCRealloc(hdr_td->items, no_of_headers * sizeof(HttpMultiBufItem));
490  if (unlikely(new_buffer == NULL)) {
491  return NULL;
492  }
493  hdr_td->items = new_buffer;
494  // zeroes the new part of the items
495  memset(hdr_td->items + hdr_td->cap, 0,
496  (no_of_headers - hdr_td->cap) * sizeof(HttpMultiBufItem));
497  hdr_td->cap = no_of_headers;
498  }
499  for (size_t i = 0; i < no_of_headers; i++) {
500  const htp_header_t *h = htp_headers_get_index(headers, i);
501  uint32_t size1 = (uint32_t)htp_header_name_len(h);
502  uint32_t size2 = (uint32_t)htp_header_value_len(h);
503  uint32_t size = size1 + size2 + 2;
504  if (hdr_td->items[i].len < size) {
505  // Use realloc, as this pointer is not freed until HttpMultiBufHeaderThreadDataFree
506  void *tmp = SCRealloc(hdr_td->items[i].buffer, size);
507  if (unlikely(tmp == NULL)) {
508  return NULL;
509  }
510  hdr_td->items[i].buffer = tmp;
511  }
512  memcpy(hdr_td->items[i].buffer, htp_header_name_ptr(h), size1);
513  hdr_td->items[i].buffer[size1] = ':';
514  hdr_td->items[i].buffer[size1 + 1] = ' ';
515  memcpy(hdr_td->items[i].buffer + size1 + 2, htp_header_value_ptr(h), size2);
516  hdr_td->items[i].len = size;
517  }
518  hdr_td->len = no_of_headers;
519  }
520 
521  // cbdata->local_id is the index of the requested header buffer
522  // hdr_td->len is the number of header buffers
523  if (local_id < hdr_td->len) {
524  // we have one valid header buffer
525  *buf = hdr_td->items[local_id].buffer;
526  *buf_len = hdr_td->items[local_id].len;
527  return true;
528  } // else there are no more header buffer to get
529  return false;
530 }
531 
532 static int DetectHTTPRequestHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
533 {
534  if (SCDetectBufferSetActiveList(de_ctx, s, g_http_request_header_buffer_id) < 0)
535  return -1;
536 
538  return -1;
539 
540  return 0;
541 }
542 
544 {
545  sigmatch_table[DETECT_HTTP_REQUEST_HEADER].name = "http.request_header";
547  "sticky buffer to match on only one HTTP header name and value";
548  sigmatch_table[DETECT_HTTP_REQUEST_HEADER].url = "/rules/http-keywords.html#request_header";
549  sigmatch_table[DETECT_HTTP_REQUEST_HEADER].Setup = DetectHTTPRequestHeaderSetup;
552 
554  HTTP2StateOpen, SCHttp2TxGetHeader, 2);
556  HTP_REQUEST_PROGRESS_HEADERS, GetHttp1HeaderData, 2);
557 
558  DetectBufferTypeSetDescriptionByName("http_request_header", "HTTP header name and value");
559  g_http_request_header_buffer_id = DetectBufferTypeGetByName("http_request_header");
560  DetectBufferTypeSupportsMultiInstance("http_request_header");
561  g_request_header_thread_id = DetectRegisterThreadCtxGlobalFuncs("http_request_header",
562  HttpMultiBufHeaderThreadDataInit, NULL, HttpMultiBufHeaderThreadDataFree);
563 }
564 
565 static int DetectHTTPResponseHeaderSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
566 {
567  if (SCDetectBufferSetActiveList(de_ctx, s, g_http_response_header_buffer_id) < 0)
568  return -1;
569 
571  return -1;
572 
573  return 0;
574 }
575 
577 {
578  sigmatch_table[DETECT_HTTP_RESPONSE_HEADER].name = "http.response_header";
580  "sticky buffer to match on only one HTTP header name and value";
581  sigmatch_table[DETECT_HTTP_RESPONSE_HEADER].url = "/rules/http2-keywords.html#response_header";
582  sigmatch_table[DETECT_HTTP_RESPONSE_HEADER].Setup = DetectHTTPResponseHeaderSetup;
585 
587  HTTP2StateOpen, SCHttp2TxGetHeader, 2);
589  HTP_RESPONSE_PROGRESS_HEADERS, GetHttp1HeaderData, 2);
590 
591  DetectBufferTypeSetDescriptionByName("http_response_header", "HTTP header name and value");
592  g_http_response_header_buffer_id = DetectBufferTypeGetByName("http_response_header");
593  DetectBufferTypeSupportsMultiInstance("http_response_header");
594  g_response_header_thread_id = DetectRegisterThreadCtxGlobalFuncs("http_response_header",
595  HttpMultiBufHeaderThreadDataInit, NULL, HttpMultiBufHeaderThreadDataFree);
596 }
597 
598 /************************************Unittests*********************************/
599 
600 #ifdef UNITTESTS
602 #endif
603 
604 /**
605  * @}
606  */
SigTableElmt_::url
const char * url
Definition: detect.h:1461
BUFFER_SIZE_STEP
#define BUFFER_SIZE_STEP
Definition: detect-http-header.c:68
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:1675
SigTableElmt_::desc
const char * desc
Definition: detect.h:1460
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:1673
SigTableElmt_::name
const char * name
Definition: detect.h:1458
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1628
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectEngineTransforms
Definition: detect.h:390
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1449
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
DetectHttpRequestHeaderRegister
void DetectHttpRequestHeaderRegister(void)
Definition: detect-http-header.c:543
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:1093
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:1348
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:2235
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:1440
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:576
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:433
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:429
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:206
HttpMultiBufHeaderThreadData
Definition: detect-http-header.c:427
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:1456
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:501
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:431
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:422
DetectEngineThreadCtx_::mtc
MpmThreadCtx mtc
Definition: detect.h:1344
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:181
HttpMultiBufItem::len
uint32_t len
Definition: detect-http-header.c:424
PrefilterMpmHttpHeaderCtx
Definition: detect-http-header.c:180
DetectHttpHeaderRegister
void DetectHttpHeaderRegister(void)
Registers the keyword handlers for the "http_header" keyword.
Definition: detect-http-header.c:362
suricata-common.h
DETECT_HTTP_HEADER
@ DETECT_HTTP_HEADER
Definition: detect-engine-register.h:162
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:1685
util-validate.h
PrefilterMpmHttpHeaderCtx::transforms
const DetectEngineTransforms * transforms
Definition: detect-http-header.c:183
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:182
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:3843
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:161
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:1650
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:207
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:423
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:3799
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1447
app-layer.h