• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 22618661228

02 Mar 2026 09:33PM UTC coverage: 42.258% (-34.4%) from 76.611%
22618661228

push

github

victorjulien
github-actions: bump actions/download-artifact from 7.0.0 to 8.0.0

Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 7.0.0 to 8.0.0.
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/37930b1c2...70fc10c6e)

---
updated-dependencies:
- dependency-name: actions/download-artifact
  dependency-version: 8.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

91511 of 216553 relevant lines covered (42.26%)

3416852.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.29
/rust/src/ssh/ssh.rs
1
/* Copyright (C) 2020-2025 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 super::parser;
19
use crate::applayer::*;
20
use crate::core::*;
21
use crate::direction::Direction;
22
use crate::encryption::EncryptionHandling;
23
use crate::flow::Flow;
24
use crate::frames::Frame;
25
use nom8::Err;
26
use std::ffi::CString;
27
use std::sync::atomic::{AtomicBool, Ordering};
28
use suricata_sys::sys::{
29
    AppLayerParserState, AppProto, SCAppLayerParserConfParserEnabled,
30
    SCAppLayerParserRegisterLogger, SCAppLayerParserStateSetFlag,
31
    SCAppLayerProtoDetectConfProtoDetectionEnabled,
32
};
33

34
pub(super) static mut ALPROTO_SSH: AppProto = ALPROTO_UNKNOWN;
35
static HASSH_ENABLED: AtomicBool = AtomicBool::new(false);
36
static HASSH_DISABLED: AtomicBool = AtomicBool::new(false);
37

38
static mut ENCRYPTION_BYPASS_ENABLED: EncryptionHandling =
39
    EncryptionHandling::ENCRYPTION_HANDLING_TRACK_ONLY;
40

41
fn hassh_is_enabled() -> bool {
78✔
42
    HASSH_ENABLED.load(Ordering::Relaxed)
78✔
43
}
78✔
44

45
fn encryption_bypass_mode() -> EncryptionHandling {
11✔
46
    unsafe { ENCRYPTION_BYPASS_ENABLED }
11✔
47
}
11✔
48

49
#[derive(AppLayerFrameType)]
50
pub enum SshFrameType {
51
    RecordHdr,
52
    RecordData,
53
    RecordPdu,
54
}
55

56
#[derive(AppLayerEvent)]
×
57
pub enum SSHEvent {
58
    InvalidBanner,
59
    LongBanner,
60
    InvalidRecord,
61
    LongKexRecord,
62
}
63

64
#[repr(u8)]
65
#[derive(AppLayerState, Copy, Clone, PartialOrd, PartialEq, Eq)]
66
#[suricata(alstate_strip_prefix = "SshState")]
67
pub enum SSHConnectionState {
68
    SshStateInProgress = 0,
69
    SshStateBannerWaitEol = 1,
70
    SshStateBannerDone = 2,
71
    SshStateFinished = 3,
72
}
73

74
pub const SSH_MAX_BANNER_LEN: usize = 256;
75
const SSH_RECORD_HEADER_LEN: usize = 6;
76
const SSH_MAX_REASSEMBLED_RECORD_LEN: usize = 65535;
77

78
pub struct SshHeader {
79
    record_left: u32,
80
    record_left_msg: parser::MessageCode,
81

82
    flags: SSHConnectionState,
83
    pub protover: Vec<u8>,
84
    pub swver: Vec<u8>,
85

86
    pub hassh: Vec<u8>,
87
    pub hassh_string: Vec<u8>,
88
}
89

90
impl Default for SshHeader {
91
    fn default() -> Self {
38✔
92
        Self::new()
38✔
93
    }
38✔
94
}
95

96
impl SshHeader {
97
    pub fn new() -> SshHeader {
38✔
98
        Self {
38✔
99
            record_left: 0,
38✔
100
            record_left_msg: parser::MessageCode::Undefined(0),
38✔
101

38✔
102
            flags: SSHConnectionState::SshStateInProgress,
38✔
103
            protover: Vec::new(),
38✔
104
            swver: Vec::new(),
38✔
105

38✔
106
            hassh: Vec::new(),
38✔
107
            hassh_string: Vec::new(),
38✔
108
        }
38✔
109
    }
38✔
110
}
111

112
#[derive(Default)]
113
pub struct SSHTransaction {
114
    pub srv_hdr: SshHeader,
115
    pub cli_hdr: SshHeader,
116

117
    tx_data: AppLayerTxData,
118
}
119

120
#[derive(Default)]
121
pub struct SSHState {
122
    state_data: AppLayerStateData,
123
    transaction: SSHTransaction,
124
}
125

126
impl SSHState {
127
    pub fn new() -> Self {
19✔
128
        Default::default()
19✔
129
    }
19✔
130

131
    fn set_event(&mut self, event: SSHEvent) {
×
132
        self.transaction.tx_data.set_event(event as u8);
×
133
    }
×
134

135
    fn parse_record(
121✔
136
        &mut self, mut input: &[u8], resp: bool, pstate: *mut AppLayerParserState,
121✔
137
        flow: *mut Flow, stream_slice: &StreamSlice,
121✔
138
    ) -> AppLayerResult {
121✔
139
        let (hdr, ohdr) = if !resp {
121✔
140
            (&mut self.transaction.cli_hdr, &self.transaction.srv_hdr)
65✔
141
        } else {
142
            (&mut self.transaction.srv_hdr, &self.transaction.cli_hdr)
56✔
143
        };
144
        let il = input.len();
121✔
145
        //first skip record left bytes
121✔
146
        if hdr.record_left > 0 {
121✔
147
            //should we check for overflow ?
148
            let ilen = input.len() as u32;
6✔
149
            if hdr.record_left > ilen {
6✔
150
                hdr.record_left -= ilen;
3✔
151
                return AppLayerResult::ok();
3✔
152
            } else {
153
                let start = hdr.record_left as usize;
3✔
154
                match hdr.record_left_msg {
×
155
                    // parse reassembled tcp segments
156
                    parser::MessageCode::Kexinit if hassh_is_enabled() => {
×
157
                        if let Ok((_rem, key_exchange)) =
×
158
                            parser::ssh_parse_key_exchange(&input[..start])
×
159
                        {
×
160
                            key_exchange.generate_hassh(
×
161
                                &mut hdr.hassh_string,
×
162
                                &mut hdr.hassh,
×
163
                                &resp,
×
164
                            );
×
165
                        }
×
166
                        hdr.record_left_msg = parser::MessageCode::Undefined(0);
×
167
                    }
168
                    _ => {}
3✔
169
                }
170
                input = &input[start..];
3✔
171
                hdr.record_left = 0;
3✔
172
            }
173
        }
115✔
174
        //parse records out of input
175
        while !input.is_empty() {
196✔
176
            match parser::ssh_parse_record(input) {
92✔
177
                Ok((rem, head)) => {
78✔
178
                    let _pdu = Frame::new(
78✔
179
                        flow,
78✔
180
                        stream_slice,
78✔
181
                        input,
78✔
182
                        SSH_RECORD_HEADER_LEN as i64,
78✔
183
                        SshFrameType::RecordHdr as u8,
78✔
184
                        Some(0),
78✔
185
                    );
78✔
186
                    let _pdu = Frame::new(
78✔
187
                        flow,
78✔
188
                        stream_slice,
78✔
189
                        &input[SSH_RECORD_HEADER_LEN..],
78✔
190
                        (head.pkt_len - 2) as i64,
78✔
191
                        SshFrameType::RecordData as u8,
78✔
192
                        Some(0),
78✔
193
                    );
78✔
194
                    let _pdu = Frame::new(
78✔
195
                        flow,
78✔
196
                        stream_slice,
78✔
197
                        input,
78✔
198
                        (head.pkt_len + 4) as i64,
78✔
199
                        SshFrameType::RecordPdu as u8,
78✔
200
                        Some(0),
78✔
201
                    );
78✔
202
                    SCLogDebug!("SSH valid record {}", head);
203
                    match head.msg_code {
25✔
204
                        parser::MessageCode::Kexinit if hassh_is_enabled() => {
×
205
                            //let endkex = SSH_RECORD_HEADER_LEN + head.pkt_len - 2;
×
206
                            let endkex = input.len() - rem.len();
×
207
                            if let Ok((_, key_exchange)) = parser::ssh_parse_key_exchange(
×
208
                                &input[SSH_RECORD_HEADER_LEN..endkex],
×
209
                            ) {
×
210
                                key_exchange.generate_hassh(
×
211
                                    &mut hdr.hassh_string,
×
212
                                    &mut hdr.hassh,
×
213
                                    &resp,
×
214
                                );
×
215
                            }
×
216
                        }
217
                        parser::MessageCode::NewKeys => {
218
                            hdr.flags = SSHConnectionState::SshStateFinished;
24✔
219
                            if ohdr.flags >= SSHConnectionState::SshStateFinished {
24✔
220
                                let mut flags = 0;
11✔
221

11✔
222
                                match encryption_bypass_mode() {
11✔
223
                                    EncryptionHandling::ENCRYPTION_HANDLING_BYPASS => {
×
224
                                        flags |= APP_LAYER_PARSER_NO_INSPECTION
×
225
                                            | APP_LAYER_PARSER_NO_REASSEMBLY
×
226
                                            | APP_LAYER_PARSER_BYPASS_READY;
×
227
                                    }
×
228
                                    EncryptionHandling::ENCRYPTION_HANDLING_TRACK_ONLY => {
11✔
229
                                        flags |= APP_LAYER_PARSER_NO_INSPECTION;
11✔
230
                                    }
11✔
231
                                    _ => {}
×
232
                                }
233

234
                                if flags != 0 {
11✔
235
                                    unsafe {
11✔
236
                                        SCAppLayerParserStateSetFlag(pstate, flags);
11✔
237
                                    }
11✔
238
                                }
×
239
                            }
13✔
240
                        }
241
                        _ => {}
54✔
242
                    }
243

244
                    input = rem;
78✔
245
                    //header and complete data (not returned)
246
                }
247
                Err(Err::Incomplete(_)) => {
248
                    match parser::ssh_parse_record_header(input) {
14✔
249
                        Ok((rem, head)) => {
14✔
250
                            let _pdu = Frame::new(
14✔
251
                                flow,
14✔
252
                                stream_slice,
14✔
253
                                input,
14✔
254
                                SSH_RECORD_HEADER_LEN as i64,
14✔
255
                                SshFrameType::RecordHdr as u8,
14✔
256
                                Some(0),
14✔
257
                            );
14✔
258
                            let _pdu = Frame::new(
14✔
259
                                flow,
14✔
260
                                stream_slice,
14✔
261
                                &input[SSH_RECORD_HEADER_LEN..],
14✔
262
                                (head.pkt_len - 2) as i64,
14✔
263
                                SshFrameType::RecordData as u8,
14✔
264
                                Some(0),
14✔
265
                            );
14✔
266
                            let _pdu = Frame::new(
14✔
267
                                flow,
14✔
268
                                stream_slice,
14✔
269
                                input,
14✔
270
                                // cast first to avoid unsigned integer overflow
14✔
271
                                (head.pkt_len as u64 + 4) as i64,
14✔
272
                                SshFrameType::RecordPdu as u8,
14✔
273
                                Some(0),
14✔
274
                            );
14✔
275
                            SCLogDebug!("SSH valid record header {}", head);
14✔
276
                            let remlen = rem.len() as u32;
14✔
277
                            hdr.record_left = head.pkt_len - 2 - remlen;
14✔
278
                            //header with rem as incomplete data
279
                            match head.msg_code {
2✔
280
                                parser::MessageCode::NewKeys => {
1✔
281
                                    hdr.flags = SSHConnectionState::SshStateFinished;
1✔
282
                                }
1✔
283
                                parser::MessageCode::Kexinit if hassh_is_enabled() => {
×
284
                                    // check if buffer is bigger than maximum reassembled packet size
×
285
                                    hdr.record_left = head.pkt_len - 2;
×
286
                                    if hdr.record_left < SSH_MAX_REASSEMBLED_RECORD_LEN as u32 {
×
287
                                        // saving type of incomplete kex message
288
                                        hdr.record_left_msg = parser::MessageCode::Kexinit;
×
289
                                        return AppLayerResult::incomplete(
×
290
                                            (il - rem.len()) as u32,
×
291
                                            head.pkt_len - 2,
×
292
                                        );
×
293
                                    } else {
×
294
                                        SCLogDebug!("SSH buffer is bigger than maximum reassembled packet size");
×
295
                                        self.set_event(SSHEvent::LongKexRecord);
×
296
                                    }
×
297
                                }
298
                                _ => {}
13✔
299
                            }
300
                            return AppLayerResult::ok();
14✔
301
                        }
302
                        Err(Err::Incomplete(_)) => {
303
                            //we may have consumed data from previous records
304
                            debug_validate_bug_on!(input.len() >= SSH_RECORD_HEADER_LEN);
305
                            //do not trust nom incomplete value
306
                            return AppLayerResult::incomplete(
×
307
                                (il - input.len()) as u32,
×
308
                                SSH_RECORD_HEADER_LEN as u32,
×
309
                            );
×
310
                        }
311
                        Err(_e) => {
×
312
                            SCLogDebug!("SSH invalid record header {}", _e);
×
313
                            self.set_event(SSHEvent::InvalidRecord);
×
314
                            return AppLayerResult::err();
×
315
                        }
316
                    }
317
                }
318
                Err(_e) => {
×
319
                    SCLogDebug!("SSH invalid record {}", _e);
×
320
                    self.set_event(SSHEvent::InvalidRecord);
×
321
                    return AppLayerResult::err();
×
322
                }
323
            }
324
        }
325
        return AppLayerResult::ok();
104✔
326
    }
121✔
327

328
    fn parse_banner(
37✔
329
        &mut self, input: &[u8], resp: bool, pstate: *mut AppLayerParserState, flow: *mut Flow,
37✔
330
        stream_slice: &StreamSlice,
37✔
331
    ) -> AppLayerResult {
37✔
332
        let hdr = if !resp {
37✔
333
            &mut self.transaction.cli_hdr
18✔
334
        } else {
335
            &mut self.transaction.srv_hdr
19✔
336
        };
337
        if hdr.flags == SSHConnectionState::SshStateBannerWaitEol {
37✔
338
            match parser::ssh_parse_line(input) {
×
339
                Ok((rem, _)) => {
×
340
                    let mut r = self.parse_record(rem, resp, pstate, flow, stream_slice);
×
341
                    if r.is_incomplete() {
×
342
                        //adds bytes consumed by banner to incomplete result
×
343
                        r.consumed += (input.len() - rem.len()) as u32;
×
344
                    } else if r.is_ok() {
×
345
                        let mut dir = Direction::ToServer as i32;
×
346
                        if resp {
×
347
                            dir = Direction::ToClient as i32;
×
348
                        }
×
349
                        sc_app_layer_parser_trigger_raw_stream_inspection(flow, dir);
×
350
                    }
×
351
                    return r;
×
352
                }
353
                Err(Err::Incomplete(_)) => {
354
                    // we do not need to retain these bytes
355
                    // we parsed them, we skip them
356
                    return AppLayerResult::ok();
×
357
                }
358
                Err(_e) => {
×
359
                    SCLogDebug!("SSH invalid banner {}", _e);
×
360
                    self.set_event(SSHEvent::InvalidBanner);
×
361
                    return AppLayerResult::err();
×
362
                }
363
            }
364
        }
37✔
365
        match parser::ssh_parse_line(input) {
37✔
366
            Ok((rem, line)) => {
36✔
367
                if let Ok((_, banner)) = parser::ssh_parse_banner(line) {
36✔
368
                    hdr.protover.extend(banner.protover);
36✔
369
                    if !banner.swver.is_empty() {
36✔
370
                        hdr.swver.extend(banner.swver);
36✔
371
                    }
36✔
372
                    hdr.flags = SSHConnectionState::SshStateBannerDone;
36✔
373
                } else {
374
                    SCLogDebug!("SSH invalid banner");
375
                    self.set_event(SSHEvent::InvalidBanner);
×
376
                    return AppLayerResult::err();
×
377
                }
378
                if line.len() >= SSH_MAX_BANNER_LEN {
36✔
379
                    SCLogDebug!(
×
380
                        "SSH banner too long {} vs {}",
×
381
                        line.len(),
×
382
                        SSH_MAX_BANNER_LEN
×
383
                    );
×
384
                    self.set_event(SSHEvent::LongBanner);
×
385
                }
36✔
386
                let mut r = self.parse_record(rem, resp, pstate, flow, stream_slice);
36✔
387
                if r.is_incomplete() {
36✔
388
                    //adds bytes consumed by banner to incomplete result
×
389
                    r.consumed += (input.len() - rem.len()) as u32;
×
390
                } else if r.is_ok() {
36✔
391
                    let mut dir = Direction::ToServer as i32;
36✔
392
                    if resp {
36✔
393
                        dir = Direction::ToClient as i32;
19✔
394
                    }
19✔
395
                    sc_app_layer_parser_trigger_raw_stream_inspection(flow, dir);
36✔
396
                }
×
397
                return r;
36✔
398
            }
399
            Err(Err::Incomplete(_)) => {
400
                // see https://github.com/rust-lang/rust-clippy/issues/15158
401
                #[allow(clippy::collapsible_else_if)]
402
                if input.len() < SSH_MAX_BANNER_LEN {
1✔
403
                    //0 consumed, needs at least one more byte
404
                    return AppLayerResult::incomplete(0_u32, (input.len() + 1) as u32);
1✔
405
                } else {
406
                    SCLogDebug!(
407
                        "SSH banner too long {} vs {} and waiting for eol",
408
                        input.len(),
409
                        SSH_MAX_BANNER_LEN
410
                    );
411
                    if let Ok((_, banner)) = parser::ssh_parse_banner(input) {
×
412
                        hdr.protover.extend(banner.protover);
×
413
                        if !banner.swver.is_empty() {
×
414
                            hdr.swver.extend(banner.swver);
×
415
                        }
×
416
                        hdr.flags = SSHConnectionState::SshStateBannerWaitEol;
×
417
                        self.set_event(SSHEvent::LongBanner);
×
418
                        return AppLayerResult::ok();
×
419
                    } else {
420
                        self.set_event(SSHEvent::InvalidBanner);
×
421
                        return AppLayerResult::err();
×
422
                    }
423
                }
424
            }
425
            Err(_e) => {
×
426
                SCLogDebug!("SSH invalid banner {}", _e);
×
427
                self.set_event(SSHEvent::InvalidBanner);
×
428
                return AppLayerResult::err();
×
429
            }
430
        }
431
    }
37✔
432
}
433

434
// C exports.
435

436
export_tx_data_get!(ssh_get_tx_data, SSHTransaction);
437
export_state_data_get!(ssh_get_state_data, SSHState);
438

439
extern "C" fn ssh_state_new(
19✔
440
    _orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto,
19✔
441
) -> *mut std::os::raw::c_void {
19✔
442
    let state = SSHState::new();
19✔
443
    let boxed = Box::new(state);
19✔
444
    return Box::into_raw(boxed) as *mut _;
19✔
445
}
19✔
446

447
unsafe extern "C" fn ssh_state_free(state: *mut std::os::raw::c_void) {
19✔
448
    std::mem::drop(Box::from_raw(state as *mut SSHState));
19✔
449
}
19✔
450

451
extern "C" fn ssh_state_tx_free(_state: *mut std::os::raw::c_void, _tx_id: u64) {
11✔
452
    //do nothing
11✔
453
}
11✔
454

455
unsafe extern "C" fn ssh_parse_request(
66✔
456
    flow: *mut Flow, state: *mut std::os::raw::c_void, pstate: *mut AppLayerParserState,
66✔
457
    stream_slice: StreamSlice, _data: *mut std::os::raw::c_void,
66✔
458
) -> AppLayerResult {
66✔
459
    let state = &mut cast_pointer!(state, SSHState);
66✔
460
    let buf = stream_slice.as_slice();
66✔
461
    let hdr = &mut state.transaction.cli_hdr;
66✔
462
    state.transaction.tx_data.0.updated_ts = true;
66✔
463
    if hdr.flags < SSHConnectionState::SshStateBannerDone {
66✔
464
        return state.parse_banner(buf, false, pstate, flow, &stream_slice);
18✔
465
    } else {
466
        return state.parse_record(buf, false, pstate, flow, &stream_slice);
48✔
467
    }
468
}
66✔
469

470
unsafe extern "C" fn ssh_parse_response(
56✔
471
    flow: *mut Flow, state: *mut std::os::raw::c_void, pstate: *mut AppLayerParserState,
56✔
472
    stream_slice: StreamSlice, _data: *mut std::os::raw::c_void,
56✔
473
) -> AppLayerResult {
56✔
474
    let state = &mut cast_pointer!(state, SSHState);
56✔
475
    let buf = stream_slice.as_slice();
56✔
476
    let hdr = &mut state.transaction.srv_hdr;
56✔
477
    state.transaction.tx_data.0.updated_tc = true;
56✔
478
    if hdr.flags < SSHConnectionState::SshStateBannerDone {
56✔
479
        return state.parse_banner(buf, true, pstate, flow, &stream_slice);
19✔
480
    } else {
481
        return state.parse_record(buf, true, pstate, flow, &stream_slice);
37✔
482
    }
483
}
56✔
484

485
#[no_mangle]
486
pub unsafe extern "C" fn SCSshStateGetTx(
586✔
487
    state: *mut std::os::raw::c_void, _tx_id: u64,
586✔
488
) -> *mut std::os::raw::c_void {
586✔
489
    let state = cast_pointer!(state, SSHState);
586✔
490
    return &state.transaction as *const _ as *mut _;
586✔
491
}
586✔
492

493
extern "C" fn ssh_state_get_tx_count(_state: *mut std::os::raw::c_void) -> u64 {
1,185✔
494
    return 1;
1,185✔
495
}
1,185✔
496

497
#[no_mangle]
498
pub unsafe extern "C" fn SCSshTxGetFlags(
×
499
    tx: *mut std::os::raw::c_void, direction: u8,
×
500
) -> SSHConnectionState {
×
501
    let tx = cast_pointer!(tx, SSHTransaction);
×
502
    if direction == u8::from(Direction::ToServer) {
×
503
        return tx.cli_hdr.flags;
×
504
    } else {
505
        return tx.srv_hdr.flags;
×
506
    }
507
}
×
508

509
#[no_mangle]
510
pub unsafe extern "C" fn SCSshTxGetAlStateProgress(
650✔
511
    tx: *mut std::os::raw::c_void, direction: u8,
650✔
512
) -> std::os::raw::c_int {
650✔
513
    let tx = cast_pointer!(tx, SSHTransaction);
650✔
514

650✔
515
    if tx.cli_hdr.flags >= SSHConnectionState::SshStateFinished
650✔
516
        && tx.srv_hdr.flags >= SSHConnectionState::SshStateFinished
66✔
517
    {
518
        return SSHConnectionState::SshStateFinished as i32;
66✔
519
    }
584✔
520

584✔
521
    if direction == u8::from(Direction::ToServer) {
584✔
522
        if tx.cli_hdr.flags >= SSHConnectionState::SshStateBannerDone {
225✔
523
            return SSHConnectionState::SshStateBannerDone as i32;
187✔
524
        }
38✔
525
    } else if tx.srv_hdr.flags >= SSHConnectionState::SshStateBannerDone {
359✔
526
        return SSHConnectionState::SshStateBannerDone as i32;
282✔
527
    }
77✔
528

529
    return SSHConnectionState::SshStateInProgress as i32;
115✔
530
}
650✔
531

532
// Parser name as a C style string.
533
const PARSER_NAME: &[u8] = b"ssh\0";
534

535
#[no_mangle]
536
pub unsafe extern "C" fn SCRegisterSshParser() {
7✔
537
    let parser = RustParser {
7✔
538
        name: PARSER_NAME.as_ptr() as *const std::os::raw::c_char,
7✔
539
        default_port: std::ptr::null(),
7✔
540
        ipproto: IPPROTO_TCP,
7✔
541
        //simple patterns, no probing
7✔
542
        probe_ts: None,
7✔
543
        probe_tc: None,
7✔
544
        min_depth: 0,
7✔
545
        max_depth: 0,
7✔
546
        state_new: ssh_state_new,
7✔
547
        state_free: ssh_state_free,
7✔
548
        tx_free: ssh_state_tx_free,
7✔
549
        parse_ts: ssh_parse_request,
7✔
550
        parse_tc: ssh_parse_response,
7✔
551
        get_tx_count: ssh_state_get_tx_count,
7✔
552
        get_tx: SCSshStateGetTx,
7✔
553
        tx_comp_st_ts: SSHConnectionState::SshStateFinished as i32,
7✔
554
        tx_comp_st_tc: SSHConnectionState::SshStateFinished as i32,
7✔
555
        tx_get_progress: SCSshTxGetAlStateProgress,
7✔
556
        get_eventinfo: Some(SSHEvent::get_event_info),
7✔
557
        get_eventinfo_byid: Some(SSHEvent::get_event_info_by_id),
7✔
558
        localstorage_new: None,
7✔
559
        localstorage_free: None,
7✔
560
        get_tx_files: None,
7✔
561
        get_tx_iterator: None,
7✔
562
        get_tx_data: ssh_get_tx_data,
7✔
563
        get_state_data: ssh_get_state_data,
7✔
564
        apply_tx_config: None,
7✔
565
        flags: 0,
7✔
566
        get_frame_id_by_name: Some(SshFrameType::ffi_id_from_name),
7✔
567
        get_frame_name_by_id: Some(SshFrameType::ffi_name_from_id),
7✔
568
        get_state_id_by_name: Some(SSHConnectionState::ffi_id_from_name),
7✔
569
        get_state_name_by_id: Some(SSHConnectionState::ffi_name_from_id),
7✔
570
    };
7✔
571

7✔
572
    let ip_proto_str = CString::new("tcp").unwrap();
7✔
573

7✔
574
    if SCAppLayerProtoDetectConfProtoDetectionEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
7✔
575
        let alproto = applayer_register_protocol_detection(&parser, 1);
7✔
576
        ALPROTO_SSH = alproto;
7✔
577
        if SCAppLayerParserConfParserEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
7✔
578
            let _ = AppLayerRegisterParser(&parser, alproto);
7✔
579
        }
7✔
580
        SCAppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SSH);
7✔
581
        SCLogDebug!("Rust ssh parser registered.");
582
    } else {
583
        SCLogNotice!("Protocol detector and parser disabled for SSH.");
×
584
    }
585
}
7✔
586

587
#[no_mangle]
588
pub extern "C" fn SCSshEnableHassh() {
×
589
    if !HASSH_DISABLED.load(Ordering::Relaxed) {
×
590
        HASSH_ENABLED.store(true, Ordering::Relaxed)
×
591
    }
×
592
}
×
593

594
#[no_mangle]
595
pub extern "C" fn SCSshHasshIsEnabled() -> bool {
51✔
596
    hassh_is_enabled()
51✔
597
}
51✔
598

599
#[no_mangle]
600
pub extern "C" fn SCSshDisableHassh() {
×
601
    HASSH_DISABLED.store(true, Ordering::Relaxed)
×
602
}
×
603

604
#[no_mangle]
605
pub extern "C" fn SCSshEnableBypass(mode: EncryptionHandling) {
×
606
    unsafe {
×
607
        ENCRYPTION_BYPASS_ENABLED = mode;
×
608
    }
×
609
}
×
610

611
#[no_mangle]
612
pub unsafe extern "C" fn SCSshTxGetLogCondition(tx: *mut std::os::raw::c_void) -> bool {
51✔
613
    let tx = cast_pointer!(tx, SSHTransaction);
51✔
614

51✔
615
    if SCSshHasshIsEnabled() {
51✔
616
        if tx.cli_hdr.flags == SSHConnectionState::SshStateFinished
×
617
            && tx.srv_hdr.flags == SSHConnectionState::SshStateFinished
×
618
        {
619
            return true;
×
620
        }
×
621
    } else if tx.cli_hdr.flags == SSHConnectionState::SshStateBannerDone
51✔
622
        && tx.srv_hdr.flags == SSHConnectionState::SshStateBannerDone
39✔
623
    {
624
        return true;
17✔
625
    }
34✔
626
    return false;
34✔
627
}
51✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc