]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
enip: trigger raw stream reassembly
authorShivani Bhardwaj <shivani@oisf.net>
Thu, 8 May 2025 07:05:58 +0000 (12:35 +0530)
committerShivani Bhardwaj <shivanib134@gmail.com>
Thu, 15 May 2025 07:12:36 +0000 (12:42 +0530)
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 reassembly 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.

ENIP has a classic request response model, so, a call to trigger raw
stream reassembly is added on completion of each request and response.

Optimization 7026
Bug 7004

rust/src/enip/enip.rs

index ce7610bca3458d10addb9777e20e5838fe1b5e54..11e7a93d3f433c8f610ed4a9dd0cdc3017f24f05 100644 (file)
@@ -19,20 +19,17 @@ use super::constant::{EnipCommand, EnipStatus};
 use super::parser;
 use crate::applayer::{self, *};
 use crate::conf::conf_get;
-use crate::core::{
-    ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP, IPPROTO_UDP,
-    STREAM_TOCLIENT, STREAM_TOSERVER,
-};
+use crate::core::*;
 use crate::detect::EnumString;
 use crate::direction::Direction;
 use crate::flow::Flow;
 use crate::frames::Frame;
 use nom7 as nom;
-use suricata_sys::sys::AppProto;
 use std;
 use std::collections::VecDeque;
 use std::ffi::CString;
 use std::os::raw::{c_char, c_int, c_void};
+use suricata_sys::sys::AppProto;
 
 pub(super) static mut ALPROTO_ENIP: AppProto = ALPROTO_UNKNOWN;
 
@@ -299,6 +296,10 @@ impl EnipState {
                                 tx.tx_data.set_event(EnipEvent::InvalidPdu as u8);
                             }
                             tx.response = Some(pdu);
+                            sc_app_layer_parser_trigger_raw_stream_reassembly(
+                                flow,
+                                Direction::ToClient as i32,
+                            );
                             start = rem;
                             continue;
                         }
@@ -314,8 +315,10 @@ impl EnipState {
                         }
                         if request {
                             tx.request = Some(pdu);
+                            sc_app_layer_parser_trigger_raw_stream_reassembly(flow, Direction::ToServer as i32);
                         } else {
                             tx.response = Some(pdu);
+                            sc_app_layer_parser_trigger_raw_stream_reassembly(flow, Direction::ToClient as i32);
                         }
                         self.transactions.push_back(tx);
                     }