Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
packet-smb.h
1/* packet-smb.h
2 * Defines for SMB packet dissection
3 * Copyright 1999, Richard Sharpe <[email protected]>
4 *
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <[email protected]>
7 * Copyright 1998, 1999 Gerald Combs
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11
12#ifndef __PACKET_SMB_H__
13#define __PACKET_SMB_H__
14
15#include "ws_symbol_export.h"
16
17#include <epan/proto.h>
18#include <epan/wmem_scopes.h>
19
20WS_DLL_PUBLIC bool sid_name_snooping;
21
22/* SMB command codes, from the SNIA CIFS spec. With MSVC and a
23 * libwireshark.dll, we need a special declaration.
24 */
25WS_DLL_PUBLIC value_string_ext smb_cmd_vals_ext;
26WS_DLL_PUBLIC value_string_ext trans2_cmd_vals_ext;
27WS_DLL_PUBLIC value_string_ext nt_cmd_vals_ext;
28
29#define SMB_COM_CREATE_DIRECTORY 0x00
30#define SMB_COM_DELETE_DIRECTORY 0x01
31#define SMB_COM_OPEN 0x02
32#define SMB_COM_CREATE 0x03
33#define SMB_COM_CLOSE 0x04
34#define SMB_COM_FLUSH 0x05
35#define SMB_COM_DELETE 0x06
36#define SMB_COM_RENAME 0x07
37#define SMB_COM_QUERY_INFORMATION 0x08
38#define SMB_COM_SET_INFORMATION 0x09
39#define SMB_COM_READ 0x0A
40#define SMB_COM_WRITE 0x0B
41#define SMB_COM_LOCK_BYTE_RANGE 0x0C
42#define SMB_COM_UNLOCK_BYTE_RANGE 0x0D
43#define SMB_COM_CREATE_TEMPORARY 0x0E
44#define SMB_COM_CREATE_NEW 0x0F
45#define SMB_COM_CHECK_DIRECTORY 0x10
46#define SMB_COM_PROCESS_EXIT 0x11
47#define SMB_COM_SEEK 0x12
48#define SMB_COM_LOCK_AND_READ 0x13
49#define SMB_COM_WRITE_AND_UNLOCK 0x14
50#define SMB_COM_READ_RAW 0x1A
51#define SMB_COM_READ_MPX 0x1B
52#define SMB_COM_READ_MPX_SECONDARY 0x1C
53#define SMB_COM_WRITE_RAW 0x1D
54#define SMB_COM_WRITE_MPX 0x1E
55#define SMB_COM_WRITE_MPX_SECONDARY 0x1F
56#define SMB_COM_WRITE_COMPLETE 0x20
57#define SMB_COM_QUERY_SERVER 0x21
58#define SMB_COM_SET_INFORMATION2 0x22
59#define SMB_COM_QUERY_INFORMATION2 0x23
60#define SMB_COM_LOCKING_ANDX 0x24
61#define SMB_COM_TRANSACTION 0x25
62#define SMB_COM_TRANSACTION_SECONDARY 0x26
63#define SMB_COM_IOCTL 0x27
64#define SMB_COM_IOCTL_SECONDARY 0x28
65#define SMB_COM_COPY 0x29
66#define SMB_COM_MOVE 0x2A
67#define SMB_COM_ECHO 0x2B
68#define SMB_COM_WRITE_AND_CLOSE 0x2C
69#define SMB_COM_OPEN_ANDX 0x2D
70#define SMB_COM_READ_ANDX 0x2E
71#define SMB_COM_WRITE_ANDX 0x2F
72#define SMB_COM_NEW_FILE_SIZE 0x30
73#define SMB_COM_CLOSE_AND_TREE_DISC 0x31
74#define SMB_COM_TRANSACTION2 0x32
75#define SMB_COM_TRANSACTION2_SECONDARY 0x33
76#define SMB_COM_FIND_CLOSE2 0x34
77#define SMB_COM_FIND_NOTIFY_CLOSE 0x35
78/* Used by Xenix/Unix 0x60-0x6E */
79#define SMB_COM_TREE_CONNECT 0x70
80#define SMB_COM_TREE_DISCONNECT 0x71
81#define SMB_COM_NEGOTIATE 0x72
82#define SMB_COM_SESSION_SETUP_ANDX 0x73
83#define SMB_COM_LOGOFF_ANDX 0x74
84#define SMB_COM_TREE_CONNECT_ANDX 0x75
85#define SMB_COM_QUERY_INFORMATION_DISK 0x80
86#define SMB_COM_SEARCH 0x81
87#define SMB_COM_FIND 0x82
88#define SMB_COM_FIND_UNIQUE 0x83
89#define SMB_COM_FIND_CLOSE 0x84
90#define SMB_COM_NT_TRANSACT 0xA0
91#define SMB_COM_NT_TRANSACT_SECONDARY 0xA1
92#define SMB_COM_NT_CREATE_ANDX 0xA2
93#define SMB_COM_NT_CANCEL 0xA4
94#define SMB_COM_NT_RENAME 0xA5
95#define SMB_COM_OPEN_PRINT_FILE 0xC0
96#define SMB_COM_WRITE_PRINT_FILE 0xC1
97#define SMB_COM_CLOSE_PRINT_FILE 0xC2
98#define SMB_COM_GET_PRINT_QUEUE 0xC3
99#define SMB_COM_READ_BULK 0xD8
100#define SMB_COM_WRITE_BULK 0xD9
101#define SMB_COM_WRITE_BULK_DATA 0xDA
102
103/* Error codes */
104
105#define SMB_SUCCESS 0x00 /* All OK */
106#define SMB_ERRDOS 0x01 /* DOS based error */
107#define SMB_ERRSRV 0x02 /* server error, network file manager */
108#define SMB_ERRHRD 0x03 /* Hardware style error */
109#define SMB_ERRCMD 0x04 /* Not an SMB format command */
110
111/* used for SMB export object functionality */
112typedef struct _smb_eo_t {
113 unsigned smbversion;
114 uint16_t cmd;
115 int tid,uid;
116 unsigned fid;
117 uint32_t pkt_num;
118 char *hostname;
119 char *filename;
120 int fid_type;
121 int64_t end_of_file;
122 char *content_type;
123 uint32_t payload_len;
124 const uint8_t *payload_data;
125 uint64_t smb_file_offset;
126 uint32_t smb_chunk_len;
127} smb_eo_t;
128
129/* the information we need to keep around for NT transaction commands */
130typedef struct {
131 int subcmd;
132 int fid_type;
133 uint32_t ioctl_function;
135
136/* the information we need to keep around for transaction2 commands
137* t2i and st2i */
138typedef struct {
139 int subcmd;
140 int info_level;
141 bool resume_keys; /* if "return resume" keys set in T2 FIND_FIRST request */
142 const char *name;
144
145/*
146 * The information we need to save about a request in order to show the
147 * frame number of the request in the dissection of the reply.
148 */
149#define SMB_SIF_TID_IS_IPC 0x0001
150#define SMB_SIF_IS_CONTINUED 0x0002
151typedef enum {
152 SMB_EI_NONE, /* Unassigned / NULL */
153 SMB_EI_FID, /* FID */
154 SMB_EI_NTI, /* smb_nt_transact_info_t * */
155 SMB_EI_TRI, /* smb_transact_info_t * */
156 SMB_EI_T2I, /* smb_transact2_info_t * */
157 SMB_EI_TIDNAME, /* tid tracking char * */
158 SMB_EI_FILEDATA, /* fid tracking */
159 SMB_EI_FILENAME, /* filename tracking */
160 SMB_EI_UID, /* smb_uid_t */
161 SMB_EI_RWINFO, /* read/write offset/count info */
162 SMB_EI_LOCKDATA, /* locking and x data */
163 SMB_EI_RENAMEDATA, /* rename data */
164 SMB_EI_DIALECTS /* negprot dialects */
165} smb_extra_info_t;
166
167typedef struct _smb_fid_into_t smb_fid_info_t;
168
169/* sip */
170typedef struct {
171 uint32_t frame_req, frame_res;
172 nstime_t req_time;
173 uint16_t flags;
174 uint8_t cmd;
175 void *extra_info;
176 smb_extra_info_t extra_info_type;
177 bool is_create_req;
178 /* we save the fid in each transaction so that we can get fid filters
179 to match both request and response */
180 bool fid_seen_in_request;
181 uint16_t fid;
183
184/*
185 * The information we need to save about a Transaction request in order
186 * to dissect the reply; this includes information for use by the
187 * Remote API and Mailslot dissectors.
188 * XXX - have an additional data structure hung off of this by the
189 * subdissectors?
190 * tri */
191typedef struct {
192 int subcmd;
193 int trans_subcmd;
194 int function;
195 /* Unification of fid variable type (was int) */
196 uint16_t fid;
197 uint16_t lanman_cmd;
198 unsigned char *param_descrip; /* Keep these descriptors around */
199 unsigned char *data_descrip;
200 unsigned char *aux_data_descrip;
201 int info_level;
203
204/*
205 * Subcommand type.
206 */
207#define TRANSACTION_PIPE 0
208#define TRANSACTION_MAILSLOT 1
209
210/* these are defines used to represent different types of TIDs.
211 don't use the value 0 for any of these */
212#define TID_NORMAL 1
213#define TID_IPC 2
214
215/* this is the structure which is associated with each conversation */
216typedef struct conv_tables {
217 /* these two tables are used to match requests with responses */
218 GHashTable *unmatched;
219 GHashTable *matched;
220 /* This table keeps primary transact requests so secondaries can find
221 them */
222 GHashTable *primaries;
223
224 /* This table is used to track TID->services for a conversation */
225 GHashTable *tid_service;
226 bool raw_ntlmssp; /* Do extended security exc use raw ntlmssp */
227
228 /* track fid to fidstruct (filename/openframe/closeframe */
229 wmem_tree_t *fid_tree;
230 /* We'll use a GSL list instead */
231 GSList *GSL_fid_info;
232
233 /* track tid to fidstruct (sharename/shareframe/unshareframe */
234 wmem_tree_t *tid_tree;
235
236 /* track uid to username mappings */
237 wmem_tree_t *uid_tree;
238
239 /* This table is used to track which request frame a [NT]Trans[2] response fragment maps to */
240 GHashTable *trans_frag_resp;
242
243/* si */
244typedef struct smb_info {
245 uint8_t cmd;
246 int tid, pid, uid, mid;
247 uint32_t nt_status;
248 bool unicode; /* Are strings in this SMB Unicode? */
249 bool request; /* Is this a request? */
250 bool unidir;
251 int info_level;
252 int info_count;
253 smb_saved_info_t *sip; /* smb_saved_info_t, if any, for this */
254 conv_tables_t *ct;
255 proto_tree *smbtree;
256} smb_info_t;
257
258/*
259 * Show file data for a read or write.
260 */
261extern int dissect_file_data(tvbuff_t *tvb, proto_tree *tree, int offset,
262 uint16_t bc, int dataoffset, uint16_t datalen);
263
264
265#define SMB_FID_TYPE_UNKNOWN 0
266#define SMB_FID_TYPE_FILE 1
267#define SMB_FID_TYPE_DIR 2
268#define SMB_FID_TYPE_PIPE 3
269
270/* used for tracking filenames from rename request to response */
272 char *old_name;
273 char *new_name;
275
276/* used for tracking lock data between lock request/response */
277typedef struct _smb_lock_info_t {
278 struct _smb_lock_info_t *next;
279 uint16_t pid;
280 uint64_t offset;
281 uint64_t length;
283
285 uint8_t type;
286 uint8_t oplock_level;
287 uint16_t num_lock;
288 uint16_t num_unlock;
289 smb_lock_info_t *locks;
290 smb_lock_info_t *unlocks;
292
293/* fsi used for tracking fid/tid to filename/sharename openedframe closedframe */
294typedef struct _smb_fid_saved_info_t {
295 char *filename;
296 uint32_t create_flags;
297 uint32_t access_mask;
298 uint32_t file_attributes;
299 uint32_t share_access;
300 uint32_t create_options;
301 uint32_t create_disposition;
303
305 uint16_t tid,fid;
306 /* The end_of_file will store the last registered offset or
307 the reported end_of_file from the SMB protocol */
308 int64_t end_of_file;
309 /* These two were int */
310 unsigned opened_in;
311 unsigned closed_in;
312 int type;
314};
315
316/* used for tracking tid to sharename openedframe closedframe */
317typedef struct _smb_tid_into_t {
318 int opened_in;
319 int closed_in;
320 char *filename;
321 int type;
323
324
325/*
326 * Dissect an smb FID
327 */
328extern smb_fid_info_t *dissect_smb_fid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
329 int offset, int len, uint16_t fid, bool is_created, bool is_closed, bool is_generated, bool is_displayed, smb_info_t* si);
330
331/*
332 * Dissect named pipe state information.
333 */
334extern int dissect_ipc_state(tvbuff_t *tvb, proto_tree *parent_tree,
335 int offset, bool setstate);
336
337extern bool smb_dcerpc_reassembly;
338
339extern const value_string create_disposition_vals[];
340
341extern int dissect_nt_create_options(tvbuff_t *tvb, proto_tree *parent_tree, int offset);
342
343extern int dissect_nt_share_access(tvbuff_t *tvb, proto_tree *parent_tree, int offset);
344
345extern int dissect_smb_access_mask(tvbuff_t *tvb, proto_tree *parent_tree, int offset);
346
347extern const value_string oa_open_vals[];
348extern const value_string impersonation_level_vals[];
349
350extern bool sid_display_hex;
351
352extern int dissect_security_information_mask(tvbuff_t *tvb, proto_tree *parent_tree, int offset);
353
354extern int dissect_qfsi_FS_VOLUME_INFO(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, int offset, uint16_t *bcp, int unicode);
355extern int dissect_qfsi_FS_SIZE_INFO(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, int offset, uint16_t *bcp);
356extern int dissect_qfsi_FS_DEVICE_INFO(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, int offset, uint16_t *bcp);
357extern int dissect_qfsi_FS_ATTRIBUTE_INFO(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, int offset, uint16_t *bcp);
358extern int dissect_nt_quota(tvbuff_t *tvb, proto_tree *tree, int offset, uint16_t *bcp);
359extern int dissect_nt_user_quota(tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, int offset, uint16_t *bcp);
360extern int dissect_nt_get_user_quota(tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, int offset, uint32_t *bcp);
361extern int dissect_qfsi_FS_OBJECTID_INFO(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, int offset, uint16_t *bcp);
362extern int dissect_qfsi_FS_FULL_SIZE_INFO(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, int offset, uint16_t *bcp);
363extern int dissect_qfi_SMB_FILE_EA_INFO(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
364extern int dissect_qfi_SMB_FILE_STREAM_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset, uint16_t *bcp, bool *trunc, int unicode);
365extern int dissect_qfi_SMB_FILE_NAME_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc, bool unicode);
366extern int dissect_qfi_SMB_FILE_STANDARD_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
367extern int dissect_qfi_SMB_FILE_INTERNAL_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
368extern int dissect_qsfi_SMB_FILE_POSITION_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
369extern int dissect_qsfi_SMB_FILE_MODE_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
370extern int dissect_qfi_SMB_FILE_ALIGNMENT_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
371extern int dissect_qfi_SMB_FILE_COMPRESSION_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
372extern int dissect_qfi_SMB_FILE_NETWORK_OPEN_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
373extern int dissect_qfi_SMB_FILE_ATTRIBUTE_TAG_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
374extern int dissect_qsfi_SMB_FILE_ALLOCATION_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
375extern int dissect_qsfi_SMB_FILE_ENDOFFILE_INFO(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
376extern int dissect_nt_notify_completion_filter(tvbuff_t *tvb, proto_tree *parent_tree, int offset);
377extern int dissect_sfi_SMB_FILE_PIPE_INFO(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
378extern int dissect_qfi_SMB_FILE_PIPE_LOCAL_INFO(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
379extern int dissect_qfi_SMB_FILE_PIPE_REMOTE_INFO(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, int offset, uint16_t *bcp, bool *trunc);
380extern int dissect_smb_get_dfs_request_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool unicode);
381extern int dissect_smb_get_dfs_referral_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset, uint16_t *bcp, bool unicode);
382extern const char *smb_get_unicode_or_ascii_string(wmem_allocator_t *scope, tvbuff_t *tvb, int *offsetp, bool useunicode,
383 int *len, bool nopad, bool exactlen, uint16_t *bcp);
384
385/* Returns an IP (v4 or v6) of the server in a SMB/SMB2 conversation */
386extern const char *tree_ip_str(packet_info *pinfo, uint16_t cmd);
387
388#endif
389
390/*
391 * Editor modelines - https://www.wireshark.org/tools/modelines.html
392 *
393 * Local variables:
394 * c-basic-offset: 8
395 * tab-width: 8
396 * indent-tabs-mode: t
397 * End:
398 *
399 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
400 * :indentSize=8:tabSize=8:noTabs=false:
401 */
Definition packet_info.h:43
Definition proto.h:907
Definition packet-smb.h:112
Definition packet-smb.h:304
Definition packet-smb.h:294
Definition packet-smb.h:277
Definition packet-smb.h:284
Definition packet-smb.h:271
Definition packet-smb.h:317
Extended metadata for a value_string array.
Definition value_string.h:325
Mapping between a 32-bit integer value and its string representation.
Definition value_string.h:33
Definition wmem_allocator.h:27
Definition wmem_tree-int.h:48
Definition packet-smb.h:216
Definition nstime.h:26
Definition packet-smb.h:244
Definition packet-smb.h:130
Definition packet-smb.h:170
Definition packet-smb.h:138
Definition packet-smb.h:191
Definition tvbuff-int.h:35