suricata
detect-smb-share.c
Go to the documentation of this file.
1/* Copyright (C) 2017 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 * \file
20 *
21 * \author Victor Julien <victor@inliniac.net>
22 *
23 */
24
25#include "suricata-common.h"
26
27#include "detect.h"
28#include "detect-parse.h"
29
30#include "detect-engine.h"
32#include "detect-engine-mpm.h"
33#include "detect-engine-state.h"
36
37#include "detect-smb-share.h"
38#include "rust.h"
39
40#define BUFFER_NAME "smb_named_pipe"
41#define KEYWORD_NAME "smb.named_pipe"
42#define KEYWORD_NAME_LEGACY BUFFER_NAME
43#define KEYWORD_ID DETECT_SMB_NAMED_PIPE
44
45static int g_smb_named_pipe_buffer_id = 0;
46
47static int DetectSmbNamedPipeSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
48{
49 if (SCDetectBufferSetActiveList(de_ctx, s, g_smb_named_pipe_buffer_id) < 0)
50 return -1;
51
53 return -1;
54
55 return 0;
56}
57
58static InspectionBuffer *GetNamedPipeData(DetectEngineThreadCtx *det_ctx,
59 const DetectEngineTransforms *transforms,
60 Flow *_f, const uint8_t _flow_flags,
61 void *txv, const int list_id)
62{
63 InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
64 if (buffer->inspect == NULL) {
65 uint32_t b_len = 0;
66 const uint8_t *b = NULL;
67
68 if (SCSmbTxGetNamedPipe(txv, &b, &b_len) != 1)
69 return NULL;
70 if (b == NULL || b_len == 0)
71 return NULL;
72
73 InspectionBufferSetupAndApplyTransforms(det_ctx, list_id, buffer, b, b_len, transforms);
74 }
75 return buffer;
76}
77
94
95#undef BUFFER_NAME
96#undef KEYWORD_NAME
97#undef KEYWORD_NAME_LEGACY
98#undef KEYWORD_ID
99
100#define BUFFER_NAME "smb_share"
101#define KEYWORD_NAME "smb.share"
102#define KEYWORD_NAME_LEGACY BUFFER_NAME
103#define KEYWORD_ID DETECT_SMB_SHARE
104
105static int g_smb_share_buffer_id = 0;
106
107static int DetectSmbShareSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
108{
109 if (SCDetectBufferSetActiveList(de_ctx, s, g_smb_share_buffer_id) < 0)
110 return -1;
111
113 return -1;
114
115 return 0;
116}
117
118static InspectionBuffer *GetShareData(DetectEngineThreadCtx *det_ctx,
119 const DetectEngineTransforms *transforms,
120 Flow *_f, const uint8_t _flow_flags,
121 void *txv, const int list_id)
122{
123 InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
124 if (buffer->inspect == NULL) {
125 uint32_t b_len = 0;
126 const uint8_t *b = NULL;
127
128 if (SCSmbTxGetShare(txv, &b, &b_len) != 1)
129 return NULL;
130 if (b == NULL || b_len == 0)
131 return NULL;
132
133 InspectionBufferSetupAndApplyTransforms(det_ctx, list_id, buffer, b, b_len, transforms);
134 }
135 return buffer;
136}
137
@ ALPROTO_SMB
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)
Data structures and function prototypes for keeping state for the detection engine.
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.
int DetectBufferTypeGetByName(const char *name)
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
SigTableElmt * sigmatch_table
#define KEYWORD_NAME_LEGACY
void DetectSmbNamedPipeRegister(void)
#define BUFFER_NAME
#define KEYWORD_NAME
void DetectSmbShareRegister(void)
#define KEYWORD_ID
#define SIGMATCH_NOOPT
Definition detect.h:1651
#define SIGMATCH_INFO_STICKY_BUFFER
Definition detect.h:1676
#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
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 * alias
Definition detect.h:1460
const char * name
Definition detect.h:1459
Signature container.
Definition detect.h:668