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 "debug.h"
37 #include "decode.h"
38 
39 #include "detect.h"
40 #include "detect-parse.h"
41 
42 #include "detect-engine.h"
43 #include "detect-engine-mpm.h"
44 #include "detect-engine-state.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 static int InspectSshBanner(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
80  const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f,
81  uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
82 {
84  de_ctx, det_ctx, s, engine->smd, f, flags, alstate, txv, tx_id);
85 }
86 
87 /**
88  * \brief Registration function for keyword: ssh.softwareversion
89  */
91 {
92  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].name = "ssh.softwareversion";
93  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].desc = "match SSH software string";
94  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].url = "/rules/ssh-keywords.html#ssh-softwareversion";
95  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].AppLayerTxMatch = DetectSshSoftwareVersionMatch;
96  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].Setup = DetectSshSoftwareVersionSetup;
97  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].Free = DetectSshSoftwareVersionFree;
98 #ifdef UNITTESTS
99  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].RegisterTests = DetectSshSoftwareVersionRegisterTests;
100 #endif
103 
104  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
105 
106  g_ssh_banner_list_id = DetectBufferTypeRegister("ssh_banner");
107 
109  SshStateBannerDone, InspectSshBanner, NULL);
111  SshStateBannerDone, InspectSshBanner, NULL);
112 }
113 
114 /**
115  * \brief match the specified version on a ssh session
116  *
117  * \param t pointer to thread vars
118  * \param det_ctx pointer to the pattern matcher thread
119  * \param p pointer to the current packet
120  * \param m pointer to the sigmatch that we will cast into DetectSshSoftwareVersionData
121  *
122  * \retval 0 no match
123  * \retval 1 match
124  */
125 static int DetectSshSoftwareVersionMatch (DetectEngineThreadCtx *det_ctx,
126  Flow *f, uint8_t flags, void *state, void *txv,
127  const Signature *s, const SigMatchCtx *m)
128 {
129  SCEnter();
130 
132  if (state == NULL) {
133  SCLogDebug("no ssh state, no match");
134  SCReturnInt(0);
135  }
136 
137  int ret = 0;
138  const uint8_t *software = NULL;
139  uint32_t b_len = 0;
140 
141  if (rs_ssh_tx_get_software(txv, &software, &b_len, flags) != 1)
142  SCReturnInt(0);
143  if (software == NULL || b_len == 0)
144  SCReturnInt(0);
145  if (b_len == ssh->len) {
146  if (memcmp(software, ssh->software_ver, ssh->len) == 0) {
147  ret = 1;
148  }
149  }
150 
151  SCReturnInt(ret);
152 }
153 
154 /**
155  * \brief This function is used to parse IPV4 ip_id passed via keyword: "id"
156  *
157  * \param de_ctx Pointer to the detection engine context
158  * \param idstr Pointer to the user provided id option
159  *
160  * \retval id_d pointer to DetectSshSoftwareVersionData on success
161  * \retval NULL on failure
162  */
163 static DetectSshSoftwareVersionData *DetectSshSoftwareVersionParse (DetectEngineCtx *de_ctx, const char *str)
164 {
165  DetectSshSoftwareVersionData *ssh = NULL;
166  int ret = 0, res = 0;
167  size_t pcre2_len;
168 
169  ret = DetectParsePcreExec(&parse_regex, str, 0, 0);
170 
171  if (ret < 1 || ret > 3) {
172  SCLogError(SC_ERR_PCRE_MATCH, "invalid ssh.softwareversion option");
173  goto error;
174  }
175 
176  if (ret > 1) {
177  const char *str_ptr = NULL;
178  res = pcre2_substring_get_bynumber(
179  parse_regex.match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
180  if (res < 0) {
181  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_get_bynumber failed");
182  goto error;
183  }
184 
185  /* We have a correct id option */
186  ssh = SCMalloc(sizeof(DetectSshSoftwareVersionData));
187  if (unlikely(ssh == NULL))
188  goto error;
189 
190  ssh->software_ver = (uint8_t *)SCStrdup((char *)str_ptr);
191  if (ssh->software_ver == NULL) {
192  goto error;
193  }
194  pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
195 
196  ssh->len = strlen((char *)ssh->software_ver);
197 
198  SCLogDebug("will look for ssh %s", ssh->software_ver);
199  }
200 
201  return ssh;
202 
203 error:
204  if (ssh != NULL)
205  DetectSshSoftwareVersionFree(de_ctx, ssh);
206  return NULL;
207 
208 }
209 
210 /**
211  * \brief this function is used to add the parsed "id" option
212  * \brief into the current signature
213  *
214  * \param de_ctx pointer to the Detection Engine Context
215  * \param s pointer to the Current Signature
216  * \param idstr pointer to the user provided "id" option
217  *
218  * \retval 0 on Success
219  * \retval -1 on Failure
220  */
221 static int DetectSshSoftwareVersionSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
222 {
223  DetectSshSoftwareVersionData *ssh = NULL;
224  SigMatch *sm = NULL;
225 
227  return -1;
228 
229  ssh = DetectSshSoftwareVersionParse(NULL, str);
230  if (ssh == NULL)
231  goto error;
232 
233  /* Okay so far so good, lets get this into a SigMatch
234  * and put it in the Signature. */
235  sm = SigMatchAlloc();
236  if (sm == NULL)
237  goto error;
238 
240  sm->ctx = (void *)ssh;
241 
242  SigMatchAppendSMToList(s, sm, g_ssh_banner_list_id);
243  return 0;
244 
245 error:
246  if (ssh != NULL)
247  DetectSshSoftwareVersionFree(de_ctx, ssh);
248  if (sm != NULL)
249  SCFree(sm);
250  return -1;
251 
252 }
253 
254 /**
255  * \brief this function will free memory associated with DetectSshSoftwareVersionData
256  *
257  * \param id_d pointer to DetectSshSoftwareVersionData
258  */
259 static void DetectSshSoftwareVersionFree(DetectEngineCtx *de_ctx, void *ptr)
260 {
261  if (ptr == NULL)
262  return;
263 
265  if (ssh->software_ver != NULL)
266  SCFree(ssh->software_ver);
267  SCFree(ssh);
268 }
269 
270 #ifdef UNITTESTS /* UNITTESTS */
271 
272 /**
273  * \test DetectSshSoftwareVersionTestParse01 is a test to make sure that we parse
274  * a software version correctly
275  */
276 static int DetectSshSoftwareVersionTestParse01 (void)
277 {
278  DetectSshSoftwareVersionData *ssh = NULL;
279  ssh = DetectSshSoftwareVersionParse(NULL, "PuTTY_1.0");
280  if (ssh != NULL && strncmp((char *) ssh->software_ver, "PuTTY_1.0", 9) == 0) {
281  DetectSshSoftwareVersionFree(NULL, ssh);
282  return 1;
283  }
284 
285  return 0;
286 }
287 
288 /**
289  * \test DetectSshSoftwareVersionTestParse02 is a test to make sure that we parse
290  * the software version correctly
291  */
292 static int DetectSshSoftwareVersionTestParse02 (void)
293 {
294  DetectSshSoftwareVersionData *ssh = NULL;
295  ssh = DetectSshSoftwareVersionParse(NULL, "\"SecureCRT-4.0\"");
296  if (ssh != NULL && strncmp((char *) ssh->software_ver, "SecureCRT-4.0", 13) == 0) {
297  DetectSshSoftwareVersionFree(NULL, ssh);
298  return 1;
299  }
300 
301  return 0;
302 }
303 
304 /**
305  * \test DetectSshSoftwareVersionTestParse03 is a test to make sure that we
306  * don't return a ssh_data with an empty value specified
307  */
308 static int DetectSshSoftwareVersionTestParse03 (void)
309 {
310  DetectSshSoftwareVersionData *ssh = NULL;
311  ssh = DetectSshSoftwareVersionParse(NULL, "");
312  if (ssh != NULL) {
313  DetectSshSoftwareVersionFree(NULL, ssh);
314  return 0;
315  }
316 
317  return 1;
318 }
319 
320 
321 #include "stream-tcp-reassemble.h"
322 #include "stream-tcp-util.h"
323 
324 /** \test Send a get request in three chunks + more data. */
325 static int DetectSshSoftwareVersionTestDetect01(void)
326 {
327  TcpReassemblyThreadCtx *ra_ctx = NULL;
328  ThreadVars tv;
329  TcpSession ssn;
330  Flow *f = NULL;
331  Packet *p = NULL;
332 
333  uint8_t sshbuf1[] = "SSH-1.";
334  uint8_t sshbuf2[] = "10-PuTTY_2.123" ;
335  uint8_t sshbuf3[] = "\n";
336  uint8_t sshbuf4[] = "whatever...";
337 
338  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
339  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
340 
341  memset(&tv, 0x00, sizeof(tv));
342 
343  StreamTcpUTInit(&ra_ctx);
348 
349  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
350  FAIL_IF_NULL(f);
351  f->protoctx = &ssn;
352  f->proto = IPPROTO_TCP;
353  f->alproto = ALPROTO_SSH;
354 
355  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
356  FAIL_IF(unlikely(p == NULL));
357  p->flow = f;
358 
359  Signature *s = NULL;
360  ThreadVars th_v;
361  DetectEngineThreadCtx *det_ctx = NULL;
362 
363  memset(&th_v, 0, sizeof(th_v));
364 
367 
368  de_ctx->flags |= DE_QUIET;
369 
370  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.softwareversion:PuTTY_2.123; sid:1;)");
371  FAIL_IF_NULL(s);
372 
374  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
375 
376  uint32_t seq = 2;
377  for (int i=0; i<4; i++) {
378  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
379  seq += sshlens[i];
380  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
381  }
382 
383  void *ssh_state = f->alstate;
384  FAIL_IF_NULL(ssh_state);
385 
386  /* do detect */
387  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
388 
389  FAIL_IF(PacketAlertCheck(p, 1));
390 
391  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
393 
394  UTHFreePacket(p);
396  StreamTcpUTDeinit(ra_ctx);
397  UTHFreeFlow(f);
398  PASS;
399 }
400 
401 /** \test Send a get request in three chunks + more data. */
402 static int DetectSshSoftwareVersionTestDetect02(void)
403 {
404  TcpReassemblyThreadCtx *ra_ctx = NULL;
405  ThreadVars tv;
406  TcpSession ssn;
407  Flow *f = NULL;
408  Packet *p = NULL;
409 
410  uint8_t sshbuf1[] = "SSH-1.99-Pu";
411  uint8_t sshbuf2[] = "TTY_2.123" ;
412  uint8_t sshbuf3[] = "\n";
413  uint8_t sshbuf4[] = "whatever...";
414 
415  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
416  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
417 
418  memset(&tv, 0x00, sizeof(tv));
419 
420  StreamTcpUTInit(&ra_ctx);
425 
426  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
427  FAIL_IF_NULL(f);
428  f->protoctx = &ssn;
429  f->proto = IPPROTO_TCP;
430  f->alproto = ALPROTO_SSH;
431 
432  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
433  FAIL_IF(unlikely(p == NULL));
434  p->flow = f;
435 
436  Signature *s = NULL;
437  ThreadVars th_v;
438  DetectEngineThreadCtx *det_ctx = NULL;
439 
440  memset(&th_v, 0, sizeof(th_v));
441 
444 
445  de_ctx->flags |= DE_QUIET;
446 
447  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.softwareversion:PuTTY_2.123; sid:1;)");
448  FAIL_IF_NULL(s);
449 
451  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
452 
453  uint32_t seq = 2;
454  for (int i=0; i<4; i++) {
455  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
456  seq += sshlens[i];
457  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
458  }
459 
460  void *ssh_state = f->alstate;
461  FAIL_IF_NULL(ssh_state);
462 
463  /* do detect */
464  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
465 
466  FAIL_IF(PacketAlertCheck(p, 1));
467 
468  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
470 
471  UTHFreePacket(p);
473  StreamTcpUTDeinit(ra_ctx);
474  UTHFreeFlow(f);
475  PASS;
476 }
477 
478 /** \test Send a get request in three chunks + more data. */
479 static int DetectSshSoftwareVersionTestDetect03(void)
480 {
481  TcpReassemblyThreadCtx *ra_ctx = NULL;
482  ThreadVars tv;
483  TcpSession ssn;
484  Flow *f = NULL;
485  Packet *p = NULL;
486 
487  uint8_t sshbuf1[] = "SSH-1.";
488  uint8_t sshbuf2[] = "7-PuTTY_2.123" ;
489  uint8_t sshbuf3[] = "\n";
490  uint8_t sshbuf4[] = "whatever...";
491 
492  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
493  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
494 
495  memset(&tv, 0x00, sizeof(tv));
496 
497  StreamTcpUTInit(&ra_ctx);
502 
503  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
504  FAIL_IF_NULL(f);
505  f->protoctx = &ssn;
506  f->proto = IPPROTO_TCP;
507  f->alproto = ALPROTO_SSH;
508 
509  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
510  FAIL_IF(unlikely(p == NULL));
511  p->flow = f;
512 
513  Signature *s = NULL;
514  ThreadVars th_v;
515  DetectEngineThreadCtx *det_ctx = NULL;
516 
517  memset(&th_v, 0, sizeof(th_v));
518 
521 
522  de_ctx->flags |= DE_QUIET;
523 
524  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.softwareversion:lalala-3.1.4; sid:1;)");
525  FAIL_IF_NULL(s);
526 
528  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
529 
530  uint32_t seq = 2;
531  for (int i=0; i<4; i++) {
532  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
533  seq += sshlens[i];
534  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
535  }
536 
537  void *ssh_state = f->alstate;
538  FAIL_IF_NULL(ssh_state);
539 
540  /* do detect */
541  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
542 
543  FAIL_IF(PacketAlertCheck(p, 1));
544 
545  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
547 
548  UTHFreePacket(p);
550  StreamTcpUTDeinit(ra_ctx);
551  UTHFreeFlow(f);
552  PASS;
553 }
554 
555 /**
556  * \brief this function registers unit tests for DetectSshSoftwareVersion
557  */
558 static void DetectSshSoftwareVersionRegisterTests(void)
559 {
560  UtRegisterTest("DetectSshSoftwareVersionTestParse01",
561  DetectSshSoftwareVersionTestParse01);
562  UtRegisterTest("DetectSshSoftwareVersionTestParse02",
563  DetectSshSoftwareVersionTestParse02);
564  UtRegisterTest("DetectSshSoftwareVersionTestParse03",
565  DetectSshSoftwareVersionTestParse03);
566  UtRegisterTest("DetectSshSoftwareVersionTestDetect01",
567  DetectSshSoftwareVersionTestDetect01);
568  UtRegisterTest("DetectSshSoftwareVersionTestDetect02",
569  DetectSshSoftwareVersionTestDetect02);
570  UtRegisterTest("DetectSshSoftwareVersionTestDetect03",
571  DetectSshSoftwareVersionTestDetect03);
572 }
573 #endif /* UNITTESTS */
UPDATE_DIR_PACKET
@ UPDATE_DIR_PACKET
Definition: stream-tcp-reassemble.h:55
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:45
DetectEngineAppInspectionEngine_
Definition: detect.h:398
SigTableElmt_::url
const char * url
Definition: detect.h:1270
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:1269
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
Definition: detect-parse.c:2474
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1257
flow-util.h
DetectEngineInspectGenericList
int DetectEngineInspectGenericList(const DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const Signature *s, const SigMatchData *smd, Flow *f, const uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
Definition: detect-engine.c:1941
DetectParseRegex
Definition: detect-parse.h:42
DetectSshSoftwareVersionData_
Definition: detect-ssh-software-version.h:27
SigTableElmt_::name
const char * name
Definition: detect.h:1267
DetectSshSoftwareVersionRegister
void DetectSshSoftwareVersionRegister(void)
Registration function for keyword: ssh.softwareversion.
Definition: detect-ssh-software-version.c:90
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:298
SIGMATCH_QUOTES_OPTIONAL
#define SIGMATCH_QUOTES_OPTIONAL
Definition: detect.h:1465
seq
uint32_t seq
Definition: stream-tcp-private.h:2
Flow_::proto
uint8_t proto
Definition: flow.h:375
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:166
PacketAlertCheck
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
Definition: detect-engine-alert.c:137
threads.h
Flow_
Flow data structure.
Definition: flow.h:353
SigInit
Signature * SigInit(DetectEngineCtx *, const char *)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2115
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1261
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:811
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2433
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1238
rust.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:295
stream-tcp-reassemble.h
UTHBuildPacket
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
Definition: util-unittest-helper.c:337
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1790
m
SCMutex m
Definition: flow-hash.h:6
SC_ERR_PCRE_GET_SUBSTRING
@ SC_ERR_PCRE_GET_SUBSTRING
Definition: util-error.h:34
ALPROTO_SSH
@ ALPROTO_SSH
Definition: app-layer-protos.h:34
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:237
Flow_::protoctx
void * protoctx
Definition: flow.h:451
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1252
StreamTcpUTInitInline
void StreamTcpUTInitInline(void)
Definition: stream-tcp-util.c:58
util-unittest.h
util-unittest-helper.h
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:521
StreamTcpReassembleAppLayer
int StreamTcpReassembleAppLayer(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, TcpSession *ssn, TcpStream *stream, Packet *p, enum StreamUpdateDir dir)
Update the stream reassembly upon receiving a packet.
Definition: stream-tcp-reassemble.c:1225
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:236
decode.h
util-debug.h
SC_ERR_PCRE_MATCH
@ SC_ERR_PCRE_MATCH
Definition: util-error.h:32
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1060
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2597
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
DETECT_AL_SSH_SOFTWARE
@ DETECT_AL_SSH_SOFTWARE
Definition: detect-engine-register.h:165
StreamTcpUTSetupStream
void StreamTcpUTSetupStream(TcpStream *s, uint32_t isn)
Definition: stream-tcp-util.c:79
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1265
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:324
Packet_
Definition: decode.h:427
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:225
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:235
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:1948
UTHFreeFlow
void UTHFreeFlow(Flow *flow)
Definition: util-unittest-helper.c:526
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:316
StreamTcpUTClearSession
void StreamTcpUTClearSession(TcpSession *ssn)
Definition: stream-tcp-util.c:71
DetectEngineAppInspectionEngine_::smd
SigMatchData * smd
Definition: detect.h:415
detect-ssh-software-version.h
Packet_::flow
struct Flow_ * flow
Definition: decode.h:464
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3142
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition: detect-engine.c:1023
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3354
SigMatch_::type
uint16_t type
Definition: detect.h:322
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:257
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:817
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:272
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
StreamTcpUTAddSegmentWithPayload
int StreamTcpUTAddSegmentWithPayload(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, TcpStream *stream, uint32_t seq, uint8_t *payload, uint16_t len)
Definition: stream-tcp-util.c:113
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
StreamTcpUTSetupSession
void StreamTcpUTSetupSession(TcpSession *ssn)
Definition: stream-tcp-util.c:62
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:271
str
#define str(s)
Definition: suricata-common.h:272
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SIGMATCH_INFO_DEPRECATED
#define SIGMATCH_INFO_DEPRECATED
Definition: detect.h:1479
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:485
Flow_::alstate
void * alstate
Definition: flow.h:486
detect-parse.h
Signature_
Signature container.
Definition: detect.h:548
SigMatch_
a single match condition for a signature
Definition: detect.h:321
stream-tcp-util.h
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2394
TcpReassemblyThreadCtx_
Definition: stream-tcp-reassemble.h:60
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:812
TcpSession_
Definition: stream-tcp-private.h:260
flow.h
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:460
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:304
flow-var.h
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:349
debug.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1259
app-layer.h