Coverage Report

Created: 2025-11-16 07:09

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