/src/suricata8/src/detect-ssh-software.c
Line | Count | Source |
1 | | /* Copyright (C) 2007-2016 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 | | * \ingroup sshlayer |
20 | | * |
21 | | * @{ |
22 | | */ |
23 | | |
24 | | |
25 | | /** |
26 | | * \file |
27 | | * |
28 | | * \author Victor Julien <victor@inliniac.net> |
29 | | * |
30 | | * Implements support ssh_software sticky buffer |
31 | | */ |
32 | | |
33 | | #include "suricata-common.h" |
34 | | #include "threads.h" |
35 | | #include "decode.h" |
36 | | |
37 | | #include "detect.h" |
38 | | #include "detect-parse.h" |
39 | | #include "detect-engine.h" |
40 | | #include "detect-engine-buffer.h" |
41 | | #include "detect-engine-mpm.h" |
42 | | #include "detect-engine-state.h" |
43 | | #include "detect-engine-prefilter.h" |
44 | | #include "detect-engine-content-inspection.h" |
45 | | |
46 | | #include "app-layer.h" |
47 | | #include "app-layer-parser.h" |
48 | | #include "app-layer-ssh.h" |
49 | | #include "detect-ssh-software.h" |
50 | | #include "rust.h" |
51 | | |
52 | 39 | #define KEYWORD_NAME "ssh.software" |
53 | 39 | #define KEYWORD_NAME_LEGACY "ssh_software" |
54 | 39 | #define KEYWORD_DOC "ssh-keywords.html#ssh-software" |
55 | 273 | #define BUFFER_NAME "ssh_software" |
56 | 39 | #define BUFFER_DESC "ssh software field" |
57 | | static int g_buffer_id = 0; |
58 | | |
59 | | static InspectionBuffer *GetSshData(DetectEngineThreadCtx *det_ctx, |
60 | | const DetectEngineTransforms *transforms, Flow *_f, |
61 | | const uint8_t flow_flags, void *txv, const int list_id) |
62 | 0 | { |
63 | 0 | SCEnter(); |
64 | |
|
65 | 0 | InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id); |
66 | |
|
67 | 0 | if (buffer->inspect == NULL) { |
68 | 0 | const uint8_t *software = NULL; |
69 | 0 | uint32_t b_len = 0; |
70 | |
|
71 | 0 | if (SCSshTxGetSoftware(txv, &software, &b_len, flow_flags) != 1) |
72 | 0 | return NULL; |
73 | 0 | if (software == NULL || b_len == 0) { |
74 | 0 | SCLogDebug("SSH software version not set"); |
75 | 0 | return NULL; |
76 | 0 | } |
77 | | |
78 | 0 | InspectionBufferSetupAndApplyTransforms( |
79 | 0 | det_ctx, list_id, buffer, software, b_len, transforms); |
80 | 0 | } |
81 | | |
82 | 0 | return buffer; |
83 | 0 | } |
84 | | |
85 | | static int DetectSshSoftwareSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg) |
86 | 6 | { |
87 | 6 | if (SCDetectBufferSetActiveList(de_ctx, s, g_buffer_id) < 0) |
88 | 1 | return -1; |
89 | | |
90 | 5 | if (SCDetectSignatureSetAppProto(s, ALPROTO_SSH) < 0) |
91 | 1 | return -1; |
92 | | |
93 | 4 | return 0; |
94 | 5 | } |
95 | | |
96 | | |
97 | | void DetectSshSoftwareRegister(void) |
98 | 39 | { |
99 | 39 | sigmatch_table[DETECT_SSH_SOFTWARE].name = KEYWORD_NAME; |
100 | 39 | sigmatch_table[DETECT_SSH_SOFTWARE].alias = KEYWORD_NAME_LEGACY; |
101 | 39 | sigmatch_table[DETECT_SSH_SOFTWARE].desc = BUFFER_NAME " sticky buffer"; |
102 | 39 | sigmatch_table[DETECT_SSH_SOFTWARE].url = "/rules/" KEYWORD_DOC; |
103 | 39 | sigmatch_table[DETECT_SSH_SOFTWARE].Setup = DetectSshSoftwareSetup; |
104 | 39 | sigmatch_table[DETECT_SSH_SOFTWARE].flags |= SIGMATCH_INFO_STICKY_BUFFER | SIGMATCH_NOOPT; |
105 | | |
106 | 39 | DetectAppLayerMpmRegister(BUFFER_NAME, SIG_FLAG_TOSERVER, 2, PrefilterGenericMpmRegister, |
107 | 39 | GetSshData, ALPROTO_SSH, SshStateBannerDone), |
108 | 39 | DetectAppLayerMpmRegister(BUFFER_NAME, SIG_FLAG_TOCLIENT, 2, |
109 | 39 | PrefilterGenericMpmRegister, GetSshData, ALPROTO_SSH, SshStateBannerDone), |
110 | | |
111 | 39 | DetectAppLayerInspectEngineRegister(BUFFER_NAME, ALPROTO_SSH, SIG_FLAG_TOSERVER, |
112 | 39 | SshStateBannerDone, DetectEngineInspectBufferGeneric, GetSshData); |
113 | 39 | DetectAppLayerInspectEngineRegister(BUFFER_NAME, ALPROTO_SSH, SIG_FLAG_TOCLIENT, |
114 | 39 | SshStateBannerDone, DetectEngineInspectBufferGeneric, GetSshData); |
115 | | |
116 | 39 | DetectBufferTypeSetDescriptionByName(BUFFER_NAME, BUFFER_DESC); |
117 | | |
118 | 39 | g_buffer_id = DetectBufferTypeGetByName(BUFFER_NAME); |
119 | 39 | } |