Coverage Report

Created: 2026-01-16 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata7/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-mpm.h"
31
#include "detect-engine-prefilter.h"
32
#include "detect-urilen.h"
33
34
#include "flow.h"
35
#include "flow-var.h"
36
#include "flow-util.h"
37
38
#include "util-debug.h"
39
#include "util-unittest.h"
40
#include "util-unittest-helper.h"
41
#include "util-spm.h"
42
43
#include "app-layer.h"
44
#include "app-layer-parser.h"
45
46
#include "detect-ike-nonce-payload.h"
47
#include "stream-tcp.h"
48
49
#include "rust.h"
50
#include "app-layer-ike.h"
51
#include "rust-bindings.h"
52
53
73
#define KEYWORD_NAME_NONCE "ike.nonce_payload"
54
73
#define KEYWORD_DOC_NONCE  "ike-keywords.html#ike-nonce_payload";
55
438
#define BUFFER_NAME_NONCE  "ike.nonce_payload"
56
73
#define BUFFER_DESC_NONCE  "ike nonce payload"
57
58
static int g_buffer_nonce_id = 0;
59
60
static int DetectNonceSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
61
5.40k
{
62
5.40k
    if (DetectBufferSetActiveList(de_ctx, s, g_buffer_nonce_id) < 0)
63
7
        return -1;
64
65
5.39k
    if (DetectSignatureSetAppProto(s, ALPROTO_IKE) < 0)
66
58
        return -1;
67
68
5.34k
    return 0;
69
5.39k
}
70
71
static InspectionBuffer *GetNonceData(DetectEngineThreadCtx *det_ctx,
72
        const DetectEngineTransforms *transforms, Flow *_f, const uint8_t _flow_flags, void *txv,
73
        const int list_id)
74
323
{
75
323
    InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
76
323
    if (buffer->inspect == NULL) {
77
290
        const uint8_t *b = NULL;
78
290
        uint32_t b_len = 0;
79
80
290
        if (rs_ike_state_get_nonce(txv, &b, &b_len) != 1)
81
227
            return NULL;
82
63
        if (b == NULL || b_len == 0)
83
0
            return NULL;
84
85
63
        InspectionBufferSetup(det_ctx, list_id, buffer, b, b_len);
86
63
        InspectionBufferApplyTransforms(buffer, transforms);
87
63
    }
88
89
96
    return buffer;
90
323
}
91
92
void DetectIkeNonceRegister(void)
93
73
{
94
    // register nonce
95
73
    sigmatch_table[DETECT_AL_IKE_NONCE].name = KEYWORD_NAME_NONCE;
96
73
    sigmatch_table[DETECT_AL_IKE_NONCE].url =
97
73
            "/rules/" KEYWORD_DOC_NONCE sigmatch_table[DETECT_AL_IKE_NONCE].desc =
98
73
                    "sticky buffer to match on the IKE nonce_payload";
99
73
    sigmatch_table[DETECT_AL_IKE_NONCE].Setup = DetectNonceSetup;
100
73
    sigmatch_table[DETECT_AL_IKE_NONCE].flags |= SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
101
102
73
    DetectAppLayerInspectEngineRegister2(BUFFER_NAME_NONCE, ALPROTO_IKE, SIG_FLAG_TOSERVER, 1,
103
73
            DetectEngineInspectBufferGeneric, GetNonceData);
104
105
73
    DetectAppLayerMpmRegister2(BUFFER_NAME_NONCE, SIG_FLAG_TOSERVER, 1, PrefilterGenericMpmRegister,
106
73
            GetNonceData, ALPROTO_IKE, 1);
107
108
73
    DetectAppLayerInspectEngineRegister2(BUFFER_NAME_NONCE, ALPROTO_IKE, SIG_FLAG_TOCLIENT, 1,
109
73
            DetectEngineInspectBufferGeneric, GetNonceData);
110
111
73
    DetectAppLayerMpmRegister2(BUFFER_NAME_NONCE, SIG_FLAG_TOCLIENT, 1, PrefilterGenericMpmRegister,
112
73
            GetNonceData, ALPROTO_IKE, 1);
113
114
73
    DetectBufferTypeSetDescriptionByName(BUFFER_NAME_NONCE, BUFFER_DESC_NONCE);
115
116
73
    g_buffer_nonce_id = DetectBufferTypeGetByName(BUFFER_NAME_NONCE);
117
73
    SCLogDebug("registering " BUFFER_NAME_NONCE " rule option");
118
73
}