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 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("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("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  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 #include "detect-engine-alert.h"
276 
277 /**
278  * \test DetectSshVersionTestParse01 is a test to make sure that we parse
279  * a proto version correctly
280  */
281 static int DetectSshVersionTestParse01 (void)
282 {
283  DetectSshVersionData *ssh = NULL;
284  ssh = DetectSshVersionParse(NULL, "1.0");
285  if (ssh != NULL && strncmp((char *) ssh->ver, "1.0", 3) == 0) {
286  DetectSshVersionFree(NULL, ssh);
287  return 1;
288  }
289 
290  return 0;
291 }
292 
293 /**
294  * \test DetectSshVersionTestParse02 is a test to make sure that we parse
295  * the proto version (compatible with proto version 2) correctly
296  */
297 static int DetectSshVersionTestParse02 (void)
298 {
299  DetectSshVersionData *ssh = NULL;
300  ssh = DetectSshVersionParse(NULL, "2_compat");
302  DetectSshVersionFree(NULL, ssh);
303  return 1;
304  }
305 
306  return 0;
307 }
308 
309 /**
310  * \test DetectSshVersionTestParse03 is a test to make sure that we
311  * don't return a ssh_data with an invalid value specified
312  */
313 static int DetectSshVersionTestParse03 (void)
314 {
315  DetectSshVersionData *ssh = NULL;
316  ssh = DetectSshVersionParse(NULL, "2_com");
317  if (ssh != NULL) {
318  DetectSshVersionFree(NULL, ssh);
319  return 0;
320  }
321  ssh = DetectSshVersionParse(NULL, "");
322  if (ssh != NULL) {
323  DetectSshVersionFree(NULL, ssh);
324  return 0;
325  }
326  ssh = DetectSshVersionParse(NULL, ".1");
327  if (ssh != NULL) {
328  DetectSshVersionFree(NULL, ssh);
329  return 0;
330  }
331  ssh = DetectSshVersionParse(NULL, "lalala");
332  if (ssh != NULL) {
333  DetectSshVersionFree(NULL, ssh);
334  return 0;
335  }
336 
337  return 1;
338 }
339 
340 
341 #include "stream-tcp-reassemble.h"
342 #include "stream-tcp-util.h"
343 
344 /** \test Send a get request in three chunks + more data. */
345 static int DetectSshVersionTestDetect01(void)
346 {
347  TcpReassemblyThreadCtx *ra_ctx = NULL;
348  ThreadVars tv;
349  TcpSession ssn;
350  Flow *f = NULL;
351  Packet *p = NULL;
352 
353  uint8_t sshbuf1[] = "SSH-1.";
354  uint8_t sshbuf2[] = "10-PuTTY_2.123" ;
355  uint8_t sshbuf3[] = "\n";
356  uint8_t sshbuf4[] = "whatever...";
357 
358  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
359  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
360 
361  memset(&tv, 0x00, sizeof(tv));
362 
363  StreamTcpUTInit(&ra_ctx);
368 
369  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
370  FAIL_IF_NULL(f);
371  f->protoctx = &ssn;
372  f->proto = IPPROTO_TCP;
373  f->alproto = ALPROTO_SSH;
374 
375  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
376  FAIL_IF(unlikely(p == NULL));
377  p->flow = f;
378 
379  Signature *s = NULL;
380  ThreadVars th_v;
381  DetectEngineThreadCtx *det_ctx = NULL;
382 
383  memset(&th_v, 0, sizeof(th_v));
384 
387 
388  de_ctx->flags |= DE_QUIET;
389 
390  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:1.10; sid:1;)");
391  FAIL_IF_NULL(s);
392 
394  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
395 
396  uint32_t seq = 2;
397  for (int i=0; i<4; i++) {
398  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
399  seq += sshlens[i];
400  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
401  }
402 
403  void *ssh_state = f->alstate;
404  FAIL_IF_NULL(ssh_state);
405 
406  /* do detect */
407  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
408 
409  FAIL_IF(PacketAlertCheck(p, 1));
410 
411  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
413 
414  UTHFreePacket(p);
416  StreamTcpUTDeinit(ra_ctx);
417  UTHFreeFlow(f);
418  PASS;
419 }
420 
421 /** \test Send a get request in three chunks + more data. */
422 static int DetectSshVersionTestDetect02(void)
423 {
424  TcpReassemblyThreadCtx *ra_ctx = NULL;
425  ThreadVars tv;
426  TcpSession ssn;
427  Flow *f = NULL;
428  Packet *p = NULL;
429 
430  uint8_t sshbuf1[] = "SSH-1.99-Pu";
431  uint8_t sshbuf2[] = "TTY_2.123" ;
432  uint8_t sshbuf3[] = "\n";
433  uint8_t sshbuf4[] = "whatever...";
434 
435  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
436  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
437 
438  memset(&tv, 0x00, sizeof(tv));
439 
440  StreamTcpUTInit(&ra_ctx);
445 
446  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
447  FAIL_IF_NULL(f);
448  f->protoctx = &ssn;
449  f->proto = IPPROTO_TCP;
450  f->alproto = ALPROTO_SSH;
451 
452  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
453  FAIL_IF(unlikely(p == NULL));
454  p->flow = f;
455 
456  Signature *s = NULL;
457  ThreadVars th_v;
458  DetectEngineThreadCtx *det_ctx = NULL;
459 
460  memset(&th_v, 0, sizeof(th_v));
461 
464 
465  de_ctx->flags |= DE_QUIET;
466 
467  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:2_compat; sid:1;)");
468  FAIL_IF_NULL(s);
469 
471  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
472 
473  uint32_t seq = 2;
474  for (int i=0; i<4; i++) {
475  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
476  seq += sshlens[i];
477  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
478  }
479 
480  void *ssh_state = f->alstate;
481  FAIL_IF_NULL(ssh_state);
482 
483  /* do detect */
484  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
485 
486  FAIL_IF(PacketAlertCheck(p, 1));
487 
488  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
490 
491  UTHFreePacket(p);
493  StreamTcpUTDeinit(ra_ctx);
494  UTHFreeFlow(f);
495  PASS;
496 }
497 
498 /** \test Send a get request in three chunks + more data. */
499 static int DetectSshVersionTestDetect03(void)
500 {
501  TcpReassemblyThreadCtx *ra_ctx = NULL;
502  ThreadVars tv;
503  TcpSession ssn;
504  Flow *f = NULL;
505  Packet *p = NULL;
506 
507  uint8_t sshbuf1[] = "SSH-1.";
508  uint8_t sshbuf2[] = "7-PuTTY_2.123" ;
509  uint8_t sshbuf3[] = "\n";
510  uint8_t sshbuf4[] = "whatever...";
511 
512  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
513  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
514 
515  memset(&tv, 0x00, sizeof(tv));
516 
517  StreamTcpUTInit(&ra_ctx);
522 
523  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
524  FAIL_IF_NULL(f);
525  f->protoctx = &ssn;
526  f->proto = IPPROTO_TCP;
527  f->alproto = ALPROTO_SSH;
528 
529  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
530  FAIL_IF(unlikely(p == NULL));
531  p->flow = f;
532 
533  Signature *s = NULL;
534  ThreadVars th_v;
535  DetectEngineThreadCtx *det_ctx = NULL;
536 
537  memset(&th_v, 0, sizeof(th_v));
538 
541 
542  de_ctx->flags |= DE_QUIET;
543 
544  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:2_compat; sid:1;)");
545  FAIL_IF_NULL(s);
546 
548  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
549 
550  uint32_t seq = 2;
551  for (int i=0; i<4; i++) {
552  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
553  seq += sshlens[i];
554  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
555  }
556 
557  void *ssh_state = f->alstate;
558  FAIL_IF_NULL(ssh_state);
559 
560  /* do detect */
561  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
562 
563  FAIL_IF(PacketAlertCheck(p, 1));
564 
565  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
567 
568  UTHFreePacket(p);
570  StreamTcpUTDeinit(ra_ctx);
571  UTHFreeFlow(f);
572  PASS;
573 }
574 
575 /**
576  * \brief this function registers unit tests for DetectSshVersion
577  */
578 static void DetectSshVersionRegisterTests(void)
579 {
580  UtRegisterTest("DetectSshVersionTestParse01", DetectSshVersionTestParse01);
581  UtRegisterTest("DetectSshVersionTestParse02", DetectSshVersionTestParse02);
582  UtRegisterTest("DetectSshVersionTestParse03", DetectSshVersionTestParse03);
583  UtRegisterTest("DetectSshVersionTestDetect01",
584  DetectSshVersionTestDetect01);
585  UtRegisterTest("DetectSshVersionTestDetect02",
586  DetectSshVersionTestDetect02);
587  UtRegisterTest("DetectSshVersionTestDetect03",
588  DetectSshVersionTestDetect03);
589 }
590 #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:54
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:47
SigTableElmt_::url
const char * url
Definition: detect.h:1241
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1498
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:1240
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
Definition: detect-parse.c:2488
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1228
flow-util.h
DetectParseRegex
Definition: detect-parse.h:44
SigTableElmt_::name
const char * name
Definition: detect.h:1238
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:1435
seq
uint32_t seq
Definition: stream-tcp-private.h:2
Flow_::proto
uint8_t proto
Definition: flow.h:379
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:357
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1232
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:785
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2442
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1209
rust.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:287
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:1809
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:447
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1223
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:1349
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:1025
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2609
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:2129
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1236
app-layer-parser.h
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:316
Packet_
Definition: decode.h:428
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:239
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:1951
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:308
StreamTcpUTClearSession
void StreamTcpUTClearSession(TcpSession *ssn)
Definition: stream-tcp-util.c:71
Packet_::flow
struct Flow_ * flow
Definition: decode.h:465
detect-ssh-proto-version.h
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3153
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:1025
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3367
SigMatch_::type
uint16_t type
Definition: detect.h:314
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:76
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:791
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:285
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:284
str
#define str(s)
Definition: suricata-common.h:280
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:1449
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:482
detect-parse.h
Signature_
Signature container.
Definition: detect.h:540
SigMatch_
a single match condition for a signature
Definition: detect.h:313
stream-tcp-util.h
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2403
PARSE_REGEX
#define PARSE_REGEX
Regex for parsing the protoversion string.
Definition: detect-ssh-proto-version.c:61
TcpReassemblyThreadCtx_
Definition: stream-tcp-reassemble.h:59
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:786
TcpSession_
Definition: stream-tcp-private.h:272
flow.h
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:456
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275
flow-var.h
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:354
DetectSshVersionData_::ver
uint8_t * ver
Definition: detect-ssh-proto-version.h:31
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1230
app-layer.h