Bug Summary

File:builds/wireshark/wireshark/epan/dissectors/packet-ssh.c
Warning:line 2711, column 17
Value of 'errno' was not checked and may be overwritten by function 'ferror'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name packet-ssh.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-22/lib/clang/22 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/epan/dissectors -isystem /builds/wireshark/wireshark/build/epan/dissectors -isystem /usr/include/mit-krb5 -isystem /builds/wireshark/wireshark/epan -isystem /usr/include/libxml2 -D CARES_NO_DEPRECATED -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-22/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=gnu17 -ferror-limit 19 -fvisibility=hidden -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /builds/wireshark/wireshark/sbout/2026-11-13-100306-3661-1 -x c /builds/wireshark/wireshark/epan/dissectors/packet-ssh.c
1/* packet-ssh.c
2 * Routines for ssh packet dissection
3 *
4 * Huagang XIE <[email protected]>
5 * Kees Cook <[email protected]>
6 *
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <[email protected]>
9 * Copyright 1998 Gerald Combs
10 *
11 * Copied from packet-mysql.c
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 *
15 *
16 * Note: support SSH v1 and v2 now.
17 *
18 */
19
20/* SSH version 2 is defined in:
21 *
22 * RFC 4250: The Secure Shell (SSH) Protocol Assigned Numbers
23 * RFC 4251: The Secure Shell (SSH) Protocol Architecture
24 * RFC 4252: The Secure Shell (SSH) Authentication Protocol
25 * RFC 4253: The Secure Shell (SSH) Transport Layer Protocol
26 * RFC 4254: The Secure Shell (SSH) Connection Protocol
27 *
28 * SSH versions under 2 were never officially standardized.
29 *
30 * Diffie-Hellman Group Exchange is defined in:
31 *
32 * RFC 4419: Diffie-Hellman Group Exchange for
33 * the Secure Shell (SSH) Transport Layer Protocol
34 */
35
36/* "SSH" prefixes are for version 2, whereas "SSH1" is for version 1 */
37
38#include "config.h"
39#define WS_LOG_DOMAIN"packet-ssh" "packet-ssh"
40/* Start with WIRESHARK_LOG_DOMAINS=packet-ssh and WIRESHARK_LOG_LEVEL=debug to see messages. */
41
42// Define this to get hex dumps more similar to what you get in openssh. If not defined, dumps look more like what you get with other dissectors.
43#define OPENSSH_STYLE
44
45#include <errno(*__errno_location ()).h>
46
47#include <epan/packet.h>
48#include <epan/exceptions.h>
49#include <epan/prefs.h>
50#include <epan/expert.h>
51#include <epan/proto_data.h>
52#include <epan/tfs.h>
53#include <epan/unit_strings.h>
54#include <wsutil/strtoi.h>
55#include <wsutil/to_str.h>
56#include <wsutil/file_util.h>
57#include <wsutil/filesystem.h>
58#include <wsutil/wsgcrypt.h>
59#include <wsutil/curve25519.h>
60#include <wsutil/pint.h>
61#include <wsutil/str_util.h>
62#include <wsutil/wslog.h>
63#include <epan/secrets.h>
64#include <wiretap/secrets-types.h>
65
66#if defined(HAVE_LIBGNUTLS1)
67#include <gnutls/abstract.h>
68#endif
69
70#include "packet-tcp.h"
71#include "packet-sctp.h"
72
73void proto_register_ssh(void);
74void proto_reg_handoff_ssh(void);
75
76/* SSH Version 1 definition , from openssh ssh1.h */
77#define SSH1_MSG_NONE0 0 /* no message */
78#define SSH1_MSG_DISCONNECT1 1 /* cause (string) */
79#define SSH1_SMSG_PUBLIC_KEY2 2 /* ck,msk,srvk,hostk */
80#define SSH1_CMSG_SESSION_KEY3 3 /* key (BIGNUM) */
81#define SSH1_CMSG_USER4 4 /* user (string) */
82
83
84#define SSH_VERSION_UNKNOWN0 0
85#define SSH_VERSION_11 1
86#define SSH_VERSION_22 2
87
88/* proto data */
89
90typedef struct {
91 uint8_t *data;
92 unsigned length;
93} ssh_bignum;
94
95#define SSH_KEX_CURVE255190x00010000 0x00010000
96#define SSH_KEX_DH_GEX0x00020000 0x00020000
97#define SSH_KEX_DH_GROUP10x00030001 0x00030001
98#define SSH_KEX_DH_GROUP140x00030014 0x00030014
99#define SSH_KEX_DH_GROUP160x00030016 0x00030016
100#define SSH_KEX_DH_GROUP180x00030018 0x00030018
101#define SSH_KEX_SNTRUP761X255190x00040000 0x00040000
102#define SSH_KEX_MLKEM768X255190x00050000 0x00050000
103
104#define SSH_KEX_HASH_SHA11 1
105#define SSH_KEX_HASH_SHA2562 2
106#define SSH_KEX_HASH_SHA5124 4
107
108#define DIGEST_MAX_SIZE48 48
109
110/* The maximum SSH packet_length accepted. If the packet_length field after
111 * attempted decryption is larger than this, the packet will be assumed to
112 * have failed decryption (possibly due to being continuation data).
113 * (This could be made a preference.)
114 */
115#define SSH_MAX_PACKET_LEN32768 32768
116
117typedef struct _ssh_message_info_t {
118 uint32_t sequence_number;
119 unsigned char *plain_data; /**< Decrypted data. */
120 unsigned data_len; /**< Length of decrypted data. */
121 int id; /**< Identifies the exact message within a frame
122 (there can be multiple records in a frame). */
123 uint32_t byte_seq;
124 uint32_t next_byte_seq;
125 struct _ssh_message_info_t* next;
126 uint8_t calc_mac[DIGEST_MAX_SIZE48];
127} ssh_message_info_t;
128
129typedef struct {
130 bool_Bool from_server;
131 ssh_message_info_t * messages;
132} ssh_packet_info_t;
133
134typedef struct _ssh_channel_info_t {
135 uint32_t byte_seq;
136 uint16_t flags;
137 wmem_tree_t *multisegment_pdus;
138 dissector_handle_t handle;
139} ssh_channel_info_t;
140
141struct ssh_peer_data {
142 unsigned counter;
143
144 uint32_t frame_version_start;
145 uint32_t frame_version_end;
146
147 uint32_t frame_key_start;
148 uint32_t frame_key_end;
149 int frame_key_end_offset;
150
151 char* kex_proposal;
152
153 /* For all subsequent proposals,
154 [0] is client-to-server and [1] is server-to-client. */
155#define CLIENT_TO_SERVER_PROPOSAL0 0
156#define SERVER_TO_CLIENT_PROPOSAL1 1
157
158 char* mac_proposals[2];
159 char* mac;
160 int mac_length;
161
162 char* enc_proposals[2];
163 char* enc;
164
165 char* comp_proposals[2];
166 char* comp;
167
168 int length_is_plaintext;
169
170 // see libgcrypt source, gcrypt.h:gcry_cipher_algos
171 unsigned cipher_id;
172 unsigned mac_id;
173 // chacha20 needs two cipher handles
174 gcry_cipher_hd_t cipher, cipher_2;
175 unsigned sequence_number;
176 ssh_bignum *bn_cookie;
177 uint8_t iv[12];
178 uint8_t hmac_iv[DIGEST_MAX_SIZE48];
179 unsigned hmac_iv_len;
180
181 unsigned int rekey_trigger_frame; // for storing new KEXINIT frame value when REKEY
182 bool_Bool rekey_pending; // trace REKEY
183 uint8_t plain0[16];
184 bool_Bool plain0_valid;
185
186 wmem_map_t *channel_info; /**< Map of sender channel numbers to recipient numbers. */
187 wmem_map_t *channel_handles; /**< Map of recipient channel numbers to subdissector handles. */
188 struct ssh_flow_data * global_data;
189};
190
191struct ssh_flow_data {
192 unsigned version;
193
194 /* The address/port of the server */
195 address srv_addr;
196 unsigned srv_port;
197
198 char* kex;
199 int (*kex_specific_dissector)(uint8_t msg_code, tvbuff_t *tvb,
200 packet_info *pinfo, int offset, proto_tree *tree,
201 struct ssh_flow_data *global_data);
202
203 /* [0] is client's, [1] is server's */
204#define CLIENT_PEER_DATA0 0
205#define SERVER_PEER_DATA1 1
206 struct ssh_peer_data peer_data[2];
207
208 const uint8_t *session_id;
209 unsigned session_id_length;
210 ssh_bignum *kex_e;
211 ssh_bignum *kex_f;
212 ssh_bignum *kex_gex_p; // Group modulo
213 ssh_bignum *kex_gex_g; // Group generator
214 ssh_bignum *secret;
215 wmem_array_t *kex_client_version;
216 wmem_array_t *kex_server_version;
217 wmem_array_t *kex_client_key_exchange_init;
218 wmem_array_t *kex_server_key_exchange_init;
219 wmem_array_t *kex_server_host_key_blob;
220 wmem_array_t *kex_gex_bits_min;
221 wmem_array_t *kex_gex_bits_req;
222 wmem_array_t *kex_gex_bits_max;
223 wmem_array_t *kex_shared_secret;
224 bool_Bool do_decrypt;
225 bool_Bool ext_ping_openssh_offered;
226 bool_Bool ext_kex_strict;
227 ssh_bignum new_keys[6];
228 uint8_t *pqkem_ciphertext;
229 uint32_t pqkem_ciphertext_len;
230 uint8_t *curve25519_pub;
231 uint32_t curve25519_pub_len;
232 // storing PQ dissected keys
233 uint8_t *kex_e_pq; // binary material => no bignum (not traditional DH integer / not math ready)
234 uint8_t *kex_f_pq; // binary material => no bignum (not traditional DH integer / not math ready)
235 uint32_t kex_e_pq_len;
236 uint32_t kex_f_pq_len;
237};
238
239typedef struct {
240 char *type; // "PRIVATE_KEY" or "SHARED_SECRET"
241 ssh_bignum *key_material; // Either private key or shared secret
242} ssh_key_map_entry_t;
243
244static GHashTable * ssh_master_key_map;
245
246static int proto_ssh;
247
248/* Version exchange */
249static int hf_ssh_protocol;
250
251/* Framing */
252static int hf_ssh_packet_length;
253static int hf_ssh_packet_length_encrypted;
254static int hf_ssh_padding_length;
255static int hf_ssh_payload;
256static int hf_ssh_encrypted_packet;
257static int hf_ssh_padding_string;
258static int hf_ssh_mac_string;
259static int hf_ssh_mac_status;
260static int hf_ssh_seq_num;
261static int hf_ssh_direction;
262
263/* Message codes */
264static int hf_ssh_msg_code;
265static int hf_ssh2_msg_code;
266static int hf_ssh2_kex_dh_msg_code;
267static int hf_ssh2_kex_dh_gex_msg_code;
268static int hf_ssh2_kex_ecdh_msg_code;
269static int hf_ssh2_kex_hybrid_msg_code;
270static int hf_ssh2_ext_ping_msg_code;
271
272/* Algorithm negotiation */
273static int hf_ssh_cookie;
274static int hf_ssh_kex_algorithms;
275static int hf_ssh_server_host_key_algorithms;
276static int hf_ssh_encryption_algorithms_client_to_server;
277static int hf_ssh_encryption_algorithms_server_to_client;
278static int hf_ssh_mac_algorithms_client_to_server;
279static int hf_ssh_mac_algorithms_server_to_client;
280static int hf_ssh_compression_algorithms_client_to_server;
281static int hf_ssh_compression_algorithms_server_to_client;
282static int hf_ssh_languages_client_to_server;
283static int hf_ssh_languages_server_to_client;
284static int hf_ssh_kex_algorithms_length;
285static int hf_ssh_server_host_key_algorithms_length;
286static int hf_ssh_encryption_algorithms_client_to_server_length;
287static int hf_ssh_encryption_algorithms_server_to_client_length;
288static int hf_ssh_mac_algorithms_client_to_server_length;
289static int hf_ssh_mac_algorithms_server_to_client_length;
290static int hf_ssh_compression_algorithms_client_to_server_length;
291static int hf_ssh_compression_algorithms_server_to_client_length;
292static int hf_ssh_languages_client_to_server_length;
293static int hf_ssh_languages_server_to_client_length;
294static int hf_ssh_first_kex_packet_follows;
295static int hf_ssh_kex_reserved;
296static int hf_ssh_kex_hassh_algo;
297static int hf_ssh_kex_hassh;
298static int hf_ssh_kex_hasshserver_algo;
299static int hf_ssh_kex_hasshserver;
300
301/* Key exchange common elements */
302static int hf_ssh_hostkey_length;
303static int hf_ssh_hostkey_type_length;
304static int hf_ssh_hostkey_type;
305static int hf_ssh_hostkey_data;
306static int hf_ssh_hostkey_rsa_n;
307static int hf_ssh_hostkey_rsa_e;
308static int hf_ssh_hostkey_dsa_p;
309static int hf_ssh_hostkey_dsa_q;
310static int hf_ssh_hostkey_dsa_g;
311static int hf_ssh_hostkey_dsa_y;
312static int hf_ssh_hostkey_ecdsa_curve_id;
313static int hf_ssh_hostkey_ecdsa_curve_id_length;
314static int hf_ssh_hostkey_ecdsa_q;
315static int hf_ssh_hostkey_ecdsa_q_length;
316static int hf_ssh_hostkey_eddsa_key;
317static int hf_ssh_hostkey_eddsa_key_length;
318static int hf_ssh_hostsig_length;
319static int hf_ssh_hostsig_type_length;
320static int hf_ssh_hostsig_type;
321static int hf_ssh_hostsig_rsa;
322static int hf_ssh_hostsig_dsa;
323static int hf_ssh_hostsig_data_length;
324static int hf_ssh_hostsig_data;
325
326/* Key exchange: Diffie-Hellman */
327static int hf_ssh_dh_e;
328static int hf_ssh_dh_f;
329
330/* Key exchange: Diffie-Hellman Group Exchange */
331static int hf_ssh_dh_gex_min;
332static int hf_ssh_dh_gex_nbits;
333static int hf_ssh_dh_gex_max;
334static int hf_ssh_dh_gex_p;
335static int hf_ssh_dh_gex_g;
336
337/* Key exchange: Elliptic Curve Diffie-Hellman */
338static int hf_ssh_ecdh_q_c;
339static int hf_ssh_ecdh_q_c_length;
340static int hf_ssh_ecdh_q_s;
341static int hf_ssh_ecdh_q_s_length;
342
343/* Key exchange: Post-Quantum Hybrid KEM */
344static int hf_ssh_hybrid_blob_client; // client's full PQ blob
345static int hf_ssh_hybrid_blob_client_len;
346static int hf_ssh_hybrid_blob_server; // server's full PQ blob
347static int hf_ssh_hybrid_blob_server_len;
348static int hf_ssh_pq_kem_client; // client's PQ public key
349static int hf_ssh_pq_kem_server; // server's PQ response
350
351/* Extension negotiation */
352static int hf_ssh_ext_count;
353static int hf_ssh_ext_name_length;
354static int hf_ssh_ext_name;
355static int hf_ssh_ext_value_length;
356static int hf_ssh_ext_value;
357static int hf_ssh_ext_server_sig_algs_algorithms;
358static int hf_ssh_ext_delay_compression_algorithms_client_to_server_length;
359static int hf_ssh_ext_delay_compression_algorithms_client_to_server;
360static int hf_ssh_ext_delay_compression_algorithms_server_to_client_length;
361static int hf_ssh_ext_delay_compression_algorithms_server_to_client;
362static int hf_ssh_ext_no_flow_control_value;
363static int hf_ssh_ext_elevation_value;
364static int hf_ssh_ext_prop_publickey_algorithms_algorithms;
365
366/* Miscellaneous */
367static int hf_ssh_mpint_length;
368
369static int hf_ssh_ignore_data_length;
370static int hf_ssh_ignore_data;
371static int hf_ssh_debug_always_display;
372static int hf_ssh_debug_message_length;
373static int hf_ssh_debug_message;
374static int hf_ssh_service_name_length;
375static int hf_ssh_service_name;
376static int hf_ssh_userauth_user_name_length;
377static int hf_ssh_userauth_user_name;
378static int hf_ssh_userauth_change_password;
379static int hf_ssh_userauth_service_name_length;
380static int hf_ssh_userauth_service_name;
381static int hf_ssh_userauth_method_name_length;
382static int hf_ssh_userauth_method_name;
383static int hf_ssh_userauth_have_signature;
384static int hf_ssh_userauth_password_length;
385static int hf_ssh_userauth_password;
386static int hf_ssh_userauth_new_password_length;
387static int hf_ssh_userauth_new_password;
388static int hf_ssh_auth_failure_list_length;
389static int hf_ssh_auth_failure_list;
390static int hf_ssh_userauth_partial_success;
391static int hf_ssh_userauth_pka_name_len;
392static int hf_ssh_userauth_pka_name;
393static int hf_ssh_pk_blob_name_length;
394static int hf_ssh_pk_blob_name;
395static int hf_ssh_blob_length;
396static int hf_ssh_signature_length;
397static int hf_ssh_pk_sig_blob_name_length;
398static int hf_ssh_pk_sig_blob_name;
399static int hf_ssh_connection_type_name_len;
400static int hf_ssh_connection_type_name;
401static int hf_ssh_connection_sender_channel;
402static int hf_ssh_connection_recipient_channel;
403static int hf_ssh_connection_initial_window;
404static int hf_ssh_connection_maximum_packet_size;
405static int hf_ssh_global_request_name_len;
406static int hf_ssh_global_request_name;
407static int hf_ssh_global_request_want_reply;
408static int hf_ssh_global_request_hostkeys_array_len;
409static int hf_ssh_channel_request_name_len;
410static int hf_ssh_channel_request_name;
411static int hf_ssh_channel_request_want_reply;
412static int hf_ssh_subsystem_name_len;
413static int hf_ssh_subsystem_name;
414static int hf_ssh_exec_cmd;
415static int hf_ssh_env_name;
416static int hf_ssh_env_value;
417static int hf_ssh_pty_term;
418static int hf_ssh_pty_term_width_char;
419static int hf_ssh_pty_term_height_row;
420static int hf_ssh_pty_term_width_pixel;
421static int hf_ssh_pty_term_height_pixel;
422static int hf_ssh_pty_term_modes_len;
423static int hf_ssh_pty_term_modes;
424static int hf_ssh_pty_term_mode;
425static int hf_ssh_pty_term_mode_opcode;
426static int hf_ssh_pty_term_mode_vintr;
427static int hf_ssh_pty_term_mode_vquit;
428static int hf_ssh_pty_term_mode_verase;
429static int hf_ssh_pty_term_mode_vkill;
430static int hf_ssh_pty_term_mode_veof;
431static int hf_ssh_pty_term_mode_veol;
432static int hf_ssh_pty_term_mode_veol2;
433static int hf_ssh_pty_term_mode_vstart;
434static int hf_ssh_pty_term_mode_vstop;
435static int hf_ssh_pty_term_mode_vsusp;
436static int hf_ssh_pty_term_mode_vdsusp;
437static int hf_ssh_pty_term_mode_vreprint;
438static int hf_ssh_pty_term_mode_vwerase;
439static int hf_ssh_pty_term_mode_vlnext;
440static int hf_ssh_pty_term_mode_vflush;
441static int hf_ssh_pty_term_mode_vswtch;
442static int hf_ssh_pty_term_mode_vstatus;
443static int hf_ssh_pty_term_mode_vdiscard;
444static int hf_ssh_pty_term_mode_ignpar;
445static int hf_ssh_pty_term_mode_parmrk;
446static int hf_ssh_pty_term_mode_inpck;
447static int hf_ssh_pty_term_mode_istrip;
448static int hf_ssh_pty_term_mode_inlcr;
449static int hf_ssh_pty_term_mode_igncr;
450static int hf_ssh_pty_term_mode_icrnl;
451static int hf_ssh_pty_term_mode_iuclc;
452static int hf_ssh_pty_term_mode_ixon;
453static int hf_ssh_pty_term_mode_ixany;
454static int hf_ssh_pty_term_mode_ixoff;
455static int hf_ssh_pty_term_mode_imaxbel;
456static int hf_ssh_pty_term_mode_iutf8;
457static int hf_ssh_pty_term_mode_isig;
458static int hf_ssh_pty_term_mode_icanon;
459static int hf_ssh_pty_term_mode_xcase;
460static int hf_ssh_pty_term_mode_echo;
461static int hf_ssh_pty_term_mode_echoe;
462static int hf_ssh_pty_term_mode_echok;
463static int hf_ssh_pty_term_mode_echonl;
464static int hf_ssh_pty_term_mode_noflsh;
465static int hf_ssh_pty_term_mode_tostop;
466static int hf_ssh_pty_term_mode_iexten;
467static int hf_ssh_pty_term_mode_echoctl;
468static int hf_ssh_pty_term_mode_echoke;
469static int hf_ssh_pty_term_mode_pendin;
470static int hf_ssh_pty_term_mode_opost;
471static int hf_ssh_pty_term_mode_olcuc;
472static int hf_ssh_pty_term_mode_onlcr;
473static int hf_ssh_pty_term_mode_ocrnl;
474static int hf_ssh_pty_term_mode_onocr;
475static int hf_ssh_pty_term_mode_onlret;
476static int hf_ssh_pty_term_mode_cs7;
477static int hf_ssh_pty_term_mode_cs8;
478static int hf_ssh_pty_term_mode_parenb;
479static int hf_ssh_pty_term_mode_parodd;
480static int hf_ssh_pty_term_mode_ispeed;
481static int hf_ssh_pty_term_mode_ospeed;
482static int hf_ssh_pty_term_mode_value;
483static int hf_ssh_channel_window_adjust;
484static int hf_ssh_channel_data_len;
485static int hf_ssh_channel_data_type_code;
486static int hf_ssh_exit_status;
487static int hf_ssh_disconnect_reason;
488static int hf_ssh_disconnect_description_length;
489static int hf_ssh_disconnect_description;
490static int hf_ssh_lang_tag_length;
491static int hf_ssh_lang_tag;
492static int hf_ssh_ping_data_length;
493static int hf_ssh_ping_data;
494static int hf_ssh_pong_data_length;
495static int hf_ssh_pong_data;
496
497static int hf_ssh_blob;
498static int hf_ssh_blob_e;
499static int hf_ssh_blob_n;
500static int hf_ssh_blob_dsa_p;
501static int hf_ssh_blob_dsa_q;
502static int hf_ssh_blob_dsa_g;
503static int hf_ssh_blob_dsa_y;
504static int hf_ssh_blob_ecdsa_curve_id;
505static int hf_ssh_blob_ecdsa_curve_id_length;
506static int hf_ssh_blob_ecdsa_q;
507static int hf_ssh_blob_ecdsa_q_length;
508static int hf_ssh_blob_eddsa_key;
509static int hf_ssh_blob_eddsa_key_length;
510static int hf_ssh_blob_data;
511
512static int hf_ssh_pk_sig_s_length;
513static int hf_ssh_pk_sig_s;
514
515static int hf_ssh_reassembled_in;
516static int hf_ssh_reassembled_length;
517static int hf_ssh_reassembled_data;
518static int hf_ssh_segments;
519static int hf_ssh_segment;
520static int hf_ssh_segment_overlap;
521static int hf_ssh_segment_overlap_conflict;
522static int hf_ssh_segment_multiple_tails;
523static int hf_ssh_segment_too_long_fragment;
524static int hf_ssh_segment_error;
525static int hf_ssh_segment_count;
526static int hf_ssh_segment_data;
527
528static int ett_ssh;
529static int ett_key_exchange;
530static int ett_key_exchange_host_key;
531static int ett_key_exchange_host_sig;
532static int ett_extension;
533static int ett_userauth_pk_blob;
534static int ett_userauth_pk_signature;
535static int ett_term_modes;
536static int ett_term_mode;
537static int ett_key_init;
538static int ett_ssh1;
539static int ett_ssh2;
540static int ett_ssh_segments;
541static int ett_ssh_segment;
542static int ett_ssh_pqhybrid_client;
543static int ett_ssh_pqhybrid_server;
544
545static expert_field ei_ssh_packet_length;
546static expert_field ei_ssh_padding_length;
547static expert_field ei_ssh_packet_decode;
548static expert_field ei_ssh_channel_number;
549static expert_field ei_ssh_invalid_keylen;
550static expert_field ei_ssh_mac_bad;
551static expert_field ei_ssh2_kex_hybrid_msg_code;
552static expert_field ei_ssh2_kex_hybrid_msg_code_unknown;
553
554static bool_Bool ssh_desegment = true1;
555static bool_Bool ssh_ignore_mac_failed;
556
557static dissector_handle_t ssh_handle;
558static dissector_handle_t sftp_handle;
559static dissector_handle_t data_text_lines_handle;
560
561static const char *pref_keylog_file;
562static FILE *ssh_keylog_file;
563
564static reassembly_table ssh_reassembly_table;
565
566static const fragment_items ssh_segment_items = {
567 &ett_ssh_segment,
568 &ett_ssh_segments,
569 &hf_ssh_segments,
570 &hf_ssh_segment,
571 &hf_ssh_segment_overlap,
572 &hf_ssh_segment_overlap_conflict,
573 &hf_ssh_segment_multiple_tails,
574 &hf_ssh_segment_too_long_fragment,
575 &hf_ssh_segment_error,
576 &hf_ssh_segment_count,
577 &hf_ssh_reassembled_in,
578 &hf_ssh_reassembled_length,
579 &hf_ssh_reassembled_data,
580 "Segments"
581};
582
583#define SSH_DECRYPT_DEBUG
584
585#ifdef SSH_DECRYPT_DEBUG
586static const char *ssh_debug_file_name;
587#endif
588
589#define TCP_RANGE_SSH"22" "22"
590#define SCTP_PORT_SSH22 22
591
592/* Message Numbers (from RFC 4250) (1-255) */
593
594/* Transport layer protocol: generic (1-19) */
595#define SSH_MSG_DISCONNECT1 1
596#define SSH_MSG_IGNORE2 2
597#define SSH_MSG_UNIMPLEMENTED3 3
598#define SSH_MSG_DEBUG4 4
599#define SSH_MSG_SERVICE_REQUEST5 5
600#define SSH_MSG_SERVICE_ACCEPT6 6
601#define SSH_MSG_EXT_INFO7 7
602#define SSH_MSG_NEWCOMPRESS8 8
603
604/* Transport layer protocol: Algorithm negotiation (20-29) */
605#define SSH_MSG_KEXINIT20 20
606#define SSH_MSG_NEWKEYS21 21
607
608/* Transport layer: Key exchange method specific (reusable) (30-49) */
609#define SSH_MSG_KEXDH_INIT30 30
610#define SSH_MSG_KEXDH_REPLY31 31
611
612#define SSH_MSG_KEX_DH_GEX_REQUEST_OLD30 30
613#define SSH_MSG_KEX_DH_GEX_GROUP31 31
614#define SSH_MSG_KEX_DH_GEX_INIT32 32
615#define SSH_MSG_KEX_DH_GEX_REPLY33 33
616#define SSH_MSG_KEX_DH_GEX_REQUEST34 34
617
618#define SSH_MSG_KEX_ECDH_INIT30 30
619#define SSH_MSG_KEX_ECDH_REPLY31 31
620
621#define SSH_MSG_KEX_HYBRID_INIT30 30
622#define SSH_MSG_KEX_HYBRID_REPLY31 31
623
624/* User authentication protocol: generic (50-59) */
625#define SSH_MSG_USERAUTH_REQUEST50 50
626#define SSH_MSG_USERAUTH_FAILURE51 51
627#define SSH_MSG_USERAUTH_SUCCESS52 52
628#define SSH_MSG_USERAUTH_BANNER53 53
629
630/* User authentication protocol: method specific (reusable) (50-79) */
631#define SSH_MSG_USERAUTH_PK_OK60 60
632
633/* Connection protocol: generic (80-89) */
634#define SSH_MSG_GLOBAL_REQUEST80 80
635#define SSH_MSG_REQUEST_SUCCESS81 81
636#define SSH_MSG_REQUEST_FAILURE82 82
637
638/* Connection protocol: channel related messages (90-127) */
639#define SSH_MSG_CHANNEL_OPEN90 90
640#define SSH_MSG_CHANNEL_OPEN_CONFIRMATION91 91
641#define SSH_MSG_CHANNEL_OPEN_FAILURE92 92
642#define SSH_MSG_CHANNEL_WINDOW_ADJUST93 93
643#define SSH_MSG_CHANNEL_DATA94 94
644#define SSH_MSG_CHANNEL_EXTENDED_DATA95 95
645#define SSH_MSG_CHANNEL_EOF96 96
646#define SSH_MSG_CHANNEL_CLOSE97 97
647#define SSH_MSG_CHANNEL_REQUEST98 98
648#define SSH_MSG_CHANNEL_SUCCESS99 99
649#define SSH_MSG_CHANNEL_FAILURE100 100
650
651/* 128-191 reserved for client protocols */
652/* 192-255 local extensions */
653#define SSH_MSG_PING192 192
654#define SSH_MSG_PONG193 193
655
656#define CIPHER_AES128_CTR0x00010001 0x00010001
657#define CIPHER_AES192_CTR0x00010003 0x00010003
658#define CIPHER_AES256_CTR0x00010004 0x00010004
659#define CIPHER_AES128_CBC0x00020001 0x00020001
660#define CIPHER_AES192_CBC0x00020002 0x00020002
661#define CIPHER_AES256_CBC0x00020004 0x00020004
662#define CIPHER_AES128_GCM0x00040001 0x00040001
663//#define CIPHER_AES192_GCM 0x00040002 -- does not exist
664#define CIPHER_AES256_GCM0x00040004 0x00040004
665// DO NOT USE 0x00040000 (used by SSH_KEX_SNTRUP761X25519)
666#define CIPHER_NULL0x00080000 0x00080000
667
668#define CIPHER_MAC_SHA2_2560x00020001 0x00020001
669
670#define SSH_EXTENDED_DATA_STDERR1 1
671
672#define SSH_TTY_OP_END0 0
673#define SSH_TTY_OP_VINTR1 1
674#define SSH_TTY_OP_VQUIT2 2
675#define SSH_TTY_OP_VERASE3 3
676#define SSH_TTY_OP_VKILL4 4
677#define SSH_TTY_OP_VEOF5 5
678#define SSH_TTY_OP_VEOL6 6
679#define SSH_TTY_OP_VEOL27 7
680#define SSH_TTY_OP_VSTART8 8
681#define SSH_TTY_OP_VSTOP9 9
682#define SSH_TTY_OP_VSUSP10 10
683#define SSH_TTY_OP_VDSUSP11 11
684#define SSH_TTY_OP_VREPRINT12 12
685#define SSH_TTY_OP_VWERASE13 13
686#define SSH_TTY_OP_VLNEXT14 14
687#define SSH_TTY_OP_VFLUSH15 15
688#define SSH_TTY_OP_VSWTCH16 16
689#define SSH_TTY_OP_VSTATUS17 17
690#define SSH_TTY_OP_VDISCARD18 18
691#define SSH_TTY_OP_IGNPAR30 30
692#define SSH_TTY_OP_PARMRK31 31
693#define SSH_TTY_OP_INPCK32 32
694#define SSH_TTY_OP_ISTRIP33 33
695#define SSH_TTY_OP_INLCR34 34
696#define SSH_TTY_OP_IGNCR35 35
697#define SSH_TTY_OP_ICRNL36 36
698#define SSH_TTY_OP_IUCLC37 37
699#define SSH_TTY_OP_IXON38 38
700#define SSH_TTY_OP_IXANY39 39
701#define SSH_TTY_OP_IXOFF40 40
702#define SSH_TTY_OP_IMAXBEL41 41
703#define SSH_TTY_OP_IUTF842 42
704#define SSH_TTY_OP_ISIG50 50
705#define SSH_TTY_OP_ICANON51 51
706#define SSH_TTY_OP_XCASE52 52
707#define SSH_TTY_OP_ECHO53 53
708#define SSH_TTY_OP_ECHOE54 54
709#define SSH_TTY_OP_ECHOK55 55
710#define SSH_TTY_OP_ECHONL56 56
711#define SSH_TTY_OP_NOFLSH57 57
712#define SSH_TTY_OP_TOSTOP58 58
713#define SSH_TTY_OP_IEXTEN59 59
714#define SSH_TTY_OP_ECHOCTL60 60
715#define SSH_TTY_OP_ECHOKE61 61
716#define SSH_TTY_OP_PENDIN62 62
717#define SSH_TTY_OP_OPOST70 70
718#define SSH_TTY_OP_OLCUC71 71
719#define SSH_TTY_OP_ONLCR72 72
720#define SSH_TTY_OP_OCRNL73 73
721#define SSH_TTY_OP_ONOCR74 74
722#define SSH_TTY_OP_ONLRET75 75
723#define SSH_TTY_OP_CS790 90
724#define SSH_TTY_OP_CS891 91
725#define SSH_TTY_OP_PARENB92 92
726#define SSH_TTY_OP_PARODD93 93
727#define SSH_TTY_OP_ISPEED128 128
728#define SSH_TTY_OP_OSPEED129 129
729
730static const value_string ssh2_msg_vals[] = {
731 { SSH_MSG_DISCONNECT1, "Disconnect" },
732 { SSH_MSG_IGNORE2, "Ignore" },
733 { SSH_MSG_UNIMPLEMENTED3, "Unimplemented" },
734 { SSH_MSG_DEBUG4, "Debug" },
735 { SSH_MSG_SERVICE_REQUEST5, "Service Request" },
736 { SSH_MSG_SERVICE_ACCEPT6, "Service Accept" },
737 { SSH_MSG_EXT_INFO7, "Extension Information" },
738 { SSH_MSG_NEWCOMPRESS8, "New Compression" },
739 { SSH_MSG_KEXINIT20, "Key Exchange Init" },
740 { SSH_MSG_NEWKEYS21, "New Keys" },
741 { SSH_MSG_USERAUTH_REQUEST50, "User Authentication Request" },
742 { SSH_MSG_USERAUTH_FAILURE51, "User Authentication Failure" },
743 { SSH_MSG_USERAUTH_SUCCESS52, "User Authentication Success" },
744 { SSH_MSG_USERAUTH_BANNER53, "User Authentication Banner" },
745 { SSH_MSG_GLOBAL_REQUEST80, "Global Request" },
746 { SSH_MSG_REQUEST_SUCCESS81, "Request Success" },
747 { SSH_MSG_REQUEST_FAILURE82, "Request Failure" },
748 { SSH_MSG_CHANNEL_OPEN90, "Channel Open" },
749 { SSH_MSG_CHANNEL_OPEN_CONFIRMATION91, "Channel Open Confirmation" },
750 { SSH_MSG_CHANNEL_OPEN_FAILURE92, "Channel Open Failure" },
751 { SSH_MSG_CHANNEL_WINDOW_ADJUST93, "Window Adjust" },
752 { SSH_MSG_CHANNEL_DATA94, "Channel Data" },
753 { SSH_MSG_CHANNEL_EXTENDED_DATA95, "Channel Extended Data" },
754 { SSH_MSG_CHANNEL_EOF96, "Channel EOF" },
755 { SSH_MSG_CHANNEL_CLOSE97, "Channel Close" },
756 { SSH_MSG_CHANNEL_REQUEST98, "Channel Request" },
757 { SSH_MSG_CHANNEL_SUCCESS99, "Channel Success" },
758 { SSH_MSG_CHANNEL_FAILURE100, "Channel Failure" },
759 { SSH_MSG_USERAUTH_PK_OK60, "Public Key algorithm accepted" },
760 { 0, NULL((void*)0) }
761};
762
763static const value_string ssh2_kex_dh_msg_vals[] = {
764 { SSH_MSG_KEXDH_INIT30, "Diffie-Hellman Key Exchange Init" },
765 { SSH_MSG_KEXDH_REPLY31, "Diffie-Hellman Key Exchange Reply" },
766 { 0, NULL((void*)0) }
767};
768
769static const value_string ssh2_kex_dh_gex_msg_vals[] = {
770 { SSH_MSG_KEX_DH_GEX_REQUEST_OLD30, "Diffie-Hellman Group Exchange Request (Old)" },
771 { SSH_MSG_KEX_DH_GEX_GROUP31, "Diffie-Hellman Group Exchange Group" },
772 { SSH_MSG_KEX_DH_GEX_INIT32, "Diffie-Hellman Group Exchange Init" },
773 { SSH_MSG_KEX_DH_GEX_REPLY33, "Diffie-Hellman Group Exchange Reply" },
774 { SSH_MSG_KEX_DH_GEX_REQUEST34, "Diffie-Hellman Group Exchange Request" },
775 { 0, NULL((void*)0) }
776};
777
778static const value_string ssh2_kex_ecdh_msg_vals[] = {
779 { SSH_MSG_KEX_ECDH_INIT30, "Elliptic Curve Diffie-Hellman Key Exchange Init" },
780 { SSH_MSG_KEX_ECDH_REPLY31, "Elliptic Curve Diffie-Hellman Key Exchange Reply" },
781 { 0, NULL((void*)0) }
782};
783
784static const value_string ssh2_kex_hybrid_msg_vals[] = {
785 { SSH_MSG_KEX_HYBRID_INIT30, "PQ/T Hybrid Key Exchange Init" },
786 { SSH_MSG_KEX_HYBRID_REPLY31, "PQ/T Hybrid Key Exchange Reply" },
787 { 0, NULL((void*)0) }
788};
789
790static const value_string ssh2_ext_ping_msg_vals[] = {
791 { SSH_MSG_PING192, "Ping" },
792 { SSH_MSG_PONG193, "Pong" },
793 { 0, NULL((void*)0) }
794};
795
796static const value_string ssh1_msg_vals[] = {
797 {SSH1_MSG_NONE0, "No Message"},
798 {SSH1_MSG_DISCONNECT1, "Disconnect"},
799 {SSH1_SMSG_PUBLIC_KEY2, "Public Key"},
800 {SSH1_CMSG_SESSION_KEY3, "Session Key"},
801 {SSH1_CMSG_USER4, "User"},
802 {0, NULL((void*)0)}
803};
804
805static const value_string ssh_channel_data_type_code_vals[] = {
806 { SSH_EXTENDED_DATA_STDERR1, "Standard Error" },
807 { 0, NULL((void*)0) }
808};
809
810static const value_string ssh_tty_op_vals[] = {
811 { SSH_TTY_OP_END0, "TTY_OP_END" }, // [RFC4250]
812 { SSH_TTY_OP_VINTR1, "VINTR" }, // [RFC4254],Section 8
813 { SSH_TTY_OP_VQUIT2, "VQUIT" }, // [RFC4254],Section 8
814 { SSH_TTY_OP_VERASE3, "VERASE" }, // [RFC4254],Section 8
815 { SSH_TTY_OP_VKILL4, "VKILL" }, // [RFC4254], Section 8
816 { SSH_TTY_OP_VEOF5, "VEOF" }, // [RFC4254],Section 8
817 { SSH_TTY_OP_VEOL6, "VEOL" }, // [RFC4254],Section 8
818 { SSH_TTY_OP_VEOL27, "VEOL2" }, // [RFC4254], Section 8
819 { SSH_TTY_OP_VSTART8, "VSTART" }, // [RFC4254],Section 8
820 { SSH_TTY_OP_VSTOP9, "VSTOP" }, // [RFC4254], Section 8
821 { SSH_TTY_OP_VSUSP10, "VSUSP" }, // [RFC4254], Section 8
822 { SSH_TTY_OP_VDSUSP11, "VDSUSP" }, // [RFC4254], Section 8
823 { SSH_TTY_OP_VREPRINT12, "VREPRINT" }, // [RFC4254], Section 8
824 { SSH_TTY_OP_VWERASE13, "VWERASE" }, // [RFC4254], Section 8
825 { SSH_TTY_OP_VLNEXT14, "VLNEXT" }, // [RFC4254],Section 8
826 { SSH_TTY_OP_VFLUSH15, "VFLUSH" }, // [RFC4254], Section 8
827 { SSH_TTY_OP_VSWTCH16, "VSWTCH" }, // [RFC4254], Section 8
828 { SSH_TTY_OP_VSTATUS17, "VSTATUS" }, // [RFC4254],Section 8
829 { SSH_TTY_OP_VDISCARD18, "VDISCARD" }, // [RFC4254], Section 8
830 { SSH_TTY_OP_IGNPAR30, "IGNPAR" }, // [RFC4254],Section 8
831 { SSH_TTY_OP_PARMRK31, "PARMRK" }, // [RFC4254], Section 8
832 { SSH_TTY_OP_INPCK32, "INPCK" }, // [RFC4254], Section 8
833 { SSH_TTY_OP_ISTRIP33, "ISTRIP" }, // [RFC4254], Section 8
834 { SSH_TTY_OP_INLCR34, "INLCR" }, // [RFC4254], Section 8
835 { SSH_TTY_OP_IGNCR35, "IGNCR" }, // [RFC4254], Section 8
836 { SSH_TTY_OP_ICRNL36, "ICRNL" }, // [RFC4254], Section 8
837 { SSH_TTY_OP_IUCLC37, "IUCLC" }, // [RFC4254],Section 8
838 { SSH_TTY_OP_IXON38, "IXON" }, // [RFC4254], Section 8
839 { SSH_TTY_OP_IXANY39, "IXANY" }, // [RFC4254], Section 8
840 { SSH_TTY_OP_IXOFF40, "IXOFF" }, // [RFC4254], Section 8
841 { SSH_TTY_OP_IMAXBEL41, "IMAXBEL" }, // [RFC4254], Section 8
842 { SSH_TTY_OP_IUTF842, "IUTF8" }, // [RFC8160],
843 { SSH_TTY_OP_ISIG50, "ISIG" }, // [RFC4254], Section 8
844 { SSH_TTY_OP_ICANON51, "ICANON" }, // [RFC4254], Section 8
845 { SSH_TTY_OP_XCASE52, "XCASE" }, // [RFC4254],Section 8
846 { SSH_TTY_OP_ECHO53, "ECHO" }, // [RFC4254], Section 8
847 { SSH_TTY_OP_ECHOE54, "ECHOE" }, // [RFC4254], Section 8
848 { SSH_TTY_OP_ECHOK55, "ECHOK" }, // [RFC4254], Section 8
849 { SSH_TTY_OP_ECHONL56, "ECHONL" }, // [RFC4254], Section 8
850 { SSH_TTY_OP_NOFLSH57, "NOFLSH" }, // [RFC4254],Section 8
851 { SSH_TTY_OP_TOSTOP58, "TOSTOP" }, // [RFC4254], Section 8
852 { SSH_TTY_OP_IEXTEN59, "IEXTEN" }, // [RFC4254], Section 8
853 { SSH_TTY_OP_ECHOCTL60, "ECHOCTL" }, // [RFC4254], Section 8
854 { SSH_TTY_OP_ECHOKE61, "ECHOKE" }, // [RFC4254], Section 8
855 { SSH_TTY_OP_PENDIN62, "PENDIN" }, // [RFC4254], Section 8
856 { SSH_TTY_OP_OPOST70, "OPOST" }, // [RFC4254], Section 8
857 { SSH_TTY_OP_OLCUC71, "OLCUC" }, // [RFC4254], Section 8
858 { SSH_TTY_OP_ONLCR72, "ONLCR" }, // [RFC4254], Section 8
859 { SSH_TTY_OP_OCRNL73, "OCRNL" }, // [RFC4254],Section 8
860 { SSH_TTY_OP_ONOCR74, "ONOCR" }, // [RFC4254],Section 8
861 { SSH_TTY_OP_ONLRET75, "ONLRET" }, // [RFC4254],Section 8
862 { SSH_TTY_OP_CS790, "CS7" }, // [RFC4254], Section 8
863 { SSH_TTY_OP_CS891, "CS8" }, // [RFC4254], Section 8
864 { SSH_TTY_OP_PARENB92, "PARENB" }, // [RFC4254], Section 8
865 { SSH_TTY_OP_PARODD93, "PARODD" }, // [RFC4254], Section 8
866 { SSH_TTY_OP_ISPEED128, "TTY_OP_ISPEED" }, // [RFC4254],Section 8
867 { SSH_TTY_OP_OSPEED129, "TTY_OP_OSPEED" }, // [RFC4254],Section 8
868 { 0, NULL((void*)0) }
869};
870
871static int ssh_dissect_key_init(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *tree,
872 int is_response,
873 struct ssh_flow_data *global_data);
874static int ssh_dissect_proposal(tvbuff_t *tvb, int offset, proto_tree *tree,
875 int hf_index_length, int hf_index_value, char **store);
876static int ssh_dissect_ssh1(tvbuff_t *tvb, packet_info *pinfo,
877 struct ssh_flow_data *global_data,
878 int offset, proto_tree *tree, int is_response,
879 bool_Bool *need_desegmentation);
880static int ssh_dissect_ssh2(tvbuff_t *tvb, packet_info *pinfo,
881 struct ssh_flow_data *global_data,
882 int offset, proto_tree *tree, int is_response,
883 bool_Bool *need_desegmentation);
884static int ssh_dissect_key_exchange(tvbuff_t *tvb, packet_info *pinfo,
885 struct ssh_flow_data *global_data,
886 int offset, proto_tree *tree, int is_response,
887 bool_Bool *need_desegmentation);
888static int ssh_dissect_kex_dh(uint8_t msg_code, tvbuff_t *tvb,
889 packet_info *pinfo, int offset, proto_tree *tree,
890 struct ssh_flow_data *global_data);
891static int ssh_dissect_kex_dh_gex(uint8_t msg_code, tvbuff_t *tvb,
892 packet_info *pinfo, int offset, proto_tree *tree,
893 struct ssh_flow_data *global_data);
894static int ssh_dissect_kex_ecdh(uint8_t msg_code, tvbuff_t *tvb,
895 packet_info *pinfo, int offset, proto_tree *tree,
896 struct ssh_flow_data *global_data);
897static int ssh_dissect_kex_pq_hybrid(uint8_t msg_code, tvbuff_t *tvb,
898 packet_info *pinfo, int offset, proto_tree *tree,
899 struct ssh_flow_data *global_data);
900static int // add support of client PQ hybrid key (e)
901ssh_read_e_pq(tvbuff_t *tvb, int offset, struct ssh_flow_data *global_data);
902static int // add support of server PQ hybrid key (f)
903ssh_read_f_pq(tvbuff_t *tvb, int offset, struct ssh_flow_data *global_data);
904static int ssh_dissect_protocol(tvbuff_t *tvb, packet_info *pinfo,
905 struct ssh_flow_data *global_data,
906 unsigned offset, proto_tree *tree, int is_response, unsigned *version,
907 bool_Bool *need_desegmentation);
908static int ssh_try_dissect_encrypted_packet(tvbuff_t *tvb, packet_info *pinfo,
909 struct ssh_peer_data *peer_data, int offset, proto_tree *tree);
910static int ssh_dissect_encrypted_packet(tvbuff_t *tvb, packet_info *pinfo,
911 struct ssh_peer_data *peer_data,
912 int offset, proto_tree *tree);
913static bool_Bool ssh_choose_algo(char *client, char *server, char **result);
914static void ssh_set_mac_length(struct ssh_peer_data *peer_data);
915static void ssh_set_kex_specific_dissector(struct ssh_flow_data *global_data);
916
917static void ssh_keylog_read_file(void);
918static void ssh_keylog_process_line(const char *line);
919static void ssh_keylog_process_lines(const uint8_t *data, unsigned datalen);
920static void ssh_keylog_reset(void);
921static ssh_bignum *ssh_kex_make_bignum(const uint8_t *data, unsigned length);
922static bool_Bool ssh_read_e(tvbuff_t *tvb, int offset,
923 struct ssh_flow_data *global_data);
924static bool_Bool ssh_read_f(tvbuff_t *tvb, int offset,
925 struct ssh_flow_data *global_data);
926static ssh_bignum * ssh_read_mpint(tvbuff_t *tvb, int offset);
927static void ssh_keylog_hash_write_secret(struct ssh_flow_data *global_data, wmem_allocator_t* tmp_allocator);
928static ssh_bignum *ssh_kex_shared_secret(int kex_type, ssh_bignum *pub, ssh_bignum *priv, ssh_bignum *modulo);
929static void ssh_hash_buffer_put_string(wmem_array_t *buffer, const uint8_t *string,
930 unsigned len);
931static void ssh_hash_buffer_put_uint32(wmem_array_t *buffer, unsigned val);
932static char *ssh_string(wmem_allocator_t* allocator, const uint8_t *string, unsigned len);
933static void ssh_derive_symmetric_keys(ssh_bignum *shared_secret,
934 uint8_t *exchange_hash, unsigned hash_length,
935 struct ssh_flow_data *global_data);
936static void ssh_derive_symmetric_key(ssh_bignum *shared_secret,
937 const uint8_t *exchange_hash, unsigned hash_length, char id,
938 ssh_bignum *result_key, struct ssh_flow_data *global_data, unsigned we_need);
939
940static void ssh_choose_enc_mac(struct ssh_flow_data *global_data);
941static void ssh_decryption_set_cipher_id(struct ssh_peer_data *peer);
942static void ssh_decryption_setup_cipher(struct ssh_peer_data *peer,
943 ssh_bignum *iv, ssh_bignum *key);
944static void ssh_decryption_set_mac_id(struct ssh_peer_data *peer);
945static void ssh_decryption_setup_mac(struct ssh_peer_data *peer,
946 ssh_bignum *iv);
947static ssh_packet_info_t* ssh_get_packet_info(packet_info *pinfo, bool_Bool is_response);
948static ssh_message_info_t* ssh_get_message(packet_info *pinfo, int record_id);
949static unsigned ssh_decrypt_packet(tvbuff_t *tvb, packet_info *pinfo,
950 struct ssh_peer_data *peer_data, int offset);
951static bool_Bool ssh_decrypt_chacha20(gcry_cipher_hd_t hd, uint32_t seqnr,
952 uint32_t counter, const unsigned char *ctext, unsigned ctext_len,
953 unsigned char *plain, unsigned plain_len);
954static int ssh_dissect_decrypted_packet(tvbuff_t *tvb, packet_info *pinfo,
955 struct ssh_peer_data *peer_data, proto_tree *tree,
956 ssh_message_info_t *message);
957static int ssh_dissect_transport_generic(tvbuff_t *packet_tvb, packet_info *pinfo,
958 int offset, struct ssh_peer_data *peer_data, proto_item *msg_type_tree, unsigned msg_code);
959static int ssh_dissect_rfc8308_extension(tvbuff_t *packet_tvb, packet_info *pinfo,
960 int offset, struct ssh_peer_data *peer_data, proto_item *msg_type_tree);
961static int ssh_dissect_userauth_generic(tvbuff_t *packet_tvb, packet_info *pinfo,
962 int offset, proto_item *msg_type_tree, unsigned msg_code);
963static int ssh_dissect_userauth_specific(tvbuff_t *packet_tvb, packet_info *pinfo,
964 int offset, proto_item *msg_type_tree, unsigned msg_code);
965static int ssh_dissect_connection_specific(tvbuff_t *packet_tvb, packet_info *pinfo,
966 struct ssh_peer_data *peer_data, int offset, proto_item *msg_type_tree,
967 unsigned msg_code, ssh_message_info_t *message);
968static int ssh_dissect_connection_generic(tvbuff_t *packet_tvb, packet_info *pinfo,
969 int offset, proto_item *msg_type_tree, unsigned msg_code);
970static int ssh_dissect_local_extension(tvbuff_t *packet_tvb, packet_info *pinfo,
971 int offset, struct ssh_peer_data *peer_data, proto_item *msg_type_tree, unsigned msg_code);
972static int ssh_dissect_public_key_blob(tvbuff_t *tvb, packet_info *pinfo,
973 proto_item *msg_type_tree);
974static int ssh_dissect_public_key_signature(tvbuff_t *packet_tvb, packet_info *pinfo,
975 int offset, proto_item *msg_type_tree);
976
977static void create_channel(struct ssh_peer_data *peer_data, uint32_t recipient_channel, uint32_t sender_channel);
978static ssh_channel_info_t* get_channel_info_for_channel(struct ssh_peer_data *peer_data, uint32_t recipient_channel);
979static void set_subdissector_for_channel(struct ssh_peer_data *peer_data, uint32_t recipient_channel, const char* subsystem_name);
980
981#define SSH_DEBUG_USE_STDERR"-" "-"
982
983#ifdef SSH_DECRYPT_DEBUG
984static void
985ssh_debug_printf(const char* fmt,...) G_GNUC_PRINTF(1,2)__attribute__((__format__ (__printf__, 1, 2)));
986static void
987ssh_print_data(const char* name, const unsigned char* data, size_t len);
988static void
989ssh_set_debug(const char* name);
990static void
991ssh_debug_flush(void);
992#else
993
994/* No debug: nullify debug operation*/
995static inline void G_GNUC_PRINTF(1,2)__attribute__((__format__ (__printf__, 1, 2)))
996ssh_debug_printf(const char* fmt _U___attribute__((unused)),...)
997{
998}
999#define ssh_print_data(a, b, c)
1000#define ssh_print_string(a, b)
1001#define ssh_set_debug(name)
1002#define ssh_debug_flush()
1003
1004#endif /* SSH_DECRYPT_DEBUG */
1005
1006static void
1007ssh_set_server(struct ssh_flow_data *global_data, address *addr, uint32_t port)
1008{
1009 copy_address_wmem(wmem_file_scope(), &global_data->srv_addr, addr);
1010 global_data->srv_port = port;
1011}
1012
1013static bool_Bool
1014ssh_packet_from_server(struct ssh_flow_data *session, const packet_info *pinfo)
1015{
1016 bool_Bool ret;
1017 if (session && session->srv_addr.type != AT_NONE) {
1018 ret = (session->srv_port == pinfo->srcport) &&
1019 addresses_equal(&session->srv_addr, &pinfo->src);
1020 } else {
1021 ret = (pinfo->match_uint == pinfo->srcport);
1022 }
1023
1024 ssh_debug_printf("packet_from_server: is from server - %s\n", (ret)?"TRUE":"FALSE");
1025 return ret;
1026}
1027
1028static bool_Bool
1029ssh_peer_data_from_server(struct ssh_peer_data* peer_data) {
1030 return &peer_data->global_data->peer_data[SERVER_PEER_DATA1] == peer_data;
1031}
1032
1033static int
1034dissect_ssh(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U___attribute__((unused)))
1035{
1036 proto_tree *ssh_tree;
1037 proto_item *ti;
1038 conversation_t *conversation;
1039 int last_offset, offset = 0;
1040
1041 bool_Bool is_response,
1042 need_desegmentation;
1043 unsigned version;
1044
1045 struct ssh_flow_data *global_data = NULL((void*)0);
1046 struct ssh_peer_data *peer_data;
1047
1048 ssh_debug_printf("\ndissect_ssh enter frame #%u (%s)\n", pinfo->num, (pinfo->fd->visited)?"already visited":"first time");
1049
1050 conversation = find_or_create_conversation(pinfo);
1051
1052 global_data = (struct ssh_flow_data *)conversation_get_proto_data(conversation, proto_ssh);
1053 if (!global_data) {
1054 global_data = wmem_new0(wmem_file_scope(), struct ssh_flow_data)((struct ssh_flow_data*)wmem_alloc0((wmem_file_scope()), sizeof
(struct ssh_flow_data)))
;
1055 global_data->version = SSH_VERSION_UNKNOWN0;
1056 global_data->kex_specific_dissector = ssh_dissect_kex_dh;
1057 global_data->peer_data[CLIENT_PEER_DATA0].mac_length = -1;
1058 global_data->peer_data[SERVER_PEER_DATA1].mac_length = -1;
1059 global_data->peer_data[CLIENT_PEER_DATA0].sequence_number = 0;
1060 global_data->peer_data[SERVER_PEER_DATA1].sequence_number = 0;
1061 global_data->peer_data[CLIENT_PEER_DATA0].bn_cookie = NULL((void*)0);
1062 global_data->peer_data[SERVER_PEER_DATA1].bn_cookie = NULL((void*)0);
1063 global_data->peer_data[CLIENT_PEER_DATA0].global_data = global_data;
1064 global_data->peer_data[SERVER_PEER_DATA1].global_data = global_data;
1065 global_data->kex_client_version = wmem_array_new(wmem_file_scope(), 1);
1066 global_data->kex_server_version = wmem_array_new(wmem_file_scope(), 1);
1067 global_data->kex_client_key_exchange_init = wmem_array_new(wmem_file_scope(), 1);
1068 global_data->kex_server_key_exchange_init = wmem_array_new(wmem_file_scope(), 1);
1069 global_data->kex_server_host_key_blob = wmem_array_new(wmem_file_scope(), 1);
1070 global_data->kex_gex_bits_min = wmem_array_new(wmem_file_scope(), 1);
1071 global_data->kex_gex_bits_req = wmem_array_new(wmem_file_scope(), 1);
1072 global_data->kex_gex_bits_max = wmem_array_new(wmem_file_scope(), 1);
1073 global_data->kex_shared_secret = wmem_array_new(wmem_file_scope(), 1);
1074 global_data->do_decrypt = true1;
1075 global_data->ext_ping_openssh_offered = false0;
1076
1077 /* We expect to get the client message first. If this is from an
1078 * an assigned server port, call it the server, otherwise call it
1079 * the client.
1080 * XXX - We don't unambiguously know which side is the server and
1081 * which the client until the KEX specific _INIT and _REPLY messages;
1082 * we ought to be able to handle the cases where the version string or
1083 * KEXINIT messages are out of order or where the client version string
1084 * is missing. */
1085 if (pinfo->match_uint == pinfo->srcport) {
1086 ssh_set_server(global_data, &pinfo->src, pinfo->srcport);
1087 } else {
1088 ssh_set_server(global_data, &pinfo->dst, pinfo->destport);
1089 }
1090
1091 conversation_add_proto_data(conversation, proto_ssh, global_data);
1092 }
1093
1094 is_response = ssh_packet_from_server(global_data, pinfo);
1095 peer_data = &global_data->peer_data[is_response];
1096
1097 ti = proto_tree_add_item(tree, proto_ssh, tvb, offset, -1, ENC_NA0x00000000);
1098 ssh_tree = proto_item_add_subtree(ti, ett_ssh);
1099
1100 version = global_data->version;
1101
1102 switch(version) {
1103 case SSH_VERSION_UNKNOWN0:
1104 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SSH");
1105 break;
1106 case SSH_VERSION_11:
1107 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SSHv1");
1108 break;
1109 case SSH_VERSION_22:
1110 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SSHv2");
1111 break;
1112
1113 }
1114
1115 col_clear(pinfo->cinfo, COL_INFO);
1116
1117 while(tvb_reported_length_remaining(tvb, offset)> 0) {
1118 bool_Bool after_version_start = (peer_data->frame_version_start == 0 ||
1119 pinfo->num >= peer_data->frame_version_start);
1120 bool_Bool before_version_end = (peer_data->frame_version_end == 0 ||
1121 pinfo->num <= peer_data->frame_version_end);
1122
1123 need_desegmentation = false0;
1124 last_offset = offset;
1125
1126 peer_data->counter++;
1127
1128 if (after_version_start && before_version_end &&
1129 (tvb_strncaseeql(tvb, offset, "SSH-", 4) == 0)) {
1130 if (peer_data->frame_version_start == 0)
1131 peer_data->frame_version_start = pinfo->num;
1132
1133 offset = ssh_dissect_protocol(tvb, pinfo,
1134 global_data,
1135 offset, ssh_tree, is_response,
1136 &version, &need_desegmentation);
1137
1138 if (!need_desegmentation) {
1139 peer_data->frame_version_end = pinfo->num;
1140 global_data->version = version;
1141 }
1142 } else {
1143 switch(version) {
1144
1145 case SSH_VERSION_UNKNOWN0:
1146 offset = ssh_try_dissect_encrypted_packet(tvb, pinfo,
1147 &global_data->peer_data[is_response], offset, ssh_tree);
1148 break;
1149
1150 case SSH_VERSION_11:
1151 offset = ssh_dissect_ssh1(tvb, pinfo, global_data,
1152 offset, ssh_tree, is_response,
1153 &need_desegmentation);
1154 break;
1155
1156 case SSH_VERSION_22:
1157 offset = ssh_dissect_ssh2(tvb, pinfo, global_data,
1158 offset, ssh_tree, is_response,
1159 &need_desegmentation);
1160 break;
1161 }
1162 }
1163
1164 if (need_desegmentation)
1165 return tvb_captured_length(tvb);
1166 if (offset <= last_offset) {
1167 /* XXX - add an expert info in the function
1168 that decrements offset */
1169 break;
1170 }
1171 }
1172
1173 col_prepend_fstr(pinfo->cinfo, COL_INFO, "%s: ", is_response ? "Server" : "Client");
1174 ti = proto_tree_add_boolean(ssh_tree, hf_ssh_direction, tvb, 0, 0, is_response);
1175 proto_item_set_generated(ti);
1176
1177 ssh_debug_flush();
1178
1179 return tvb_captured_length(tvb);
1180}
1181
1182static bool_Bool
1183dissect_ssh_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
1184{
1185 conversation_t *conversation;
1186
1187 if (tvb_strneql(tvb, 0, "SSH-", 4) != 0) {
1188 return false0;
1189 }
1190
1191 conversation = find_or_create_conversation(pinfo);
1192 conversation_set_dissector(conversation, ssh_handle);
1193
1194 dissect_ssh(tvb, pinfo, tree, data);
1195
1196 return true1;
1197}
1198
1199static int
1200ssh_dissect_ssh2(tvbuff_t *tvb, packet_info *pinfo,
1201 struct ssh_flow_data *global_data,
1202 int offset, proto_tree *tree, int is_response,
1203 bool_Bool *need_desegmentation)
1204{
1205 proto_item *ssh2_tree = NULL((void*)0);
1206 int remain_length;
1207
1208 struct ssh_peer_data *peer_data = &global_data->peer_data[is_response];
1209
1210 remain_length = tvb_captured_length_remaining(tvb, offset);
1211
1212 if (PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
1213 ws_debug("SSH: SECOND PASS frame %u", pinfo->num)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 1213, __func__, "SSH: SECOND PASS frame %u", pinfo->num)
; } } while (0)
;
1214 }else{
1215 ws_debug("SSH: FIRST PASS frame %u", pinfo->num)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 1215, __func__, "SSH: FIRST PASS frame %u", pinfo->num);
} } while (0)
;
1216 }
1217
1218 while(remain_length>0){
1219 int last_offset = offset;
1220 if (tree) {
1221 wmem_strbuf_t *title = wmem_strbuf_new(pinfo->pool, "SSH Version 2");
1222
1223 if (peer_data->enc || peer_data->mac || peer_data->comp) {
1224 wmem_strbuf_append_printf(title, " (");
1225 if (peer_data->enc)
1226 wmem_strbuf_append_printf(title, "encryption:%s%s",
1227 peer_data->enc,
1228 peer_data->mac || peer_data->comp
1229 ? " " : "");
1230 if (peer_data->mac)
1231 wmem_strbuf_append_printf(title, "mac:%s%s",
1232 peer_data->mac,
1233 peer_data->comp ? " " : "");
1234 if (peer_data->comp)
1235 wmem_strbuf_append_printf(title, "compression:%s",
1236 peer_data->comp);
1237 wmem_strbuf_append_printf(title, ")");
1238 }
1239
1240 ssh2_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_ssh2, NULL((void*)0), wmem_strbuf_get_str(title));
1241 }
1242 ws_noisy("....ssh_dissect_ssh2[%c]: frame_key_start=%d, pinfo->num=%d, frame_key_end=%d, offset=%d, frame_key_end_offset=%d ", is_response==SERVER_PEER_DATA?'S':'C', peer_data->frame_key_start, pinfo->num, peer_data->frame_key_end, offset, peer_data->frame_key_end_offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 1242, __func__, "....ssh_dissect_ssh2[%c]: frame_key_start=%d, pinfo->num=%d, frame_key_end=%d, offset=%d, frame_key_end_offset=%d "
, is_response==1?'S':'C', peer_data->frame_key_start, pinfo
->num, peer_data->frame_key_end, offset, peer_data->
frame_key_end_offset); } } while (0)
;
1243 if ((peer_data->frame_key_start == 0) ||
1244 ((peer_data->frame_key_start <= pinfo->num) &&
1245 ((peer_data->frame_key_end == 0) || (pinfo->num < peer_data->frame_key_end) ||
1246 ((pinfo->num == peer_data->frame_key_end) && (offset < peer_data->frame_key_end_offset))))) {
1247 offset = ssh_dissect_key_exchange(tvb, pinfo, global_data,
1248 offset, ssh2_tree, is_response,
1249 need_desegmentation);
1250
1251 if (!*need_desegmentation) {
1252 ssh_get_packet_info(pinfo, is_response);
1253 }else{
1254 break;
1255 }
1256 } else {
1257 if(!*need_desegmentation){
1258 offset = ssh_try_dissect_encrypted_packet(tvb, pinfo,
1259 &global_data->peer_data[is_response], offset, ssh2_tree);
1260 if (pinfo->desegment_len) {
1261 break;
1262 }
1263 }else{
1264 break;
1265 }
1266 }
1267
1268 if (ssh2_tree) {
1269 proto_item_set_len(ssh2_tree, offset - last_offset);
1270 }
1271
1272 remain_length = tvb_captured_length_remaining(tvb, offset);
1273 }
1274
1275 return offset;
1276}
1277static int
1278ssh_dissect_ssh1(tvbuff_t *tvb, packet_info *pinfo,
1279 struct ssh_flow_data *global_data,
1280 int offset, proto_tree *tree, int is_response,
1281 bool_Bool *need_desegmentation)
1282{
1283 unsigned plen, padding_length, len;
1284 uint8_t msg_code;
1285 unsigned remain_length;
1286
1287 proto_item *ssh1_tree;
1288
1289 struct ssh_peer_data *peer_data = &global_data->peer_data[is_response];
1290
1291 ssh1_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_ssh1, NULL((void*)0), "SSH Version 1");
1292
1293 /*
1294 * We use "tvb_ensure_captured_length_remaining()" to make sure there
1295 * actually *is* data remaining.
1296 *
1297 * This means we're guaranteed that "remain_length" is positive.
1298 */
1299 remain_length = tvb_ensure_captured_length_remaining(tvb, offset);
1300 /*
1301 * Can we do reassembly?
1302 */
1303 if (ssh_desegment && pinfo->can_desegment) {
1304 /*
1305 * Yes - would an SSH header starting at this offset be split
1306 * across segment boundaries?
1307 */
1308 if (remain_length < 4) {
1309 /*
1310 * Yes. Tell the TCP dissector where the data for
1311 * this message starts in the data it handed us and
1312 * that we need "some more data." Don't tell it
1313 * exactly how many bytes we need because if/when we
1314 * ask for even more (after the header) that will
1315 * break reassembly.
1316 */
1317 pinfo->desegment_offset = offset;
1318 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT0x0fffffff;
1319 *need_desegmentation = true1;
1320 return offset;
1321 }
1322 }
1323 plen = tvb_get_ntohl(tvb, offset) ;
1324
1325 /*
1326 * Amount of random padding.
1327 *
1328 * This is between 1 and 8; if the length is a multiple of 8,
1329 * there are 8 bytes of padding, not 1 byte.
1330 *
1331 * That means this calculation is correct; do not use either
1332 * WS_ROUNDUP_8() or WS_PADDING_TO_8() here.
1333 */
1334 padding_length = 8 - plen%8;
1335
1336
1337 if (ssh_desegment && pinfo->can_desegment) {
1338 if (plen+4+padding_length > remain_length) {
1339 pinfo->desegment_offset = offset;
1340 pinfo->desegment_len = plen+padding_length - remain_length;
1341 *need_desegmentation = true1;
1342 return offset;
1343 }
1344 }
1345
1346 if (plen >= SSH_MAX_PACKET_LEN32768) {
1347 if (ssh1_tree) {
1348 proto_tree_add_uint_format(ssh1_tree, hf_ssh_packet_length, tvb,
1349 offset, 4, plen, "Overly large length %x", plen);
1350 }
1351 plen = remain_length-4-padding_length;
1352 } else {
1353 if (ssh1_tree && plen > 0) {
1354 proto_tree_add_uint(ssh1_tree, hf_ssh_packet_length, tvb,
1355 offset, 4, plen);
1356 }
1357 }
1358 offset+=4;
1359 /* padding length */
1360
1361 proto_tree_add_uint(ssh1_tree, hf_ssh_padding_length, tvb,
1362 offset, padding_length, padding_length);
1363 offset += padding_length;
1364
1365 /* msg_code */
1366 if ((peer_data->frame_key_start == 0) ||
1367 ((peer_data->frame_key_start >= pinfo->num) && (pinfo->num <= peer_data->frame_key_end))) {
1368
1369 proto_tree_add_item_ret_uint8(ssh1_tree, hf_ssh_msg_code, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000, &msg_code);
1370 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0),
1371 val_to_str(pinfo->pool, msg_code, ssh1_msg_vals, "Unknown (%u)"));
1372 offset += 1;
1373 len = plen -1;
1374 if (!pinfo->fd->visited) {
1375 if (peer_data->frame_key_start == 0)
1376 peer_data->frame_key_start = pinfo->num;
1377 peer_data->frame_key_end = pinfo->num;
1378 }
1379 } else {
1380 len = plen;
1381 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL((void*)0), "Encrypted packet (len=%d)", len);
1382 }
1383 /* payload */
1384 if (ssh1_tree) {
1385 proto_tree_add_item(ssh1_tree, hf_ssh_payload,
1386 tvb, offset, len, ENC_NA0x00000000);
1387 }
1388 offset += len;
1389
1390 return offset;
1391}
1392
1393static int
1394ssh_tree_add_mpint(tvbuff_t *tvb, int offset, proto_tree *tree,
1395 int hf_ssh_mpint_selection)
1396{
1397 unsigned len = tvb_get_ntohl(tvb, offset);
1398 proto_tree_add_uint(tree, hf_ssh_mpint_length, tvb,
1399 offset, 4, len);
1400 offset+=4;
1401 proto_tree_add_item(tree, hf_ssh_mpint_selection,
1402 tvb, offset, len, ENC_NA0x00000000);
1403 return 4+len;
1404}
1405
1406static int
1407ssh_tree_add_string(tvbuff_t *tvb, int offset, proto_tree *tree,
1408 int hf_ssh_string, int hf_ssh_string_length)
1409{
1410 unsigned len = tvb_get_ntohl(tvb, offset);
1411 proto_tree_add_uint(tree, hf_ssh_string_length, tvb,
1412 offset, 4, len);
1413 offset+=4;
1414 proto_tree_add_item(tree, hf_ssh_string,
1415 tvb, offset, len, ENC_NA0x00000000);
1416 return 4+len;
1417}
1418
1419static unsigned
1420ssh_tree_add_hostkey(tvbuff_t *tvb, packet_info* pinfo, int offset, proto_tree *parent_tree,
1421 const char *tree_name, int ett_idx,
1422 struct ssh_flow_data *global_data)
1423{
1424 proto_tree *tree = NULL((void*)0);
1425 proto_item *ti;
1426 int last_offset;
1427 int remaining_len;
1428 unsigned key_len, type_len;
1429 char* key_type;
1430 char *tree_title;
1431
1432 last_offset = offset;
1433
1434 key_len = tvb_get_ntohl(tvb, offset);
1435 offset += 4;
1436
1437 /* Read the key type before creating the tree so we can append it as info. */
1438 type_len = tvb_get_ntohl(tvb, offset);
1439 offset += 4;
1440 key_type = (char *) tvb_get_string_enc(pinfo->pool, tvb, offset, type_len, ENC_ASCII0x00000000|ENC_NA0x00000000);
1441
1442 tree_title = wmem_strdup_printf(pinfo->pool, "%s (type: %s)", tree_name, key_type);
1443 tree = proto_tree_add_subtree(parent_tree, tvb, last_offset, key_len + 4, ett_idx, NULL((void*)0),
1444 tree_title);
1445
1446 ti = proto_tree_add_uint(tree, hf_ssh_hostkey_length, tvb, last_offset, 4, key_len);
1447
1448 // server host key (K_S / Q)
1449 uint8_t *data = (uint8_t *)tvb_memdup(pinfo->pool, tvb, last_offset + 4, key_len);
1450 if (global_data) {
1451 // Reset array while REKEY: sanitize server host key blob
1452 global_data->kex_server_host_key_blob = wmem_array_new(wmem_file_scope(), 1);
1453 ssh_hash_buffer_put_string(global_data->kex_server_host_key_blob, data, key_len);
1454 }
1455
1456 last_offset += 4;
1457 proto_tree_add_uint(tree, hf_ssh_hostkey_type_length, tvb, last_offset, 4, type_len);
1458 proto_tree_add_string(tree, hf_ssh_hostkey_type, tvb, offset, type_len, key_type);
1459 offset += type_len;
1460
1461 if (0 == strcmp(key_type, "ssh-rsa")) {
1462 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_hostkey_rsa_e);
1463 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_hostkey_rsa_n);
1464 } else if (0 == strcmp(key_type, "ssh-dss")) {
1465 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_hostkey_dsa_p);
1466 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_hostkey_dsa_q);
1467 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_hostkey_dsa_g);
1468 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_hostkey_dsa_y);
1469 } else if (g_str_has_prefix(key_type, "ecdsa-sha2-")(__builtin_constant_p ("ecdsa-sha2-")? __extension__ ({ const
char * const __str = (key_type); const char * const __prefix
= ("ecdsa-sha2-"); gboolean __result = (0); if (__str == ((void
*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix)
(__str, __prefix); else { const size_t __str_len = strlen ((
(__str) + !(__str))); const size_t __prefix_len = strlen (((__prefix
) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (key_type, "ecdsa-sha2-"
) )
) {
1470 offset += ssh_tree_add_string(tvb, offset, tree,
1471 hf_ssh_hostkey_ecdsa_curve_id, hf_ssh_hostkey_ecdsa_curve_id_length);
1472 offset += ssh_tree_add_string(tvb, offset, tree,
1473 hf_ssh_hostkey_ecdsa_q, hf_ssh_hostkey_ecdsa_q_length);
1474 } else if (g_str_has_prefix(key_type, "ssh-ed")(__builtin_constant_p ("ssh-ed")? __extension__ ({ const char
* const __str = (key_type); const char * const __prefix = ("ssh-ed"
); gboolean __result = (0); if (__str == ((void*)0) || __prefix
== ((void*)0)) __result = (g_str_has_prefix) (__str, __prefix
); else { const size_t __str_len = strlen (((__str) + !(__str
))); const size_t __prefix_len = strlen (((__prefix) + !(__prefix
))); if (__str_len >= __prefix_len) __result = memcmp (((__str
) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len) == 0
; } __result; }) : (g_str_has_prefix) (key_type, "ssh-ed") )
) {
1475 offset += ssh_tree_add_string(tvb, offset, tree,
1476 hf_ssh_hostkey_eddsa_key, hf_ssh_hostkey_eddsa_key_length);
1477 } else {
1478 remaining_len = key_len - (type_len + 4);
1479 proto_tree_add_item(tree, hf_ssh_hostkey_data, tvb, offset, remaining_len, ENC_NA0x00000000);
1480 offset += remaining_len;
1481 }
1482
1483 if (last_offset + (int)key_len != offset) {
1484 expert_add_info_format(pinfo, ti, &ei_ssh_packet_decode, "Decoded %d bytes, but hostkey length is %d bytes", offset - last_offset, key_len);
1485 }
1486 return 4+key_len;
1487}
1488
1489static unsigned
1490ssh_tree_add_hostsignature(tvbuff_t *tvb, packet_info *pinfo, int offset, proto_tree *parent_tree,
1491 const char *tree_name, int ett_idx,
1492 struct ssh_flow_data *global_data)
1493{
1494 (void)global_data;
1495 proto_tree *tree = NULL((void*)0);
1496 proto_item* ti = NULL((void*)0);
1497 int last_offset;
1498 int offset0 = offset;
1499 unsigned sig_len, type_len, data_len;
1500 const char* sig_type;
1501 char *tree_title;
1502
1503 last_offset = offset;
1504
1505 sig_len = tvb_get_ntohl(tvb, offset);
1506 offset += 4;
1507
1508 /* Read the signature type before creating the tree so we can append it as info. */
1509 type_len = tvb_get_ntohl(tvb, offset);
1510 offset += 4;
1511 sig_type = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset, type_len, ENC_ASCII0x00000000|ENC_NA0x00000000);
1512
1513 tree_title = wmem_strdup_printf(pinfo->pool, "%s (type: %s)", tree_name, sig_type);
1514 tree = proto_tree_add_subtree(parent_tree, tvb, last_offset, sig_len + 4, ett_idx, NULL((void*)0),
1515 tree_title);
1516
1517 ti = proto_tree_add_uint(tree, hf_ssh_hostsig_length, tvb, last_offset, 4, sig_len);
1518
1519 last_offset += 4;
1520 proto_tree_add_uint(tree, hf_ssh_hostsig_type_length, tvb, last_offset, 4, type_len);
1521 proto_tree_add_string(tree, hf_ssh_hostsig_type, tvb, offset, type_len, sig_type);
1522 offset += type_len;
1523
1524 if (0 == strcmp(sig_type, "ssh-rsa")) {
1525 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_hostsig_rsa);
1526 } else if (0 == strcmp(sig_type, "ssh-dss")) {
1527 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_hostsig_dsa);
1528// } else if (g_str_has_prefix(sig_type, "ecdsa-sha2-")) {
1529// offset += ssh_tree_add_string(tvb, offset, tree,
1530// hf_ssh_hostkey_ecdsa_curve_id, hf_ssh_hostkey_ecdsa_curve_id_length);
1531// ssh_tree_add_string(tvb, offset, tree,
1532// hf_ssh_hostkey_ecdsa_q, hf_ssh_hostkey_ecdsa_q_length);
1533// } else if (g_str_has_prefix(sig_type, "ssh-ed")) {
1534// ssh_tree_add_string(tvb, offset, tree,
1535// hf_ssh_hostkey_eddsa_key, hf_ssh_hostkey_eddsa_key_length);
1536 } else {
1537 proto_tree_add_item_ret_uint(tree, hf_ssh_hostsig_data_length, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &data_len);
1538 offset += 4;
1539 proto_tree_add_item(tree, hf_ssh_hostsig_data, tvb, offset, data_len, ENC_NA0x00000000);
1540 offset += data_len;
1541 }
1542
1543 if(offset-offset0!=(int)(4+sig_len)){
1544 expert_add_info_format(pinfo, ti, &ei_ssh_packet_decode, "Decoded %d bytes, but packet length is %d bytes", offset-offset0, sig_len);
1545 }
1546
1547 return 4+sig_len;
1548}
1549
1550static int
1551ssh_dissect_key_exchange(tvbuff_t *tvb, packet_info *pinfo,
1552 struct ssh_flow_data *global_data,
1553 int offset, proto_tree *tree, int is_response,
1554 bool_Bool *need_desegmentation)
1555{
1556 unsigned plen, len;
1557 uint8_t padding_length;
1558 unsigned remain_length;
1559 int last_offset = offset;
1560 unsigned msg_code;
1561
1562 proto_item *ti;
1563 proto_item *key_ex_tree = NULL((void*)0);
1564 const char *key_ex_title = "Key Exchange";
1565
1566 struct ssh_peer_data *peer_data = &global_data->peer_data[is_response];
1567
1568 if (PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
1569 ws_debug("SSH: SECOND PASS dissecting keys -for Wireshark UI- frame %u", pinfo->num)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 1569, __func__, "SSH: SECOND PASS dissecting keys -for Wireshark UI- frame %u"
, pinfo->num); } } while (0)
;
1570 }
1571 /* This is after the identification string (Protocol Version Exchange)
1572 * but before the first key exchange has completed, so we expect the SSH
1573 * packets to be unencrypted, and to contain KEX related messages.
1574 *
1575 * XXX - Without the "strict kex" extension, other messages are allowed;
1576 * most don't make sense (SSH_MSG_IGNORE and SSH_MSG_DEBUG might), but we
1577 * could dissect them and add them to the tree.
1578 *
1579 * XXX - Could we combine this with ssh_dissect_decrypted_packet, with a
1580 * flag to indicate whether we're before the initial key exchange?
1581 */
1582
1583 /*
1584 * We use "tvb_ensure_captured_length_remaining()" to make sure there
1585 * actually *is* data remaining.
1586 *
1587 * This means we're guaranteed that "remain_length" is positive.
1588 */
1589 remain_length = tvb_ensure_captured_length_remaining(tvb, offset);
1590 /*
1591 * Can we do reassembly?
1592 */
1593 if (ssh_desegment && pinfo->can_desegment) {
1594 /*
1595 * Yes - would an SSH header starting at this offset
1596 * be split across segment boundaries?
1597 */
1598 if (remain_length < 4) {
1599 /*
1600 * Yes. Tell the TCP dissector where the data for
1601 * this message starts in the data it handed us and
1602 * that we need "some more data." Don't tell it
1603 * exactly how many bytes we need because if/when we
1604 * ask for even more (after the header) that will
1605 * break reassembly.
1606 */
1607 pinfo->desegment_offset = offset;
1608 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT0x0fffffff;
1609 *need_desegmentation = true1;
1610 return offset;
1611 }
1612 }
1613 plen = tvb_get_ntohl(tvb, offset) ;
1614
1615 if (ssh_desegment && pinfo->can_desegment) {
1616 if (plen +4 > remain_length) {
1617 pinfo->desegment_offset = offset;
1618 pinfo->desegment_len = plen+4 - remain_length;
1619 *need_desegmentation = true1;
1620 return offset;
1621 }
1622 }
1623 /*
1624 * Need to check plen > 0x80000000 here
1625 */
1626
1627 ti = proto_tree_add_uint(tree, hf_ssh_packet_length, tvb,
1628 offset, 4, plen);
1629 if (plen >= SSH_MAX_PACKET_LEN32768) {
1630 expert_add_info_format(pinfo, ti, &ei_ssh_packet_length, "Overly large number %d", plen);
1631 plen = remain_length-4;
1632
1633 /* XXX - Mark as Continuation Data and return without incrementing?
1634 * Or do so *before* using this length to desegment? */
1635 }
1636 offset+=4;
1637
1638 ssh_packet_info_t *packet = ssh_get_packet_info(pinfo, is_response);
1639
1640 int record_id = tvb_raw_offset(tvb)+offset;
1641 ssh_message_info_t *message;
1642 message = ssh_get_message(pinfo, record_id);
1643 if (!message) {
1644 message = wmem_new0(wmem_file_scope(), ssh_message_info_t)((ssh_message_info_t*)wmem_alloc0((wmem_file_scope()), sizeof
(ssh_message_info_t)))
;
1645 message->sequence_number = peer_data->sequence_number++;
1646 message->id = record_id;
1647 /* No data, and no MAC, as is this is before encryption starts. */
1648 message->next = NULL((void*)0);
1649 ssh_debug_printf("%s->sequence_number++ > %d\n", is_response?"server":"client", peer_data->sequence_number);
1650
1651 ssh_message_info_t **pmessage = &packet->messages;
1652 while(*pmessage){
1653 pmessage = &(*pmessage)->next;
1654 }
1655 *pmessage = message;
1656 }
1657
1658 /* padding length */
1659 padding_length = tvb_get_uint8(tvb, offset);
1660 proto_tree_add_uint(tree, hf_ssh_padding_length, tvb, offset, 1, padding_length);
1661 offset += 1;
1662
1663 if (global_data->kex)
1664 key_ex_title = wmem_strdup_printf(pinfo->pool, "%s (method:%s)", key_ex_title, global_data->kex);
1665 key_ex_tree = proto_tree_add_subtree(tree, tvb, offset, plen-1, ett_key_exchange, NULL((void*)0), key_ex_title);
1666
1667 /* msg_code */
1668 msg_code = tvb_get_uint8(tvb, offset);
1669
1670 if (msg_code >= 30 && msg_code < 40) {
1671 offset = global_data->kex_specific_dissector(msg_code, tvb, pinfo,
1672 offset, key_ex_tree, global_data);
1673 } else {
1674 proto_tree_add_item(key_ex_tree, hf_ssh2_msg_code, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
1675 offset += 1;
1676
1677 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0),
1678 val_to_str(pinfo->pool, msg_code, ssh2_msg_vals, "Unknown (%u)"));
1679
1680 /* 16 bytes cookie */
1681 switch(msg_code)
1682 {
1683 case SSH_MSG_KEXINIT20:
1684 offset = ssh_dissect_key_init(tvb, pinfo, offset, key_ex_tree, is_response, global_data);
1685 if ((peer_data->frame_key_start == 0) && (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited))) {
1686 peer_data->frame_key_start = pinfo->num;
1687 }
1688 break;
1689 case SSH_MSG_NEWKEYS21:
1690 if (peer_data->frame_key_end == 0) {
1691 peer_data->frame_key_end = pinfo->num;
1692 peer_data->frame_key_end_offset = offset;
1693
1694 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
1695 /* "After sending or receiving a SSH2_MSG_NEWKEYS message,
1696 * reset the packet sequence number to zero. This behaviour
1697 * persists for the duration of the connection (i.e. not
1698 * just the first SSH2_MSG_NEWKEYS) */
1699 if (global_data->ext_kex_strict) {
1700 peer_data->sequence_number = 0;
1701 ssh_debug_printf("%s->sequence_number reset to 0 (Strict KEX)\n", is_response?"server":"client");
1702 }
1703 }
1704
1705 // the client sent SSH_MSG_NEWKEYS
1706 if (!is_response) {
1707 ssh_debug_printf("Activating new keys for CLIENT => SERVER\n");
1708 ssh_decryption_setup_cipher(&global_data->peer_data[CLIENT_PEER_DATA0], &global_data->new_keys[0], &global_data->new_keys[2]);
1709 ssh_decryption_setup_mac(&global_data->peer_data[CLIENT_PEER_DATA0], &global_data->new_keys[4]);
1710 }else{
1711 ssh_debug_printf("Activating new keys for SERVER => CLIENT\n");
1712 ssh_decryption_setup_cipher(&global_data->peer_data[SERVER_PEER_DATA1], &global_data->new_keys[1], &global_data->new_keys[3]);
1713 ssh_decryption_setup_mac(&global_data->peer_data[SERVER_PEER_DATA1], &global_data->new_keys[5]);
1714 }
1715 }
1716 break;
1717 }
1718 }
1719
1720 len = plen+4-padding_length-(offset-last_offset);
1721 if (len > 0) {
1722 proto_tree_add_item(key_ex_tree, hf_ssh_payload, tvb, offset, len, ENC_NA0x00000000);
1723 }
1724 offset += len;
1725
1726 /* padding */
1727 proto_tree_add_item(tree, hf_ssh_padding_string, tvb, offset, padding_length, ENC_NA0x00000000);
1728 offset+= padding_length;
1729 ti = proto_tree_add_uint(tree, hf_ssh_seq_num, tvb, offset, 0, message->sequence_number);
1730 proto_item_set_generated(ti);
1731
1732 return offset;
1733}
1734
1735static int ssh_dissect_kex_dh(uint8_t msg_code, tvbuff_t *tvb,
1736 packet_info *pinfo, int offset, proto_tree *tree,
1737 struct ssh_flow_data *global_data)
1738{
1739 proto_tree_add_item(tree, hf_ssh2_kex_dh_msg_code, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
1740 offset += 1;
1741
1742 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0),
1743 val_to_str(pinfo->pool, msg_code, ssh2_kex_dh_msg_vals, "Unknown (%u)"));
1744
1745 switch (msg_code) {
1746 case SSH_MSG_KEXDH_INIT30:
1747 // e (client ephemeral key public part)
1748 if (!ssh_read_e(tvb, offset, global_data)) {
1749 proto_tree_add_expert_format(tree, pinfo, &ei_ssh_invalid_keylen, tvb, offset, 2,
1750 "Invalid key length: %u", tvb_get_ntohl(tvb, offset));
1751 }
1752
1753 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_dh_e);
1754 break;
1755
1756 case SSH_MSG_KEXDH_REPLY31:
1757 offset += ssh_tree_add_hostkey(tvb, pinfo, offset, tree, "KEX host key",
1758 ett_key_exchange_host_key, global_data);
1759
1760 // f (server ephemeral key public part), K_S (host key)
1761 if (!ssh_read_f(tvb, offset, global_data)) {
1762 proto_tree_add_expert_format(tree, pinfo, &ei_ssh_invalid_keylen, tvb, offset, 2,
1763 "Invalid key length: %u", tvb_get_ntohl(tvb, offset));
1764 }
1765 ssh_choose_enc_mac(global_data);
1766 ssh_keylog_hash_write_secret(global_data, pinfo->pool);
1767
1768 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_dh_f);
1769 offset += ssh_tree_add_hostsignature(tvb, pinfo, offset, tree, "KEX host signature",
1770 ett_key_exchange_host_sig, global_data);
1771 break;
1772 }
1773
1774 return offset;
1775}
1776
1777static int ssh_dissect_kex_dh_gex(uint8_t msg_code, tvbuff_t *tvb,
1778 packet_info *pinfo, int offset, proto_tree *tree,
1779 struct ssh_flow_data *global_data)
1780{
1781 proto_tree_add_item(tree, hf_ssh2_kex_dh_gex_msg_code, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
1782 offset += 1;
1783
1784 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0),
1785 val_to_str(pinfo->pool, msg_code, ssh2_kex_dh_gex_msg_vals, "Unknown (%u)"));
1786
1787 switch (msg_code) {
1788 case SSH_MSG_KEX_DH_GEX_REQUEST_OLD30:
1789 proto_tree_add_item(tree, hf_ssh_dh_gex_nbits, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
1790 offset += 4;
1791 break;
1792
1793 case SSH_MSG_KEX_DH_GEX_GROUP31:
1794 // p (Group modulo)
1795 global_data->kex_gex_p = ssh_read_mpint(tvb, offset);
1796 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_dh_gex_p);
1797 // g (Group generator)
1798 global_data->kex_gex_g = ssh_read_mpint(tvb, offset);
1799 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_dh_gex_g);
1800 break;
1801
1802 case SSH_MSG_KEX_DH_GEX_INIT32:
1803 // e (Client public key)
1804 if (!ssh_read_e(tvb, offset, global_data)) {
1805 proto_tree_add_expert_format(tree, pinfo, &ei_ssh_invalid_keylen, tvb, offset, 2,
1806 "Invalid key length: %u", tvb_get_ntohl(tvb, offset));
1807 }
1808 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_dh_e);
1809 break;
1810
1811 case SSH_MSG_KEX_DH_GEX_REPLY33:
1812 offset += ssh_tree_add_hostkey(tvb, pinfo, offset, tree, "KEX host key",
1813 ett_key_exchange_host_key, global_data);
1814 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
1815 ssh_read_f(tvb, offset, global_data);
1816 // f (server ephemeral key public part), K_S (host key)
1817 ssh_choose_enc_mac(global_data);
1818 ssh_keylog_hash_write_secret(global_data, pinfo->pool);
1819 }
1820 offset += ssh_tree_add_mpint(tvb, offset, tree, hf_ssh_dh_f);
1821 offset += ssh_tree_add_hostsignature(tvb, pinfo, offset, tree, "KEX host signature",
1822 ett_key_exchange_host_sig, global_data);
1823 break;
1824
1825 case SSH_MSG_KEX_DH_GEX_REQUEST34:{
1826
1827 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
1828 ssh_hash_buffer_put_uint32(global_data->kex_gex_bits_min, tvb_get_ntohl(tvb, offset));
1829 }
1830 proto_tree_add_item(tree, hf_ssh_dh_gex_min, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
1831 offset += 4;
1832 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
1833 ssh_hash_buffer_put_uint32(global_data->kex_gex_bits_req, tvb_get_ntohl(tvb, offset));
1834 }
1835 proto_tree_add_item(tree, hf_ssh_dh_gex_nbits, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
1836 offset += 4;
1837 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
1838 ssh_hash_buffer_put_uint32(global_data->kex_gex_bits_max, tvb_get_ntohl(tvb, offset));
1839 }
1840 proto_tree_add_item(tree, hf_ssh_dh_gex_max, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
1841 offset += 4;
1842 break;
1843 }
1844 }
1845
1846 return offset;
1847}
1848
1849static int
1850ssh_dissect_kex_ecdh(uint8_t msg_code, tvbuff_t *tvb,
1851 packet_info *pinfo, int offset, proto_tree *tree,
1852 struct ssh_flow_data *global_data)
1853{
1854 proto_tree_add_item(tree, hf_ssh2_kex_ecdh_msg_code, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
1855 offset += 1;
1856
1857 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0),
1858 val_to_str(pinfo->pool, msg_code, ssh2_kex_ecdh_msg_vals, "Unknown (%u)"));
1859
1860 switch (msg_code) {
1861 case SSH_MSG_KEX_ECDH_INIT30:
1862 if (!ssh_read_e(tvb, offset, global_data)) {
1863 proto_tree_add_expert_format(tree, pinfo, &ei_ssh_invalid_keylen, tvb, offset, 2,
1864 "Invalid key length: %u", tvb_get_ntohl(tvb, offset));
1865 }
1866
1867 offset += ssh_tree_add_string(tvb, offset, tree, hf_ssh_ecdh_q_c, hf_ssh_ecdh_q_c_length);
1868 break;
1869
1870 case SSH_MSG_KEX_ECDH_REPLY31:
1871 offset += ssh_tree_add_hostkey(tvb, pinfo, offset, tree, "KEX host key",
1872 ett_key_exchange_host_key, global_data);
1873
1874 if (!ssh_read_f(tvb, offset, global_data)){
1875 proto_tree_add_expert_format(tree, pinfo, &ei_ssh_invalid_keylen, tvb, offset, 2,
1876 "Invalid key length: %u", tvb_get_ntohl(tvb, offset));
1877 }
1878
1879 ssh_choose_enc_mac(global_data);
1880 ssh_keylog_hash_write_secret(global_data, pinfo->pool);
1881
1882 offset += ssh_tree_add_string(tvb, offset, tree, hf_ssh_ecdh_q_s, hf_ssh_ecdh_q_s_length);
1883 offset += ssh_tree_add_hostsignature(tvb, pinfo, offset, tree, "KEX host signature",
1884 ett_key_exchange_host_sig, global_data);
1885 break;
1886 }
1887
1888 return offset;
1889}
1890
1891 /*
1892 * === Hybrid KEX Dissection Strategy for Post-Quantum algorithms ===
1893 *
1894 * This 3 functions:
1895 *
1896 * - ssh_dissect_kex_pq_hybrid()
1897 * - ssh_read_e_pq()
1898 * - ssh_read_f_pq()
1899 *
1900 * handles the dissection of server key exchange payloads for the
1901 * post-quantum hybrid key exchange method:
1902 * - sntrup761x25519-sha512
1903 * - mlkem768x25519-sha256
1904 * - mlkem768nistp256-sha256
1905 * - mlkem1024nistp384-sha384
1906 *
1907 * /!\ Rationale for implementation approach:
1908 *
1909 * SSH encodes the server's ephemeral key (`Q_S`) as a single SSH `string`
1910 * which contains both the post-quantum KEM ciphertext (from sntrup761 / mlkem768
1911 * / mlkem1024) and the traditional (Curve25519 / nistp256 / nistp384) public key.
1912 * Therefore, we parse one string
1913 *
1914 * sntrup761x25519:
1915 * - PQ client keyshare: 1158 bytes
1916 * - PQ server ciphertext: 1039 bytes
1917 * - Curve25519 pubkey: 32 bytes
1918 *
1919 * mlkem768x25519:
1920 * - PQ client keyshare: 1184 bytes
1921 * - PQ server ciphertext: 1088 bytes
1922 * - Curve25519 pubkey: 32 bytes
1923 *
1924 * mlkem768nistp256:
1925 * - PQ client keyshare: 1184 bytes
1926 * - PQ server ciphertext: 1088 bytes
1927 * - nistp256 pubkey: 65 bytes
1928 *
1929 * mlkem1024nistp384:
1930 * - PQ client keyshare: 1568 bytes
1931 * - PQ server ciphertext: 1568 bytes
1932 * - nistp384 pubkey: 97 bytes
1933 *
1934 * OpenSSH uses `[email protected]` as an (old) alias for `sntrup761x25519-sha512`
1935 *
1936 * This matches how OpenSSH serializes the hybrid key material, and allows Wireshark
1937 * to compute the correct key exchange hash and derive session keys accurately.
1938 *
1939 * /!\ This design is necessary for live decryption support in Wireshark and TShark.
1940 *
1941 * References:
1942 * - RFC 4253: The SSH Transport Layer Protocol
1943 * - Section 6: string encoding format
1944 * - Section 7.2: Key derivation
1945 * - RFC 8731: Secure Shell (SSH) Key Exchange Method using Curve25519
1946 * - Internet-Draft on sntrup761x25519-sha512
1947 * - https://datatracker.ietf.org/doc/draft-ietf-sshm-ntruprime-ssh/
1948 * - Internet-Draft on mlkem768x25519-sha256
1949 * - https://datatracker.ietf.org/doc/draft-ietf-sshm-mlkem-hybrid-kex/
1950 * - OpenSSH Hybrid KEM Implementation (sntrup761x25519-sha512 / mlkem768x25519-sha256)
1951 * - https://github.com/openssh/openssh-portable/blob/master/kexc25519.c
1952 * - https://github.com/openssh/openssh-portable/blob/master/kexsntrup761x25519.c
1953 * - https://github.com/openssh/openssh-portable/blob/master/kexmlkem768x25519.c
1954 * - AsyncSSH Hybrid KEM Implementation (sntrup761x25519-sha512 / mlkem768x25519-sha256 / mlkem768nistp256-sha256 / mlkem1024nistp384-sha384)
1955 * - https://github.com/ronf/asyncssh/blob/develop/asyncssh/kex_dh.py
1956 *
1957 */
1958
1959static int
1960ssh_dissect_kex_pq_hybrid(uint8_t msg_code, tvbuff_t *tvb,
1961 packet_info *pinfo, int offset, proto_tree *tree,
1962 struct ssh_flow_data *global_data)
1963{
1964 // SSH PACKET STRUCTURE RFC4253 (e.g. packet of 1228 bytes payload)
1965 // [00 00 04 cc] → ssh payload blob length field in tcp packet (e.g. 1228=0x04cc): 4 bytes
1966 // [1228 bytes of SSH PAYLOAD BLOB] → ssh payload blob field: 1228 bytes
1967
1968 // Add the message code byte (first field in packet) to the GUI tree.
1969 proto_tree_add_item(tree, hf_ssh2_kex_hybrid_msg_code, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
1970 offset += 1; // Move offset past the msg_code byte.
1971
1972 // Add a descriptive string to Wireshark's "Info" column.
1973 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0),
1974 val_to_str(pinfo->pool, msg_code, ssh2_kex_hybrid_msg_vals, "Unknown (%u)"));
1975
1976 const char *kex_name = global_data->kex;
1977
1978 if (msg_code == SSH_MSG_KEX_HYBRID_INIT30) {
1
Assuming 'msg_code' is not equal to SSH_MSG_KEX_HYBRID_INIT
2
Taking false branch
1979 // Print warning when PQ hybrid KEM is detected in KEX
1980 // This implementation currently rely on SHARED_SECRET only and do not work with PRIVATE_KEY
1981 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
1982 ws_warning("POST-QUANTUM KEX_HYBRID detected: KEX = %s", kex_name)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_WARNING, "epan/dissectors/packet-ssh.c"
, 1982, __func__, "POST-QUANTUM KEX_HYBRID detected: KEX = %s"
, kex_name); } } while (0)
;
1983 ws_warning("SHARED_SECRET decryption is supported - PRIVATE_KEY decryption is not supported")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_WARNING, "epan/dissectors/packet-ssh.c"
, 1983, __func__, "SHARED_SECRET decryption is supported - PRIVATE_KEY decryption is not supported"
); } } while (0)
;
1984 }
1985 // Print noisy debug info
1986 ws_noisy(">>> HYBRID KEM: msg_code = %u, offset = %d, kex = %s", msg_code, offset, kex_name)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 1986, __func__, ">>> HYBRID KEM: msg_code = %u, offset = %d, kex = %s"
, msg_code, offset, kex_name); } } while (0)
;
1987 }
1988
1989 switch (msg_code) {
3
Control jumps to 'case 31:' at line 2076
1990
1991 // Client Key Exchange INIT
1992 case SSH_MSG_KEX_HYBRID_INIT30: {
1993
1994 // SNTRUP761X25519: RFC4253 SSH "string" (binary-encoded structure)
1995 // [00 00 04 a6] → length = 1190 (0x04a6)
1996 // [1158 bytes PQ blob] → sntrup761 encapsulated client key
1997 // [32 bytes of X25519 pubkey] → ephemeral X25519 public key
1998
1999 // MLKEM768X25519: RFC4253 SSH "string" (binary-encoded structure)
2000 // [00 00 04 c0] → length = 1216 (0x04c0)
2001 // [1184 bytes PQ blob] → mlkem768 encapsulated client key
2002 // [32 bytes of X25519 pubkey] → ephemeral X25519 public key
2003
2004 // MLKEM768NISTP256: RFC4253 SSH "string" (binary-encoded structure)
2005 // [00 00 04 e1] → length = 1249 (0x04e1)
2006 // [1184 bytes PQ blob] → mlkem768 encapsulated client key
2007 // [65 bytes of nistp256 pubkey] → ephemeral nistp256 public key
2008
2009 // MLKEM1024NISTP384: RFC4253 SSH "string" (binary-encoded structure)
2010 // [00 00 06 81] → length = 1665 (0x0681)
2011 // [1568 bytes PQ blob] → mlkem1024 encapsulated client key
2012 // [97 bytes of nistp384 pubkey] → ephemeral nistp384 public key
2013
2014 ws_debug("CLIENT INIT follow offset pointer - absolute offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2014, __func__, "CLIENT INIT follow offset pointer - absolute offset: %d"
, offset); } } while (0)
; // debug trace offset
2015 int new_offset_client = ssh_read_e_pq(tvb, offset, global_data);
2016 if (new_offset_client < 0) {
2017 uint32_t bad_len = tvb_get_ntohl(tvb, offset);
2018 proto_tree_add_expert_format(tree, pinfo, &ei_ssh_invalid_keylen, tvb, offset, 4,
2019 "Invalid PQ client key length: %u", bad_len);
2020 ws_debug("ExpertInfo: Invalid PQ client key length at offset %d: %u", offset, bad_len)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2020, __func__, "ExpertInfo: Invalid PQ client key length at offset %d: %u"
, offset, bad_len); } } while (0)
;
2021
2022 return offset + 4;
2023 }
2024
2025 // PQ-hybrid KEMs cannot use ssh_add_tree_string => manual dissection
2026 // Get PQ blob size
2027 proto_tree *pq_tree = NULL((void*)0);
2028 uint32_t hybrid_len;
2029
2030 // Add a subtree for dissecting PQ blob
2031 proto_tree_add_item_ret_uint(tree, hf_ssh_hybrid_blob_client_len, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &hybrid_len); // add blob length
2032 ws_debug("CLIENT INIT PQ blob length - pq_len: %d", hybrid_len)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2032, __func__, "CLIENT INIT PQ blob length - pq_len: %d", hybrid_len
); } } while (0)
; // debug trace pq_len
2033 offset += 4; // shift length field
2034 pq_tree = proto_tree_add_subtree(tree, tvb, offset, hybrid_len, ett_ssh_pqhybrid_client, NULL((void*)0), "Hybrid Key Exchange Blob Client");
2035 ws_debug("CLIENT INIT add PQ Hybrid subtree - offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2035, __func__, "CLIENT INIT add PQ Hybrid subtree - offset: %d"
, offset); } } while (0)
; // debug trace offset
2036
2037 // Make a new tvb for just the PQ hybrid blob string contents
2038 tvbuff_t *string_tvb = tvb_new_subset_length(tvb, offset, hybrid_len);
2039
2040 uint32_t pq_len;
2041 uint32_t t_len;
2042 if (g_str_has_prefix(kex_name, "sntrup761x25519-sha512")(__builtin_constant_p ("sntrup761x25519-sha512")? __extension__
({ const char * const __str = (kex_name); const char * const
__prefix = ("sntrup761x25519-sha512"); gboolean __result = (
0); if (__str == ((void*)0) || __prefix == ((void*)0)) __result
= (g_str_has_prefix) (__str, __prefix); else { const size_t __str_len
= strlen (((__str) + !(__str))); const size_t __prefix_len =
strlen (((__prefix) + !(__prefix))); if (__str_len >= __prefix_len
) __result = memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix
)), __prefix_len) == 0; } __result; }) : (g_str_has_prefix) (
kex_name, "sntrup761x25519-sha512") )
) {
2043 pq_len = 1158;
2044 t_len = 32;
2045 } else if (strcmp(kex_name, "mlkem768x25519-sha256") == 0) {
2046 pq_len = 1184;
2047 t_len = 32;
2048 } else if (strcmp(kex_name, "mlkem768nistp256-sha256") == 0) {
2049 pq_len = 1184;
2050 t_len = 65;
2051 } else if (strcmp(kex_name, "mlkem1024nistp384-sha384") == 0) {
2052 pq_len = 1568;
2053 t_len = 97;
2054 } else {
2055 DISSECTOR_ASSERT_NOT_REACHED()(proto_report_dissector_bug("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\""
, "epan/dissectors/packet-ssh.c", 2055))
;
2056 break;
2057 }
2058
2059 if (pq_len + t_len != hybrid_len) {
2060 proto_tree_add_expert_format(tree, pinfo, &ei_ssh_invalid_keylen, tvb, offset, 4,
2061 "Invalid PQ hybrid client key length for %s: %u does not match %u + %u",
2062 kex_name, hybrid_len, pq_len, t_len);
2063 } else {
2064 // Now dissect string inside the blob and add PQ server response and ECDH Q_S to GUI subtree
2065 proto_tree_add_item(pq_tree, hf_ssh_pq_kem_client, string_tvb, 0, pq_len, ENC_NA0x00000000);
2066 proto_tree_add_item(pq_tree, hf_ssh_ecdh_q_c, string_tvb, pq_len, t_len, ENC_NA0x00000000);
2067 }
2068
2069 // retrieve offset from read_f_pq() to shift blob length and consume packet
2070 offset = new_offset_client;
2071 ws_debug("CLIENT INIT shift PQ blob - offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2071, __func__, "CLIENT INIT shift PQ blob - offset: %d", offset
); } } while (0)
; // debug trace offset
2072 break;
2073 }
2074
2075 // Server Reply Message
2076 case SSH_MSG_KEX_HYBRID_REPLY31: {
2077
2078 // SNTRUP761X25519: RFC4253 SSH "string" (binary-encoded structure)
2079 // [00 00 00 33] → host key structure length = 51
2080 // [00 00 00 0b] → host key alg length = 11
2081 // [73 73 68 2d 65 64 32 35 35 31 39] → "ssh-ed25519"
2082 // [00 00 00 20] → host key length = 32
2083 // [32 bytes of public key] → public key
2084 // [00 00 04 2f] → PQ blob length = 1071 (0x042f)
2085 // [1071 bytes PQ blob] → PQ blob (1039 sntrup761 + 32 x25519)
2086 // [00 00 00 53] → signature structure length = 83
2087 // [00 00 00 0b] → signature alg length
2088 // [73 73 68 2d 65 64 32 35 35 31 39] → "ssh-ed25519"
2089 // [00 00 00 40] → signature length
2090 // [40 bytes signature] → server signature
2091
2092 // MLKEM768X25519: RFC4253 SSH "string" (binary-encoded structure)
2093 // [00 00 00 33] → host key structure length = 51
2094 // [00 00 00 0b] → host key alg length = 11
2095 // [73 73 68 2d 65 64 32 35 35 31 39] → "ssh-ed25519"
2096 // [00 00 00 20] → host key length = 32
2097 // [32 bytes of public key] → public key
2098 // [00 00 04 60] → PQ blob length = 1120 (0x0460)
2099 // [1120 bytes PQ blob] → PQ blob (1088 mlkem768 + 32 x25519)
2100 // [00 00 00 53] → signature structure length = 83
2101 // [00 00 00 0b] → signature alg length
2102 // [73 73 68 2d 65 64 32 35 35 31 39] → "ssh-ed25519"
2103 // [00 00 00 40] → signature length
2104 // [40 bytes signature] → server signature
2105
2106 // MLKEM768NISTP256: RFC4253 SSH "string" (binary-encoded structure)
2107 // [00 00 00 33] → host key structure length = 51
2108 // [00 00 00 0b] → host key alg length = 11
2109 // [73 73 68 2d 65 64 32 35 35 31 39] → "ssh-ed25519"
2110 // [00 00 00 20] → host key length = 32
2111 // [32 bytes of public key] → public key
2112 // [00 00 04 81] → PQ blob length = 1153 (0x0481)
2113 // [1153 bytes PQ blob] → PQ blob (1088 mlkem768 + 65 nistp256)
2114 // [00 00 00 53] → signature structure length = 83
2115 // [00 00 00 0b] → signature alg length
2116 // [73 73 68 2d 65 64 32 35 35 31 39] → "ssh-ed25519"
2117 // [00 00 00 40] → signature length
2118 // [40 bytes signature] → server signature
2119
2120 // MLKEM1024NISTP384: RFC4253 SSH "string" (binary-encoded structure)
2121 // [00 00 00 33] → host key structure length = 51
2122 // [00 00 00 0b] → host key alg length = 11
2123 // [73 73 68 2d 65 64 32 35 35 31 39] → "ssh-ed25519"
2124 // [00 00 00 20] → host key length = 32
2125 // [32 bytes of public key] → public key
2126 // [00 00 06 81] → PQ blob length = 1665 (0x0681)
2127 // [1665 bytes PQ blob] → PQ blob (1568 mlkem1024 + 97 nistp384)
2128 // [00 00 00 53] → signature structure length = 83
2129 // [00 00 00 0b] → signature alg length
2130 // [73 73 68 2d 65 64 32 35 35 31 39] → "ssh-ed25519"
2131 // [00 00 00 40] → signature length
2132 // [40 bytes signature] → server signature
2133
2134 ws_debug("SERVER REPLY follow offset pointer - absolute offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2134, __func__, "SERVER REPLY follow offset pointer - absolute offset: %d"
, offset); } } while (0)
; // debug trace offset
4
Taking true branch
5
Loop condition is false. Exiting loop
2135
2136 // Add the host key used to sign the key exchange to the GUI tree.
2137 offset += ssh_tree_add_hostkey(tvb, pinfo, offset, tree, "KEX host key", ett_key_exchange_host_key, global_data);
2138
2139 ws_debug("SERVER REPLY add hostkey tree - offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2139, __func__, "SERVER REPLY add hostkey tree - offset: %d"
, offset); } } while (0)
; // debug trace offset
6
Taking true branch
7
Loop condition is false. Exiting loop
2140
2141 int new_offset_server = ssh_read_f_pq(tvb, offset, global_data);
2142 if (new_offset_server < 0) {
8
Assuming 'new_offset_server' is >= 0
9
Taking false branch
2143 uint32_t bad_len = tvb_get_ntohl(tvb, offset);
2144 proto_tree_add_expert_format(tree, pinfo, &ei_ssh_invalid_keylen, tvb, offset, 4,
2145 "Invalid PQ server key length: %u", bad_len);
2146 ws_debug("ExpertInfo: Invalid PQ server key length at offset %d: %u", offset, bad_len)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2146, __func__, "ExpertInfo: Invalid PQ server key length at offset %d: %u"
, offset, bad_len); } } while (0)
;
2147
2148 return offset + 4;
2149 }
2150
2151 // Select encryption and MAC based on negotiated algorithms.
2152 ssh_choose_enc_mac(global_data);
2153
2154 // Write session secrets to keylog file (if enabled).
2155 ssh_keylog_hash_write_secret(global_data, pinfo->pool);
10
Calling 'ssh_keylog_hash_write_secret'
2156
2157 // PQ-hybrid KEMs cannot use ssh_add_tree_string => manual dissection
2158 // Get PQ blob size
2159 proto_tree *pq_tree = NULL((void*)0);
2160 uint32_t hybrid_len = tvb_get_ntohl(tvb, offset);
2161 ws_debug("SERVER REPLY PQ blob length - hybrid_len: %d", hybrid_len)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2161, __func__, "SERVER REPLY PQ blob length - hybrid_len: %d"
, hybrid_len); } } while (0)
; // debug trace hybrid_len
2162
2163 // Add a subtree for dissecting PQ blob
2164 proto_tree_add_item(tree, hf_ssh_hybrid_blob_server_len, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000); // add blob length
2165 offset += 4; // shift length field
2166 pq_tree = proto_tree_add_subtree(tree, tvb, offset, hybrid_len, ett_ssh_pqhybrid_server, NULL((void*)0), "Hybrid Key Exchange Blob Server");
2167 ws_debug("SERVER REPLY add PQ Hybrid subtree - offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2167, __func__, "SERVER REPLY add PQ Hybrid subtree - offset: %d"
, offset); } } while (0)
; // debug trace offset
2168
2169 // Make a new tvb for just the PQ hybrid blob string contents
2170 tvbuff_t *string_tvb = tvb_new_subset_length(tvb, offset, hybrid_len);
2171
2172 uint32_t pq_len;
2173 uint32_t t_len;
2174 if (g_str_has_prefix(kex_name, "sntrup761x25519-sha512")(__builtin_constant_p ("sntrup761x25519-sha512")? __extension__
({ const char * const __str = (kex_name); const char * const
__prefix = ("sntrup761x25519-sha512"); gboolean __result = (
0); if (__str == ((void*)0) || __prefix == ((void*)0)) __result
= (g_str_has_prefix) (__str, __prefix); else { const size_t __str_len
= strlen (((__str) + !(__str))); const size_t __prefix_len =
strlen (((__prefix) + !(__prefix))); if (__str_len >= __prefix_len
) __result = memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix
)), __prefix_len) == 0; } __result; }) : (g_str_has_prefix) (
kex_name, "sntrup761x25519-sha512") )
) {
2175 pq_len = 1039;
2176 t_len = 32;
2177 } else if (strcmp(kex_name, "mlkem768x25519-sha256") == 0) {
2178 pq_len = 1088;
2179 t_len = 32;
2180 } else if (strcmp(kex_name, "mlkem768nistp256-sha256") == 0) {
2181 pq_len = 1088;
2182 t_len = 65;
2183 } else if (strcmp(kex_name, "mlkem1024nistp384-sha384") == 0) {
2184 pq_len = 1568;
2185 t_len = 97;
2186 } else {
2187 DISSECTOR_ASSERT_NOT_REACHED()(proto_report_dissector_bug("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\""
, "epan/dissectors/packet-ssh.c", 2187))
;
2188 break;
2189 }
2190
2191 if (pq_len + t_len != hybrid_len) {
2192 proto_tree_add_expert_format(tree, pinfo, &ei_ssh_invalid_keylen, tvb, offset, 4,
2193 "Invalid PQ hybrid server key length for %s: %u does not match %u + %u",
2194 kex_name, hybrid_len, pq_len, t_len);
2195 } else {
2196 // Now dissect string inside the blob and add PQ server response and ECDH Q_S to GUI subtree
2197 proto_tree_add_item(pq_tree, hf_ssh_pq_kem_server, string_tvb, 0, pq_len, ENC_NA0x00000000);
2198 proto_tree_add_item(pq_tree, hf_ssh_ecdh_q_s, string_tvb, pq_len, t_len, ENC_NA0x00000000);
2199 }
2200
2201 // retrieve offset from read_f_pq() to shift blob length
2202 offset = new_offset_server;
2203 ws_debug("SERVER REPLY shift PQ blob - offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2203, __func__, "SERVER REPLY shift PQ blob - offset: %d", offset
); } } while (0)
; // debug trace offset
2204
2205 // Add the host's digital signature to the GUI tree
2206 offset += ssh_tree_add_hostsignature(tvb, pinfo, offset, tree, "KEX host signature",
2207 ett_key_exchange_host_sig, global_data);
2208 ws_debug("SERVER REPLY add signature tree - offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2208, __func__, "SERVER REPLY add signature tree - offset: %d"
, offset); } } while (0)
; // debug trace offset
2209 break;
2210 }
2211 }
2212
2213 if (msg_code == SSH_MSG_KEX_HYBRID_INIT30) {
2214 ws_debug("OUT PQ HYBRID KEX - CLIENT INIT track offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2214, __func__, "OUT PQ HYBRID KEX - CLIENT INIT track offset: %d"
, offset); } } while (0)
; // debug trace offset
2215 } else if (msg_code == SSH_MSG_KEX_HYBRID_REPLY31) {
2216 ws_debug("OUT PQ HYBRID KEX - SERVER REPLY track offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2216, __func__, "OUT PQ HYBRID KEX - SERVER REPLY track offset: %d"
, offset); } } while (0)
; // debug trace offset
2217 } else {
2218 ws_debug("OUT PQ HYBRID KEX - track offset: %d", offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2218, __func__, "OUT PQ HYBRID KEX - track offset: %d", offset
); } } while (0)
; // debug trace offset
2219 }
2220
2221 return offset; // Final offset after packet is processed by ssh_dissect_kex_pq_hybrid()
2222}
2223
2224static ssh_message_info_t*
2225ssh_get_message(packet_info *pinfo, int record_id)
2226{
2227 ssh_packet_info_t *packet = (ssh_packet_info_t *)p_get_proto_data(
2228 wmem_file_scope(), pinfo, proto_ssh, 0);
2229
2230 if (!packet) {
2231 return NULL((void*)0);
2232 }
2233
2234 ssh_message_info_t *message = NULL((void*)0);
2235 for (message = packet->messages; message; message = message->next) {
2236 ws_noisy("%u:looking for message %d now %d", pinfo->num, record_id, message->id)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 2236, __func__, "%u:looking for message %d now %d", pinfo->
num, record_id, message->id); } } while (0)
;
2237 if (message->id == record_id) {
2238 return message;
2239 }
2240 }
2241
2242 return NULL((void*)0);
2243}
2244
2245static int
2246ssh_try_dissect_encrypted_packet(tvbuff_t *tvb, packet_info *pinfo,
2247 struct ssh_peer_data *peer_data, int offset, proto_tree *tree)
2248{
2249 bool_Bool can_decrypt = peer_data->cipher != NULL((void*)0) || peer_data->cipher_id == CIPHER_NULL0x00080000;
2250 ssh_message_info_t *message = NULL((void*)0);
2251
2252 if (can_decrypt) {
2253 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
2254 ssh_decrypt_packet(tvb, pinfo, peer_data, offset);
2255 if (pinfo->desegment_len) {
2256 return offset;
2257 }
2258 }
2259
2260 int record_id = tvb_raw_offset(tvb) + offset;
2261 message = ssh_get_message(pinfo, record_id);
2262
2263 if (message) {
2264 offset += ssh_dissect_decrypted_packet(tvb_new_subset_remaining(tvb, offset), pinfo, peer_data, tree, message);
2265 return offset;
2266 }
2267 }
2268
2269 return ssh_dissect_encrypted_packet(tvb, pinfo, peer_data, offset, tree);
2270}
2271
2272static int
2273ssh_dissect_encrypted_packet(tvbuff_t *tvb, packet_info *pinfo,
2274 struct ssh_peer_data *peer_data,
2275 int offset, proto_tree *tree)
2276{
2277 int len;
2278 unsigned plen;
2279
2280 len = tvb_reported_length_remaining(tvb, offset);
2281 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL((void*)0), "Encrypted packet (len=%d)", len);
2282
2283 if (tree) {
2284 int encrypted_len = len;
2285
2286 if (len > 4 && peer_data->length_is_plaintext) {
2287 plen = tvb_get_ntohl(tvb, offset) ;
2288 proto_tree_add_uint(tree, hf_ssh_packet_length, tvb, offset, 4, plen);
2289 encrypted_len -= 4;
2290 }
2291 else if (len > 4) {
2292 proto_tree_add_item(tree, hf_ssh_packet_length_encrypted, tvb, offset, 4, ENC_NA0x00000000);
2293 encrypted_len -= 4;
2294 }
2295
2296 if (peer_data->mac_length>0)
2297 encrypted_len -= peer_data->mac_length;
2298
2299 proto_tree_add_item(tree, hf_ssh_encrypted_packet,
2300 tvb, offset+4, encrypted_len, ENC_NA0x00000000);
2301
2302 if (peer_data->mac_length>0)
2303 proto_tree_add_item(tree, hf_ssh_mac_string,
2304 tvb, offset+4+encrypted_len,
2305 peer_data->mac_length, ENC_NA0x00000000);
2306 }
2307 offset += len;
2308 return offset;
2309}
2310
2311static int
2312ssh_dissect_protocol(tvbuff_t *tvb, packet_info *pinfo,
2313 struct ssh_flow_data *global_data,
2314 unsigned offset, proto_tree *tree, int is_response, unsigned * version,
2315 bool_Bool *need_desegmentation)
2316{
2317 unsigned protolen, next_offset;
2318
2319 /*
2320 * If the first packet do not contain the banner,
2321 * it is dump in the middle of a flow or not a ssh at all
2322 */
2323 if (tvb_strncaseeql(tvb, offset, "SSH-", 4) != 0) {
2324 offset = ssh_dissect_encrypted_packet(tvb, pinfo,
2325 &global_data->peer_data[is_response], offset, tree);
2326 return offset;
2327 }
2328
2329 if (!is_response) {
2330 if (tvb_strncaseeql(tvb, offset, "SSH-2.", 6) == 0) {
2331 *(version) = SSH_VERSION_22;
2332 } else if (tvb_strncaseeql(tvb, offset, "SSH-1.99-", 9) == 0) {
2333 *(version) = SSH_VERSION_22;
2334 } else if (tvb_strncaseeql(tvb, offset, "SSH-1.", 6) == 0) {
2335 *(version) = SSH_VERSION_11;
2336 }
2337 }
2338
2339 if (!tvb_find_line_end_remaining(tvb, offset, &protolen, &next_offset)) {
2340 if (ssh_desegment && pinfo->can_desegment) {
2341 pinfo->desegment_offset = offset;
2342 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT0x0fffffff;
2343 *need_desegmentation = true1;
2344 return offset;
2345 }
2346 }
2347 /* Either we found it, or we're not reassembling and take everything. */
2348
2349 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL((void*)0), "Protocol (%s)",
2350 tvb_format_text(pinfo->pool, tvb, offset, protolen));
2351
2352 // V_C / V_S (client and server identification strings) RFC4253 4.2
2353 // format: SSH-protoversion-softwareversion SP comments [CR LF not incl.]
2354 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
2355 uint8_t *data = (uint8_t *)tvb_memdup(pinfo->pool, tvb, offset, protolen);
2356 if(!is_response){
2357 ssh_hash_buffer_put_string(global_data->kex_client_version, data, protolen);
2358 }else{
2359 ssh_hash_buffer_put_string(global_data->kex_server_version, data, protolen);
2360 }
2361 }
2362
2363 proto_tree_add_item(tree, hf_ssh_protocol,
2364 tvb, offset, protolen, ENC_ASCII0x00000000);
2365 offset = next_offset;
2366 return offset;
2367}
2368
2369static void
2370ssh_set_mac_length(struct ssh_peer_data *peer_data)
2371{
2372 char *size_str;
2373 uint32_t size = 0;
2374 char *mac_name = peer_data->mac;
2375 char *strip;
2376
2377 if (!mac_name)
2378 return;
2379
2380 /* wmem_strdup() never returns NULL */
2381 mac_name = wmem_strdup(NULL((void*)0), (const char *)mac_name);
2382
2383 /* strip trailing "[email protected]" or "@openssh.com" */
2384 strip = strstr(mac_name, "[email protected]");
2385 if (strip) {
2386 peer_data->length_is_plaintext = 1;
2387 *strip = '\0';
2388 }
2389 else {
2390 strip = strstr(mac_name, "@openssh.com");
2391 if (strip) *strip = '\0';
2392 }
2393
2394 size_str = g_strrstr(mac_name, "-");
2395 if (size_str && ws_strtou32(size_str + 1, NULL((void*)0), &size) && size > 0 && size % 8 == 0 && size / 8 <= DIGEST_MAX_SIZE48) {
2396 peer_data->mac_length = size / 8;
2397 }
2398 else if (strcmp(mac_name, "hmac-sha1") == 0) {
2399 peer_data->mac_length = 20;
2400 }
2401 else if (strcmp(mac_name, "hmac-md5") == 0) {
2402 peer_data->mac_length = 16;
2403 }
2404 else if (strcmp(mac_name, "hmac-ripemd160") == 0) {
2405 peer_data->mac_length = 20;
2406 }
2407 else if (strcmp(mac_name, "none") == 0) {
2408 peer_data->mac_length = 0;
2409 }
2410
2411 wmem_free(NULL((void*)0), mac_name);
2412}
2413
2414static void ssh_set_kex_specific_dissector(struct ssh_flow_data *global_data)
2415{
2416 const char *kex_name = global_data->kex;
2417
2418 if (!kex_name) return;
2419
2420 if (strcmp(kex_name, "diffie-hellman-group-exchange-sha1") == 0 ||
2421 strcmp(kex_name, "diffie-hellman-group-exchange-sha256") == 0)
2422 {
2423 global_data->kex_specific_dissector = ssh_dissect_kex_dh_gex;
2424 }
2425 else if (g_str_has_prefix(kex_name, "ecdh-sha2-")(__builtin_constant_p ("ecdh-sha2-")? __extension__ ({ const char
* const __str = (kex_name); const char * const __prefix = ("ecdh-sha2-"
); gboolean __result = (0); if (__str == ((void*)0) || __prefix
== ((void*)0)) __result = (g_str_has_prefix) (__str, __prefix
); else { const size_t __str_len = strlen (((__str) + !(__str
))); const size_t __prefix_len = strlen (((__prefix) + !(__prefix
))); if (__str_len >= __prefix_len) __result = memcmp (((__str
) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len) == 0
; } __result; }) : (g_str_has_prefix) (kex_name, "ecdh-sha2-"
) )
||
2426 strcmp(kex_name, "[email protected]") == 0 ||
2427 strcmp(kex_name, "curve25519-sha256") == 0 ||
2428 strcmp(kex_name, "curve448-sha512") == 0)
2429 {
2430 global_data->kex_specific_dissector = ssh_dissect_kex_ecdh;
2431 }
2432 else if (strcmp(kex_name, "diffie-hellman-group14-sha256") == 0 ||
2433 strcmp(kex_name, "diffie-hellman-group16-sha512") == 0 ||
2434 strcmp(kex_name, "diffie-hellman-group18-sha512") == 0 ||
2435 strcmp(kex_name, "diffie-hellman-group1-sha1") == 0 ||
2436 strcmp(kex_name, "diffie-hellman-group14-sha1") == 0)
2437 {
2438 global_data->kex_specific_dissector = ssh_dissect_kex_dh;
2439 }
2440 else if (g_str_has_prefix(kex_name, "sntrup761x25519-sha512")(__builtin_constant_p ("sntrup761x25519-sha512")? __extension__
({ const char * const __str = (kex_name); const char * const
__prefix = ("sntrup761x25519-sha512"); gboolean __result = (
0); if (__str == ((void*)0) || __prefix == ((void*)0)) __result
= (g_str_has_prefix) (__str, __prefix); else { const size_t __str_len
= strlen (((__str) + !(__str))); const size_t __prefix_len =
strlen (((__prefix) + !(__prefix))); if (__str_len >= __prefix_len
) __result = memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix
)), __prefix_len) == 0; } __result; }) : (g_str_has_prefix) (
kex_name, "sntrup761x25519-sha512") )
||
2441 strcmp(kex_name, "mlkem768x25519-sha256") == 0 ||
2442 strcmp(kex_name, "mlkem768nistp256-sha256") == 0 ||
2443 strcmp(kex_name, "mlkem1024nistp384-sha384") == 0)
2444 {
2445 global_data->kex_specific_dissector = ssh_dissect_kex_pq_hybrid;
2446 }
2447 else
2448 {
2449 ws_warning("NOT SUPPORTED OR UNKNOWN KEX DETECTED: ALGORITHM = %s", kex_name)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_WARNING, "epan/dissectors/packet-ssh.c"
, 2449, __func__, "NOT SUPPORTED OR UNKNOWN KEX DETECTED: ALGORITHM = %s"
, kex_name); } } while (0)
;
2450 }
2451}
2452
2453static int
2454ssh_gslist_compare_strings(const void *a, const void *b)
2455{
2456 if (a == NULL((void*)0) && b == NULL((void*)0))
2457 return 0;
2458 if (a == NULL((void*)0))
2459 return -1;
2460 if (b == NULL((void*)0))
2461 return 1;
2462 return strcmp((const char*)a, (const char*)b);
2463}
2464
2465/* expects that *result is NULL */
2466static bool_Bool
2467ssh_choose_algo(char *client, char *server, char **result)
2468{
2469 char **server_strings = NULL((void*)0);
2470 char **client_strings = NULL((void*)0);
2471 char **step;
2472 GSList *server_list = NULL((void*)0);
2473
2474 static const char* client_strict = "[email protected]";
2475 static const char* server_strict = "[email protected]";
2476 bool_Bool kex_strict = false0;
2477
2478 if (!client || !server || !result || *result)
2479 return false0;
2480
2481 server_strings = g_strsplit(server, ",", 0);
2482 for (step = server_strings; *step; step++) {
2483 server_list = g_slist_append(server_list, *step);
2484 }
2485
2486 client_strings = g_strsplit(client, ",", 0);
2487 for (step = client_strings; *step; step++) {
2488 GSList *agreed;
2489 if ((agreed = g_slist_find_custom(server_list, *step, ssh_gslist_compare_strings))) {
2490 *result = wmem_strdup(wmem_file_scope(), (const char *)agreed->data);
2491 break;
2492 }
2493 }
2494
2495 /* Check for the OpenSSH strict key exchange extension designed to
2496 * mitigate the Terrapin attack by resetting the packet sequence
2497 * number to zero after a SSH2_MSG_NEWKEYS message.
2498 * https://www.openssh.com/txt/release-9.6
2499 * Also see PROTOCOL in the OpenSSH source distribution.
2500 *
2501 * OpenSSH says this is activated "when an endpoint that supports this
2502 * extension observes this algorithm name in a peer's KEXINIT packet".
2503 * We'll have to assume that any endpoint that supports this also
2504 * indicates support for it in its own first SSH2_MSG_KEXINIT.
2505 */
2506 if (g_strv_contains((const char* const*)client_strings, client_strict) &&
2507 g_strv_contains((const char* const*)server_strings, server_strict)) {
2508
2509 kex_strict = true1;
2510 }
2511
2512 g_strfreev(client_strings);
2513 g_slist_free(server_list);
2514 g_strfreev(server_strings);
2515
2516 return kex_strict;
2517}
2518
2519static int
2520ssh_dissect_key_init(tvbuff_t *tvb, packet_info *pinfo, int offset,
2521 proto_tree *tree, int is_response, struct ssh_flow_data *global_data)
2522{
2523 int start_offset = offset;
2524 int payload_length;
2525 wmem_strbuf_t *hassh_algo;
2526 char *hassh;
2527
2528 proto_item *tf, *ti;
2529 proto_tree *key_init_tree;
2530
2531 struct ssh_peer_data *peer_data = &global_data->peer_data[is_response];
2532
2533 key_init_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_key_init, &tf, "Algorithms");
2534 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
2535 peer_data->bn_cookie = ssh_kex_make_bignum(tvb_get_ptr(tvb, offset, 16), 16);
2536 }
2537 proto_tree_add_item(key_init_tree, hf_ssh_cookie,
2538 tvb, offset, 16, ENC_NA0x00000000);
2539 offset += 16;
2540
2541 offset = ssh_dissect_proposal(tvb, offset, key_init_tree,
2542 hf_ssh_kex_algorithms_length, hf_ssh_kex_algorithms,
2543 &peer_data->kex_proposal);
2544 offset = ssh_dissect_proposal(tvb, offset, key_init_tree,
2545 hf_ssh_server_host_key_algorithms_length,
2546 hf_ssh_server_host_key_algorithms, NULL((void*)0));
2547 offset = ssh_dissect_proposal(tvb, offset, key_init_tree,
2548 hf_ssh_encryption_algorithms_client_to_server_length,
2549 hf_ssh_encryption_algorithms_client_to_server,
2550 &peer_data->enc_proposals[CLIENT_TO_SERVER_PROPOSAL0]);
2551 offset = ssh_dissect_proposal(tvb, offset, key_init_tree,
2552 hf_ssh_encryption_algorithms_server_to_client_length,
2553 hf_ssh_encryption_algorithms_server_to_client,
2554 &peer_data->enc_proposals[SERVER_TO_CLIENT_PROPOSAL1]);
2555 offset = ssh_dissect_proposal(tvb, offset, key_init_tree,
2556 hf_ssh_mac_algorithms_client_to_server_length,
2557 hf_ssh_mac_algorithms_client_to_server,
2558 &peer_data->mac_proposals[CLIENT_TO_SERVER_PROPOSAL0]);
2559 offset = ssh_dissect_proposal(tvb, offset, key_init_tree,
2560 hf_ssh_mac_algorithms_server_to_client_length,
2561 hf_ssh_mac_algorithms_server_to_client,
2562 &peer_data->mac_proposals[SERVER_TO_CLIENT_PROPOSAL1]);
2563 offset = ssh_dissect_proposal(tvb, offset, key_init_tree,
2564 hf_ssh_compression_algorithms_client_to_server_length,
2565 hf_ssh_compression_algorithms_client_to_server,
2566 &peer_data->comp_proposals[CLIENT_TO_SERVER_PROPOSAL0]);
2567 offset = ssh_dissect_proposal(tvb, offset, key_init_tree,
2568 hf_ssh_compression_algorithms_server_to_client_length,
2569 hf_ssh_compression_algorithms_server_to_client,
2570 &peer_data->comp_proposals[SERVER_TO_CLIENT_PROPOSAL1]);
2571 offset = ssh_dissect_proposal(tvb, offset, key_init_tree,
2572 hf_ssh_languages_client_to_server_length,
2573 hf_ssh_languages_client_to_server, NULL((void*)0));
2574 offset = ssh_dissect_proposal(tvb, offset, key_init_tree,
2575 hf_ssh_languages_server_to_client_length,
2576 hf_ssh_languages_server_to_client, NULL((void*)0));
2577
2578 proto_tree_add_item(key_init_tree, hf_ssh_first_kex_packet_follows,
2579 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
2580 offset+=1;
2581
2582 proto_tree_add_item(key_init_tree, hf_ssh_kex_reserved,
2583 tvb, offset, 4, ENC_NA0x00000000);
2584 offset+=4;
2585
2586 hassh_algo = wmem_strbuf_new(pinfo->pool, "");
2587 if(!is_response) {
2588 wmem_strbuf_append_printf(hassh_algo, "%s;%s;%s;%s", peer_data->kex_proposal, peer_data->enc_proposals[CLIENT_TO_SERVER_PROPOSAL0],
2589 peer_data->mac_proposals[CLIENT_TO_SERVER_PROPOSAL0], peer_data->comp_proposals[CLIENT_TO_SERVER_PROPOSAL0]);
2590 hassh = g_compute_checksum_for_string(G_CHECKSUM_MD5, wmem_strbuf_get_str(hassh_algo), wmem_strbuf_get_len(hassh_algo));
2591 ti = proto_tree_add_string(key_init_tree, hf_ssh_kex_hassh_algo, tvb, offset, 0, wmem_strbuf_get_str(hassh_algo));
2592 proto_item_set_generated(ti);
2593 ti = proto_tree_add_string(key_init_tree, hf_ssh_kex_hassh, tvb, offset, 0, hassh);
2594 proto_item_set_generated(ti);
2595 g_free(hassh)(__builtin_object_size ((hassh), 0) != ((size_t) - 1)) ? g_free_sized
(hassh, __builtin_object_size ((hassh), 0)) : (g_free) (hassh
)
;
2596 } else {
2597 wmem_strbuf_append_printf(hassh_algo, "%s;%s;%s;%s", peer_data->kex_proposal, peer_data->enc_proposals[SERVER_TO_CLIENT_PROPOSAL1],
2598 peer_data->mac_proposals[SERVER_TO_CLIENT_PROPOSAL1], peer_data->comp_proposals[SERVER_TO_CLIENT_PROPOSAL1]);
2599 hassh = g_compute_checksum_for_string(G_CHECKSUM_MD5, wmem_strbuf_get_str(hassh_algo), wmem_strbuf_get_len(hassh_algo));
2600 ti = proto_tree_add_string(key_init_tree, hf_ssh_kex_hasshserver_algo, tvb, offset, 0, wmem_strbuf_get_str(hassh_algo));
2601 proto_item_set_generated(ti);
2602 ti = proto_tree_add_string(key_init_tree, hf_ssh_kex_hasshserver, tvb, offset, 0, hassh);
2603 proto_item_set_generated(ti);
2604 g_free(hassh)(__builtin_object_size ((hassh), 0) != ((size_t) - 1)) ? g_free_sized
(hassh, __builtin_object_size ((hassh), 0)) : (g_free) (hassh
)
;
2605 }
2606
2607 if (global_data->peer_data[CLIENT_PEER_DATA0].kex_proposal &&
2608 global_data->peer_data[SERVER_PEER_DATA1].kex_proposal &&
2609 !global_data->kex)
2610 {
2611 /* Note: we're ignoring first_kex_packet_follows. */
2612 global_data->ext_kex_strict = ssh_choose_algo(
2613 global_data->peer_data[CLIENT_PEER_DATA0].kex_proposal,
2614 global_data->peer_data[SERVER_PEER_DATA1].kex_proposal,
2615 &global_data->kex);
2616 ssh_set_kex_specific_dissector(global_data);
2617 }
2618
2619 payload_length = offset - start_offset;
2620
2621 if (tf != NULL((void*)0)) {
2622 proto_item_set_len(tf, payload_length);
2623 }
2624
2625 // I_C / I_S (client and server SSH_MSG_KEXINIT payload) RFC4253 4.2
2626 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
2627 uint8_t *data = (uint8_t *)wmem_alloc(pinfo->pool, payload_length + 1);
2628 tvb_memcpy(tvb, data + 1, start_offset, payload_length);
2629 data[0] = SSH_MSG_KEXINIT20;
2630 if(is_response){
2631 ssh_hash_buffer_put_string(global_data->kex_server_key_exchange_init, data, payload_length + 1);
2632 }else{
2633 // Reset array while REKEY: sanitize client key
2634 global_data->kex_client_key_exchange_init = wmem_array_new(wmem_file_scope(), 1);
2635 ssh_hash_buffer_put_string(global_data->kex_client_key_exchange_init, data, payload_length + 1);
2636 }
2637 }
2638
2639 return offset;
2640}
2641
2642static int
2643ssh_dissect_proposal(tvbuff_t *tvb, int offset, proto_tree *tree,
2644 int hf_index_length, int hf_index_value, char **store)
2645{
2646 uint32_t len = tvb_get_ntohl(tvb, offset);
2647 proto_tree_add_uint(tree, hf_index_length, tvb, offset, 4, len);
2648 offset += 4;
2649
2650 proto_tree_add_item(tree, hf_index_value, tvb, offset, len,
2651 ENC_ASCII0x00000000);
2652 if (store)
2653 *store = (char *) tvb_get_string_enc(wmem_file_scope(), tvb, offset, len, ENC_ASCII0x00000000);
2654 offset += len;
2655
2656 return offset;
2657}
2658
2659static void
2660ssh_keylog_read_file(void)
2661{
2662 if (!pref_keylog_file || !*pref_keylog_file) {
12
Assuming 'pref_keylog_file' is non-null
13
Assuming the condition is false
2663 ws_debug("no keylog file preference set")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2663, __func__, "no keylog file preference set"); } } while
(0)
;
2664 return;
2665 }
2666
2667 if (ssh_keylog_file && file_needs_reopen(ws_filenofileno(ssh_keylog_file),
14
Assuming 'ssh_keylog_file' is non-null
15
Assuming the condition is false
16
Taking false branch
2668 pref_keylog_file)) {
2669 ssh_keylog_reset();
2670 g_hash_table_remove_all(ssh_master_key_map);
2671 }
2672
2673 if (!ssh_keylog_file) {
17
Assuming 'ssh_keylog_file' is non-null
18
Taking false branch
2674 ssh_keylog_file = ws_fopenfopen(pref_keylog_file, "r");
2675 if (!ssh_keylog_file) {
2676 ws_debug("ssh: failed to open key log file %s: %s",do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2677, __func__, "ssh: failed to open key log file %s: %s", pref_keylog_file
, g_strerror((*__errno_location ()))); } } while (0)
2677 pref_keylog_file, g_strerror(errno))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2677, __func__, "ssh: failed to open key log file %s: %s", pref_keylog_file
, g_strerror((*__errno_location ()))); } } while (0)
;
2678 return;
2679 }
2680 }
2681
2682 /* File format: each line follows the format "<cookie> <type> <key>".
2683 * <cookie> is the hex-encoded (client or server) 16 bytes cookie
2684 * (32 characters) found in the SSH_MSG_KEXINIT of the endpoint whose
2685 * private random is disclosed.
2686 * <type> is either SHARED_SECRET or PRIVATE_KEY depending on the
2687 * type of key provided. PRIVAT_KEY is only supported for DH,
2688 * DH group exchange, and ECDH (including Curve25519) key exchanges.
2689 * <key> is the private random number that is used to generate the DH
2690 * negotiation (length depends on algorithm). In RFC4253 it is called
2691 * x for the client and y for the server.
2692 * For openssh and DH group exchange, it can be retrieved using
2693 * DH_get0_key(kex->dh, NULL, &server_random)
2694 * for groupN in file kexdh.c function kex_dh_compute_key
2695 * for custom group in file kexgexs.c function input_kex_dh_gex_init
2696 * For openssh and curve25519, it can be found in function kex_c25519_enc
2697 * in variable server_key. One may also provide the shared secret
2698 * directly if <type> is set to SHARED_SECRET.
2699 *
2700 * Example:
2701 * 90d886612f9c35903db5bb30d11f23c2 PRIVATE_KEY DEF830C22F6C927E31972FFB20B46C96D0A5F2D5E7BE5A3A8804D6BFC431619ED10AF589EEDFF4750DEA00EFD7AFDB814B6F3528729692B1F2482041521AE9DC
2702 */
2703 for (;;) {
19
Loop condition is true. Entering loop body
2704 // XXX - What is a reasonable max line length here? Note at a certain
2705 // point we have to increase the maximum ssh_kex_make_bignum supports (not needed for post quantum material (pure binary)).
2706 char buf[4096];// 4096 is needed for mlkem1024 private_key binary meterial: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.203.pdf
2707 buf[0] = 0;
2708
2709 if (!fgets(buf, sizeof(buf), ssh_keylog_file)) {
20
Taking true branch
2710 rewind(ssh_keylog_file); // Resets to start of file (to handle parallel multi sessions decryption)
21
After calling 'rewind' reading 'errno' is required to find out if the call has failed
2711 if (ferror(ssh_keylog_file)) {
22
Value of 'errno' was not checked and may be overwritten by function 'ferror'
2712 ws_debug("Error while reading %s, closing it.", pref_keylog_file)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2712, __func__, "Error while reading %s, closing it.", pref_keylog_file
); } } while (0)
;
2713 ssh_keylog_reset();
2714 g_hash_table_remove_all(ssh_master_key_map);
2715 }
2716 break;
2717 }
2718
2719 size_t len = strlen(buf);
2720 while(len>0 && (buf[len-1]=='\r' || buf[len-1]=='\n')){len-=1;buf[len]=0;}
2721 ws_noisy("ssh: raw keylog line read: %s", buf)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 2721, __func__, "ssh: raw keylog line read: %s", buf); } } while
(0)
;
2722
2723 ssh_keylog_process_line(buf);
2724 }
2725}
2726
2727static void
2728ssh_keylog_process_lines(const uint8_t *data, unsigned datalen)
2729{
2730 const char *next_line = (const char *)data;
2731 const char *line_end = next_line + datalen;
2732 while (next_line && next_line < line_end) {
2733 const char *line = next_line;
2734 next_line = (const char *)memchr(line, '\n', line_end - line);
2735 ssize_t linelen;
2736
2737 if (next_line) {
2738 linelen = next_line - line;
2739 next_line++; /* drop LF */
2740 } else {
2741 linelen = (ssize_t)(line_end - line);
2742 }
2743 if (linelen > 0 && line[linelen - 1] == '\r') {
2744 linelen--; /* drop CR */
2745 }
2746
2747 ssh_debug_printf(" checking keylog line: %.*s\n", (int)linelen, line);
2748 ws_noisy("ssh: about to process line: %.*s", (int)linelen, line)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 2748, __func__, "ssh: about to process line: %.*s", (int)linelen
, line); } } while (0)
;
2749
2750 char * strippedline = g_strndup(line, linelen);
2751 ssh_keylog_process_line(strippedline);
2752 g_free(strippedline)(__builtin_object_size ((strippedline), 0) != ((size_t) - 1))
? g_free_sized (strippedline, __builtin_object_size ((strippedline
), 0)) : (g_free) (strippedline)
;
2753 }
2754}
2755
2756static void
2757ssh_keylog_process_line(const char *line)
2758{
2759 ws_noisy("ssh: process line: %s", line)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 2759, __func__, "ssh: process line: %s", line); } } while (
0)
;
2760
2761 char **split = g_strsplit(line, " ", 3);
2762 char *cookie, *type, *key;
2763 size_t cookie_len, key_len;
2764
2765 if (g_strv_length(split) == 3) {
2766 // New format: [hex-encoded cookie] [key type] [hex-encoded key material]
2767 cookie = split[0];
2768 type = split[1];
2769 key = split[2];
2770 } else if (g_strv_length(split) == 2) {
2771 // Old format: [hex-encoded cookie] [hex-encoded private key]
2772 ws_debug("ssh keylog: detected old keylog format without explicit key type")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2772, __func__, "ssh keylog: detected old keylog format without explicit key type"
); } } while (0)
;
2773 type = "PRIVATE_KEY";
2774 cookie = split[0];
2775 key = split[1];
2776 } else {
2777 ws_info("ssh keylog: invalid format")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_INFO, ((void
*)0), -1, ((void*)0), "ssh keylog: invalid format"); } } while
(0)
;
2778 g_strfreev(split);
2779 return;
2780 }
2781
2782 key_len = strlen(key);
2783 cookie_len = strlen(cookie);
2784 if(key_len & 1){
2785 ws_info("ssh keylog: invalid format (key should at least be even!)")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_INFO, ((void
*)0), -1, ((void*)0), "ssh keylog: invalid format (key should at least be even!)"
); } } while (0)
;
2786 g_strfreev(split);
2787 return;
2788 }
2789 if(cookie_len & 1){
2790 ws_info("ssh keylog: invalid format (cookie should at least be even!)")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_INFO, ((void
*)0), -1, ((void*)0), "ssh keylog: invalid format (cookie should at least be even!)"
); } } while (0)
;
2791 g_strfreev(split);
2792 return;
2793 }
2794 ssh_bignum * bn_cookie = ssh_kex_make_bignum(NULL((void*)0), (unsigned)(cookie_len/2));
2795 if (bn_cookie == NULL((void*)0)) {
2796 ws_info("ssh keylog: invalid format (invalid cookie length %zu)", cookie_len)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_INFO, ((void
*)0), -1, ((void*)0), "ssh keylog: invalid format (invalid cookie length %zu)"
, cookie_len); } } while (0)
;
2797 g_strfreev(split);
2798 return;
2799 }
2800 ssh_bignum * bn_priv = ssh_kex_make_bignum(NULL((void*)0), (unsigned)(key_len/2));
2801 if (bn_priv == NULL((void*)0)) {
2802 ws_info("ssh keylog: invalid format (invalid key length %zu)", key_len)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_INFO, ((void
*)0), -1, ((void*)0), "ssh keylog: invalid format (invalid key length %zu)"
, key_len); } } while (0)
;
2803 g_strfreev(split);
2804 return;
2805 }
2806 uint8_t c;
2807 for (size_t i = 0; i < key_len/2; i ++) {
2808 char v0 = key[i * 2];
2809 int8_t h0 = ws_xton(v0);
2810 char v1 = key[i * 2 + 1];
2811 int8_t h1 = ws_xton(v1);
2812
2813 if (h0==-1 || h1==-1) {
2814 ws_debug("ssh: can't process key, invalid hex number: %c%c", v0, v1)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2814, __func__, "ssh: can't process key, invalid hex number: %c%c"
, v0, v1); } } while (0)
;
2815 g_strfreev(split);
2816 return;
2817 }
2818
2819 c = (h0 << 4) | h1;
2820
2821 bn_priv->data[i] = c;
2822 }
2823 for (size_t i = 0; i < cookie_len/2; i ++) {
2824 char v0 = cookie[i * 2];
2825 int8_t h0 = ws_xton(v0);
2826 char v1 = cookie[i * 2 + 1];
2827 int8_t h1 = ws_xton(v1);
2828
2829 if (h0==-1 || h1==-1) {
2830 ws_debug("ssh: can't process cookie, invalid hex number: %c%c", v0, v1)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2830, __func__, "ssh: can't process cookie, invalid hex number: %c%c"
, v0, v1); } } while (0)
;
2831 g_strfreev(split);
2832 return;
2833 }
2834
2835 c = (h0 << 4) | h1;
2836
2837 bn_cookie->data[i] = c;
2838 }
2839 ssh_bignum * bn_priv_ht = g_new(ssh_bignum, 1)((ssh_bignum *) g_malloc_n ((1), sizeof (ssh_bignum)));
2840 bn_priv_ht->length = bn_priv->length;
2841 bn_priv_ht->data = (uint8_t *) g_memdup2(bn_priv->data, bn_priv->length);
2842 ssh_bignum * bn_cookie_ht = g_new(ssh_bignum, 1)((ssh_bignum *) g_malloc_n ((1), sizeof (ssh_bignum)));
2843 bn_cookie_ht->length = bn_cookie->length;
2844 bn_cookie_ht->data = (uint8_t *) g_memdup2(bn_cookie->data, bn_cookie->length);
2845
2846 char * type_ht = (char *) g_memdup2(type, strlen(type) + 1);
2847 ssh_key_map_entry_t * entry_ht = g_new(ssh_key_map_entry_t, 1)((ssh_key_map_entry_t *) g_malloc_n ((1), sizeof (ssh_key_map_entry_t
)))
;
2848 entry_ht->type = type_ht;
2849 entry_ht->key_material = bn_priv_ht;
2850 g_hash_table_insert(ssh_master_key_map, bn_cookie_ht, entry_ht);
2851 g_strfreev(split);
2852}
2853
2854static void
2855ssh_keylog_reset(void)
2856{
2857 if (ssh_keylog_file) {
2858 fclose(ssh_keylog_file);
2859 ssh_keylog_file = NULL((void*)0);
2860 }
2861}
2862
2863static unsigned
2864ssh_kex_type(char *type)
2865{
2866 if (type) {
2867 if (g_str_has_prefix(type, "curve25519")(__builtin_constant_p ("curve25519")? __extension__ ({ const char
* const __str = (type); const char * const __prefix = ("curve25519"
); gboolean __result = (0); if (__str == ((void*)0) || __prefix
== ((void*)0)) __result = (g_str_has_prefix) (__str, __prefix
); else { const size_t __str_len = strlen (((__str) + !(__str
))); const size_t __prefix_len = strlen (((__prefix) + !(__prefix
))); if (__str_len >= __prefix_len) __result = memcmp (((__str
) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len) == 0
; } __result; }) : (g_str_has_prefix) (type, "curve25519") )
) {
2868 return SSH_KEX_CURVE255190x00010000;
2869 }else if (g_str_has_prefix(type, "sntrup761x25519")(__builtin_constant_p ("sntrup761x25519")? __extension__ ({ const
char * const __str = (type); const char * const __prefix = (
"sntrup761x25519"); gboolean __result = (0); if (__str == ((void
*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix)
(__str, __prefix); else { const size_t __str_len = strlen ((
(__str) + !(__str))); const size_t __prefix_len = strlen (((__prefix
) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (type, "sntrup761x25519"
) )
) {
2870 return SSH_KEX_SNTRUP761X255190x00040000;
2871 }else if (g_str_has_prefix(type, "mlkem768x25519")(__builtin_constant_p ("mlkem768x25519")? __extension__ ({ const
char * const __str = (type); const char * const __prefix = (
"mlkem768x25519"); gboolean __result = (0); if (__str == ((void
*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix)
(__str, __prefix); else { const size_t __str_len = strlen ((
(__str) + !(__str))); const size_t __prefix_len = strlen (((__prefix
) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (type, "mlkem768x25519"
) )
) {
2872 return SSH_KEX_MLKEM768X255190x00050000;
2873 }else if (g_str_has_prefix(type, "diffie-hellman-group-exchange")(__builtin_constant_p ("diffie-hellman-group-exchange")? __extension__
({ const char * const __str = (type); const char * const __prefix
= ("diffie-hellman-group-exchange"); gboolean __result = (0)
; if (__str == ((void*)0) || __prefix == ((void*)0)) __result
= (g_str_has_prefix) (__str, __prefix); else { const size_t __str_len
= strlen (((__str) + !(__str))); const size_t __prefix_len =
strlen (((__prefix) + !(__prefix))); if (__str_len >= __prefix_len
) __result = memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix
)), __prefix_len) == 0; } __result; }) : (g_str_has_prefix) (
type, "diffie-hellman-group-exchange") )
) {
2874 return SSH_KEX_DH_GEX0x00020000;
2875 }else if (g_str_has_prefix(type, "diffie-hellman-group14")(__builtin_constant_p ("diffie-hellman-group14")? __extension__
({ const char * const __str = (type); const char * const __prefix
= ("diffie-hellman-group14"); gboolean __result = (0); if (__str
== ((void*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix
) (__str, __prefix); else { const size_t __str_len = strlen (
((__str) + !(__str))); const size_t __prefix_len = strlen (((
__prefix) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (type, "diffie-hellman-group14"
) )
) {
2876 return SSH_KEX_DH_GROUP140x00030014;
2877 }else if (g_str_has_prefix(type, "diffie-hellman-group16")(__builtin_constant_p ("diffie-hellman-group16")? __extension__
({ const char * const __str = (type); const char * const __prefix
= ("diffie-hellman-group16"); gboolean __result = (0); if (__str
== ((void*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix
) (__str, __prefix); else { const size_t __str_len = strlen (
((__str) + !(__str))); const size_t __prefix_len = strlen (((
__prefix) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (type, "diffie-hellman-group16"
) )
) {
2878 return SSH_KEX_DH_GROUP160x00030016;
2879 }else if (g_str_has_prefix(type, "diffie-hellman-group18")(__builtin_constant_p ("diffie-hellman-group18")? __extension__
({ const char * const __str = (type); const char * const __prefix
= ("diffie-hellman-group18"); gboolean __result = (0); if (__str
== ((void*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix
) (__str, __prefix); else { const size_t __str_len = strlen (
((__str) + !(__str))); const size_t __prefix_len = strlen (((
__prefix) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (type, "diffie-hellman-group18"
) )
) {
2880 return SSH_KEX_DH_GROUP180x00030018;
2881 }else if (g_str_has_prefix(type, "diffie-hellman-group1")(__builtin_constant_p ("diffie-hellman-group1")? __extension__
({ const char * const __str = (type); const char * const __prefix
= ("diffie-hellman-group1"); gboolean __result = (0); if (__str
== ((void*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix
) (__str, __prefix); else { const size_t __str_len = strlen (
((__str) + !(__str))); const size_t __prefix_len = strlen (((
__prefix) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (type, "diffie-hellman-group1"
) )
) {
2882 return SSH_KEX_DH_GROUP10x00030001;
2883 }
2884 }
2885
2886 return 0;
2887}
2888
2889static unsigned
2890ssh_kex_hash_type(char *type_string)
2891{
2892 if (type_string && g_str_has_suffix(type_string, "sha1")(__builtin_constant_p ("sha1")? __extension__ ({ const char *
const __str = (type_string); const char * const __suffix = (
"sha1"); gboolean __result = (0); if (__str == ((void*)0) || __suffix
== ((void*)0)) __result = (g_str_has_suffix) (__str, __suffix
); else { const size_t __str_len = strlen (((__str) + !(__str
))); const size_t __suffix_len = strlen (((__suffix) + !(__suffix
))); if (__str_len >= __suffix_len) __result = memcmp (__str
+ __str_len - __suffix_len, ((__suffix) + !(__suffix)), __suffix_len
) == 0; } __result; }) : (g_str_has_suffix) (type_string, "sha1"
) )
) {
2893 return SSH_KEX_HASH_SHA11;
2894 }else if (type_string && g_str_has_suffix(type_string, "sha256")(__builtin_constant_p ("sha256")? __extension__ ({ const char
* const __str = (type_string); const char * const __suffix =
("sha256"); gboolean __result = (0); if (__str == ((void*)0)
|| __suffix == ((void*)0)) __result = (g_str_has_suffix) (__str
, __suffix); else { const size_t __str_len = strlen (((__str)
+ !(__str))); const size_t __suffix_len = strlen (((__suffix
) + !(__suffix))); if (__str_len >= __suffix_len) __result
= memcmp (__str + __str_len - __suffix_len, ((__suffix) + !(
__suffix)), __suffix_len) == 0; } __result; }) : (g_str_has_suffix
) (type_string, "sha256") )
) {
2895 return SSH_KEX_HASH_SHA2562;
2896 }else if (type_string && g_str_has_suffix(type_string, "[email protected]")(__builtin_constant_p ("[email protected]")? __extension__ ({
const char * const __str = (type_string); const char * const
__suffix = ("[email protected]"); gboolean __result = (0); if
(__str == ((void*)0) || __suffix == ((void*)0)) __result = (
g_str_has_suffix) (__str, __suffix); else { const size_t __str_len
= strlen (((__str) + !(__str))); const size_t __suffix_len =
strlen (((__suffix) + !(__suffix))); if (__str_len >= __suffix_len
) __result = memcmp (__str + __str_len - __suffix_len, ((__suffix
) + !(__suffix)), __suffix_len) == 0; } __result; }) : (g_str_has_suffix
) (type_string, "[email protected]") )
) {
2897 return SSH_KEX_HASH_SHA2562;
2898 }else if (type_string && g_str_has_suffix(type_string, "sha512")(__builtin_constant_p ("sha512")? __extension__ ({ const char
* const __str = (type_string); const char * const __suffix =
("sha512"); gboolean __result = (0); if (__str == ((void*)0)
|| __suffix == ((void*)0)) __result = (g_str_has_suffix) (__str
, __suffix); else { const size_t __str_len = strlen (((__str)
+ !(__str))); const size_t __suffix_len = strlen (((__suffix
) + !(__suffix))); if (__str_len >= __suffix_len) __result
= memcmp (__str + __str_len - __suffix_len, ((__suffix) + !(
__suffix)), __suffix_len) == 0; } __result; }) : (g_str_has_suffix
) (type_string, "sha512") )
) {
2899 return SSH_KEX_HASH_SHA5124;
2900 } else {
2901 ws_debug("hash type %s not supported", type_string)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2901, __func__, "hash type %s not supported", type_string);
} } while (0)
;
2902 return 0;
2903 }
2904}
2905
2906static ssh_bignum *
2907ssh_kex_make_bignum(const uint8_t *data, unsigned length)
2908{
2909 // 512 bytes (4096 bits) is the maximum bignum size we're supporting
2910 // Actually we need 513 bytes, to make provision for signed values
2911 // Diffie-Hellman group 18 has 8192 bits
2912 if (length == 0 || length > 1025) {
2913 return NULL((void*)0);
2914 }
2915
2916 ssh_bignum *bn = wmem_new0(wmem_file_scope(), ssh_bignum)((ssh_bignum*)wmem_alloc0((wmem_file_scope()), sizeof(ssh_bignum
)))
;
2917 bn->data = (uint8_t *)wmem_alloc0(wmem_file_scope(), length);
2918
2919 if (data) {
2920 memcpy(bn->data, data, length);
2921 }
2922
2923 bn->length = length;
2924 return bn;
2925}
2926
2927static bool_Bool
2928ssh_read_e(tvbuff_t *tvb, int offset, struct ssh_flow_data *global_data)
2929{
2930 // store the client's public part (e) for later usage
2931 uint32_t length = tvb_get_ntohl(tvb, offset);
2932 global_data->kex_e = ssh_kex_make_bignum(NULL((void*)0), length);
2933 if (!global_data->kex_e) {
2934 return false0;
2935 }
2936 tvb_memcpy(tvb, global_data->kex_e->data, offset + 4, length);
2937 return true1;
2938}
2939
2940static bool_Bool
2941ssh_read_f(tvbuff_t *tvb, int offset, struct ssh_flow_data *global_data)
2942{
2943 // store the server's public part (f) for later usage
2944 uint32_t length = tvb_get_ntohl(tvb, offset);
2945 global_data->kex_f = ssh_kex_make_bignum(NULL((void*)0), length);
2946 if (!global_data->kex_f) {
2947 return false0;
2948 }
2949 tvb_memcpy(tvb, global_data->kex_f->data, offset + 4, length);
2950 return true1;
2951}
2952
2953static int // add support of client PQ hybrid key (e)
2954ssh_read_e_pq(tvbuff_t *tvb, int offset, struct ssh_flow_data *global_data)
2955{
2956 // Read length of PQ client key
2957 uint32_t length = tvb_get_ntohl(tvb, offset);
2958
2959 // Sanity check
2960 if (length == 0 || length > 65535) {
2961 ws_debug("ssh_read_e_pq: Invalid PQ key length: %u", length)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2961, __func__, "ssh_read_e_pq: Invalid PQ key length: %u",
length); } } while (0)
;
2962 return -1;
2963 }
2964
2965 // Free any existing data (if dissecting multiple sessions)
2966 wmem_free(wmem_file_scope(), global_data->kex_e_pq);
2967
2968 // Allocate and store the PQ client key
2969 global_data->kex_e_pq = (unsigned char *)wmem_alloc(wmem_file_scope(), length);
2970 global_data->kex_e_pq_len = length;
2971
2972 tvb_memcpy(tvb, global_data->kex_e_pq, offset + 4, length);
2973
2974 ws_debug("Stored %u bytes of client PQ key - stored new_offset_client: %d - offset: %d", length, offset + 4 + length, offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2974, __func__, "Stored %u bytes of client PQ key - stored new_offset_client: %d - offset: %d"
, length, offset + 4 + length, offset); } } while (0)
;
2975 return offset + 4 + length; // consuming packet (advancing offset)
2976}
2977
2978static int // add support of server PQ hybrid key (f)
2979ssh_read_f_pq(tvbuff_t *tvb, int offset, struct ssh_flow_data *global_data)
2980{
2981 // Read length of PQ server key
2982 uint32_t length = tvb_get_ntohl(tvb, offset);
2983
2984 // Sanity check
2985 if (length == 0 || length > 65535) {
2986 ws_debug("ssh_read_f_pq: Invalid PQ key length: %u", length)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2986, __func__, "ssh_read_f_pq: Invalid PQ key length: %u",
length); } } while (0)
;
2987 return -1;
2988 }
2989
2990 // Free any existing data
2991 wmem_free(wmem_file_scope(), global_data->kex_f_pq);
2992
2993 // Allocate and store the PQ server key
2994 global_data->kex_f_pq = (unsigned char *)wmem_alloc(wmem_file_scope(), length);
2995 global_data->kex_f_pq_len = length;
2996
2997 tvb_memcpy(tvb, global_data->kex_f_pq, offset + 4, length);
2998
2999 ws_debug("Stored %u bytes of server PQ key - stored new_offset_server: %d - offset: %d", length, offset + 4 + length, offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 2999, __func__, "Stored %u bytes of server PQ key - stored new_offset_server: %d - offset: %d"
, length, offset + 4 + length, offset); } } while (0)
;
3000 return offset + 4 + length; // consuming packet (advancing offset)
3001}
3002
3003
3004static ssh_bignum *
3005ssh_read_mpint(tvbuff_t *tvb, int offset)
3006{
3007 // store the DH group modulo (p) for later usage
3008 int length = tvb_get_ntohl(tvb, offset);
3009 ssh_bignum * bn = ssh_kex_make_bignum(NULL((void*)0), length);
3010 if (!bn) {
3011 ws_debug("invalid bignum length %u", length)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3011, __func__, "invalid bignum length %u", length); } } while
(0)
;
3012 return NULL((void*)0);
3013 }
3014 tvb_memcpy(tvb, bn->data, offset + 4, length);
3015 return bn;
3016}
3017
3018static void
3019ssh_keylog_hash_write_secret(struct ssh_flow_data *global_data, wmem_allocator_t* tmp_allocator)
3020{
3021 /*
3022 * This computation is defined differently for each key exchange method:
3023 * https://tools.ietf.org/html/rfc4253#page-23
3024 * https://tools.ietf.org/html/rfc5656#page-8
3025 * https://tools.ietf.org/html/rfc4419#page-4
3026 * All key exchange methods:
3027 * https://www.iana.org/assignments/ssh-parameters/ssh-parameters.xhtml#ssh-parameters-16
3028 */
3029
3030 gcry_md_hd_t hd;
3031 ssh_key_map_entry_t *entry;
3032 ssh_bignum *secret = NULL((void*)0);
3033 int length;
3034 bool_Bool client_cookie = false0;
3035
3036 ssh_keylog_read_file();
11
Calling 'ssh_keylog_read_file'
3037
3038 unsigned kex_type = ssh_kex_type(global_data->kex);
3039 unsigned kex_hash_type = ssh_kex_hash_type(global_data->kex);
3040
3041 entry = (ssh_key_map_entry_t *)g_hash_table_lookup(ssh_master_key_map, global_data->peer_data[SERVER_PEER_DATA1].bn_cookie);
3042 if (!entry) {
3043 entry = (ssh_key_map_entry_t *)g_hash_table_lookup(ssh_master_key_map, global_data->peer_data[CLIENT_PEER_DATA0].bn_cookie);
3044 client_cookie = true1;
3045 }
3046 if (!entry) {
3047 ws_debug("ssh decryption: no entry in keylog file for this session")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3047, __func__, "ssh decryption: no entry in keylog file for this session"
); } } while (0)
;
3048 global_data->do_decrypt = false0;
3049 return;
3050 }
3051
3052 if (!strcmp(entry->type, "PRIVATE_KEY")) {
3053 if (client_cookie) {
3054 secret = ssh_kex_shared_secret(kex_type, global_data->kex_f, entry->key_material, global_data->kex_gex_p);
3055 } else {
3056 secret = ssh_kex_shared_secret(kex_type, global_data->kex_e, entry->key_material, global_data->kex_gex_p);
3057 }
3058 } else if (!strcmp(entry->type, "SHARED_SECRET")) {
3059 secret = ssh_kex_make_bignum(entry->key_material->data, entry->key_material->length);
3060 } else {
3061 ws_debug("ssh decryption: unknown key type in keylog file")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3061, __func__, "ssh decryption: unknown key type in keylog file"
); } } while (0)
;
3062 global_data->do_decrypt = false0;
3063 return;
3064 }
3065
3066 if (!secret) {
3067 ws_debug("ssh decryption: no key material for this session")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3067, __func__, "ssh decryption: no key material for this session"
); } } while (0)
;
3068 global_data->do_decrypt = false0;
3069 return;
3070 }
3071
3072 // shared secret data needs to be written as an mpint, and we need it later
3073 if (kex_type == SSH_KEX_SNTRUP761X255190x00040000 || kex_type == SSH_KEX_MLKEM768X255190x00050000) {
3074 // Reset array while REKEY: sanitize shared_secret:
3075 global_data->kex_shared_secret = wmem_array_new(wmem_file_scope(), 1);
3076 // For PQ KEMs: use shared_secret as-is, whether SHARED_SECRET or PRIVATE_KEY
3077 // Do NOT prepend 0x00 (OpenSSH already encodes correctly for PQ KEM)
3078 ssh_hash_buffer_put_string(global_data->kex_shared_secret, secret->data, secret->length);
3079 } else {
3080 // For all other KEX types (e.g., curve25519, ecdh-sha2, etc.)
3081 // Pad with 0x00 if MSB is set, to comply with mpint format (RFC 4251)
3082 if (secret->data[0] & 0x80) { // Stored in Big endian
3083 length = secret->length + 1;
3084 uint8_t *tmp = (uint8_t *)wmem_alloc0(tmp_allocator, length);
3085 memcpy(tmp + 1, secret->data, secret->length);
3086 tmp[0] = 0;
3087 secret->data = tmp;
3088 secret->length = length;
3089 }
3090 // Reset array while REKEY: sanitize shared_secret:
3091 global_data->kex_shared_secret = wmem_array_new(wmem_file_scope(), 1);
3092 ssh_hash_buffer_put_string(global_data->kex_shared_secret, secret->data, secret->length);
3093 }
3094
3095 wmem_array_t * kex_gex_p = wmem_array_new(tmp_allocator, 1);
3096 if(global_data->kex_gex_p){ssh_hash_buffer_put_string(kex_gex_p, global_data->kex_gex_p->data, global_data->kex_gex_p->length);}
3097 wmem_array_t * kex_gex_g = wmem_array_new(tmp_allocator, 1);
3098 if(global_data->kex_gex_g){ssh_hash_buffer_put_string(kex_gex_g, global_data->kex_gex_g->data, global_data->kex_gex_g->length);}
3099 wmem_array_t * kex_e = wmem_array_new(tmp_allocator, 1);
3100 if(global_data->kex_e){ssh_hash_buffer_put_string(kex_e, global_data->kex_e->data, global_data->kex_e->length);}
3101 wmem_array_t * kex_f = wmem_array_new(tmp_allocator, 1);
3102 if(global_data->kex_f){ssh_hash_buffer_put_string(kex_f, global_data->kex_f->data, global_data->kex_f->length);}
3103 wmem_array_t * kex_e_pq = wmem_array_new(tmp_allocator, 1);
3104 if(global_data->kex_e_pq){ssh_hash_buffer_put_string(kex_e_pq, global_data->kex_e_pq, global_data->kex_e_pq_len);}
3105 wmem_array_t * kex_f_pq = wmem_array_new(tmp_allocator, 1);
3106 if(global_data->kex_f_pq){ssh_hash_buffer_put_string(kex_f_pq, global_data->kex_f_pq, global_data->kex_f_pq_len);}
3107
3108 wmem_array_t * kex_hash_buffer = wmem_array_new(tmp_allocator, 1);
3109 ssh_print_data("client_version", (const unsigned char *)wmem_array_get_raw(global_data->kex_client_version), wmem_array_get_count(global_data->kex_client_version));
3110 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(global_data->kex_client_version), wmem_array_get_count(global_data->kex_client_version));
3111 ssh_print_data("server_version", (const unsigned char *)wmem_array_get_raw(global_data->kex_server_version), wmem_array_get_count(global_data->kex_server_version));
3112 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(global_data->kex_server_version), wmem_array_get_count(global_data->kex_server_version));
3113 ssh_print_data("client_key_exchange_init", (const unsigned char *)wmem_array_get_raw(global_data->kex_client_key_exchange_init), wmem_array_get_count(global_data->kex_client_key_exchange_init));
3114 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(global_data->kex_client_key_exchange_init), wmem_array_get_count(global_data->kex_client_key_exchange_init));
3115 ssh_print_data("server_key_exchange_init", (const unsigned char *)wmem_array_get_raw(global_data->kex_server_key_exchange_init), wmem_array_get_count(global_data->kex_server_key_exchange_init));
3116 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(global_data->kex_server_key_exchange_init), wmem_array_get_count(global_data->kex_server_key_exchange_init));
3117 ssh_print_data("kex_server_host_key_blob", (const unsigned char *)wmem_array_get_raw(global_data->kex_server_host_key_blob), wmem_array_get_count(global_data->kex_server_host_key_blob));
3118 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(global_data->kex_server_host_key_blob), wmem_array_get_count(global_data->kex_server_host_key_blob));
3119 if(kex_type==SSH_KEX_DH_GEX0x00020000){
3120 ssh_print_data("kex_gex_bits_min", (const unsigned char *)wmem_array_get_raw(global_data->kex_gex_bits_min), wmem_array_get_count(global_data->kex_gex_bits_min));
3121 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(global_data->kex_gex_bits_min), wmem_array_get_count(global_data->kex_gex_bits_min));
3122 ssh_print_data("kex_gex_bits_req", (const unsigned char *)wmem_array_get_raw(global_data->kex_gex_bits_req), wmem_array_get_count(global_data->kex_gex_bits_req));
3123 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(global_data->kex_gex_bits_req), wmem_array_get_count(global_data->kex_gex_bits_req));
3124 ssh_print_data("kex_gex_bits_max", (const unsigned char *)wmem_array_get_raw(global_data->kex_gex_bits_max), wmem_array_get_count(global_data->kex_gex_bits_max));
3125 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(global_data->kex_gex_bits_max), wmem_array_get_count(global_data->kex_gex_bits_max));
3126 ssh_print_data("key modulo (p)", (const unsigned char *)wmem_array_get_raw(kex_gex_p), wmem_array_get_count(kex_gex_p));
3127 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_gex_p), wmem_array_get_count(kex_gex_p));
3128 ssh_print_data("key base (g)", (const unsigned char *)wmem_array_get_raw(kex_gex_g), wmem_array_get_count(kex_gex_g));
3129 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_gex_g), wmem_array_get_count(kex_gex_g));
3130 ssh_print_data("key client (e)", (const unsigned char *)wmem_array_get_raw(kex_e), wmem_array_get_count(kex_e));
3131 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_e), wmem_array_get_count(kex_e));
3132 ssh_print_data("key server (f)", (const unsigned char *)wmem_array_get_raw(kex_f), wmem_array_get_count(kex_f));
3133 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_f), wmem_array_get_count(kex_f));
3134 }
3135 if(kex_type==SSH_KEX_DH_GROUP10x00030001 || kex_type==SSH_KEX_DH_GROUP140x00030014 || kex_type==SSH_KEX_DH_GROUP160x00030016 || kex_type==SSH_KEX_DH_GROUP180x00030018){
3136 ssh_print_data("key client (e)", (const unsigned char *)wmem_array_get_raw(kex_e), wmem_array_get_count(kex_e));
3137 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_e), wmem_array_get_count(kex_e));
3138 ssh_print_data("key server (f)", (const unsigned char *)wmem_array_get_raw(kex_f), wmem_array_get_count(kex_f));
3139 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_f), wmem_array_get_count(kex_f));
3140 }
3141 if(kex_type==SSH_KEX_CURVE255190x00010000){
3142 ssh_print_data("key client (Q_C)", (const unsigned char *)wmem_array_get_raw(kex_e), wmem_array_get_count(kex_e));
3143 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_e), wmem_array_get_count(kex_e));
3144 ssh_print_data("key server (Q_S)", (const unsigned char *)wmem_array_get_raw(kex_f), wmem_array_get_count(kex_f));
3145 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_f), wmem_array_get_count(kex_f));
3146 }
3147 if (kex_type==SSH_KEX_SNTRUP761X255190x00040000){ // Add support of sntrup761x25519
3148 ssh_print_data("key client (Q_C)", (const unsigned char *)wmem_array_get_raw(kex_e_pq), wmem_array_get_count(kex_e_pq));
3149 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_e_pq), wmem_array_get_count(kex_e_pq));
3150 ssh_print_data("key server (Q_S)", (const unsigned char *)wmem_array_get_raw(kex_f_pq), wmem_array_get_count(kex_f_pq));
3151 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_f_pq), wmem_array_get_count(kex_f_pq));
3152 ws_noisy("Switch to SSH_KEX_SNTRUP761X25519")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 3152, __func__, "Switch to SSH_KEX_SNTRUP761X25519"); } } while
(0)
;
3153 }
3154 if (kex_type==SSH_KEX_MLKEM768X255190x00050000){ // Add support of mlkem768x25519
3155 ssh_print_data("key client (Q_C)", (const unsigned char *)wmem_array_get_raw(kex_e_pq), wmem_array_get_count(kex_e_pq));
3156 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_e_pq), wmem_array_get_count(kex_e_pq));
3157 ssh_print_data("key server (Q_S)", (const unsigned char *)wmem_array_get_raw(kex_f_pq), wmem_array_get_count(kex_f_pq));
3158 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(kex_f_pq), wmem_array_get_count(kex_f_pq));
3159 ws_noisy("Switch to SSH_KEX_MLKEM768X25519")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 3159, __func__, "Switch to SSH_KEX_MLKEM768X25519"); } } while
(0)
;
3160 }
3161 ssh_print_data("shared secret", (const unsigned char *)wmem_array_get_raw(global_data->kex_shared_secret), wmem_array_get_count(global_data->kex_shared_secret));
3162 wmem_array_append(kex_hash_buffer, wmem_array_get_raw(global_data->kex_shared_secret), wmem_array_get_count(global_data->kex_shared_secret));
3163
3164 ssh_print_data("exchange", (const unsigned char *)wmem_array_get_raw(kex_hash_buffer), wmem_array_get_count(kex_hash_buffer));
3165
3166 unsigned hash_len = 32;
3167 if(kex_hash_type==SSH_KEX_HASH_SHA11) {
3168 gcry_md_open(&hd, GCRY_MD_SHA1, 0);
3169 hash_len = 20;
3170 } else if(kex_hash_type==SSH_KEX_HASH_SHA2562) {
3171 gcry_md_open(&hd, GCRY_MD_SHA256, 0);
3172 hash_len = 32;
3173 } else if(kex_hash_type==SSH_KEX_HASH_SHA5124) {
3174 gcry_md_open(&hd, GCRY_MD_SHA512, 0);
3175 hash_len = 64;
3176 } else {
3177 ws_debug("kex_hash_type type %d not supported", kex_hash_type)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3177, __func__, "kex_hash_type type %d not supported", kex_hash_type
); } } while (0)
;
3178 return;
3179 }
3180 uint8_t *exchange_hash = (uint8_t *)wmem_alloc0(wmem_file_scope(), hash_len);
3181 gcry_md_write(hd, wmem_array_get_raw(kex_hash_buffer), wmem_array_get_count(kex_hash_buffer));
3182 memcpy(exchange_hash, gcry_md_read(hd, 0), hash_len);
3183 gcry_md_close(hd);
3184 ssh_print_data("hash", exchange_hash, hash_len);
3185 global_data->secret = secret;
3186 ssh_derive_symmetric_keys(secret, exchange_hash, hash_len, global_data);
3187}
3188
3189// the purpose of this function is to deal with all different kex methods
3190static ssh_bignum *
3191ssh_kex_shared_secret(int kex_type, ssh_bignum *pub, ssh_bignum *priv, ssh_bignum *modulo)
3192{
3193 if (pub == NULL((void*)0) || priv == NULL((void*)0)) {
3194 ws_debug("missing public or private key")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3194, __func__, "missing public or private key"); } } while
(0)
;
3195 return NULL((void*)0);
3196 }
3197
3198 ssh_bignum *secret = ssh_kex_make_bignum(NULL((void*)0), pub->length);
3199 if (!secret) {
3200 ws_debug("invalid key length %u", pub->length)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3200, __func__, "invalid key length %u", pub->length); }
} while (0)
;
3201 return NULL((void*)0);
3202 }
3203
3204 if(kex_type==SSH_KEX_DH_GEX0x00020000){
3205 if (modulo == NULL((void*)0)) {
3206 ws_debug("Missing group modulo")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3206, __func__, "Missing group modulo"); } } while (0)
;
3207 return NULL((void*)0);
3208 }
3209 gcry_mpi_t b = NULL((void*)0);
3210 gcry_mpi_scan(&b, GCRYMPI_FMT_USG, pub->data, pub->length, NULL((void*)0));
3211 gcry_mpi_t d = NULL((void*)0), e = NULL((void*)0), m = NULL((void*)0);
3212 size_t result_len = 0;
3213 d = gcry_mpi_new(pub->length*8);
3214 gcry_mpi_scan(&e, GCRYMPI_FMT_USG, priv->data, priv->length, NULL((void*)0));
3215 gcry_mpi_scan(&m, GCRYMPI_FMT_USG, modulo->data, modulo->length, NULL((void*)0));
3216 if (m == NULL((void*)0) || gcry_mpi_cmp_ui(m, 1) <= 0) {
3217 ws_debug("invalid group modulo")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3217, __func__, "invalid group modulo"); } } while (0)
;
3218 gcry_mpi_release(d);
3219 gcry_mpi_release(b);
3220 gcry_mpi_release(e);
3221 gcry_mpi_release(m);
3222 return NULL((void*)0);
3223 }
3224 gcry_mpi_powm(d, b, e, m); // gcry_mpi_powm(d, b, e, m) => d = b^e % m
3225 gcry_mpi_print(GCRYMPI_FMT_USG, secret->data, secret->length, &result_len, d);
3226 secret->length = (unsigned)result_len; // Should not be larger than what fits in a 32-bit unsigned integer...
3227 gcry_mpi_release(d);
3228 gcry_mpi_release(b);
3229 gcry_mpi_release(e);
3230 gcry_mpi_release(m);
3231
3232 }else if(kex_type==SSH_KEX_DH_GROUP10x00030001 || kex_type==SSH_KEX_DH_GROUP140x00030014 || kex_type==SSH_KEX_DH_GROUP160x00030016 || kex_type==SSH_KEX_DH_GROUP180x00030018){
3233 gcry_mpi_t m = NULL((void*)0);
3234 if(kex_type==SSH_KEX_DH_GROUP10x00030001){
3235 static const uint8_t p[] = {
3236 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
3237 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
3238 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
3239 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
3240 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
3241 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
3242 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
3243 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,};
3244 gcry_mpi_scan(&m, GCRYMPI_FMT_USG, p, sizeof(p), NULL((void*)0));
3245 }else if(kex_type==SSH_KEX_DH_GROUP140x00030014){
3246//p:FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF
3247 static const uint8_t p[] = {
3248 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
3249 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
3250 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
3251 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
3252 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
3253 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
3254 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
3255 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
3256 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
3257 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
3258 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
3259 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
3260 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F,
3261 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18,
3262 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
3263 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
3264 gcry_mpi_scan(&m, GCRYMPI_FMT_USG, p, sizeof(p), NULL((void*)0));
3265 }else if(kex_type==SSH_KEX_DH_GROUP160x00030016){
3266//p:FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF
3267 static const uint8_t p[] = {
3268 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
3269 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
3270 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
3271 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
3272 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
3273 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
3274 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
3275 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
3276 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
3277 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
3278 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
3279 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
3280 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F,
3281 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18,
3282 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
3283 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33,
3284 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A,
3285 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7,
3286 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D,
3287 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64,
3288 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C,
3289 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2,
3290 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E,
3291 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01, 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7,
3292 0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, 0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C,
3293 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA, 0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8,
3294 0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9, 0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6,
3295 0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, 0x99, 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2,
3296 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED, 0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF,
3297 0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C, 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9,
3298 0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, 0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F,
3299 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,};
3300 gcry_mpi_scan(&m, GCRYMPI_FMT_USG, p, sizeof(p), NULL((void*)0));
3301 }else if(kex_type==SSH_KEX_DH_GROUP180x00030018){
3302//p:FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E438777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F5683423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD922222E04A4037C0713EB57A81A23F0C73473FC646CEA306B4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A364597E899A0255DC164F31CC50846851DF9AB48195DED7EA1B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F924009438B481C6CD7889A002ED5EE382BC9190DA6FC026E479558E4475677E9AA9E3050E2765694DFC81F56E880B96E7160C980DD98EDD3DFFFFFFFFFFFFFFFFF
3303 static const uint8_t p[] = {
3304 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
3305 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
3306 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
3307 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
3308 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
3309 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
3310 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
3311 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
3312 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
3313 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
3314 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
3315 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
3316 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F,
3317 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18,
3318 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
3319 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D, 0x04, 0x50, 0x7A, 0x33,
3320 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A,
3321 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7,
3322 0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D,
3323 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64,
3324 0xD8, 0x76, 0x02, 0x73, 0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C,
3325 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 0xE2,
3326 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, 0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E,
3327 0x4B, 0x82, 0xD1, 0x20, 0xA9, 0x21, 0x08, 0x01, 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7,
3328 0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, 0x99, 0xC3, 0x27, 0x18, 0x6A, 0xF4, 0xE2, 0x3C,
3329 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA, 0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8,
3330 0xDB, 0xBB, 0xC2, 0xDB, 0x04, 0xDE, 0x8E, 0xF9, 0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6,
3331 0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, 0x99, 0xB2, 0x96, 0x4F, 0xA0, 0x90, 0xC3, 0xA2,
3332 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED, 0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF,
3333 0xB8, 0x1B, 0xDD, 0x76, 0x21, 0x70, 0x48, 0x1C, 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9,
3334 0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, 0x86, 0xFF, 0xB7, 0xDC, 0x90, 0xA6, 0xC0, 0x8F,
3335 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x02, 0x84, 0x92, 0x36, 0xC3, 0xFA, 0xB4, 0xD2, 0x7C, 0x70, 0x26,
3336 0xC1, 0xD4, 0xDC, 0xB2, 0x60, 0x26, 0x46, 0xDE, 0xC9, 0x75, 0x1E, 0x76, 0x3D, 0xBA, 0x37, 0xBD,
3337 0xF8, 0xFF, 0x94, 0x06, 0xAD, 0x9E, 0x53, 0x0E, 0xE5, 0xDB, 0x38, 0x2F, 0x41, 0x30, 0x01, 0xAE,
3338 0xB0, 0x6A, 0x53, 0xED, 0x90, 0x27, 0xD8, 0x31, 0x17, 0x97, 0x27, 0xB0, 0x86, 0x5A, 0x89, 0x18,
3339 0xDA, 0x3E, 0xDB, 0xEB, 0xCF, 0x9B, 0x14, 0xED, 0x44, 0xCE, 0x6C, 0xBA, 0xCE, 0xD4, 0xBB, 0x1B,
3340 0xDB, 0x7F, 0x14, 0x47, 0xE6, 0xCC, 0x25, 0x4B, 0x33, 0x20, 0x51, 0x51, 0x2B, 0xD7, 0xAF, 0x42,
3341 0x6F, 0xB8, 0xF4, 0x01, 0x37, 0x8C, 0xD2, 0xBF, 0x59, 0x83, 0xCA, 0x01, 0xC6, 0x4B, 0x92, 0xEC,
3342 0xF0, 0x32, 0xEA, 0x15, 0xD1, 0x72, 0x1D, 0x03, 0xF4, 0x82, 0xD7, 0xCE, 0x6E, 0x74, 0xFE, 0xF6,
3343 0xD5, 0x5E, 0x70, 0x2F, 0x46, 0x98, 0x0C, 0x82, 0xB5, 0xA8, 0x40, 0x31, 0x90, 0x0B, 0x1C, 0x9E,
3344 0x59, 0xE7, 0xC9, 0x7F, 0xBE, 0xC7, 0xE8, 0xF3, 0x23, 0xA9, 0x7A, 0x7E, 0x36, 0xCC, 0x88, 0xBE,
3345 0x0F, 0x1D, 0x45, 0xB7, 0xFF, 0x58, 0x5A, 0xC5, 0x4B, 0xD4, 0x07, 0xB2, 0x2B, 0x41, 0x54, 0xAA,
3346 0xCC, 0x8F, 0x6D, 0x7E, 0xBF, 0x48, 0xE1, 0xD8, 0x14, 0xCC, 0x5E, 0xD2, 0x0F, 0x80, 0x37, 0xE0,
3347 0xA7, 0x97, 0x15, 0xEE, 0xF2, 0x9B, 0xE3, 0x28, 0x06, 0xA1, 0xD5, 0x8B, 0xB7, 0xC5, 0xDA, 0x76,
3348 0xF5, 0x50, 0xAA, 0x3D, 0x8A, 0x1F, 0xBF, 0xF0, 0xEB, 0x19, 0xCC, 0xB1, 0xA3, 0x13, 0xD5, 0x5C,
3349 0xDA, 0x56, 0xC9, 0xEC, 0x2E, 0xF2, 0x96, 0x32, 0x38, 0x7F, 0xE8, 0xD7, 0x6E, 0x3C, 0x04, 0x68,
3350 0x04, 0x3E, 0x8F, 0x66, 0x3F, 0x48, 0x60, 0xEE, 0x12, 0xBF, 0x2D, 0x5B, 0x0B, 0x74, 0x74, 0xD6,
3351 0xE6, 0x94, 0xF9, 0x1E, 0x6D, 0xBE, 0x11, 0x59, 0x74, 0xA3, 0x92, 0x6F, 0x12, 0xFE, 0xE5, 0xE4,
3352 0x38, 0x77, 0x7C, 0xB6, 0xA9, 0x32, 0xDF, 0x8C, 0xD8, 0xBE, 0xC4, 0xD0, 0x73, 0xB9, 0x31, 0xBA,
3353 0x3B, 0xC8, 0x32, 0xB6, 0x8D, 0x9D, 0xD3, 0x00, 0x74, 0x1F, 0xA7, 0xBF, 0x8A, 0xFC, 0x47, 0xED,
3354 0x25, 0x76, 0xF6, 0x93, 0x6B, 0xA4, 0x24, 0x66, 0x3A, 0xAB, 0x63, 0x9C, 0x5A, 0xE4, 0xF5, 0x68,
3355 0x34, 0x23, 0xB4, 0x74, 0x2B, 0xF1, 0xC9, 0x78, 0x23, 0x8F, 0x16, 0xCB, 0xE3, 0x9D, 0x65, 0x2D,
3356 0xE3, 0xFD, 0xB8, 0xBE, 0xFC, 0x84, 0x8A, 0xD9, 0x22, 0x22, 0x2E, 0x04, 0xA4, 0x03, 0x7C, 0x07,
3357 0x13, 0xEB, 0x57, 0xA8, 0x1A, 0x23, 0xF0, 0xC7, 0x34, 0x73, 0xFC, 0x64, 0x6C, 0xEA, 0x30, 0x6B,
3358 0x4B, 0xCB, 0xC8, 0x86, 0x2F, 0x83, 0x85, 0xDD, 0xFA, 0x9D, 0x4B, 0x7F, 0xA2, 0xC0, 0x87, 0xE8,
3359 0x79, 0x68, 0x33, 0x03, 0xED, 0x5B, 0xDD, 0x3A, 0x06, 0x2B, 0x3C, 0xF5, 0xB3, 0xA2, 0x78, 0xA6,
3360 0x6D, 0x2A, 0x13, 0xF8, 0x3F, 0x44, 0xF8, 0x2D, 0xDF, 0x31, 0x0E, 0xE0, 0x74, 0xAB, 0x6A, 0x36,
3361 0x45, 0x97, 0xE8, 0x99, 0xA0, 0x25, 0x5D, 0xC1, 0x64, 0xF3, 0x1C, 0xC5, 0x08, 0x46, 0x85, 0x1D,
3362 0xF9, 0xAB, 0x48, 0x19, 0x5D, 0xED, 0x7E, 0xA1, 0xB1, 0xD5, 0x10, 0xBD, 0x7E, 0xE7, 0x4D, 0x73,
3363 0xFA, 0xF3, 0x6B, 0xC3, 0x1E, 0xCF, 0xA2, 0x68, 0x35, 0x90, 0x46, 0xF4, 0xEB, 0x87, 0x9F, 0x92,
3364 0x40, 0x09, 0x43, 0x8B, 0x48, 0x1C, 0x6C, 0xD7, 0x88, 0x9A, 0x00, 0x2E, 0xD5, 0xEE, 0x38, 0x2B,
3365 0xC9, 0x19, 0x0D, 0xA6, 0xFC, 0x02, 0x6E, 0x47, 0x95, 0x58, 0xE4, 0x47, 0x56, 0x77, 0xE9, 0xAA,
3366 0x9E, 0x30, 0x50, 0xE2, 0x76, 0x56, 0x94, 0xDF, 0xC8, 0x1F, 0x56, 0xE8, 0x80, 0xB9, 0x6E, 0x71,
3367 0x60, 0xC9, 0x80, 0xDD, 0x98, 0xED, 0xD3, 0xDF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,};
3368 gcry_mpi_scan(&m, GCRYMPI_FMT_USG, p, sizeof(p), NULL((void*)0));
3369 }
3370
3371 gcry_mpi_t b = NULL((void*)0);
3372 gcry_mpi_scan(&b, GCRYMPI_FMT_USG, pub->data, pub->length, NULL((void*)0));
3373 gcry_mpi_t d = NULL((void*)0), e = NULL((void*)0);
3374 size_t result_len = 0;
3375 d = gcry_mpi_new(pub->length*8);
3376 gcry_mpi_scan(&e, GCRYMPI_FMT_USG, priv->data, priv->length, NULL((void*)0));
3377 gcry_mpi_powm(d, b, e, m); // gcry_mpi_powm(d, b, e, m) => d = b^e % m
3378 gcry_mpi_print(GCRYMPI_FMT_USG, secret->data, secret->length, &result_len, d);
3379 secret->length = (unsigned)result_len; // Should not be larger than what fits in a 32-bit unsigned integer...
3380 gcry_mpi_release(d);
3381 gcry_mpi_release(b);
3382 gcry_mpi_release(e);
3383 gcry_mpi_release(m);
3384 }else if(kex_type==SSH_KEX_CURVE255190x00010000){
3385 if (priv->length != 32 || pub->length != 32) {
3386 ws_debug("curve25519: bad key length pub=%u or priv=%u != 32", pub->length, priv->length)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3386, __func__, "curve25519: bad key length pub=%u or priv=%u != 32"
, pub->length, priv->length); } } while (0)
;
3387 return NULL((void*)0);
3388 }
3389 if (crypto_scalarmult_curve25519(secret->data, priv->data, pub->data)) {
3390 ws_debug("curve25519: can't compute shared secret")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3390, __func__, "curve25519: can't compute shared secret");
} } while (0)
;
3391 return NULL((void*)0);
3392 }
3393 } else {
3394 ws_debug("kex_type type %d not supported", kex_type)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3394, __func__, "kex_type type %d not supported", kex_type)
; } } while (0)
;
3395 return 0;
3396 }
3397
3398 return secret;
3399}
3400
3401static char *
3402ssh_string(wmem_allocator_t* allocator, const uint8_t *string, unsigned length)
3403{
3404 char *ssh_string = (char *)wmem_alloc(allocator, length + 4);
3405 ssh_string[0] = (length >> 24) & 0xff;
3406 ssh_string[1] = (length >> 16) & 0xff;
3407 ssh_string[2] = (length >> 8) & 0xff;
3408 ssh_string[3] = length & 0xff;
3409 memcpy(ssh_string + 4, string, length);
3410 return ssh_string;
3411}
3412
3413static void
3414ssh_hash_buffer_put_string(wmem_array_t *buffer, const uint8_t *string,
3415 unsigned length)
3416{
3417 if (!buffer) {
3418 return;
3419 }
3420
3421 char *string_with_length = ssh_string(wmem_array_get_allocator(buffer), string, length);
3422 wmem_array_append(buffer, string_with_length, length + 4);
3423}
3424
3425static void
3426ssh_hash_buffer_put_uint32(wmem_array_t *buffer, unsigned val)
3427{
3428 if (!buffer) {
3429 return;
3430 }
3431
3432 char buf[4];
3433 buf[0] = (val >> 24); buf[1] = (val >> 16); buf[2] = (val >> 8); buf[3] = (val >> 0);
3434 wmem_array_append(buffer, buf, 4);
3435}
3436
3437static void ssh_derive_symmetric_keys(ssh_bignum *secret, uint8_t *exchange_hash,
3438 unsigned hash_length, struct ssh_flow_data *global_data)
3439{
3440 if (!global_data->session_id) {
3441 global_data->session_id = exchange_hash;
3442 global_data->session_id_length = hash_length;
3443 }
3444
3445 unsigned int we_need = 0;
3446 for(int peer_cnt=0;peer_cnt<2;peer_cnt++){
3447 struct ssh_peer_data * peer_data = &global_data->peer_data[peer_cnt];
3448 // required size of key depends on cipher used. chacha20 wants 64 bytes
3449 unsigned need = 0;
3450 if (GCRY_CIPHER_CHACHA20 == peer_data->cipher_id) {
3451 need = 64;
3452 } else if (CIPHER_AES128_CBC0x00020001 == peer_data->cipher_id || CIPHER_AES128_CTR0x00010001 == peer_data->cipher_id || CIPHER_AES128_GCM0x00040001 == peer_data->cipher_id) {
3453 need = 16;
3454 } else if (CIPHER_AES192_CBC0x00020002 == peer_data->cipher_id || CIPHER_AES192_CTR0x00010003 == peer_data->cipher_id) {
3455 need = 24;
3456 } else if (CIPHER_AES256_CBC0x00020004 == peer_data->cipher_id || CIPHER_AES256_CTR0x00010004 == peer_data->cipher_id || CIPHER_AES256_GCM0x00040004 == peer_data->cipher_id) {
3457 need = 32;
3458 } else {
3459 ssh_debug_printf("ssh: cipher (%d) is unknown or not set\n", peer_data->cipher_id);
3460 ssh_debug_flush();
3461 }
3462 if(peer_data->mac_id == CIPHER_MAC_SHA2_2560x00020001){
3463 if (need < 32) {
3464 need = 32;
3465 }
3466 }else{
3467 ssh_debug_printf("ssh: MAC (%d) is unknown or not set\n", peer_data->mac_id);
3468 ssh_debug_flush();
3469 }
3470 if (we_need<need) {
3471 we_need = need;
3472 }
3473 }
3474
3475 for (int i = 0; i < 6; i ++) {
3476 ssh_derive_symmetric_key(secret, exchange_hash, hash_length,
3477 'A' + i, &global_data->new_keys[i], global_data, we_need);
3478 if(i==0){ ssh_print_data("Initial IV client to server", global_data->new_keys[i].data, global_data->new_keys[i].length);
3479 }else if(i==1){ ssh_print_data("Initial IV server to client", global_data->new_keys[i].data, global_data->new_keys[i].length);
3480 }else if(i==2){ ssh_print_data("Encryption key client to server", global_data->new_keys[i].data, global_data->new_keys[i].length);
3481 }else if(i==3){ ssh_print_data("Encryption key server to client", global_data->new_keys[i].data, global_data->new_keys[i].length);
3482 }else if(i==4){ ssh_print_data("Integrity key client to server", global_data->new_keys[i].data, global_data->new_keys[i].length);
3483 }else if(i==5){ ssh_print_data("Integrity key server to client", global_data->new_keys[i].data, global_data->new_keys[i].length);
3484 }
3485 }
3486}
3487
3488static void ssh_derive_symmetric_key(ssh_bignum *secret, const uint8_t *exchange_hash,
3489 unsigned hash_length, char id, ssh_bignum *result_key,
3490 struct ssh_flow_data *global_data, unsigned we_need)
3491{
3492 gcry_md_hd_t hd;
3493
3494 unsigned kex_hash_type = ssh_kex_hash_type(global_data->kex);
3495 int algo = GCRY_MD_SHA256;
3496 if(kex_hash_type==SSH_KEX_HASH_SHA11){
3497 algo = GCRY_MD_SHA1;
3498 }else if(kex_hash_type==SSH_KEX_HASH_SHA2562){
3499 algo = GCRY_MD_SHA256;
3500 }else if(kex_hash_type==SSH_KEX_HASH_SHA5124){
3501 algo = GCRY_MD_SHA512;
3502 }
3503 unsigned len = gcry_md_get_algo_dlen(algo);
3504
3505 result_key->data = (unsigned char *)wmem_alloc(wmem_file_scope(), we_need);
3506
3507 char *secret_with_length = ssh_string(NULL((void*)0), secret->data, secret->length);
3508
3509 if (gcry_md_open(&hd, algo, 0) == 0) {
3510 gcry_md_write(hd, secret_with_length, secret->length + 4);
3511 gcry_md_write(hd, exchange_hash, hash_length);
3512 gcry_md_putc(hd, id)do { gcry_md_hd_t h__ = (hd); if( (h__)->bufpos == (h__)->
bufsize ) gcry_md_write( (h__), ((void*)0), 0 ); (h__)->buf
[(h__)->bufpos++] = (id) & 0xff; } while(0)
;
3513 gcry_md_write(hd, global_data->session_id, hash_length);
3514 unsigned add_length = MIN(len, we_need)(((len) < (we_need)) ? (len) : (we_need));
3515 memcpy(result_key->data, gcry_md_read(hd, 0), add_length);
3516 gcry_md_close(hd);
3517 }
3518
3519 // expand key
3520 for (unsigned have = len; have < we_need; have += len) {
3521 if (gcry_md_open(&hd, algo, 0) == 0) {
3522 gcry_md_write(hd, secret_with_length, secret->length + 4);
3523 gcry_md_write(hd, exchange_hash, hash_length);
3524 gcry_md_write(hd, result_key->data+have-len, len);
3525 unsigned add_length = MIN(len, we_need - have)(((len) < (we_need - have)) ? (len) : (we_need - have));
3526 memcpy(result_key->data+have, gcry_md_read(hd, 0), add_length);
3527 gcry_md_close(hd);
3528 }
3529 }
3530 wmem_free(NULL((void*)0), secret_with_length);
3531
3532 result_key->length = we_need;
3533}
3534
3535static void
3536ssh_choose_enc_mac(struct ssh_flow_data *global_data)
3537{
3538 for(int peer_cnt=0;peer_cnt<2;peer_cnt++){
3539 struct ssh_peer_data * peer_data = &global_data->peer_data[peer_cnt];
3540 ssh_choose_algo(global_data->peer_data[CLIENT_PEER_DATA0].enc_proposals[peer_cnt],
3541 global_data->peer_data[SERVER_PEER_DATA1].enc_proposals[peer_cnt],
3542 &peer_data->enc);
3543 /* some ciphers have their own MAC so the "negotiated" one is meaningless */
3544 if(peer_data->enc && (0 == strcmp(peer_data->enc, "[email protected]") ||
3545 0 == strcmp(peer_data->enc, "[email protected]"))) {
3546 peer_data->mac = wmem_strdup(wmem_file_scope(), (const char *)"<implicit>");
3547 peer_data->mac_length = 16;
3548 peer_data->length_is_plaintext = 1;
3549 }
3550 else if(peer_data->enc && 0 == strcmp(peer_data->enc, "[email protected]")) {
3551 peer_data->mac = wmem_strdup(wmem_file_scope(), (const char *)"<implicit>");
3552 peer_data->mac_length = 16;
3553 }
3554 else {
3555 ssh_choose_algo(global_data->peer_data[CLIENT_PEER_DATA0].mac_proposals[peer_cnt],
3556 global_data->peer_data[SERVER_PEER_DATA1].mac_proposals[peer_cnt],
3557 &peer_data->mac);
3558 ssh_set_mac_length(peer_data);
3559 }
3560 ssh_choose_algo(global_data->peer_data[CLIENT_PEER_DATA0].comp_proposals[peer_cnt],
3561 global_data->peer_data[SERVER_PEER_DATA1].comp_proposals[peer_cnt],
3562 &peer_data->comp);
3563 }
3564
3565 ssh_decryption_set_cipher_id(&global_data->peer_data[CLIENT_PEER_DATA0]);
3566 ssh_decryption_set_mac_id(&global_data->peer_data[CLIENT_PEER_DATA0]);
3567 ssh_decryption_set_cipher_id(&global_data->peer_data[SERVER_PEER_DATA1]);
3568 ssh_decryption_set_mac_id(&global_data->peer_data[SERVER_PEER_DATA1]);
3569}
3570
3571static void
3572ssh_decryption_set_cipher_id(struct ssh_peer_data *peer)
3573{
3574 char *cipher_name = peer->enc;
3575
3576 if (!cipher_name) {
3577 peer->cipher = NULL((void*)0);
3578 ws_debug("ERROR: cipher_name is NULL")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3578, __func__, "ERROR: cipher_name is NULL"); } } while (0
)
;
3579 } else if (0 == strcmp(cipher_name, "[email protected]")) { // add [email protected]
3580 peer->cipher_id = GCRY_CIPHER_CHACHA20;
3581 } else if (0 == strcmp(cipher_name, "chacha20-poly1305")) { // add chacha20-poly1305
3582 peer->cipher_id = GCRY_CIPHER_CHACHA20;
3583 } else if (0 == strcmp(cipher_name, "[email protected]")) {
3584 peer->cipher_id = CIPHER_AES128_GCM0x00040001;
3585 } else if (0 == strcmp(cipher_name, "aes128-gcm")) {
3586 peer->cipher_id = CIPHER_AES128_GCM0x00040001;
3587 } else if (0 == strcmp(cipher_name, "[email protected]")) {
3588 peer->cipher_id = CIPHER_AES256_GCM0x00040004;
3589 } else if (0 == strcmp(cipher_name, "aes256-gcm")) {
3590 peer->cipher_id = CIPHER_AES256_GCM0x00040004;
3591 } else if (0 == strcmp(cipher_name, "aes128-cbc")) {
3592 peer->cipher_id = CIPHER_AES128_CBC0x00020001;
3593 } else if (0 == strcmp(cipher_name, "aes192-cbc")) {
3594 peer->cipher_id = CIPHER_AES192_CBC0x00020002;
3595 } else if (0 == strcmp(cipher_name, "aes256-cbc")) {
3596 peer->cipher_id = CIPHER_AES256_CBC0x00020004;
3597 } else if (0 == strcmp(cipher_name, "aes128-ctr")) {
3598 peer->cipher_id = CIPHER_AES128_CTR0x00010001;
3599 } else if (0 == strcmp(cipher_name, "aes192-ctr")) {
3600 peer->cipher_id = CIPHER_AES192_CTR0x00010003;
3601 } else if (0 == strcmp(cipher_name, "aes256-ctr")) {
3602 peer->cipher_id = CIPHER_AES256_CTR0x00010004;
3603 } else if (0 == strcmp(cipher_name, "none")) {
3604 peer->cipher_id = CIPHER_NULL0x00080000;
3605 peer->length_is_plaintext = 1;
3606 } else {
3607 peer->cipher = NULL((void*)0);
3608 ws_debug("decryption not supported: %s", cipher_name)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3608, __func__, "decryption not supported: %s", cipher_name
); } } while (0)
;
3609 }
3610}
3611
3612static void
3613ssh_decryption_set_mac_id(struct ssh_peer_data *peer)
3614{
3615 char *mac_name = peer->mac;
3616
3617 if (!mac_name) {
3618 peer->mac = NULL((void*)0);
3619 ws_debug("ERROR: mac_name is NULL")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3619, __func__, "ERROR: mac_name is NULL"); } } while (0)
;
3620 } else if (0 == strcmp(mac_name, "hmac-sha2-256")) {
3621 peer->mac_id = CIPHER_MAC_SHA2_2560x00020001;
3622 } else {
3623 ws_debug("decryption MAC not supported: %s", mac_name)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3623, __func__, "decryption MAC not supported: %s", mac_name
); } } while (0)
;
3624 }
3625}
3626
3627static bool_Bool
3628gcry_cipher_destroy_cb(wmem_allocator_t *allocator _U___attribute__((unused)), wmem_cb_event_t event _U___attribute__((unused)), void *user_data)
3629{
3630 gcry_cipher_hd_t hd = (gcry_cipher_hd_t)user_data;
3631
3632 gcry_cipher_close(hd);
3633
3634 return false0;
3635}
3636
3637static void
3638ssh_decryption_setup_cipher(struct ssh_peer_data *peer_data,
3639 ssh_bignum *iv, ssh_bignum *key)
3640{
3641 gcry_error_t err;
3642 gcry_cipher_hd_t *hd1, *hd2;
3643
3644 hd1 = &peer_data->cipher;
3645 hd2 = &peer_data->cipher_2;
3646
3647 if (GCRY_CIPHER_CHACHA20 == peer_data->cipher_id) {
3648 if (gcry_cipher_open(hd1, GCRY_CIPHER_CHACHA20, GCRY_CIPHER_MODE_STREAM, 0) ||
3649 gcry_cipher_open(hd2, GCRY_CIPHER_CHACHA20, GCRY_CIPHER_MODE_STREAM, 0)) {
3650 gcry_cipher_close(*hd1);
3651 gcry_cipher_close(*hd2);
3652 ws_debug("ssh: can't open chacha20 cipher handles")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3652, __func__, "ssh: can't open chacha20 cipher handles");
} } while (0)
;
3653 return;
3654 }
3655
3656 uint8_t k1[32];
3657 uint8_t k2[32];
3658 if(key->data && key->length >= 64){
3659 memcpy(k1, key->data, 32);
3660 memcpy(k2, key->data + 32, 32);
3661 }else{
3662 memset(k1, 0, 32);
3663 memset(k2, 0, 32);
3664 }
3665
3666 ssh_debug_printf("ssh: cipher is chacha20\n");
3667 ssh_print_data("key 1", k1, 32);
3668 ssh_print_data("key 2", k2, 32);
3669
3670 if ((err = gcry_cipher_setkey(*hd1, k1, 32))) {
3671 gcry_cipher_close(*hd1);
3672 ws_debug("ssh: can't set chacha20 cipher key %s", gcry_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3672, __func__, "ssh: can't set chacha20 cipher key %s", gcry_strerror
(err)); } } while (0)
;
3673 return;
3674 }
3675
3676 if ((err = gcry_cipher_setkey(*hd2, k2, 32))) {
3677 gcry_cipher_close(*hd1);
3678 gcry_cipher_close(*hd2);
3679 ws_debug("ssh: can't set chacha20 cipher key %s", gcry_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3679, __func__, "ssh: can't set chacha20 cipher key %s", gcry_strerror
(err)); } } while (0)
;
3680 return;
3681 }
3682
3683 wmem_register_callback(wmem_file_scope(), gcry_cipher_destroy_cb, *hd1);
3684 wmem_register_callback(wmem_file_scope(), gcry_cipher_destroy_cb, *hd2);
3685
3686 } else if (CIPHER_AES128_CBC0x00020001 == peer_data->cipher_id || CIPHER_AES192_CBC0x00020002 == peer_data->cipher_id || CIPHER_AES256_CBC0x00020004 == peer_data->cipher_id) {
3687 int iKeyLen = CIPHER_AES128_CBC0x00020001 == peer_data->cipher_id?16:CIPHER_AES192_CBC0x00020002 == peer_data->cipher_id?24:32;
3688 if (gcry_cipher_open(hd1, CIPHER_AES128_CBC0x00020001 == peer_data->cipher_id?GCRY_CIPHER_AES128GCRY_CIPHER_AES:CIPHER_AES192_CBC0x00020002 == peer_data->cipher_id?GCRY_CIPHER_AES192:GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC, 0)) {
3689 gcry_cipher_close(*hd1);
3690 ws_debug("ssh: can't open aes%d cipher handle", iKeyLen*8)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3690, __func__, "ssh: can't open aes%d cipher handle", iKeyLen
*8); } } while (0)
;
3691 return;
3692 }
3693 uint8_t k1[32], iv1[16];
3694 if(key->data){
3695 memcpy(k1, key->data, iKeyLen);
3696 }else{
3697 memset(k1, 0, iKeyLen);
3698 }
3699 if(iv->data){
3700 memcpy(iv1, iv->data, 16);
3701 }else{
3702 memset(iv1, 0, 16);
3703 }
3704
3705 ssh_debug_printf("ssh: cipher is aes%d-cbc\n", iKeyLen*8);
3706 ssh_print_data("key", k1, iKeyLen);
3707 ssh_print_data("iv", iv1, 16);
3708
3709 if ((err = gcry_cipher_setkey(*hd1, k1, iKeyLen))) {
3710 gcry_cipher_close(*hd1);
3711 ws_debug("ssh: can't set aes%d cipher key", iKeyLen*8)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3711, __func__, "ssh: can't set aes%d cipher key", iKeyLen*
8); } } while (0)
;
3712 ws_debug("libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource(err), gcry_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3712, __func__, "libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource
(err), gcry_strerror(err)); } } while (0)
;
3713 return;
3714 }
3715
3716 if ((err = gcry_cipher_setiv(*hd1, iv1, 16))) {
3717 gcry_cipher_close(*hd1);
3718 ws_debug("ssh: can't set aes%d cipher iv", iKeyLen*8)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3718, __func__, "ssh: can't set aes%d cipher iv", iKeyLen*8
); } } while (0)
;
3719 ws_debug("libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource(err), gcry_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3719, __func__, "libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource
(err), gcry_strerror(err)); } } while (0)
;
3720 return;
3721 }
3722
3723 wmem_register_callback(wmem_file_scope(), gcry_cipher_destroy_cb, *hd1);
3724
3725 } else if (CIPHER_AES128_CTR0x00010001 == peer_data->cipher_id || CIPHER_AES192_CTR0x00010003 == peer_data->cipher_id || CIPHER_AES256_CTR0x00010004 == peer_data->cipher_id) {
3726 int iKeyLen = CIPHER_AES128_CTR0x00010001 == peer_data->cipher_id?16:CIPHER_AES192_CTR0x00010003 == peer_data->cipher_id?24:32;
3727 if (gcry_cipher_open(hd1, CIPHER_AES128_CTR0x00010001 == peer_data->cipher_id?GCRY_CIPHER_AES128GCRY_CIPHER_AES:CIPHER_AES192_CTR0x00010003 == peer_data->cipher_id?GCRY_CIPHER_AES192:GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CTR, 0)) {
3728 gcry_cipher_close(*hd1);
3729 ws_debug("ssh: can't open aes%d cipher handle", iKeyLen*8)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3729, __func__, "ssh: can't open aes%d cipher handle", iKeyLen
*8); } } while (0)
;
3730 return;
3731 }
3732 uint8_t k1[32], iv1[16];
3733 if(key->data){
3734 memcpy(k1, key->data, iKeyLen);
3735 }else{
3736 memset(k1, 0, iKeyLen);
3737 }
3738 if(iv->data){
3739 memcpy(iv1, iv->data, 16);
3740 }else{
3741 memset(iv1, 0, 16);
3742 }
3743
3744 ssh_debug_printf("ssh: cipher is aes%d-ctr\n", iKeyLen*8);
3745 ssh_print_data("key", k1, iKeyLen);
3746 ssh_print_data("iv", iv1, 16);
3747
3748 if ((err = gcry_cipher_setkey(*hd1, k1, iKeyLen))) {
3749 gcry_cipher_close(*hd1);
3750 ws_debug("ssh: can't set aes%d cipher key", iKeyLen*8)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3750, __func__, "ssh: can't set aes%d cipher key", iKeyLen*
8); } } while (0)
;
3751 ws_debug("libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource(err), gcry_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3751, __func__, "libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource
(err), gcry_strerror(err)); } } while (0)
;
3752 return;
3753 }
3754
3755 if ((err = gcry_cipher_setctr(*hd1, iv1, 16))) {
3756 gcry_cipher_close(*hd1);
3757 ws_debug("ssh: can't set aes%d cipher iv", iKeyLen*8)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3757, __func__, "ssh: can't set aes%d cipher iv", iKeyLen*8
); } } while (0)
;
3758 ws_debug("libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource(err), gcry_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3758, __func__, "libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource
(err), gcry_strerror(err)); } } while (0)
;
3759 return;
3760 }
3761
3762 wmem_register_callback(wmem_file_scope(), gcry_cipher_destroy_cb, *hd1);
3763
3764 } else if (CIPHER_AES128_GCM0x00040001 == peer_data->cipher_id || CIPHER_AES256_GCM0x00040004 == peer_data->cipher_id) {
3765 int iKeyLen = CIPHER_AES128_GCM0x00040001 == peer_data->cipher_id?16:32;
3766 if (gcry_cipher_open(hd1, CIPHER_AES128_GCM0x00040001 == peer_data->cipher_id?GCRY_CIPHER_AES128GCRY_CIPHER_AES:GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_GCM, 0)) {
3767 gcry_cipher_close(*hd1);
3768 ws_debug("ssh: can't open aes%d cipher handle", iKeyLen*8)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3768, __func__, "ssh: can't open aes%d cipher handle", iKeyLen
*8); } } while (0)
;
3769 return;
3770 }
3771
3772 uint8_t k1[32], iv2[12];
3773 if(key->data){
3774 memcpy(k1, key->data, iKeyLen);
3775 }else{
3776 memset(k1, 0, iKeyLen);
3777 }
3778 if(iv->data){
3779 memcpy(peer_data->iv, iv->data, 12);
3780 }else{
3781 memset(iv2, 0, 12);
3782 }
3783
3784 ssh_debug_printf("ssh: cipher is aes%d-gcm\n", iKeyLen*8);
3785 ssh_print_data("key", k1, iKeyLen);
3786 ssh_print_data("iv", peer_data->iv, 12);
3787
3788 if ((err = gcry_cipher_setkey(*hd1, k1, iKeyLen))) {
3789 gcry_cipher_close(*hd1);
3790 ws_debug("ssh: can't set aes%d cipher key", iKeyLen*8)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3790, __func__, "ssh: can't set aes%d cipher key", iKeyLen*
8); } } while (0)
;
3791 ws_debug("libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource(err), gcry_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3791, __func__, "libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource
(err), gcry_strerror(err)); } } while (0)
;
3792 return;
3793 }
3794
3795 wmem_register_callback(wmem_file_scope(), gcry_cipher_destroy_cb, *hd1);
3796
3797 } else {
3798 ssh_debug_printf("ssh: cipher (%d) is unknown or not set\n", peer_data->cipher_id);
3799 }
3800}
3801
3802static void
3803ssh_decryption_setup_mac(struct ssh_peer_data *peer_data,
3804 ssh_bignum *iv)
3805{
3806 if(peer_data->mac_id == CIPHER_MAC_SHA2_2560x00020001){
3807 if(iv->data){
3808 memcpy(peer_data->hmac_iv, iv->data, 32);
3809 }else{
3810 memset(peer_data->hmac_iv, 0, 32);
3811 }
3812 peer_data->hmac_iv_len = 32;
3813 ssh_debug_printf("ssh: mac is hmac-sha2-256\n");
3814 ssh_print_data("iv", peer_data->hmac_iv, peer_data->hmac_iv_len);
3815 }else{
3816 ws_debug("ssh: unsupported MAC")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3816, __func__, "ssh: unsupported MAC"); } } while (0)
;
3817 }
3818}
3819
3820/* libgcrypt wrappers for HMAC/message digest operations {{{ */
3821/* hmac abstraction layer */
3822#define SSH_HMACgcry_md_hd_t gcry_md_hd_t
3823
3824static inline int
3825ssh_hmac_init(SSH_HMACgcry_md_hd_t* md, const void * key, int len, int algo)
3826{
3827 gcry_error_t err;
3828 const char *err_str, *err_src;
3829
3830 err = gcry_md_open(md,algo, GCRY_MD_FLAG_HMAC);
3831 if (err != 0) {
3832 err_str = gcry_strerror(err);
3833 err_src = gcry_strsource(err);
3834 ssh_debug_printf("ssh_hmac_init(): gcry_md_open failed %s/%s", err_str, err_src);
3835 return -1;
3836 }
3837 err = gcry_md_setkey(*(md), key, len);
3838 if (err != 0) {
3839 err_str = gcry_strerror(err);
3840 err_src = gcry_strsource(err);
3841 ssh_debug_printf("ssh_hmac_init(): gcry_md_setkey(..., ..., %d) failed %s/%s", len, err_str, err_src);
3842 return -1;
3843 }
3844 return 0;
3845}
3846
3847static inline void
3848ssh_hmac_update(SSH_HMACgcry_md_hd_t* md, const void* data, int len)
3849{
3850 gcry_md_write(*(md), data, len);
3851}
3852
3853static inline void
3854ssh_hmac_final(SSH_HMACgcry_md_hd_t* md, unsigned char* data, unsigned* datalen)
3855{
3856 int algo;
3857 unsigned len;
3858
3859 algo = gcry_md_get_algo (*(md));
3860 len = gcry_md_get_algo_dlen(algo);
3861 DISSECTOR_ASSERT(len <= *datalen)((void) ((len <= *datalen) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-ssh.c"
, 3861, "len <= *datalen"))))
;
3862 memcpy(data, gcry_md_read(*(md), algo), len);
3863 *datalen = len;
3864}
3865
3866static inline void
3867ssh_hmac_cleanup(SSH_HMACgcry_md_hd_t* md)
3868{
3869 gcry_md_close(*(md));
3870}
3871/* libgcrypt wrappers for HMAC/message digest operations }}} */
3872
3873/* Decryption integrity check {{{ */
3874
3875static int
3876ssh_get_digest_by_id(unsigned mac_id)
3877{
3878 if(mac_id==CIPHER_MAC_SHA2_2560x00020001){
3879 return GCRY_MD_SHA256;
3880 }
3881 return -1;
3882}
3883
3884static void
3885ssh_calc_mac(struct ssh_peer_data *peer_data, uint32_t seqnr, uint8_t* data, uint32_t datalen, uint8_t* calc_mac)
3886{
3887 SSH_HMACgcry_md_hd_t hm;
3888 int md;
3889 uint32_t len;
3890 uint8_t buf[DIGEST_MAX_SIZE48];
3891
3892 md=ssh_get_digest_by_id(peer_data->mac_id);
3893// ssl_debug_printf("ssh_check_mac mac type:%s md %d\n",
3894// ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
3895
3896 memset(calc_mac, 0, DIGEST_MAX_SIZE48);
3897
3898 if (md == -1) {
3899 return;
3900 }
3901 if (ssh_hmac_init(&hm, peer_data->hmac_iv, peer_data->hmac_iv_len, md) != 0)
3902 return;
3903
3904 /* hash sequence number */
3905 phtonu32(buf, seqnr);
3906
3907 ssh_print_data("Mac IV", peer_data->hmac_iv, peer_data->hmac_iv_len);
3908 ssh_print_data("Mac seq", buf, 4);
3909 ssh_print_data("Mac data", data, datalen);
3910
3911 ssh_hmac_update(&hm,buf,4);
3912
3913 ssh_hmac_update(&hm,data,datalen);
3914
3915 /* get digest and digest len*/
3916 len = sizeof(buf);
3917 ssh_hmac_final(&hm,buf,&len);
3918 ssh_hmac_cleanup(&hm);
3919 ssh_print_data("Mac", buf, len);
3920 memcpy(calc_mac, buf, len);
3921
3922 return;
3923}
3924/* Decryption integrity check }}} */
3925
3926static ssh_packet_info_t *
3927ssh_get_packet_info(packet_info *pinfo, bool_Bool is_response)
3928{
3929 ssh_packet_info_t *packet = (ssh_packet_info_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_ssh, 0);
3930 if(!packet){
3931 packet = wmem_new0(wmem_file_scope(), ssh_packet_info_t)((ssh_packet_info_t*)wmem_alloc0((wmem_file_scope()), sizeof(
ssh_packet_info_t)))
;
3932 packet->from_server = is_response;
3933 packet->messages = NULL((void*)0);
3934 p_add_proto_data(wmem_file_scope(), pinfo, proto_ssh, 0, packet);
3935 }
3936 return packet;
3937}
3938
3939static unsigned
3940ssh_decrypt_packet(tvbuff_t *tvb, packet_info *pinfo,
3941 struct ssh_peer_data *peer_data, int offset)
3942{
3943 bool_Bool is_response = ssh_peer_data_from_server(peer_data);
3944
3945 gcry_error_t err;
3946 unsigned message_length = 0, seqnr;
3947 uint8_t *plain = NULL((void*)0);
3948 const uint8_t *mac;
3949 unsigned mac_len, data_len = 0;
3950 uint8_t calc_mac[DIGEST_MAX_SIZE48];
3951 memset(calc_mac, 0, DIGEST_MAX_SIZE48);
3952 unsigned remaining = tvb_captured_length_remaining(tvb, offset);
3953
3954 mac_len = peer_data->mac_length > 0 ? peer_data->mac_length : 0;
3955 seqnr = peer_data->sequence_number;
3956
3957 /* General algorithm:
3958 * 1. If there are not enough bytes for the packet_length, and we can
3959 * do reassembly, ask for one more segment.
3960 * 2. Retrieve packet_length (encrypted in some modes).
3961 * 3. Sanity check packet_length (the field is 4 bytes, but packet_length
3962 * is unlikely to be much larger than 32768, which provides good indication
3963 * a packet is continuation data or, in some modes, failed decryption.
3964 * https://www.rfc-editor.org/rfc/rfc4253.html#section-6.1 )
3965 * 4. If there are not enough bytes for packet_length, and we can do
3966 * reassembly, tell the TCP dissector how many more bytes we need.
3967 * 5. If the packet is truncated and we cannot reassemble, at this
3968 * point we conclude that it is the next SSH packet, and advance the
3969 * sequence number, invocation_counter, etc. before throwing an exception.
3970 * 6. If we do have all the data, we decrypt and check the MAC before
3971 * doing all that. (XXX - Advancing seqnr regardless could make sense
3972 * in some ciphers.)
3973 * 7. Possibly the MAC should be checked before decryption in some ciphers
3974 * if we have all the data; possibly there should be a "do not check the
3975 * MAC" preference a la TLS.
3976 */
3977
3978 if (GCRY_CIPHER_CHACHA20 == peer_data->cipher_id) {
3979 if (ssh_desegment && pinfo->can_desegment && remaining < 4) {
3980 /* Can do reassembly, and the packet length is split across
3981 * segment boundaries. */
3982 pinfo->desegment_offset = offset;
3983 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT0x0fffffff;
3984 return tvb_captured_length(tvb);
3985 }
3986
3987 const uint8_t *ctext = tvb_get_ptr(tvb, offset, 4);
3988 uint8_t plain_length_buf[4];
3989
3990 if (!ssh_decrypt_chacha20(peer_data->cipher_2, seqnr, 0, ctext, 4,
3991 plain_length_buf, 4)) {
3992 ws_debug("ERROR: could not decrypt packet len")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 3992, __func__, "ERROR: could not decrypt packet len"); } }
while (0)
;
3993 return tvb_captured_length(tvb);
3994 }
3995
3996 message_length = pntohu32(plain_length_buf);
3997
3998 ssh_debug_printf("chachapoly_crypt seqnr=%d [%u]\n", seqnr, message_length);
3999
4000 ssh_debug_printf("%s plain for seq = %d len = %u\n", is_response?"s2c":"c2s", seqnr, message_length);
4001 if (message_length > SSH_MAX_PACKET_LEN32768) {
4002 ws_debug("ssh: unreasonable message length %u", message_length)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4002, __func__, "ssh: unreasonable message length %u", message_length
); } } while (0)
;
4003 return tvb_captured_length(tvb);
4004 }
4005 if (remaining < message_length + 4 + mac_len) {
4006 // Need desegmentation; as "the [email protected] AEAD
4007 // uses the sequence number as an initialisation vector (IV) to
4008 // generate its per-packet MAC key and is otherwise stateless
4009 // between packets," we need no special handling here.
4010 // https://datatracker.ietf.org/doc/draft-miller-sshm-strict-kex/
4011 //
4012 if (ssh_desegment && pinfo->can_desegment) {
4013 pinfo->desegment_offset = offset;
4014 pinfo->desegment_len = message_length + 4 + mac_len - remaining;
4015 return tvb_captured_length(tvb);
4016 }
4017 // If we can't desegment, we will have an exception below in
4018 // the tvb_get_ptr. Advance the sequence number so that the
4019 // next SSH packet start will decrypt correctly.
4020 peer_data->sequence_number++;
4021 }
4022
4023 plain = (uint8_t *)wmem_alloc0(pinfo->pool, message_length+4);
4024 memcpy(plain, plain_length_buf, 4);
4025 const uint8_t *ctext2 = tvb_get_ptr(tvb, offset+4, message_length);
4026
4027 /* XXX - "Once the entire packet has been received, the MAC MUST be
4028 * checked before decryption," but we decrypt first.
4029 * https://datatracker.ietf.org/doc/html/draft-ietf-sshm-chacha20-poly1305-01
4030 */
4031 if (!ssh_decrypt_chacha20(peer_data->cipher, seqnr, 1, ctext2,
4032 message_length, plain+4, message_length)) {
4033 ws_debug("ERROR: could not decrypt packet payload")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4033, __func__, "ERROR: could not decrypt packet payload");
} } while (0)
;
4034 return tvb_captured_length(tvb);
4035 }
4036
4037 mac = tvb_get_ptr(tvb, offset + 4 + message_length, mac_len);
4038 uint8_t poly_key[32], iv[16];
4039
4040 memset(poly_key, 0, 32);
4041 memset(iv, 0, 8);
4042 phtonu64(iv+8, (uint64_t)seqnr);
4043 gcry_cipher_setiv(peer_data->cipher, iv, mac_len);
4044 gcry_cipher_encrypt(peer_data->cipher, poly_key, 32, poly_key, 32);
4045
4046 gcry_mac_hd_t mac_hd;
4047 gcry_mac_open(&mac_hd, GCRY_MAC_POLY1305, 0, NULL((void*)0));
4048 gcry_mac_setkey(mac_hd, poly_key, 32);
4049 gcry_mac_write(mac_hd, ctext, 4);
4050 gcry_mac_write(mac_hd, ctext2, message_length);
4051 if (gcry_mac_verify(mac_hd, mac, mac_len)) {
4052 ws_debug("ssh: MAC does not match")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4052, __func__, "ssh: MAC does not match"); } } while (0)
;
4053 }
4054 size_t buflen = DIGEST_MAX_SIZE48;
4055 gcry_mac_read(mac_hd, calc_mac, &buflen);
4056 gcry_mac_close(mac_hd);
4057
4058 data_len = message_length + 4;
4059
4060 ssh_debug_printf("%s plain text seq=%d", is_response?"s2c":"c2s",seqnr);
4061 ssh_print_data("", plain, message_length+4);
4062 } else if (CIPHER_AES128_GCM0x00040001 == peer_data->cipher_id || CIPHER_AES256_GCM0x00040004 == peer_data->cipher_id) {
4063
4064 /* AES GCM for Secure Shell [RFC 5647] */
4065 /* The message length is Additional Authenticated Data */
4066 if (ssh_desegment && pinfo->can_desegment && remaining < 4) {
4067 /* Can do reassembly, and the packet length is split across
4068 * segment boundaries. */
4069 pinfo->desegment_offset = offset;
4070 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT0x0fffffff;
4071 return tvb_captured_length(tvb);
4072 }
4073 message_length = tvb_get_uint32(tvb, offset, ENC_BIG_ENDIAN0x00000000);
4074 ssh_debug_printf("length: %d, remaining: %d\n", message_length, remaining);
4075 /* The minimum size of a packet (not counting mac) is 16. */
4076 if (message_length > SSH_MAX_PACKET_LEN32768 || message_length < 16) {
4077 ws_debug("ssh: unreasonable message length %u", message_length)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4077, __func__, "ssh: unreasonable message length %u", message_length
); } } while (0)
;
4078 return tvb_captured_length(tvb);
4079 }
4080
4081 /* SSH requires that the data to be encrypted (not including the AAD,
4082 * so message_length) be a multiple of the block size, 16 octets */
4083 if (message_length % 16 != 0) {
4084 ssh_debug_printf("length not a multiple of block length (16)!\n");
4085 }
4086
4087 if (message_length + 4 + mac_len > remaining) {
4088 // Need desegmentation; as the message length was unencrypted
4089 // AAD, we need no special handling here.
4090 if (pinfo->can_desegment) {
4091 pinfo->desegment_offset = offset;
4092 pinfo->desegment_len = message_length + 4 + mac_len - remaining;
4093 return tvb_captured_length(tvb);
4094 }
4095 // If we can't desegment, we will have an exception below in
4096 // the tvb_get_ptr. Advance the sequence number (less crucial
4097 // than with ChaCha20, as it's not an input.)
4098 peer_data->sequence_number++;
4099 }
4100
4101 /* Set the IV and increment the invocation_counter for the next
4102 * packet. Do this before retrieving the ciphertext with tvb_get_ptr
4103 * in case this packet is truncated.
4104 */
4105 if ((err = gcry_cipher_setiv(peer_data->cipher, peer_data->iv, 12))) {
4106 //gcry_cipher_close(peer_data->cipher);
4107 //Don't close this unless we also remove the wmem callback
4108// TODO: temporary work-around as long as a Windows python bug is triggered by automated tests
4109#ifndef _WIN32
4110 ws_debug("ssh: can't set aes128 cipher iv")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4110, __func__, "ssh: can't set aes128 cipher iv"); } } while
(0)
;
4111 ws_debug("libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource(err), gcry_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4111, __func__, "libgcrypt: %d %s %s", gcry_err_code(err), gcry_strsource
(err), gcry_strerror(err)); } } while (0)
;
4112#endif //ndef _WIN32
4113 return tvb_captured_length(tvb);
4114 }
4115 // Increment invocation_counter for next packet
4116 int idx = 12;
4117 do{
4118 idx -= 1;
4119 peer_data->iv[idx] += 1;
4120 }while(idx>4 && peer_data->iv[idx]==0);
4121
4122 const char *ctext = (const char *)tvb_get_ptr(tvb, offset + 4,
4123 message_length);
4124 plain = (uint8_t *)wmem_alloc(pinfo->pool, message_length+4);
4125 phtonu32(plain, message_length);
4126
4127 if ((err = gcry_cipher_authenticate(peer_data->cipher, plain, 4))) {
4128// TODO: temporary work-around as long as a Windows python bug is triggered by automated tests
4129#ifndef _WIN32
4130 ws_debug("can't authenticate using aes128-gcm: %s\n", gpg_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4130, __func__, "can't authenticate using aes128-gcm: %s\n"
, gpg_strerror(err)); } } while (0)
;
4131#endif //ndef _WIN32
4132 return tvb_captured_length(tvb);
4133 }
4134
4135 if ((err = gcry_cipher_decrypt(peer_data->cipher, plain+4, message_length,
4136 ctext, message_length))) {
4137// TODO: temporary work-around as long as a Windows python bug is triggered by automated tests
4138#ifndef _WIN32
4139 ws_debug("can't decrypt aes-gcm %d %s %s", gcry_err_code(err), gcry_strsource(err), gcry_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4139, __func__, "can't decrypt aes-gcm %d %s %s", gcry_err_code
(err), gcry_strsource(err), gcry_strerror(err)); } } while (0
)
;
4140
4141#endif //ndef _WIN32
4142 return tvb_captured_length(tvb);
4143 }
4144
4145 if (gcry_cipher_gettag (peer_data->cipher, calc_mac, 16)) {
4146// TODO: temporary work-around as long as a Windows python bug is triggered by automated tests
4147#ifndef _WIN32
4148 ws_debug ("aes128-gcm, gcry_cipher_gettag() failed\n")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4148, __func__, "aes128-gcm, gcry_cipher_gettag() failed\n"
); } } while (0)
;
4149#endif //ndef _WIN32
4150 return tvb_captured_length(tvb);
4151 }
4152
4153 if ((err = gcry_cipher_reset(peer_data->cipher)gcry_cipher_ctl ((peer_data->cipher), GCRYCTL_RESET, ((void
*)0), 0)
)) {
4154// TODO: temporary work-around as long as a Windows python bug is triggered by automated tests
4155#ifndef _WIN32
4156 ws_debug("aes-gcm, gcry_cipher_reset failed: %s\n", gpg_strerror (err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4156, __func__, "aes-gcm, gcry_cipher_reset failed: %s\n", gpg_strerror
(err)); } } while (0)
;
4157#endif //ndef _WIN32
4158 return tvb_captured_length(tvb);
4159 }
4160
4161 data_len = message_length + 4;
4162
4163 ssh_debug_printf("%s plain text seq=%d", is_response?"s2c":"c2s",seqnr);
4164 ssh_print_data("", plain, message_length+4);
4165
4166 } else if (CIPHER_AES128_CBC0x00020001 == peer_data->cipher_id || CIPHER_AES128_CTR0x00010001 == peer_data->cipher_id ||
4167 CIPHER_AES192_CBC0x00020002 == peer_data->cipher_id || CIPHER_AES192_CTR0x00010003 == peer_data->cipher_id ||
4168 CIPHER_AES256_CBC0x00020004 == peer_data->cipher_id || CIPHER_AES256_CTR0x00010004 == peer_data->cipher_id) {
4169
4170 ws_noisy("Getting raw bytes of length %d", tvb_reported_length_remaining(tvb, offset))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 4170, __func__, "Getting raw bytes of length %d", tvb_reported_length_remaining
(tvb, offset)); } } while (0)
;
4171 /* In CBC and CTR mode, the message length is encrypted as well.
4172 * We need to decrypt one block, 16 octets, to get the length.
4173 */
4174 if (ssh_desegment && pinfo->can_desegment && remaining < 16) {
4175 /* Can do reassembly, and the packet length is split across
4176 * segment boundaries. */
4177 pinfo->desegment_offset = offset;
4178 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT0x0fffffff;
4179 return tvb_captured_length(tvb);
4180 }
4181 /* Do we already have the first block decrypted from when the packet
4182 * was too large and segmented?
4183 */
4184 if (!peer_data->plain0_valid) {
4185 const char *cypher_buf0 = (const char *)tvb_get_ptr(tvb, offset, 16);
4186
4187 if (gcry_cipher_decrypt(peer_data->cipher, peer_data->plain0, 16, cypher_buf0, 16))
4188 {
4189 ws_debug("can\'t decrypt aes128")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4189, __func__, "can\'t decrypt aes128"); } } while (0)
;
4190 return tvb_captured_length(tvb);
4191 }
4192 }
4193
4194 message_length = pntohu32(peer_data->plain0);
4195
4196 /* The message_length value doesn't include the length of the
4197 * message_length field itself, so it must be at least 12 bytes.
4198 */
4199 if (message_length > SSH_MAX_PACKET_LEN32768 || message_length < 12){
4200 ws_debug("ssh: unreasonable message length %u", message_length)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4200, __func__, "ssh: unreasonable message length %u", message_length
); } } while (0)
;
4201 return tvb_captured_length(tvb);
4202 }
4203
4204 /* SSH requires that the data to be encrypted (message_length+4)
4205 * be a multiple of the block size, 16 octets. */
4206 if (message_length % 16 != 12) {
4207 ssh_debug_printf("total length not a multiple of block length (16)!\n");
4208 }
4209 if (remaining < message_length + 4 + mac_len) {
4210 /* Need desegmentation
4211 *
4212 * We will be handed the full encrypted packet again. We can either
4213 * store the decrypted first block, or will need to reset the CTR
4214 * or IV appropriately before decrypting the first block again.
4215 * libgcrypt does not provide an easy way to get the current value
4216 * of the CTR or (or IV/last block for CBC), so we just store the
4217 * decrypted first block.
4218 */
4219 if (ssh_desegment && pinfo->can_desegment) {
4220 ws_noisy(" need_desegmentation: offset = %d, reported_length_remaining = %d\n",do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 4221, __func__, " need_desegmentation: offset = %d, reported_length_remaining = %d\n"
, offset, tvb_reported_length_remaining(tvb, offset)); } } while
(0)
4221 offset, tvb_reported_length_remaining(tvb, offset))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 4221, __func__, " need_desegmentation: offset = %d, reported_length_remaining = %d\n"
, offset, tvb_reported_length_remaining(tvb, offset)); } } while
(0)
;
4222 peer_data->plain0_valid = true1;
4223 pinfo->desegment_offset = offset;
4224 pinfo->desegment_len = message_length + 4 + mac_len - remaining;
4225 return tvb_captured_length(tvb);
4226 } else {
4227 // If we can't desegment, we will have an exception below in
4228 // the tvb_get_ptr. Advance the sequence number so that the
4229 // the hash will work for the next packet.
4230 //
4231 // XXX - In CTR mode, we should advance the CTR based on the
4232 // known length so we can dissect the next block. We would
4233 // also need to reset the CTR after failing to dissect a
4234 // packet_length on the continuation data that comes next.
4235 peer_data->sequence_number++;
4236 }
4237 }
4238 peer_data->plain0_valid = false0;
4239 plain = (uint8_t *)wmem_alloc(pinfo->pool, message_length+4);
4240 memcpy(plain, peer_data->plain0, 16);
4241
4242 if (message_length > 12) {
4243 /* All of these functions actually do handle the case where
4244 * there is no data left, so the check is unnecessary.
4245 */
4246 char *ct = (char *)tvb_get_ptr(tvb, offset + 16, message_length - 12);
4247 if ((err = gcry_cipher_decrypt(peer_data->cipher, plain + 16, message_length - 12, ct, message_length - 12)))
4248 {
4249 ws_debug("can't decrypt aes-cbc/ctr %d %s %s", gcry_err_code(err), gcry_strsource(err), gcry_strerror(err))do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4249, __func__, "can't decrypt aes-cbc/ctr %d %s %s", gcry_err_code
(err), gcry_strsource(err), gcry_strerror(err)); } } while (0
)
;
4250 return tvb_captured_length(tvb);
4251 }
4252 }
4253
4254 ssh_debug_printf("%s plain text seq=%d", is_response?"s2c":"c2s",seqnr);
4255 ssh_print_data("", plain, message_length+4);
4256
4257 data_len = message_length + 4;
4258
4259 // XXX - In -etm modes, should calculate MAC based on ciphertext.
4260 ssh_calc_mac(peer_data, seqnr, plain, data_len, calc_mac);
4261 } else if (CIPHER_NULL0x00080000 == peer_data->cipher_id) {
4262 if (ssh_desegment && pinfo->can_desegment && remaining < 4) {
4263 /* Can do reassembly, and the packet length is split across
4264 * segment boundaries. */
4265 pinfo->desegment_offset = offset;
4266 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT0x0fffffff;
4267 return tvb_captured_length(tvb);
4268 }
4269 message_length = tvb_get_uint32(tvb, offset, ENC_BIG_ENDIAN0x00000000);
4270 ssh_debug_printf("length: %d, remaining: %d\n", message_length, remaining);
4271 if (message_length > SSH_MAX_PACKET_LEN32768 || message_length < 8) {
4272 ws_debug("ssh: unreasonable message length %u", message_length)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4272, __func__, "ssh: unreasonable message length %u", message_length
); } } while (0)
;
4273 return tvb_captured_length(tvb);
4274 }
4275
4276 if (message_length + 4 + mac_len > remaining) {
4277 // Need desegmentation; as the message length was unencrypted
4278 // AAD, we need no special handling here.
4279 if (pinfo->can_desegment) {
4280 pinfo->desegment_offset = offset;
4281 pinfo->desegment_len = message_length + 4 + mac_len - remaining;
4282 return tvb_captured_length(tvb);
4283 }
4284 // If we can't desegment, we will have an exception below in
4285 // the tvb_memdup. Advance the sequence number (not crucial).
4286 peer_data->sequence_number++;
4287 }
4288 data_len = message_length + 4;
4289 plain = tvb_memdup(pinfo->pool, tvb, offset, data_len);
4290
4291 // XXX - In -etm modes, should calculate MAC based on ciphertext.
4292 ssh_calc_mac(peer_data, seqnr, plain, data_len, calc_mac);
4293 }
4294
4295 if (mac_len && data_len) {
4296 if (mac_len <= DIGEST_MAX_SIZE48 && !memcmp(tvb_get_ptr(tvb, offset + data_len, mac_len), calc_mac, mac_len)){
4297 ws_noisy("MAC OK")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_NOISY, "epan/dissectors/packet-ssh.c"
, 4297, __func__, "MAC OK"); } } while (0)
;
4298 }else{
4299 ws_debug("MAC ERR")do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4299, __func__, "MAC ERR"); } } while (0)
;
4300 /* Bad MAC, just show the packet as encrypted. We can get
4301 * this for a known encryption type with no keys currently. */
4302 if (!ssh_ignore_mac_failed) {
4303 return tvb_captured_length(tvb);
4304 }
4305 }
4306 }
4307
4308 if(plain){
4309 // Save message
4310
4311 ssh_packet_info_t *packet = ssh_get_packet_info(pinfo, is_response);
4312
4313 int record_id = tvb_raw_offset(tvb)+offset;
4314 ssh_message_info_t *message;
4315
4316 message = wmem_new(wmem_file_scope(), ssh_message_info_t)((ssh_message_info_t*)wmem_alloc((wmem_file_scope()), sizeof(
ssh_message_info_t)))
;
4317 message->sequence_number = peer_data->sequence_number++;
4318 message->plain_data = wmem_memdup(wmem_file_scope(), plain, data_len);
4319 message->data_len = data_len;
4320 message->id = record_id;
4321 message->next = NULL((void*)0);
4322 memcpy(message->calc_mac, calc_mac, DIGEST_MAX_SIZE48);
4323 ssh_debug_printf("%s->sequence_number++ > %d\n", is_response?"server":"client", peer_data->sequence_number);
4324
4325 ssh_message_info_t **pmessage = &packet->messages;
4326 while(*pmessage){
4327 pmessage = &(*pmessage)->next;
4328 }
4329 *pmessage = message;
4330 }
4331
4332 offset += message_length + mac_len + 4;
4333 return offset;
4334}
4335
4336static bool_Bool
4337ssh_decrypt_chacha20(gcry_cipher_hd_t hd,
4338 uint32_t seqnr, uint32_t counter, const unsigned char *ctext, unsigned ctext_len,
4339 unsigned char *plain, unsigned plain_len)
4340{
4341 unsigned char seq[8];
4342 unsigned char iv[16];
4343
4344 phtonu64(seq, (uint64_t)seqnr);
4345
4346 // chacha20 uses a different cipher handle for the packet payload & length
4347 // the payload uses a block counter
4348 if (counter) {
4349 const unsigned char ctr[8] = {1,0,0,0,0,0,0,0};
4350 memcpy(iv, ctr, 8);
4351 memcpy(iv+8, seq, 8);
4352 }
4353
4354 return ((!counter && gcry_cipher_setiv(hd, seq, 8) == 0) ||
4355 (counter && gcry_cipher_setiv(hd, iv, 16) == 0)) &&
4356 gcry_cipher_decrypt(hd, plain, plain_len, ctext, ctext_len) == 0;
4357}
4358
4359static int
4360ssh_dissect_decrypted_packet(tvbuff_t *tvb, packet_info *pinfo,
4361 struct ssh_peer_data *peer_data, proto_tree *tree,
4362 ssh_message_info_t *message)
4363{
4364 unsigned offset = 0; // TODO:
4365 int dissected_len = 0;
4366 tvbuff_t* payload_tvb;
4367
4368 const uint8_t* plaintext = message->plain_data;
4369 unsigned plaintext_len = message->data_len;
4370
4371 col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL((void*)0), "Encrypted packet (plaintext_len=%d)", plaintext_len);
4372
4373 tvbuff_t *packet_tvb = tvb_new_child_real_data(tvb, plaintext, plaintext_len, plaintext_len);
4374 add_new_data_source(pinfo, packet_tvb, "Decrypted Packet");
4375
4376 unsigned plen;
4377 uint32_t padding_length;
4378 unsigned remain_length;
4379 unsigned msg_code;
4380
4381 proto_item *ti, *padding_ti;
4382 proto_item *msg_type_tree = NULL((void*)0);
4383
4384 /*
4385 * We use "tvb_ensure_captured_length_remaining()" to make sure there
4386 * actually *is* data remaining.
4387 *
4388 * This means we're guaranteed that "remain_length" is positive.
4389 */
4390 remain_length = tvb_ensure_captured_length_remaining(packet_tvb, offset);
4391 /*
4392 * Can we do reassembly?
4393 */
4394 if (ssh_desegment && pinfo->can_desegment) {
4395 /*
4396 * Yes - would an SSH header starting at this offset
4397 * be split across segment boundaries?
4398 */
4399 if (remain_length < 4) {
4400 /*
4401 * Yes. Tell the TCP dissector where the data for
4402 * this message starts in the data it handed us and
4403 * that we need "some more data." Don't tell it
4404 * exactly how many bytes we need because if/when we
4405 * ask for even more (after the header) that will
4406 * break reassembly.
4407 */
4408 pinfo->desegment_offset = offset;
4409 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT0x0fffffff;
4410 return offset;
4411 }
4412 }
4413 /* XXX - Defragmentation needs to be done in ssh_decrypt_packet, and the
4414 * checks there should mean that the above never has an effect. (It's
4415 * copied from ssh_dissect_key_exchange.)
4416 */
4417 plen = tvb_get_ntohl(packet_tvb, offset);
4418
4419 if (ssh_desegment && pinfo->can_desegment) {
4420 if (plen + 4 > remain_length) {
4421 pinfo->desegment_offset = offset;
4422 pinfo->desegment_len = plen+4 - remain_length;
4423 return offset;
4424 }
4425 }
4426 /*
4427 * Need to check plen > 0x80000000 here
4428 */
4429
4430 ti = proto_tree_add_uint(tree, hf_ssh_packet_length, packet_tvb,
4431 offset, 4, plen);
4432 if (plen < 8) {
4433 /* RFC 4253 6: "[T]he length of the concatenation of 'packet_length',
4434 * 'padding_length', 'payload', and 'random padding' MUST be a multiple
4435 * of the cipher block size or 8, whichever is larger,... even when
4436 * using stream ciphers."
4437 *
4438 * Modes that do not encrypt plen with the same key as the other three
4439 * cannot follow this as written and delete 'packet_length' from the
4440 * above sentence. As padding_length is one byte and random_padding at
4441 * least four, packet_length must be at least 8 in all modes.
4442 */
4443 expert_add_info_format(pinfo, ti, &ei_ssh_packet_length, "Packet length is %d, MUST be at least 8", plen);
4444 } else if (plen >= SSH_MAX_PACKET_LEN32768) {
4445 expert_add_info_format(pinfo, ti, &ei_ssh_packet_length, "Overly large number %d", plen);
4446 plen = remain_length-4;
4447 }
4448 offset+=4;
4449
4450 /* padding length */
4451 padding_ti = proto_tree_add_item_ret_uint(tree, hf_ssh_padding_length, packet_tvb, offset, 1, ENC_NA0x00000000, &padding_length);
4452 /* RFC 4253 6: "There MUST be at least four bytes of padding." */
4453 if (padding_length < 4) {
4454 expert_add_info_format(pinfo, padding_ti, &ei_ssh_padding_length, "Padding length is %d, MUST be at least 4", padding_length);
4455 }
4456 unsigned payload_length;
4457 if (ckd_sub(&payload_length, plen, padding_length + 1)__builtin_sub_overflow((plen), (padding_length + 1), (&payload_length
))
) {
4458 expert_add_info_format(pinfo, padding_ti, &ei_ssh_padding_length, "Padding length is too large [%d], implies a negative payload length", padding_length);
4459 payload_length = 0;
4460 }
4461 offset += 1;
4462
4463 /* msg_code */
4464 msg_code = tvb_get_uint8(packet_tvb, offset);
4465 /* XXX - Payload compression could have been negotiated */
4466 payload_tvb = tvb_new_subset_length(packet_tvb, offset, (int)payload_length);
4467 bool_Bool is_response = ssh_peer_data_from_server(peer_data);
4468
4469 /* Transport layer protocol */
4470 /* Generic (1-19) */
4471 if(msg_code >= 1 && msg_code <= 19) {
4472 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0), val_to_str(pinfo->pool, msg_code, ssh2_msg_vals, "Unknown (%u)"));
4473 msg_type_tree = proto_tree_add_subtree(tree, packet_tvb, offset, plen-1, ett_key_exchange, NULL((void*)0), "Message: Transport (generic)");
4474 proto_tree_add_item(msg_type_tree, hf_ssh2_msg_code, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4475 dissected_len = ssh_dissect_transport_generic(payload_tvb, pinfo, 1, peer_data, msg_type_tree, msg_code);
4476 }
4477 /* Algorithm negotiation (20-29) */
4478 /* Normally these messages are all dissected in ssh_dissect_key_exchange */
4479 else if(msg_code >=20 && msg_code <= 29) {
4480//TODO: See if the complete dissector should be refactored to always go through here first offset = ssh_dissect_transport_algorithm_negotiation(packet_tvb, pinfo, global_data, offset, msg_type_tree, is_response, msg_code);
4481
4482 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0), val_to_str(pinfo->pool, msg_code, ssh2_msg_vals, "Unknown (%u)"));
4483 msg_type_tree = proto_tree_add_subtree(tree, packet_tvb, offset, plen-1, ett_key_exchange, NULL((void*)0), "Message: Transport (algorithm negotiation)");
4484 proto_tree_add_item(msg_type_tree, hf_ssh2_msg_code, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4485 dissected_len = 1;
4486
4487 ws_debug("SSH dissect: pass %u, frame %u, msg_code %u, do_decrypt=%d", pinfo->fd->visited, pinfo->fd->num, msg_code, peer_data->global_data->do_decrypt)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4487, __func__, "SSH dissect: pass %u, frame %u, msg_code %u, do_decrypt=%d"
, pinfo->fd->visited, pinfo->fd->num, msg_code, peer_data
->global_data->do_decrypt); } } while (0)
;
4488 switch(msg_code)
4489 {
4490 case SSH_MSG_KEXINIT20:
4491 {
4492 ws_debug("ssh: REKEY msg_code 20: storing frame %u number, offset %d" , pinfo->num, offset)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4492, __func__, "ssh: REKEY msg_code 20: storing frame %u number, offset %d"
, pinfo->num, offset); } } while (0)
;
4493 peer_data->rekey_trigger_frame = pinfo->num;
4494 // Reset array while REKEY: sanitize server_key_exchange_init and force do_decrypt :
4495 peer_data->global_data->kex_server_key_exchange_init = wmem_array_new(wmem_file_scope(), 1);
4496 peer_data->global_data->do_decrypt = true1;
4497 dissected_len = ssh_dissect_key_init(payload_tvb, pinfo, offset - 4, msg_type_tree, is_response, peer_data->global_data);
4498 break;
4499 }
4500 case SSH_MSG_NEWKEYS21:
4501 {
4502 if (peer_data->rekey_pending) {
4503 ws_debug("ssh: REKEY pending... NEWKEYS frame %u", pinfo->num)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4503, __func__, "ssh: REKEY pending... NEWKEYS frame %u", pinfo
->num); } } while (0)
;
4504 ws_debug("ssh: decrypting frame %u with key ID %u, seq=%u", pinfo->num, peer_data->cipher_id, peer_data->sequence_number)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4504, __func__, "ssh: decrypting frame %u with key ID %u, seq=%u"
, pinfo->num, peer_data->cipher_id, peer_data->sequence_number
); } } while (0)
;
4505 if (peer_data->global_data->ext_kex_strict) {
4506 peer_data->sequence_number = 0;
4507 ssh_debug_printf("%s->sequence_number reset to 0 (Strict KEX)\n", is_response ? "server" : "client");
4508 ws_debug("ssh: REKEY reset %s sequence number to 0 at frame %u (Strict KEX)", is_response ? "server" : "client", pinfo->num)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4508, __func__, "ssh: REKEY reset %s sequence number to 0 at frame %u (Strict KEX)"
, is_response ? "server" : "client", pinfo->num); } } while
(0)
;
4509 }
4510 // finalize the rekey (activate the new keys)
4511 if (!is_response) { // Only process client-sent NEWKEYS
4512 // Activate new key material into peer_data->cipher
4513 ssh_debug_printf("Activating new keys for CLIENT => SERVER\n");
4514 ssh_decryption_setup_cipher(peer_data, &peer_data->global_data->new_keys[0], &peer_data->global_data->new_keys[2]);
4515 ssh_decryption_setup_mac(peer_data, &peer_data->global_data->new_keys[4]);
4516 } else { // Only process server-sent NEWKEYS
4517 // Activate new key material into peer_data->cipher
4518 ssh_debug_printf("Activating new keys for SERVER => CLIENT\n");
4519 ssh_decryption_setup_cipher(peer_data, &peer_data->global_data->new_keys[1], &peer_data->global_data->new_keys[3]);
4520 ssh_decryption_setup_mac(peer_data, &peer_data->global_data->new_keys[5]);
4521 }
4522 // Finishing REKEY
4523 peer_data->rekey_pending = false0;
4524 ws_debug("ssh: REKEY done... switched to NEWKEYS at frame %u", pinfo->num)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4524, __func__, "ssh: REKEY done... switched to NEWKEYS at frame %u"
, pinfo->num); } } while (0)
;
4525 }
4526 break;
4527 }
4528 }
4529 }
4530 /* Key exchange method specific (reusable) (30-49) */
4531 /* Normally these messages are all dissected in ssh_dissect_key_exchange */
4532 else if (msg_code >=30 && msg_code <= 49) {
4533//TODO: See if the complete dissector should be refactored to always go through here first offset = global_data->kex_specific_dissector(msg_code, packet_tvb, pinfo, offset, msg_type_tree);
4534
4535 msg_type_tree = proto_tree_add_subtree(tree, packet_tvb, offset, plen-1, ett_key_exchange, NULL((void*)0), "Message: Transport (key exchange method specific)");
4536 ws_debug("ssh: rekey KEX_xxx_INIT/KEX_xxx_REPLY detected in frame %u", pinfo->num)do { if (1) { ws_log_full("packet-ssh", LOG_LEVEL_DEBUG, "epan/dissectors/packet-ssh.c"
, 4536, __func__, "ssh: rekey KEX_xxx_INIT/KEX_xxx_REPLY detected in frame %u"
, pinfo->num); } } while (0)
;
4537 peer_data->rekey_pending = true1;
4538 dissected_len = peer_data->global_data->kex_specific_dissector(msg_code, payload_tvb, pinfo, offset -5, msg_type_tree, peer_data->global_data);
4539 }
4540
4541 /* User authentication protocol */
4542 /* Generic (50-59) */
4543 else if (msg_code >= 50 && msg_code <= 59) {
4544 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0), val_to_str(pinfo->pool, msg_code, ssh2_msg_vals, "Unknown (%u)"));
4545 msg_type_tree = proto_tree_add_subtree(tree, packet_tvb, offset, plen-1, ett_key_exchange, NULL((void*)0), "Message: User Authentication (generic)");
4546 proto_tree_add_item(msg_type_tree, hf_ssh2_msg_code, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4547 dissected_len = ssh_dissect_userauth_generic(payload_tvb, pinfo, 1, msg_type_tree, msg_code);
4548 }
4549 /* User authentication method specific (reusable) (60-79) */
4550 else if (msg_code >= 60 && msg_code <= 79) {
4551 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0), val_to_str(pinfo->pool, msg_code, ssh2_msg_vals, "Unknown (%u)"));
4552 msg_type_tree = proto_tree_add_subtree(tree, packet_tvb, offset, plen-1, ett_key_exchange, NULL((void*)0), "Message: User Authentication: (method specific)");
4553 proto_tree_add_item(msg_type_tree, hf_ssh2_msg_code, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4554 dissected_len = ssh_dissect_userauth_specific(payload_tvb, pinfo, 1, msg_type_tree, msg_code);
4555 }
4556
4557 /* Connection protocol */
4558 /* Generic (80-89) */
4559 else if (msg_code >= 80 && msg_code <= 89) {
4560 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0), val_to_str(pinfo->pool, msg_code, ssh2_msg_vals, "Unknown (%u)"));
4561 msg_type_tree = proto_tree_add_subtree(tree, packet_tvb, offset, plen-1, ett_key_exchange, NULL((void*)0), "Message: Connection (generic)");
4562 proto_tree_add_item(msg_type_tree, hf_ssh2_msg_code, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4563 dissected_len = ssh_dissect_connection_generic(payload_tvb, pinfo, 1, msg_type_tree, msg_code);
4564 }
4565 /* Channel related messages (90-127) */
4566 else if (msg_code >= 90 && msg_code <= 127) {
4567 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0), val_to_str(pinfo->pool, msg_code, ssh2_msg_vals, "Unknown (%u)"));
4568 msg_type_tree = proto_tree_add_subtree(tree, packet_tvb, offset, plen-1, ett_key_exchange, NULL((void*)0), "Message: Connection: (channel related message)");
4569 proto_tree_add_item(msg_type_tree, hf_ssh2_msg_code, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4570 dissected_len = ssh_dissect_connection_specific(payload_tvb, pinfo, peer_data, 1, msg_type_tree, msg_code, message);
4571 }
4572
4573 /* Reserved for client protocols (128-191) */
4574 else if (msg_code >= 128 && msg_code <= 191) {
4575 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0), val_to_str(pinfo->pool, msg_code, ssh2_msg_vals, "Unknown (%u)"));
4576 msg_type_tree = proto_tree_add_subtree(tree, packet_tvb, offset, plen-1, ett_key_exchange, NULL((void*)0), "Message: Client protocol");
4577 proto_tree_add_item(msg_type_tree, hf_ssh2_msg_code, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4578 offset+=1;
4579 // TODO: dissected_len = ssh_dissect_client(payload_tvb, pinfo, global_data, 1, msg_type_tree, is_response, msg_code);
4580 }
4581
4582 /* Local extensions (192-255) */
4583 else if (msg_code >= 192 && msg_code <= 255) {
4584 msg_type_tree = proto_tree_add_subtree(tree, packet_tvb, offset, plen-1, ett_key_exchange, NULL((void*)0), "Message: Local extension");
4585 dissected_len = ssh_dissect_local_extension(payload_tvb, pinfo, 0, peer_data, msg_type_tree, msg_code);
4586 }
4587
4588 /* XXX - ssh_dissect_key_exchange only adds undecoded payload here,
4589 * i.e., tvb_reported_length_remaining(payload_tvb, dissected_len)
4590 */
4591 if (payload_length > 0) {
4592 proto_tree_add_item(msg_type_tree, hf_ssh_payload, packet_tvb, offset, payload_length, ENC_NA0x00000000);
4593 }
4594 if(dissected_len!=(int)payload_length){
4595 expert_add_info_format(pinfo, ti, &ei_ssh_packet_decode, "Decoded %d bytes, but payload length is %d bytes [%d]", dissected_len, payload_length, msg_code);
4596 }
4597 offset += payload_length;
4598
4599 /* padding */
4600 proto_tree_add_item(tree, hf_ssh_padding_string, packet_tvb, offset, padding_length, ENC_NA0x00000000);
4601 offset += padding_length;
4602
4603 if (peer_data->mac_length > 0) {
4604 proto_tree_add_checksum_bytes(tree, tvb, offset, hf_ssh_mac_string, hf_ssh_mac_status, &ei_ssh_mac_bad, pinfo, message->calc_mac, peer_data->mac_length, PROTO_CHECKSUM_VERIFY0x01);
4605 offset += peer_data->mac_length;
4606 }
4607 ti = proto_tree_add_uint(tree, hf_ssh_seq_num, tvb, offset, 0, message->sequence_number);
4608 proto_item_set_generated(ti);
4609 return offset;
4610}
4611
4612static int
4613ssh_dissect_transport_generic(tvbuff_t *packet_tvb, packet_info *pinfo,
4614 int offset, struct ssh_peer_data *peer_data, proto_item *msg_type_tree, unsigned msg_code)
4615{
4616 (void)pinfo;
4617 if(msg_code==SSH_MSG_DISCONNECT1){
4618 proto_tree_add_item(msg_type_tree, hf_ssh_disconnect_reason, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
4619 offset += 4;
4620 unsigned nlen;
4621 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_disconnect_description_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &nlen);
4622 offset += 4;
4623 proto_tree_add_item(msg_type_tree, hf_ssh_disconnect_description, packet_tvb, offset, nlen, ENC_ASCII0x00000000);
4624 offset += nlen;
4625 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_lang_tag_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &nlen);
4626 offset += 4;
4627 proto_tree_add_item(msg_type_tree, hf_ssh_lang_tag, packet_tvb, offset, nlen, ENC_ASCII0x00000000);
4628 offset += nlen;
4629 }else if(msg_code==SSH_MSG_IGNORE2){
4630 offset += ssh_tree_add_string(packet_tvb, offset, msg_type_tree, hf_ssh_ignore_data, hf_ssh_ignore_data_length);
4631 }else if(msg_code==SSH_MSG_DEBUG4){
4632 unsigned slen;
4633 proto_tree_add_item(msg_type_tree, hf_ssh_debug_always_display, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4634 offset += 1;
4635 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_debug_message_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4636 offset += 4;
4637 proto_tree_add_item(msg_type_tree, hf_ssh_debug_message, packet_tvb, offset, slen, ENC_UTF_80x00000002);
4638 offset += slen;
4639 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_lang_tag_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4640 offset += 4;
4641 proto_tree_add_item(msg_type_tree, hf_ssh_lang_tag, packet_tvb, offset, slen, ENC_ASCII0x00000000);
4642 offset += slen;
4643 }else if(msg_code==SSH_MSG_SERVICE_REQUEST5){
4644 unsigned nlen;
4645 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_service_name_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &nlen);
4646 offset += 4;
4647 proto_tree_add_item(msg_type_tree, hf_ssh_service_name, packet_tvb, offset, nlen, ENC_ASCII0x00000000);
4648 offset += nlen;
4649 }else if(msg_code==SSH_MSG_SERVICE_ACCEPT6){
4650 unsigned nlen;
4651 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_service_name_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &nlen);
4652 offset += 4;
4653 proto_tree_add_item(msg_type_tree, hf_ssh_service_name, packet_tvb, offset, nlen, ENC_ASCII0x00000000);
4654 offset += nlen;
4655 }else if(msg_code==SSH_MSG_EXT_INFO7){
4656 unsigned ext_cnt;
4657 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_ext_count, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &ext_cnt);
4658 offset += 4;
4659 for(unsigned ext_index = 0; ext_index < ext_cnt; ext_index++) {
4660 offset = ssh_dissect_rfc8308_extension(packet_tvb, pinfo, offset, peer_data, msg_type_tree);
4661 }
4662 }
4663 return offset;
4664}
4665
4666static int
4667ssh_dissect_rfc8308_extension(tvbuff_t *packet_tvb, packet_info *pinfo,
4668 int offset, struct ssh_peer_data *peer_data, proto_item *msg_type_tree)
4669{
4670 (void)pinfo;
4671 unsigned ext_name_slen = tvb_get_ntohl(packet_tvb, offset);
4672 uint8_t *ext_name = tvb_get_string_enc(pinfo->pool, packet_tvb, offset + 4, ext_name_slen, ENC_ASCII0x00000000);
4673 unsigned ext_value_slen = tvb_get_ntohl(packet_tvb, offset + 4 + ext_name_slen);
4674 unsigned ext_len = 8 + ext_name_slen + ext_value_slen;
4675 proto_item *ext_tree = proto_tree_add_subtree_format(msg_type_tree, packet_tvb, offset, ext_len, ett_extension, NULL((void*)0), "Extension: %s", ext_name);
4676
4677 proto_tree_add_item(ext_tree, hf_ssh_ext_name_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
4678 offset += 4;
4679 proto_tree_add_item(ext_tree, hf_ssh_ext_name, packet_tvb, offset, ext_name_slen, ENC_ASCII0x00000000);
4680 offset += ext_name_slen;
4681 proto_tree_add_item(ext_tree, hf_ssh_ext_value_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
4682 offset += 4;
4683 proto_tree_add_item(ext_tree, hf_ssh_ext_value, packet_tvb, offset, ext_value_slen, ENC_NA0x00000000);
4684
4685 if (g_str_equal(ext_name, "server-sig-algs")(strcmp ((const char *) (ext_name), (const char *) ("server-sig-algs"
)) == 0)
) {
4686 // server-sig-algs (RFC8308 Sec. 3.1)
4687 proto_tree_add_item(ext_tree, hf_ssh_ext_server_sig_algs_algorithms, packet_tvb, offset, ext_value_slen, ENC_ASCII0x00000000);
4688 offset += ext_value_slen;
4689 } else if (g_str_equal(ext_name, "delay-compression")(strcmp ((const char *) (ext_name), (const char *) ("delay-compression"
)) == 0)
) {
4690 // delay-compression (RFC8308 Sec 3.2)
4691 unsigned slen;
4692 proto_tree_add_item_ret_uint(ext_tree, hf_ssh_ext_delay_compression_algorithms_client_to_server_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4693 offset += 4;
4694 proto_tree_add_item(ext_tree, hf_ssh_ext_delay_compression_algorithms_client_to_server, packet_tvb, offset, slen, ENC_ASCII0x00000000);
4695 offset += slen;
4696 proto_tree_add_item_ret_uint(ext_tree, hf_ssh_ext_delay_compression_algorithms_server_to_client_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4697 offset += 4;
4698 proto_tree_add_item(ext_tree, hf_ssh_ext_delay_compression_algorithms_server_to_client, packet_tvb, offset, slen, ENC_ASCII0x00000000);
4699 offset += slen;
4700 } else if (g_str_equal(ext_name, "no-flow-control")(strcmp ((const char *) (ext_name), (const char *) ("no-flow-control"
)) == 0)
) {
4701 // no-flow-control (RFC 8308 Sec 3.3)
4702 proto_tree_add_item(ext_tree, hf_ssh_ext_no_flow_control_value, packet_tvb, offset, ext_value_slen, ENC_ASCII0x00000000);
4703 offset += ext_value_slen;
4704 } else if (g_str_equal(ext_name, "elevation")(strcmp ((const char *) (ext_name), (const char *) ("elevation"
)) == 0)
) {
4705 // elevation (RFC 8308 Sec 3.4)
4706 proto_tree_add_item(ext_tree, hf_ssh_ext_elevation_value, packet_tvb, offset, ext_value_slen, ENC_ASCII0x00000000);
4707 offset += ext_value_slen;
4708 } else if (g_str_equal(ext_name, "[email protected]")(strcmp ((const char *) (ext_name), (const char *) ("[email protected]"
)) == 0)
) {
4709 // [email protected] (proprietary)
4710 proto_tree_add_item(ext_tree, hf_ssh_ext_prop_publickey_algorithms_algorithms, packet_tvb, offset, ext_value_slen, ENC_ASCII0x00000000);
4711 offset += ext_value_slen;
4712 } else if (g_str_equal(ext_name, "[email protected]")(strcmp ((const char *) (ext_name), (const char *) ("[email protected]"
)) == 0)
) {
4713 // [email protected] (proprietary w/ primitive extension value)
4714 peer_data->global_data->ext_ping_openssh_offered = true1;
4715 offset += ext_value_slen;
4716 } else {
4717 offset += ext_value_slen;
4718 }
4719
4720 // The following extensions do not require advanced dissection:
4721 // - global-requests-ok
4722 // - ext-auth-info
4723 // - [email protected]
4724 // - [email protected]
4725
4726 return offset;
4727}
4728
4729static int
4730ssh_dissect_userauth_generic(tvbuff_t *packet_tvb, packet_info *pinfo,
4731 int offset, proto_item *msg_type_tree, unsigned msg_code)
4732{
4733 if(msg_code==SSH_MSG_USERAUTH_REQUEST50){
4734 uint32_t slen;
4735 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_userauth_user_name_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4736 offset += 4;
4737 proto_tree_add_item(msg_type_tree, hf_ssh_userauth_user_name, packet_tvb, offset, slen, ENC_ASCII0x00000000);
4738 offset += slen;
4739 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_userauth_service_name_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4740 offset += 4;
4741 proto_tree_add_item(msg_type_tree, hf_ssh_userauth_service_name, packet_tvb, offset, slen, ENC_ASCII0x00000000);
4742 offset += slen;
4743 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_userauth_method_name_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4744 offset += 4;
4745 const char* key_type;
4746 proto_tree_add_item_ret_string(msg_type_tree, hf_ssh_userauth_method_name, packet_tvb, offset, slen, ENC_ASCII0x00000000, pinfo->pool, (const uint8_t**)&key_type);
4747 offset += slen;
4748 if (0 == strcmp(key_type, "none")) {
4749 }else if (0 == strcmp(key_type, "publickey") || 0 == strcmp(key_type, "[email protected]")) {
4750 uint8_t bHaveSignature = tvb_get_uint8(packet_tvb, offset);
4751 int dissected_len = 0;
4752 proto_tree_add_item(msg_type_tree, hf_ssh_userauth_have_signature, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4753 offset += 1;
4754 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_userauth_pka_name_len, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4755 offset += 4;
4756 proto_tree_add_item(msg_type_tree, hf_ssh_userauth_pka_name, packet_tvb, offset, slen, ENC_ASCII0x00000000);
4757 offset += slen;
4758 proto_item *ti;
4759 ti = proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_blob_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4760 offset += 4;
4761 dissected_len = ssh_dissect_public_key_blob(tvb_new_subset_length(packet_tvb, offset, slen), pinfo, msg_type_tree);
4762 if(dissected_len!=(int)slen){
4763 expert_add_info_format(pinfo, ti, &ei_ssh_packet_decode, "Decoded %d bytes, but packet length is %d bytes", dissected_len, slen);
4764 }
4765 offset += slen;
4766 if (0 == strcmp(key_type, "[email protected]")) {
4767 // Host key - but should we add it to global data or not?
4768 offset += ssh_tree_add_hostkey(packet_tvb, pinfo, offset, msg_type_tree, "Server host key",
4769 ett_key_exchange_host_key, NULL((void*)0));
4770 }
4771 if(bHaveSignature){
4772 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_signature_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4773 offset += 4;
4774 proto_item *signature_tree = NULL((void*)0);
4775 signature_tree = proto_tree_add_subtree(msg_type_tree, packet_tvb, offset, slen, ett_userauth_pk_signature, NULL((void*)0), "Public key signature");
4776 dissected_len = ssh_dissect_public_key_signature(packet_tvb, pinfo, offset, signature_tree) - offset;
4777 if(dissected_len!=(int)slen){
4778 expert_add_info_format(pinfo, signature_tree, &ei_ssh_packet_decode, "Decoded %d bytes, but packet length is %d bytes", dissected_len, slen);
4779 }
4780 offset += slen;
4781 }
4782 }else if (0 == strcmp(key_type, "password")) {
4783 uint8_t bChangePassword = tvb_get_uint8(packet_tvb, offset);
4784 proto_tree_add_item(msg_type_tree, hf_ssh_userauth_change_password, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4785 offset += 1;
4786 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_userauth_password_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4787 offset += 4;
4788 proto_tree_add_item(msg_type_tree, hf_ssh_userauth_password, packet_tvb, offset, slen, ENC_ASCII0x00000000);
4789 offset += slen;
4790 if(bChangePassword){
4791 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_userauth_new_password_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4792 offset += 4;
4793 proto_tree_add_item(msg_type_tree, hf_ssh_userauth_new_password, packet_tvb, offset, slen, ENC_ASCII0x00000000);
4794 offset += slen;
4795 }
4796 }else{
4797 }
4798
4799 }else if(msg_code==SSH_MSG_USERAUTH_FAILURE51){
4800 unsigned slen;
4801 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_auth_failure_list_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4802 offset += 4;
4803 proto_tree_add_item(msg_type_tree, hf_ssh_auth_failure_list, packet_tvb, offset, slen, ENC_ASCII0x00000000);
4804 offset += slen;
4805 proto_tree_add_item(msg_type_tree, hf_ssh_userauth_partial_success, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
4806 offset += 1;
4807 }
4808 return offset;
4809}
4810
4811static int
4812ssh_dissect_userauth_specific(tvbuff_t *packet_tvb, packet_info *pinfo,
4813 int offset, proto_item *msg_type_tree, unsigned msg_code)
4814{
4815 if(msg_code==SSH_MSG_USERAUTH_PK_OK60){
4816 proto_item *ti;
4817 int dissected_len = 0;
4818 unsigned slen;
4819 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_userauth_pka_name_len, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4820 offset += 4;
4821 proto_tree_add_item(msg_type_tree, hf_ssh_userauth_pka_name, packet_tvb, offset, slen, ENC_ASCII0x00000000);
4822 offset += slen;
4823 ti = proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_blob_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
4824 offset += 4;
4825 dissected_len = ssh_dissect_public_key_blob(tvb_new_subset_length(packet_tvb, offset, slen), pinfo, msg_type_tree);
4826 if(dissected_len!=(int)slen){
4827 expert_add_info_format(pinfo, ti, &ei_ssh_packet_decode, "Decoded %d bytes, but packet length is %d bytes", dissected_len, slen);
4828 }
4829 offset += slen;
4830 }
4831 return offset;
4832}
4833
4834static void
4835ssh_process_payload(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, ssh_channel_info_t *channel)
4836{
4837 tvbuff_t *next_tvb = tvb_new_subset_remaining(tvb, offset);
4838 if (channel->handle) {
4839 call_dissector(channel->handle, next_tvb, pinfo, proto_tree_get_root(tree));
4840 } else {
4841 call_data_dissector(next_tvb, pinfo, proto_tree_get_root(tree));
4842 }
4843}
4844
4845static void
4846print_ssh_fragment_tree(fragment_head *ipfd_head, proto_tree *tree, proto_tree *ssh_tree, packet_info *pinfo, tvbuff_t *next_tvb)
4847{
4848 proto_item *ssh_tree_item, *frag_tree_item;
4849
4850 /*
4851 * The subdissector thought it was completely
4852 * desegmented (although the stuff at the
4853 * end may, in turn, require desegmentation),
4854 * so we show a tree with all segments.
4855 */
4856 show_fragment_tree(ipfd_head, &ssh_segment_items,
4857 tree, pinfo, next_tvb, &frag_tree_item);
4858 /*
4859 * The toplevel fragment subtree is now
4860 * behind all desegmented data; move it
4861 * right behind the SSH tree.
4862 */
4863 ssh_tree_item = proto_tree_get_parent(ssh_tree);
4864 /* The SSH protocol item is up a few levels from the message tree */
4865 ssh_tree_item = proto_item_get_parent_nth(ssh_tree_item, 2);
4866 if (frag_tree_item && ssh_tree_item) {
4867 proto_tree_move_item(tree, ssh_tree_item, frag_tree_item);
4868 }
4869}
4870
4871static uint32_t
4872ssh_msp_fragment_id(struct tcp_multisegment_pdu *msp)
4873{
4874 /*
4875 * If a frame contains multiple PDUs, then "first_frame" is not
4876 * sufficient to uniquely identify groups of fragments. Therefore we use
4877 * the tcp reassembly functions that also test msp->seq (the position of
4878 * the initial fragment in the SSH channel).
4879 */
4880 return msp->first_frame;
4881}
4882
4883static void
4884ssh_proto_tree_add_segment_data(
4885 proto_tree *tree,
4886 tvbuff_t *tvb,
4887 int offset,
4888 int length,
4889 const char *prefix)
4890{
4891 proto_tree_add_bytes_format(
4892 tree,
4893 hf_ssh_segment_data,
4894 tvb,
4895 offset,
4896 length,
4897 NULL((void*)0),
4898 "%sSSH segment data (%u %s)",
4899 prefix != NULL((void*)0) ? prefix : "",
4900 length,
4901 plurality(length, "byte", "bytes")((length) == 1 ? ("byte") : ("bytes")));
4902}
4903
4904static void
4905desegment_ssh(tvbuff_t *tvb, packet_info *pinfo, uint32_t seq,
4906 uint32_t nxtseq, proto_tree *tree, ssh_channel_info_t *channel)
4907{
4908 fragment_head *ipfd_head;
4909 bool_Bool must_desegment;
4910 bool_Bool called_dissector;
4911 unsigned another_pdu_follows;
4912 bool_Bool another_segment_in_frame = false0;
4913 int deseg_offset, offset = 0;
4914 uint32_t deseg_seq;
4915 int nbytes;
4916 proto_item *item;
4917 struct tcp_multisegment_pdu *msp;
4918 bool_Bool first_pdu = true1;
4919
4920again:
4921 ipfd_head = NULL((void*)0);
4922 must_desegment = false0;
4923 called_dissector = false0;
4924 another_pdu_follows = 0;
4925 msp = NULL((void*)0);
4926
4927 /*
4928 * Initialize these to assume no desegmentation.
4929 * If that's not the case, these will be set appropriately
4930 * by the subdissector.
4931 */
4932 pinfo->desegment_offset = 0;
4933 pinfo->desegment_len = 0;
4934
4935 /*
4936 * Initialize this to assume that this segment will just be
4937 * added to the middle of a desegmented chunk of data, so
4938 * that we should show it all as data.
4939 * If that's not the case, it will be set appropriately.
4940 */
4941 deseg_offset = offset;
4942
4943 /* If we've seen this segment before (e.g., it's a retransmission),
4944 * there's nothing for us to do. Certainly, don't add it to the list
4945 * of multisegment_pdus (that would cause subsequent lookups to find
4946 * the retransmission instead of the original transmission, breaking
4947 * dissection of the desegmented pdu if we'd already seen the end of
4948 * the pdu).
4949 */
4950 if ((msp = (struct tcp_multisegment_pdu *)wmem_tree_lookup32(channel->multisegment_pdus, seq))) {
4951 const char *prefix;
4952 bool_Bool is_retransmission = false0;
4953
4954 if (msp->first_frame == pinfo->num) {
4955 /* This must be after the first pass. */
4956 prefix = "";
4957 if (msp->last_frame == pinfo->num) {
4958 col_clear(pinfo->cinfo, COL_INFO);
4959 } else {
4960 if (first_pdu) {
4961 col_append_sep_str(pinfo->cinfo, COL_INFO, " ", "[SSH segment of a reassembled PDU]");
4962 }
4963 }
4964 } else {
4965 prefix = "Retransmitted ";
4966 is_retransmission = true1;
4967 }
4968
4969 if (!is_retransmission) {
4970 ipfd_head = fragment_get(&ssh_reassembly_table, pinfo, msp->first_frame, msp);
4971 if (ipfd_head != NULL((void*)0) && ipfd_head->reassembled_in !=0 &&
4972 ipfd_head->reassembled_in != pinfo->num) {
4973 /* Show what frame this was reassembled in if not this one. */
4974 item=proto_tree_add_uint(tree, *ssh_segment_items.hf_reassembled_in,
4975 tvb, 0, 0, ipfd_head->reassembled_in);
4976 proto_item_set_generated(item);
4977 }
4978 }
4979 nbytes = tvb_reported_length_remaining(tvb, offset);
4980 ssh_proto_tree_add_segment_data(tree, tvb, offset, nbytes, prefix);
4981 return;
4982 }
4983
4984 /* Else, find the most previous PDU starting before this sequence number */
4985 msp = (struct tcp_multisegment_pdu *)wmem_tree_lookup32_le(channel->multisegment_pdus, seq-1);
4986 if (msp && msp->seq <= seq && msp->nxtpdu > seq) {
4987 unsigned len;
4988
4989 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
4990 msp->last_frame = pinfo->num;
4991 msp->last_frame_time = pinfo->abs_ts;
4992 }
4993
4994 /* OK, this PDU was found, which means the segment continues
4995 * a higher-level PDU and that we must desegment it.
4996 */
4997 if (msp->flags & MSP_FLAGS_REASSEMBLE_ENTIRE_SEGMENT0x00000001) {
4998 /* The dissector asked for the entire segment */
4999 len = tvb_reported_length_remaining(tvb, offset);
5000 } else {
5001 len = MIN(nxtseq, msp->nxtpdu)(((nxtseq) < (msp->nxtpdu)) ? (nxtseq) : (msp->nxtpdu
))
- seq;
5002 }
5003
5004 ipfd_head = fragment_add(&ssh_reassembly_table, tvb, offset,
5005 pinfo, ssh_msp_fragment_id(msp), msp,
5006 seq - msp->seq,
5007 len, (LT_SEQ (nxtseq,msp->nxtpdu)((int32_t)((nxtseq) - (msp->nxtpdu)) < 0)));
5008
5009 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)
5010 && msp->flags & MSP_FLAGS_REASSEMBLE_ENTIRE_SEGMENT0x00000001) {
5011 msp->flags &= (~MSP_FLAGS_REASSEMBLE_ENTIRE_SEGMENT0x00000001);
5012
5013 /* If we consumed the entire segment there is no
5014 * other pdu starting anywhere inside this segment.
5015 * So update nxtpdu to point at least to the start
5016 * of the next segment.
5017 * (If the subdissector asks for even more data we
5018 * will advance nxtpdu even further later down in
5019 * the code.)
5020 */
5021 msp->nxtpdu = nxtseq;
5022 }
5023
5024 if ( (msp->nxtpdu < nxtseq)
5025 && (msp->nxtpdu >= seq)
5026 && (len > 0)) {
5027 another_pdu_follows = msp->nxtpdu - seq;
5028 }
5029 } else {
5030 /* This segment was not found in our table, so it doesn't
5031 * contain a continuation of a higher-level PDU.
5032 * Call the normal subdissector.
5033 */
5034 ssh_process_payload(tvb, offset, pinfo, tree, channel);
5035 called_dissector = true1;
5036
5037 /* Did the subdissector ask us to desegment some more data
5038 * before it could handle the packet?
5039 * If so we have to create some structures in our table but
5040 * this is something we only do the first time we see this
5041 * packet.
5042 */
5043 if (pinfo->desegment_len) {
5044 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited))
5045 must_desegment = true1;
5046
5047 /*
5048 * Set "deseg_offset" to the offset in "tvb"
5049 * of the first byte of data that the
5050 * subdissector didn't process.
5051 */
5052 deseg_offset = offset + pinfo->desegment_offset;
5053 }
5054
5055 /* Either no desegmentation is necessary, or this is
5056 * segment contains the beginning but not the end of
5057 * a higher-level PDU and thus isn't completely
5058 * desegmented.
5059 */
5060 ipfd_head = NULL((void*)0);
5061 }
5062
5063 /* is it completely desegmented? */
5064 if (ipfd_head && ipfd_head->reassembled_in == pinfo->num) {
5065 /*
5066 * Yes, we think it is.
5067 * We only call subdissector for the last segment.
5068 * Note that the last segment may include more than what
5069 * we needed.
5070 */
5071 if (nxtseq < msp->nxtpdu) {
5072 /*
5073 * This is *not* the last segment. It is part of a PDU in the same
5074 * frame, so no another PDU can follow this one.
5075 * Do not reassemble SSH yet, it will be done in the final segment.
5076 * (If we are reassembling at FIN, we will do that in dissect_ssl()
5077 * after iterating through all the records.)
5078 * Clear the Info column and avoid displaying [SSH segment of a
5079 * reassembled PDU], the payload dissector will typically set it.
5080 * (This is needed here for the second pass.)
5081 */
5082 another_pdu_follows = 0;
5083 col_clear(pinfo->cinfo, COL_INFO);
5084 another_segment_in_frame = true1;
5085 } else {
5086 /*
5087 * OK, this is the last segment of the PDU and also the
5088 * last segment in this frame.
5089 * Let's call the subdissector with the desegmented
5090 * data.
5091 */
5092 tvbuff_t *next_tvb;
5093 int old_len;
5094
5095 /*
5096 * Reset column in case multiple SSH segments form the PDU
5097 * and this last SSH segment is not in the first TCP segment of
5098 * this frame.
5099 * XXX prevent clearing the column if the last layer is not SSH?
5100 */
5101 /* Clear column during the first pass. */
5102 col_clear(pinfo->cinfo, COL_INFO);
5103
5104 /* create a new TVB structure for desegmented data */
5105 next_tvb = tvb_new_chain(tvb, ipfd_head->tvb_data);
5106
5107 /* add desegmented data to the data source list */
5108 add_new_data_source(pinfo, next_tvb, "Reassembled SSH");
5109
5110 /* call subdissector */
5111 ssh_process_payload(next_tvb, 0, pinfo, tree, channel);
5112 called_dissector = true1;
5113
5114 /*
5115 * OK, did the subdissector think it was completely
5116 * desegmented, or does it think we need even more
5117 * data?
5118 */
5119 old_len = (int)(tvb_reported_length(next_tvb) - tvb_reported_length_remaining(tvb, offset));
5120 if (pinfo->desegment_len && pinfo->desegment_offset <= old_len) {
5121 /*
5122 * "desegment_len" isn't 0, so it needs more
5123 * data for something - and "desegment_offset"
5124 * is before "old_len", so it needs more data
5125 * to dissect the stuff we thought was
5126 * completely desegmented (as opposed to the
5127 * stuff at the beginning being completely
5128 * desegmented, but the stuff at the end
5129 * being a new higher-level PDU that also
5130 * needs desegmentation).
5131 */
5132 fragment_set_partial_reassembly(&ssh_reassembly_table,
5133 pinfo, ssh_msp_fragment_id(msp), msp);
5134 /* Update msp->nxtpdu to point to the new next
5135 * pdu boundary.
5136 */
5137 if (pinfo->desegment_len == DESEGMENT_ONE_MORE_SEGMENT0x0fffffff) {
5138 /* We want reassembly of at least one
5139 * more segment so set the nxtpdu
5140 * boundary to one byte into the next
5141 * segment.
5142 * This means that the next segment
5143 * will complete reassembly even if it
5144 * is only one single byte in length.
5145 */
5146 msp->nxtpdu = seq + tvb_reported_length_remaining(tvb, offset) + 1;
5147 msp->flags |= MSP_FLAGS_REASSEMBLE_ENTIRE_SEGMENT0x00000001;
5148 } else if (pinfo->desegment_len == DESEGMENT_UNTIL_FIN0x0ffffffe) {
5149 /* This is not the first segment, and we thought reassembly
5150 * would be done now, but now we know we desegment at FIN.
5151 * E.g., a HTTP response where the headers were split
5152 * across segments (so previous ONE_MORE_SEGMENT) and
5153 * also no Content-Length (so now DESEGMENT_UNTIL_FIN).
5154 */
5155 channel->flags |= TCP_FLOW_REASSEMBLE_UNTIL_FIN0x0001;
5156 msp->nxtpdu = nxtseq + 0x40000000;
5157 } else {
5158 msp->nxtpdu = seq + tvb_reported_length_remaining(tvb, offset) + pinfo->desegment_len;
5159 }
5160 /* Since we need at least some more data
5161 * there can be no pdu following in the
5162 * tail of this segment.
5163 */
5164 another_pdu_follows = 0;
5165 } else {
5166 /*
5167 * Show the stuff in this TCP segment as
5168 * just raw TCP segment data.
5169 */
5170 nbytes = another_pdu_follows > 0
5171 ? another_pdu_follows
5172 : tvb_reported_length_remaining(tvb, offset);
5173 ssh_proto_tree_add_segment_data(tree, tvb, offset, nbytes, NULL((void*)0));
5174
5175 /* Show details of the reassembly */
5176 print_ssh_fragment_tree(ipfd_head, proto_tree_get_root(tree), tree, pinfo, next_tvb);
5177
5178 /* Did the subdissector ask us to desegment
5179 * some more data? This means that the data
5180 * at the beginning of this segment completed
5181 * a higher-level PDU, but the data at the
5182 * end of this segment started a higher-level
5183 * PDU but didn't complete it.
5184 *
5185 * If so, we have to create some structures
5186 * in our table, but this is something we
5187 * only do the first time we see this packet.
5188 */
5189 if (pinfo->desegment_len) {
5190 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited))
5191 must_desegment = true1;
5192
5193 /* The stuff we couldn't dissect
5194 * must have come from this segment,
5195 * so it's all in "tvb".
5196 *
5197 * "pinfo->desegment_offset" is
5198 * relative to the beginning of
5199 * "next_tvb"; we want an offset
5200 * relative to the beginning of "tvb".
5201 *
5202 * First, compute the offset relative
5203 * to the *end* of "next_tvb" - i.e.,
5204 * the number of bytes before the end
5205 * of "next_tvb" at which the
5206 * subdissector stopped. That's the
5207 * length of "next_tvb" minus the
5208 * offset, relative to the beginning
5209 * of "next_tvb, at which the
5210 * subdissector stopped.
5211 */
5212 deseg_offset = ipfd_head->datalen - pinfo->desegment_offset;
5213
5214 /* "tvb" and "next_tvb" end at the
5215 * same byte of data, so the offset
5216 * relative to the end of "next_tvb"
5217 * of the byte at which we stopped
5218 * is also the offset relative to
5219 * the end of "tvb" of the byte at
5220 * which we stopped.
5221 *
5222 * Convert that back into an offset
5223 * relative to the beginning of
5224 * "tvb", by taking the length of
5225 * "tvb" and subtracting the offset
5226 * relative to the end.
5227 */
5228 deseg_offset = tvb_reported_length(tvb) - deseg_offset;
5229 }
5230 }
5231 }
5232 }
5233
5234 if (must_desegment) {
5235 /* If the dissector requested "reassemble until FIN"
5236 * just set this flag for the flow and let reassembly
5237 * proceed at normal. We will check/pick up these
5238 * reassembled PDUs later down in dissect_tcp() when checking
5239 * for the FIN flag.
5240 */
5241 if (pinfo->desegment_len == DESEGMENT_UNTIL_FIN0x0ffffffe) {
5242 channel->flags |= TCP_FLOW_REASSEMBLE_UNTIL_FIN0x0001;
5243 }
5244 /*
5245 * The sequence number at which the stuff to be desegmented
5246 * starts is the sequence number of the byte at an offset
5247 * of "deseg_offset" into "tvb".
5248 *
5249 * The sequence number of the byte at an offset of "offset"
5250 * is "seq", i.e. the starting sequence number of this
5251 * segment, so the sequence number of the byte at
5252 * "deseg_offset" is "seq + (deseg_offset - offset)".
5253 */
5254 deseg_seq = seq + (deseg_offset - offset);
5255
5256 if (((nxtseq - deseg_seq) <= 1024*1024)
5257 && (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited))) {
5258 if (pinfo->desegment_len == DESEGMENT_ONE_MORE_SEGMENT0x0fffffff) {
5259 /* The subdissector asked to reassemble using the
5260 * entire next segment.
5261 * Just ask reassembly for one more byte
5262 * but set this msp flag so we can pick it up
5263 * above.
5264 */
5265 msp = pdu_store_sequencenumber_of_next_pdu(pinfo,
5266 deseg_seq, nxtseq+1, channel->multisegment_pdus);
5267 msp->flags |= MSP_FLAGS_REASSEMBLE_ENTIRE_SEGMENT0x00000001;
5268 } else if (pinfo->desegment_len == DESEGMENT_UNTIL_FIN0x0ffffffe) {
5269 /* Set nxtseq very large so that reassembly won't happen
5270 * until we force it at the end of the stream in dissect_ssl()
5271 * outside this function.
5272 */
5273 msp = pdu_store_sequencenumber_of_next_pdu(pinfo,
5274 deseg_seq, nxtseq+0x40000000, channel->multisegment_pdus);
5275 } else {
5276 msp = pdu_store_sequencenumber_of_next_pdu(pinfo,
5277 deseg_seq, nxtseq+pinfo->desegment_len, channel->multisegment_pdus);
5278 }
5279
5280 /* add this segment as the first one for this new pdu */
5281 fragment_add(&ssh_reassembly_table, tvb, deseg_offset,
5282 pinfo, ssh_msp_fragment_id(msp), msp,
5283 0, nxtseq - deseg_seq,
5284 LT_SEQ(nxtseq, msp->nxtpdu)((int32_t)((nxtseq) - (msp->nxtpdu)) < 0));
5285 }
5286 }
5287
5288 if (!called_dissector || pinfo->desegment_len != 0) {
5289 if (ipfd_head != NULL((void*)0) && ipfd_head->reassembled_in != 0 &&
5290 ipfd_head->reassembled_in != pinfo->num &&
5291 !(ipfd_head->flags & FD_PARTIAL_REASSEMBLY0x0040)) {
5292 /*
5293 * We know what other frame this PDU is reassembled in;
5294 * let the user know.
5295 */
5296 item=proto_tree_add_uint(tree, *ssh_segment_items.hf_reassembled_in,
5297 tvb, 0, 0, ipfd_head->reassembled_in);
5298 proto_item_set_generated(item);
5299 }
5300
5301 /*
5302 * Either we didn't call the subdissector at all (i.e.,
5303 * this is a segment that contains the middle of a
5304 * higher-level PDU, but contains neither the beginning
5305 * nor the end), or the subdissector couldn't dissect it
5306 * all, as some data was missing (i.e., it set
5307 * "pinfo->desegment_len" to the amount of additional
5308 * data it needs).
5309 */
5310 if (!another_segment_in_frame && pinfo->desegment_offset == 0) {
5311 /*
5312 * It couldn't, in fact, dissect any of it (the
5313 * first byte it couldn't dissect is at an offset
5314 * of "pinfo->desegment_offset" from the beginning
5315 * of the payload, and that's 0).
5316 * Just mark this as SSH.
5317 */
5318
5319 /* SFTP checks the length before setting the protocol column.
5320 * If other subdissectors don't do this, we'd want to set the
5321 * protocol column back - but we want to get the SSH version
5322 */
5323 //col_set_str(pinfo->cinfo, COL_PROTOCOL,
5324 // val_to_str_const(session->version, ssl_version_short_names, "SSH"));
5325 if (first_pdu) {
5326 col_append_sep_str(pinfo->cinfo, COL_INFO, " ", "[SSH segment of a reassembled PDU]");
5327 }
5328 }
5329
5330 /*
5331 * Show what's left in the packet as just raw SSH segment data.
5332 * XXX - remember what protocol the last subdissector
5333 * was, and report it as a continuation of that, instead?
5334 */
5335 nbytes = tvb_reported_length_remaining(tvb, deseg_offset);
5336 ssh_proto_tree_add_segment_data(tree, tvb, deseg_offset, nbytes, NULL((void*)0));
5337 }
5338 pinfo->can_desegment = 0;
5339 pinfo->desegment_offset = 0;
5340 pinfo->desegment_len = 0;
5341
5342 if (another_pdu_follows) {
5343 /* there was another pdu following this one. */
5344 pinfo->can_desegment=2;
5345 /* we also have to prevent the dissector from changing the
5346 * PROTOCOL and INFO columns since what follows may be an
5347 * incomplete PDU and we don't want it be changed back from
5348 * <Protocol> to <SSH>
5349 */
5350 col_set_fence(pinfo->cinfo, COL_INFO);
5351 col_set_writable(pinfo->cinfo, COL_PROTOCOL, false0);
5352 first_pdu = false0;
5353 offset += another_pdu_follows;
5354 seq += another_pdu_follows;
5355 goto again;
5356 }
5357}
5358
5359static void
5360ssh_dissect_channel_data(tvbuff_t *tvb, packet_info *pinfo,
5361 struct ssh_peer_data *peer_data _U___attribute__((unused)), proto_tree *tree,
5362 ssh_message_info_t *message _U___attribute__((unused)), ssh_channel_info_t *channel)
5363{
5364
5365 uint16_t save_can_desegment = pinfo->can_desegment;
5366
5367 if (ssh_desegment) {
5368 pinfo->can_desegment = 2;
5369 desegment_ssh(tvb, pinfo, message->byte_seq, message->next_byte_seq, tree, channel);
5370 } else {
5371 pinfo->can_desegment = 0;
5372 bool_Bool save_fragmented = pinfo->fragmented;
5373 pinfo->fragmented = true1;
5374
5375 ssh_process_payload(tvb, 0, pinfo, tree, channel);
5376 pinfo->fragmented = save_fragmented;
5377 }
5378
5379 pinfo->can_desegment = save_can_desegment;
5380}
5381
5382static int
5383ssh_dissect_term_modes(tvbuff_t *tvb, packet_info *pinfo _U___attribute__((unused)), proto_tree *tree)
5384{
5385 proto_item *ti;
5386 proto_tree *term_mode_tree, *subtree;
5387 unsigned offset = 0;
5388 uint32_t opcode, value, idx;
5389 bool_Bool boolval;
5390
5391 struct tty_opt_info {
5392 unsigned id;
5393 int *hfindex;
5394 };
5395 static const struct tty_opt_info tty_opts[] = {
5396 { SSH_TTY_OP_END0, NULL((void*)0)},
5397 { SSH_TTY_OP_VINTR1, &hf_ssh_pty_term_mode_vintr },
5398 { SSH_TTY_OP_VQUIT2, &hf_ssh_pty_term_mode_vquit },
5399 { SSH_TTY_OP_VERASE3, &hf_ssh_pty_term_mode_verase },
5400 { SSH_TTY_OP_VKILL4, &hf_ssh_pty_term_mode_vkill },
5401 { SSH_TTY_OP_VEOF5, &hf_ssh_pty_term_mode_veof },
5402 { SSH_TTY_OP_VEOL6, &hf_ssh_pty_term_mode_veol },
5403 { SSH_TTY_OP_VEOL27, &hf_ssh_pty_term_mode_veol2 },
5404 { SSH_TTY_OP_VSTART8, &hf_ssh_pty_term_mode_vstart },
5405 { SSH_TTY_OP_VSTOP9, &hf_ssh_pty_term_mode_vstop },
5406 { SSH_TTY_OP_VSUSP10, &hf_ssh_pty_term_mode_vsusp },
5407 { SSH_TTY_OP_VDSUSP11, &hf_ssh_pty_term_mode_vdsusp },
5408 { SSH_TTY_OP_VREPRINT12, &hf_ssh_pty_term_mode_vreprint },
5409 { SSH_TTY_OP_VWERASE13, &hf_ssh_pty_term_mode_vwerase },
5410 { SSH_TTY_OP_VLNEXT14, &hf_ssh_pty_term_mode_vlnext },
5411 { SSH_TTY_OP_VFLUSH15, &hf_ssh_pty_term_mode_vflush },
5412 { SSH_TTY_OP_VSWTCH16, &hf_ssh_pty_term_mode_vswtch },
5413 { SSH_TTY_OP_VSTATUS17, &hf_ssh_pty_term_mode_vstatus },
5414 { SSH_TTY_OP_VDISCARD18, &hf_ssh_pty_term_mode_vdiscard },
5415 { SSH_TTY_OP_IGNPAR30, &hf_ssh_pty_term_mode_ignpar },
5416 { SSH_TTY_OP_PARMRK31, &hf_ssh_pty_term_mode_parmrk },
5417 { SSH_TTY_OP_INPCK32, &hf_ssh_pty_term_mode_inpck },
5418 { SSH_TTY_OP_ISTRIP33, &hf_ssh_pty_term_mode_istrip },
5419 { SSH_TTY_OP_INLCR34, &hf_ssh_pty_term_mode_inlcr },
5420 { SSH_TTY_OP_IGNCR35, &hf_ssh_pty_term_mode_igncr },
5421 { SSH_TTY_OP_ICRNL36, &hf_ssh_pty_term_mode_icrnl },
5422 { SSH_TTY_OP_IUCLC37, &hf_ssh_pty_term_mode_iuclc },
5423 { SSH_TTY_OP_IXON38, &hf_ssh_pty_term_mode_ixon },
5424 { SSH_TTY_OP_IXANY39, &hf_ssh_pty_term_mode_ixany },
5425 { SSH_TTY_OP_IXOFF40, &hf_ssh_pty_term_mode_ixoff },
5426 { SSH_TTY_OP_IMAXBEL41, &hf_ssh_pty_term_mode_imaxbel },
5427 { SSH_TTY_OP_IUTF842, &hf_ssh_pty_term_mode_iutf8 },
5428 { SSH_TTY_OP_ISIG50, &hf_ssh_pty_term_mode_isig },
5429 { SSH_TTY_OP_ICANON51, &hf_ssh_pty_term_mode_icanon },
5430 { SSH_TTY_OP_XCASE52, &hf_ssh_pty_term_mode_xcase },
5431 { SSH_TTY_OP_ECHO53, &hf_ssh_pty_term_mode_echo },
5432 { SSH_TTY_OP_ECHOE54, &hf_ssh_pty_term_mode_echoe },
5433 { SSH_TTY_OP_ECHOK55, &hf_ssh_pty_term_mode_echok },
5434 { SSH_TTY_OP_ECHONL56, &hf_ssh_pty_term_mode_echonl },
5435 { SSH_TTY_OP_NOFLSH57, &hf_ssh_pty_term_mode_noflsh },
5436 { SSH_TTY_OP_TOSTOP58, &hf_ssh_pty_term_mode_tostop },
5437 { SSH_TTY_OP_IEXTEN59, &hf_ssh_pty_term_mode_iexten },
5438 { SSH_TTY_OP_ECHOCTL60, &hf_ssh_pty_term_mode_echoctl },
5439 { SSH_TTY_OP_ECHOKE61, &hf_ssh_pty_term_mode_echoke },
5440 { SSH_TTY_OP_PENDIN62, &hf_ssh_pty_term_mode_pendin },
5441 { SSH_TTY_OP_OPOST70, &hf_ssh_pty_term_mode_opost },
5442 { SSH_TTY_OP_OLCUC71, &hf_ssh_pty_term_mode_olcuc },
5443 { SSH_TTY_OP_ONLCR72, &hf_ssh_pty_term_mode_onlcr },
5444 { SSH_TTY_OP_OCRNL73, &hf_ssh_pty_term_mode_ocrnl },
5445 { SSH_TTY_OP_ONOCR74, &hf_ssh_pty_term_mode_onocr },
5446 { SSH_TTY_OP_ONLRET75, &hf_ssh_pty_term_mode_onlret },
5447 { SSH_TTY_OP_CS790, &hf_ssh_pty_term_mode_cs7 },
5448 { SSH_TTY_OP_CS891, &hf_ssh_pty_term_mode_cs8 },
5449 { SSH_TTY_OP_PARENB92, &hf_ssh_pty_term_mode_parenb },
5450 { SSH_TTY_OP_PARODD93, &hf_ssh_pty_term_mode_parodd },
5451 { SSH_TTY_OP_ISPEED128, &hf_ssh_pty_term_mode_ispeed },
5452 { SSH_TTY_OP_OSPEED129, &hf_ssh_pty_term_mode_ospeed }
5453 };
5454
5455 ti = proto_tree_add_item(tree, hf_ssh_pty_term_modes, tvb, offset, tvb_reported_length(tvb), ENC_NA0x00000000);
5456 term_mode_tree = proto_item_add_subtree(ti, ett_term_modes);
5457 while (tvb_reported_length_remaining(tvb, offset)) {
5458 ti = proto_tree_add_item(term_mode_tree, hf_ssh_pty_term_mode, tvb, offset, 5, ENC_NA0x00000000);
5459 subtree = proto_item_add_subtree(ti, ett_term_mode);
5460 proto_tree_add_item_ret_uint(subtree, hf_ssh_pty_term_mode_opcode, tvb, offset, 1, ENC_NA0x00000000, &opcode);
5461 proto_item_append_text(ti, ": %s", val_to_str_const(opcode, ssh_tty_op_vals, "Unknown"));
5462 offset += 1;
5463 if (opcode == SSH_TTY_OP_END0) {
5464 break;
5465 }
5466 for (idx = 0; idx < array_length(tty_opts)(sizeof (tty_opts) / sizeof (tty_opts)[0]); idx++) {
5467 if (tty_opts[idx].id == opcode) break;
5468 }
5469 if (idx >= array_length(tty_opts)(sizeof (tty_opts) / sizeof (tty_opts)[0])) {
5470 proto_tree_add_item_ret_uint(subtree, hf_ssh_pty_term_mode_value, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &value);
5471 proto_item_append_text(ti, "=%d", value);
5472 } else {
5473 DISSECTOR_ASSERT(tty_opts[idx].hfindex)((void) ((tty_opts[idx].hfindex) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-ssh.c"
, 5473, "tty_opts[idx].hfindex"))))
;
5474 int hfindex = *tty_opts[idx].hfindex;
5475 switch (proto_registrar_get_ftype(hfindex)) {
5476 case FT_BOOLEAN:
5477 proto_tree_add_item_ret_boolean(subtree, hfindex, tvb, offset + 3, 1, ENC_NA0x00000000, &boolval);
5478 proto_item_append_text(ti, "=%s", boolval ? "True" : "False");
5479 break;
5480 case FT_CHAR:
5481 proto_tree_add_item_ret_uint(subtree, hfindex, tvb, offset + 3, 1, ENC_NA0x00000000, &value);
5482 proto_item_append_text(ti, "='%s'", format_char(pinfo->pool, (char)value));
5483 break;
5484 case FT_UINT32:
5485 proto_tree_add_item_ret_uint(subtree, hfindex, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &value);
5486 proto_item_append_text(ti, "=%d", value);
5487 break;
5488 default:
5489 DISSECTOR_ASSERT_NOT_REACHED()(proto_report_dissector_bug("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\""
, "epan/dissectors/packet-ssh.c", 5489))
;
5490 }
5491 }
5492 offset += 4;
5493 }
5494 return offset;
5495}
5496
5497static int
5498ssh_dissect_connection_specific(tvbuff_t *packet_tvb, packet_info *pinfo,
5499 struct ssh_peer_data *peer_data, int offset, proto_tree *msg_type_tree,
5500 unsigned msg_code, ssh_message_info_t *message)
5501{
5502 uint32_t recipient_channel, sender_channel;
5503
5504 if (msg_code == SSH_MSG_CHANNEL_OPEN90) {
5505 uint32_t slen;
5506 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_connection_type_name_len, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5507 offset += 4;
5508 proto_tree_add_item(msg_type_tree, hf_ssh_connection_type_name, packet_tvb, offset, slen, ENC_UTF_80x00000002);
5509 offset += slen;
5510 proto_tree_add_item(msg_type_tree, hf_ssh_connection_sender_channel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5511 offset += 4;
5512 proto_tree_add_item(msg_type_tree, hf_ssh_connection_initial_window, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5513 offset += 4;
5514 proto_tree_add_item(msg_type_tree, hf_ssh_connection_maximum_packet_size, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5515 offset += 4;
5516 } else if (msg_code == SSH_MSG_CHANNEL_OPEN_CONFIRMATION91) {
5517 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_connection_recipient_channel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &recipient_channel);
5518 offset += 4;
5519 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_connection_sender_channel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &sender_channel);
5520 offset += 4;
5521 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
5522 create_channel(peer_data, recipient_channel, sender_channel);
5523 }
5524 proto_tree_add_item(msg_type_tree, hf_ssh_connection_initial_window, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5525 offset += 4;
5526 proto_tree_add_item(msg_type_tree, hf_ssh_connection_maximum_packet_size, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5527 offset += 4;
5528 } else if (msg_code == SSH_MSG_CHANNEL_WINDOW_ADJUST93) {
5529 proto_tree_add_item(msg_type_tree, hf_ssh_connection_recipient_channel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5530 offset += 4;
5531 proto_tree_add_item(msg_type_tree, hf_ssh_channel_window_adjust, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000); // TODO: maintain count of transferred bytes and window size
5532 offset += 4;
5533 } else if (msg_code == SSH_MSG_CHANNEL_DATA94) {
5534 proto_item* ti = proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_connection_recipient_channel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &recipient_channel);
5535 offset += 4;
5536 // TODO: process according to the type of channel
5537 uint32_t slen;
5538 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_channel_data_len, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5539 offset += 4;
5540 tvbuff_t* next_tvb = tvb_new_subset_length(packet_tvb, offset, slen);
5541
5542 ssh_channel_info_t* channel = get_channel_info_for_channel(peer_data, recipient_channel);
5543 if (channel) {
5544 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
5545 message->byte_seq = channel->byte_seq;
5546 channel->byte_seq += slen;
5547 message->next_byte_seq = channel->byte_seq;
5548 }
5549 ssh_dissect_channel_data(next_tvb, pinfo, peer_data, msg_type_tree, message, channel);
5550 } else {
5551 expert_add_info_format(pinfo, ti, &ei_ssh_channel_number, "Could not find configuration for channel %d", recipient_channel);
5552 }
5553 offset += slen;
5554 } else if (msg_code == SSH_MSG_CHANNEL_EXTENDED_DATA95) {
5555 proto_item* ti = proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_connection_recipient_channel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &recipient_channel);
5556 offset += 4;
5557 // TODO: process according to the type of channel
5558 proto_tree_add_item(msg_type_tree, hf_ssh_channel_data_type_code, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5559 offset += 4;
5560 uint32_t slen;
5561 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_channel_data_len, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5562 offset += 4;
5563 tvbuff_t* next_tvb = tvb_new_subset_length(packet_tvb, offset, slen);
5564
5565 ssh_channel_info_t* channel = get_channel_info_for_channel(peer_data, recipient_channel);
5566 if (channel) {
5567 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
5568 message->byte_seq = channel->byte_seq;
5569 channel->byte_seq += slen;
5570 message->next_byte_seq = channel->byte_seq;
5571 }
5572 ssh_dissect_channel_data(next_tvb, pinfo, peer_data, msg_type_tree, message, channel);
5573 } else {
5574 expert_add_info_format(pinfo, ti, &ei_ssh_channel_number, "Could not find configuration for channel %d", recipient_channel);
5575 }
5576 offset += slen;
5577 } else if (msg_code == SSH_MSG_CHANNEL_EOF96) {
5578 proto_tree_add_item(msg_type_tree, hf_ssh_connection_recipient_channel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5579 offset += 4;
5580 } else if (msg_code == SSH_MSG_CHANNEL_CLOSE97) {
5581 proto_tree_add_item(msg_type_tree, hf_ssh_connection_recipient_channel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5582 offset += 4;
5583 } else if (msg_code == SSH_MSG_CHANNEL_REQUEST98) {
5584 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_connection_recipient_channel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &recipient_channel);
5585 offset += 4;
5586 const char* request_name;
5587 uint32_t slen;
5588 unsigned item_len;
5589 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_channel_request_name_len, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5590 offset += 4;
5591 proto_tree_add_item_ret_string(msg_type_tree, hf_ssh_channel_request_name, packet_tvb, offset, slen, ENC_UTF_80x00000002, pinfo->pool, (const uint8_t**)&request_name);
5592 offset += slen;
5593 proto_tree_add_item(msg_type_tree, hf_ssh_channel_request_want_reply, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
5594 offset += 1;
5595 /* RFC 4254 6.5: "Only one of these requests ["shell", "exec",
5596 * or "subsystem"] can succeed per channel." Set up the
5597 * appropriate handler for future CHANNEL_DATA and
5598 * CHANNEL_EXTENDED_DATA messages on the channel.
5599 *
5600 * XXX - For "shell" and "exec", it might make more sense to send
5601 * CHANNEL_DATA to the "data-text-lines" dissector rather than "data".
5602 * Ideally if a pty has been setup there would be a way to interpret
5603 * the escape codes.
5604 */
5605 if (0 == strcmp(request_name, "subsystem")) {
5606 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_subsystem_name_len, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5607 offset += 4;
5608 const char* subsystem_name;
5609 proto_tree_add_item_ret_string(msg_type_tree, hf_ssh_subsystem_name, packet_tvb, offset, slen, ENC_UTF_80x00000002, pinfo->pool, (const uint8_t**)&subsystem_name);
5610 set_subdissector_for_channel(peer_data, recipient_channel, subsystem_name);
5611 offset += slen;
5612 } else if (0 == strcmp(request_name, "env")) {
5613 /* The encoding for "env" variables and "exec" commands is not
5614 * specified in the SSH protocol, and must match whatever the
5615 * server expects. (Unlike CHANNEL_DATA, it is not affected by
5616 * whatever is in "env" or anything else in the protocol, and the
5617 * strings are passed to execve directly.) In practice the strings
5618 * must not have internal NULs (no UTF-16), and OpenSSH for Windows
5619 * and IBM z/OS force the use of UTF-8 and ISO-8859-1, respectively.
5620 *
5621 * These will probably be ASCII-compatible.
5622 */
5623 proto_tree_add_item_ret_length(msg_type_tree, hf_ssh_env_name, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000 | ENC_UTF_80x00000002, &item_len);
5624 offset += item_len;
5625 proto_tree_add_item_ret_length(msg_type_tree, hf_ssh_env_value, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000 | ENC_UTF_80x00000002, &item_len);
5626 offset += item_len;
5627 } else if (0 == strcmp(request_name, "exec")) {
5628 proto_tree_add_item_ret_length(msg_type_tree, hf_ssh_exec_cmd, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000 | ENC_UTF_80x00000002, &item_len);
5629 offset += item_len;
5630 set_subdissector_for_channel(peer_data, recipient_channel, "exec");
5631 } else if (0 == strcmp(request_name, "exit-status")) {
5632 proto_tree_add_item(msg_type_tree, hf_ssh_exit_status, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5633 offset += 4;
5634 } else if (0 == strcmp(request_name, "shell")) {
5635 set_subdissector_for_channel(peer_data, recipient_channel, "shell");
5636 } else if (0 == strcmp(request_name, "pty-req")) {
5637 proto_tree_add_item_ret_length(msg_type_tree, hf_ssh_pty_term, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000 | ENC_UTF_80x00000002, &item_len);
5638 offset += item_len;
5639 proto_tree_add_item(msg_type_tree, hf_ssh_pty_term_width_char, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5640 offset += 4;
5641 proto_tree_add_item(msg_type_tree, hf_ssh_pty_term_height_row, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5642 offset += 4;
5643 proto_tree_add_item(msg_type_tree, hf_ssh_pty_term_width_pixel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5644 offset += 4;
5645 proto_tree_add_item(msg_type_tree, hf_ssh_pty_term_height_pixel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5646 offset += 4;
5647 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_pty_term_modes_len, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5648 offset += 4;
5649 offset += ssh_dissect_term_modes(tvb_new_subset_length(packet_tvb, offset, slen), pinfo, msg_type_tree);
5650 }
5651 } else if (msg_code == SSH_MSG_CHANNEL_SUCCESS99) {
5652 proto_tree_add_item(msg_type_tree, hf_ssh_connection_recipient_channel, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
5653 offset += 4;
5654 }
5655 return offset;
5656}
5657
5658/* Channel mapping {{{ */
5659
5660/* The usual flow:
5661 * 1. client sends SSH_MSG_CHANNEL_OPEN with its (sender) channel number
5662 * 2. server responds with SSH_MSG_CHANNEL_OPEN_CONFIRMATION with
5663 * its channel number and echoing the client's number, creating
5664 * a bijective map
5665 * 3. client sends SSH_MSG_CHANNEL_REQUEST which has the name of
5666 * the shell, command, or subsystem to start. This has the recipient's
5667 * channel number (i.e. the server's)
5668 * 4. server may send back a SSG_MSG_CHANNEL_SUCCESS (or _FAILURE) with
5669 * the the recipient (i.e., client) channel number, but this does not
5670 * contain the subsystem name or anything identifying the request to
5671 * which it responds. It MUST be sent in the same order as the
5672 * corresponding request message (RFC 4254 4 Global Requests), so we
5673 * could track it that way, but for our purposes we just treat all
5674 * requests as successes. (If not, either there won't be data or another
5675 * request will supercede it later.)
5676 *
5677 * Either side can open a channel (RFC 4254 5 Channel Mechanism). The
5678 * typical flow is the client opening a channel, but in the case of
5679 * remote port forwarding (7 TCP/IP Port Forwarding) the directions are
5680 * swapped. For port forwarding, all the information is contained in the
5681 * SSH_MSG_CHANNEL_OPEN, there is no SSH_MSG_CHANNEL_REQUEST.
5682*
5683 * XXX: Channel numbers can be re-used after being closed (5.3 Closing a
5684 * Channel), but not necessarily mapped to the same channel number on the
5685 * other side. If that actually happens, the right way to handle this is
5686 * to track the state changes over time for random packet access (e.g.,
5687 * using a multimap with the packet number instead of maps.)
5688 */
5689
5690static struct ssh_peer_data*
5691get_other_peer_data(struct ssh_peer_data *peer_data)
5692{
5693 bool_Bool is_server = &peer_data->global_data->peer_data[SERVER_PEER_DATA1]==peer_data;
5694 if (is_server) {
5695 return &peer_data->global_data->peer_data[CLIENT_PEER_DATA0];
5696 } else {
5697 return &peer_data->global_data->peer_data[SERVER_PEER_DATA1];
5698 }
5699}
5700
5701/* Create pairings between a recipient channel and the sender's channel,
5702 * from a SSH_MSG_CHANNEL_OPEN_CONFIRMATION. */
5703static void
5704create_channel(struct ssh_peer_data *peer_data, uint32_t recipient_channel, uint32_t sender_channel)
5705{
5706 if (peer_data->channel_info == NULL((void*)0)) {
5707 peer_data->channel_info = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
5708 }
5709 wmem_map_insert(peer_data->channel_info, GUINT_TO_POINTER(sender_channel)((gpointer) (gulong) (sender_channel)), GUINT_TO_POINTER(recipient_channel)((gpointer) (gulong) (recipient_channel)));
5710
5711 if (peer_data->channel_handles == NULL((void*)0)) {
5712 peer_data->channel_handles = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
5713 }
5714
5715 ssh_channel_info_t *new_channel = wmem_new0(wmem_file_scope(), ssh_channel_info_t)((ssh_channel_info_t*)wmem_alloc0((wmem_file_scope()), sizeof
(ssh_channel_info_t)))
;
5716 new_channel->multisegment_pdus = wmem_tree_new(wmem_file_scope());
5717 wmem_map_insert(peer_data->channel_handles, GUINT_TO_POINTER(recipient_channel)((gpointer) (gulong) (recipient_channel)), new_channel);
5718
5719 /* If the recipient channel is already configured in the other direction,
5720 * set the handle. We need this if we eventually handle port forwarding,
5721 * where all the information to handle the traffic is sent in the
5722 * SSH_MSG_CHANNEL_OPEN message before the CONFIRMATION. It might also
5723 * help if the packets are out of order (i.e. we get the client
5724 * CHANNEL_REQUEST before the CHANNEL_OPEN_CONFIRMATION.)
5725 */
5726 struct ssh_peer_data *other_peer_data = get_other_peer_data(peer_data);
5727 if (other_peer_data->channel_handles) {
5728 ssh_channel_info_t *peer_channel = wmem_map_lookup(other_peer_data->channel_handles, GUINT_TO_POINTER(sender_channel)((gpointer) (gulong) (sender_channel)));
5729 if (peer_channel) {
5730 new_channel->handle = peer_channel->handle;
5731 }
5732 }
5733}
5734
5735static ssh_channel_info_t*
5736get_channel_info_for_channel(struct ssh_peer_data *peer_data, uint32_t recipient_channel)
5737{
5738 if (peer_data->channel_handles == NULL((void*)0)) {
5739 return NULL((void*)0);
5740 }
5741 ssh_channel_info_t *channel = wmem_map_lookup(peer_data->channel_handles, GUINT_TO_POINTER(recipient_channel)((gpointer) (gulong) (recipient_channel)));
5742
5743 return channel;
5744}
5745
5746static void
5747set_subdissector_for_channel(struct ssh_peer_data *peer_data, uint32_t recipient_channel, const char* subsystem_name)
5748{
5749 dissector_handle_t handle = NULL((void*)0);
5750 if (0 == strcmp(subsystem_name, "sftp")) {
5751 handle = sftp_handle;
5752 } else if (0 == strcmp(subsystem_name, "shell") ||
5753 0 == strcmp(subsystem_name, "exec")) {
5754 handle = data_text_lines_handle;
5755 }
5756
5757 if (handle) {
5758 /* Map this handle to the recipient channel */
5759 ssh_channel_info_t *channel = NULL((void*)0);
5760 if (peer_data->channel_handles == NULL((void*)0)) {
5761 peer_data->channel_handles = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
5762 } else {
5763 channel = wmem_map_lookup(peer_data->channel_handles, GUINT_TO_POINTER(recipient_channel)((gpointer) (gulong) (recipient_channel)));
5764 }
5765 if (channel == NULL((void*)0)) {
5766 channel = wmem_new0(wmem_file_scope(), ssh_channel_info_t)((ssh_channel_info_t*)wmem_alloc0((wmem_file_scope()), sizeof
(ssh_channel_info_t)))
;
5767 channel->multisegment_pdus = wmem_tree_new(wmem_file_scope());
5768 wmem_map_insert(peer_data->channel_handles, GUINT_TO_POINTER(recipient_channel)((gpointer) (gulong) (recipient_channel)), channel);
5769 }
5770 channel->handle = handle;
5771
5772 /* This recipient channel is the sender channel for the other side.
5773 * Do we know what the recipient channel on the other side is? */
5774 struct ssh_peer_data *other_peer_data = get_other_peer_data(peer_data);
5775
5776 wmem_map_t *channel_info = other_peer_data->channel_info;
5777 if (channel_info) {
5778 void *sender_channel_p;
5779 if (wmem_map_lookup_extended(channel_info, GUINT_TO_POINTER(recipient_channel)((gpointer) (gulong) (recipient_channel)), NULL((void*)0), &sender_channel_p)) {
5780 uint32_t sender_channel = GPOINTER_TO_UINT(sender_channel_p)((guint) (gulong) (sender_channel_p));
5781 /* Yes. See the handle for the other side too. */
5782 if (other_peer_data->channel_handles == NULL((void*)0)) {
5783 other_peer_data->channel_handles = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
5784 channel = NULL((void*)0);
5785 } else {
5786 channel = wmem_map_lookup(other_peer_data->channel_handles, GUINT_TO_POINTER(sender_channel)((gpointer) (gulong) (sender_channel)));
5787 }
5788 if (channel == NULL((void*)0)) {
5789 channel = wmem_new0(wmem_file_scope(), ssh_channel_info_t)((ssh_channel_info_t*)wmem_alloc0((wmem_file_scope()), sizeof
(ssh_channel_info_t)))
;
5790 channel->multisegment_pdus = wmem_tree_new(wmem_file_scope());
5791 wmem_map_insert(other_peer_data->channel_handles, GUINT_TO_POINTER(sender_channel)((gpointer) (gulong) (sender_channel)), channel);
5792 }
5793 channel->handle = handle;
5794 }
5795 }
5796 }
5797}
5798
5799/* Channel mapping. }}} */
5800
5801static int
5802ssh_dissect_connection_generic(tvbuff_t *packet_tvb, packet_info *pinfo,
5803 int offset, proto_item *msg_type_tree, unsigned msg_code)
5804{
5805 (void)pinfo;
5806 if(msg_code==SSH_MSG_GLOBAL_REQUEST80){
5807 const char* request_name;
5808 unsigned slen;
5809 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_global_request_name_len, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5810 offset += 4;
5811 request_name = (char*)tvb_get_string_enc(pinfo->pool, packet_tvb, offset, slen, ENC_ASCII0x00000000|ENC_NA0x00000000);
5812 proto_tree_add_item(msg_type_tree, hf_ssh_global_request_name, packet_tvb, offset, slen, ENC_ASCII0x00000000);
5813 offset += slen;
5814 proto_tree_add_item(msg_type_tree, hf_ssh_global_request_want_reply, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
5815 offset += 1;
5816 if (0 == strcmp(request_name, "[email protected]") ||
5817 0 == strcmp(request_name, "[email protected]")) {
5818 while (tvb_reported_length_remaining(packet_tvb, offset)) {
5819 offset += ssh_tree_add_hostkey(packet_tvb, pinfo, offset, msg_type_tree,
5820 "Server host key", ett_key_exchange_host_key, NULL((void*)0));
5821 }
5822 }
5823 }
5824 return offset;
5825}
5826
5827static int
5828ssh_dissect_local_extension(tvbuff_t *packet_tvb, packet_info *pinfo,
5829 int offset, struct ssh_peer_data *peer_data, proto_item *msg_type_tree, unsigned msg_code) {
5830 unsigned slen;
5831 if (peer_data->global_data->ext_ping_openssh_offered && msg_code >= SSH_MSG_PING192 && msg_code <= SSH_MSG_PONG193) {
5832 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0), val_to_str(pinfo->pool, msg_code, ssh2_ext_ping_msg_vals, "Unknown (%u)"));
5833 proto_tree_add_item(msg_type_tree, hf_ssh2_ext_ping_msg_code, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
5834 offset += 1;
5835 if (msg_code == SSH_MSG_PING192) {
5836 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_ping_data_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5837 offset += 4;
5838 proto_tree_add_item(msg_type_tree, hf_ssh_ping_data, packet_tvb, offset, slen, ENC_NA0x00000000);
5839 offset += slen;
5840 } else if (msg_code == SSH_MSG_PONG193) {
5841 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_pong_data_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5842 offset += 4;
5843 proto_tree_add_item(msg_type_tree, hf_ssh_pong_data, packet_tvb, offset, slen, ENC_NA0x00000000);
5844 offset += slen;
5845 }
5846 } else {
5847 col_append_sep_str(pinfo->cinfo, COL_INFO, NULL((void*)0), val_to_str(pinfo->pool, msg_code, ssh2_msg_vals, "Unknown (%u)"));
5848 proto_tree_add_item(msg_type_tree, hf_ssh2_msg_code, packet_tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
5849 offset += 1;
5850 }
5851 return offset;
5852}
5853
5854static int
5855ssh_dissect_public_key_blob(tvbuff_t *tvb, packet_info *pinfo, proto_item *tree)
5856{
5857 uint32_t slen;
5858 const char* key_type;
5859
5860 unsigned offset = 0;
5861 proto_tree *blob_tree = NULL((void*)0);
5862 proto_item *blob_item = NULL((void*)0);
5863
5864 blob_item = proto_tree_add_item(tree, hf_ssh_blob, tvb, offset, tvb_reported_length(tvb), ENC_NA0x00000000);
5865 blob_tree = proto_item_add_subtree(blob_item, ett_userauth_pk_blob);
5866 proto_tree_add_item_ret_uint(blob_tree, hf_ssh_pk_blob_name_length, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5867 offset += 4;
5868 proto_tree_add_item_ret_string(blob_tree, hf_ssh_pk_blob_name, tvb, offset, slen, ENC_ASCII0x00000000, pinfo->pool, (const uint8_t**)&key_type);
5869 proto_item_append_text(blob_item, " (type: %s)", key_type);
5870 offset += slen;
5871
5872 if (0 == strcmp(key_type, "ssh-rsa")) {
5873 offset += ssh_tree_add_mpint(tvb, offset, blob_tree, hf_ssh_blob_e);
5874 offset += ssh_tree_add_mpint(tvb, offset, blob_tree, hf_ssh_blob_n);
5875 } else if (0 == strcmp(key_type, "ssh-dss")) {
5876 offset += ssh_tree_add_mpint(tvb, offset, blob_tree, hf_ssh_blob_dsa_p);
5877 offset += ssh_tree_add_mpint(tvb, offset, blob_tree, hf_ssh_blob_dsa_q);
5878 offset += ssh_tree_add_mpint(tvb, offset, blob_tree, hf_ssh_blob_dsa_g);
5879 offset += ssh_tree_add_mpint(tvb, offset, blob_tree, hf_ssh_blob_dsa_y);
5880 } else if (g_str_has_prefix(key_type, "ecdsa-sha2-")(__builtin_constant_p ("ecdsa-sha2-")? __extension__ ({ const
char * const __str = (key_type); const char * const __prefix
= ("ecdsa-sha2-"); gboolean __result = (0); if (__str == ((void
*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix)
(__str, __prefix); else { const size_t __str_len = strlen ((
(__str) + !(__str))); const size_t __prefix_len = strlen (((__prefix
) + !(__prefix))); if (__str_len >= __prefix_len) __result
= memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len
) == 0; } __result; }) : (g_str_has_prefix) (key_type, "ecdsa-sha2-"
) )
) {
5881 offset += ssh_tree_add_string(tvb, offset, blob_tree,
5882 hf_ssh_blob_ecdsa_curve_id, hf_ssh_blob_ecdsa_curve_id_length);
5883 offset += ssh_tree_add_string(tvb, offset, blob_tree,
5884 hf_ssh_blob_ecdsa_q, hf_ssh_blob_ecdsa_q_length);
5885 } else if (g_str_has_prefix(key_type, "ssh-ed")(__builtin_constant_p ("ssh-ed")? __extension__ ({ const char
* const __str = (key_type); const char * const __prefix = ("ssh-ed"
); gboolean __result = (0); if (__str == ((void*)0) || __prefix
== ((void*)0)) __result = (g_str_has_prefix) (__str, __prefix
); else { const size_t __str_len = strlen (((__str) + !(__str
))); const size_t __prefix_len = strlen (((__prefix) + !(__prefix
))); if (__str_len >= __prefix_len) __result = memcmp (((__str
) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len) == 0
; } __result; }) : (g_str_has_prefix) (key_type, "ssh-ed") )
) {
5886 offset += ssh_tree_add_string(tvb, offset, blob_tree,
5887 hf_ssh_blob_eddsa_key, hf_ssh_blob_eddsa_key_length);
5888 } else {
5889 proto_tree_add_item(blob_tree, hf_ssh_blob_data, tvb, offset, tvb_reported_length_remaining(tvb, offset), ENC_NA0x00000000);
5890 offset += tvb_reported_length_remaining(tvb, offset);
5891 }
5892
5893 return offset;
5894}
5895
5896static int
5897ssh_dissect_public_key_signature(tvbuff_t *packet_tvb, packet_info *pinfo,
5898 int offset, proto_item *msg_type_tree)
5899{
5900 (void)pinfo;
5901 unsigned slen;
5902 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_pk_sig_blob_name_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5903 offset += 4;
5904 proto_tree_add_item(msg_type_tree, hf_ssh_pk_sig_blob_name, packet_tvb, offset, slen, ENC_ASCII0x00000000);
5905 offset += slen;
5906 proto_tree_add_item_ret_uint(msg_type_tree, hf_ssh_pk_sig_s_length, packet_tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &slen);
5907 offset += 4;
5908 proto_tree_add_item(msg_type_tree, hf_ssh_pk_sig_s, packet_tvb, offset, slen, ENC_NA0x00000000);
5909 offset += slen;
5910 return offset;
5911}
5912
5913#ifdef SSH_DECRYPT_DEBUG /* {{{ */
5914
5915static FILE* ssh_debug_file;
5916
5917static void
5918ssh_prefs_apply_cb(void)
5919{
5920 ssh_set_debug(ssh_debug_file_name);
5921}
5922
5923static void
5924ssh_set_debug(const char* name)
5925{
5926 static int debug_file_must_be_closed;
5927 int use_stderr;
5928
5929 use_stderr = name?(strcmp(name, SSH_DEBUG_USE_STDERR"-") == 0):0;
5930
5931 if (debug_file_must_be_closed)
5932 fclose(ssh_debug_file);
5933
5934 if (use_stderr)
5935 ssh_debug_file = stderrstderr;
5936 else if (!name || (strcmp(name, "") ==0))
5937 ssh_debug_file = NULL((void*)0);
5938 else
5939 ssh_debug_file = ws_fopenfopen(name, "w");
5940
5941 if (!use_stderr && ssh_debug_file)
5942 debug_file_must_be_closed = 1;
5943 else
5944 debug_file_must_be_closed = 0;
5945
5946 ssh_debug_printf("Wireshark SSH debug log \n\n");
5947#ifdef HAVE_LIBGNUTLS1
5948 ssh_debug_printf("GnuTLS version: %s\n", gnutls_check_version(NULL((void*)0)));
5949#endif
5950 ssh_debug_printf("Libgcrypt version: %s\n", gcry_check_version(NULL((void*)0)));
5951 ssh_debug_printf("\n");
5952}
5953
5954static void
5955ssh_debug_flush(void)
5956{
5957 if (ssh_debug_file)
5958 fflush(ssh_debug_file);
5959}
5960
5961static void
5962ssh_debug_printf(const char* fmt, ...)
5963{
5964 va_list ap;
5965
5966 if (!ssh_debug_file)
5967 return;
5968
5969 va_start(ap, fmt)__builtin_va_start(ap, fmt);
5970 vfprintf(ssh_debug_file, fmt, ap);
5971 va_end(ap)__builtin_va_end(ap);
5972}
5973
5974static void
5975ssh_print_data(const char* name, const unsigned char* data, size_t len)
5976{
5977 size_t i, j, k;
5978 if (!ssh_debug_file)
5979 return;
5980#ifdef OPENSSH_STYLE
5981 fprintf(ssh_debug_file,"%s[%d]\n",name, (int) len);
5982#else
5983 fprintf(ssh_debug_file,"%s[%d]:\n",name, (int) len);
5984#endif
5985 for (i=0; i<len; i+=16) {
5986#ifdef OPENSSH_STYLE
5987 fprintf(ssh_debug_file,"%04u: ", (unsigned int)i);
5988#else
5989 fprintf(ssh_debug_file,"| ");
5990#endif
5991 for (j=i, k=0; k<16 && j<len; ++j, ++k)
5992 fprintf(ssh_debug_file,"%.2x ",data[j]);
5993 for (; k<16; ++k)
5994 fprintf(ssh_debug_file," ");
5995#ifdef OPENSSH_STYLE
5996 fputc(' ', ssh_debug_file);
5997#else
5998 fputc('|', ssh_debug_file);
5999#endif
6000 for (j=i, k=0; k<16 && j<len; ++j, ++k) {
6001 unsigned char c = data[j];
6002 if (!g_ascii_isprint(c)((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0) || (c=='\t')) c = '.';
6003 fputc(c, ssh_debug_file);
6004 }
6005#ifdef OPENSSH_STYLE
6006 fprintf(ssh_debug_file,"\n");
6007#else
6008 for (; k<16; ++k)
6009 fputc(' ', ssh_debug_file);
6010 fprintf(ssh_debug_file,"|\n");
6011#endif
6012 }
6013}
6014
6015#endif /* SSH_DECRYPT_DEBUG }}} */
6016
6017static void
6018ssh_secrets_block_callback(const void *secrets, unsigned size)
6019{
6020 ssh_keylog_process_lines((const uint8_t *)secrets, size);
6021}
6022
6023/* Functions for SSH random hashtables. {{{ */
6024static int
6025ssh_equal (const void *v, const void *v2)
6026{
6027 if (v == NULL((void*)0) || v2 == NULL((void*)0)) {
6028 return 0;
6029 }
6030
6031 const ssh_bignum *val1;
6032 const ssh_bignum *val2;
6033 val1 = (const ssh_bignum *)v;
6034 val2 = (const ssh_bignum *)v2;
6035
6036 if (val1->length == val2->length &&
6037 !memcmp(val1->data, val2->data, val2->length)) {
6038 return 1;
6039 }
6040 return 0;
6041}
6042
6043static unsigned
6044ssh_hash (const void *v)
6045{
6046 unsigned l,hash;
6047 const ssh_bignum* id;
6048 const unsigned* cur;
6049
6050 if (v == NULL((void*)0)) {
6051 return 0;
6052 }
6053
6054 hash = 0;
6055 id = (const ssh_bignum*) v;
6056
6057 /* id and id->data are mallocated in ssh_save_master_key(). As such 'data'
6058 * should be aligned for any kind of access (for example as a unsigned as
6059 * is done below). The intermediate void* cast is to prevent "cast
6060 * increases required alignment of target type" warnings on CPUs (such
6061 * as SPARCs) that do not allow misaligned memory accesses.
6062 */
6063 cur = (const unsigned*)(void*) id->data;
6064
6065 for (l=4; (l < id->length); l+=4, cur++)
6066 hash = hash ^ (*cur);
6067
6068 return hash;
6069}
6070
6071static void
6072ssh_free_glib_allocated_bignum(void *data)
6073{
6074 ssh_bignum * bignum;
6075 if (data == NULL((void*)0)) {
6076 return;
6077 }
6078
6079 bignum = (ssh_bignum *) data;
6080 g_free(bignum->data)(__builtin_object_size ((bignum->data), 0) != ((size_t) - 1
)) ? g_free_sized (bignum->data, __builtin_object_size ((bignum
->data), 0)) : (g_free) (bignum->data)
;
6081 g_free(bignum)(__builtin_object_size ((bignum), 0) != ((size_t) - 1)) ? g_free_sized
(bignum, __builtin_object_size ((bignum), 0)) : (g_free) (bignum
)
;
6082}
6083
6084static void
6085ssh_free_glib_allocated_entry(void *data)
6086{
6087 ssh_key_map_entry_t * entry;
6088 if (data == NULL((void*)0)) {
6089 return;
6090 }
6091
6092 entry = (ssh_key_map_entry_t *) data;
6093 g_free(entry->type)(__builtin_object_size ((entry->type), 0) != ((size_t) - 1
)) ? g_free_sized (entry->type, __builtin_object_size ((entry
->type), 0)) : (g_free) (entry->type)
;
6094 ssh_free_glib_allocated_bignum(entry->key_material);
6095 g_free(entry)(__builtin_object_size ((entry), 0) != ((size_t) - 1)) ? g_free_sized
(entry, __builtin_object_size ((entry), 0)) : (g_free) (entry
)
;
6096}
6097/* Functions for SSH random hashtables. }}} */
6098
6099static void
6100ssh_shutdown(void) {
6101 g_hash_table_destroy(ssh_master_key_map);
6102}
6103
6104void
6105proto_register_ssh(void)
6106{
6107 static hf_register_info hf[] = {
6108 { &hf_ssh_protocol,
6109 { "Protocol", "ssh.protocol",
6110 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6111 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6112
6113 { &hf_ssh_packet_length,
6114 { "Packet Length", "ssh.packet_length",
6115 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6116 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6117
6118 { &hf_ssh_packet_length_encrypted,
6119 { "Packet Length (encrypted)", "ssh.packet_length_encrypted",
6120 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6121 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6122
6123 { &hf_ssh_padding_length,
6124 { "Padding Length", "ssh.padding_length",
6125 FT_UINT8, BASE_DEC, NULL((void*)0), 0x0,
6126 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6127
6128 { &hf_ssh_payload,
6129 { "Payload", "ssh.payload",
6130 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6131 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6132
6133 { &hf_ssh_encrypted_packet,
6134 { "Encrypted Packet", "ssh.encrypted_packet",
6135 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6136 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6137
6138 { &hf_ssh_padding_string,
6139 { "Padding String", "ssh.padding_string",
6140 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6141 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6142
6143 { &hf_ssh_seq_num,
6144 { "Sequence number", "ssh.seq_num",
6145 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6146 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6147
6148 { &hf_ssh_mac_string,
6149 { "MAC", "ssh.mac",
6150 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6151 "Message authentication code", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6152
6153 { &hf_ssh_mac_status,
6154 { "MAC Status", "ssh.mac.status", FT_UINT8, BASE_NONE, VALS(proto_checksum_vals)((0 ? (const struct _value_string*)0 : ((proto_checksum_vals)
)))
, 0x0,
6155 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6156
6157 { &hf_ssh_direction,
6158 { "Direction", "ssh.direction",
6159 FT_BOOLEAN, BASE_NONE, TFS(&tfs_s2c_c2s)((0 ? (const struct true_false_string*)0 : ((&tfs_s2c_c2s
))))
, 0x0,
6160 "Message direction", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6161
6162 { &hf_ssh_msg_code,
6163 { "Message Code", "ssh.message_code",
6164 FT_UINT8, BASE_DEC, VALS(ssh1_msg_vals)((0 ? (const struct _value_string*)0 : ((ssh1_msg_vals)))), 0x0,
6165 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6166
6167 { &hf_ssh2_msg_code,
6168 { "Message Code", "ssh.message_code",
6169 FT_UINT8, BASE_DEC, VALS(ssh2_msg_vals)((0 ? (const struct _value_string*)0 : ((ssh2_msg_vals)))), 0x0,
6170 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6171
6172 { &hf_ssh2_kex_dh_msg_code,
6173 { "Message Code", "ssh.message_code",
6174 FT_UINT8, BASE_DEC, VALS(ssh2_kex_dh_msg_vals)((0 ? (const struct _value_string*)0 : ((ssh2_kex_dh_msg_vals
))))
, 0x0,
6175 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6176
6177 { &hf_ssh2_kex_dh_gex_msg_code,
6178 { "Message Code", "ssh.message_code",
6179 FT_UINT8, BASE_DEC, VALS(ssh2_kex_dh_gex_msg_vals)((0 ? (const struct _value_string*)0 : ((ssh2_kex_dh_gex_msg_vals
))))
, 0x0,
6180 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6181
6182 { &hf_ssh2_kex_ecdh_msg_code,
6183 { "Message Code", "ssh.message_code",
6184 FT_UINT8, BASE_DEC, VALS(ssh2_kex_ecdh_msg_vals)((0 ? (const struct _value_string*)0 : ((ssh2_kex_ecdh_msg_vals
))))
, 0x0,
6185 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6186
6187 { &hf_ssh2_kex_hybrid_msg_code,
6188 { "Message Code", "ssh.message_code",
6189 FT_UINT8, BASE_DEC, VALS(ssh2_kex_hybrid_msg_vals)((0 ? (const struct _value_string*)0 : ((ssh2_kex_hybrid_msg_vals
))))
, 0x0,
6190 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6191
6192 { &hf_ssh2_ext_ping_msg_code,
6193 { "Message Code", "ssh.message_code",
6194 FT_UINT8, BASE_DEC, VALS(ssh2_ext_ping_msg_vals)((0 ? (const struct _value_string*)0 : ((ssh2_ext_ping_msg_vals
))))
, 0x0,
6195 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6196
6197 { &hf_ssh_cookie,
6198 { "Cookie", "ssh.cookie",
6199 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6200 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6201
6202 { &hf_ssh_kex_algorithms,
6203 { "kex_algorithms string", "ssh.kex_algorithms",
6204 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6205 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6206
6207 { &hf_ssh_server_host_key_algorithms,
6208 { "server_host_key_algorithms string", "ssh.server_host_key_algorithms",
6209 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6210 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6211
6212 { &hf_ssh_encryption_algorithms_client_to_server,
6213 { "encryption_algorithms_client_to_server string", "ssh.encryption_algorithms_client_to_server",
6214 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6215 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6216
6217 { &hf_ssh_encryption_algorithms_server_to_client,
6218 { "encryption_algorithms_server_to_client string", "ssh.encryption_algorithms_server_to_client",
6219 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6220 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6221
6222 { &hf_ssh_mac_algorithms_client_to_server,
6223 { "mac_algorithms_client_to_server string", "ssh.mac_algorithms_client_to_server",
6224 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6225 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6226
6227 { &hf_ssh_mac_algorithms_server_to_client,
6228 { "mac_algorithms_server_to_client string", "ssh.mac_algorithms_server_to_client",
6229 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6230 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6231
6232 { &hf_ssh_compression_algorithms_client_to_server,
6233 { "compression_algorithms_client_to_server string", "ssh.compression_algorithms_client_to_server",
6234 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6235 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6236
6237 { &hf_ssh_compression_algorithms_server_to_client,
6238 { "compression_algorithms_server_to_client string", "ssh.compression_algorithms_server_to_client",
6239 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6240 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6241
6242 { &hf_ssh_languages_client_to_server,
6243 { "languages_client_to_server string", "ssh.languages_client_to_server",
6244 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6245 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6246
6247 { &hf_ssh_languages_server_to_client,
6248 { "languages_server_to_client string", "ssh.languages_server_to_client",
6249 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6250 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6251
6252 { &hf_ssh_kex_algorithms_length,
6253 { "kex_algorithms length", "ssh.kex_algorithms_length",
6254 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6255 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6256
6257 { &hf_ssh_server_host_key_algorithms_length,
6258 { "server_host_key_algorithms length", "ssh.server_host_key_algorithms_length",
6259 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6260 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6261
6262 { &hf_ssh_encryption_algorithms_client_to_server_length,
6263 { "encryption_algorithms_client_to_server length", "ssh.encryption_algorithms_client_to_server_length",
6264 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6265 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6266
6267 { &hf_ssh_encryption_algorithms_server_to_client_length,
6268 { "encryption_algorithms_server_to_client length", "ssh.encryption_algorithms_server_to_client_length",
6269 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6270 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6271
6272 { &hf_ssh_mac_algorithms_client_to_server_length,
6273 { "mac_algorithms_client_to_server length", "ssh.mac_algorithms_client_to_server_length",
6274 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6275 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6276
6277 { &hf_ssh_mac_algorithms_server_to_client_length,
6278 { "mac_algorithms_server_to_client length", "ssh.mac_algorithms_server_to_client_length",
6279 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6280 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6281
6282 { &hf_ssh_compression_algorithms_client_to_server_length,
6283 { "compression_algorithms_client_to_server length", "ssh.compression_algorithms_client_to_server_length",
6284 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6285 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6286
6287 { &hf_ssh_compression_algorithms_server_to_client_length,
6288 { "compression_algorithms_server_to_client length", "ssh.compression_algorithms_server_to_client_length",
6289 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6290 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6291
6292 { &hf_ssh_languages_client_to_server_length,
6293 { "languages_client_to_server length", "ssh.languages_client_to_server_length",
6294 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6295 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6296
6297 { &hf_ssh_languages_server_to_client_length,
6298 { "languages_server_to_client length", "ssh.languages_server_to_client_length",
6299 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6300 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6301
6302 { &hf_ssh_first_kex_packet_follows,
6303 { "First KEX Packet Follows", "ssh.first_kex_packet_follows",
6304 FT_UINT8, BASE_DEC, NULL((void*)0), 0x0,
6305 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6306
6307 { &hf_ssh_kex_reserved,
6308 { "Reserved", "ssh.kex.reserved",
6309 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6310 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6311
6312 { &hf_ssh_kex_hassh_algo,
6313 { "hasshAlgorithms", "ssh.kex.hassh_algorithms",
6314 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6315 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6316
6317 { &hf_ssh_kex_hassh,
6318 { "hassh", "ssh.kex.hassh",
6319 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6320 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6321
6322 { &hf_ssh_kex_hasshserver_algo,
6323 { "hasshServerAlgorithms", "ssh.kex.hasshserver_algorithms",
6324 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6325 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6326
6327 { &hf_ssh_kex_hasshserver,
6328 { "hasshServer", "ssh.kex.hasshserver",
6329 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6330 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6331
6332 { &hf_ssh_hostkey_length,
6333 { "Host key length", "ssh.host_key.length",
6334 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6335 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6336
6337 { &hf_ssh_hostkey_type_length,
6338 { "Host key type length", "ssh.host_key.type_length",
6339 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6340 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6341
6342 { &hf_ssh_hostkey_type,
6343 { "Host key type", "ssh.host_key.type",
6344 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6345 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6346
6347 { &hf_ssh_hostkey_data,
6348 { "Host key data", "ssh.host_key.data",
6349 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6350 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6351
6352 { &hf_ssh_hostkey_rsa_n,
6353 { "RSA modulus (N)", "ssh.host_key.rsa.n",
6354 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6355 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6356
6357 { &hf_ssh_hostkey_rsa_e,
6358 { "RSA public exponent (e)", "ssh.host_key.rsa.e",
6359 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6360 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6361
6362 { &hf_ssh_hostkey_dsa_p,
6363 { "DSA prime modulus (p)", "ssh.host_key.dsa.p",
6364 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6365 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6366
6367 { &hf_ssh_hostkey_dsa_q,
6368 { "DSA prime divisor (q)", "ssh.host_key.dsa.q",
6369 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6370 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6371
6372 { &hf_ssh_hostkey_dsa_g,
6373 { "DSA subgroup generator (g)", "ssh.host_key.dsa.g",
6374 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6375 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6376
6377 { &hf_ssh_hostkey_dsa_y,
6378 { "DSA public key (y)", "ssh.host_key.dsa.y",
6379 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6380 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6381
6382 { &hf_ssh_hostkey_ecdsa_curve_id,
6383 { "ECDSA elliptic curve identifier", "ssh.host_key.ecdsa.id",
6384 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6385 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6386
6387 { &hf_ssh_hostkey_ecdsa_curve_id_length,
6388 { "ECDSA elliptic curve identifier length", "ssh.host_key.ecdsa.id_length",
6389 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6390 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6391
6392 { &hf_ssh_hostkey_ecdsa_q,
6393 { "ECDSA public key (Q)", "ssh.host_key.ecdsa.q",
6394 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6395 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6396
6397 { &hf_ssh_hostkey_ecdsa_q_length,
6398 { "ECDSA public key length", "ssh.host_key.ecdsa.q_length",
6399 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6400 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6401
6402 { &hf_ssh_hostkey_eddsa_key,
6403 { "EdDSA public key", "ssh.host_key.eddsa.key",
6404 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6405 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6406
6407 { &hf_ssh_hostkey_eddsa_key_length,
6408 { "EdDSA public key length", "ssh.host_key.eddsa.key_length",
6409 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6410 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6411
6412 { &hf_ssh_hostsig_length,
6413 { "Host signature length", "ssh.host_sig.length",
6414 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6415 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6416
6417 { &hf_ssh_hostsig_type_length,
6418 { "Host signature type length", "ssh.host_sig.type_length",
6419 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6420 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6421
6422 { &hf_ssh_hostsig_type,
6423 { "Host signature type", "ssh.host_sig.type",
6424 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6425 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6426
6427 { &hf_ssh_hostsig_data_length,
6428 { "Host signature data length", "ssh.host_sig.data_length",
6429 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6430 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6431
6432 { &hf_ssh_hostsig_data,
6433 { "Host signature data", "ssh.host_sig.data",
6434 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6435 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6436
6437 { &hf_ssh_hostsig_rsa,
6438 { "RSA signature", "ssh.host_sig.rsa",
6439 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6440 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6441
6442 { &hf_ssh_hostsig_dsa,
6443 { "DSA signature", "ssh.host_sig.dsa",
6444 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6445 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6446
6447 { &hf_ssh_dh_e,
6448 { "DH client e", "ssh.dh.e",
6449 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6450 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6451
6452 { &hf_ssh_dh_f,
6453 { "DH server f", "ssh.dh.f",
6454 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6455 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6456
6457 { &hf_ssh_dh_gex_min,
6458 { "DH GEX Min", "ssh.dh_gex.min",
6459 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6460 "Minimal acceptable group size", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6461
6462 { &hf_ssh_dh_gex_nbits,
6463 { "DH GEX Number of Bits", "ssh.dh_gex.nbits",
6464 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6465 "Preferred group size", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6466
6467 { &hf_ssh_dh_gex_max,
6468 { "DH GEX Max", "ssh.dh_gex.max",
6469 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6470 "Maximal acceptable group size", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6471
6472 { &hf_ssh_dh_gex_p,
6473 { "DH GEX modulus (P)", "ssh.dh_gex.p",
6474 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6475 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6476
6477 { &hf_ssh_dh_gex_g,
6478 { "DH GEX base (G)", "ssh.dh_gex.g",
6479 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6480 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6481
6482 { &hf_ssh_ecdh_q_c,
6483 { "ECDH client's ephemeral public key (Q_C)", "ssh.ecdh.q_c",
6484 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6485 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6486
6487 { &hf_ssh_ecdh_q_c_length,
6488 { "ECDH client's ephemeral public key length", "ssh.ecdh.q_c_length",
6489 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6490 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6491
6492 { &hf_ssh_ecdh_q_s,
6493 { "ECDH server's ephemeral public key (Q_S)", "ssh.ecdh.q_s",
6494 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6495 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6496
6497 { &hf_ssh_ecdh_q_s_length,
6498 { "ECDH server's ephemeral public key length", "ssh.ecdh.q_s_length",
6499 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6500 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6501
6502 { &hf_ssh_mpint_length,
6503 { "Multi Precision Integer Length", "ssh.mpint_length",
6504 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6505 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6506
6507 { &hf_ssh_ignore_data_length,
6508 { "Debug message length", "ssh.ignore_data_length",
6509 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6510 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6511
6512 { &hf_ssh_ignore_data,
6513 { "Ignore data", "ssh.ignore_data",
6514 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6515 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6516
6517 { &hf_ssh_debug_always_display,
6518 { "Always Display", "ssh.debug_always_display",
6519 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
6520 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6521
6522 { &hf_ssh_debug_message_length,
6523 { "Debug message length", "ssh.debug_name_length",
6524 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6525 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6526
6527 { &hf_ssh_debug_message,
6528 { "Debug message", "ssh.debug_name",
6529 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6530 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6531
6532 { &hf_ssh_service_name_length,
6533 { "Service Name length", "ssh.service_name_length",
6534 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6535 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6536
6537 { &hf_ssh_service_name,
6538 { "Service Name", "ssh.service_name",
6539 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6540 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6541
6542 { &hf_ssh_disconnect_reason,
6543 { "Disconnect reason", "ssh.disconnect_reason",
6544 FT_UINT32, BASE_HEX, NULL((void*)0), 0x0,
6545 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6546
6547 { &hf_ssh_disconnect_description_length,
6548 { "Disconnect description length", "ssh.disconnect_description_length",
6549 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6550 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6551
6552 { &hf_ssh_disconnect_description,
6553 { "Disconnect description", "ssh.disconnect_description",
6554 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6555 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6556
6557 { &hf_ssh_ext_count,
6558 { "Extension count", "ssh.extension.count",
6559 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6560 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6561
6562 { &hf_ssh_ext_name_length,
6563 { "Extension name length", "ssh.extension.name_length",
6564 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6565 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6566
6567 { &hf_ssh_ext_name,
6568 { "Extension name", "ssh.extension.name",
6569 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6570 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6571
6572 { &hf_ssh_ext_value_length,
6573 { "Extension value length", "ssh.extension.value_length",
6574 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6575 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6576
6577 { &hf_ssh_ext_value,
6578 { "Extension value", "ssh.extension.value",
6579 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6580 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6581
6582 { &hf_ssh_ext_server_sig_algs_algorithms,
6583 { "Accepted signature algorithms", "ssh.extension.server_sig_algs.algorithms",
6584 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6585 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6586
6587 { &hf_ssh_ext_delay_compression_algorithms_client_to_server_length,
6588 { "Compression algorithms (client to server) length", "ssh.extension.delay_compression.compression_algorithms_client_to_server_length",
6589 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6590 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6591
6592 { &hf_ssh_ext_delay_compression_algorithms_client_to_server,
6593 { "Compression algorithms (client to server)", "ssh.extension.delay_compression.compression_algorithms_client_to_server",
6594 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6595 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6596
6597 { &hf_ssh_ext_delay_compression_algorithms_server_to_client_length,
6598 { "Compression algorithms (server to client) length", "ssh.extension.delay_compression.compression_algorithms_server_to_client_length",
6599 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6600 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6601
6602 { &hf_ssh_ext_delay_compression_algorithms_server_to_client,
6603 { "Compression algorithms (server to client)", "ssh.extension.delay_compression.compression_algorithms_server_to_client",
6604 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6605 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6606
6607 { &hf_ssh_ext_no_flow_control_value,
6608 { "No flow control flag", "ssh.extension.no_flow_control.value",
6609 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6610 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6611
6612 { &hf_ssh_ext_elevation_value,
6613 { "Elevation flag", "ssh.extension.elevation.value",
6614 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6615 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6616
6617 { &hf_ssh_ext_prop_publickey_algorithms_algorithms,
6618 { "Public key algorithms", "ssh.extension.prop_publickey_algorithms.algorithms",
6619 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6620 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6621
6622 { &hf_ssh_lang_tag_length,
6623 { "Language tag length", "ssh.lang_tag_length",
6624 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6625 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6626
6627 { &hf_ssh_lang_tag,
6628 { "Language tag", "ssh.lang_tag",
6629 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6630 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6631
6632 { &hf_ssh_ping_data_length,
6633 { "Data length", "ssh.ping_data_length",
6634 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6635 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6636
6637 { &hf_ssh_ping_data,
6638 { "Data", "ssh.ping_data",
6639 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6640 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6641
6642 { &hf_ssh_pong_data_length,
6643 { "Data length", "ssh.pong_data_length",
6644 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6645 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6646
6647 { &hf_ssh_pong_data,
6648 { "Data", "ssh.pong_data",
6649 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6650 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6651
6652
6653 { &hf_ssh_userauth_user_name_length,
6654 { "User Name length", "ssh.userauth_user_name_length",
6655 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6656 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6657
6658 { &hf_ssh_userauth_user_name,
6659 { "User Name", "ssh.userauth_user_name",
6660 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6661 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6662
6663 { &hf_ssh_userauth_change_password,
6664 { "Change password", "ssh.userauth.change_password",
6665 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
6666 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6667
6668 { &hf_ssh_userauth_service_name_length,
6669 { "Service Name length", "ssh.userauth_service_name_length",
6670 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6671 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6672
6673 { &hf_ssh_userauth_service_name,
6674 { "Service Name", "ssh.userauth_service_name",
6675 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6676 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6677
6678 { &hf_ssh_userauth_method_name_length,
6679 { "Method Name length", "ssh.userauth_method_name_length",
6680 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6681 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6682
6683 { &hf_ssh_userauth_method_name,
6684 { "Method Name", "ssh.userauth_method_name",
6685 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6686 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6687
6688 { &hf_ssh_userauth_have_signature,
6689 { "Have signature", "ssh.userauth.have_signature",
6690 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
6691 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6692
6693 { &hf_ssh_userauth_password_length,
6694 { "Password length", "ssh.userauth_password_length",
6695 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6696 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6697
6698 { &hf_ssh_userauth_password,
6699 { "Password", "ssh.userauth_password",
6700 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6701 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6702
6703 { &hf_ssh_userauth_new_password_length,
6704 { "New password length", "ssh.userauth_new_password_length",
6705 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6706 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6707
6708 { &hf_ssh_userauth_new_password,
6709 { "New password", "ssh.userauth_new_password",
6710 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6711 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6712
6713 { &hf_ssh_auth_failure_list_length,
6714 { "Authentications that can continue list len", "ssh.auth_failure_cont_list_length",
6715 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6716 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6717
6718 { &hf_ssh_auth_failure_list,
6719 { "Authentications that can continue list", "ssh.auth_failure_cont_list",
6720 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6721 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6722
6723 { &hf_ssh_userauth_partial_success,
6724 { "Partial success", "ssh.userauth.partial_success",
6725 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
6726 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6727
6728 { &hf_ssh_userauth_pka_name_len,
6729 { "Public key algorithm name length", "ssh.userauth_pka_name_length",
6730 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6731 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6732
6733 { &hf_ssh_userauth_pka_name,
6734 { "Public key algorithm name", "ssh.userauth_pka_name",
6735 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6736 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6737
6738 { &hf_ssh_pk_blob_name_length,
6739 { "Public key blob algorithm name length", "ssh.pk_blob_name_length",
6740 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6741 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6742
6743 { &hf_ssh_pk_blob_name,
6744 { "Public key blob algorithm name", "ssh.pk_blob_name",
6745 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6746 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6747
6748 { &hf_ssh_blob_length,
6749 { "Public key blob length", "ssh.pk_blob_length",
6750 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6751 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6752
6753 { &hf_ssh_blob,
6754 { "Public key blob", "ssh.pk_blob",
6755 FT_NONE, BASE_NONE, NULL((void*)0), 0x0,
6756 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6757
6758 { &hf_ssh_blob_e,
6759 { "ssh-rsa public exponent (e)", "ssh.pk_blob.ssh-rsa.e",
6760 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6761 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6762
6763 { &hf_ssh_blob_n,
6764 { "ssh-rsa modulus (n)", "ssh.pk_blob.ssh-rsa.n",
6765 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6766 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6767
6768 { &hf_ssh_blob_dsa_p,
6769 { "DSA prime modulus (p)", "ssh.pk_blob.dsa.p",
6770 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6771 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6772
6773 { &hf_ssh_blob_dsa_q,
6774 { "DSA prime divisor (q)", "ssh.pk_blob.dsa.q",
6775 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6776 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6777
6778 { &hf_ssh_blob_dsa_g,
6779 { "DSA subgroup generator (g)", "ssh.pk_blob.dsa.g",
6780 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6781 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6782
6783 { &hf_ssh_blob_dsa_y,
6784 { "DSA public key (y)", "ssh.pk_blob.dsa.y",
6785 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6786 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6787
6788 { &hf_ssh_blob_ecdsa_curve_id,
6789 { "ECDSA elliptic curve identifier", "ssh.pk_blob.ecdsa.id",
6790 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6791 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6792
6793 { &hf_ssh_blob_ecdsa_curve_id_length,
6794 { "ECDSA elliptic curve identifier length", "ssh.pk_blob.ecdsa.id_length",
6795 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6796 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6797
6798 { &hf_ssh_blob_ecdsa_q,
6799 { "ECDSA public key (Q)", "ssh.pk_blob.ecdsa.q",
6800 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6801 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6802
6803 { &hf_ssh_blob_ecdsa_q_length,
6804 { "ECDSA public key length", "ssh.pk_blob.ecdsa.q_length",
6805 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6806 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6807
6808 { &hf_ssh_blob_eddsa_key,
6809 { "EdDSA public key", "ssh.pk_blob.eddsa.key",
6810 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6811 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6812
6813 { &hf_ssh_blob_eddsa_key_length,
6814 { "EdDSA public key length", "ssh.pk_blob.eddsa.key_length",
6815 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6816 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6817
6818 { &hf_ssh_blob_data,
6819 { "Public key blob data", "ssh.pk_blob.data",
6820 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6821 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6822
6823 { &hf_ssh_signature_length,
6824 { "Public key signature blob length", "ssh.pk_sig_blob_length",
6825 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6826 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6827
6828 { &hf_ssh_pk_sig_blob_name_length,
6829 { "Public key signature blob algorithm name length", "ssh.pk_sig_blob_name_length",
6830 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6831 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6832
6833 { &hf_ssh_pk_sig_blob_name,
6834 { "Public key signature blob algorithm name", "ssh.pk_sig_blob_name",
6835 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6836 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6837
6838 { &hf_ssh_pk_sig_s_length,
6839 { "ssh-rsa signature length", "ssh.sig.ssh-rsa.length",
6840 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6841 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6842
6843 { &hf_ssh_pk_sig_s,
6844 { "ssh-rsa signature (s)", "ssh.sig.ssh-rsa.s",
6845 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
6846 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6847
6848 { &hf_ssh_connection_type_name_len,
6849 { "Channel type name length", "ssh.connection_type_name_length",
6850 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6851 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6852
6853 { &hf_ssh_connection_type_name,
6854 { "Channel type name", "ssh.connection_type_name",
6855 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6856 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6857
6858 { &hf_ssh_connection_sender_channel,
6859 { "Sender channel", "ssh.connection_sender_channel",
6860 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6861 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6862
6863 { &hf_ssh_connection_recipient_channel,
6864 { "Recipient channel", "ssh.connection_recipient_channel",
6865 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6866 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6867
6868 { &hf_ssh_connection_initial_window,
6869 { "Initial window size", "ssh.connection_initial_window_size",
6870 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6871 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6872
6873 { &hf_ssh_connection_maximum_packet_size,
6874 { "Maximum packet size", "ssh.userauth_maximum_packet_size",
6875 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6876 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6877
6878 { &hf_ssh_global_request_name_len,
6879 { "Global request name length", "ssh.global_request_name_length",
6880 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6881 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6882
6883 { &hf_ssh_global_request_name,
6884 { "Global request name", "ssh.global_request_name",
6885 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6886 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6887
6888 { &hf_ssh_global_request_want_reply,
6889 { "Global request want reply", "ssh.global_request_want_reply",
6890 FT_UINT8, BASE_DEC, NULL((void*)0), 0x0,
6891 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6892
6893 { &hf_ssh_global_request_hostkeys_array_len,
6894 { "Host keys array length", "ssh.global_request_hostkeys",
6895 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6896 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6897
6898 { &hf_ssh_channel_request_name_len,
6899 { "Channel request name length", "ssh.channel_request_name_length",
6900 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6901 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6902
6903 { &hf_ssh_channel_request_name,
6904 { "Channel request name", "ssh.channel_request_name",
6905 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6906 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6907
6908 { &hf_ssh_channel_request_want_reply,
6909 { "Channel request want reply", "ssh.channel_request_want_reply",
6910 FT_UINT8, BASE_DEC, NULL((void*)0), 0x0,
6911 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6912
6913 { &hf_ssh_subsystem_name_len,
6914 { "Subsystem name length", "ssh.subsystem_name_length",
6915 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6916 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6917
6918 { &hf_ssh_subsystem_name,
6919 { "Subsystem name", "ssh.subsystem_name",
6920 FT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6921 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
6922
6923 { &hf_ssh_exec_cmd,
6924 { "Command", "ssh.exec_command",
6925 FT_UINT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6926 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6927
6928 { &hf_ssh_env_name,
6929 { "Variable name", "ssh.env_name",
6930 FT_UINT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6931 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6932
6933 { &hf_ssh_env_value,
6934 { "Variable value", "ssh.env_value",
6935 FT_UINT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6936 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6937
6938 { &hf_ssh_pty_term,
6939 { "TERM environment variable", "ssh.pty_term",
6940 FT_UINT_STRING, BASE_NONE, NULL((void*)0), 0x0,
6941 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6942
6943 { &hf_ssh_pty_term_width_char,
6944 { "Terminal width, characters", "ssh.pty_term_width_char",
6945 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6946 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6947
6948 { &hf_ssh_pty_term_height_row,
6949 { "Terminal height, rows", "ssh.pty_term_height_row",
6950 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6951 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6952
6953 { &hf_ssh_pty_term_width_pixel,
6954 { "Terminal width, pixels", "ssh.pty_term_width_pixel",
6955 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6956 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6957
6958 { &hf_ssh_pty_term_height_pixel,
6959 { "Terminal height, pixels", "ssh.pty_term_height_pixel",
6960 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6961 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6962
6963 { &hf_ssh_pty_term_modes_len,
6964 { "Encoded Terminal Modes Length", "ssh.pty_term_modes_length",
6965 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
6966 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6967
6968 { &hf_ssh_pty_term_modes,
6969 { "Encoded Terminal Modes", "ssh.pty_term_modes",
6970 FT_NONE, BASE_NONE, NULL((void*)0), 0x0,
6971 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6972
6973 { &hf_ssh_pty_term_mode,
6974 { "Mode", "ssh.pty_term_mode",
6975 FT_NONE, BASE_NONE, NULL((void*)0), 0x0,
6976 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6977
6978 { &hf_ssh_pty_term_mode_opcode,
6979 { "Opcode", "ssh.pty_term_mode.opcode",
6980 FT_UINT8, BASE_DEC, VALS(ssh_tty_op_vals)((0 ? (const struct _value_string*)0 : ((ssh_tty_op_vals)))), 0x0,
6981 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6982
6983 { &hf_ssh_pty_term_mode_vintr,
6984 { "Interrupt character", "ssh.pty_term_mode.vintr",
6985 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
6986 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
6987
6988 { &hf_ssh_pty_term_mode_vquit,
6989 { "Quit character", "ssh.pty_term_mode.vquit",
6990 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
6991 "Sends SIGQUIT on POSIX systems", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)}},
6992
6993 { &hf_ssh_pty_term_mode_verase,
6994 { "Erase the character to the left of the cursor", "ssh.pty_term_mode.verase",
6995 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
6996 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
6997
6998 { &hf_ssh_pty_term_mode_vkill,
6999 { "Kill the current input line", "ssh.pty_term_mode.vkill",
7000 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7001 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7002
7003 { &hf_ssh_pty_term_mode_veof,
7004 { "End-of-file character", "ssh.pty_term_mode.veof",
7005 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7006 "Sends EOF from the terminal", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)}},
7007
7008 { &hf_ssh_pty_term_mode_veol,
7009 { "End-of-line character", "ssh.pty_term_mode.veol",
7010 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7011 "In additional to carriage return and/or line feed", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7012
7013 { &hf_ssh_pty_term_mode_veol2,
7014 { "Additional end-of-line character", "ssh.pty_term_mode.veol2",
7015 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7016 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7017
7018 { &hf_ssh_pty_term_mode_vstart,
7019 { "Continues paused output", "ssh.pty_term_mode.vstart",
7020 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7021 "Normally Control-Q", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)}},
7022
7023 { &hf_ssh_pty_term_mode_vstop,
7024 { "Pauses output", "ssh.pty_term_mode.vstop",
7025 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7026 "Normally Control-S", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7027
7028 { &hf_ssh_pty_term_mode_vsusp,
7029 { "Suspends the current program", "ssh.pty_term_mode.vsusp",
7030 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7031 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7032
7033 { &hf_ssh_pty_term_mode_vdsusp,
7034 { "Another suspend character", "ssh.pty_term_mode.vdsusp",
7035 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7036 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7037
7038 { &hf_ssh_pty_term_mode_vreprint,
7039 { "Reprints the current input line", "ssh.pty_term_mode.vreprint",
7040 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7041 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7042
7043 { &hf_ssh_pty_term_mode_vwerase,
7044 { "Erase a word to the left of the cursor", "ssh.pty_term_mode.vwerase",
7045 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7046 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7047
7048 { &hf_ssh_pty_term_mode_vlnext,
7049 { "Enter the next character typed literally", "ssh.pty_term_mode.vlnext",
7050 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7051 "Even if a special character", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7052
7053 { &hf_ssh_pty_term_mode_vflush,
7054 { "Character to flush output", "ssh.pty_term_mode.vflush",
7055 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7056 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7057
7058 { &hf_ssh_pty_term_mode_vswtch,
7059 { "Switch to a different shell layer", "ssh.pty_term_mode.vswtch",
7060 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7061 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7062
7063 { &hf_ssh_pty_term_mode_vstatus,
7064 { "Print system status line", "ssh.pty_term_mode.vstatus",
7065 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7066 "Load, command, pid, etc.", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)}},
7067
7068 { &hf_ssh_pty_term_mode_vdiscard,
7069 { "Toggles the flushing of terminal output", "ssh.pty_term_mode.vdiscard",
7070 FT_CHAR, BASE_HEX, NULL((void*)0), 0x0,
7071 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0)} },
7072
7073 { &hf_ssh_pty_term_mode_ignpar,
7074 { "Ignore parity flag", "ssh.pty_term_mode.ignpar",
7075 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7076 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7077
7078 { &hf_ssh_pty_term_mode_parmrk,
7079 { "Mark parity and framing errors", "ssh.pty_term_mode.parmrk",
7080 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7081 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7082
7083 { &hf_ssh_pty_term_mode_inpck,
7084 { "Enable checking of parity errors", "ssh.pty_term_mode.inpck",
7085 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7086 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7087
7088 { &hf_ssh_pty_term_mode_istrip,
7089 { "Strip 8th bit off characters", "ssh.pty_term_mode.istrip",
7090 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7091 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7092
7093 { &hf_ssh_pty_term_mode_inlcr,
7094 { "Map NL into CR on input", "ssh.pty_term_mode.inlcr",
7095 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7096 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7097
7098 { &hf_ssh_pty_term_mode_igncr,
7099 { "Ignore CR on input", "ssh.pty_term_mode.igncr",
7100 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7101 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7102
7103 { &hf_ssh_pty_term_mode_icrnl,
7104 { "Map CR to NL on input", "ssh.pty_term_mode.icrnl",
7105 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7106 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7107
7108 { &hf_ssh_pty_term_mode_iuclc,
7109 { "Translate uppercase characters to lowercase", "ssh.pty_term_mode.iuclc",
7110 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7111 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7112
7113 { &hf_ssh_pty_term_mode_ixon,
7114 { "Enable output flow control", "ssh.pty_term_mode.ixon",
7115 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7116 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7117
7118 { &hf_ssh_pty_term_mode_ixany,
7119 { "Any char will restart after stop", "ssh.pty_term_mode.ixany",
7120 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7121 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7122
7123 { &hf_ssh_pty_term_mode_ixoff,
7124 { "Enable input flow control", "ssh.pty_term_mode.ixoff",
7125 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7126 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7127
7128 { &hf_ssh_pty_term_mode_imaxbel,
7129 { "Ring bell on input queue full", "ssh.pty_term_mode.imaxbel",
7130 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7131 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7132
7133 { &hf_ssh_pty_term_mode_iutf8,
7134 { "Terminal input and output is assumed to be encoded in UTF-8", "ssh.pty_term_mode.iutf8",
7135 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7136 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7137
7138 { &hf_ssh_pty_term_mode_isig,
7139 { "Enable signals INTR, QUIT, [D]SUSP", "ssh.pty_term_mode.isig",
7140 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7141 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7142
7143 { &hf_ssh_pty_term_mode_icanon,
7144 { "Canonicalize input lines", "ssh.pty_term_mode.icanon",
7145 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7146 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7147
7148 { &hf_ssh_pty_term_mode_xcase,
7149 { "Enable input and output of uppercase characters by preceding their lowercase equivalents with '\'", "ssh.pty_term_mode.xcase",
7150 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7151 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7152
7153 { &hf_ssh_pty_term_mode_echo,
7154 { "Enable echoing", "ssh.pty_term_mode.echo",
7155 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7156 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7157
7158 { &hf_ssh_pty_term_mode_echoe,
7159 { "Visually erase chars", "ssh.pty_term_mode.echoe",
7160 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7161 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7162
7163 { &hf_ssh_pty_term_mode_echok,
7164 { "Kill character discards current line", "ssh.pty_term_mode.echok",
7165 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7166 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7167
7168 { &hf_ssh_pty_term_mode_echonl,
7169 { "Echo NL even if ECHO is off", "ssh.pty_term_mode.echonl",
7170 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7171 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7172
7173 { &hf_ssh_pty_term_mode_noflsh,
7174 { "No flush after interrupt", "ssh.pty_term_mode.noflsh",
7175 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7176 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7177
7178 { &hf_ssh_pty_term_mode_tostop,
7179 { "Stop background jobs from output", "ssh.pty_term_mode.tostop",
7180 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7181 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7182
7183 { &hf_ssh_pty_term_mode_iexten,
7184 { "Enable extensions", "ssh.pty_term_mode.iexten",
7185 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7186 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7187
7188 { &hf_ssh_pty_term_mode_echoctl,
7189 { "Echo control characters as ^(Char)", "ssh.pty_term_mode.echoctl",
7190 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7191 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7192
7193 { &hf_ssh_pty_term_mode_echoke,
7194 { "Visual erase for line kill", "ssh.pty_term_mode.echoke",
7195 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7196 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7197
7198 { &hf_ssh_pty_term_mode_pendin,
7199 { "Retype pending input", "ssh.pty_term_mode.pendin",
7200 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7201 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7202
7203 { &hf_ssh_pty_term_mode_opost,
7204 { "Enable output processing", "ssh.pty_term_mode.opost",
7205 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7206 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7207
7208 { &hf_ssh_pty_term_mode_olcuc,
7209 { "Convert lowercase to uppercase", "ssh.pty_term_mode.olcuc",
7210 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7211 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7212
7213 { &hf_ssh_pty_term_mode_onlcr,
7214 { "Map NL to CR-NL", "ssh.pty_term_mode.onlcr",
7215 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7216 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7217
7218 { &hf_ssh_pty_term_mode_ocrnl,
7219 { "Translate carriage return to newline (output)", "ssh.pty_term_mode.ocrnl",
7220 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7221 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7222
7223 { &hf_ssh_pty_term_mode_onocr,
7224 { "Translate newline to carriage-return newline (output)", "ssh.pty_term_mode.onocr",
7225 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7226 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7227
7228 { &hf_ssh_pty_term_mode_onlret,
7229 { "Newline performs a carriage return (output)", "ssh.pty_term_mode.onlret",
7230 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7231 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7232
7233 { &hf_ssh_pty_term_mode_cs7,
7234 { "7 bit mode", "ssh.pty_term_mode.cs7",
7235 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7236 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7237
7238 { &hf_ssh_pty_term_mode_cs8,
7239 { "8 bit mode", "ssh.pty_term_mode.cs8",
7240 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7241 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7242
7243 { &hf_ssh_pty_term_mode_parenb,
7244 { "Parity enable", "ssh.pty_term_mode.parenb",
7245 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7246 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7247
7248 { &hf_ssh_pty_term_mode_parodd,
7249 { "Odd parity", "ssh.pty_term_mode.parodd",
7250 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7251 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7252
7253 { &hf_ssh_pty_term_mode_ispeed,
7254 { "Input baud rate", "ssh.pty_term_mode.ispeed",
7255 FT_UINT32, BASE_DEC|BASE_UNIT_STRING0x00001000, UNS(&units_bit_sec)((0 ? (const struct unit_name_string*)0 : ((&units_bit_sec
))))
, 0x0,
7256 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7257
7258 { &hf_ssh_pty_term_mode_ospeed,
7259 { "Output baud rate", "ssh.pty_term_mode.ospeed",
7260 FT_UINT32, BASE_DEC|BASE_UNIT_STRING0x00001000, UNS(&units_bit_sec)((0 ? (const struct unit_name_string*)0 : ((&units_bit_sec
))))
, 0x0,
7261 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7262
7263 { &hf_ssh_pty_term_mode_value,
7264 { "Value", "ssh.pty_term_mode.value",
7265 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
7266 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7267
7268 { &hf_ssh_exit_status,
7269 { "Exit status", "ssh.exit_status",
7270 FT_UINT32, BASE_HEX, NULL((void*)0), 0x0,
7271 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7272
7273 { &hf_ssh_channel_window_adjust,
7274 { "Bytes to add", "ssh.channel_window_adjust",
7275 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
7276 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7277
7278 { &hf_ssh_channel_data_len,
7279 { "Data length", "ssh.channel_data_length",
7280 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
7281 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7282
7283 { &hf_ssh_channel_data_type_code,
7284 { "Data Type Code", "ssh.channel_data_type_code",
7285 FT_UINT32, BASE_DEC, VALS(ssh_channel_data_type_code_vals)((0 ? (const struct _value_string*)0 : ((ssh_channel_data_type_code_vals
))))
, 0x0,
7286 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } },
7287
7288 { &hf_ssh_reassembled_in,
7289 { "Reassembled PDU in frame", "ssh.reassembled_in",
7290 FT_FRAMENUM, BASE_NONE, NULL((void*)0), 0x0,
7291 "The PDU that doesn't end in this segment is reassembled in this frame", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7292
7293 { &hf_ssh_reassembled_length,
7294 { "Reassembled PDU length", "ssh.reassembled.length",
7295 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
7296 "The total length of the reassembled payload", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7297
7298 { &hf_ssh_reassembled_data,
7299 { "Reassembled PDU data", "ssh.reassembled.data",
7300 FT_BYTES, BASE_NONE, NULL((void*)0), 0x00,
7301 "The payload of multiple reassembled SSH segments", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7302
7303 { &hf_ssh_segments,
7304 { "Reassembled SSH segments", "ssh.segments",
7305 FT_NONE, BASE_NONE, NULL((void*)0), 0x0,
7306 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7307
7308 { &hf_ssh_segment,
7309 { "SSH segment", "ssh.segment",
7310 FT_FRAMENUM, BASE_NONE, NULL((void*)0), 0x0,
7311 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7312
7313 { &hf_ssh_segment_overlap,
7314 { "Segment overlap", "ssh.segment.overlap",
7315 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7316 "Segment overlaps with other segments", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7317
7318 { &hf_ssh_segment_overlap_conflict,
7319 { "Conflicting data in segment overlap", "ssh.segment.overlap.conflict",
7320 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7321 "Overlapping segments contained conflicting data", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7322
7323 { &hf_ssh_segment_multiple_tails,
7324 { "Multiple tail segments found", "ssh.segment.multipletails",
7325 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7326 "Several tails were found when reassembling the pdu", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7327
7328 { &hf_ssh_segment_too_long_fragment,
7329 { "Segment too long", "ssh.segment.toolongfragment",
7330 FT_BOOLEAN, BASE_NONE, NULL((void*)0), 0x0,
7331 "Segment contained data past end of the pdu", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7332
7333 { &hf_ssh_segment_error,
7334 { "Reassembling error", "ssh.segment.error",
7335 FT_FRAMENUM, BASE_NONE, NULL((void*)0), 0x0,
7336 "Reassembling error due to illegal segments", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7337
7338 { &hf_ssh_segment_count,
7339 { "Segment count", "ssh.segment.count",
7340 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0,
7341 NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7342
7343 { &hf_ssh_segment_data,
7344 { "SSH segment data", "ssh.segment.data",
7345 FT_BYTES, BASE_NONE, NULL((void*)0), 0x00,
7346 "The payload of a single SSH segment", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }},
7347
7348 { &hf_ssh_hybrid_blob_client,
7349 { "Hybrid Key Exchange Blob Client", "ssh.kex_hybrid_blob_client",
7350 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0, "Client post-quantum hybrid blob", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }
7351 },
7352
7353 { &hf_ssh_hybrid_blob_client_len,
7354 { "Hybrid Key Exchange Blob Client Length", "ssh.kex_hybrid_blob_client_len",
7355 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0, "Length of client post-quantum hybrid blob", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }
7356 },
7357
7358 { &hf_ssh_hybrid_blob_server,
7359 { "Hybrid Key Exchange Blob Server", "ssh.kex_hybrid_blob_server",
7360 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0, "Server post-quantum hybrid blob", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }
7361 },
7362
7363 { &hf_ssh_hybrid_blob_server_len,
7364 { "Hybrid Key Exchange Blob Server Length", "ssh.kex_hybrid_blob_server_len",
7365 FT_UINT32, BASE_DEC, NULL((void*)0), 0x0, "Length of server post-quantum hybrid blob", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }
7366 },
7367
7368 { &hf_ssh_pq_kem_client,
7369 { "Client PQ KEM Public Key", "ssh.kex.pq_kem_client",
7370 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
7371 "Post-quantum key (client)", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }
7372 },
7373
7374 { &hf_ssh_pq_kem_server,
7375 { "Server PQ KEM Response", "ssh.kex.pq_kem_server",
7376 FT_BYTES, BASE_NONE, NULL((void*)0), 0x0,
7377 "Post-quantum ciphertext (server response)", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) }
7378 },
7379
7380 };
7381
7382 static int *ett[] = {
7383 &ett_ssh,
7384 &ett_key_exchange,
7385 &ett_key_exchange_host_key,
7386 &ett_key_exchange_host_sig,
7387 &ett_extension,
7388 &ett_userauth_pk_blob,
7389 &ett_userauth_pk_signature,
7390 &ett_term_modes,
7391 &ett_term_mode,
7392 &ett_ssh1,
7393 &ett_ssh2,
7394 &ett_key_init,
7395 &ett_ssh_segments,
7396 &ett_ssh_pqhybrid_client, // added for PQ hybrid CLIENT dissection
7397 &ett_ssh_pqhybrid_server, // added for PQ hybrid SERVER dissection
7398 &ett_ssh_segment
7399 };
7400
7401 static ei_register_info ei[] = {
7402 { &ei_ssh_packet_length, { "ssh.packet_length.error", PI_PROTOCOL0x09000000, PI_WARN0x00600000, "Invalid packet length", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE
, BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE
, -1, ((void*)0)}}
}},
7403 { &ei_ssh_padding_length, { "ssh.padding_length.error", PI_PROTOCOL0x09000000, PI_WARN0x00600000, "Invalid padding length", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE
, BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE
, -1, ((void*)0)}}
}},
7404 { &ei_ssh_packet_decode, { "ssh.packet_decode.error", PI_UNDECODED0x05000000, PI_WARN0x00600000, "Packet decoded length not equal to packet length", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE
, BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE
, -1, ((void*)0)}}
}},
7405 { &ei_ssh_channel_number, { "ssh.channel_number.error", PI_PROTOCOL0x09000000, PI_WARN0x00600000, "Could not find channel", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE
, BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE
, -1, ((void*)0)}}
}},
7406 { &ei_ssh_invalid_keylen, { "ssh.key_length.error", PI_PROTOCOL0x09000000, PI_ERROR0x00800000, "Invalid key length", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE
, BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE
, -1, ((void*)0)}}
}},
7407 { &ei_ssh_mac_bad, { "ssh.mac_bad.expert", PI_CHECKSUM0x01000000, PI_ERROR0x00800000, "Bad MAC", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE
, BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE
, -1, ((void*)0)}}
}},
7408 { &ei_ssh2_kex_hybrid_msg_code, { "ssh.kex_hybrid_msg_code", PI_SECURITY0x0a000000, PI_NOTE0x00400000, "Hybrid KEX encountered", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE
, BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE
, -1, ((void*)0)}}
}},
7409 { &ei_ssh2_kex_hybrid_msg_code_unknown, { "ssh.kex_hybrid_msg_code.unknown", PI_UNDECODED0x05000000, PI_NOTE0x00400000, "Unknown KEX_HYBRID message code", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE
, BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE
, -1, ((void*)0)}}
}},
7410
7411 };
7412 module_t *ssh_module;
7413 expert_module_t *expert_ssh;
7414
7415 proto_ssh = proto_register_protocol("SSH Protocol", "SSH", "ssh");
7416 proto_register_field_array(proto_ssh, hf, array_length(hf)(sizeof (hf) / sizeof (hf)[0]));
7417 proto_register_subtree_array(ett, array_length(ett)(sizeof (ett) / sizeof (ett)[0]));
7418 expert_ssh = expert_register_protocol(proto_ssh);
7419 expert_register_field_array(expert_ssh, ei, array_length(ei)(sizeof (ei) / sizeof (ei)[0]));
7420
7421#ifdef SSH_DECRYPT_DEBUG
7422 ssh_module = prefs_register_protocol(proto_ssh, ssh_prefs_apply_cb);
7423#else
7424 ssh_module = prefs_register_protocol(proto_ssh, NULL((void*)0));
7425#endif
7426 prefs_register_bool_preference(ssh_module, "desegment_buffers",
7427 "Reassemble SSH buffers spanning multiple TCP segments",
7428 "Whether the SSH dissector should reassemble SSH buffers spanning multiple TCP segments. "
7429 "To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
7430 &ssh_desegment);
7431 prefs_register_bool_preference(ssh_module, "ignore_ssh_mac_failed",
7432 "Ignore Message Authentication Code (MAC) failure",
7433 "For troubleshooting purposes, decrypt even if the "
7434 "Message Authentication Code (MAC) check fails.",
7435 &ssh_ignore_mac_failed);
7436
7437 ssh_master_key_map = g_hash_table_new_full(ssh_hash, ssh_equal, ssh_free_glib_allocated_bignum, ssh_free_glib_allocated_entry);
7438 prefs_register_filename_preference(ssh_module, "keylog_file", "Key log filename",
7439 "The path to the file which contains a list of key exchange secrets in the following format:\n"
7440 "\"<hex-encoded-cookie> <PRIVATE_KEY|SHARED_SECRET> <hex-encoded-key>\" (without quotes or leading spaces).\n",
7441 &pref_keylog_file, false0);
7442
7443 prefs_register_filename_preference(ssh_module, "debug_file", "SSH debug file",
7444 "Redirect SSH debug to the file specified. Leave empty to disable debugging "
7445 "or use \"" SSH_DEBUG_USE_STDERR"-" "\" to redirect output to stderr.",
7446 &ssh_debug_file_name, true1);
7447
7448 secrets_register_type(SECRETS_TYPE_SSH0x5353484b, ssh_secrets_block_callback);
7449
7450 ssh_handle = register_dissector("ssh", dissect_ssh, proto_ssh);
7451 reassembly_table_register(&ssh_reassembly_table, &tcp_reassembly_table_functions);
7452 register_shutdown_routine(ssh_shutdown);
7453}
7454
7455void
7456proto_reg_handoff_ssh(void)
7457{
7458#ifdef SSH_DECRYPT_DEBUG
7459 ssh_set_debug(ssh_debug_file_name);
7460#endif
7461 dissector_add_uint_range_with_preference("tcp.port", TCP_RANGE_SSH"22", ssh_handle);
7462 dissector_add_uint("sctp.port", SCTP_PORT_SSH22, ssh_handle);
7463 dissector_add_uint("sctp.ppi", SSH_PAYLOAD_PROTOCOL_ID45, ssh_handle);
7464 sftp_handle = find_dissector_add_dependency("sftp", proto_ssh);
7465 data_text_lines_handle = find_dissector_add_dependency("data-text-lines", proto_ssh);
7466
7467 heur_dissector_add("tcp", dissect_ssh_heur, "SSH over TCP", "ssh_tcp", proto_ssh, HEURISTIC_ENABLE);
7468}
7469
7470/*
7471 * Editor modelines - https://www.wireshark.org/tools/modelines.html
7472 *
7473 * Local variables:
7474 * c-basic-offset: 4
7475 * tab-width: 8
7476 * indent-tabs-mode: nil
7477 * End:
7478 *
7479 * vi: set shiftwidth=4 tabstop=8 expandtab:
7480 * :indentSize=4:tabSize=8:noTabs=true:
7481 */