suricata
detect-sip-request-line.c
Go to the documentation of this file.
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 "debug.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"
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 
52 #include "stream-tcp.h"
53 
54 #include "rust.h"
55 #include "app-layer-sip.h"
56 #include "rust-sip-detect-gen.h"
57 
58 #define KEYWORD_NAME "sip.request_line"
59 #define KEYWORD_DOC "sip-keywords.html#sip-request-line"
60 #define BUFFER_NAME "sip.request_line"
61 #define BUFFER_DESC "sip request line"
62 static int g_buffer_id = 0;
63 
64 static int DetectSipRequestLineSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
65 {
66  if (DetectBufferSetActiveList(s, g_buffer_id) < 0)
67  return -1;
68 
70  return -1;
71 
72  return 0;
73 }
74 
75 static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
76  const DetectEngineTransforms *transforms,
77  Flow *_f, const uint8_t _flow_flags,
78  void *txv, const int list_id)
79 {
80  InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
81  if (buffer->inspect == NULL) {
82  const uint8_t *b = NULL;
83  uint32_t b_len = 0;
84 
85  if (rs_sip_tx_get_request_line(txv, &b, &b_len) != 1)
86  return NULL;
87  if (b == NULL || b_len == 0)
88  return NULL;
89 
90  InspectionBufferSetup(buffer, b, b_len);
91  InspectionBufferApplyTransforms(buffer, transforms);
92  }
93  return buffer;
94 }
95 
97 {
98  /* sip.request_line sticky buffer */
100  sigmatch_table[DETECT_AL_SIP_REQUEST_LINE].desc = "sticky buffer to match on the SIP request line";
102  sigmatch_table[DETECT_AL_SIP_REQUEST_LINE].Setup = DetectSipRequestLineSetup;
104 
108 
111  1);
112 
114 
115  g_buffer_id = DetectBufferTypeGetByName(BUFFER_NAME);
116 
117  SCLogDebug("registering " BUFFER_NAME " rule option");
118 }
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect.h:1448
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1186
#define SCLogDebug(...)
Definition: util-debug.h:335
int DetectSignatureSetAppProto(Signature *s, AppProto alproto)
#define KEYWORD_DOC
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
const char * name
Definition: detect.h:1200
Signature container.
Definition: detect.h:522
void DetectAppLayerMpmRegister2(const char *name, int direction, int priority, int(*PrefilterRegister)(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistery *mpm_reg, int list_id), InspectionBufferGetDataPtr GetData, AppProto alproto, int tx_min_progress)
register a MPM engine
main detection engine ctx
Definition: detect.h:761
int DetectBufferTypeGetByName(const char *name)
#define SIG_FLAG_TOSERVER
Definition: detect.h:236
void DetectAppLayerInspectEngineRegister2(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr2 Callback2, InspectionBufferGetDataPtr GetData)
register inspect engine at start up time
int DetectEngineInspectBufferGeneric(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineAppInspectionEngine *engine, const Signature *s, Flow *f, uint8_t flags, void *alstate, void *txv, uint64_t tx_id)
Do the content inspection & validation for a signature.
const char * desc
Definition: detect.h:1202
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistery *mpm_reg, int list_id)
#define KEYWORD_NAME
#define BUFFER_NAME
void InspectionBufferSetup(InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len)
setup the buffer with our initial data
void InspectionBufferApplyTransforms(InspectionBuffer *buffer, const DetectEngineTransforms *transforms)
#define SIGMATCH_NOOPT
Definition: detect.h:1369
const char * url
Definition: detect.h:1203
int DetectBufferSetActiveList(Signature *s, const int list)
const uint8_t * inspect
Definition: detect.h:343
#define DOC_URL
Definition: suricata.h:86
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
void DetectSipRequestLineRegister(void)
#define BUFFER_DESC
#define DOC_VERSION
Definition: suricata.h:91
uint16_t flags
Definition: detect.h:1194
Flow data structure.
Definition: flow.h:325