suricata
detect-ssh-software-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.softwareversion keyword
24  * You can match over the software version string of ssh, and it will
25  * be compared from the beginning of the string so you can say for
26  * example ssh.softwareversion:"PuTTY" and it can match, or you can
27  * also specify the version, something like
28  * ssh.softwareversion:"PuTTY-Release-0.55"
29  * I find this useful to match over a known vulnerable server/client
30  * software version incombination to other checks, so you can know
31  * that the risk is higher
32  */
33 
34 #include "suricata-common.h"
35 #include "threads.h"
36 #include "decode.h"
37 
38 #include "detect.h"
39 #include "detect-parse.h"
40 
41 #include "detect-engine.h"
42 #include "detect-engine-mpm.h"
43 #include "detect-engine-state.h"
44 #include "detect-engine-build.h"
45 
46 #include "flow.h"
47 #include "flow-var.h"
48 #include "flow-util.h"
49 
50 #include "util-debug.h"
51 #include "util-unittest.h"
52 #include "util-unittest-helper.h"
53 
54 #include "app-layer.h"
55 #include "app-layer-parser.h"
56 #include "app-layer-ssh.h"
58 #include "rust.h"
59 
60 #include "stream-tcp.h"
61 
62 /**
63  * \brief Regex for parsing the softwareversion string
64  */
65 #define PARSE_REGEX "^\\s*\"?\\s*?([0-9a-zA-Z\\:\\.\\-\\_\\+\\s+]+)\\s*\"?\\s*$"
66 
67 static DetectParseRegex parse_regex;
68 
69 static int DetectSshSoftwareVersionMatch (DetectEngineThreadCtx *,
70  Flow *, uint8_t, void *, void *,
71  const Signature *, const SigMatchCtx *);
72 static int DetectSshSoftwareVersionSetup (DetectEngineCtx *, Signature *, const char *);
73 #ifdef UNITTESTS
74 static void DetectSshSoftwareVersionRegisterTests(void);
75 #endif
76 static void DetectSshSoftwareVersionFree(DetectEngineCtx *de_ctx, void *);
77 static int g_ssh_banner_list_id = 0;
78 
79 
80 /**
81  * \brief Registration function for keyword: ssh.softwareversion
82  */
84 {
85  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].name = "ssh.softwareversion";
86  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].desc = "match SSH software string";
87  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].url = "/rules/ssh-keywords.html#ssh-softwareversion";
88  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].AppLayerTxMatch = DetectSshSoftwareVersionMatch;
89  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].Setup = DetectSshSoftwareVersionSetup;
90  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].Free = DetectSshSoftwareVersionFree;
91 #ifdef UNITTESTS
92  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].RegisterTests = DetectSshSoftwareVersionRegisterTests;
93 #endif
96 
97  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
98 
99  g_ssh_banner_list_id = DetectBufferTypeRegister("ssh_banner");
100 
102  SshStateBannerDone, DetectEngineInspectGenericList, NULL);
104  SshStateBannerDone, DetectEngineInspectGenericList, NULL);
105 }
106 
107 /**
108  * \brief match the specified version on a ssh session
109  *
110  * \param t pointer to thread vars
111  * \param det_ctx pointer to the pattern matcher thread
112  * \param p pointer to the current packet
113  * \param m pointer to the sigmatch that we will cast into DetectSshSoftwareVersionData
114  *
115  * \retval 0 no match
116  * \retval 1 match
117  */
118 static int DetectSshSoftwareVersionMatch (DetectEngineThreadCtx *det_ctx,
119  Flow *f, uint8_t flags, void *state, void *txv,
120  const Signature *s, const SigMatchCtx *m)
121 {
122  SCEnter();
123 
125  if (state == NULL) {
126  SCLogDebug("no ssh state, no match");
127  SCReturnInt(0);
128  }
129 
130  int ret = 0;
131  const uint8_t *software = NULL;
132  uint32_t b_len = 0;
133 
134  if (rs_ssh_tx_get_software(txv, &software, &b_len, flags) != 1)
135  SCReturnInt(0);
136  if (software == NULL || b_len == 0)
137  SCReturnInt(0);
138  if (b_len == ssh->len) {
139  if (memcmp(software, ssh->software_ver, ssh->len) == 0) {
140  ret = 1;
141  }
142  }
143 
144  SCReturnInt(ret);
145 }
146 
147 /**
148  * \brief This function is used to parse IPV4 ip_id passed via keyword: "id"
149  *
150  * \param de_ctx Pointer to the detection engine context
151  * \param idstr Pointer to the user provided id option
152  *
153  * \retval id_d pointer to DetectSshSoftwareVersionData on success
154  * \retval NULL on failure
155  */
156 static DetectSshSoftwareVersionData *DetectSshSoftwareVersionParse (DetectEngineCtx *de_ctx, const char *str)
157 {
158  DetectSshSoftwareVersionData *ssh = NULL;
159  int ret = 0, res = 0;
160  size_t pcre2_len;
161 
162  ret = DetectParsePcreExec(&parse_regex, str, 0, 0);
163 
164  if (ret < 1 || ret > 3) {
165  SCLogError(SC_ERR_PCRE_MATCH, "invalid ssh.softwareversion option");
166  goto error;
167  }
168 
169  if (ret > 1) {
170  const char *str_ptr = NULL;
171  res = pcre2_substring_get_bynumber(
172  parse_regex.match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
173  if (res < 0) {
174  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_get_bynumber failed");
175  goto error;
176  }
177 
178  /* We have a correct id option */
179  ssh = SCMalloc(sizeof(DetectSshSoftwareVersionData));
180  if (unlikely(ssh == NULL))
181  goto error;
182 
183  ssh->software_ver = (uint8_t *)SCStrdup((char *)str_ptr);
184  if (ssh->software_ver == NULL) {
185  goto error;
186  }
187  pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
188 
189  ssh->len = (uint16_t)strlen((char *)ssh->software_ver);
190 
191  SCLogDebug("will look for ssh %s", ssh->software_ver);
192  }
193 
194  return ssh;
195 
196 error:
197  if (ssh != NULL)
198  DetectSshSoftwareVersionFree(de_ctx, ssh);
199  return NULL;
200 
201 }
202 
203 /**
204  * \brief this function is used to add the parsed "id" option
205  * \brief into the current signature
206  *
207  * \param de_ctx pointer to the Detection Engine Context
208  * \param s pointer to the Current Signature
209  * \param idstr pointer to the user provided "id" option
210  *
211  * \retval 0 on Success
212  * \retval -1 on Failure
213  */
214 static int DetectSshSoftwareVersionSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
215 {
216  DetectSshSoftwareVersionData *ssh = NULL;
217  SigMatch *sm = NULL;
218 
220  return -1;
221 
222  ssh = DetectSshSoftwareVersionParse(NULL, str);
223  if (ssh == NULL)
224  goto error;
225 
226  /* Okay so far so good, lets get this into a SigMatch
227  * and put it in the Signature. */
228  sm = SigMatchAlloc();
229  if (sm == NULL)
230  goto error;
231 
233  sm->ctx = (void *)ssh;
234 
235  SigMatchAppendSMToList(s, sm, g_ssh_banner_list_id);
236  return 0;
237 
238 error:
239  if (ssh != NULL)
240  DetectSshSoftwareVersionFree(de_ctx, ssh);
241  if (sm != NULL)
242  SCFree(sm);
243  return -1;
244 
245 }
246 
247 /**
248  * \brief this function will free memory associated with DetectSshSoftwareVersionData
249  *
250  * \param id_d pointer to DetectSshSoftwareVersionData
251  */
252 static void DetectSshSoftwareVersionFree(DetectEngineCtx *de_ctx, void *ptr)
253 {
254  if (ptr == NULL)
255  return;
256 
258  if (ssh->software_ver != NULL)
259  SCFree(ssh->software_ver);
260  SCFree(ssh);
261 }
262 
263 #ifdef UNITTESTS /* UNITTESTS */
264 
265 /**
266  * \test DetectSshSoftwareVersionTestParse01 is a test to make sure that we parse
267  * a software version correctly
268  */
269 static int DetectSshSoftwareVersionTestParse01 (void)
270 {
271  DetectSshSoftwareVersionData *ssh = NULL;
272  ssh = DetectSshSoftwareVersionParse(NULL, "PuTTY_1.0");
273  if (ssh != NULL && strncmp((char *) ssh->software_ver, "PuTTY_1.0", 9) == 0) {
274  DetectSshSoftwareVersionFree(NULL, ssh);
275  return 1;
276  }
277 
278  return 0;
279 }
280 
281 /**
282  * \test DetectSshSoftwareVersionTestParse02 is a test to make sure that we parse
283  * the software version correctly
284  */
285 static int DetectSshSoftwareVersionTestParse02 (void)
286 {
287  DetectSshSoftwareVersionData *ssh = NULL;
288  ssh = DetectSshSoftwareVersionParse(NULL, "\"SecureCRT-4.0\"");
289  if (ssh != NULL && strncmp((char *) ssh->software_ver, "SecureCRT-4.0", 13) == 0) {
290  DetectSshSoftwareVersionFree(NULL, ssh);
291  return 1;
292  }
293 
294  return 0;
295 }
296 
297 /**
298  * \test DetectSshSoftwareVersionTestParse03 is a test to make sure that we
299  * don't return a ssh_data with an empty value specified
300  */
301 static int DetectSshSoftwareVersionTestParse03 (void)
302 {
303  DetectSshSoftwareVersionData *ssh = NULL;
304  ssh = DetectSshSoftwareVersionParse(NULL, "");
305  if (ssh != NULL) {
306  DetectSshSoftwareVersionFree(NULL, ssh);
307  return 0;
308  }
309 
310  return 1;
311 }
312 
313 
314 #include "stream-tcp-reassemble.h"
315 #include "stream-tcp-util.h"
316 
317 /** \test Send a get request in three chunks + more data. */
318 static int DetectSshSoftwareVersionTestDetect01(void)
319 {
320  TcpReassemblyThreadCtx *ra_ctx = NULL;
321  ThreadVars tv;
322  TcpSession ssn;
323  Flow *f = NULL;
324  Packet *p = NULL;
325 
326  uint8_t sshbuf1[] = "SSH-1.";
327  uint8_t sshbuf2[] = "10-PuTTY_2.123" ;
328  uint8_t sshbuf3[] = "\n";
329  uint8_t sshbuf4[] = "whatever...";
330 
331  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
332  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
333 
334  memset(&tv, 0x00, sizeof(tv));
335 
336  StreamTcpUTInit(&ra_ctx);
341 
342  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
343  FAIL_IF_NULL(f);
344  f->protoctx = &ssn;
345  f->proto = IPPROTO_TCP;
346  f->alproto = ALPROTO_SSH;
347 
348  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
349  FAIL_IF(unlikely(p == NULL));
350  p->flow = f;
351 
352  Signature *s = NULL;
353  ThreadVars th_v;
354  DetectEngineThreadCtx *det_ctx = NULL;
355 
356  memset(&th_v, 0, sizeof(th_v));
357 
360 
361  de_ctx->flags |= DE_QUIET;
362 
363  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.softwareversion:PuTTY_2.123; sid:1;)");
364  FAIL_IF_NULL(s);
365 
367  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
368 
369  uint32_t seq = 2;
370  for (int i=0; i<4; i++) {
371  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
372  seq += sshlens[i];
373  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
374  }
375 
376  void *ssh_state = f->alstate;
377  FAIL_IF_NULL(ssh_state);
378 
379  /* do detect */
380  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
381 
382  FAIL_IF(PacketAlertCheck(p, 1));
383 
384  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
386 
387  UTHFreePacket(p);
389  StreamTcpUTDeinit(ra_ctx);
390  UTHFreeFlow(f);
391  PASS;
392 }
393 
394 /** \test Send a get request in three chunks + more data. */
395 static int DetectSshSoftwareVersionTestDetect02(void)
396 {
397  TcpReassemblyThreadCtx *ra_ctx = NULL;
398  ThreadVars tv;
399  TcpSession ssn;
400  Flow *f = NULL;
401  Packet *p = NULL;
402 
403  uint8_t sshbuf1[] = "SSH-1.99-Pu";
404  uint8_t sshbuf2[] = "TTY_2.123" ;
405  uint8_t sshbuf3[] = "\n";
406  uint8_t sshbuf4[] = "whatever...";
407 
408  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
409  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
410 
411  memset(&tv, 0x00, sizeof(tv));
412 
413  StreamTcpUTInit(&ra_ctx);
418 
419  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
420  FAIL_IF_NULL(f);
421  f->protoctx = &ssn;
422  f->proto = IPPROTO_TCP;
423  f->alproto = ALPROTO_SSH;
424 
425  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
426  FAIL_IF(unlikely(p == NULL));
427  p->flow = f;
428 
429  Signature *s = NULL;
430  ThreadVars th_v;
431  DetectEngineThreadCtx *det_ctx = NULL;
432 
433  memset(&th_v, 0, sizeof(th_v));
434 
437 
438  de_ctx->flags |= DE_QUIET;
439 
440  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.softwareversion:PuTTY_2.123; sid:1;)");
441  FAIL_IF_NULL(s);
442 
444  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
445 
446  uint32_t seq = 2;
447  for (int i=0; i<4; i++) {
448  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
449  seq += sshlens[i];
450  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
451  }
452 
453  void *ssh_state = f->alstate;
454  FAIL_IF_NULL(ssh_state);
455 
456  /* do detect */
457  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
458 
459  FAIL_IF(PacketAlertCheck(p, 1));
460 
461  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
463 
464  UTHFreePacket(p);
466  StreamTcpUTDeinit(ra_ctx);
467  UTHFreeFlow(f);
468  PASS;
469 }
470 
471 /** \test Send a get request in three chunks + more data. */
472 static int DetectSshSoftwareVersionTestDetect03(void)
473 {
474  TcpReassemblyThreadCtx *ra_ctx = NULL;
475  ThreadVars tv;
476  TcpSession ssn;
477  Flow *f = NULL;
478  Packet *p = NULL;
479 
480  uint8_t sshbuf1[] = "SSH-1.";
481  uint8_t sshbuf2[] = "7-PuTTY_2.123" ;
482  uint8_t sshbuf3[] = "\n";
483  uint8_t sshbuf4[] = "whatever...";
484 
485  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
486  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
487 
488  memset(&tv, 0x00, sizeof(tv));
489 
490  StreamTcpUTInit(&ra_ctx);
495 
496  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
497  FAIL_IF_NULL(f);
498  f->protoctx = &ssn;
499  f->proto = IPPROTO_TCP;
500  f->alproto = ALPROTO_SSH;
501 
502  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
503  FAIL_IF(unlikely(p == NULL));
504  p->flow = f;
505 
506  Signature *s = NULL;
507  ThreadVars th_v;
508  DetectEngineThreadCtx *det_ctx = NULL;
509 
510  memset(&th_v, 0, sizeof(th_v));
511 
514 
515  de_ctx->flags |= DE_QUIET;
516 
517  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.softwareversion:lalala-3.1.4; sid:1;)");
518  FAIL_IF_NULL(s);
519 
521  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
522 
523  uint32_t seq = 2;
524  for (int i=0; i<4; i++) {
525  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
526  seq += sshlens[i];
527  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
528  }
529 
530  void *ssh_state = f->alstate;
531  FAIL_IF_NULL(ssh_state);
532 
533  /* do detect */
534  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
535 
536  FAIL_IF(PacketAlertCheck(p, 1));
537 
538  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
540 
541  UTHFreePacket(p);
543  StreamTcpUTDeinit(ra_ctx);
544  UTHFreeFlow(f);
545  PASS;
546 }
547 
548 /**
549  * \brief this function registers unit tests for DetectSshSoftwareVersion
550  */
551 static void DetectSshSoftwareVersionRegisterTests(void)
552 {
553  UtRegisterTest("DetectSshSoftwareVersionTestParse01",
554  DetectSshSoftwareVersionTestParse01);
555  UtRegisterTest("DetectSshSoftwareVersionTestParse02",
556  DetectSshSoftwareVersionTestParse02);
557  UtRegisterTest("DetectSshSoftwareVersionTestParse03",
558  DetectSshSoftwareVersionTestParse03);
559  UtRegisterTest("DetectSshSoftwareVersionTestDetect01",
560  DetectSshSoftwareVersionTestDetect01);
561  UtRegisterTest("DetectSshSoftwareVersionTestDetect02",
562  DetectSshSoftwareVersionTestDetect02);
563  UtRegisterTest("DetectSshSoftwareVersionTestDetect03",
564  DetectSshSoftwareVersionTestDetect03);
565 }
566 #endif /* UNITTESTS */
UPDATE_DIR_PACKET
@ UPDATE_DIR_PACKET
Definition: stream-tcp-reassemble.h:57
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:45
SigTableElmt_::url
const char * url
Definition: detect.h:1248
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1490
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:1247
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
Definition: detect-parse.c:2475
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1235
flow-util.h
DetectParseRegex
Definition: detect-parse.h:42
DetectSshSoftwareVersionData_
Definition: detect-ssh-software-version.h:27
SigTableElmt_::name
const char * name
Definition: detect.h:1245
DetectSshSoftwareVersionRegister
void DetectSshSoftwareVersionRegister(void)
Registration function for keyword: ssh.softwareversion.
Definition: detect-ssh-software-version.c:83
stream-tcp.h
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:296
SIGMATCH_QUOTES_OPTIONAL
#define SIGMATCH_QUOTES_OPTIONAL
Definition: detect.h:1443
seq
uint32_t seq
Definition: stream-tcp-private.h:2
Flow_::proto
uint8_t proto
Definition: flow.h:375
DetectSshSoftwareVersionData_::len
uint16_t len
Definition: detect-ssh-software-version.h:29
DETECT_AL_SSH_SOFTWAREVERSION
@ DETECT_AL_SSH_SOFTWAREVERSION
Definition: detect-engine-register.h:169
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:142
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:2116
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1239
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:785
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2445
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1216
rust.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:288
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:338
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1785
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
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:231
Flow_::protoctx
void * protoctx
Definition: flow.h:451
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1230
StreamTcpUTInitInline
void StreamTcpUTInitInline(void)
Definition: stream-tcp-util.c:58
util-unittest.h
util-unittest-helper.h
DetectSshSoftwareVersionData_::software_ver
uint8_t * software_ver
Definition: detect-ssh-software-version.h:28
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:522
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:1301
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:230
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:1034
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2598
SCEnter
#define SCEnter(...)
Definition: util-debug.h:298
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:56
DETECT_AL_SSH_SOFTWARE
@ DETECT_AL_SSH_SOFTWARE
Definition: detect-engine-register.h:168
StreamTcpUTSetupStream
void StreamTcpUTSetupStream(TcpStream *s, uint32_t isn)
Definition: stream-tcp-util.c:79
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1243
PARSE_REGEX
#define PARSE_REGEX
Regex for parsing the softwareversion string.
Definition: detect-ssh-software-version.c:65
app-layer-parser.h
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:317
Packet_
Definition: decode.h:434
detect-engine-build.h
DetectAppLayerInspectEngineRegister2
void DetectAppLayerInspectEngineRegister2(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr2 Callback2, InspectionBufferGetDataPtr GetData)
register inspect engine at start up time
Definition: detect-engine.c:227
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:1953
UTHFreeFlow
void UTHFreeFlow(Flow *flow)
Definition: util-unittest-helper.c:527
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:309
StreamTcpUTClearSession
void StreamTcpUTClearSession(TcpSession *ssn)
Definition: stream-tcp-util.c:71
detect-ssh-software-version.h
Packet_::flow
struct Flow_ * flow
Definition: decode.h:471
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3154
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:1032
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3368
SigMatch_::type
uint16_t type
Definition: detect.h:315
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:255
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:791
DetectEngineInspectGenericList
uint8_t DetectEngineInspectGenericList(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:1951
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:284
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:31
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:283
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:1457
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:486
Flow_::alstate
void * alstate
Definition: flow.h:486
detect-parse.h
Signature_
Signature container.
Definition: detect.h:540
SigMatch_
a single match condition for a signature
Definition: detect.h:314
stream-tcp-util.h
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2406
TcpReassemblyThreadCtx_
Definition: stream-tcp-reassemble.h:62
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:786
TcpSession_
Definition: stream-tcp-private.h:271
flow.h
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:460
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:302
flow-var.h
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:349
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1237
app-layer.h