suricata
detect-hostbits.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  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  *
23  * Implements the hostbits keyword
24  */
25 
26 #include "suricata-common.h"
27 #include "decode.h"
28 #include "action-globals.h"
29 #include "detect.h"
30 #include "threads.h"
31 #include "flow.h"
32 #include "flow-util.h"
33 #include "detect-hostbits.h"
34 #include "util-spm.h"
35 
36 #include "detect-engine-sigorder.h"
37 
38 #include "app-layer-parser.h"
39 
40 #include "detect-parse.h"
41 #include "detect-engine.h"
42 #include "detect-engine-mpm.h"
43 #include "detect-engine-state.h"
44 #include "detect-engine-build.h"
45 
46 #include "flow-bit.h"
47 #include "host-bit.h"
48 #include "util-var-name.h"
49 #include "util-debug.h"
50 
51 /*
52  hostbits:isset,bitname;
53  hostbits:set,bitname;
54 
55  hostbits:set,bitname,src;
56  hostbits:set,bitname,dst;
57 TODO:
58  hostbits:set,bitname,both;
59 
60  hostbits:set,bitname,src,3600;
61  hostbits:set,bitname,dst,60;
62  hostbits:set,bitname,both,120;
63  */
64 
65 #define PARSE_REGEX \
66  "^([a-z]+)" /* Action */ \
67  "(?:\\s*,\\s*([^\\s,]+))?(?:\\s*)?" /* Name. */ \
68  "(?:\\s*,\\s*([^,\\s]+))?(?:\\s*)?" /* Direction. */ \
69  "(.+)?" /* Any remaining data. */
70 static DetectParseRegex parse_regex;
71 
72 static int DetectHostbitMatch (DetectEngineThreadCtx *, Packet *,
73  const Signature *, const SigMatchCtx *);
74 static int DetectHostbitSetup (DetectEngineCtx *, Signature *, const char *);
75 void DetectHostbitFree (DetectEngineCtx *, void *);
76 #ifdef UNITTESTS
77 void HostBitsRegisterTests(void);
78 #endif
79 
81 {
82  sigmatch_table[DETECT_HOSTBITS].name = "hostbits";
83  sigmatch_table[DETECT_HOSTBITS].desc = "operate on host flag";
84 // sigmatch_table[DETECT_HOSTBITS].url = "/rules/flow-keywords.html#flowbits";
85  sigmatch_table[DETECT_HOSTBITS].Match = DetectHostbitMatch;
86  sigmatch_table[DETECT_HOSTBITS].Setup = DetectHostbitSetup;
88 #ifdef UNITTESTS
90 #endif
91  /* this is compatible to ip-only signatures */
93 
94  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
95 }
96 
97 static int DetectHostbitMatchToggle (Packet *p, const DetectXbitsData *fd)
98 {
99  switch (fd->tracker) {
101  if (p->host_src == NULL) {
103  if (p->host_src == NULL)
104  return 0;
105  }
106  else
107  HostLock(p->host_src);
108 
111  break;
113  if (p->host_dst == NULL) {
115  if (p->host_dst == NULL)
116  return 0;
117  }
118  else
119  HostLock(p->host_dst);
120 
123  break;
124  }
125  return 1;
126 }
127 
128 /* return true even if bit not found */
129 static int DetectHostbitMatchUnset (Packet *p, const DetectXbitsData *fd)
130 {
131  switch (fd->tracker) {
133  if (p->host_src == NULL) {
135  if (p->host_src == NULL)
136  return 1;
137  } else
138  HostLock(p->host_src);
139 
140  HostBitUnset(p->host_src,fd->idx);
142  break;
144  if (p->host_dst == NULL) {
146  if (p->host_dst == NULL)
147  return 1;
148  } else
149  HostLock(p->host_dst);
150 
151  HostBitUnset(p->host_dst,fd->idx);
153  break;
154  }
155  return 1;
156 }
157 
158 static int DetectHostbitMatchSet (Packet *p, const DetectXbitsData *fd)
159 {
160  switch (fd->tracker) {
162  if (p->host_src == NULL) {
164  if (p->host_src == NULL)
165  return 0;
166  } else
167  HostLock(p->host_src);
168 
171  break;
173  if (p->host_dst == NULL) {
175  if (p->host_dst == NULL)
176  return 0;
177  } else
178  HostLock(p->host_dst);
179 
182  break;
183  }
184  return 1;
185 }
186 
187 static int DetectHostbitMatchIsset (Packet *p, const DetectXbitsData *fd)
188 {
189  int r = 0;
190  switch (fd->tracker) {
192  if (p->host_src == NULL) {
194  if (p->host_src == NULL)
195  return 0;
196  } else
197  HostLock(p->host_src);
198 
199  r = HostBitIsset(p->host_src, fd->idx, p->ts);
201  return r;
203  if (p->host_dst == NULL) {
205  if (p->host_dst == NULL)
206  return 0;
207  } else
208  HostLock(p->host_dst);
209 
210  r = HostBitIsset(p->host_dst, fd->idx, p->ts);
212  return r;
213  }
214  return 0;
215 }
216 
217 static int DetectHostbitMatchIsnotset (Packet *p, const DetectXbitsData *fd)
218 {
219  int r = 0;
220  switch (fd->tracker) {
222  if (p->host_src == NULL) {
224  if (p->host_src == NULL)
225  return 1;
226  } else
227  HostLock(p->host_src);
228 
229  r = HostBitIsnotset(p->host_src, fd->idx, p->ts);
231  return r;
233  if (p->host_dst == NULL) {
235  if (p->host_dst == NULL)
236  return 1;
237  } else
238  HostLock(p->host_dst);
239 
240  r = HostBitIsnotset(p->host_dst, fd->idx, p->ts);
242  return r;
243  }
244  return 0;
245 }
246 
248 {
249  switch (xd->cmd) {
251  return DetectHostbitMatchIsset(p,xd);
253  return DetectHostbitMatchIsnotset(p,xd);
255  return DetectHostbitMatchSet(p,xd);
257  return DetectHostbitMatchUnset(p,xd);
259  return DetectHostbitMatchToggle(p,xd);
260  default:
261  SCLogError("unknown cmd %" PRIu32 "", xd->cmd);
262  return 0;
263  }
264 
265  return 0;
266 }
267 
268 /*
269  * returns 0: no match
270  * 1: match
271  * -1: error
272  */
273 
274 static int DetectHostbitMatch (DetectEngineThreadCtx *det_ctx, Packet *p,
275  const Signature *s, const SigMatchCtx *ctx)
276 {
277  const DetectXbitsData *xd = (const DetectXbitsData *)ctx;
278  if (xd == NULL)
279  return 0;
280 
281  return DetectXbitMatchHost(p, xd);
282 }
283 
284 static int DetectHostbitParse(const char *str, char *cmd, int cmd_len,
285  char *name, int name_len, char *dir, int dir_len)
286 {
287  int rc;
288  size_t pcre2len;
289 
290  pcre2_match_data *match = NULL;
291  int count = DetectParsePcreExec(&parse_regex, &match, str, 0, 0);
292  if (count != 2 && count != 3 && count != 4) {
293  SCLogError("\"%s\" is not a valid setting for hostbits.", str);
294  goto error;
295  }
296 
297  pcre2len = cmd_len;
298  rc = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)cmd, &pcre2len);
299  if (rc < 0) {
300  SCLogError("pcre2_substring_copy_bynumber failed");
301  goto error;
302  }
303 
304  if (count >= 3) {
305  pcre2len = name_len;
306  rc = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)name, &pcre2len);
307  if (rc < 0) {
308  SCLogError("pcre2_substring_copy_bynumber failed");
309  goto error;
310  }
311  if (count >= 4) {
312  pcre2len = dir_len;
313  rc = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)dir, &pcre2len);
314  if (rc < 0) {
315  SCLogError("pcre2_substring_copy_bynumber failed");
316  goto error;
317  }
318  }
319  }
320 
321  pcre2_match_data_free(match);
322  return 1;
323 
324 error:
325  if (match) {
326  pcre2_match_data_free(match);
327  }
328  return 0;
329 }
330 
331 int DetectHostbitSetup (DetectEngineCtx *de_ctx, Signature *s, const char *rawstr)
332 {
333  DetectXbitsData *cd = NULL;
334  uint8_t fb_cmd = 0;
335  uint8_t hb_dir = 0;
336  char fb_cmd_str[16] = "", fb_name[256] = "";
337  char hb_dir_str[16] = "";
338 
339  if (!DetectHostbitParse(rawstr, fb_cmd_str, sizeof(fb_cmd_str),
340  fb_name, sizeof(fb_name), hb_dir_str, sizeof(hb_dir_str))) {
341  return -1;
342  }
343 
344  if (strlen(hb_dir_str) > 0) {
345  if (strcmp(hb_dir_str, "src") == 0)
346  hb_dir = DETECT_XBITS_TRACK_IPSRC;
347  else if (strcmp(hb_dir_str, "dst") == 0)
348  hb_dir = DETECT_XBITS_TRACK_IPDST;
349  else if (strcmp(hb_dir_str, "both") == 0) {
350  //hb_dir = DETECT_XBITS_TRACK_IPBOTH;
351  SCLogError("'both' not implemented");
352  goto error;
353  } else {
354  // TODO
355  goto error;
356  }
357  }
358 
359  if (strcmp(fb_cmd_str,"noalert") == 0) {
360  fb_cmd = DETECT_XBITS_CMD_NOALERT;
361  } else if (strcmp(fb_cmd_str,"isset") == 0) {
362  fb_cmd = DETECT_XBITS_CMD_ISSET;
363  } else if (strcmp(fb_cmd_str,"isnotset") == 0) {
364  fb_cmd = DETECT_XBITS_CMD_ISNOTSET;
365  } else if (strcmp(fb_cmd_str,"set") == 0) {
366  fb_cmd = DETECT_XBITS_CMD_SET;
367  } else if (strcmp(fb_cmd_str,"unset") == 0) {
368  fb_cmd = DETECT_XBITS_CMD_UNSET;
369  } else if (strcmp(fb_cmd_str,"toggle") == 0) {
370  fb_cmd = DETECT_XBITS_CMD_TOGGLE;
371  } else {
372  SCLogError("ERROR: flowbits action \"%s\" is not supported.", fb_cmd_str);
373  goto error;
374  }
375 
376  switch (fb_cmd) {
378  if (strlen(fb_name) != 0)
379  goto error;
380  s->action &= ~ACTION_ALERT;
381  return 0;
387  default:
388  if (strlen(fb_name) == 0)
389  goto error;
390  break;
391  }
392 
393  cd = SCMalloc(sizeof(DetectXbitsData));
394  if (unlikely(cd == NULL))
395  goto error;
396 
397  uint32_t varname_id = VarNameStoreRegister(fb_name, VAR_TYPE_HOST_BIT);
398  if (unlikely(varname_id == 0))
399  goto error;
400  cd->idx = varname_id;
401  cd->cmd = fb_cmd;
402  cd->tracker = hb_dir;
403  cd->type = VAR_TYPE_HOST_BIT;
404  cd->expire = 300;
405 
406  SCLogDebug("idx %" PRIu32 ", cmd %s, name %s",
407  cd->idx, fb_cmd_str, strlen(fb_name) ? fb_name : "(none)");
408 
409  /* Okay so far so good, lets get this into a SigMatch
410  * and put it in the Signature. */
411 
412  switch (fb_cmd) {
413  /* case DETECT_XBITS_CMD_NOALERT can't happen here */
414 
417  /* checks, so packet list */
419  DETECT_SM_LIST_MATCH) == NULL) {
420  goto error;
421  }
422  break;
423 
427  /* modifiers, only run when entire sig has matched */
429  DETECT_SM_LIST_POSTMATCH) == NULL) {
430  goto error;
431  }
432  break;
433 
434  // suppress coverity warning as scan-build-7 warns w/o this.
435  // coverity[deadcode : FALSE]
436  default:
437  goto error;
438  }
439 
440  return 0;
441 
442 error:
443  if (cd != NULL)
444  SCFree(cd);
445  return -1;
446 }
447 
449 {
450  DetectXbitsData *fd = (DetectXbitsData *)ptr;
451 
452  if (fd == NULL)
453  return;
455 
456  SCFree(fd);
457 }
458 
459 #ifdef UNITTESTS
460 
461 static void HostBitsTestSetup(void)
462 {
464  SCStorageInit();
465  HostBitInitCtx();
467  HostInitConfig(true);
468 }
469 
470 static void HostBitsTestShutdown(void)
471 {
472  HostShutdown();
474 }
475 
476 static int HostBitsTestParse01(void)
477 {
478  char cmd[16] = "", name[256] = "", dir[16] = "";
479 
480  /* No direction. */
481  FAIL_IF(!DetectHostbitParse("isset,name", cmd, sizeof(cmd), name,
482  sizeof(name), dir, sizeof(dir)));
483  FAIL_IF(strcmp(cmd, "isset") != 0);
484  FAIL_IF(strcmp(name, "name") != 0);
485  FAIL_IF(strlen(dir));
486 
487  /* No direction, leading space. */
488  *cmd = '\0';
489  *name = '\0';
490  *dir = '\0';
491  FAIL_IF(!DetectHostbitParse("isset, name", cmd, sizeof(cmd), name,
492  sizeof(name), dir, sizeof(dir)));
493  FAIL_IF(strcmp(cmd, "isset") != 0);
494  FAIL_IF(strcmp(name, "name") != 0);
495 
496  /* No direction, trailing space. */
497  *cmd = '\0';
498  *name = '\0';
499  *dir = '\0';
500  FAIL_IF(!DetectHostbitParse("isset,name ", cmd, sizeof(cmd), name,
501  sizeof(name), dir, sizeof(dir)));
502  FAIL_IF(strcmp(cmd, "isset") != 0);
503  FAIL_IF(strcmp(name, "name") != 0);
504 
505  /* No direction, leading and trailing space. */
506  *cmd = '\0';
507  *name = '\0';
508  *dir = '\0';
509  FAIL_IF(!DetectHostbitParse("isset, name ", cmd, sizeof(cmd), name,
510  sizeof(name), dir, sizeof(dir)));
511  FAIL_IF(strcmp(cmd, "isset") != 0);
512  FAIL_IF(strcmp(name, "name") != 0);
513 
514  /* With direction. */
515  *cmd = '\0';
516  *name = '\0';
517  *dir = '\0';
518  FAIL_IF(!DetectHostbitParse("isset,name,src", cmd, sizeof(cmd), name,
519  sizeof(name), dir, sizeof(dir)));
520  FAIL_IF(strcmp(cmd, "isset") != 0);
521  FAIL_IF(strcmp(name, "name") != 0);
522  FAIL_IF(strcmp(dir, "src") != 0);
523 
524  /* With direction - leading and trailing spaces on name. */
525  *cmd = '\0';
526  *name = '\0';
527  *dir = '\0';
528  FAIL_IF(!DetectHostbitParse("isset, name ,src", cmd, sizeof(cmd), name,
529  sizeof(name), dir, sizeof(dir)));
530  FAIL_IF(strcmp(cmd, "isset") != 0);
531  FAIL_IF(strcmp(name, "name") != 0);
532  FAIL_IF(strcmp(dir, "src") != 0);
533 
534  /* With direction - space around direction. */
535  *cmd = '\0';
536  *name = '\0';
537  *dir = '\0';
538  FAIL_IF(!DetectHostbitParse("isset, name , src ", cmd, sizeof(cmd), name,
539  sizeof(name), dir, sizeof(dir)));
540  FAIL_IF(strcmp(cmd, "isset") != 0);
541  FAIL_IF(strcmp(name, "name") != 0);
542  FAIL_IF(strcmp(dir, "src") != 0);
543 
544  /* Name with space, no direction - should fail. */
545  *cmd = '\0';
546  *name = '\0';
547  *dir = '\0';
548  FAIL_IF(DetectHostbitParse("isset, name withspace ", cmd, sizeof(cmd), name,
549  sizeof(name), dir, sizeof(dir)));
550 
551  PASS;
552 }
553 
554 /**
555  * \test HostBitsTestSig01 is a test for a valid noalert flowbits option
556  *
557  * \retval 1 on success
558  * \retval 0 on failure
559  */
560 
561 static int HostBitsTestSig01(void)
562 {
563  uint8_t *buf = (uint8_t *)
564  "GET /one/ HTTP/1.1\r\n"
565  "Host: one.example.org\r\n"
566  "\r\n";
567  uint16_t buflen = strlen((char *)buf);
569  FAIL_IF_NULL(p);
570  Signature *s = NULL;
572  DetectEngineThreadCtx *det_ctx = NULL;
573  DetectEngineCtx *de_ctx = NULL;
574 
575  memset(&th_v, 0, sizeof(th_v));
577  p->src.family = AF_INET;
578  p->dst.family = AF_INET;
579  p->payload = buf;
580  p->payload_len = buflen;
581  p->proto = IPPROTO_TCP;
582 
583  HostBitsTestSetup();
584 
587 
588  de_ctx->flags |= DE_QUIET;
589 
590  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (hostbits:set,abc; content:\"GET \"; sid:1;)");
591  FAIL_IF_NULL(s);
592 
594  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
595 
596  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
597 
598  PacketFree(p);
599  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
601  HostBitsTestShutdown();
603  PASS;
604 }
605 
606 /**
607  * \test various options
608  *
609  * \retval 1 on success
610  * \retval 0 on failure
611  */
612 
613 static int HostBitsTestSig02(void)
614 {
615  Signature *s = NULL;
617  DetectEngineCtx *de_ctx = NULL;
618 
619  memset(&th_v, 0, sizeof(th_v));
620 
623 
624  de_ctx->flags |= DE_QUIET;
625 
627  "alert ip any any -> any any (hostbits:isset,abc,src; content:\"GET \"; sid:1;)");
628  FAIL_IF_NULL(s);
629 
631  "alert ip any any -> any any (hostbits:isnotset,abc,dst; content:\"GET \"; sid:2;)");
632  FAIL_IF_NULL(s);
633 
635  "alert ip any any -> any any (hostbits:!isset,abc,dst; content:\"GET \"; sid:3;)");
636  FAIL_IF_NOT_NULL(s);
637 
638 /* TODO reenable after both is supported
639  s = DetectEngineAppendSig(de_ctx,
640  "alert ip any any -> any any (hostbits:set,abc,both; content:\"GET \"; sid:3;)");
641  FAIL_IF_NULL(s);
642 */
644  "alert ip any any -> any any (hostbits:unset,abc,src; content:\"GET \"; sid:4;)");
645  FAIL_IF_NULL(s);
646 
648  "alert ip any any -> any any (hostbits:toggle,abc,dst; content:\"GET \"; sid:5;)");
649  FAIL_IF_NULL(s);
650 
652  PASS;
653 }
654 
655 /**
656  * \test HostBitsTestSig03 is a test check idx value
657  *
658  * \retval 1 on success
659  * \retval 0 on failure
660  */
661 
662 static int HostBitsTestSig03(void)
663 {
664  uint8_t *buf = (uint8_t *)
665  "GET /one/ HTTP/1.1\r\n"
666  "Host: one.example.org\r\n"
667  "\r\n";
668  uint16_t buflen = strlen((char *)buf);
670  if (unlikely(p == NULL))
671  return 0;
672  Signature *s = NULL;
674  DetectEngineThreadCtx *det_ctx = NULL;
675  DetectEngineCtx *de_ctx = NULL;
676  int idx = 0;
677 
678  memset(&th_v, 0, sizeof(th_v));
680  p->src.family = AF_INET;
681  p->dst.family = AF_INET;
682  p->payload = buf;
683  p->payload_len = buflen;
684  p->proto = IPPROTO_TCP;
685 
686  HostBitsTestSetup();
687 
690 
691  de_ctx->flags |= DE_QUIET;
692 
693  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"isset option\"; hostbits:isset,fbt; content:\"GET \"; sid:1;)");
694  FAIL_IF_NULL(s);
695 
697  FAIL_IF(idx == 0);
698 
700  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
701 
702  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
703 
704  PacketFree(p);
705  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
707  HostBitsTestShutdown();
709  PASS;
710 }
711 
712 /**
713  * \brief this function registers unit tests for HostBits
714  */
716 {
717  UtRegisterTest("HostBitsTestParse01", HostBitsTestParse01);
718  UtRegisterTest("HostBitsTestSig01", HostBitsTestSig01);
719  UtRegisterTest("HostBitsTestSig02", HostBitsTestSig02);
720  UtRegisterTest("HostBitsTestSig03", HostBitsTestSig03);
721 }
722 #endif /* UNITTESTS */
HostUnlock
void HostUnlock(Host *h)
Definition: host.c:472
Packet_::proto
uint8_t proto
Definition: decode.h:538
detect-engine.h
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SCStorageInit
void SCStorageInit(void)
Definition: util-storage.c:67
SigTableElmt_::desc
const char * desc
Definition: detect.h:1544
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:78
DetectXbitsData_::expire
uint32_t expire
Definition: detect-xbits.h:45
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1529
flow-util.h
DetectParseRegex
Definition: detect-parse.h:94
SigTableElmt_::name
const char * name
Definition: detect.h:1542
HostBitsRegisterTests
void HostBitsRegisterTests(void)
this function registers unit tests for HostBits
Definition: detect-hostbits.c:715
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
Packet_::host_src
struct Host_ * host_src
Definition: decode.h:639
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:101
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1533
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
name
const char * name
Definition: detect-engine-proto.c:47
Packet_::payload
uint8_t * payload
Definition: decode.h:620
action-globals.h
PARSE_REGEX
#define PARSE_REGEX
Definition: detect-hostbits.c:65
threads.h
ctx
struct Thresholds ctx
HostBitSet
void HostBitSet(Host *h, uint32_t idx, SCTime_t expire)
Definition: host-bit.c:130
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:995
DetectXbitsData_::cmd
uint8_t cmd
Definition: detect-xbits.h:43
HostGetHostFromHash
Host * HostGetHostFromHash(Address *a)
Definition: host.c:486
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2912
flow-bit.h
util-var-name.h
DETECT_XBITS_TRACK_IPDST
#define DETECT_XBITS_TRACK_IPDST
Definition: detect-xbits.h:35
DE_QUIET
#define DE_QUIET
Definition: detect.h:334
DetectHostbitsRegister
void DetectHostbitsRegister(void)
Definition: detect-hostbits.c:80
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:3305
p
Packet * p
Definition: fuzz_dataset.c:30
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:4019
VarNameStoreRegister
uint32_t VarNameStoreRegister(const char *name, const enum VarTypes type)
Definition: util-var-name.c:156
Packet_::host_dst
struct Host_ * host_dst
Definition: decode.h:640
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3965
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1524
HostBitInitCtx
void HostBitInitCtx(void)
Definition: host-bit.c:48
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:621
DetectXbitsData_
Definition: detect-xbits.h:41
DETECT_HOSTBITS
@ DETECT_HOSTBITS
Definition: detect-engine-register.h:72
DETECT_SM_LIST_POSTMATCH
@ DETECT_SM_LIST_POSTMATCH
Definition: detect.h:128
DetectXbitMatchHost
int DetectXbitMatchHost(Packet *p, const DetectXbitsData *xd)
Definition: detect-hostbits.c:247
DETECT_XBITS_CMD_ISNOTSET
#define DETECT_XBITS_CMD_ISNOTSET
Definition: detect-xbits.h:30
decode.h
FAIL_IF_NOT_NULL
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
Definition: util-unittest.h:96
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
DetectEngineThreadCtx_
Definition: detect.h:1316
Packet_::ts
SCTime_t ts
Definition: decode.h:570
HostBitUnset
void HostBitUnset(Host *h, uint32_t idx)
Definition: host-bit.c:138
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:4145
detect-engine-mpm.h
SCSigMatchAppendSMToList
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:424
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
Definition: detect-engine.c:3660
VarNameStoreUnregister
void VarNameStoreUnregister(const uint32_t id, const enum VarTypes type)
Definition: util-var-name.c:205
PacketFree
void PacketFree(Packet *p)
Return a malloced packet.
Definition: decode.c:221
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:118
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:3618
app-layer-parser.h
HostLock
void HostLock(Host *h)
Definition: host.c:467
Signature_::action
uint8_t action
Definition: detect.h:707
DetectXbitsData_::type
enum VarTypes type
Definition: detect-xbits.h:47
ACTION_ALERT
#define ACTION_ALERT
Definition: action-globals.h:29
Packet_
Definition: decode.h:516
SIGMATCH_IPONLY_COMPAT
#define SIGMATCH_IPONLY_COMPAT
Definition: detect-engine-register.h:310
detect-engine-build.h
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1504
HostBitIsset
int HostBitIsset(Host *h, uint32_t idx, SCTime_t ts)
Definition: host-bit.c:156
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2300
StatsThreadInit
void StatsThreadInit(StatsThreadContext *stats)
Definition: counters.c:1332
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:355
th_v
ThreadVars * th_v
Definition: fuzz_dataset.c:29
HostBitToggle
void HostBitToggle(Host *h, uint32_t idx, SCTime_t expire)
Definition: host-bit.c:146
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
Definition: detect-engine.c:3905
util-spm.h
DetectXbitsData_::idx
uint32_t idx
Definition: detect-xbits.h:42
HostBitIsnotset
int HostBitIsnotset(Host *h, uint32_t idx, SCTime_t ts)
Definition: host-bit.c:169
HostShutdown
void HostShutdown(void)
shutdown the flow engine
Definition: host.c:296
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:1005
detect-hostbits.h
VAR_TYPE_HOST_BIT
@ VAR_TYPE_HOST_BIT
Definition: util-var.h:41
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:260
detect-engine-sigorder.h
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
DetectXbitsData_::tracker
uint8_t tracker
Definition: detect-xbits.h:44
str
#define str(s)
Definition: suricata-common.h:313
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DETECT_XBITS_TRACK_IPSRC
#define DETECT_XBITS_TRACK_IPSRC
Definition: detect-xbits.h:34
detect-parse.h
Signature_
Signature container.
Definition: detect.h:692
DETECT_XBITS_CMD_NOALERT
#define DETECT_XBITS_CMD_NOALERT
Definition: detect-xbits.h:32
DETECT_XBITS_CMD_ISSET
#define DETECT_XBITS_CMD_ISSET
Definition: detect-xbits.h:31
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2873
HostLookupHostFromHash
Host * HostLookupHostFromHash(Address *a)
look up a host in the hash
Definition: host.c:585
SCStorageCleanup
void SCStorageCleanup(void)
Definition: util-storage.c:75
Address_::family
char family
Definition: decode.h:114
Packet_::dst
Address dst
Definition: decode.h:521
HostInitConfig
void HostInitConfig(bool quiet)
initialize the configuration
Definition: host.c:168
DETECT_XBITS_CMD_SET
#define DETECT_XBITS_CMD_SET
Definition: detect-xbits.h:27
DetectHostbitFree
void DetectHostbitFree(DetectEngineCtx *, void *)
Definition: detect-hostbits.c:448
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:997
DETECT_XBITS_CMD_TOGGLE
#define DETECT_XBITS_CMD_TOGGLE
Definition: detect-xbits.h:28
flow.h
DETECT_XBITS_CMD_UNSET
#define DETECT_XBITS_CMD_UNSET
Definition: detect-xbits.h:29
SCTIME_ADD_SECS
#define SCTIME_ADD_SECS(ts, s)
Definition: util-time.h:64
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:120
StatsThreadCleanup
void StatsThreadCleanup(StatsThreadContext *stats)
Definition: counters.c:1428
Packet_::src
Address src
Definition: decode.h:520
SCStorageFinalize
int SCStorageFinalize(void)
Definition: util-storage.c:134
host-bit.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1531