suricata
detect-ssh-proto-version.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2020 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 Pablo Rincon <pablo.rincon.crespo@gmail.com>
22  *
23  * Implements the ssh.protoversion keyword
24  * You can specify a concrete version like ssh.protoversion: 1.66
25  * or search for protoversion 2 compat (1.99 is considered as 2) like
26  * ssh.protoversion:2_compat
27  * or just the beginning of the string like ssh.protoversion:"1."
28  */
29 
30 #include "suricata-common.h"
31 #include "threads.h"
32 #include "debug.h"
33 #include "decode.h"
34 
35 #include "detect.h"
36 #include "detect-parse.h"
37 
38 #include "detect-engine.h"
39 #include "detect-engine-mpm.h"
40 #include "detect-engine-state.h"
41 
42 #include "flow.h"
43 #include "flow-var.h"
44 #include "flow-util.h"
45 
46 #include "util-debug.h"
47 #include "util-unittest.h"
48 #include "util-unittest-helper.h"
49 
50 #include "app-layer.h"
51 #include "app-layer-parser.h"
52 #include "app-layer-ssh.h"
54 #include "rust.h"
55 
56 #include "stream-tcp.h"
57 
58 /**
59  * \brief Regex for parsing the protoversion string
60  */
61 #define PARSE_REGEX "^\\s*\"?\\s*([0-9]+([\\.\\-0-9]+)?|2_compat)\\s*\"?\\s*$"
62 
63 static DetectParseRegex parse_regex;
64 
65 static int DetectSshVersionMatch (DetectEngineThreadCtx *,
66  Flow *, uint8_t, void *, void *,
67  const Signature *, const SigMatchCtx *);
68 static int DetectSshVersionSetup (DetectEngineCtx *, Signature *, const char *);
69 #ifdef UNITTESTS
70 static void DetectSshVersionRegisterTests(void);
71 #endif
72 static void DetectSshVersionFree(DetectEngineCtx *, void *);
73 static int g_ssh_banner_list_id = 0;
74 
75 /**
76  * \brief Registration function for keyword: ssh.protoversion
77  */
79 {
80  sigmatch_table[DETECT_AL_SSH_PROTOVERSION].name = "ssh.protoversion";
81  sigmatch_table[DETECT_AL_SSH_PROTOVERSION].desc = "match SSH protocol version";
82  sigmatch_table[DETECT_AL_SSH_PROTOVERSION].url = "/rules/ssh-keywords.html#ssh-protoversion";
84  sigmatch_table[DETECT_AL_SSH_PROTOVERSION].Setup = DetectSshVersionSetup;
85  sigmatch_table[DETECT_AL_SSH_PROTOVERSION].Free = DetectSshVersionFree;
86 #ifdef UNITTESTS
87  sigmatch_table[DETECT_AL_SSH_PROTOVERSION].RegisterTests = DetectSshVersionRegisterTests;
88 #endif
91 
92  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
93 
94  g_ssh_banner_list_id = DetectBufferTypeRegister("ssh_banner");
95 }
96 
97 /**
98  * \brief match the specified version on a ssh session
99  *
100  * \param t pointer to thread vars
101  * \param det_ctx pointer to the pattern matcher thread
102  * \param p pointer to the current packet
103  * \param m pointer to the sigmatch that we will cast into DetectSshVersionData
104  *
105  * \retval 0 no match
106  * \retval 1 match
107  */
108 static int DetectSshVersionMatch (DetectEngineThreadCtx *det_ctx,
109  Flow *f, uint8_t flags, void *state, void *txv,
110  const Signature *s, const SigMatchCtx *m)
111 {
112  SCEnter();
113 
114  SCLogDebug("lets see");
115 
117  if (state == NULL) {
118  SCLogDebug("no ssh state, no match");
119  SCReturnInt(0);
120  }
121 
122  int ret = 0;
123  const uint8_t *protocol = NULL;
124  uint32_t b_len = 0;
125 
126  if (rs_ssh_tx_get_protocol(txv, &protocol, &b_len, flags) != 1)
127  SCReturnInt(0);
128  if (protocol == NULL || b_len == 0)
129  SCReturnInt(0);
130 
132  SCLogDebug("looking for ssh protoversion 2 compat");
133  if (protocol[0] == '2') {
134  ret = 1;
135  } else if (b_len >= 4) {
136  if (memcmp(protocol, "1.99", 4) == 0) {
137  ret = 1;
138  }
139  }
140  } else {
141  SCLogDebug("looking for ssh protoversion %s length %"PRIu16"", ssh->ver, ssh->len);
142  if (b_len == ssh->len) {
143  if (memcmp(protocol, ssh->ver, ssh->len) == 0) {
144  ret = 1;
145  }
146  }
147  }
148  SCReturnInt(ret);
149 }
150 
151 /**
152  * \brief This function is used to parse IPV4 ip_id passed via keyword: "id"
153  *
154  * \param de_ctx Pointer to the detection engine context
155  * \param idstr Pointer to the user provided id option
156  *
157  * \retval id_d pointer to DetectSshVersionData on success
158  * \retval NULL on failure
159  */
160 static DetectSshVersionData *DetectSshVersionParse (DetectEngineCtx *de_ctx, const char *str)
161 {
162  DetectSshVersionData *ssh = NULL;
163  int ret = 0, res = 0;
164  size_t pcre2_len;
165 
166  ret = DetectParsePcreExec(&parse_regex, str, 0, 0);
167  if (ret < 1 || ret > 3) {
168  SCLogError(SC_ERR_PCRE_MATCH, "invalid ssh.protoversion option");
169  goto error;
170  }
171 
172  if (ret > 1) {
173  const char *str_ptr;
174  res = pcre2_substring_get_bynumber(
175  parse_regex.match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
176  if (res < 0) {
177  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_get_bynumber failed");
178  goto error;
179  }
180 
181  /* We have a correct id option */
182  ssh = SCMalloc(sizeof(DetectSshVersionData));
183  if (unlikely(ssh == NULL)) {
184  pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
185  goto error;
186  }
187  memset(ssh, 0x00, sizeof(DetectSshVersionData));
188 
189  /* If we expect a protocol version 2 or 1.99 (considered 2, we
190  * will compare it with both strings) */
191  if (strcmp("2_compat", str_ptr) == 0) {
193  SCLogDebug("will look for ssh protocol version 2 (2, 2.0, 1.99 that's considered as 2");
194  pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
195  return ssh;
196  }
197 
198  ssh->ver = (uint8_t *)SCStrdup((char*)str_ptr);
199  if (ssh->ver == NULL) {
200  pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
201  goto error;
202  }
203  ssh->len = strlen((char *) ssh->ver);
204  pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
205 
206  SCLogDebug("will look for ssh %s", ssh->ver);
207  }
208 
209  return ssh;
210 
211 error:
212  if (ssh != NULL)
213  DetectSshVersionFree(de_ctx, ssh);
214  return NULL;
215 
216 }
217 
218 /**
219  * \brief this function is used to add the parsed "id" option
220  * \brief into the current signature
221  *
222  * \param de_ctx pointer to the Detection Engine Context
223  * \param s pointer to the Current Signature
224  * \param idstr pointer to the user provided "id" option
225  *
226  * \retval 0 on Success
227  * \retval -1 on Failure
228  */
229 static int DetectSshVersionSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
230 {
231  DetectSshVersionData *ssh = NULL;
232  SigMatch *sm = NULL;
233 
235  return -1;
236 
237  ssh = DetectSshVersionParse(de_ctx, str);
238  if (ssh == NULL)
239  goto error;
240 
241  /* Okay so far so good, lets get this into a SigMatch
242  * and put it in the Signature. */
243  sm = SigMatchAlloc();
244  if (sm == NULL)
245  goto error;
246 
248  sm->ctx = (void *)ssh;
249 
250  SigMatchAppendSMToList(s, sm, g_ssh_banner_list_id);
251  return 0;
252 
253 error:
254  if (ssh != NULL)
255  DetectSshVersionFree(de_ctx, ssh);
256  if (sm != NULL)
257  SCFree(sm);
258  return -1;
259 
260 }
261 
262 /**
263  * \brief this function will free memory associated with DetectSshVersionData
264  *
265  * \param id_d pointer to DetectSshVersionData
266  */
267 void DetectSshVersionFree(DetectEngineCtx *de_ctx, void *ptr)
268 {
270  SCFree(sshd->ver);
271  SCFree(sshd);
272 }
273 
274 #ifdef UNITTESTS /* UNITTESTS */
275 
276 /**
277  * \test DetectSshVersionTestParse01 is a test to make sure that we parse
278  * a proto version correctly
279  */
280 static int DetectSshVersionTestParse01 (void)
281 {
282  DetectSshVersionData *ssh = NULL;
283  ssh = DetectSshVersionParse(NULL, "1.0");
284  if (ssh != NULL && strncmp((char *) ssh->ver, "1.0", 3) == 0) {
285  DetectSshVersionFree(NULL, ssh);
286  return 1;
287  }
288 
289  return 0;
290 }
291 
292 /**
293  * \test DetectSshVersionTestParse02 is a test to make sure that we parse
294  * the proto version (compatible with proto version 2) correctly
295  */
296 static int DetectSshVersionTestParse02 (void)
297 {
298  DetectSshVersionData *ssh = NULL;
299  ssh = DetectSshVersionParse(NULL, "2_compat");
301  DetectSshVersionFree(NULL, ssh);
302  return 1;
303  }
304 
305  return 0;
306 }
307 
308 /**
309  * \test DetectSshVersionTestParse03 is a test to make sure that we
310  * don't return a ssh_data with an invalid value specified
311  */
312 static int DetectSshVersionTestParse03 (void)
313 {
314  DetectSshVersionData *ssh = NULL;
315  ssh = DetectSshVersionParse(NULL, "2_com");
316  if (ssh != NULL) {
317  DetectSshVersionFree(NULL, ssh);
318  return 0;
319  }
320  ssh = DetectSshVersionParse(NULL, "");
321  if (ssh != NULL) {
322  DetectSshVersionFree(NULL, ssh);
323  return 0;
324  }
325  ssh = DetectSshVersionParse(NULL, ".1");
326  if (ssh != NULL) {
327  DetectSshVersionFree(NULL, ssh);
328  return 0;
329  }
330  ssh = DetectSshVersionParse(NULL, "lalala");
331  if (ssh != NULL) {
332  DetectSshVersionFree(NULL, ssh);
333  return 0;
334  }
335 
336  return 1;
337 }
338 
339 
340 #include "stream-tcp-reassemble.h"
341 #include "stream-tcp-util.h"
342 
343 /** \test Send a get request in three chunks + more data. */
344 static int DetectSshVersionTestDetect01(void)
345 {
346  TcpReassemblyThreadCtx *ra_ctx = NULL;
347  ThreadVars tv;
348  TcpSession ssn;
349  Flow *f = NULL;
350  Packet *p = NULL;
351 
352  uint8_t sshbuf1[] = "SSH-1.";
353  uint8_t sshbuf2[] = "10-PuTTY_2.123" ;
354  uint8_t sshbuf3[] = "\n";
355  uint8_t sshbuf4[] = "whatever...";
356 
357  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
358  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
359 
360  memset(&tv, 0x00, sizeof(tv));
361 
362  StreamTcpUTInit(&ra_ctx);
367 
368  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
369  FAIL_IF_NULL(f);
370  f->protoctx = &ssn;
371  f->proto = IPPROTO_TCP;
372  f->alproto = ALPROTO_SSH;
373 
374  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
375  FAIL_IF(unlikely(p == NULL));
376  p->flow = f;
377 
378  Signature *s = NULL;
379  ThreadVars th_v;
380  DetectEngineThreadCtx *det_ctx = NULL;
381 
382  memset(&th_v, 0, sizeof(th_v));
383 
386 
387  de_ctx->flags |= DE_QUIET;
388 
389  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:1.10; sid:1;)");
390  FAIL_IF_NULL(s);
391 
393  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
394 
395  uint32_t seq = 2;
396  for (int i=0; i<4; i++) {
397  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
398  seq += sshlens[i];
399  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
400  }
401 
402  void *ssh_state = f->alstate;
403  FAIL_IF_NULL(ssh_state);
404 
405  /* do detect */
406  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
407 
408  FAIL_IF(PacketAlertCheck(p, 1));
409 
410  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
412 
413  UTHFreePacket(p);
415  StreamTcpUTDeinit(ra_ctx);
416  UTHFreeFlow(f);
417  PASS;
418 }
419 
420 /** \test Send a get request in three chunks + more data. */
421 static int DetectSshVersionTestDetect02(void)
422 {
423  TcpReassemblyThreadCtx *ra_ctx = NULL;
424  ThreadVars tv;
425  TcpSession ssn;
426  Flow *f = NULL;
427  Packet *p = NULL;
428 
429  uint8_t sshbuf1[] = "SSH-1.99-Pu";
430  uint8_t sshbuf2[] = "TTY_2.123" ;
431  uint8_t sshbuf3[] = "\n";
432  uint8_t sshbuf4[] = "whatever...";
433 
434  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
435  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
436 
437  memset(&tv, 0x00, sizeof(tv));
438 
439  StreamTcpUTInit(&ra_ctx);
444 
445  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
446  FAIL_IF_NULL(f);
447  f->protoctx = &ssn;
448  f->proto = IPPROTO_TCP;
449  f->alproto = ALPROTO_SSH;
450 
451  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
452  FAIL_IF(unlikely(p == NULL));
453  p->flow = f;
454 
455  Signature *s = NULL;
456  ThreadVars th_v;
457  DetectEngineThreadCtx *det_ctx = NULL;
458 
459  memset(&th_v, 0, sizeof(th_v));
460 
463 
464  de_ctx->flags |= DE_QUIET;
465 
466  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:2_compat; sid:1;)");
467  FAIL_IF_NULL(s);
468 
470  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
471 
472  uint32_t seq = 2;
473  for (int i=0; i<4; i++) {
474  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
475  seq += sshlens[i];
476  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
477  }
478 
479  void *ssh_state = f->alstate;
480  FAIL_IF_NULL(ssh_state);
481 
482  /* do detect */
483  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
484 
485  FAIL_IF(PacketAlertCheck(p, 1));
486 
487  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
489 
490  UTHFreePacket(p);
492  StreamTcpUTDeinit(ra_ctx);
493  UTHFreeFlow(f);
494  PASS;
495 }
496 
497 /** \test Send a get request in three chunks + more data. */
498 static int DetectSshVersionTestDetect03(void)
499 {
500  TcpReassemblyThreadCtx *ra_ctx = NULL;
501  ThreadVars tv;
502  TcpSession ssn;
503  Flow *f = NULL;
504  Packet *p = NULL;
505 
506  uint8_t sshbuf1[] = "SSH-1.";
507  uint8_t sshbuf2[] = "7-PuTTY_2.123" ;
508  uint8_t sshbuf3[] = "\n";
509  uint8_t sshbuf4[] = "whatever...";
510 
511  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
512  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
513 
514  memset(&tv, 0x00, sizeof(tv));
515 
516  StreamTcpUTInit(&ra_ctx);
521 
522  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
523  FAIL_IF_NULL(f);
524  f->protoctx = &ssn;
525  f->proto = IPPROTO_TCP;
526  f->alproto = ALPROTO_SSH;
527 
528  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
529  FAIL_IF(unlikely(p == NULL));
530  p->flow = f;
531 
532  Signature *s = NULL;
533  ThreadVars th_v;
534  DetectEngineThreadCtx *det_ctx = NULL;
535 
536  memset(&th_v, 0, sizeof(th_v));
537 
540 
541  de_ctx->flags |= DE_QUIET;
542 
543  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:2_compat; sid:1;)");
544  FAIL_IF_NULL(s);
545 
547  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
548 
549  uint32_t seq = 2;
550  for (int i=0; i<4; i++) {
551  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
552  seq += sshlens[i];
553  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
554  }
555 
556  void *ssh_state = f->alstate;
557  FAIL_IF_NULL(ssh_state);
558 
559  /* do detect */
560  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
561 
562  FAIL_IF(PacketAlertCheck(p, 1));
563 
564  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
566 
567  UTHFreePacket(p);
569  StreamTcpUTDeinit(ra_ctx);
570  UTHFreeFlow(f);
571  PASS;
572 }
573 
574 /**
575  * \brief this function registers unit tests for DetectSshVersion
576  */
577 static void DetectSshVersionRegisterTests(void)
578 {
579  UtRegisterTest("DetectSshVersionTestParse01", DetectSshVersionTestParse01);
580  UtRegisterTest("DetectSshVersionTestParse02", DetectSshVersionTestParse02);
581  UtRegisterTest("DetectSshVersionTestParse03", DetectSshVersionTestParse03);
582  UtRegisterTest("DetectSshVersionTestDetect01",
583  DetectSshVersionTestDetect01);
584  UtRegisterTest("DetectSshVersionTestDetect02",
585  DetectSshVersionTestDetect02);
586  UtRegisterTest("DetectSshVersionTestDetect03",
587  DetectSshVersionTestDetect03);
588 }
589 #endif /* UNITTESTS */
DetectSshVersionRegister
void DetectSshVersionRegister(void)
Registration function for keyword: ssh.protoversion.
Definition: detect-ssh-proto-version.c:78
UPDATE_DIR_PACKET
@ UPDATE_DIR_PACKET
Definition: stream-tcp-reassemble.h:55
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:45
SigTableElmt_::url
const char * url
Definition: detect.h:1270
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1490
SSH_FLAG_PROTOVERSION_2_COMPAT
#define SSH_FLAG_PROTOVERSION_2_COMPAT
Definition: detect-ssh-proto-version.h:28
detect-engine.h
StreamTcpUTDeinit
void StreamTcpUTDeinit(TcpReassemblyThreadCtx *ra_ctx)
Definition: stream-tcp-util.c:51
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
app-layer-ssh.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1269
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
Definition: detect-parse.c:2474
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1257
flow-util.h
DetectParseRegex
Definition: detect-parse.h:42
SigTableElmt_::name
const char * name
Definition: detect.h:1267
stream-tcp.h
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectSshVersionData_::len
uint16_t len
Definition: detect-ssh-proto-version.h:32
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
SIGMATCH_QUOTES_OPTIONAL
#define SIGMATCH_QUOTES_OPTIONAL
Definition: detect.h:1465
seq
uint32_t seq
Definition: stream-tcp-private.h:2
Flow_::proto
uint8_t proto
Definition: flow.h:375
PacketAlertCheck
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
Definition: detect-engine-alert.c:137
DETECT_AL_SSH_PROTOVERSION
@ DETECT_AL_SSH_PROTOVERSION
Definition: detect-engine-register.h:164
threads.h
Flow_
Flow data structure.
Definition: flow.h:353
SigInit
Signature * SigInit(DetectEngineCtx *, const char *)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2115
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1261
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:811
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2433
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1238
rust.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:295
stream-tcp-reassemble.h
UTHBuildPacket
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
Definition: util-unittest-helper.c:337
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1790
m
SCMutex m
Definition: flow-hash.h:6
SC_ERR_PCRE_GET_SUBSTRING
@ SC_ERR_PCRE_GET_SUBSTRING
Definition: util-error.h:34
ALPROTO_SSH
@ ALPROTO_SSH
Definition: app-layer-protos.h:34
DetectSshVersionData_
Definition: detect-ssh-proto-version.h:30
Flow_::protoctx
void * protoctx
Definition: flow.h:451
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1252
StreamTcpUTInitInline
void StreamTcpUTInitInline(void)
Definition: stream-tcp-util.c:58
util-unittest.h
util-unittest-helper.h
StreamTcpUTInit
void StreamTcpUTInit(TcpReassemblyThreadCtx **ra_ctx)
Definition: stream-tcp-util.c:44
UTHBuildFlow
Flow * UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
Definition: util-unittest-helper.c:521
StreamTcpReassembleAppLayer
int StreamTcpReassembleAppLayer(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, TcpSession *ssn, TcpStream *stream, Packet *p, enum StreamUpdateDir dir)
Update the stream reassembly upon receiving a packet.
Definition: stream-tcp-reassemble.c:1225
protocol
uint16_t protocol
Definition: decode-ppp.h:2
decode.h
util-debug.h
SC_ERR_PCRE_MATCH
@ SC_ERR_PCRE_MATCH
Definition: util-error.h:32
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1060
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2597
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
StreamTcpUTSetupStream
void StreamTcpUTSetupStream(TcpStream *s, uint32_t isn)
Definition: stream-tcp-util.c:79
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1265
app-layer-parser.h
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:324
Packet_
Definition: decode.h:427
DetectSshVersionData_::flags
uint8_t flags
Definition: detect-ssh-proto-version.h:33
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:235
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:1948
DETECT_AL_SSH_PROTOCOL
@ DETECT_AL_SSH_PROTOCOL
Definition: detect-engine-register.h:163
UTHFreeFlow
void UTHFreeFlow(Flow *flow)
Definition: util-unittest-helper.c:526
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:316
StreamTcpUTClearSession
void StreamTcpUTClearSession(TcpSession *ssn)
Definition: stream-tcp-util.c:71
Packet_::flow
struct Flow_ * flow
Definition: decode.h:464
detect-ssh-proto-version.h
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3142
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition: detect-engine.c:1023
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3354
SigMatch_::type
uint16_t type
Definition: detect.h:322
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:817
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:272
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
StreamTcpUTAddSegmentWithPayload
int StreamTcpUTAddSegmentWithPayload(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, TcpStream *stream, uint32_t seq, uint8_t *payload, uint16_t len)
Definition: stream-tcp-util.c:113
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
StreamTcpUTSetupSession
void StreamTcpUTSetupSession(TcpSession *ssn)
Definition: stream-tcp-util.c:62
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:271
str
#define str(s)
Definition: suricata-common.h:272
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SIGMATCH_INFO_DEPRECATED
#define SIGMATCH_INFO_DEPRECATED
Definition: detect.h:1479
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:485
Flow_::alstate
void * alstate
Definition: flow.h:486
detect-parse.h
Signature_
Signature container.
Definition: detect.h:548
SigMatch_
a single match condition for a signature
Definition: detect.h:321
stream-tcp-util.h
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2394
PARSE_REGEX
#define PARSE_REGEX
Regex for parsing the protoversion string.
Definition: detect-ssh-proto-version.c:61
TcpReassemblyThreadCtx_
Definition: stream-tcp-reassemble.h:60
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:812
TcpSession_
Definition: stream-tcp-private.h:260
flow.h
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:460
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:304
flow-var.h
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:349
DetectSshVersionData_::ver
uint8_t * ver
Definition: detect-ssh-proto-version.h:31
debug.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1259
app-layer.h