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  int ov[MAX_SUBSTRINGS];
165 
166  ret = DetectParsePcreExec(&parse_regex, str, 0, 0, ov, MAX_SUBSTRINGS);
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 = pcre_get_substring((char *)str, ov, MAX_SUBSTRINGS, 1, &str_ptr);
175  if (res < 0) {
176  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
177  goto error;
178  }
179 
180  /* We have a correct id option */
181  ssh = SCMalloc(sizeof(DetectSshVersionData));
182  if (unlikely(ssh == NULL)) {
183  pcre_free_substring(str_ptr);
184  goto error;
185  }
186  memset(ssh, 0x00, sizeof(DetectSshVersionData));
187 
188  /* If we expect a protocol version 2 or 1.99 (considered 2, we
189  * will compare it with both strings) */
190  if (strcmp("2_compat", str_ptr) == 0) {
192  SCLogDebug("will look for ssh protocol version 2 (2, 2.0, 1.99 that's considered as 2");
193  pcre_free_substring(str_ptr);
194  return ssh;
195  }
196 
197  ssh->ver = (uint8_t *)SCStrdup((char*)str_ptr);
198  if (ssh->ver == NULL) {
199  pcre_free_substring(str_ptr);
200  goto error;
201  }
202  ssh->len = strlen((char *) ssh->ver);
203  pcre_free_substring(str_ptr);
204 
205  SCLogDebug("will look for ssh %s", ssh->ver);
206  }
207 
208  return ssh;
209 
210 error:
211  if (ssh != NULL)
212  DetectSshVersionFree(de_ctx, ssh);
213  return NULL;
214 
215 }
216 
217 /**
218  * \brief this function is used to add the parsed "id" option
219  * \brief into the current signature
220  *
221  * \param de_ctx pointer to the Detection Engine Context
222  * \param s pointer to the Current Signature
223  * \param idstr pointer to the user provided "id" option
224  *
225  * \retval 0 on Success
226  * \retval -1 on Failure
227  */
228 static int DetectSshVersionSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
229 {
230  DetectSshVersionData *ssh = NULL;
231  SigMatch *sm = NULL;
232 
234  return -1;
235 
236  ssh = DetectSshVersionParse(de_ctx, str);
237  if (ssh == NULL)
238  goto error;
239 
240  /* Okay so far so good, lets get this into a SigMatch
241  * and put it in the Signature. */
242  sm = SigMatchAlloc();
243  if (sm == NULL)
244  goto error;
245 
247  sm->ctx = (void *)ssh;
248 
249  SigMatchAppendSMToList(s, sm, g_ssh_banner_list_id);
250  return 0;
251 
252 error:
253  if (ssh != NULL)
254  DetectSshVersionFree(de_ctx, ssh);
255  if (sm != NULL)
256  SCFree(sm);
257  return -1;
258 
259 }
260 
261 /**
262  * \brief this function will free memory associated with DetectSshVersionData
263  *
264  * \param id_d pointer to DetectSshVersionData
265  */
266 void DetectSshVersionFree(DetectEngineCtx *de_ctx, void *ptr)
267 {
269  SCFree(sshd->ver);
270  SCFree(sshd);
271 }
272 
273 #ifdef UNITTESTS /* UNITTESTS */
274 
275 /**
276  * \test DetectSshVersionTestParse01 is a test to make sure that we parse
277  * a proto version correctly
278  */
279 static int DetectSshVersionTestParse01 (void)
280 {
281  DetectSshVersionData *ssh = NULL;
282  ssh = DetectSshVersionParse(NULL, "1.0");
283  if (ssh != NULL && strncmp((char *) ssh->ver, "1.0", 3) == 0) {
284  DetectSshVersionFree(NULL, ssh);
285  return 1;
286  }
287 
288  return 0;
289 }
290 
291 /**
292  * \test DetectSshVersionTestParse02 is a test to make sure that we parse
293  * the proto version (compatible with proto version 2) correctly
294  */
295 static int DetectSshVersionTestParse02 (void)
296 {
297  DetectSshVersionData *ssh = NULL;
298  ssh = DetectSshVersionParse(NULL, "2_compat");
300  DetectSshVersionFree(NULL, ssh);
301  return 1;
302  }
303 
304  return 0;
305 }
306 
307 /**
308  * \test DetectSshVersionTestParse03 is a test to make sure that we
309  * don't return a ssh_data with an invalid value specified
310  */
311 static int DetectSshVersionTestParse03 (void)
312 {
313  DetectSshVersionData *ssh = NULL;
314  ssh = DetectSshVersionParse(NULL, "2_com");
315  if (ssh != NULL) {
316  DetectSshVersionFree(NULL, ssh);
317  return 0;
318  }
319  ssh = DetectSshVersionParse(NULL, "");
320  if (ssh != NULL) {
321  DetectSshVersionFree(NULL, ssh);
322  return 0;
323  }
324  ssh = DetectSshVersionParse(NULL, ".1");
325  if (ssh != NULL) {
326  DetectSshVersionFree(NULL, ssh);
327  return 0;
328  }
329  ssh = DetectSshVersionParse(NULL, "lalala");
330  if (ssh != NULL) {
331  DetectSshVersionFree(NULL, ssh);
332  return 0;
333  }
334 
335  return 1;
336 }
337 
338 
339 #include "stream-tcp-reassemble.h"
340 #include "stream-tcp-util.h"
341 
342 /** \test Send a get request in three chunks + more data. */
343 static int DetectSshVersionTestDetect01(void)
344 {
345  TcpReassemblyThreadCtx *ra_ctx = NULL;
346  ThreadVars tv;
347  TcpSession ssn;
348  Flow *f = NULL;
349  Packet *p = NULL;
350 
351  uint8_t sshbuf1[] = "SSH-1.";
352  uint8_t sshbuf2[] = "10-PuTTY_2.123" ;
353  uint8_t sshbuf3[] = "\n";
354  uint8_t sshbuf4[] = "whatever...";
355 
356  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
357  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
358 
359  memset(&tv, 0x00, sizeof(tv));
360 
361  StreamTcpUTInit(&ra_ctx);
366 
367  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
368  FAIL_IF_NULL(f);
369  f->protoctx = &ssn;
370  f->proto = IPPROTO_TCP;
371  f->alproto = ALPROTO_SSH;
372 
373  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
374  FAIL_IF(unlikely(p == NULL));
375  p->flow = f;
376 
377  Signature *s = NULL;
378  ThreadVars th_v;
379  DetectEngineThreadCtx *det_ctx = NULL;
380 
381  memset(&th_v, 0, sizeof(th_v));
382 
385 
386  de_ctx->flags |= DE_QUIET;
387 
388  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:1.10; sid:1;)");
389  FAIL_IF_NULL(s);
390 
392  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
393 
394  uint32_t seq = 2;
395  for (int i=0; i<4; i++) {
396  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
397  seq += sshlens[i];
398  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
399  }
400 
401  void *ssh_state = f->alstate;
402  FAIL_IF_NULL(ssh_state);
403 
404  /* do detect */
405  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
406 
407  FAIL_IF(PacketAlertCheck(p, 1));
408 
409  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
411 
412  UTHFreePacket(p);
414  StreamTcpUTDeinit(ra_ctx);
415  UTHFreeFlow(f);
416  PASS;
417 }
418 
419 /** \test Send a get request in three chunks + more data. */
420 static int DetectSshVersionTestDetect02(void)
421 {
422  TcpReassemblyThreadCtx *ra_ctx = NULL;
423  ThreadVars tv;
424  TcpSession ssn;
425  Flow *f = NULL;
426  Packet *p = NULL;
427 
428  uint8_t sshbuf1[] = "SSH-1.99-Pu";
429  uint8_t sshbuf2[] = "TTY_2.123" ;
430  uint8_t sshbuf3[] = "\n";
431  uint8_t sshbuf4[] = "whatever...";
432 
433  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
434  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
435 
436  memset(&tv, 0x00, sizeof(tv));
437 
438  StreamTcpUTInit(&ra_ctx);
443 
444  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
445  FAIL_IF_NULL(f);
446  f->protoctx = &ssn;
447  f->proto = IPPROTO_TCP;
448  f->alproto = ALPROTO_SSH;
449 
450  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
451  FAIL_IF(unlikely(p == NULL));
452  p->flow = f;
453 
454  Signature *s = NULL;
455  ThreadVars th_v;
456  DetectEngineThreadCtx *det_ctx = NULL;
457 
458  memset(&th_v, 0, sizeof(th_v));
459 
462 
463  de_ctx->flags |= DE_QUIET;
464 
465  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:2_compat; sid:1;)");
466  FAIL_IF_NULL(s);
467 
469  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
470 
471  uint32_t seq = 2;
472  for (int i=0; i<4; i++) {
473  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
474  seq += sshlens[i];
475  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
476  }
477 
478  void *ssh_state = f->alstate;
479  FAIL_IF_NULL(ssh_state);
480 
481  /* do detect */
482  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
483 
484  FAIL_IF(PacketAlertCheck(p, 1));
485 
486  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
488 
489  UTHFreePacket(p);
491  StreamTcpUTDeinit(ra_ctx);
492  UTHFreeFlow(f);
493  PASS;
494 }
495 
496 /** \test Send a get request in three chunks + more data. */
497 static int DetectSshVersionTestDetect03(void)
498 {
499  TcpReassemblyThreadCtx *ra_ctx = NULL;
500  ThreadVars tv;
501  TcpSession ssn;
502  Flow *f = NULL;
503  Packet *p = NULL;
504 
505  uint8_t sshbuf1[] = "SSH-1.";
506  uint8_t sshbuf2[] = "7-PuTTY_2.123" ;
507  uint8_t sshbuf3[] = "\n";
508  uint8_t sshbuf4[] = "whatever...";
509 
510  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
511  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
512 
513  memset(&tv, 0x00, sizeof(tv));
514 
515  StreamTcpUTInit(&ra_ctx);
520 
521  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
522  FAIL_IF_NULL(f);
523  f->protoctx = &ssn;
524  f->proto = IPPROTO_TCP;
525  f->alproto = ALPROTO_SSH;
526 
527  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
528  FAIL_IF(unlikely(p == NULL));
529  p->flow = f;
530 
531  Signature *s = NULL;
532  ThreadVars th_v;
533  DetectEngineThreadCtx *det_ctx = NULL;
534 
535  memset(&th_v, 0, sizeof(th_v));
536 
539 
540  de_ctx->flags |= DE_QUIET;
541 
542  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.protoversion:2_compat; sid:1;)");
543  FAIL_IF_NULL(s);
544 
546  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
547 
548  uint32_t seq = 2;
549  for (int i=0; i<4; i++) {
550  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
551  seq += sshlens[i];
552  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
553  }
554 
555  void *ssh_state = f->alstate;
556  FAIL_IF_NULL(ssh_state);
557 
558  /* do detect */
559  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
560 
561  FAIL_IF(PacketAlertCheck(p, 1));
562 
563  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
565 
566  UTHFreePacket(p);
568  StreamTcpUTDeinit(ra_ctx);
569  UTHFreeFlow(f);
570  PASS;
571 }
572 
573 /**
574  * \brief this function registers unit tests for DetectSshVersion
575  */
576 static void DetectSshVersionRegisterTests(void)
577 {
578  UtRegisterTest("DetectSshVersionTestParse01", DetectSshVersionTestParse01);
579  UtRegisterTest("DetectSshVersionTestParse02", DetectSshVersionTestParse02);
580  UtRegisterTest("DetectSshVersionTestParse03", DetectSshVersionTestParse03);
581  UtRegisterTest("DetectSshVersionTestDetect01",
582  DetectSshVersionTestDetect01);
583  UtRegisterTest("DetectSshVersionTestDetect02",
584  DetectSshVersionTestDetect02);
585  UtRegisterTest("DetectSshVersionTestDetect03",
586  DetectSshVersionTestDetect03);
587 }
588 #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:1214
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1480
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:1213
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1201
flow-util.h
SigTableElmt_::name
const char * name
Definition: detect.h:1211
stream-tcp.h
MAX_SUBSTRINGS
#define MAX_SUBSTRINGS
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:1392
seq
uint32_t seq
Definition: stream-tcp-private.h:2
Flow_::proto
uint8_t proto
Definition: flow.h:365
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:138
DETECT_AL_SSH_PROTOVERSION
@ DETECT_AL_SSH_PROTOVERSION
Definition: detect-engine-register.h:161
threads.h
Flow_
Flow data structure.
Definition: flow.h:347
SigInit
Signature * SigInit(DetectEngineCtx *, const char *)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2056
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1205
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:767
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2093
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1182
rust.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:294
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
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:441
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1196
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:1194
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:1010
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2493
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:1209
app-layer-parser.h
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:323
SigMatchSignatures
void SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1688
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options, int *ovector, int ovector_size)
Definition: detect-parse.c:2423
Packet_
Definition: decode.h:414
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:1888
SigMatch_::type
uint8_t type
Definition: detect.h:321
DETECT_AL_SSH_PROTOCOL
@ DETECT_AL_SSH_PROTOCOL
Definition: detect-engine-register.h:160
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:315
StreamTcpUTClearSession
void StreamTcpUTClearSession(TcpSession *ssn)
Definition: stream-tcp-util.c:71
Packet_::flow
struct Flow_ * flow
Definition: decode.h:451
detect-ssh-proto-version.h
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:2797
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:71
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition: detect-engine.c:836
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3005
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
DetectParseRegex_
Definition: detect-parse.h:42
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:773
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:273
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SIGMATCH_INFO_DEPRECATED
#define SIGMATCH_INFO_DEPRECATED
Definition: detect.h:1406
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:476
detect-parse.h
Signature_
Signature container.
Definition: detect.h:528
SigMatch_
a single match condition for a signature
Definition: detect.h:320
stream-tcp-util.h
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2048
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:768
TcpSession_
Definition: stream-tcp-private.h:260
flow.h
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:450
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:1203
app-layer.h