Coverage Report

Created: 2026-01-16 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata7/src/detect-sip-stat-msg.c
Line
Count
Source
1
/* Copyright (C) 2019 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 Giuseppe Longo <giuseppe@glongo.it>
21
 *
22
 * Implements the sip.stat_msg sticky buffer
23
 *
24
 */
25
26
#include "suricata-common.h"
27
#include "threads.h"
28
#include "decode.h"
29
#include "detect.h"
30
31
#include "detect-parse.h"
32
#include "detect-engine.h"
33
#include "detect-engine-mpm.h"
34
#include "detect-engine-prefilter.h"
35
#include "detect-content.h"
36
#include "detect-pcre.h"
37
#include "detect-urilen.h"
38
39
#include "flow.h"
40
#include "flow-var.h"
41
#include "flow-util.h"
42
43
#include "util-debug.h"
44
#include "util-unittest.h"
45
#include "util-unittest-helper.h"
46
#include "util-spm.h"
47
48
#include "app-layer.h"
49
#include "app-layer-parser.h"
50
51
#include "detect-sip-stat-msg.h"
52
#include "stream-tcp.h"
53
54
#include "rust.h"
55
#include "app-layer-sip.h"
56
57
34
#define KEYWORD_NAME "sip.stat_msg"
58
34
#define KEYWORD_DOC  "sip-keywords.html#sip-stat-msg"
59
136
#define BUFFER_NAME  "sip.stat_msg"
60
34
#define BUFFER_DESC  "sip response status message"
61
static int g_buffer_id = 0;
62
63
static int DetectSipStatMsgSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
64
125
{
65
125
    if (DetectBufferSetActiveList(de_ctx, s, g_buffer_id) < 0)
66
3
        return -1;
67
68
122
    if (DetectSignatureSetAppProto(s, ALPROTO_SIP) < 0)
69
57
        return -1;
70
71
65
    return 0;
72
122
}
73
74
static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
75
        const DetectEngineTransforms *transforms, Flow *_f,
76
        const uint8_t _flow_flags, void *txv, const int list_id)
77
0
{
78
0
    SCEnter();
79
80
0
    InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
81
0
    if (buffer->inspect == NULL) {
82
0
        const uint8_t *b = NULL;
83
0
        uint32_t b_len = 0;
84
85
0
        if (rs_sip_tx_get_stat_msg(txv, &b, &b_len) != 1)
86
0
            return NULL;
87
0
        if (b == NULL || b_len == 0)
88
0
            return NULL;
89
90
0
        InspectionBufferSetup(det_ctx, list_id, buffer, b, b_len);
91
0
        InspectionBufferApplyTransforms(buffer, transforms);
92
0
    }
93
94
0
    return buffer;
95
0
}
96
97
void DetectSipStatMsgRegister (void)
98
34
{
99
    /* sip.stat_msg sticky buffer */
100
34
    sigmatch_table[DETECT_AL_SIP_STAT_MSG].name = KEYWORD_NAME;
101
34
    sigmatch_table[DETECT_AL_SIP_STAT_MSG].desc = "sticky buffer to match on the SIP status message";
102
34
    sigmatch_table[DETECT_AL_SIP_STAT_MSG].url = "/rules/" KEYWORD_DOC;
103
34
    sigmatch_table[DETECT_AL_SIP_STAT_MSG].Setup = DetectSipStatMsgSetup;
104
34
    sigmatch_table[DETECT_AL_SIP_STAT_MSG].flags |= SIGMATCH_NOOPT;
105
106
34
    DetectAppLayerInspectEngineRegister2(BUFFER_NAME, ALPROTO_SIP,
107
34
            SIG_FLAG_TOCLIENT, 1,
108
34
            DetectEngineInspectBufferGeneric, GetData);
109
110
34
    DetectAppLayerMpmRegister2(BUFFER_NAME, SIG_FLAG_TOCLIENT, 3,
111
34
            PrefilterGenericMpmRegister, GetData, ALPROTO_SIP,
112
34
            1);
113
114
34
    DetectBufferTypeSetDescriptionByName(BUFFER_NAME, BUFFER_DESC);
115
116
34
    g_buffer_id = DetectBufferTypeGetByName(BUFFER_NAME);
117
118
34
    SCLogDebug("registering " BUFFER_NAME " rule option");
119
34
}