suricata
detect-dce-iface.c
Go to the documentation of this file.
1/* Copyright (C) 2007-2022 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 Anoop Saldanha <anoopsaldanha@gmail.com>
22 *
23 * Implements dce_iface keyword.
24 */
25
26#include "suricata-common.h"
27
28#include "detect.h"
29#include "detect-parse.h"
30
31#include "detect-engine.h"
32#include "detect-engine-mpm.h"
33#include "detect-engine-state.h"
34#include "detect-engine-build.h"
35#include "detect-dce-iface.h"
36
37#include "flow.h"
38#include "flow-var.h"
39#include "flow-util.h"
40
41#include "app-layer.h"
42#include "queue.h"
44
45#include "util-debug.h"
46#include "util-unittest.h"
48#include "stream-tcp.h"
49
50#include "rust.h"
51
52#define PARSE_REGEX "^\\s*([0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12})(?:\\s*,\\s*(<|>|=|!)([0-9]{1,5}))?(?:\\s*,\\s*(any_frag))?\\s*$"
53
54static DetectParseRegex parse_regex;
55
56static int DetectDceIfaceMatchRust(DetectEngineThreadCtx *det_ctx,
57 Flow *f, uint8_t flags, void *state, void *txv,
58 const Signature *s, const SigMatchCtx *m);
59static int DetectDceIfaceSetup(DetectEngineCtx *, Signature *, const char *);
60static void DetectDceIfaceFree(DetectEngineCtx *, void *);
61static int g_dce_generic_list_id = 0;
62
63/**
64 * \brief Registers the keyword handlers for the "dce_iface" keyword.
65 */
87
88/**
89 * \brief App layer match function for the "dce_iface" keyword.
90 *
91 * \param t Pointer to the ThreadVars instance.
92 * \param det_ctx Pointer to the DetectEngineThreadCtx.
93 * \param f Pointer to the flow.
94 * \param flags Pointer to the flags indicating the flow direction.
95 * \param state Pointer to the app layer state data.
96 * \param s Pointer to the Signature instance.
97 * \param m Pointer to the SigMatch.
98 *
99 * \retval 1 On Match.
100 * \retval 0 On no match.
101 */
102static int DetectDceIfaceMatchRust(DetectEngineThreadCtx *det_ctx,
103 Flow *f, uint8_t flags, void *state, void *txv,
104 const Signature *s, const SigMatchCtx *m)
105{
106 SCEnter();
107
108 if (f->alproto == ALPROTO_DCERPC) {
109 // TODO check if state is NULL
110 return SCDcerpcIfaceMatch(txv, state, (void *)m);
111 }
112
113 int ret = 0;
114
115 if (SCSmbTxGetDceIface(f->alstate, txv, (void *)m) != 1) {
116 SCLogDebug("SCSmbTxGetDceIface: didn't match");
117 } else {
118 SCLogDebug("SCSmbTxGetDceIface: matched!");
119 ret = 1;
120 // TODO validate frag
121 }
122 SCReturnInt(ret);
123}
124
125/**
126 * \brief Creates a SigMatch for the "dce_iface" keyword being sent as argument,
127 * and appends it to the Signature(s).
128 *
129 * \param de_ctx Pointer to the detection engine context.
130 * \param s Pointer to signature for the current Signature being parsed
131 * from the rules.
132 * \param arg Pointer to the string holding the keyword value.
133 *
134 * \retval 0 on success, -1 on failure.
135 */
136
137static int DetectDceIfaceSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
138{
139 SCEnter();
140
142 return -1;
143
144 void *did = SCDcerpcIfaceParse(arg);
145 if (did == NULL) {
146 SCLogError("Error parsing dce_iface option in "
147 "signature");
148 return -1;
149 }
150
151 if (SCSigMatchAppendSMToList(de_ctx, s, DETECT_DCE_IFACE, did, g_dce_generic_list_id) == NULL) {
152 DetectDceIfaceFree(de_ctx, did);
153 return -1;
154 }
155 return 0;
156}
157
158static void DetectDceIfaceFree(DetectEngineCtx *de_ctx, void *ptr)
159{
160 SCEnter();
161 if (ptr != NULL) {
162 SCDcerpcIfaceFree(ptr);
163 }
164 SCReturn;
165}
@ ALPROTO_DCERPC
@ ALPROTO_SMB
uint8_t flags
Definition decode-gre.h:0
void DetectDceIfaceRegister(void)
Registers the keyword handlers for the "dce_iface" keyword.
#define PARSE_REGEX
Data structures and function prototypes for keeping state for the detection engine.
int DetectBufferTypeRegister(const char *name)
void DetectAppLayerInspectEngineRegister(const char *name, AppProto alproto, uint32_t dir, int progress, InspectEngineFuncPtr Callback, InspectionBufferGetDataPtr GetData)
Registers an app inspection engine.
uint8_t DetectEngineInspectGenericList(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const struct 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 DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
int SCDetectSignatureSetAppProto(Signature *s, AppProto alproto)
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
SigTableElmt * sigmatch_table
#define SIG_FLAG_TOCLIENT
Definition detect.h:272
#define SIG_FLAG_TOSERVER
Definition detect.h:271
SCMutex m
Definition flow-hash.h:6
DetectEngineCtx * de_ctx
main detection engine ctx
Definition detect.h:932
Flow data structure.
Definition flow.h:356
AppProto alproto
application level protocol
Definition flow.h:450
void * alstate
Definition flow.h:479
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition detect.h:351
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition detect.h:1441
void(* Free)(DetectEngineCtx *, void *)
Definition detect.h:1446
int(* AppLayerTxMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, void *alstate, void *txv, const Signature *, const SigMatchCtx *)
Definition detect.h:1424
const char * alias
Definition detect.h:1460
const char * name
Definition detect.h:1459
Signature container.
Definition detect.h:668
#define SCEnter(...)
Definition util-debug.h:277
#define SCLogDebug(...)
Definition util-debug.h:275
#define SCReturnInt(x)
Definition util-debug.h:281
#define SCLogError(...)
Macro used to log ERROR messages.
Definition util-debug.h:267
#define SCReturn
Definition util-debug.h:279