suricata
detect-sip-uri.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.uri 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#include "detect-urilen.h"
39
40#include "flow.h"
41#include "flow-var.h"
42#include "flow-util.h"
43
44#include "util-debug.h"
45#include "util-unittest.h"
47#include "util-spm.h"
48
49#include "app-layer.h"
50#include "app-layer-parser.h"
51
52#include "detect-sip-uri.h"
53#include "stream-tcp.h"
54
55#include "rust.h"
56
57#define KEYWORD_NAME "sip.uri"
58#define KEYWORD_DOC "sip-keywords.html#sip-uri"
59#define BUFFER_NAME "sip.uri"
60#define BUFFER_DESC "sip request uri"
61static int g_buffer_id = 0;
62
63static void DetectSipUriSetupCallback(const DetectEngineCtx *de_ctx,
64 Signature *s)
65{
66 SCLogDebug("callback invoked by %u", s->id);
67 DetectUrilenApplyToContent(s, g_buffer_id);
68}
69
70static int DetectSipUriSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str)
71{
72 if (SCDetectBufferSetActiveList(de_ctx, s, g_buffer_id) < 0)
73 return -1;
74
76 return -1;
77
78 return 0;
79}
80
81static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
82 const DetectEngineTransforms *transforms, Flow *_f,
83 const uint8_t _flow_flags, void *txv, const int list_id)
84{
85 InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
86 if (buffer->inspect == NULL) {
87 const uint8_t *b = NULL;
88 uint32_t b_len = 0;
89
90 if (SCSipTxGetUri(txv, &b, &b_len) != 1)
91 return NULL;
92 if (b == NULL || b_len == 0)
93 return NULL;
94
95 InspectionBufferSetupAndApplyTransforms(det_ctx, list_id, buffer, b, b_len, transforms);
96 }
97
98 return buffer;
99}
100
@ 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)
void DetectBufferTypeSetDescriptionByName(const char *name, const char *desc)
void DetectBufferTypeRegisterSetupCallback(const char *name, void(*SetupCallback)(const DetectEngineCtx *, Signature *))
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
#define KEYWORD_DOC
#define BUFFER_DESC
#define BUFFER_NAME
#define KEYWORD_NAME
void DetectSipUriRegister(void)
bool DetectUrilenValidateContent(const Signature *s, const char **sigerror, const DetectBufferType *dbt)
void DetectUrilenApplyToContent(Signature *s, int list)
set prefilter dsize pair
#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
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
Signature container.
Definition detect.h:668
uint32_t id
Definition detect.h:713
#define str(s)
#define SCLogDebug(...)
Definition util-debug.h:275