Bug Summary

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