Wireshark 4.7.3
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
packet-smb2.h
1/* packet-smb2.h
2 * Defines for SMB2 packet dissection
3 *
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <[email protected]>
6 * Copyright 1998, 1999 Gerald Combs
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11#ifndef __PACKET_SMB2_H__
12#define __PACKET_SMB2_H__
13
14#include "packet-dcerpc.h"
15#include "packet-smb.h"
16#include "packet-ntlmssp.h"
17
18/* SMB2 command codes. With MSVC and a
19 * libwireshark.dll, we need a special declaration.
20 */
21WS_DLL_PUBLIC value_string_ext smb2_cmd_vals_ext;
22
23/* Structure to keep track of information specific to a single
24 * SMB2 transaction. Here we store things we need to remember between
25 * a specific request and a specific response.
26 *
27 * There is no guarantee we will have this structure available for all
28 * SMB2 packets so a dissector must check this pointer for NULL
29 * before dereferencing it.
30 *
31 * private data is set to NULL when the structure is created. It is used
32 * for communications between the Request and the Response packets.
33 */
34
35/* extra info needed by export object smb */
36typedef struct _smb2_eo_file_info_t {
37 uint32_t attr_mask;
38 int64_t end_of_file;
39} smb2_eo_file_info_t;
40
41typedef struct _smb2_fid_info_t {
42 uint64_t fid_persistent;
43 uint64_t fid_volatile;
44 uint64_t sesid; /* *host* byte order - not necessarily little-endian! */
45 uint32_t tid;
46 /* only used for key lookup in equal func, must be zero when inserting */
47 uint32_t frame_key;
48 /* first and last frame nums this FID is valid */
49 uint32_t frame_beg;
50 uint32_t frame_end;
51 /* file name used to open this FID */
52 char *name;
53 bool is_dir;
54 bool delete_on_close;
55 uint32_t desired_access;
56 uint32_t granted_access;
57} smb2_fid_info_t;
58
59typedef enum {
60 SMB2_EI_NONE, /* Unassigned / NULL */
61 SMB2_EI_TREENAME, /* tid tracking char * */
62 SMB2_EI_FILENAME, /* fid tracking char * */
63 SMB2_EI_FINDPATTERN /* find tracking char * */
64} smb2_extra_info_t;
65typedef struct _smb2_saved_info_t {
66 uint8_t smb2_class;
67 uint8_t infolevel;
68 uint64_t msg_id;
69 uint32_t frame_req, frame_res;
70 nstime_t req_time;
71 nstime_t resp_time;
72 uint32_t cancelled_in; /* non-async requests can also be cancelled, so this belongs here */
73 struct smb2_async_t *async; /* If an aid is associated with this ssi, async is stored here. */
74 uint8_t *preauth_hash_req, *preauth_hash_res;
75 smb2_fid_info_t *file;
76 e_ctx_hnd policy_hnd; /* for eo_smb tracking */
77 smb_eo_t *eo_info_t; /* for storing eo_smb infos */
78 uint64_t file_offset; /* needed file_offset for eo_smb */
79 uint32_t bytes_moved; /* needed for eo_smb */
80 void *extra_info;
81 smb2_extra_info_t extra_info_type;
82 uint32_t fid_hash;
83 uint16_t num_matched;
84 proto_item *hnd_item;
85 e_guid_t uuid_fid;
86 uint32_t frame_beg; /* The create frame. */
87 uint32_t frame_end; /* The close frame. */
88 const uint8_t *filename;
89} smb2_saved_info_t;
90
91typedef struct smb2_async_t {
92 uint64_t aid;
93 uint32_t opcode; /* Command that has been pended or cancelled */
94 uint32_t status_pending_in;
95 uint32_t cancel_req_in; /* Cancel requests can arrive without the async flag but they are... */
96 nstime_t cancel_req_time; /* ...stored here nonetheless. */
97 smb2_saved_info_t *ssi_parent;
99
100typedef struct _smb2_tid_info_t {
101 uint32_t tid;
102 uint32_t connect_frame;
103 uint32_t disconnect_frame;
104 uint8_t share_type;
105 char *name;
106} smb2_tid_info_t;
107
108#define SMB2_PREAUTH_HASH_SIZE 64
109#define AES_KEY_SIZE 16
110
111typedef struct _smb2_sesid_info_t {
112 uint64_t sesid; /* *host* byte order - not necessarily little-endian! */
113 uint32_t auth_frame;
114 char *acct_name;
115 char *domain_name;
116 char *host_name;
117 uint16_t server_port;
118 uint32_t session_key_frame;
119 unsigned session_key_len;
120 uint8_t session_key[NTLMSSP_KEY_LEN*2];
121 uint8_t signing_key[NTLMSSP_KEY_LEN];
122 uint8_t client_decryption_key16[AES_KEY_SIZE];
123 uint8_t server_decryption_key16[AES_KEY_SIZE];
124 uint8_t client_decryption_key32[AES_KEY_SIZE*2];
125 uint8_t server_decryption_key32[AES_KEY_SIZE*2];
126
127 wmem_map_t *tids;
128 wmem_map_t *fids;
129 /* table to store some infos for smb export object */
130 wmem_map_t *files;
131
132 uint8_t preauth_hash[SMB2_PREAUTH_HASH_SIZE];
133} smb2_sesid_info_t;
134
135/* Structure to keep track of conversations and the hash tables.
136 * There is one such structure for each conversation.
137 */
138typedef struct _smb2_conv_info_t {
139 /* these two tables are used to match requests with responses */
140 GHashTable *unmatched;
141 GHashTable *matched;
142 GHashTable *asyncs; /* Table of smb2_async_t structs indexed by aid */
143 GHashTable *asy_cancels; /* When the msg_id of a request to Cancel a pended request is 0,
144 the ssi associated with it cannot be looked up. Instead a pointer
145 to the async is stored indexed by the aid in the asyncs table.
146 A response to a Cancel of a pended request contains both the msg_id, and
147 aid, so when it arrives, ssi is stored in async->ssi_parent. The aid key
148 must be removed from the asyncs table because the aid can be reused.
149 Unfortunately, with the aid removed there is no way to lookup the async
150 of Cancel requests, so it is stored in the this table indexed by its
151 frame#. */
152 uint16_t dialect;
153 uint16_t sign_alg;
154 uint16_t enc_alg;
155
156 /* preauth hash before session setup */
157 uint8_t *preauth_hash_current;
158 uint8_t preauth_hash_con[SMB2_PREAUTH_HASH_SIZE];
159 uint8_t preauth_hash_ses[SMB2_PREAUTH_HASH_SIZE];
160} smb2_conv_info_t;
161
162
163/* This structure contains information from the SMB2 header
164 * as well as pointers to the conversation and the transaction specific
165 * structures.
166 */
167#define SMB2_FLAGS_RESPONSE 0x00000001
168#define SMB2_FLAGS_ASYNC_CMD 0x00000002
169#define SMB2_FLAGS_CHAINED 0x00000004
170#define SMB2_FLAGS_SIGNATURE 0x00000008
171#define SMB2_FLAGS_PRIORITY_MASK 0x00000070
172#define SMB2_FLAGS_DFS_OP 0x10000000
173#define SMB2_FLAGS_REPLAY_OPERATION 0x20000000
174
175#define SMB2_FLAGS_PRIORITY1 0x00000010
176#define SMB2_FLAGS_PRIORITY2 0x00000020
177#define SMB2_FLAGS_PRIORITY3 0x00000030
178#define SMB2_FLAGS_PRIORITY4 0x00000040
179#define SMB2_FLAGS_PRIORITY5 0x00000050
180#define SMB2_FLAGS_PRIORITY6 0x00000060
181#define SMB2_FLAGS_PRIORITY7 0x00000070
182
183/* SMB2 FLAG MASKS */
184#define SMB2_FLAGS_ATTR_ENCRYPTED 0x00004000
185#define SMB2_FLAGS_ATTR_INDEXED 0x00002000
186#define SMB2_FLAGS_ATTR_OFFLINE 0x00001000
187#define SMB2_FLAGS_ATTR_COMPRESSED 0x00000800
188#define SMB2_FLAGS_ATTR_REPARSEPOINT 0x00000400
189#define SMB2_FLAGS_ATTR_SPARSE 0x00000200
190#define SMB2_FLAGS_ATTR_TEMPORARY 0x00000100
191#define SMB2_FLAGS_ATTR_NORMAL 0x00000080
192#define SMB2_FLAGS_ATTR_DEVICE 0x00000040
193#define SMB2_FLAGS_ATTR_ARCHIVE 0x00000020
194#define SMB2_FLAGS_ATTR_DIRECTORY 0x00000010
195#define SMB2_FLAGS_ATTR_VOLUMEID 0x00000008
196#define SMB2_FLAGS_ATTR_SYSTEM 0x00000004
197#define SMB2_FLAGS_ATTR_HIDDEN 0x00000002
198#define SMB2_FLAGS_ATTR_READONLY 0x00000001
199
200/* SMB2 FILE TYPES ASSIGNED TO EXPORT OBJECTS */
201#define SMB2_FID_TYPE_UNKNOWN 0
202#define SMB2_FID_TYPE_FILE 1
203#define SMB2_FID_TYPE_DIR 2
204#define SMB2_FID_TYPE_PIPE 3
205#define SMB2_FID_TYPE_OTHER 4
206
207/* SMB2 COMMAND CODES */
208#define SMB2_COM_NEGOTIATE_PROTOCOL 0x00
209#define SMB2_COM_SESSION_SETUP 0x01
210#define SMB2_COM_SESSION_LOGOFF 0x02
211#define SMB2_COM_TREE_CONNECT 0x03
212#define SMB2_COM_TREE_DISCONNECT 0x04
213#define SMB2_COM_CREATE 0x05
214#define SMB2_COM_CLOSE 0x06
215#define SMB2_COM_FLUSH 0x07
216#define SMB2_COM_READ 0x08
217#define SMB2_COM_WRITE 0x09
218#define SMB2_COM_LOCK 0x0A
219#define SMB2_COM_IOCTL 0x0B
220#define SMB2_COM_CANCEL 0x0C
221#define SMB2_COM_KEEPALIVE 0x0D
222#define SMB2_COM_FIND 0x0E
223#define SMB2_COM_NOTIFY 0x0F
224#define SMB2_COM_GETINFO 0x10
225#define SMB2_COM_SETINFO 0x11
226#define SMB2_COM_BREAK 0x12
227
228typedef struct _smb2_info_t {
229 uint16_t opcode;
230 uint32_t ioctl_function;
231 uint32_t status;
232 uint32_t tid;
233 uint64_t sesid; /* *host* byte order - not necessarily little-endian! */
234 uint64_t msg_id;
235 uint64_t aid; /* async Id */
236 uint32_t flags;
237 smb2_eo_file_info_t *eo_file_info; /* eo_smb extra info */
238 smb2_conv_info_t *conv;
239 smb2_saved_info_t *saved;
240 smb2_tid_info_t *tree;
241 smb2_sesid_info_t *session;
242 smb2_fid_info_t *file;
243 proto_tree *top_tree;
244} smb2_info_t;
245
246/* for transform content information */
247
249 uint8_t nonce[16];
250 uint32_t size;
251 uint16_t flags;
252 uint64_t sesid; /* *host* byte order - not necessarily little-endian! */
253 smb2_conv_info_t *conv;
254 smb2_sesid_info_t *session;
255} smb2_transform_info_t;
256
258 unsigned orig_size;
259 unsigned alg;
260 unsigned comp_offset;
261 smb2_conv_info_t *conv;
262 smb2_sesid_info_t *session;
263} smb2_comp_transform_info_t;
264
265
266int dissect_smb2_FILE_OBJECTID_BUFFER(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset);
267int dissect_smb2_ioctl_function(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset, uint32_t *ioctl_function);
268void dissect_smb2_ioctl_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree *top_tree, uint32_t ioctl_function, bool data_in, void *private_data);
269
270#endif
271
272/*
273 * Editor modelines - https://www.wireshark.org/tools/modelines.html
274 *
275 * Local variables:
276 * c-basic-offset: 8
277 * tab-width: 8
278 * indent-tabs-mode: t
279 * End:
280 *
281 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
282 * :indentSize=8:tabSize=8:noTabs=false:
283 */
struct _packet_info packet_info
Represents the metadata and indexing information for a single captured frame.
proto_node proto_item
Definition proto.h:927
struct _wmem_map_t wmem_map_t
Opaque type representing a wmem-managed hash map.
Definition wmem_map.h:46
struct _e_guid_t e_guid_t
Represents a GUID/UUID value; may be larger than GUID_LEN so must not be used to directly overlay pac...
Definition packet-smb2.h:257
Definition packet-smb2.h:138
Definition packet-smb2.h:36
Definition packet-smb2.h:41
Definition packet-smb2.h:228
Definition packet-smb2.h:65
Definition packet-smb2.h:111
Definition packet-smb2.h:100
Definition packet-smb2.h:248
Definition nstime.h:26
Definition packet-smb2.h:91