Coverage Report

Created: 2025-12-31 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/suricata7/rust/src/ssh/detect.rs
Line
Count
Source
1
/* Copyright (C) 2020 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::ssh::SSHTransaction;
19
use crate::core::Direction;
20
use std::ptr;
21
22
#[no_mangle]
23
13
pub unsafe extern "C" fn rs_ssh_tx_get_protocol(
24
13
    tx: *mut std::os::raw::c_void, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8,
25
13
) -> u8 {
26
13
    let tx = cast_pointer!(tx, SSHTransaction);
27
13
    match direction.into() {
28
        Direction::ToServer => {
29
13
            let m = &tx.cli_hdr.protover;
30
13
            if !m.is_empty() {
31
13
                *buffer = m.as_ptr();
32
13
                *buffer_len = m.len() as u32;
33
13
                return 1;
34
0
            }
35
        }
36
        Direction::ToClient => {
37
0
            let m = &tx.srv_hdr.protover;
38
0
            if !m.is_empty() {
39
0
                *buffer = m.as_ptr();
40
0
                *buffer_len = m.len() as u32;
41
0
                return 1;
42
0
            }
43
        }
44
    }
45
0
    *buffer = ptr::null();
46
0
    *buffer_len = 0;
47
48
0
    return 0;
49
13
}
50
51
#[no_mangle]
52
3
pub unsafe extern "C" fn rs_ssh_tx_get_software(
53
3
    tx: *mut std::os::raw::c_void, buffer: *mut *const u8, buffer_len: *mut u32, direction: u8,
54
3
) -> u8 {
55
3
    let tx = cast_pointer!(tx, SSHTransaction);
56
3
    match direction.into() {
57
        Direction::ToServer => {
58
2
            let m = &tx.cli_hdr.swver;
59
2
            if !m.is_empty() {
60
2
                *buffer = m.as_ptr();
61
2
                *buffer_len = m.len() as u32;
62
2
                return 1;
63
0
            }
64
        }
65
        Direction::ToClient => {
66
1
            let m = &tx.srv_hdr.swver;
67
1
            if !m.is_empty() {
68
1
                *buffer = m.as_ptr();
69
1
                *buffer_len = m.len() as u32;
70
1
                return 1;
71
0
            }
72
        }
73
    }
74
0
    *buffer = ptr::null();
75
0
    *buffer_len = 0;
76
77
0
    return 0;
78
3
}
79
80
#[no_mangle]
81
35
pub unsafe extern "C" fn rs_ssh_tx_get_hassh(
82
35
    tx: *mut std::os::raw::c_void,
83
35
    buffer: *mut *const u8,
84
35
    buffer_len: *mut u32,
85
35
    direction: u8,
86
35
) -> u8 {
87
35
    let tx = cast_pointer!(tx, SSHTransaction);
88
35
    match direction.into() {
89
        Direction::ToServer => {
90
31
            let m = &tx.cli_hdr.hassh;
91
31
            if !m.is_empty() {
92
2
                *buffer = m.as_ptr();
93
2
                *buffer_len = m.len() as u32;
94
2
                return 1;
95
29
            }
96
        }
97
        Direction::ToClient => {
98
4
            let m = &tx.srv_hdr.hassh;
99
4
            if !m.is_empty() {
100
3
                *buffer = m.as_ptr();
101
3
                *buffer_len = m.len() as u32;
102
3
                return 1;
103
1
            }
104
        }
105
    }
106
30
    *buffer = ptr::null();
107
30
    *buffer_len = 0;
108
109
30
    return 0;
110
35
}
111
112
#[no_mangle]
113
8
pub unsafe extern "C" fn rs_ssh_tx_get_hassh_string(
114
8
    tx: *mut std::os::raw::c_void,
115
8
    buffer: *mut *const u8,
116
8
    buffer_len: *mut u32,
117
8
    direction: u8,
118
8
) -> u8 {
119
8
    let tx = cast_pointer!(tx, SSHTransaction);
120
8
    match direction.into() {
121
        Direction::ToServer => {
122
4
            let m = &tx.cli_hdr.hassh_string;
123
4
            if !m.is_empty() {
124
0
                *buffer = m.as_ptr();
125
0
                *buffer_len = m.len() as u32;
126
0
                return 1;
127
4
            }
128
        }
129
        Direction::ToClient => {
130
4
            let m = &tx.srv_hdr.hassh_string;
131
4
            if !m.is_empty() {
132
3
                *buffer = m.as_ptr();
133
3
                *buffer_len = m.len() as u32;
134
3
                return 1;
135
1
            }
136
        }
137
    }
138
5
    *buffer = ptr::null();
139
5
    *buffer_len = 0;
140
141
5
    return 0;
142
8
}