Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect rule hook/v11 #12758

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
626bd3b
detect: reorder struct
victorjulien Feb 27, 2025
b0b6e40
detect: move non-pf rules into special prefilter engines
victorjulien Dec 28, 2023
4239155
detect: allow longer buffer names
victorjulien Jan 20, 2025
79a1b9a
tls: introduce per direction progress tracking
victorjulien Jan 16, 2025
2c815c3
app-layer: API for mapping progress name vs id
victorjulien Jan 17, 2025
66dbabf
tls: expose progress by name
victorjulien Jan 17, 2025
93c9b3e
http1: register progress state names
victorjulien Jan 23, 2025
78b0213
WIP detect: introduce explicit hooks
victorjulien Jan 14, 2025
88b373d
detect/lua: use rule hook instead of init() 'needs' table
victorjulien Jan 19, 2025
fd63091
detect: reuse hook based generic lists
victorjulien Jan 20, 2025
145e8f0
tls/ja3: register keyword at client_hello_done hook
victorjulien Feb 28, 2025
833c525
detect/tls.version: allow using rule hook
victorjulien Feb 28, 2025
080d353
WIP start of pkt hook
victorjulien Jan 23, 2025
7a49c63
WIP start of firewall rules
victorjulien Feb 26, 2025
fe5750c
WIP fw rules
victorjulien Feb 26, 2025
b60ea56
WIP explicit actions
victorjulien Feb 27, 2025
da582b0
detect: require explicit action scope for firewall rules
victorjulien Feb 27, 2025
58587e0
firewall: add --firewall-rules-exclusive
victorjulien Feb 27, 2025
b3216ac
detect/loader: allow -S with --firewall-rules-exclusive
victorjulien Mar 11, 2025
4bc4015
WIP start of a 'all' pkt hook
victorjulien Feb 28, 2025
73e1032
detect: skip duplicate nopacket inspect check
victorjulien Mar 12, 2025
fee6352
WIP firewall: default drop, add accept action
victorjulien Feb 28, 2025
8ebcfe4
WIP remove FLOW_NOPACKET_INSPECTION - not separate from FLOW_ACTION_PASS
victorjulien Mar 13, 2025
8c577e0
detect: check for a flow drop first
victorjulien Mar 13, 2025
8eec6d4
firewall: split pass:flow and accept:flow
victorjulien Mar 13, 2025
62e3139
detect/prefilter: allow special engine for each app update
victorjulien Mar 14, 2025
7198472
detect: request_update/response_update rule hooks
victorjulien Mar 14, 2025
2ec9062
WIP detect/app-layer-state
victorjulien Mar 14, 2025
4c10cee
SQUASH fixup
victorjulien Mar 15, 2025
236eda2
SQUASH fixup
victorjulien Mar 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions etc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5278,6 +5278,16 @@
"description":
"Number of packets dropped due to inner tunnel packet being dropped",
"type": "integer"
},
"default_packet_policy": {
"description":
"Number of packets dropped due to default packet policy",
"type": "integer"
},
"default_app_policy": {
"description":
"Number of packets dropped due to default app policy",
"type": "integer"
}
},
"additionalProperties": false
Expand Down
5 changes: 5 additions & 0 deletions rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,9 @@ pub struct RustParser {

pub get_frame_id_by_name: Option<GetFrameIdByName>,
pub get_frame_name_by_id: Option<GetFrameNameById>,

pub get_state_id_by_name: Option<GetStateIdByName>,
pub get_state_name_by_id: Option<GetStateNameById>,
}

/// Create a slice, given a buffer and a length
Expand Down Expand Up @@ -471,6 +474,8 @@ pub type GetStateDataFn = unsafe extern "C" fn(*mut c_void) -> *mut AppLayerStat
pub type ApplyTxConfigFn = unsafe extern "C" fn (*mut c_void, *mut c_void, c_int, AppLayerTxConfig);
pub type GetFrameIdByName = unsafe extern "C" fn(*const c_char) -> c_int;
pub type GetFrameNameById = unsafe extern "C" fn(u8) -> *const c_char;
pub type GetStateIdByName = unsafe extern "C" fn(*const c_char, u8) -> c_int;
pub type GetStateNameById = unsafe extern "C" fn(c_int, u8) -> *const c_char;


// Defined in app-layer-register.h
Expand Down
2 changes: 2 additions & 0 deletions rust/src/applayertemplate/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ pub unsafe extern "C" fn rs_template_register_parser() {
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/bittorrent_dht/bittorrent_dht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ pub unsafe extern "C" fn SCRegisterBittorrentDhtUdpParser() {
flags: 0,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/dcerpc/dcerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,8 @@ pub unsafe extern "C" fn SCRegisterDcerpcParser() {
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
get_frame_id_by_name: Some(DCERPCFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(DCERPCFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/dcerpc/dcerpc_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ pub unsafe extern "C" fn SCRegisterDcerpcUdpParser() {
flags: 0,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/dhcp/dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ pub unsafe extern "C" fn SCRegisterDhcpParser() {
flags: 0,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down
4 changes: 4 additions & 0 deletions rust/src/dns/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,8 @@ pub unsafe extern "C" fn SCRegisterDnsUdpParser() {
flags: 0,
get_frame_id_by_name: Some(DnsFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(DnsFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down Expand Up @@ -1291,6 +1293,8 @@ pub unsafe extern "C" fn SCRegisterDnsTcpParser() {
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
get_frame_id_by_name: Some(DnsFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(DnsFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/enip/enip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ pub unsafe extern "C" fn SCEnipRegisterParsers() {
flags: 0,
get_frame_id_by_name: Some(EnipFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(EnipFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/http2/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,8 @@ pub unsafe extern "C" fn rs_http2_register_parser() {
flags: 0,
get_frame_id_by_name: Some(Http2FrameType::ffi_id_from_name),
get_frame_name_by_id: Some(Http2FrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/ike/ike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ pub unsafe extern "C" fn rs_ike_register_parser() {
flags: 0,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/krb/krb5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ pub unsafe extern "C" fn rs_register_krb5_parser() {
flags : 0,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};
// register UDP parser
let ip_proto_str = CString::new("udp").unwrap();
Expand Down
4 changes: 4 additions & 0 deletions rust/src/ldap/ldap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,8 @@ pub unsafe extern "C" fn SCRegisterLdapTcpParser() {
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
get_frame_id_by_name: Some(LdapFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(LdapFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down Expand Up @@ -736,6 +738,8 @@ pub unsafe extern "C" fn SCRegisterLdapUdpParser() {
flags: 0,
get_frame_id_by_name: Some(LdapFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(LdapFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/modbus/modbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ pub unsafe extern "C" fn rs_modbus_register_parser() {
flags: 0,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/mqtt/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,8 @@ pub unsafe extern "C" fn SCMqttRegisterParser() {
flags: 0,
get_frame_id_by_name: Some(MQTTFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(MQTTFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
4 changes: 4 additions & 0 deletions rust/src/nfs/nfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,8 @@ pub unsafe extern "C" fn rs_nfs_register_parser() {
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
get_frame_id_by_name: Some(NFSFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(NFSFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down Expand Up @@ -2078,6 +2080,8 @@ pub unsafe extern "C" fn rs_nfs_udp_register_parser() {
flags: 0,
get_frame_id_by_name: Some(NFSFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(NFSFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/ntp/ntp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ pub unsafe extern "C" fn rs_register_ntp_parser() {
flags: 0,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/pgsql/pgsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,8 @@ pub unsafe extern "C" fn SCRegisterPgsqlParser() {
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/quic/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,8 @@ pub unsafe extern "C" fn rs_quic_register_parser() {
flags: 0,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/rdp/rdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ pub unsafe extern "C" fn rs_rdp_register_parser() {
flags: 0,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = std::ffi::CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/rfb/rfb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ pub unsafe extern "C" fn SCRfbRegisterParser() {
flags: 0,
get_frame_id_by_name: Some(RFBFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(RFBFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/sip/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ pub unsafe extern "C" fn rs_sip_register_parser() {
flags: 0,
get_frame_id_by_name: Some(SIPFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(SIPFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("udp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/smb/smb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,8 @@ pub unsafe extern "C" fn rs_smb_register_parser() {
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
get_frame_id_by_name: Some(SMBFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(SMBFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/snmp/snmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ pub unsafe extern "C" fn rs_register_snmp_parser() {
flags : 0,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
get_state_id_by_name: None,
get_state_name_by_id: None,
};
let ip_proto_str = CString::new("udp").unwrap();
if AppLayerProtoDetectConfProtoDetectionEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
Expand Down
2 changes: 2 additions & 0 deletions rust/src/ssh/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ pub unsafe extern "C" fn SCRegisterSshParser() {
flags: 0,
get_frame_id_by_name: Some(SshFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(SshFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions rust/src/telnet/telnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ pub unsafe extern "C" fn rs_telnet_register_parser() {
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
get_frame_id_by_name: Some(TelnetFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(TelnetFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,

};

Expand Down
2 changes: 2 additions & 0 deletions rust/src/websocket/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ pub unsafe extern "C" fn rs_websocket_register_parser() {
flags: 0, // do not accept gaps as there is no good way to resync
get_frame_id_by_name: Some(WebSocketFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(WebSocketFrameType::ffi_name_from_id),
get_state_id_by_name: None,
get_state_name_by_id: None,
};

let ip_proto_str = CString::new("tcp").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ noinst_HEADERS = \
defrag-timeout.h \
detect-app-layer-event.h \
detect-app-layer-protocol.h \
detect-app-layer-state.h \
detect-asn1.h \
detect-base64-data.h \
detect-base64-decode.h \
Expand Down Expand Up @@ -664,6 +665,7 @@ libsuricata_c_a_SOURCES = \
defrag-timeout.c \
detect-app-layer-event.c \
detect-app-layer-protocol.c \
detect-app-layer-state.c \
detect-asn1.c \
detect-base64-data.c \
detect-base64-decode.c \
Expand Down
8 changes: 8 additions & 0 deletions src/action-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,17 @@
#define ACTION_REJECT_BOTH 0x10
#define ACTION_PASS 0x20
#define ACTION_CONFIG 0x40
#define ACTION_ACCEPT 0x80 /**< firewall 'accept' rule */

#define ACTION_REJECT_ANY (ACTION_REJECT|ACTION_REJECT_DST|ACTION_REJECT_BOTH)

#define ACTION_DROP_REJECT (ACTION_REJECT_ANY | ACTION_DROP)

enum ActionScope {
ACTION_SCOPE_AUTO = 0,
ACTION_SCOPE_PACKET, /**< apply action to packet */
ACTION_SCOPE_FLOW, /**< apply drop/pass/accept action to flow */
ACTION_SCOPE_HOOK /**< apply action to current hook */
};

#endif /* SURICATA_ACTION_GLOBALS_H */
4 changes: 2 additions & 2 deletions src/alert-debuglog.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ static TmEcode AlertDebugLogger(ThreadVars *tv, const Packet *p, void *thread_da
p->flow->todstbytecnt + p->flow->tosrcbytecnt);
MemBufferWriteString(aft->buffer,
"FLOW ACTION: DROP: %s\n"
"FLOW NOINSPECTION: PACKET: %s, PAYLOAD: %s, APP_LAYER: %s\n"
"FLOW PAYLOAD: %s, APP_LAYER: %s\n"
"FLOW APP_LAYER: DETECTED: %s, PROTO %" PRIu16 "\n",
p->flow->flags & FLOW_ACTION_DROP ? "TRUE" : "FALSE",
p->flow->flags & FLOW_NOPACKET_INSPECTION ? "TRUE" : "FALSE",
// p->flow->flags & FLOW_NOPACKET_INSPECTION ? "TRUE" : "FALSE",
p->flow->flags & FLOW_NOPAYLOAD_INSPECTION ? "TRUE" : "FALSE",
applayer ? "TRUE" : "FALSE",
(p->flow->alproto != ALPROTO_UNKNOWN) ? "TRUE" : "FALSE", p->flow->alproto);
Expand Down
2 changes: 2 additions & 0 deletions src/app-layer-frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include "rust.h"

/** special value for matching any type */
#define FRAME_ANY_TYPE 62
/** max 63 to fit the 64 bit per protocol space */
#define FRAME_STREAM_TYPE 63

Expand Down
Loading
Loading