suricata
detect-sip-method.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.method 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"
34#include "detect-engine-mpm.h"
36#include "detect-content.h"
37#include "detect-pcre.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"
46#include "util-spm.h"
47
48#include "app-layer.h"
49#include "app-layer-parser.h"
50
51#include "detect-sip-method.h"
52#include "stream-tcp.h"
53
54#include "rust.h"
55
56#define KEYWORD_NAME "sip.method"
57#define KEYWORD_DOC "sip-keywords.html#sip-method"
58#define BUFFER_NAME "sip.method"
59#define BUFFER_DESC "sip request method"
60static int g_buffer_id = 0;
61
62static int DetectSipMethodSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
63{
64 if (SCDetectBufferSetActiveList(de_ctx, s, g_buffer_id) < 0)
65 return -1;
66
68 return -1;
69
70 return 0;
71}
72
73static bool DetectSipMethodValidateCallback(
74 const Signature *s, const char **sigerror, const DetectBufferType *dbt)
75{
76 for (uint32_t x = 0; x < s->init_data->buffer_index; x++) {
77 if (s->init_data->buffers[x].id != (uint32_t)dbt->id)
78 continue;
79 const SigMatch *sm = s->init_data->buffers[x].head;
80 for (; sm != NULL; sm = sm->next) {
81 if (sm->type != DETECT_CONTENT)
82 continue;
83 const DetectContentData *cd = (const DetectContentData *)sm->ctx;
84 if (cd->content && cd->content_len) {
85 if (cd->content[cd->content_len - 1] == 0x20) {
86 *sigerror = "sip.method pattern with trailing space";
87 SCLogError("%s", *sigerror);
88 return true;
89 } else if (cd->content[0] == 0x20) {
90 *sigerror = "sip.method pattern with leading space";
91 SCLogError("%s", *sigerror);
92 return true;
93 } else if (cd->content[cd->content_len - 1] == 0x09) {
94 *sigerror = "sip.method pattern with trailing tab";
95 SCLogError("%s", *sigerror);
96 return true;
97 } else if (cd->content[0] == 0x09) {
98 *sigerror = "sip.method pattern with leading tab";
99 SCLogError("%s", *sigerror);
100 return true;
101 }
102 }
103 }
104 }
105 return true;
106}
107
108static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
109 const DetectEngineTransforms *transforms, Flow *_f,
110 const uint8_t _flow_flags, void *txv, const int list_id)
111{
112 InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
113 if (buffer->inspect == NULL) {
114 const uint8_t *b = NULL;
115 uint32_t b_len = 0;
116
117 if (SCSipTxGetMethod(txv, &b, &b_len) != 1)
118 return NULL;
119 if (b == NULL || b_len == 0)
120 return NULL;
121
122 InspectionBufferSetupAndApplyTransforms(det_ctx, list_id, buffer, b, b_len, transforms);
123 }
124
125 return buffer;
126}
127
@ ALPROTO_SIP
int SCDetectBufferSetActiveList(DetectEngineCtx *de_ctx, Signature *s, const int list)
void InspectionBufferSetupAndApplyTransforms(DetectEngineThreadCtx *det_ctx, const int list_id, InspectionBuffer *buffer, const uint8_t *data, const uint32_t data_len, const DetectEngineTransforms *transforms)
setup the buffer with our initial data
InspectionBuffer * InspectionBufferGet(DetectEngineThreadCtx *det_ctx, const int list_id)
void DetectAppLayerMpmRegister(const char *name, int direction, int priority, PrefilterRegisterFunc PrefilterRegister, InspectionBufferGetDataPtr GetData, AppProto alproto, int tx_min_progress)
register an app layer keyword for mpm
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
@ DETECT_SIP_METHOD
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
uint8_t 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.
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
void DetectBufferTypeRegisterValidateCallback(const char *name, bool(*ValidateCallback)(const Signature *, const char **sigerror, const DetectBufferType *))
int DetectBufferTypeGetByName(const char *name)
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
SigTableElmt * sigmatch_table
void DetectSipMethodRegister(void)
#define KEYWORD_DOC
#define BUFFER_DESC
#define BUFFER_NAME
#define KEYWORD_NAME
#define SIGMATCH_NOOPT
Definition detect.h:1651
#define SIG_FLAG_TOSERVER
Definition detect.h:271
DetectEngineCtx * de_ctx
main detection engine ctx
Definition detect.h:932
Flow data structure.
Definition flow.h:356
a single match condition for a signature
Definition detect.h:356
uint16_t type
Definition detect.h:357
struct SigMatch_ * next
Definition detect.h:360
SigMatchCtx * ctx
Definition detect.h:359
const char * url
Definition detect.h:1462
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition detect.h:1441
uint16_t flags
Definition detect.h:1450
const char * desc
Definition detect.h:1461
const char * name
Definition detect.h:1459
SignatureInitDataBuffer * buffers
Definition detect.h:647
uint32_t buffer_index
Definition detect.h:648
Signature container.
Definition detect.h:668
SignatureInitData * init_data
Definition detect.h:747
#define str(s)
#define SCLogDebug(...)
Definition util-debug.h:275
#define SCLogError(...)
Macro used to log ERROR messages.
Definition util-debug.h:267