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 "decode.h"
33 
34 #include "detect.h"
35 #include "detect-parse.h"
36 
37 #include "detect-engine.h"
38 #include "detect-engine-mpm.h"
39 #include "detect-engine-state.h"
40 #include "detect-engine-build.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 res = 0;
164  size_t pcre2_len;
165 
166  pcre2_match_data *match = NULL;
167  int ret = DetectParsePcreExec(&parse_regex, &match, str, 0, 0);
168  if (ret < 1 || ret > 3) {
169  SCLogError("invalid ssh.protoversion option");
170  goto error;
171  }
172 
173  if (ret > 1) {
174  const char *str_ptr;
175  res = pcre2_substring_get_bynumber(match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
176  if (res < 0) {
177  SCLogError("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 = (uint16_t)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  pcre2_match_data_free(match);
210  return ssh;
211 
212 error:
213  if (match) {
214  pcre2_match_data_free(match);
215  }
216  if (ssh != NULL)
217  DetectSshVersionFree(de_ctx, ssh);
218  return NULL;
219 
220 }
221 
222 /**
223  * \brief this function is used to add the parsed "id" option
224  * \brief into the current signature
225  *
226  * \param de_ctx pointer to the Detection Engine Context
227  * \param s pointer to the Current Signature
228  * \param idstr pointer to the user provided "id" option
229  *
230  * \retval 0 on Success
231  * \retval -1 on Failure
232  */
233 static int DetectSshVersionSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
234 {
235  DetectSshVersionData *ssh = NULL;
236  SigMatch *sm = NULL;
237 
239  return -1;
240 
241  ssh = DetectSshVersionParse(de_ctx, str);
242  if (ssh == NULL)
243  goto error;
244 
245  /* Okay so far so good, lets get this into a SigMatch
246  * and put it in the Signature. */
247  sm = SigMatchAlloc();
248  if (sm == NULL)
249  goto error;
250 
252  sm->ctx = (void *)ssh;
253 
254  SigMatchAppendSMToList(s, sm, g_ssh_banner_list_id);
255  return 0;
256 
257 error:
258  if (ssh != NULL)
259  DetectSshVersionFree(de_ctx, ssh);
260  if (sm != NULL)
261  SCFree(sm);
262  return -1;
263 
264 }
265 
266 /**
267  * \brief this function will free memory associated with DetectSshVersionData
268  *
269  * \param id_d pointer to DetectSshVersionData
270  */
271 void DetectSshVersionFree(DetectEngineCtx *de_ctx, void *ptr)
272 {
274  SCFree(sshd->ver);
275  SCFree(sshd);
276 }
277 
278 #ifdef UNITTESTS /* UNITTESTS */
279 #include "detect-engine-alert.h"
280 
281 /**
282  * \test DetectSshVersionTestParse01 is a test to make sure that we parse
283  * a proto version correctly
284  */
285 static int DetectSshVersionTestParse01 (void)
286 {
287  DetectSshVersionData *ssh = NULL;
288  ssh = DetectSshVersionParse(NULL, "1.0");
289  if (ssh != NULL && strncmp((char *) ssh->ver, "1.0", 3) == 0) {
290  DetectSshVersionFree(NULL, ssh);
291  return 1;
292  }
293 
294  return 0;
295 }
296 
297 /**
298  * \test DetectSshVersionTestParse02 is a test to make sure that we parse
299  * the proto version (compatible with proto version 2) correctly
300  */
301 static int DetectSshVersionTestParse02 (void)
302 {
303  DetectSshVersionData *ssh = NULL;
304  ssh = DetectSshVersionParse(NULL, "2_compat");
306  DetectSshVersionFree(NULL, ssh);
307  return 1;
308  }
309 
310  return 0;
311 }
312 
313 /**
314  * \test DetectSshVersionTestParse03 is a test to make sure that we
315  * don't return a ssh_data with an invalid value specified
316  */
317 static int DetectSshVersionTestParse03 (void)
318 {
319  DetectSshVersionData *ssh = NULL;
320  ssh = DetectSshVersionParse(NULL, "2_com");
321  if (ssh != NULL) {
322  DetectSshVersionFree(NULL, ssh);
323  return 0;
324  }
325  ssh = DetectSshVersionParse(NULL, "");
326  if (ssh != NULL) {
327  DetectSshVersionFree(NULL, ssh);
328  return 0;
329  }
330  ssh = DetectSshVersionParse(NULL, ".1");
331  if (ssh != NULL) {
332  DetectSshVersionFree(NULL, ssh);
333  return 0;
334  }
335  ssh = DetectSshVersionParse(NULL, "lalala");
336  if (ssh != NULL) {
337  DetectSshVersionFree(NULL, ssh);
338  return 0;
339  }
340 
341  return 1;
342 }
343 
344 
345 #include "stream-tcp-reassemble.h"
346 #include "stream-tcp-util.h"
347 
348 /** \test Send a get request in three chunks + more data. */
349 static int DetectSshVersionTestDetect01(void)
350 {
351  TcpReassemblyThreadCtx *ra_ctx = NULL;
352  ThreadVars tv;
353  TcpSession ssn;
354  Flow *f = NULL;
355  Packet *p = NULL;
356 
357  uint8_t sshbuf1[] = "SSH-1.";
358  uint8_t sshbuf2[] = "10-PuTTY_2.123" ;
359  uint8_t sshbuf3[] = "\n";
360  uint8_t sshbuf4[] = "whatever...";
361 
362  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
363  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
364 
365  memset(&tv, 0x00, sizeof(tv));
366 
367  StreamTcpUTInit(&ra_ctx);
372 
373  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
374  FAIL_IF_NULL(f);
375  f->protoctx = &ssn;
376  f->proto = IPPROTO_TCP;
377  f->alproto = ALPROTO_SSH;
378 
379  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
380  FAIL_IF(unlikely(p == NULL));
381  p->flow = f;
382 
383  Signature *s = NULL;
384  ThreadVars th_v;
385  DetectEngineThreadCtx *det_ctx = NULL;
386 
387  memset(&th_v, 0, sizeof(th_v));
388 
391 
392  de_ctx->flags |= DE_QUIET;
393 
394  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:1.10; sid:1;)");
395  FAIL_IF_NULL(s);
396 
398  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
399 
400  uint32_t seq = 2;
401  for (int i=0; i<4; i++) {
402  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
403  seq += sshlens[i];
404  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
405  }
406 
407  void *ssh_state = f->alstate;
408  FAIL_IF_NULL(ssh_state);
409 
410  /* do detect */
411  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
412 
413  FAIL_IF(PacketAlertCheck(p, 1));
414 
415  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
417 
418  UTHFreePacket(p);
420  StreamTcpUTDeinit(ra_ctx);
421  UTHFreeFlow(f);
422  PASS;
423 }
424 
425 /** \test Send a get request in three chunks + more data. */
426 static int DetectSshVersionTestDetect02(void)
427 {
428  TcpReassemblyThreadCtx *ra_ctx = NULL;
429  ThreadVars tv;
430  TcpSession ssn;
431  Flow *f = NULL;
432  Packet *p = NULL;
433 
434  uint8_t sshbuf1[] = "SSH-1.99-Pu";
435  uint8_t sshbuf2[] = "TTY_2.123" ;
436  uint8_t sshbuf3[] = "\n";
437  uint8_t sshbuf4[] = "whatever...";
438 
439  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
440  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
441 
442  memset(&tv, 0x00, sizeof(tv));
443 
444  StreamTcpUTInit(&ra_ctx);
449 
450  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
451  FAIL_IF_NULL(f);
452  f->protoctx = &ssn;
453  f->proto = IPPROTO_TCP;
454  f->alproto = ALPROTO_SSH;
455 
456  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
457  FAIL_IF(unlikely(p == NULL));
458  p->flow = f;
459 
460  Signature *s = NULL;
461  ThreadVars th_v;
462  DetectEngineThreadCtx *det_ctx = NULL;
463 
464  memset(&th_v, 0, sizeof(th_v));
465 
468 
469  de_ctx->flags |= DE_QUIET;
470 
471  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:2_compat; sid:1;)");
472  FAIL_IF_NULL(s);
473 
475  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
476 
477  uint32_t seq = 2;
478  for (int i=0; i<4; i++) {
479  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
480  seq += sshlens[i];
481  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
482  }
483 
484  void *ssh_state = f->alstate;
485  FAIL_IF_NULL(ssh_state);
486 
487  /* do detect */
488  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
489 
490  FAIL_IF(PacketAlertCheck(p, 1));
491 
492  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
494 
495  UTHFreePacket(p);
497  StreamTcpUTDeinit(ra_ctx);
498  UTHFreeFlow(f);
499  PASS;
500 }
501 
502 /** \test Send a get request in three chunks + more data. */
503 static int DetectSshVersionTestDetect03(void)
504 {
505  TcpReassemblyThreadCtx *ra_ctx = NULL;
506  ThreadVars tv;
507  TcpSession ssn;
508  Flow *f = NULL;
509  Packet *p = NULL;
510 
511  uint8_t sshbuf1[] = "SSH-1.";
512  uint8_t sshbuf2[] = "7-PuTTY_2.123" ;
513  uint8_t sshbuf3[] = "\n";
514  uint8_t sshbuf4[] = "whatever...";
515 
516  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
517  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
518 
519  memset(&tv, 0x00, sizeof(tv));
520 
521  StreamTcpUTInit(&ra_ctx);
526 
527  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
528  FAIL_IF_NULL(f);
529  f->protoctx = &ssn;
530  f->proto = IPPROTO_TCP;
531  f->alproto = ALPROTO_SSH;
532 
533  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
534  FAIL_IF(unlikely(p == NULL));
535  p->flow = f;
536 
537  Signature *s = NULL;
538  ThreadVars th_v;
539  DetectEngineThreadCtx *det_ctx = NULL;
540 
541  memset(&th_v, 0, sizeof(th_v));
542 
545 
546  de_ctx->flags |= DE_QUIET;
547 
548  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:2_compat; sid:1;)");
549  FAIL_IF_NULL(s);
550 
552  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
553 
554  uint32_t seq = 2;
555  for (int i=0; i<4; i++) {
556  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
557  seq += sshlens[i];
558  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
559  }
560 
561  void *ssh_state = f->alstate;
562  FAIL_IF_NULL(ssh_state);
563 
564  /* do detect */
565  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
566 
567  FAIL_IF(PacketAlertCheck(p, 1));
568 
569  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
571 
572  UTHFreePacket(p);
574  StreamTcpUTDeinit(ra_ctx);
575  UTHFreeFlow(f);
576  PASS;
577 }
578 
579 /**
580  * \brief this function registers unit tests for DetectSshVersion
581  */
582 static void DetectSshVersionRegisterTests(void)
583 {
584  UtRegisterTest("DetectSshVersionTestParse01", DetectSshVersionTestParse01);
585  UtRegisterTest("DetectSshVersionTestParse02", DetectSshVersionTestParse02);
586  UtRegisterTest("DetectSshVersionTestParse03", DetectSshVersionTestParse03);
587  UtRegisterTest("DetectSshVersionTestDetect01",
588  DetectSshVersionTestDetect01);
589  UtRegisterTest("DetectSshVersionTestDetect02",
590  DetectSshVersionTestDetect02);
591  UtRegisterTest("DetectSshVersionTestDetect03",
592  DetectSshVersionTestDetect03);
593 }
594 #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
SigTableElmt_::url
const char * url
Definition: detect.h:1288
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1704
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
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:437
app-layer-ssh.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1287
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1275
flow-util.h
DetectParseRegex
Definition: detect-parse.h:62
SigTableElmt_::name
const char * name
Definition: detect.h:1285
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:269
SIGMATCH_QUOTES_OPTIONAL
#define SIGMATCH_QUOTES_OPTIONAL
Definition: detect.h:1479
seq
uint32_t seq
Definition: stream-tcp-private.h:2
Flow_::proto
uint8_t proto
Definition: flow.h:369
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:141
DETECT_AL_SSH_PROTOVERSION
@ DETECT_AL_SSH_PROTOVERSION
Definition: detect-engine-register.h:169
threads.h
Flow_
Flow data structure.
Definition: flow.h:347
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1279
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:827
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2592
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1256
rust.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:315
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:1824
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:2629
m
SCMutex m
Definition: flow-hash.h:6
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:437
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1270
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:1355
protocol
uint16_t protocol
Definition: decode-ppp.h:2
decode.h
util-debug.h
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:1075
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2753
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
StreamTcpUTSetupStream
void StreamTcpUTSetupStream(TcpStream *s, uint32_t isn)
Definition: stream-tcp-util.c:79
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2270
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1283
app-layer-parser.h
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:344
Packet_
Definition: decode.h:430
detect-engine-build.h
detect-engine-alert.h
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:322
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:1971
DETECT_AL_SSH_PROTOCOL
@ DETECT_AL_SSH_PROTOCOL
Definition: detect-engine-register.h:168
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:336
StreamTcpUTClearSession
void StreamTcpUTClearSession(TcpSession *ssn)
Definition: stream-tcp-util.c:71
Packet_::flow
struct Flow_ * flow
Definition: decode.h:469
detect-ssh-proto-version.h
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3308
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:1060
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3522
SigMatch_::type
uint16_t type
Definition: detect.h:342
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:129
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:835
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:295
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
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:294
str
#define str(s)
Definition: suricata-common.h:286
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SIGMATCH_INFO_DEPRECATED
#define SIGMATCH_INFO_DEPRECATED
Definition: detect.h:1493
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:472
detect-parse.h
Signature_
Signature container.
Definition: detect.h:582
SigMatch_
a single match condition for a signature
Definition: detect.h:341
stream-tcp-util.h
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2553
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:829
TcpSession_
Definition: stream-tcp-private.h:283
flow.h
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:446
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275
flow-var.h
DetectSshVersionData_::ver
uint8_t * ver
Definition: detect-ssh-proto-version.h:31
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1277
app-layer.h