detect/smb: add smb.ntlmssp_user keyword

Feature #5411.
pull/7959/head
Eric Leblond 5 years ago committed by Victor Julien
parent f46f895e8d
commit 69ef1bc194

@ -170,3 +170,26 @@ pub extern "C" fn rs_smb_tx_get_dce_iface(state: &mut SMBState,
}
return 0;
}
#[no_mangle]
pub unsafe extern "C" fn rs_smb_tx_get_ntlmssp_user(tx: &mut SMBTransaction,
buffer: *mut *const u8,
buffer_len: *mut u32)
-> u8
{
match tx.type_data {
Some(SMBTransactionTypeData::SESSIONSETUP(ref x)) => {
if let Some(ref ntlmssp) = x.ntlmssp {
*buffer = ntlmssp.user.as_ptr();
*buffer_len = ntlmssp.user.len() as u32;
return 1;
}
}
_ => {
}
}
*buffer = ptr::null();
*buffer_len = 0;
return 0;
}

@ -291,6 +291,7 @@ noinst_HEADERS = \
detect-sip-stat-code.h \
detect-sip-stat-msg.h \
detect-sip-uri.h \
detect-smb-ntlmssp.h \
detect-smb-share.h \
detect-snmp-community.h \
detect-snmp-pdu_type.h \
@ -895,6 +896,7 @@ libsuricata_c_a_SOURCES = \
detect-sip-stat-code.c \
detect-sip-stat-msg.c \
detect-sip-uri.c \
detect-smb-ntlmssp.c \
detect-smb-share.c \
detect-snmp-community.c \
detect-snmp-pdu_type.c \

@ -21,6 +21,7 @@
* \author Victor Julien <victor@inliniac.net>
*/
#include "detect-smb-ntlmssp.h"
#include "suricata-common.h"
#include "suricata.h"
#include "detect.h"
@ -591,6 +592,7 @@ void SigTableSetup(void)
DetectDceStubDataRegister();
DetectSmbNamedPipeRegister();
DetectSmbShareRegister();
DetectSmbNtlmsspUserRegister();
DetectTlsRegister();
DetectTlsValidityRegister();
DetectTlsVersionRegister();

@ -192,6 +192,7 @@ enum DetectKeywordId {
DETECT_DCE_STUB_DATA,
DETECT_SMB_NAMED_PIPE,
DETECT_SMB_SHARE,
DETECT_SMB_NTLMSSP_USER,
DETECT_ASN1,

@ -0,0 +1,90 @@
/* Copyright (C) 2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* \file
*
* \author Eric Leblond <el@stamus-networks.com>
*
*/
#include "suricata-common.h"
#include "detect.h"
#include "detect-parse.h"
#include "detect-engine.h"
#include "detect-engine-mpm.h"
#include "detect-engine-state.h"
#include "detect-engine-prefilter.h"
#include "detect-engine-content-inspection.h"
#include "detect-smb-ntlmssp.h"
#include "rust.h"
#define BUFFER_NAME "smb_ntlmssp_user"
#define KEYWORD_NAME "smb.ntlmssp_user"
#define KEYWORD_ID DETECT_SMB_NTLMSSP_USER
static int g_smb_nltmssp_user_buffer_id = 0;
static int DetectSmbNtlmsspUserSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg)
{
if (DetectBufferSetActiveList(s, g_smb_nltmssp_user_buffer_id) < 0)
return -1;
if (DetectSignatureSetAppProto(s, ALPROTO_SMB) < 0)
return -1;
return 0;
}
static InspectionBuffer *GetNtlmsspUserData(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms, Flow *_f, const uint8_t _flow_flags, void *txv,
const int list_id)
{
InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id);
if (buffer->inspect == NULL) {
uint32_t b_len = 0;
const uint8_t *b = NULL;
if (rs_smb_tx_get_ntlmssp_user(txv, &b, &b_len) != 1)
return NULL;
if (b == NULL || b_len == 0)
return NULL;
InspectionBufferSetup(det_ctx, list_id, buffer, b, b_len);
InspectionBufferApplyTransforms(buffer, transforms);
}
return buffer;
}
void DetectSmbNtlmsspUserRegister(void)
{
sigmatch_table[KEYWORD_ID].name = KEYWORD_NAME;
sigmatch_table[KEYWORD_ID].Setup = DetectSmbNtlmsspUserSetup;
sigmatch_table[KEYWORD_ID].flags |= SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER;
sigmatch_table[KEYWORD_ID].desc = "sticky buffer to match on SMB ntlmssp user in session setup";
DetectAppLayerMpmRegister2(BUFFER_NAME, SIG_FLAG_TOSERVER, 2, PrefilterGenericMpmRegister,
GetNtlmsspUserData, ALPROTO_SMB, 1);
DetectAppLayerInspectEngineRegister2(BUFFER_NAME, ALPROTO_SMB, SIG_FLAG_TOSERVER, 0,
DetectEngineInspectBufferGeneric, GetNtlmsspUserData);
g_smb_nltmssp_user_buffer_id = DetectBufferTypeGetByName(BUFFER_NAME);
}

@ -0,0 +1,29 @@
/* Copyright (C) 2022 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* \file
*
* \author Eric Leblond <el@stamus-networks.com>
*/
#ifndef __DETECT_SMB_NTLMSSP_H__
#define __DETECT_SMB_NTLMSSP_H__
void DetectSmbNtlmsspUserRegister(void);
#endif /* __DETECT_SMB_NTLMSSP_H__ */
Loading…
Cancel
Save