/src/suricata8/rust/src/smb/session.rs
Line | Count | Source |
1 | | /* Copyright (C) 2018-2026 Open Information Security Foundation |
2 | | * |
3 | | * You can copy, redistribute or modify this Program under the terms of |
4 | | * the GNU General Public License version 2 as published by the Free |
5 | | * Software Foundation. |
6 | | * |
7 | | * This program is distributed in the hope that it will be useful, |
8 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | | * GNU General Public License for more details. |
11 | | * |
12 | | * You should have received a copy of the GNU General Public License |
13 | | * version 2 along with this program; if not, write to the Free Software |
14 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
15 | | * 02110-1301, USA. |
16 | | */ |
17 | | |
18 | | use crate::kerberos::*; |
19 | | use crate::smb::smb::*; |
20 | | use crate::smb::smb1_session::*; |
21 | | use crate::smb::auth::*; |
22 | | |
23 | | #[derive(Default, Debug)] |
24 | | pub struct SMBTransactionSessionSetup { |
25 | | pub request_host: Option<SessionSetupRequest>, |
26 | | pub response_host: Option<SessionSetupResponse>, |
27 | | pub ntlmssp: Option<NtlmsspData>, |
28 | | pub krb_ticket: Option<Kerberos5Ticket>, |
29 | | } |
30 | | |
31 | | impl SMBTransactionSessionSetup { |
32 | 96.2k | pub fn new() -> Self { |
33 | 96.2k | return Default::default() |
34 | 96.2k | } |
35 | | } |
36 | | |
37 | | impl SMBState { |
38 | 96.2k | pub fn new_sessionsetup_tx(&mut self, hdr: SMBCommonHdr) |
39 | 96.2k | -> Option<&mut SMBTransaction> |
40 | | { |
41 | 96.2k | let mut tx = self.new_tx()?; |
42 | | |
43 | 96.2k | tx.hdr = hdr; |
44 | 96.2k | tx.type_data = Some(SMBTransactionTypeData::SESSIONSETUP( |
45 | 96.2k | SMBTransactionSessionSetup::new())); |
46 | 96.2k | tx.request_done = true; |
47 | 96.2k | tx.response_done = self.tc_trunc; // no response expected if tc is truncated |
48 | | |
49 | | SCLogDebug!("SMB: TX SESSIONSETUP created: ID {}", tx.id); |
50 | 96.2k | self.transactions.push_back(tx); |
51 | 96.2k | self.transactions.back_mut() |
52 | 96.2k | } |
53 | | |
54 | 28.5k | pub fn get_sessionsetup_tx(&mut self, hdr: SMBCommonHdr) |
55 | 28.5k | -> Option<&mut SMBTransaction> |
56 | | { |
57 | 1.43M | for tx in &mut self.transactions { |
58 | 1.41M | let hit = tx.hdr.compare(&hdr) && match tx.type_data { |
59 | 8.13k | Some(SMBTransactionTypeData::SESSIONSETUP(_)) => { true }, |
60 | 3.29k | _ => { false }, |
61 | | }; |
62 | 1.41M | if hit { |
63 | 8.13k | tx.tx_data.updated_tc = true; |
64 | 8.13k | tx.tx_data.updated_ts = true; |
65 | 8.13k | return Some(tx); |
66 | 1.40M | } |
67 | | } |
68 | 20.4k | return None; |
69 | 28.5k | } |
70 | | } |