|
|
|
|
@ -28,6 +28,7 @@ use crate::detect::{
|
|
|
|
|
SCDetectThreadBufDataInit, SigTableElmtStickyBuffer, SIGMATCH_INFO_ENUM_UINT,
|
|
|
|
|
SIGMATCH_INFO_UINT32, SIGMATCH_INFO_UINT8, SIGMATCH_SUPPORT_FIREWALL,
|
|
|
|
|
};
|
|
|
|
|
use snmp_parser::NetworkAddress;
|
|
|
|
|
use std::ffi::CStr;
|
|
|
|
|
use std::os::raw::{c_int, c_void};
|
|
|
|
|
use suricata_sys::sys::{
|
|
|
|
|
@ -46,6 +47,8 @@ static mut G_SNMP_USM_BUFFER_ID: c_int = 0;
|
|
|
|
|
static mut G_SNMP_COMMUNITY_BUFFER_ID: c_int = 0;
|
|
|
|
|
static mut G_SNMP_TRAPOID_BUFFER_ID: c_int = 0;
|
|
|
|
|
static mut G_SNMP_TRAPOID_THREAD_ID: c_int = 0;
|
|
|
|
|
static mut G_SNMP_TRAPADDRESS_BUFFER_ID: c_int = 0;
|
|
|
|
|
static mut G_SNMP_TRAPADDRESS_THREAD_ID: c_int = 0;
|
|
|
|
|
static mut G_SNMP_TRAPTYPE_KW_ID: u16 = 0;
|
|
|
|
|
static mut G_SNMP_GENERIC_BUFFER_ID: c_int = 0;
|
|
|
|
|
|
|
|
|
|
@ -304,6 +307,48 @@ unsafe extern "C" fn snmp_detect_trapoid_get_data(
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn snmp_detect_trapaddress_setup(
|
|
|
|
|
de: *mut DetectEngineCtx, s: *mut Signature, _raw: *const std::os::raw::c_char,
|
|
|
|
|
) -> c_int {
|
|
|
|
|
if SCDetectSignatureSetAppProto(s, ALPROTO_SNMP) != 0 {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if SCDetectBufferSetActiveList(de, s, G_SNMP_TRAPADDRESS_BUFFER_ID) < 0 {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn snmp_detect_trapaddress_get_data(
|
|
|
|
|
det_ctx: *mut DetectEngineThreadCtx, transforms: *const DetectEngineTransforms,
|
|
|
|
|
_flow: *mut Flow, _dir: u8, tx: *mut c_void, list_id: c_int,
|
|
|
|
|
) -> *mut InspectionBuffer {
|
|
|
|
|
let tx = cast_pointer!(tx, SNMPTransaction);
|
|
|
|
|
let buffer = SCInspectionBufferGet(det_ctx, list_id);
|
|
|
|
|
if !(*buffer).initialized {
|
|
|
|
|
if let Some(info) = &tx.info {
|
|
|
|
|
if let Some((_trap_type, _oid, address)) = &info.trap_type {
|
|
|
|
|
let NetworkAddress::IPv4(ip) = &address;
|
|
|
|
|
let tbuf = SCDetectThreadCtxGetGlobalKeywordThreadCtx(
|
|
|
|
|
det_ctx,
|
|
|
|
|
G_SNMP_TRAPADDRESS_THREAD_ID,
|
|
|
|
|
);
|
|
|
|
|
let tbuf = cast_pointer!(tbuf, DetectThreadBuf);
|
|
|
|
|
tbuf.data.clear();
|
|
|
|
|
tbuf.data.extend_from_slice(ip.to_string().as_bytes());
|
|
|
|
|
let data = tbuf.data.as_ptr();
|
|
|
|
|
let data_len = tbuf.data.len() as u32;
|
|
|
|
|
SCInspectionBufferSetupAndApplyTransforms(
|
|
|
|
|
det_ctx, list_id, buffer, data, data_len, transforms,
|
|
|
|
|
);
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return std::ptr::null_mut();
|
|
|
|
|
}
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(super) unsafe extern "C" fn detect_snmp_register() {
|
|
|
|
|
G_SNMP_GENERIC_BUFFER_ID = SCDetectHelperBufferProgressRegister(
|
|
|
|
|
b"snmp.generic\0".as_ptr() as *const libc::c_char,
|
|
|
|
|
@ -397,4 +442,26 @@ pub(super) unsafe extern "C" fn detect_snmp_register() {
|
|
|
|
|
std::ptr::null_mut(),
|
|
|
|
|
Some(SCDetectThreadBufDataFree),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let kw = SigTableElmtStickyBuffer {
|
|
|
|
|
name: String::from("snmp.trap_address"),
|
|
|
|
|
desc: String::from("SNMP trap address sticky buffer"),
|
|
|
|
|
url: String::from("/rules/snmp-keywords.html#snmp-trap-address"),
|
|
|
|
|
setup: snmp_detect_trapaddress_setup,
|
|
|
|
|
};
|
|
|
|
|
let _g_snmp_trapaddress_kw_id = helper_keyword_register_sticky_buffer(&kw);
|
|
|
|
|
G_SNMP_TRAPADDRESS_BUFFER_ID = SCDetectRegisterMpmGeneric(
|
|
|
|
|
b"snmp.trap_address\0".as_ptr() as *const libc::c_char,
|
|
|
|
|
b"SNMP Trap Address\0".as_ptr() as *const libc::c_char,
|
|
|
|
|
ALPROTO_SNMP,
|
|
|
|
|
STREAM_TOSERVER | STREAM_TOCLIENT,
|
|
|
|
|
Some(snmp_detect_trapaddress_get_data),
|
|
|
|
|
1,
|
|
|
|
|
);
|
|
|
|
|
G_SNMP_TRAPADDRESS_THREAD_ID = SCDetectRegisterThreadCtxGlobalFuncs(
|
|
|
|
|
b"snmp.trap_address\0".as_ptr() as *const libc::c_char,
|
|
|
|
|
Some(SCDetectThreadBufDataInit),
|
|
|
|
|
std::ptr::null_mut(),
|
|
|
|
|
Some(SCDetectThreadBufDataFree),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|