From: Philippe Antoine Date: Thu, 17 Dec 2020 14:57:00 +0000 (+0100) Subject: http2: http.stat_msg keyword now works for HTTP2 X-Git-Tag: suricata-7.0.0-beta1~1788 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F5875%2Fhead;p=thirdparty%2Fsuricata.git http2: http.stat_msg keyword now works for HTTP2 --- diff --git a/rust/src/http2/detect.rs b/rust/src/http2/detect.rs index a03fff12f3..6d7e6b1d48 100644 --- a/rust/src/http2/detect.rs +++ b/rust/src/http2/detect.rs @@ -540,6 +540,18 @@ pub unsafe extern "C" fn rs_http2_tx_get_useragent( return 0; } +#[no_mangle] +pub unsafe extern "C" fn rs_http2_tx_get_status( + tx: &mut HTTP2Transaction, buffer: *mut *const u8, buffer_len: *mut u32, +) -> u8 { + if let Ok(value) = http2_frames_get_header_value(&tx.frames_tc, ":status") { + *buffer = value.as_ptr(); //unsafe + *buffer_len = value.len() as u32; + return 1; + } + return 0; +} + fn http2_escape_header(hd: &parser::HTTP2FrameHeaders, i: u32) -> Vec { //minimum size + 2 for escapes let normalsize = hd.blocks[i as usize].value.len() + 2 + hd.blocks[i as usize].name.len() + 2; diff --git a/src/detect-http-stat-msg.c b/src/detect-http-stat-msg.c index 44952331e7..70f2c2acd8 100644 --- a/src/detect-http-stat-msg.c +++ b/src/detect-http-stat-msg.c @@ -71,6 +71,9 @@ static int g_http_stat_msg_buffer_id = 0; static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, const DetectEngineTransforms *transforms, Flow *_f, const uint8_t _flow_flags, void *txv, const int list_id); +static InspectionBuffer *GetData2(DetectEngineThreadCtx *det_ctx, + const DetectEngineTransforms *transforms, Flow *_f, const uint8_t _flow_flags, void *txv, + const int list_id); static int DetectHttpStatMsgSetupSticky(DetectEngineCtx *de_ctx, Signature *s, const char *str); /** @@ -102,6 +105,12 @@ void DetectHttpStatMsgRegister (void) DetectAppLayerMpmRegister2("http_stat_msg", SIG_FLAG_TOCLIENT, 3, PrefilterGenericMpmRegister, GetData, ALPROTO_HTTP1, HTP_RESPONSE_LINE); + DetectAppLayerInspectEngineRegister2("http_stat_msg", ALPROTO_HTTP2, SIG_FLAG_TOCLIENT, + HTTP2StateDataServer, DetectEngineInspectBufferGeneric, GetData2); + + DetectAppLayerMpmRegister2("http_stat_msg", SIG_FLAG_TOCLIENT, 2, PrefilterGenericMpmRegister, + GetData2, ALPROTO_HTTP2, HTTP2StateDataServer); + DetectBufferTypeSetDescriptionByName("http_stat_msg", "http response status message"); @@ -138,7 +147,7 @@ static int DetectHttpStatMsgSetupSticky(DetectEngineCtx *de_ctx, Signature *s, c { if (DetectBufferSetActiveList(s, g_http_stat_msg_buffer_id) < 0) return -1; - if (DetectSignatureSetAppProto(s, ALPROTO_HTTP1) < 0) + if (DetectSignatureSetAppProto(s, ALPROTO_HTTP) < 0) return -1; return 0; } @@ -166,6 +175,29 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, return buffer; } +static InspectionBuffer *GetData2(DetectEngineThreadCtx *det_ctx, + const DetectEngineTransforms *transforms, Flow *_f, const uint8_t _flow_flags, void *txv, + const int list_id) +{ + SCEnter(); + + InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id); + if (buffer->inspect == NULL) { + uint32_t b_len = 0; + const uint8_t *b = NULL; + + if (rs_http2_tx_get_status(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; +} + #ifdef UNITTESTS #include "tests/detect-http-stat-msg.c" #endif /* UNITTESTS */