From efa1e3d72e85a431a8378f424918fd1d411f26d3 Mon Sep 17 00:00:00 2001 From: Shivani Bhardwaj Date: Wed, 21 May 2025 12:15:11 +0530 Subject: [PATCH] ssh: trigger raw stream inspection Internals --------- Suricata's stream engine returns data for inspection to the detection engine from the stream when the chunk size is reached. Bug --- Inspection triggered only in the specified chunk sizes may be too late when it comes to inspection of smaller protocol specific data which could result in delayed inspection, incorrect data logged with a transaction and logs misindicating the pkt that triggered an alert. Fix --- Fix this by making an explicit call from all respective applayer parsers to trigger raw stream inspection which shall make the data available for inspection in the following call of the stream engine. This needs to happen per direction on the completion of an entity like a request or a response. Important notes --------------- 1. The above mentioned behavior with and without this patch is affected internally by the following conditions. - inspection depth - stream depth In these special cases, the inspection window will be affected and Suricata may not consider all the data that could be expected to be inspected. 2. This only applies to applayer protocols running over TCP. 3. The inspection window is only considered up to the ACK'd data. 4. This entire issue is about IDS mode only. SSH parser creates a new record per request or response. Appropriate calls to trigger raw stream inspection have been added on succesful parsing of each request and response. Task 7026 Bug 7004 --- rust/src/ssh/ssh.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rust/src/ssh/ssh.rs b/rust/src/ssh/ssh.rs index 174644d85b..548fea9db3 100644 --- a/rust/src/ssh/ssh.rs +++ b/rust/src/ssh/ssh.rs @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Open Information Security Foundation +/* Copyright (C) 2020-2025 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 @@ -344,6 +344,12 @@ impl SSHState { if r.is_incomplete() { //adds bytes consumed by banner to incomplete result r.consumed += (input.len() - rem.len()) as u32; + } else if r.is_ok() { + let mut dir = Direction::ToServer as i32; + if resp { + dir = Direction::ToClient as i32; + } + sc_app_layer_parser_trigger_raw_stream_inspection(flow, dir); } return r; } @@ -384,6 +390,12 @@ impl SSHState { if r.is_incomplete() { //adds bytes consumed by banner to incomplete result r.consumed += (input.len() - rem.len()) as u32; + } else if r.is_ok() { + let mut dir = Direction::ToServer as i32; + if resp { + dir = Direction::ToClient as i32; + } + sc_app_layer_parser_trigger_raw_stream_inspection(flow, dir); } return r; }