From ae2a35260e82ad25dc143e087b4b249bff38adc7 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Mon, 27 Nov 2023 17:07:21 +0100 Subject: [PATCH] detect: flush when setting no_inspection Ticket: 6578 When a protocol such as SSH sets no_inspection, we still have to flush the current streams and packets that contain clear-text for detection. --- src/app-layer-parser.c | 4 +++- src/flow-worker.c | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index 96fc607fd257..a856e79cd187 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -1440,7 +1440,6 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow /* set the packets to no inspection and reassembly if required */ if (pstate->flags & APP_LAYER_PARSER_NO_INSPECTION) { AppLayerParserSetEOF(pstate); - FlowSetNoPayloadInspectionFlag(f); if (f->proto == IPPROTO_TCP) { StreamTcpDisableAppLayer(f); @@ -1462,6 +1461,9 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow StreamTcpSetSessionBypassFlag(ssn); } } + } else { + // for TCP, this is set after flushing + FlowSetNoPayloadInspectionFlag(f); } } diff --git a/src/flow-worker.c b/src/flow-worker.c index 77fe2b87fe12..2e12ddc06726 100644 --- a/src/flow-worker.c +++ b/src/flow-worker.c @@ -371,8 +371,16 @@ static inline void FlowWorkerStreamTCPUpdate(ThreadVars *tv, FlowWorkerThreadDat StreamTcp(tv, p, fw->stream_thread, &fw->pq); FLOWWORKER_PROFILING_END(p, PROFILE_FLOWWORKER_STREAM); - if (FlowChangeProto(p->flow)) { + // this is the first packet that sets no payload inspection + bool setting_nopayload = + p->flow->alparser && + AppLayerParserStateIssetFlag(p->flow->alparser, APP_LAYER_PARSER_NO_INSPECTION) && + !(p->flags & PKT_NOPAYLOAD_INSPECTION); + if (FlowChangeProto(p->flow) || setting_nopayload) { StreamTcpDetectLogFlush(tv, fw->stream_thread, p->flow, p, &fw->pq); + if (setting_nopayload) { + FlowSetNoPayloadInspectionFlag(p->flow); + } AppLayerParserStateSetFlag(p->flow->alparser, APP_LAYER_PARSER_EOF_TS); AppLayerParserStateSetFlag(p->flow->alparser, APP_LAYER_PARSER_EOF_TC); }