]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
ldap: trigger raw stream reassembly
authorShivani Bhardwaj <shivani@oisf.net>
Thu, 8 May 2025 07:07:00 +0000 (12:37 +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.

LDAP can have multiple responses corresponding to a request. The call to
trigger raw stream reassembly has been added on common call sites that
see the completion of a request or any of the responses.

Optimization 7026
Bug 7004

rust/src/ldap/ldap.rs

index dcbaa3681439e047c93c6e583ba60ee3d4865c53..a82022567470210f889f900b5c87ab2b3383223b 100644 (file)
@@ -237,6 +237,10 @@ impl LdapState {
                     tx.complete |= tx_is_complete(&request.protocol_op, Direction::ToServer);
                     tx.request = Some(request);
                     self.transactions.push_back(tx);
+                    sc_app_layer_parser_trigger_raw_stream_reassembly(
+                        flow,
+                        Direction::ToServer as i32,
+                    );
                     let consumed = start.len() - rem.len();
                     start = rem;
                     self.set_frame_ts(flow, tx_id, consumed as i64);
@@ -304,6 +308,10 @@ impl LdapState {
                         let tx_id = tx.id();
                         tx.tx_data.updated_tc = true;
                         tx.responses.push_back(response);
+                        sc_app_layer_parser_trigger_raw_stream_reassembly(
+                            flow,
+                            Direction::ToClient as i32,
+                        );
                         let consumed = start.len() - rem.len();
                         self.set_frame_tc(flow, tx_id, consumed as i64);
                     } else if let ProtocolOp::ExtendedResponse(_) = response.protocol_op {
@@ -318,6 +326,10 @@ impl LdapState {
                         tx.complete = true;
                         tx.responses.push_back(response);
                         self.transactions.push_back(tx);
+                        sc_app_layer_parser_trigger_raw_stream_reassembly(
+                            flow,
+                            Direction::ToClient as i32,
+                        );
                         let consumed = start.len() - rem.len();
                         self.set_frame_tc(flow, tx_id, consumed as i64);
                     } else {
@@ -330,6 +342,10 @@ impl LdapState {
                         let tx_id = tx.id();
                         tx.responses.push_back(response);
                         self.transactions.push_back(tx);
+                        sc_app_layer_parser_trigger_raw_stream_reassembly(
+                            flow,
+                            Direction::ToClient as i32,
+                        );
                         self.set_event(LdapEvent::RequestNotFound);
                         let consumed = start.len() - rem.len();
                         self.set_frame_tc(flow, tx_id, consumed as i64);