/src/suricata8/src/detect-ike-nonce-payload.c
Line | Count | Source |
1 | | /* Copyright (C) 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 | | * |
20 | | * \author Frank Honza <frank.honza@dcso.de> |
21 | | */ |
22 | | |
23 | | #include "suricata-common.h" |
24 | | #include "threads.h" |
25 | | #include "decode.h" |
26 | | #include "detect.h" |
27 | | |
28 | | #include "detect-parse.h" |
29 | | #include "detect-engine.h" |
30 | | #include "detect-engine-buffer.h" |
31 | | #include "detect-engine-mpm.h" |
32 | | #include "detect-engine-prefilter.h" |
33 | | #include "detect-urilen.h" |
34 | | |
35 | | #include "flow.h" |
36 | | #include "flow-var.h" |
37 | | #include "flow-util.h" |
38 | | |
39 | | #include "util-debug.h" |
40 | | #include "util-unittest.h" |
41 | | #include "util-unittest-helper.h" |
42 | | #include "util-spm.h" |
43 | | |
44 | | #include "app-layer.h" |
45 | | #include "app-layer-parser.h" |
46 | | |
47 | | #include "detect-ike-nonce-payload.h" |
48 | | #include "stream-tcp.h" |
49 | | |
50 | | #include "rust.h" |
51 | | #include "app-layer-ike.h" |
52 | | #include "rust-bindings.h" |
53 | | |
54 | 39 | #define KEYWORD_NAME_NONCE "ike.nonce_payload" |
55 | 39 | #define KEYWORD_DOC_NONCE "ike-keywords.html#ike-nonce_payload"; |
56 | 234 | #define BUFFER_NAME_NONCE "ike.nonce_payload" |
57 | 39 | #define BUFFER_DESC_NONCE "ike nonce payload" |
58 | | |
59 | | static int g_buffer_nonce_id = 0; |
60 | | |
61 | | static int DetectNonceSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str) |
62 | 535 | { |
63 | 535 | if (SCDetectBufferSetActiveList(de_ctx, s, g_buffer_nonce_id) < 0) |
64 | 0 | return -1; |
65 | | |
66 | 535 | if (SCDetectSignatureSetAppProto(s, ALPROTO_IKE) < 0) |
67 | 1 | return -1; |
68 | | |
69 | 534 | return 0; |
70 | 535 | } |
71 | | |
72 | | static InspectionBuffer *GetNonceData(DetectEngineThreadCtx *det_ctx, |
73 | | const DetectEngineTransforms *transforms, Flow *_f, const uint8_t _flow_flags, void *txv, |
74 | | const int list_id) |
75 | 0 | { |
76 | 0 | InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id); |
77 | 0 | if (buffer->inspect == NULL) { |
78 | 0 | const uint8_t *b = NULL; |
79 | 0 | uint32_t b_len = 0; |
80 | |
|
81 | 0 | if (SCIkeStateGetNonce(txv, &b, &b_len) != 1) |
82 | 0 | return NULL; |
83 | 0 | if (b == NULL || b_len == 0) |
84 | 0 | return NULL; |
85 | | |
86 | 0 | InspectionBufferSetupAndApplyTransforms(det_ctx, list_id, buffer, b, b_len, transforms); |
87 | 0 | } |
88 | | |
89 | 0 | return buffer; |
90 | 0 | } |
91 | | |
92 | | void DetectIkeNonceRegister(void) |
93 | 39 | { |
94 | | // register nonce |
95 | 39 | sigmatch_table[DETECT_IKE_NONCE].name = KEYWORD_NAME_NONCE; |
96 | 39 | sigmatch_table[DETECT_IKE_NONCE].url = |
97 | 39 | "/rules/" KEYWORD_DOC_NONCE sigmatch_table[DETECT_IKE_NONCE].desc = |
98 | 39 | "sticky buffer to match on the IKE nonce_payload"; |
99 | 39 | sigmatch_table[DETECT_IKE_NONCE].Setup = DetectNonceSetup; |
100 | 39 | sigmatch_table[DETECT_IKE_NONCE].flags |= SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER; |
101 | | |
102 | 39 | DetectAppLayerInspectEngineRegister(BUFFER_NAME_NONCE, ALPROTO_IKE, SIG_FLAG_TOSERVER, 1, |
103 | 39 | DetectEngineInspectBufferGeneric, GetNonceData); |
104 | | |
105 | 39 | DetectAppLayerMpmRegister(BUFFER_NAME_NONCE, SIG_FLAG_TOSERVER, 1, PrefilterGenericMpmRegister, |
106 | 39 | GetNonceData, ALPROTO_IKE, 1); |
107 | | |
108 | 39 | DetectAppLayerInspectEngineRegister(BUFFER_NAME_NONCE, ALPROTO_IKE, SIG_FLAG_TOCLIENT, 1, |
109 | 39 | DetectEngineInspectBufferGeneric, GetNonceData); |
110 | | |
111 | 39 | DetectAppLayerMpmRegister(BUFFER_NAME_NONCE, SIG_FLAG_TOCLIENT, 1, PrefilterGenericMpmRegister, |
112 | 39 | GetNonceData, ALPROTO_IKE, 1); |
113 | | |
114 | 39 | DetectBufferTypeSetDescriptionByName(BUFFER_NAME_NONCE, BUFFER_DESC_NONCE); |
115 | | |
116 | 39 | g_buffer_nonce_id = DetectBufferTypeGetByName(BUFFER_NAME_NONCE); |
117 | 39 | SCLogDebug("registering " BUFFER_NAME_NONCE " rule option"); |
118 | 39 | } |