From 01610aabe7d0fad279ac1beb14e08af50c2ebadc Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 29 Jan 2026 22:12:52 +0100 Subject: [PATCH] detect/quic: move quic.cyu.string to rust Ticket: 8255 --- rust/src/quic/detect.rs | 39 ++++- src/Makefile.am | 2 - src/detect-engine-register.c | 2 - src/detect-engine-register.h | 1 - src/detect-quic-cyu-string.c | 272 ----------------------------------- src/detect-quic-cyu-string.h | 28 ---- 6 files changed, 35 insertions(+), 309 deletions(-) delete mode 100644 src/detect-quic-cyu-string.c delete mode 100644 src/detect-quic-cyu-string.h diff --git a/rust/src/quic/detect.rs b/rust/src/quic/detect.rs index 7be2353632..6b71e704f5 100644 --- a/rust/src/quic/detect.rs +++ b/rust/src/quic/detect.rs @@ -17,13 +17,17 @@ use super::quic::ALPROTO_QUIC; use crate::core::{STREAM_TOCLIENT, STREAM_TOSERVER}; -use crate::detect::{helper_keyword_register_sticky_buffer, SigTableElmtStickyBuffer}; +use crate::detect::{ + helper_keyword_register_multi_buffer, helper_keyword_register_sticky_buffer, + SigTableElmtStickyBuffer, +}; use crate::quic::quic::QuicTransaction; use std::os::raw::{c_int, c_void}; use std::ptr; use suricata_sys::sys::{ DetectEngineCtx, DetectEngineThreadCtx, SCDetectBufferSetActiveList, - SCDetectHelperBufferMpmRegister, SCDetectSignatureSetAppProto, Signature, + SCDetectHelperBufferMpmRegister, SCDetectHelperMultiBufferMpmRegister, + SCDetectSignatureSetAppProto, Signature, }; unsafe extern "C" fn quic_tx_get_ua( @@ -129,8 +133,7 @@ pub unsafe extern "C" fn SCQuicTxGetCyuHash( } } -#[no_mangle] -pub unsafe extern "C" fn SCQuicTxGetCyuString( +unsafe extern "C" fn quic_tx_get_cyu_string( _de: *mut DetectEngineThreadCtx, tx: *const c_void, _flags: u8, i: u32, buffer: *mut *const u8, buffer_len: *mut u32, ) -> bool { @@ -187,9 +190,22 @@ unsafe extern "C" fn quic_ua_setup( return 0; } +unsafe extern "C" fn quic_cyu_string_setup( + de: *mut DetectEngineCtx, s: *mut Signature, _raw: *const std::os::raw::c_char, +) -> c_int { + if SCDetectSignatureSetAppProto(s, ALPROTO_QUIC) != 0 { + return -1; + } + if SCDetectBufferSetActiveList(de, s, G_QUIC_CYU_STR_BUFFER_ID) < 0 { + return -1; + } + return 0; +} + static mut G_QUIC_VERSION_BUFFER_ID: c_int = 0; static mut G_QUIC_SNI_BUFFER_ID: c_int = 0; static mut G_QUIC_UA_BUFFER_ID: c_int = 0; +static mut G_QUIC_CYU_STR_BUFFER_ID: c_int = 0; #[no_mangle] pub unsafe extern "C" fn SCDetectQuicRegister() { @@ -237,4 +253,19 @@ pub unsafe extern "C" fn SCDetectQuicRegister() { STREAM_TOSERVER, Some(quic_tx_get_ua), ); + + let kw = SigTableElmtStickyBuffer { + name: String::from("quic.cyu.string"), + desc: String::from("sticky buffer to match on the QUIC CYU string"), + url: String::from("/rules/quic-keywords.html#quic-cyu-string"), + setup: quic_cyu_string_setup, + }; + helper_keyword_register_multi_buffer(&kw); + G_QUIC_CYU_STR_BUFFER_ID = SCDetectHelperMultiBufferMpmRegister( + b"quic.cyu.string\0".as_ptr() as *const libc::c_char, + b"QUIC CYU String\0".as_ptr() as *const libc::c_char, + ALPROTO_QUIC, + STREAM_TOSERVER, + Some(quic_tx_get_cyu_string), + ); } diff --git a/src/Makefile.am b/src/Makefile.am index cfa7b97bbe..9a8ba52a1c 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -265,7 +265,6 @@ noinst_HEADERS = \ detect-prefilter.h \ detect-priority.h \ detect-quic-cyu-hash.h \ - detect-quic-cyu-string.h \ detect-rawbytes.h \ detect-reference.h \ detect-replace.h \ @@ -854,7 +853,6 @@ libsuricata_c_a_SOURCES = \ detect-prefilter.c \ detect-priority.c \ detect-quic-cyu-hash.c \ - detect-quic-cyu-string.c \ detect-rawbytes.c \ detect-reference.c \ detect-replace.c \ diff --git a/src/detect-engine-register.c b/src/detect-engine-register.c index e2d3b5606a..11085ab4f4 100644 --- a/src/detect-engine-register.c +++ b/src/detect-engine-register.c @@ -204,7 +204,6 @@ #include "detect-sip-uri.h" #include "detect-target.h" #include "detect-quic-cyu-hash.h" -#include "detect-quic-cyu-string.h" #include "detect-ja4-hash.h" #include "detect-ftp-command.h" #include "detect-entropy.h" @@ -733,7 +732,6 @@ void SigTableSetup(void) DetectSipUriRegister(); DetectTargetRegister(); DetectQuicCyuHashRegister(); - DetectQuicCyuStringRegister(); DetectJa4HashRegister(); DetectFtpCommandRegister(); DetectFtpCommandDataRegister(); diff --git a/src/detect-engine-register.h b/src/detect-engine-register.h index 94f24f272b..f4e6ed83bd 100644 --- a/src/detect-engine-register.h +++ b/src/detect-engine-register.h @@ -284,7 +284,6 @@ enum DetectKeywordId { DETECT_FTPDATA, DETECT_TARGET, DETECT_QUIC_CYU_HASH, - DETECT_QUIC_CYU_STRING, DETECT_BYPASS, diff --git a/src/detect-quic-cyu-string.c b/src/detect-quic-cyu-string.c deleted file mode 100644 index 1d8c83de3c..0000000000 --- a/src/detect-quic-cyu-string.c +++ /dev/null @@ -1,272 +0,0 @@ -/* Copyright (C) 2021-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. - */ - -/** - * - * Implements the quic.cyu.string sticky buffer - */ - -#include "suricata-common.h" -#include "detect.h" -#include "detect-parse.h" -#include "detect-engine.h" -#include "detect-engine-buffer.h" -#include "detect-engine-mpm.h" -#include "detect-engine-prefilter.h" -#include "detect-engine-content-inspection.h" -#include "detect-quic-cyu-string.h" -#include "detect-engine-build.h" -#include "rust.h" -#include "util-profiling.h" - -#ifdef UNITTESTS -static void DetectQuicCyuStringRegisterTests(void); -#endif - -#define KEYWORD_NAME "quic.cyu.string" -#define KEYWORD_DOC "quic-cyu.html#quic-cyu-string" -#define BUFFER_NAME "quic.cyu.string" -#define BUFFER_DESC "QUIC CYU String" -static int g_buffer_id = 0; - -static int DetectQuicCyuStringSetup(DetectEngineCtx *de_ctx, Signature *s, const char *arg) -{ - if (SCDetectBufferSetActiveList(de_ctx, s, g_buffer_id) < 0) - return -1; - - if (SCDetectSignatureSetAppProto(s, ALPROTO_QUIC) < 0) - return -1; - - return 0; -} - -void DetectQuicCyuStringRegister(void) -{ - /* quic.cyu.string sticky buffer */ - sigmatch_table[DETECT_QUIC_CYU_STRING].name = KEYWORD_NAME; - sigmatch_table[DETECT_QUIC_CYU_STRING].desc = "sticky buffer to match on the QUIC CYU string"; - sigmatch_table[DETECT_QUIC_CYU_STRING].url = "/rules/" KEYWORD_DOC; - sigmatch_table[DETECT_QUIC_CYU_STRING].Setup = DetectQuicCyuStringSetup; - sigmatch_table[DETECT_QUIC_CYU_STRING].flags = - SIGMATCH_NOOPT | SIGMATCH_INFO_STICKY_BUFFER | SIGMATCH_INFO_MULTI_BUFFER; -#ifdef UNITTESTS - sigmatch_table[DETECT_QUIC_CYU_STRING].RegisterTests = DetectQuicCyuStringRegisterTests; -#endif - - DetectAppLayerMultiRegister( - BUFFER_NAME, ALPROTO_QUIC, SIG_FLAG_TOSERVER, 1, SCQuicTxGetCyuString, 2); - - DetectBufferTypeSetDescriptionByName(BUFFER_NAME, BUFFER_DESC); - - g_buffer_id = DetectBufferTypeGetByName(BUFFER_NAME); - - DetectBufferTypeSupportsMultiInstance(BUFFER_NAME); - - SCLogDebug("registering " BUFFER_NAME " rule option"); -} - -#ifdef UNITTESTS -#include "app-layer-parser.h" -#include "util-unittest.h" -#include "util-unittest-helper.h" -#include "flow-util.h" -#include "detect-engine-alert.h" - -/** - * \test DetectQuicCyuStringTest01 is a test for a valid quic packet, matching - * on the cyu string - * - * \retval 1 on success - * \retval 0 on failure - */ -static int DetectQuicCyuStringTest01(void) -{ - /* quic packet */ - uint8_t buf[] = { 0xc3, 0x51, 0x30, 0x34, 0x36, 0x50, 0x76, 0xd8, 0x63, 0xb7, 0x54, 0xf7, 0xab, - 0x32, 0x00, 0x00, 0x00, 0x01, 0x54, 0xfd, 0xf4, 0x79, 0x48, 0x76, 0xd0, 0x87, 0x58, 0x8d, - 0x26, 0x8f, 0xa0, 0x01, 0x04, 0x00, 0x43, 0x48, 0x4c, 0x4f, 0x11, 0x00, 0x00, 0x00, 0x50, - 0x41, 0x44, 0x00, 0xe4, 0x02, 0x00, 0x00, 0x53, 0x4e, 0x49, 0x00, 0xf7, 0x02, 0x00, 0x00, - 0x56, 0x45, 0x52, 0x00, 0xfb, 0x02, 0x00, 0x00, 0x43, 0x43, 0x53, 0x00, 0x0b, 0x03, 0x00, - 0x00, 0x55, 0x41, 0x49, 0x44, 0x2c, 0x03, 0x00, 0x00, 0x54, 0x43, 0x49, 0x44, 0x30, 0x03, - 0x00, 0x00, 0x50, 0x44, 0x4d, 0x44, 0x34, 0x03, 0x00, 0x00, 0x53, 0x4d, 0x48, 0x4c, 0x38, - 0x03, 0x00, 0x00, 0x49, 0x43, 0x53, 0x4c, 0x3c, 0x03, 0x00, 0x00, 0x4e, 0x4f, 0x4e, 0x50, - 0x5c, 0x03, 0x00, 0x00, 0x4d, 0x49, 0x44, 0x53, 0x60, 0x03, 0x00, 0x00, 0x53, 0x43, 0x4c, - 0x53, 0x64, 0x03, 0x00, 0x00, 0x43, 0x53, 0x43, 0x54, 0x64, 0x03, 0x00, 0x00, 0x43, 0x4f, - 0x50, 0x54, 0x64, 0x03, 0x00, 0x00, 0x49, 0x52, 0x54, 0x54, 0x68, 0x03, 0x00, 0x00, 0x43, - 0x46, 0x43, 0x57, 0x6c, 0x03, 0x00, 0x00, 0x53, 0x46, 0x43, 0x57, 0x70, 0x03, 0x00, 0x00, - 0x2d, 0x2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74, 0x23, 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1d, 0x43, - 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00 }; - - Flow f; - void *quic_state = NULL; - Packet *p = NULL; - Signature *s = NULL; - ThreadVars tv; - DetectEngineThreadCtx *det_ctx = NULL; - AppLayerParserThreadCtx *alp_tctx = AppLayerParserThreadCtxAlloc(); - - memset(&tv, 0, sizeof(ThreadVars)); - StatsThreadInit(&tv.stats); - memset(&f, 0, sizeof(Flow)); - - p = UTHBuildPacketReal(buf, sizeof(buf), IPPROTO_UDP, "192.168.1.5", "192.168.1.1", 41424, 443); - - FLOW_INITIALIZE(&f); - f.flags |= FLOW_IPV4; - f.proto = IPPROTO_UDP; - f.protomap = FlowGetProtoMapping(f.proto); - - p->flow = &f; - p->flags |= PKT_HAS_FLOW; - p->flowflags |= FLOW_PKT_TOSERVER; - f.alproto = ALPROTO_QUIC; - - DetectEngineCtx *de_ctx = DetectEngineCtxInit(); - FAIL_IF_NULL(de_ctx); - de_ctx->mpm_matcher = mpm_default_matcher; - de_ctx->flags |= DE_QUIET; - - s = DetectEngineAppendSig(de_ctx, "alert quic any any -> any any " - "(msg:\"Test QUIC CYU string\"; " - "quic.cyu.string; " - "content:\"46,PAD-SNI-VER-CCS-UAID-TCID-PDMD-SMHL-ICSL-NONP-" - "MIDS-SCLS-CSCT-COPT-IRTT-CFCW-SFCW\"; " - "sid:1;)"); - FAIL_IF_NULL(s); - - SigGroupBuild(de_ctx); - DetectEngineThreadCtxInit(&tv, (void *)de_ctx, (void *)&det_ctx); - - int r = AppLayerParserParse( - NULL, alp_tctx, &f, ALPROTO_QUIC, STREAM_TOSERVER, buf, sizeof(buf)); - if (r != 0) { - printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r); - FAIL; - } - - quic_state = f.alstate; - FAIL_IF_NULL(quic_state); - - /* do detect */ - SigMatchSignatures(&tv, de_ctx, det_ctx, p); - - if (!(PacketAlertCheck(p, 1))) { - printf("sig 1 didn't alert, but it should have: "); - FAIL; - } - - if (alp_tctx != NULL) - AppLayerParserThreadCtxFree(alp_tctx); - if (det_ctx != NULL) - DetectEngineThreadCtxDeinit(&tv, det_ctx); - if (de_ctx != NULL) - SigGroupCleanup(de_ctx); - if (de_ctx != NULL) - DetectEngineCtxFree(de_ctx); - - FLOW_DESTROY(&f); - UTHFreePacket(p); - StatsThreadCleanup(&tv.stats); - PASS; -} - -/** - * \brief this function registers unit tests for Quic Cyu String - */ -static void DetectQuicCyuStringRegisterTests(void) -{ - UtRegisterTest("DetectQuicCyuStringTest01", DetectQuicCyuStringTest01); -} - -#endif /* UNITTESTS */ diff --git a/src/detect-quic-cyu-string.h b/src/detect-quic-cyu-string.h deleted file mode 100644 index 33e1439be7..0000000000 --- a/src/detect-quic-cyu-string.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 2021 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 - * - */ - -#ifndef SURICATA_DETECT_QUIC_CYU_STRING_H -#define SURICATA_DETECT_QUIC_CYU_STRING_H - -void DetectQuicCyuStringRegister(void); - -#endif /* SURICATA_DETECT_QUIC_CYU_STRING_H */