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 static void DetectSshSoftwareVersionRegisterTests(void);
74 static void DetectSshSoftwareVersionFree(DetectEngineCtx *de_ctx, void *);
75 static int g_ssh_banner_list_id = 0;
76 
77 static int InspectSshBanner(ThreadVars *tv,
79  const Signature *s, const SigMatchData *smd,
80  Flow *f, uint8_t flags, void *alstate,
81  void *txv, uint64_t tx_id)
82 {
83  return DetectEngineInspectGenericList(tv, de_ctx, det_ctx, s, smd,
84  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  sigmatch_table[DETECT_AL_SSH_SOFTWAREVERSION].RegisterTests = DetectSshSoftwareVersionRegisterTests;
101 
102  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
103 
104  g_ssh_banner_list_id = DetectBufferTypeRegister("ssh_banner");
105 
107  ALPROTO_SSH, SIG_FLAG_TOSERVER, SshStateBannerDone,
108  InspectSshBanner);
110  ALPROTO_SSH, SIG_FLAG_TOCLIENT, SshStateBannerDone,
111  InspectSshBanner);
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  int ov[MAX_SUBSTRINGS];
168 
169  ret = DetectParsePcreExec(&parse_regex, str, 0, 0, ov, MAX_SUBSTRINGS);
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 = pcre_get_substring((char *)str, ov, MAX_SUBSTRINGS, 1, &str_ptr);
179  if (res < 0) {
180  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring failed");
181  goto error;
182  }
183 
184  /* We have a correct id option */
185  ssh = SCMalloc(sizeof(DetectSshSoftwareVersionData));
186  if (unlikely(ssh == NULL))
187  goto error;
188 
189  ssh->software_ver = (uint8_t *)SCStrdup((char *)str_ptr);
190  if (ssh->software_ver == NULL) {
191  goto error;
192  }
193  pcre_free_substring(str_ptr);
194 
195  ssh->len = strlen((char *)ssh->software_ver);
196 
197  SCLogDebug("will look for ssh %s", ssh->software_ver);
198  }
199 
200  return ssh;
201 
202 error:
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 
271 /**
272  * \test DetectSshSoftwareVersionTestParse01 is a test to make sure that we parse
273  * a software version correctly
274  */
275 static int DetectSshSoftwareVersionTestParse01 (void)
276 {
277  DetectSshSoftwareVersionData *ssh = NULL;
278  ssh = DetectSshSoftwareVersionParse(NULL, "PuTTY_1.0");
279  if (ssh != NULL && strncmp((char *) ssh->software_ver, "PuTTY_1.0", 9) == 0) {
280  DetectSshSoftwareVersionFree(NULL, ssh);
281  return 1;
282  }
283 
284  return 0;
285 }
286 
287 /**
288  * \test DetectSshSoftwareVersionTestParse02 is a test to make sure that we parse
289  * the software version correctly
290  */
291 static int DetectSshSoftwareVersionTestParse02 (void)
292 {
293  DetectSshSoftwareVersionData *ssh = NULL;
294  ssh = DetectSshSoftwareVersionParse(NULL, "\"SecureCRT-4.0\"");
295  if (ssh != NULL && strncmp((char *) ssh->software_ver, "SecureCRT-4.0", 13) == 0) {
296  DetectSshSoftwareVersionFree(NULL, ssh);
297  return 1;
298  }
299 
300  return 0;
301 }
302 
303 /**
304  * \test DetectSshSoftwareVersionTestParse03 is a test to make sure that we
305  * don't return a ssh_data with an empty value specified
306  */
307 static int DetectSshSoftwareVersionTestParse03 (void)
308 {
309  DetectSshSoftwareVersionData *ssh = NULL;
310  ssh = DetectSshSoftwareVersionParse(NULL, "");
311  if (ssh != NULL) {
312  DetectSshSoftwareVersionFree(NULL, ssh);
313  return 0;
314  }
315 
316  return 1;
317 }
318 
319 
320 #include "stream-tcp-reassemble.h"
321 #include "stream-tcp-util.h"
322 
323 /** \test Send a get request in three chunks + more data. */
324 static int DetectSshSoftwareVersionTestDetect01(void)
325 {
326  TcpReassemblyThreadCtx *ra_ctx = NULL;
327  ThreadVars tv;
328  TcpSession ssn;
329  Flow *f = NULL;
330  Packet *p = NULL;
331 
332  uint8_t sshbuf1[] = "SSH-1.";
333  uint8_t sshbuf2[] = "10-PuTTY_2.123" ;
334  uint8_t sshbuf3[] = "\n";
335  uint8_t sshbuf4[] = "whatever...";
336 
337  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
338  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
339 
340  memset(&tv, 0x00, sizeof(tv));
341 
342  StreamTcpUTInit(&ra_ctx);
347 
348  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
349  FAIL_IF_NULL(f);
350  f->protoctx = &ssn;
351  f->proto = IPPROTO_TCP;
352  f->alproto = ALPROTO_SSH;
353 
354  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
355  FAIL_IF(unlikely(p == NULL));
356  p->flow = f;
357 
358  Signature *s = NULL;
359  ThreadVars th_v;
360  DetectEngineThreadCtx *det_ctx = NULL;
361 
362  memset(&th_v, 0, sizeof(th_v));
363 
366 
367  de_ctx->flags |= DE_QUIET;
368 
369  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.softwareversion:PuTTY_2.123; sid:1;)");
370  FAIL_IF_NULL(s);
371 
373  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
374 
375  uint32_t seq = 2;
376  for (int i=0; i<4; i++) {
377  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
378  seq += sshlens[i];
379  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
380  }
381 
382  void *ssh_state = f->alstate;
383  FAIL_IF_NULL(ssh_state);
384 
385  /* do detect */
386  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
387 
388  FAIL_IF(PacketAlertCheck(p, 1));
389 
390  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
392 
393  UTHFreePacket(p);
395  StreamTcpUTDeinit(ra_ctx);
396  UTHFreeFlow(f);
397  PASS;
398 }
399 
400 /** \test Send a get request in three chunks + more data. */
401 static int DetectSshSoftwareVersionTestDetect02(void)
402 {
403  TcpReassemblyThreadCtx *ra_ctx = NULL;
404  ThreadVars tv;
405  TcpSession ssn;
406  Flow *f = NULL;
407  Packet *p = NULL;
408 
409  uint8_t sshbuf1[] = "SSH-1.99-Pu";
410  uint8_t sshbuf2[] = "TTY_2.123" ;
411  uint8_t sshbuf3[] = "\n";
412  uint8_t sshbuf4[] = "whatever...";
413 
414  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
415  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
416 
417  memset(&tv, 0x00, sizeof(tv));
418 
419  StreamTcpUTInit(&ra_ctx);
424 
425  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
426  FAIL_IF_NULL(f);
427  f->protoctx = &ssn;
428  f->proto = IPPROTO_TCP;
429  f->alproto = ALPROTO_SSH;
430 
431  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
432  FAIL_IF(unlikely(p == NULL));
433  p->flow = f;
434 
435  Signature *s = NULL;
436  ThreadVars th_v;
437  DetectEngineThreadCtx *det_ctx = NULL;
438 
439  memset(&th_v, 0, sizeof(th_v));
440 
443 
444  de_ctx->flags |= DE_QUIET;
445 
446  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.softwareversion:PuTTY_2.123; sid:1;)");
447  FAIL_IF_NULL(s);
448 
450  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
451 
452  uint32_t seq = 2;
453  for (int i=0; i<4; i++) {
454  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
455  seq += sshlens[i];
456  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
457  }
458 
459  void *ssh_state = f->alstate;
460  FAIL_IF_NULL(ssh_state);
461 
462  /* do detect */
463  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
464 
465  FAIL_IF(PacketAlertCheck(p, 1));
466 
467  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
469 
470  UTHFreePacket(p);
472  StreamTcpUTDeinit(ra_ctx);
473  UTHFreeFlow(f);
474  PASS;
475 }
476 
477 /** \test Send a get request in three chunks + more data. */
478 static int DetectSshSoftwareVersionTestDetect03(void)
479 {
480  TcpReassemblyThreadCtx *ra_ctx = NULL;
481  ThreadVars tv;
482  TcpSession ssn;
483  Flow *f = NULL;
484  Packet *p = NULL;
485 
486  uint8_t sshbuf1[] = "SSH-1.";
487  uint8_t sshbuf2[] = "7-PuTTY_2.123" ;
488  uint8_t sshbuf3[] = "\n";
489  uint8_t sshbuf4[] = "whatever...";
490 
491  uint8_t* sshbufs[4] = {sshbuf1, sshbuf2, sshbuf3, sshbuf4};
492  uint32_t sshlens[4] = {sizeof(sshbuf1) - 1, sizeof(sshbuf2) - 1, sizeof(sshbuf3) - 1, sizeof(sshbuf4) - 1};
493 
494  memset(&tv, 0x00, sizeof(tv));
495 
496  StreamTcpUTInit(&ra_ctx);
501 
502  f = UTHBuildFlow(AF_INET, "1.1.1.1", "2.2.2.2", 1234, 2222);
503  FAIL_IF_NULL(f);
504  f->protoctx = &ssn;
505  f->proto = IPPROTO_TCP;
506  f->alproto = ALPROTO_SSH;
507 
508  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
509  FAIL_IF(unlikely(p == NULL));
510  p->flow = f;
511 
512  Signature *s = NULL;
513  ThreadVars th_v;
514  DetectEngineThreadCtx *det_ctx = NULL;
515 
516  memset(&th_v, 0, sizeof(th_v));
517 
520 
521  de_ctx->flags |= DE_QUIET;
522 
523  s = de_ctx->sig_list = SigInit(de_ctx,"alert ssh any any -> any any (msg:\"SSH\"; ssh.softwareversion:lalala-3.1.4; sid:1;)");
524  FAIL_IF_NULL(s);
525 
527  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
528 
529  uint32_t seq = 2;
530  for (int i=0; i<4; i++) {
531  FAIL_IF(StreamTcpUTAddSegmentWithPayload(&tv, ra_ctx, &ssn.server, seq, sshbufs[i], sshlens[i]) == -1);
532  seq += sshlens[i];
533  FAIL_IF(StreamTcpReassembleAppLayer(&tv, ra_ctx, &ssn, &ssn.server, p, UPDATE_DIR_PACKET) < 0);
534  }
535 
536  void *ssh_state = f->alstate;
537  FAIL_IF_NULL(ssh_state);
538 
539  /* do detect */
540  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
541 
542  FAIL_IF(PacketAlertCheck(p, 1));
543 
544  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
546 
547  UTHFreePacket(p);
549  StreamTcpUTDeinit(ra_ctx);
550  UTHFreeFlow(f);
551  PASS;
552 }
553 
554 #endif /* UNITTESTS */
555 
556 /**
557  * \brief this function registers unit tests for DetectSshSoftwareVersion
558  */
559 static void DetectSshSoftwareVersionRegisterTests(void)
560 {
561 #ifdef UNITTESTS /* UNITTESTS */
562  UtRegisterTest("DetectSshSoftwareVersionTestParse01",
563  DetectSshSoftwareVersionTestParse01);
564  UtRegisterTest("DetectSshSoftwareVersionTestParse02",
565  DetectSshSoftwareVersionTestParse02);
566  UtRegisterTest("DetectSshSoftwareVersionTestParse03",
567  DetectSshSoftwareVersionTestParse03);
568  UtRegisterTest("DetectSshSoftwareVersionTestDetect01",
569  DetectSshSoftwareVersionTestDetect01);
570  UtRegisterTest("DetectSshSoftwareVersionTestDetect02",
571  DetectSshSoftwareVersionTestDetect02);
572  UtRegisterTest("DetectSshSoftwareVersionTestDetect03",
573  DetectSshSoftwareVersionTestDetect03);
574 #endif /* UNITTESTS */
575 }
576 
UPDATE_DIR_PACKET
@ UPDATE_DIR_PACKET
Definition: stream-tcp-reassemble.h:55
SigTableElmt_::url
const char * url
Definition: detect.h:1212
DetectSignatureSetAppProto
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
Definition: detect-parse.c:1468
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:1211
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1200
flow-util.h
DetectSshSoftwareVersionData_
Definition: detect-ssh-software-version.h:27
SigTableElmt_::name
const char * name
Definition: detect.h:1209
DetectSshSoftwareVersionRegister
void DetectSshSoftwareVersionRegister(void)
Registration function for keyword: ssh.softwareversion.
Definition: detect-ssh-software-version.c:90
stream-tcp.h
MAX_SUBSTRINGS
#define MAX_SUBSTRINGS
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:1390
seq
uint32_t seq
Definition: stream-tcp-private.h:2
Flow_::proto
uint8_t proto
Definition: flow.h:361
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:162
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
threads.h
Flow_
Flow data structure.
Definition: flow.h:343
SigInit
Signature * SigInit(DetectEngineCtx *, const char *)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2033
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1203
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:766
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2089
SigTableElmt_::AppLayerTxMatch
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition: detect.h:1181
rust.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:293
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:336
m
SCMutex m
Definition: flow-hash.h:3
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:416
SigMatchData_
Data needed for Match()
Definition: detect.h:328
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1195
StreamTcpUTInitInline
void StreamTcpUTInitInline(void)
Definition: stream-tcp-util.c:58
util-unittest.h
util-unittest-helper.h
DetectEngineInspectGenericList
int DetectEngineInspectGenericList(ThreadVars *tv, 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:1592
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:520
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:1118
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:1009
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2456
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:161
StreamTcpUTSetupStream
void StreamTcpUTSetupStream(TcpStream *s, uint32_t isn)
Definition: stream-tcp-util.c:79
SigTableElmt_::alternative
uint16_t alternative
Definition: detect.h:1207
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:322
SigMatchSignatures
void SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1668
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options, int *ovector, int ovector_size)
Definition: detect-parse.c:2388
Packet_
Definition: decode.h:411
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:1876
SigMatch_::type
uint8_t type
Definition: detect.h:320
UTHFreeFlow
void UTHFreeFlow(Flow *flow)
Definition: util-unittest-helper.c:525
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:314
StreamTcpUTClearSession
void StreamTcpUTClearSession(TcpSession *ssn)
Definition: stream-tcp-util.c:71
detect-ssh-software-version.h
Packet_::flow
struct Flow_ * flow
Definition: decode.h:448
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:2793
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:832
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3001
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:772
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:1404
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:484
Flow_::alstate
void * alstate
Definition: flow.h:454
detect-parse.h
Signature_
Signature container.
Definition: detect.h:527
SigMatch_
a single match condition for a signature
Definition: detect.h:319
stream-tcp-util.h
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2044
TcpReassemblyThreadCtx_
Definition: stream-tcp-reassemble.h:60
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:767
TcpSession_
Definition: stream-tcp-private.h:260
flow.h
DetectAppLayerInspectEngineRegister
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback)
register inspect engine at start up time
Definition: detect-engine.c:170
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:425
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:1201
app-layer.h