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 in combination 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 res = 0;
160  size_t pcre2_len;
161 
162  pcre2_match_data *match = NULL;
163  int ret = DetectParsePcreExec(&parse_regex, &match, str, 0, 0);
164 
165  if (ret < 1 || ret > 3) {
166  SCLogError("invalid ssh.softwareversion option");
167  goto error;
168  }
169 
170  if (ret > 1) {
171  const char *str_ptr = NULL;
172  res = pcre2_substring_get_bynumber(match, 1, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
173  if (res < 0) {
174  SCLogError("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  pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
182  goto error;
183  }
184  ssh->software_ver = (uint8_t *)SCStrdup((char *)str_ptr);
185  if (ssh->software_ver == NULL) {
186  pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
187  goto error;
188  }
189  pcre2_substring_free((PCRE2_UCHAR *)str_ptr);
190 
191  ssh->len = (uint16_t)strlen((char *)ssh->software_ver);
192 
193  SCLogDebug("will look for ssh %s", ssh->software_ver);
194  }
195 
196  pcre2_match_data_free(match);
197  return ssh;
198 
199 error:
200  if (match) {
201  pcre2_match_data_free(match);
202  }
203  if (ssh != NULL)
204  DetectSshSoftwareVersionFree(de_ctx, ssh);
205  return NULL;
206 
207 }
208 
209 /**
210  * \brief this function is used to add the parsed "id" option
211  * \brief into the current signature
212  *
213  * \param de_ctx pointer to the Detection Engine Context
214  * \param s pointer to the Current Signature
215  * \param idstr pointer to the user provided "id" option
216  *
217  * \retval 0 on Success
218  * \retval -1 on Failure
219  */
220 static int DetectSshSoftwareVersionSetup (DetectEngineCtx *de_ctx, Signature *s, const char *str)
221 {
222  DetectSshSoftwareVersionData *ssh = NULL;
223  SigMatch *sm = NULL;
224 
226  return -1;
227 
228  ssh = DetectSshSoftwareVersionParse(NULL, str);
229  if (ssh == NULL)
230  goto error;
231 
232  /* Okay so far so good, lets get this into a SigMatch
233  * and put it in the Signature. */
234  sm = SigMatchAlloc();
235  if (sm == NULL)
236  goto error;
237 
239  sm->ctx = (void *)ssh;
240 
241  SigMatchAppendSMToList(s, sm, g_ssh_banner_list_id);
242  return 0;
243 
244 error:
245  if (ssh != NULL)
246  DetectSshSoftwareVersionFree(de_ctx, ssh);
247  if (sm != NULL)
248  SCFree(sm);
249  return -1;
250 
251 }
252 
253 /**
254  * \brief this function will free memory associated with DetectSshSoftwareVersionData
255  *
256  * \param id_d pointer to DetectSshSoftwareVersionData
257  */
258 static void DetectSshSoftwareVersionFree(DetectEngineCtx *de_ctx, void *ptr)
259 {
260  if (ptr == NULL)
261  return;
262 
264  if (ssh->software_ver != NULL)
265  SCFree(ssh->software_ver);
266  SCFree(ssh);
267 }
268 
269 #ifdef UNITTESTS /* UNITTESTS */
270 #include "detect-engine-alert.h"
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
SigTableElmt_::url
const char * url
Definition: detect.h:1288
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1704
detect-engine.h
StreamTcpUTDeinit
void StreamTcpUTDeinit(TcpReassemblyThreadCtx *ra_ctx)
Definition: stream-tcp-util.c:51
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:437
app-layer-ssh.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1287
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1275
flow-util.h
DetectParseRegex
Definition: detect-parse.h:62
DetectSshSoftwareVersionData_
Definition: detect-ssh-software-version.h:27
SigTableElmt_::name
const char * name
Definition: detect.h:1285
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:269
SIGMATCH_QUOTES_OPTIONAL
#define SIGMATCH_QUOTES_OPTIONAL
Definition: detect.h:1479
seq
uint32_t seq
Definition: stream-tcp-private.h:2
Flow_::proto
uint8_t proto
Definition: flow.h:369
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:171
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
threads.h
Flow_
Flow data structure.
Definition: flow.h:347
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1279
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:827
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2592
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1256
rust.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:315
stream-tcp-reassemble.h
UTHBuildPacket
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
Definition: util-unittest-helper.c:337
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1824
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:2629
m
SCMutex m
Definition: flow-hash.h:6
ALPROTO_SSH
@ ALPROTO_SSH
Definition: app-layer-protos.h:34
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:256
Flow_::protoctx
void * protoctx
Definition: flow.h:437
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1270
StreamTcpUTInitInline
void StreamTcpUTInitInline(void)
Definition: stream-tcp-util.c:58
util-unittest.h
util-unittest-helper.h
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:1355
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:255
decode.h
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1075
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2753
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
DETECT_AL_SSH_SOFTWARE
@ DETECT_AL_SSH_SOFTWARE
Definition: detect-engine-register.h:170
StreamTcpUTSetupStream
void StreamTcpUTSetupStream(TcpStream *s, uint32_t isn)
Definition: stream-tcp-util.c:79
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2270
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1283
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:344
Packet_
Definition: decode.h:430
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:216
detect-engine-alert.h
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:322
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:1971
UTHFreeFlow
void UTHFreeFlow(Flow *flow)
Definition: util-unittest-helper.c:526
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:336
StreamTcpUTClearSession
void StreamTcpUTClearSession(TcpSession *ssn)
Definition: stream-tcp-util.c:71
detect-ssh-software-version.h
Packet_::flow
struct Flow_ * flow
Definition: decode.h:469
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3308
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
DetectBufferTypeRegister
int DetectBufferTypeRegister(const char *name)
Definition: detect-engine.c:1060
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3522
SigMatch_::type
uint16_t type
Definition: detect.h:342
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:129
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:835
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:2122
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:295
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
StreamTcpUTAddSegmentWithPayload
int StreamTcpUTAddSegmentWithPayload(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx, TcpStream *stream, uint32_t seq, uint8_t *payload, uint16_t len)
Definition: stream-tcp-util.c:113
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
StreamTcpUTSetupSession
void StreamTcpUTSetupSession(TcpSession *ssn)
Definition: stream-tcp-util.c:62
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:294
str
#define str(s)
Definition: suricata-common.h:286
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SIGMATCH_INFO_DEPRECATED
#define SIGMATCH_INFO_DEPRECATED
Definition: detect.h:1493
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:485
Flow_::alstate
void * alstate
Definition: flow.h:472
detect-parse.h
Signature_
Signature container.
Definition: detect.h:582
SigMatch_
a single match condition for a signature
Definition: detect.h:341
stream-tcp-util.h
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2553
TcpReassemblyThreadCtx_
Definition: stream-tcp-reassemble.h:60
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:829
TcpSession_
Definition: stream-tcp-private.h:283
flow.h
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:446
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275
flow-var.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1277
app-layer.h