suricata
detect-smb-ntlmssp.c
Go to the documentation of this file.
1/* Copyright (C) 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 Eric Leblond <el@stamus-networks.com>
22 *
23 */
24
25#include "suricata-common.h"
27
28#include "detect.h"
29#include "detect-parse.h"
30
31#include "detect-engine.h"
33#include "detect-engine-mpm.h"
34#include "detect-engine-state.h"
37
38#include "detect-smb-ntlmssp.h"
39#include "rust.h"
40
41#define BUFFER_NAME "smb_ntlmssp_user"
42#define KEYWORD_NAME "smb.ntlmssp_user"
43#define KEYWORD_ID DETECT_SMB_NTLMSSP_USER
44
45static int g_smb_nltmssp_user_buffer_id = 0;
46
47static int DetectSmbNtlmsspUserSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
48{
49 if (SCDetectBufferSetActiveList(de_ctx, s, g_smb_nltmssp_user_buffer_id) < 0)
50 return -1;
51
53 return -1;
54
55 return 0;
56}
57
58static InspectionBuffer *GetNtlmsspUserData(DetectEngineThreadCtx *det_ctx,
59 const DetectEngineTransforms *transforms, Flow *_f, const uint8_t _flow_flags, void *txv,
60 const int list_id)
61{
62 InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
63 if (buffer->inspect == NULL) {
64 uint32_t b_len = 0;
65 const uint8_t *b = NULL;
66
67 if (SCSmbTxGetNtlmsspUser(txv, &b, &b_len) != 1)
68 return NULL;
69 if (b == NULL || b_len == 0)
70 return NULL;
71
72 InspectionBufferSetupAndApplyTransforms(det_ctx, list_id, buffer, b, b_len, transforms);
73 }
74 return buffer;
75}
76
92
93#undef BUFFER_NAME
94#undef KEYWORD_NAME
95#undef KEYWORD_ID
96
97#define BUFFER_NAME "smb_ntlmssp_domain"
98#define KEYWORD_NAME "smb.ntlmssp_domain"
99#define KEYWORD_ID DETECT_SMB_NTLMSSP_DOMAIN
100
101static int g_smb_nltmssp_domain_buffer_id = 0;
102
103static int DetectSmbNtlmsspDomainSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
104{
105 if (SCDetectBufferSetActiveList(de_ctx, s, g_smb_nltmssp_domain_buffer_id) < 0)
106 return -1;
107
109 return -1;
110
111 return 0;
112}
113
114static InspectionBuffer *GetNtlmsspDomainData(DetectEngineThreadCtx *det_ctx,
115 const DetectEngineTransforms *transforms, Flow *_f, const uint8_t _flow_flags, void *txv,
116 const int list_id)
117{
118 InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
119 if (buffer->inspect == NULL) {
120 uint32_t b_len = 0;
121 const uint8_t *b = NULL;
122
123 if (SCSmbTxGetNtlmsspDomain(txv, &b, &b_len) != 1)
124 return NULL;
125 if (b == NULL || b_len == 0)
126 return NULL;
127
128 InspectionBufferSetupAndApplyTransforms(det_ctx, list_id, buffer, b, b_len, transforms);
129 }
130 return buffer;
131}
132
134{
136 sigmatch_table[KEYWORD_ID].Setup = DetectSmbNtlmsspDomainSetup;
139 "sticky buffer to match on SMB ntlmssp domain in session setup";
140
142 GetNtlmsspDomainData, ALPROTO_SMB, 1);
143
145 DetectEngineInspectBufferGeneric, GetNtlmsspDomainData);
146
147 g_smb_nltmssp_domain_buffer_id = DetectBufferTypeGetByName(BUFFER_NAME);
148}
@ 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
void DetectSmbNtlmsspUserRegister(void)
void DetectSmbNtlmsspDomainRegister(void)
#define BUFFER_NAME
#define KEYWORD_NAME
#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 * name
Definition detect.h:1459
Signature container.
Definition detect.h:668