• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2003-2016 CORE Security Technologies
2#
3# This software is provided under under a slightly modified version
4# of the Apache Software License. See the accompanying LICENSE file
5# for more information.
6#
7# Author: Alberto Solino (@agsolino)
8#
9# Description:
10#   SMB 2 and 3 Protocol Structures and constants [MS-SMB2]
11#
12
13from impacket.structure import Structure
14
15# Constants
16
17# SMB Packet
18SMB2_PACKET_SIZE     = 64
19
20# SMB Commands
21SMB2_NEGOTIATE       = 0x0000 #
22SMB2_SESSION_SETUP   = 0x0001 #
23SMB2_LOGOFF          = 0x0002 #
24SMB2_TREE_CONNECT    = 0x0003 #
25SMB2_TREE_DISCONNECT = 0x0004 #
26SMB2_CREATE          = 0x0005 #
27SMB2_CLOSE           = 0x0006 #
28SMB2_FLUSH           = 0x0007 #
29SMB2_READ            = 0x0008 #
30SMB2_WRITE           = 0x0009 #
31SMB2_LOCK            = 0x000A #
32SMB2_IOCTL           = 0x000B #
33SMB2_CANCEL          = 0x000C #
34SMB2_ECHO            = 0x000D #
35SMB2_QUERY_DIRECTORY = 0x000E #
36SMB2_CHANGE_NOTIFY   = 0x000F
37SMB2_QUERY_INFO      = 0x0010 #
38SMB2_SET_INFO        = 0x0011
39SMB2_OPLOCK_BREAK    = 0x0012
40
41# SMB Flags
42SMB2_FLAGS_SERVER_TO_REDIR    = 0x00000001
43SMB2_FLAGS_ASYNC_COMMAND      = 0x00000002
44SMB2_FLAGS_RELATED_OPERATIONS = 0x00000004
45SMB2_FLAGS_SIGNED             = 0x00000008
46SMB2_FLAGS_DFS_OPERATIONS     = 0x10000000
47SMB2_FLAGS_REPLAY_OPERATION   = 0x80000000
48
49# SMB Error SymLink Flags
50SYMLINK_FLAG_ABSOLUTE         = 0x0
51SYMLINK_FLAG_RELATIVE         = 0x1
52
53# SMB2_NEGOTIATE
54# Security Modes
55SMB2_NEGOTIATE_SIGNING_ENABLED  = 0x1
56SMB2_NEGOTIATE_SIGNING_REQUIRED = 0x2
57
58# Capabilities
59SMB2_GLOBAL_CAP_DFS                = 0x01
60SMB2_GLOBAL_CAP_LEASING            = 0x02
61SMB2_GLOBAL_CAP_LARGE_MTU          = 0x04
62SMB2_GLOBAL_CAP_MULTI_CHANNEL      = 0x08
63SMB2_GLOBAL_CAP_PERSISTENT_HANDLES = 0x10
64SMB2_GLOBAL_CAP_DIRECTORY_LEASING  = 0x20
65SMB2_GLOBAL_CAP_ENCRYPTION         = 0x40
66
67# Dialects
68SMB2_DIALECT_002      = 0x0202
69SMB2_DIALECT_21       = 0x0210
70SMB2_DIALECT_30       = 0x0300
71SMB2_DIALECT_WILDCARD = 0x02FF
72
73# SMB2_SESSION_SETUP
74# Flags
75SMB2_SESSION_FLAG_BINDING        = 0x01
76SMB2_SESSION_FLAG_IS_GUEST       = 0x01
77SMB2_SESSION_FLAG_IS_NULL        = 0x02
78SMB2_SESSION_FLAG_ENCRYPT_DATA   = 0x04
79
80# SMB2_TREE_CONNECT
81# Types
82SMB2_SHARE_TYPE_DISK   = 0x1
83SMB2_SHARE_TYPE_PIPE   = 0x2
84SMB2_SHARE_TYPE_PRINT  = 0x3
85
86# Share Flags
87SMB2_SHAREFLAG_MANUAL_CACHING              = 0x00000000
88SMB2_SHAREFLAG_AUTO_CACHING                = 0x00000010
89SMB2_SHAREFLAG_VDO_CACHING                 = 0x00000020
90SMB2_SHAREFLAG_NO_CACHING                  = 0x00000030
91SMB2_SHAREFLAG_DFS                         = 0x00000001
92SMB2_SHAREFLAG_DFS_ROOT                    = 0x00000002
93SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS    = 0x00000100
94SMB2_SHAREFLAG_FORCE_SHARED_DELETE         = 0x00000200
95SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING     = 0x00000400
96SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM = 0x00000800
97SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK        = 0x00001000
98SMB2_SHAREFLAG_ENABLE_HASH_V1              = 0x00002000
99SMB2_SHAREFLAG_ENABLE_HASH_V2              = 0x00004000
100SMB2_SHAREFLAG_ENCRYPT_DATA                = 0x00008000
101
102# Capabilities
103SMB2_SHARE_CAP_DFS                         = 0x00000008
104SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY     = 0x00000010
105SMB2_SHARE_CAP_SCALEOUT                    = 0x00000020
106SMB2_SHARE_CAP_CLUSTER                     = 0x00000040
107
108# SMB_CREATE
109# Oplocks
110SMB2_OPLOCK_LEVEL_NONE       = 0x00
111SMB2_OPLOCK_LEVEL_II         = 0x01
112SMB2_OPLOCK_LEVEL_EXCLUSIVE  = 0x08
113SMB2_OPLOCK_LEVEL_BATCH      = 0x09
114SMB2_OPLOCK_LEVEL_LEASE      = 0xFF
115
116# Impersonation Level
117SMB2_IL_ANONYMOUS       = 0x00000000
118SMB2_IL_IDENTIFICATION  = 0x00000001
119SMB2_IL_IMPERSONATION   = 0x00000002
120SMB2_IL_DELEGATE        = 0x00000003
121
122# File Attributes
123FILE_ATTRIBUTE_ARCHIVE             = 0x00000020
124FILE_ATTRIBUTE_COMPRESSED          = 0x00000800
125FILE_ATTRIBUTE_DIRECTORY           = 0x00000010
126FILE_ATTRIBUTE_ENCRYPTED           = 0x00004000
127FILE_ATTRIBUTE_HIDDEN              = 0x00000002
128FILE_ATTRIBUTE_NORMAL              = 0x00000080
129FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000
130FILE_ATTRIBUTE_OFFLINE             = 0x00001000
131FILE_ATTRIBUTE_READONLY            = 0x00000001
132FILE_ATTRIBUTE_REPARSE_POINT       = 0x00000400
133FILE_ATTRIBUTE_SPARSE_FILE         = 0x00000200
134FILE_ATTRIBUTE_SYSTEM              = 0x00000004
135FILE_ATTRIBUTE_TEMPORARY           = 0x00000100
136FILE_ATTRIBUTE_INTEGRITY_STREAM    = 0x00000800
137FILE_ATTRIBUTE_NO_SCRUB_DATA       = 0x00020000
138
139# Share Access
140FILE_SHARE_READ         = 0x00000001
141FILE_SHARE_WRITE        = 0x00000002
142FILE_SHARE_DELETE       = 0x00000004
143
144# Create Disposition
145FILE_SUPERSEDE          = 0x00000000
146FILE_OPEN               = 0x00000001
147FILE_CREATE             = 0x00000002
148FILE_OPEN_IF            = 0x00000003
149FILE_OVERWRITE          = 0x00000004
150FILE_OVERWRITE_IF       = 0x00000005
151
152# Create Options
153FILE_DIRECTORY_FILE            = 0x00000001
154FILE_WRITE_THROUGH             = 0x00000002
155FILE_SEQUENTIAL_ONLY           = 0x00000004
156FILE_NO_INTERMEDIATE_BUFFERING = 0x00000008
157FILE_SYNCHRONOUS_IO_ALERT      = 0x00000010
158FILE_SYNCHRONOUS_IO_NONALERT   = 0x00000020
159FILE_NON_DIRECTORY_FILE        = 0x00000040
160FILE_COMPLETE_IF_OPLOCKED      = 0x00000100
161FILE_NO_EA_KNOWLEDGE           = 0x00000200
162FILE_RANDOM_ACCESS             = 0x00000800
163FILE_DELETE_ON_CLOSE           = 0x00001000
164FILE_OPEN_BY_FILE_ID           = 0x00002000
165FILE_OPEN_FOR_BACKUP_INTENT    = 0x00004000
166FILE_NO_COMPRESSION            = 0x00008000
167FILE_RESERVE_OPFILTER          = 0x00100000
168FILE_OPEN_REPARSE_POINT        = 0x00200000
169FILE_OPEN_NO_RECALL            = 0x00400000
170FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x00800000
171
172# File Access Mask / Desired Access
173FILE_READ_DATA         = 0x00000001
174FILE_WRITE_DATA        = 0x00000002
175FILE_APPEND_DATA       = 0x00000004
176FILE_READ_EA           = 0x00000008
177FILE_WRITE_EA          = 0x00000010
178FILE_EXECUTE           = 0x00000020
179FILE_READ_ATTRIBUTES   = 0x00000080
180FILE_WRITE_ATTRIBUTES  = 0x00000100
181DELETE                 = 0x00010000
182READ_CONTROL           = 0x00020000
183WRITE_DAC              = 0x00040000
184WRITE_OWNER            = 0x00080000
185SYNCHRONIZE            = 0x00100000
186ACCESS_SYSTEM_SECURITY = 0x01000000
187MAXIMUM_ALLOWED        = 0x02000000
188GENERIC_ALL            = 0x10000000
189GENERIC_EXECUTE        = 0x20000000
190GENERIC_WRITE          = 0x40000000
191GENERIC_READ           = 0x80000000
192
193# Directory Access Mask
194FILE_LIST_DIRECTORY    = 0x00000001
195FILE_ADD_FILE          = 0x00000002
196FILE_ADD_SUBDIRECTORY  = 0x00000004
197FILE_TRAVERSE          = 0x00000020
198FILE_DELETE_CHILD      = 0x00000040
199
200# Create Contexts
201SMB2_CREATE_EA_BUFFER                     = 0x45787441
202SMB2_CREATE_SD_BUFFER                     = 0x53656344
203SMB2_CREATE_DURABLE_HANDLE_REQUEST        = 0x44486e51
204SMB2_CREATE_DURABLE_HANDLE_RECONNECT      = 0x44486e43
205SMB2_CREATE_ALLOCATION_SIZE               = 0x416c5369
206SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST  = 0x4d784163
207SMB2_CREATE_TIMEWARP_TOKEN                = 0x54577270
208SMB2_CREATE_QUERY_ON_DISK_ID              = 0x51466964
209SMB2_CREATE_REQUEST                       = 0x52714c73
210SMB2_CREATE_REQUEST_LEASE_V2              = 0x52714c73
211SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2     = 0x44483251
212SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2   = 0x44483243
213SMB2_CREATE_APP_INSTANCE_ID               = 0x45BCA66AEFA7F74A9008FA462E144D74
214
215# Flags
216SMB2_CREATE_FLAG_REPARSEPOINT  = 0x1
217FILE_NEED_EA                   = 0x80
218
219# CreateAction
220FILE_SUPERSEDED    = 0x00000000
221FILE_OPENED        = 0x00000001
222FILE_CREATED       = 0x00000002
223FILE_OVERWRITTEN   = 0x00000003
224
225# SMB2_CREATE_REQUEST_LEASE states
226SMB2_LEASE_NONE            = 0x00
227SMB2_LEASE_READ_CACHING    = 0x01
228SMB2_LEASE_HANDLE_CACHING  = 0x02
229SMB2_LEASE_WRITE_CACHING   = 0x04
230
231# SMB2_CREATE_REQUEST_LEASE_V2 Flags
232SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET = 0x4
233
234# SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 Flags
235SMB2_DHANDLE_FLAG_PERSISTENT = 0x02
236
237# SMB2_CLOSE
238# Flags
239SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB  = 0x0001
240
241# SMB2_READ
242# Channel
243SMB2_CHANNEL_NONE     = 0x00
244SMB2_CHANNEL_RDMA_V1  = 0x01
245
246# SMB2_WRITE
247# Flags
248SMB2_WRITEFLAG_WRITE_THROUGH = 0x01
249
250# Lease Break Notification
251SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED  = 0x01
252
253# SMB_LOCK
254# Flags
255SMB2_LOCKFLAG_SHARED_LOCK       = 0x01
256SMB2_LOCKFLAG_EXCLUSIVE_LOCK    = 0x02
257SMB2_LOCKFLAG_UNLOCK            = 0x04
258SMB2_LOCKFLAG_FAIL_IMMEDIATELY  = 0x10
259
260# SMB IOCTL
261# Control Codes
262FSCTL_DFS_GET_REFERRALS              = 0x00060194
263FSCTL_PIPE_PEEK                      = 0x0011400C
264FSCTL_PIPE_WAIT                      = 0x00110018
265FSCTL_PIPE_TRANSCEIVE                = 0x0011C017
266FSCTL_SRV_COPYCHUNK                  = 0x001440F2
267FSCTL_SRV_ENUMERATE_SNAPSHOTS        = 0x00144064
268FSCTL_SRV_REQUEST_RESUME_KEY         = 0x00140078
269FSCTL_SRV_READ_HASH                  = 0x001441bb
270FSCTL_SRV_COPYCHUNK_WRITE            = 0x001480F2
271FSCTL_LMR_REQUEST_RESILIENCY         = 0x001401D4
272FSCTL_QUERY_NETWORK_INTERFACE_INFO   = 0x001401FC
273FSCTL_SET_REPARSE_POINT              = 0x000900A4
274FSCTL_DFS_GET_REFERRALS_EX           = 0x000601B0
275FSCTL_FILE_LEVEL_TRIM                = 0x00098208
276FSCTL_VALIDATE_NEGOTIATE_INFO        = 0x00140204
277
278# Flags
279SMB2_0_IOCTL_IS_FSCTL  = 0x1
280
281# SRV_READ_HASH
282# Type
283SRV_HASH_TYPE_PEER_DIST  = 0x01
284
285# Version
286SRV_HASH_VER_1  = 0x1
287SRV_HASH_VER_2  = 0x2
288
289# Retrieval Type
290SRV_HASH_RETRIEVE_HASH_BASED  = 0x01
291SRV_HASH_RETRIEVE_FILE_BASED  = 0x02
292
293# NETWORK_INTERFACE_INFO
294# Capabilities
295RSS_CAPABLE  = 0x01
296RDMA_CAPABLE = 0x02
297
298# SMB2_QUERY_DIRECTORIES
299# Information Class
300FILE_DIRECTORY_INFORMATION         = 0x01
301FILE_FULL_DIRECTORY_INFORMATION    = 0x02
302FILEID_FULL_DIRECTORY_INFORMATION  = 0x26
303FILE_BOTH_DIRECTORY_INFORMATION    = 0x03
304FILEID_BOTH_DIRECTORY_INFORMATION  = 0x25
305FILENAMES_INFORMATION              = 0x0C
306
307# Flags
308SMB2_RESTART_SCANS        = 0x01
309SMB2_RETURN_SINGLE_ENTRY  = 0x02
310SMB2_INDEX_SPECIFIED      = 0x04
311SMB2_REOPEN               = 0x10
312
313# SMB2_CHANGE_NOTIFY
314# Flags
315SMB2_WATCH_TREE  = 0x01
316
317# Filters
318FILE_NOTIFY_CHANGE_FILE_NAME     = 0x00000001
319FILE_NOTIFY_CHANGE_DIR_NAME      = 0x00000002
320FILE_NOTIFY_CHANGE_ATTRIBUTES    = 0x00000004
321FILE_NOTIFY_CHANGE_SIZE          = 0x00000008
322FILE_NOTIFY_CHANGE_LAST_WRITE    = 0x00000010
323FILE_NOTIFY_CHANGE_LAST_ACCESS   = 0x00000020
324FILE_NOTIFY_CHANGE_CREATION      = 0x00000040
325FILE_NOTIFY_CHANGE_EA            = 0x00000080
326FILE_NOTIFY_CHANGE_SECURITY      = 0x00000100
327FILE_NOTIFY_CHANGE_STREAM_NAME   = 0x00000200
328FILE_NOTIFY_CHANGE_STREAM_SIZE   = 0x00000400
329FILE_NOTIFY_CHANGE_STREAM_WRITE  = 0x00000800
330
331# FILE_NOTIFY_INFORMATION
332# Actions
333FILE_ACTION_ADDED            = 0x00000001
334FILE_ACTION_REMOVED          = 0x00000002
335FILE_ACTION_MODIFIED         = 0x00000003
336FILE_ACTION_RENAMED_OLD_NAME = 0x00000004
337FILE_ACTION_RENAMED_NEW_NAME = 0x00000005
338
339# SMB2_QUERY_INFO
340# InfoTypes
341SMB2_0_INFO_FILE        = 0x01
342SMB2_0_INFO_FILESYSTEM  = 0x02
343SMB2_0_INFO_SECURITY    = 0x03
344SMB2_0_INFO_QUOTA       = 0x04
345
346# File Information Classes
347SMB2_FILE_ACCESS_INFO                 = 8
348SMB2_FILE_ALIGNMENT_INFO              = 17
349SMB2_FILE_ALL_INFO                    = 18
350SMB2_FILE_ALLOCATION_INFO             = 19
351SMB2_FILE_ALTERNATE_NAME_INFO         = 21
352SMB2_ATTRIBUTE_TAG_INFO               = 35
353SMB2_FILE_BASIC_INFO                  = 4
354SMB2_FILE_BOTH_DIRECTORY_INFO         = 3
355SMB2_FILE_COMPRESSION_INFO            = 28
356SMB2_FILE_DIRECTORY_INFO              = 1
357SMB2_FILE_DISPOSITION_INFO            = 13
358SMB2_FILE_EA_INFO                     = 7
359SMB2_FILE_END_OF_FILE_INFO            = 20
360SMB2_FULL_DIRECTORY_INFO              = 2
361SMB2_FULL_EA_INFO                     = 15
362SMB2_FILE_HARDLINK_INFO               = 46
363SMB2_FILE_ID_BOTH_DIRECTORY_INFO      = 37
364SMB2_FILE_ID_FULL_DIRECTORY_INFO      = 38
365SMB2_FILE_ID_GLOBAL_TX_DIRECTORY_INFO = 50
366SMB2_FILE_INTERNAL_INFO               = 6
367SMB2_FILE_LINK_INFO                   = 11
368SMB2_FILE_MAILSLOT_QUERY_INFO         = 26
369SMB2_FILE_MAILSLOT_SET_INFO           = 27
370SMB2_FILE_MODE_INFO                   = 16
371SMB2_FILE_MOVE_CLUSTER_INFO           = 31
372SMB2_FILE_NAME_INFO                   = 9
373SMB2_FILE_NAMES_INFO                  = 12
374SMB2_FILE_NETWORK_OPEN_INFO           = 34
375SMB2_FILE_NORMALIZED_NAME_INFO        = 48
376SMB2_FILE_OBJECT_ID_INFO              = 29
377SMB2_FILE_PIPE_INFO                   = 23
378SMB2_FILE_PIPE_LOCAL_INFO             = 24
379SMB2_FILE_PIPE_REMOTE_INFO            = 25
380SMB2_FILE_POSITION_INFO               = 14
381SMB2_FILE_QUOTA_INFO                  = 32
382SMB2_FILE_RENAME_INFO                 = 10
383SMB2_FILE_REPARSE_POINT_INFO          = 33
384SMB2_FILE_SFIO_RESERVE_INFO           = 44
385SMB2_FILE_SHORT_NAME_INFO             = 45
386SMB2_FILE_STANDARD_INFO               = 5
387SMB2_FILE_STANDARD_LINK_INFO          = 54
388SMB2_FILE_STREAM_INFO                 = 22
389SMB2_FILE_TRACKING_INFO               = 36
390SMB2_FILE_VALID_DATA_LENGTH_INFO      = 39
391
392# File System Information Classes
393SMB2_FILESYSTEM_VOLUME_INFO           = 1
394SMB2_FILESYSTEM_LABEL_INFO            = 2
395SMB2_FILESYSTEM_SIZE_INFO             = 3
396SMB2_FILESYSTEM_DEVICE_INFO           = 4
397SMB2_FILESYSTEM_ATTRIBUTE_INFO        = 5
398SMB2_FILESYSTEM_CONTROL_INFO          = 6
399SMB2_FILESYSTEM_FULL_SIZE_INFO        = 7
400SMB2_FILESYSTEM_OBJECT_ID_INFO        = 8
401SMB2_FILESYSTEM_DRIVER_PATH_INFO      = 9
402SMB2_FILESYSTEM_SECTOR_SIZE_INFO      = 11
403
404# Additional information
405OWNER_SECURITY_INFORMATION  = 0x00000001
406GROUP_SECURITY_INFORMATION  = 0x00000002
407DACL_SECURITY_INFORMATION   = 0x00000004
408SACL_SECURITY_INFORMATION   = 0x00000008
409LABEL_SECURITY_INFORMATION  = 0x00000010
410
411# Flags
412SL_RESTART_SCAN         = 0x00000001
413SL_RETURN_SINGLE_ENTRY  = 0x00000002
414SL_INDEX_SPECIFIED      = 0x00000004
415
416# TRANSFORM_HEADER
417SMB2_ENCRYPTION_AES128_CCM = 0x0001
418
419
420# STRUCtures
421# Represents a SMB2/3 Packet
422class SMBPacketBase(Structure):
423    def addCommand(self,command):
424        # Pad to 8 bytes and put the offset of another SMBPacket
425        raise 'Implement This!'
426
427    def isValidAnswer(self, status):
428        if self['Status'] != status:
429            import smb3
430            raise smb3.SessionError(self['Status'], self)
431        return True
432
433    def __init__(self, data = None):
434        Structure.__init__(self,data)
435        if data is None:
436            self['TreeID'] = 0
437
438
439class SMB2PacketAsync(SMBPacketBase):
440    structure = (
441        ('ProtocolID','"\xfeSMB'),
442        ('StructureSize','<H=64'),
443        ('CreditCharge','<H=0'),
444        ('Status','<L=0'),
445        ('Command','<H=0'),
446        ('CreditRequestResponse','<H=0'),
447        ('Flags','<L=0'),
448        ('NextCommand','<L=0'),
449        ('MessageID','<Q=0'),
450        ('AsyncID','<Q=0'),
451        ('SessionID','<Q=0'),
452        ('Signature','16s=""'),
453        ('Data',':=""'),
454    )
455
456class SMB3PacketAsync(SMBPacketBase):
457    structure = (
458        ('ProtocolID','"\xfeSMB'),
459        ('StructureSize','<H=64'),
460        ('CreditCharge','<H=0'),
461        ('ChannelSequence','<H=0'),
462        ('Reserved','<H=0'),
463        ('Command','<H=0'),
464        ('CreditRequestResponse','<H=0'),
465        ('Flags','<L=0'),
466        ('NextCommand','<L=0'),
467        ('MessageID','<Q=0'),
468        ('AsyncID','<Q=0'),
469        ('SessionID','<Q=0'),
470        ('Signature','16s=""'),
471        ('Data',':=""'),
472    )
473
474class SMB2Packet(SMBPacketBase):
475    structure = (
476        ('ProtocolID','"\xfeSMB'),
477        ('StructureSize','<H=64'),
478        ('CreditCharge','<H=0'),
479        ('Status','<L=0'),
480        ('Command','<H=0'),
481        ('CreditRequestResponse','<H=0'),
482        ('Flags','<L=0'),
483        ('NextCommand','<L=0'),
484        ('MessageID','<Q=0'),
485        ('Reserved','<L=0'),
486        ('TreeID','<L=0'),
487        ('SessionID','<Q=0'),
488        ('Signature','16s=""'),
489        ('Data',':=""'),
490    )
491
492class SMB3Packet(SMBPacketBase):
493    structure = (
494        ('ProtocolID','"\xfeSMB'),
495        ('StructureSize','<H=64'),
496        ('CreditCharge','<H=0'),
497        ('ChannelSequence','<H=0'),
498        ('Reserved','<H=0'),
499        ('Command','<H=0'),
500        ('CreditRequestResponse','<H=0'),
501        ('Flags','<L=0'),
502        ('NextCommand','<L=0'),
503        ('MessageID','<Q=0'),
504        ('Reserved','<L=0'),
505        ('TreeID','<L=0'),
506        ('SessionID','<Q=0'),
507        ('Signature','16s=""'),
508        ('Data',':=""'),
509    )
510
511class SMB2Error(Structure):
512    structure = (
513        ('StructureSize','<H=9'),
514        ('Reserved','<H=0'),
515        ('ByteCount','<L=0'),
516        ('_ErrorData','_-ErrorData','self["ByteCount"]'),
517        ('ErrorData','"\xff'),
518    )
519
520class SMB2ErrorSymbolicLink(Structure):
521    structure = (
522        ('SymLinkLength','<L=0'),
523        ('SymLinkErrorTag','<L=0'),
524        ('ReparseTag','<L=0'),
525        ('ReparseDataLenght','<H=0'),
526        ('UnparsedPathLength','<H=0'),
527        ('SubstituteNameOffset','<H=0'),
528        ('SubstituteNameLength','<H=0'),
529        ('PrintNameOffset','<H=0'),
530        ('PrintNameLength','<H=0'),
531        ('Flags','<L=0'),
532        ('PathBuffer',':'),
533    )
534
535# SMB2_NEGOTIATE
536class SMB2Negotiate(Structure):
537    structure = (
538        ('StructureSize','<H=36'),
539        ('DialectCount','<H=0'),
540        ('SecurityMode','<H=0'),
541        ('Reserved','<H=0'),
542        ('Capabilities','<L=0'),
543        ('ClientGuid','16s=""'),
544        ('ClientStartTime','<Q=0'),
545        ('Dialects','*<H'),
546    )
547
548class SMB2Negotiate_Response(Structure):
549    structure = (
550        ('StructureSize','<H=65'),
551        ('SecurityMode','<H=0'),
552        ('DialectRevision','<H=0'),
553        ('Reserved','<H=0'),
554        ('ServerGuid','16s=""'),
555        ('Capabilities','<L=0'),
556        ('MaxTransactSize','<L=0'),
557        ('MaxReadSize','<L=0'),
558        ('MaxWriteSize','<L=0'),
559        ('SystemTime','<Q=0'),
560        ('ServerStartTime','<Q=0'),
561        ('SecurityBufferOffset','<H=0'),
562        ('SecurityBufferLength','<H=0'),
563        ('Reserved2','<L=0'),
564        ('_AlignPad','_-AlignPad','self["SecurityBufferOffset"] - (64 + self["StructureSize"] - 1)'),
565        ('AlignPad',':=""'),
566        ('_Buffer','_-Buffer','self["SecurityBufferLength"]'),
567        ('Buffer',':'),
568    )
569
570# SMB2_SESSION_SETUP
571class SMB2SessionSetup(Structure):
572    SIZE = 24
573    structure = (
574        ('StructureSize','<H=25'),
575        ('Flags','<B=0'),
576        ('SecurityMode','<B=0'),
577        ('Capabilities','<L=0'),
578        ('Channel','<L=0'),
579        ('SecurityBufferOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'),
580        ('SecurityBufferLength','<H=0'),
581        ('PreviousSessionId','<Q=0'),
582        ('_AlignPad','_-AlignPad','self["SecurityBufferOffset"] - (64 + self["StructureSize"] - 1)'),
583        ('AlignPad',':=""'),
584        ('_Buffer','_-Buffer','self["SecurityBufferLength"]'),
585        ('Buffer',':'),
586    )
587
588    def __init__(self, data = None):
589        Structure.__init__(self,data)
590        if data is None:
591            self['AlignPad'] = ''
592
593    def getData(self):
594        #self['AlignPad'] = '\x00' * ((8 - ((24 + SMB2_PACKET_SIZE) & 7)) & 7)
595        #self['SecurityBufferOffset'] = 24 + SMB2_PACKET_SIZE +len(self['AlignPad'])
596        #self['SecurityBufferLength'] += len(self['AlignPad'])
597        return Structure.getData(self)
598
599
600class SMB2SessionSetup_Response(Structure):
601    structure = (
602        ('StructureSize','<H=9'),
603        ('SessionFlags','<H=0'),
604        ('SecurityBufferOffset','<H=0'),
605        ('SecurityBufferLength','<H=0'),
606        ('_AlignPad','_-AlignPad','self["SecurityBufferOffset"] - (64 + self["StructureSize"] - 1)'),
607        ('AlignPad',':=""'),
608        ('_Buffer','_-Buffer','self["SecurityBufferLength"]'),
609        ('Buffer',':'),
610    )
611
612# SMB2_LOGOFF
613class SMB2Logoff(Structure):
614    structure = (
615        ('StructureSize','<H=4'),
616        ('Reserved','<H=0'),
617    )
618
619
620class SMB2Logoff_Response(Structure):
621    structure = (
622        ('StructureSize','<H=4'),
623        ('Reserved','<H=0'),
624    )
625
626# SMB2_TREE_CONNECT
627class SMB2TreeConnect(Structure):
628    SIZE = 8
629    structure = (
630        ('StructureSize','<H=9'),
631        ('Reserved','<H=0'),
632        ('PathOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'),
633        ('PathLength','<H=0'),
634        ('_AlignPad','_-AlignPad','self["PathOffset"] - (64 + self.SIZE - 1)'),
635        ('AlignPad',':=""'),
636        ('_Buffer','_-Buffer','self["PathLength"]'),
637        ('Buffer',':'),
638    )
639    def __init__(self, data = None):
640        Structure.__init__(self,data)
641        if data is None:
642            self['AlignPad'] = ''
643
644class SMB2TreeConnect_Response(Structure):
645    structure = (
646        ('StructureSize','<H=16'),
647        ('ShareType','<B=0'),
648        ('Reserved','<B=0'),
649        ('ShareFlags','<L=0'),
650        ('Capabilities','<L=0'),
651        ('MaximalAccess','<L=0'),
652    )
653
654# SMB2_TREE_DISCONNECT
655class SMB2TreeDisconnect(Structure):
656    structure = (
657        ('StructureSize','<H=4'),
658        ('Reserved','<H=0'),
659    )
660
661class SMB2TreeDisconnect_Response(Structure):
662    structure = (
663        ('StructureSize','<H=4'),
664        ('Reserved','<H=0'),
665    )
666
667# SMB2_CREATE
668class SMB2Create(Structure):
669    SIZE = 56
670    structure = (
671        ('StructureSize','<H=57'),
672        ('SecurityFlags','<B=0'),
673        ('RequestedOplockLevel','<B=0'),
674        ('ImpersonationLevel','<L=0'),
675        ('SmbCreateFlags','<Q=0'),
676        ('Reserved','<Q=0'),
677        ('DesiredAccess','<L=0'),
678        ('FileAttributes','<L=0'),
679        ('ShareAccess','<L=0'),
680        ('CreateDisposition','<L=0'),
681        ('CreateOptions','<L=0'),
682        ('NameOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'),
683        ('NameLength','<H=0'),
684        ('CreateContextsOffset','<L=0'),
685        ('CreateContextsLength','<L=0'),
686        ('_AlignPad','_-AlignPad','self["NameOffset"] - (64 + self["StructureSize"] - 1)'),
687        ('AlignPad',':=""'),
688        ('_Buffer','_-Buffer','self["CreateContextsLength"]+self["NameLength"]'),
689        ('Buffer',':'),
690    )
691    def __init__(self, data = None):
692        Structure.__init__(self,data)
693        if data is None:
694            self['AlignPad'] = ''
695
696class SMB2CreateContext(Structure):
697     structure = (
698         ('Next','<L=0'),
699         ('NameOffset','<H=0'),
700         ('NameLength','<H=0'),
701         ('Reserved','<H=0'),
702         ('DataOffset','<H=0'),
703         ('DataLength','<L=0'),
704         ('_Buffer','_-Buffer','self["DataLength"]+self["NameLength"]'),
705         ('Buffer',':'),
706     )
707
708class SMB2_FILEID(Structure):
709    structure = (
710        ('Persistent','<Q=0'),
711        ('Volatile','<Q=0'),
712    )
713
714class SMB2Create_Response(Structure):
715    structure = (
716        ('StructureSize','<H=89'),
717        ('OplockLevel','<B=0'),
718        ('Flags','<B=0'),
719        ('CreateAction','<L=0'),
720        ('CreationTime','<Q=0'),
721        ('LastAccessTime','<Q=0'),
722        ('LastWriteTime','<Q=0'),
723        ('ChangeTime','<Q=0'),
724        ('AllocationSize','<Q=0'),
725        ('EndOfFile','<Q=0'),
726        ('FileAttributes','<L=0'),
727        ('Reserved2','<L=0'),
728        ('FileID',':',SMB2_FILEID),
729        ('CreateContextsOffset','<L=0'),
730        ('CreateContextsLength','<L=0'),
731        ('_AlignPad','_-AlignPad','self["CreateContextsOffset"] - (64 + self["StructureSize"] - 1)'),
732        ('AlignPad',':=""'),
733        ('_Buffer','_-Buffer','self["CreateContextsLength"]'),
734        ('Buffer',':'),
735    )
736
737class FILE_FULL_EA_INFORMATION(Structure):
738    structure = (
739        ('NextEntryOffset','<L=0'),
740        ('Flags','<B=0'),
741        ('EaNameLength','<B=0'),
742        ('EaValueLength','<H=0'),
743        ('_EaName','_-EaName','self["EaNameLength"]'),
744        ('EaName',':'),
745        ('_EaValue','_-EaValue','self["EaValue"]'),
746        ('EaValue',':'),
747    )
748
749
750class SMB2_CREATE_DURABLE_HANDLE_RECONNECT(Structure):
751    structure = (
752        ('Data',':',SMB2_FILEID),
753    )
754
755class SMB2_CREATE_DURABLE_HANDLE_REQUEST(Structure):
756    structure = (
757        ('DurableRequest','16s=""'),
758    )
759
760class SMB2_CREATE_DURABLE_HANDLE_RESPONSE(Structure):
761    structure = (
762        ('Reserved','<Q=0'),
763    )
764
765class SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST(Structure):
766    structure = (
767        ('Timestamp','<Q=0'),
768    )
769
770class SMB2_CREATE_QUERY_MAXIMAL_ACCESS_RESPONSE(Structure):
771    structure = (
772        ('QueryStatus','<L=0'),
773        ('MaximalAccess','<L=0'),
774    )
775
776class SMB2_CREATE_ALLOCATION_SIZE(Structure):
777    structure = (
778        ('AllocationSize','<Q=0'),
779    )
780
781class SMB2_CREATE_TIMEWARP_TOKEN(Structure):
782    structure = (
783        ('AllocationSize','<Q=0'),
784    )
785
786class SMB2_CREATE_REQUEST_LEASE(Structure):
787    structure = (
788        ('LeaseKey','16s=""'),
789        ('LeaseState','<L=0'),
790        ('LeaseFlags','<L=0'),
791        ('LeaseDuration','<Q=0'),
792    )
793
794SMB2_CREATE_RESPONSE_LEASE = SMB2_CREATE_REQUEST_LEASE
795
796class SMB2_CREATE_REQUEST_LEASE_V2(Structure):
797    structure = (
798        ('LeaseKey','16s=""'),
799        ('LeaseState','<L=0'),
800        ('Flags','<L=0'),
801        ('LeaseDuration','<Q=0'),
802        ('ParentLeaseKey','16s=""'),
803        ('Epoch','<H=0'),
804        ('Reserved','<H=0'),
805    )
806
807SMB2_CREATE_RESPONSE_LEASE_V2 = SMB2_CREATE_REQUEST_LEASE_V2
808
809class SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2(Structure):
810    structure = (
811        ('Timeout','<L=0'),
812        ('Flags','<L=0'),
813        ('Reserved','8s=""'),
814        ('CreateGuid','16s=""'),
815    )
816
817class SMB2_CREATE_DURABLE_HANDLE_RESPONSE_V2(Structure):
818    structure = (
819        ('Timeout','<L=0'),
820        ('Flags','<L=0'),
821    )
822
823class SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2(Structure):
824    structure = (
825        ('FileID',':', SMB2_FILEID),
826        ('CreateGuid','16s=""'),
827        ('Flags','<L=0'),
828    )
829
830class SMB2_CREATE_APP_INSTANCE_ID(Structure):
831    structure = (
832        ('StructureSize','<H=0'),
833        ('Reserved','<H=0'),
834        ('AppInstanceId','16s=""'),
835    )
836
837class SMB2_CREATE_QUERY_ON_DISK_ID(Structure):
838    structure = (
839        ('DiskIDBuffer','32s=""'),
840    )
841
842# Todo: Add Classes for
843#SMB2_CREATE_SD_BUFFER
844
845# SMB2_CLOSE
846class SMB2Close(Structure):
847    structure = (
848        ('StructureSize','<H=24'),
849        ('Flags','<H=0'),
850        ('Reserved','<L=0'),
851        ('FileID',':', SMB2_FILEID),
852    )
853
854class SMB2Close_Response(Structure):
855    structure = (
856        ('StructureSize','<H=60'),
857        ('Flags','<H=0'),
858        ('Reserved','<L=0'),
859        ('CreationTime','<Q=0'),
860        ('LastAccessTime','<Q=0'),
861        ('LastWriteTime','<Q=0'),
862        ('ChangeTime','<Q=0'),
863        ('AllocationSize','<Q=0'),
864        ('EndofFile','<Q=0'),
865        ('FileAttributes','<L=0'),
866    )
867
868# SMB2_FLUSH
869class SMB2Flush(Structure):
870    structure = (
871        ('StructureSize','<H=24'),
872        ('Reserved1','<H=0'),
873        ('Reserved2','<L=0'),
874        ('FileID',':',SMB2_FILEID),
875    )
876
877class SMB2Flush_Response(Structure):
878    structure = (
879        ('StructureSize','<H=4'),
880        ('Reserved','<H=0'),
881    )
882
883# SMB2_READ
884class SMB2Read(Structure):
885    SIZE = 48
886    structure = (
887        ('StructureSize','<H=49'),
888        ('Padding','<B=0'),
889        ('Reserved','<B=0'),
890        ('Length','<L=0'),
891        ('Offset','<Q=0'),
892        ('FileID',':',SMB2_FILEID),
893        ('MinimumCount','<L=0'),
894        ('Channel','<L=0'),
895        ('RemainingBytes','<L=0'),
896        ('ReadChannelInfoOffset','<H=0'),
897        ('ReadChannelInfoLength','<H=0'),
898        ('_AlignPad','_-AlignPad','self["ReadChannelInfoOffset"] - (64 + self["StructureSize"] - 1)'),
899        ('AlignPad',':=""'),
900        ('_Buffer','_-Buffer','self["ReadChannelInfoLength"]'),
901        ('Buffer',':=0'),
902    )
903    def __init__(self, data = None):
904        Structure.__init__(self,data)
905        if data is None:
906            self['AlignPad'] = ''
907
908
909class SMB2Read_Response(Structure):
910    structure = (
911        ('StructureSize','<H=17'),
912        ('DataOffset','<B=0'),
913        ('Reserved','<B=0'),
914        ('DataLength','<L=0'),
915        ('DataRemaining','<L=0'),
916        ('Reserved2','<L=0'),
917        ('_AlignPad','_-AlignPad','self["DataOffset"] - (64 + self["StructureSize"] - 1)'),
918        ('AlignPad',':=""'),
919        ('_Buffer','_-Buffer','self["DataLength"]'),
920        ('Buffer',':'),
921    )
922
923# SMB2_WRITE
924class SMB2Write(Structure):
925    SIZE = 48
926    structure = (
927        ('StructureSize','<H=49'),
928        ('DataOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'),
929        ('Length','<L=0'),
930        ('Offset','<Q=0'),
931        ('FileID',':',SMB2_FILEID),
932        ('Channel','<L=0'),
933        ('RemainingBytes','<L=0'),
934        ('WriteChannelInfoOffset','<H=0'),
935        ('WriteChannelInfoLength','<H=0'),
936        ('_AlignPad','_-AlignPad','self["DataOffset"] + self["WriteChannelInfoOffset"] - (64 + self["StructureSize"] - 1)'),
937        ('AlignPad',':=""'),
938        ('Flags','<L=0'),
939        ('_Buffer','_-Buffer','self["Length"]+self["WriteChannelInfoLength"]'),
940        ('Buffer',':'),
941    )
942    def __init__(self, data = None):
943        Structure.__init__(self,data)
944        if data is None:
945            self['AlignPad'] = ''
946
947
948class SMB2Write_Response(Structure):
949    structure = (
950        ('StructureSize','<H=17'),
951        ('Reserved','<H=0'),
952        ('Count','<L=0'),
953        ('Remaining','<L=0'),
954        ('WriteChannelInfoOffset','<H=0'),
955        ('WriteChannelInfoLength','<H=0'),
956    )
957
958class SMB2OplockBreakNotification(Structure):
959    structure = (
960        ('StructureSize','<H=24'),
961        ('OplockLevel','<B=0'),
962        ('Reserved','<B=0'),
963        ('Reserved2','<L=0'),
964        ('FileID',':',SMB2_FILEID),
965    )
966
967SMB2OplockBreakAcknowledgment = SMB2OplockBreakNotification
968SMB2OplockBreakResponse       = SMB2OplockBreakNotification
969
970class SMB2LeaseBreakNotification(Structure):
971    structure = (
972        ('StructureSize','<H=44'),
973        ('NewEpoch','<H=0'),
974        ('Flags','<L=0'),
975        ('LeaseKey','16s=""'),
976        ('CurrentLeaseState','<L=0'),
977        ('NewLeaseState','<L=0'),
978        ('BreakReason','<L=0'),
979        ('AccessMaskHint','<L=0'),
980        ('ShareMaskHint','<L=0'),
981    )
982
983class SMB2LeaseBreakAcknowledgement(Structure):
984    structure = (
985        ('StructureSize','<H=36'),
986        ('Reserved','<H=0'),
987        ('Flags','<L=0'),
988        ('LeaseKey','16s=""'),
989        ('LeaseState','<L=0'),
990        ('LeaseDuration','<Q=0'),
991    )
992
993SMB2LeaseBreakResponse = SMB2LeaseBreakAcknowledgement
994
995# SMB2_LOCK
996class SMB2_LOCK_ELEMENT(Structure):
997    structure = (
998        ('Offset','<Q=0'),
999        ('Length','<Q=0'),
1000        ('Flags','<L=0'),
1001        ('Reserved','<L=0'),
1002    )
1003
1004class SMB2Lock(Structure):
1005    structure = (
1006        ('StructureSize','<H=48'),
1007        ('LockCount','<H=0'),
1008        ('LockSequence','<L=0'),
1009        ('FileID',':',SMB2_FILEID),
1010        ('_Locks','_-Locks','self["LockCount"]*24'),
1011        ('Locks',':'),
1012    )
1013
1014class SMB2Lock_Response(Structure):
1015    structure = (
1016        ('StructureSize','<H=4'),
1017        ('Reserved','<H=0'),
1018    )
1019
1020
1021# SMB2_ECHO
1022class SMB2Echo(Structure):
1023    structure = (
1024        ('StructureSize','<H=4'),
1025        ('Reserved','<H=0'),
1026    )
1027
1028SMB2Echo_Response = SMB2Echo
1029
1030# SMB2_CANCEL`
1031class SMB2Cancel(Structure):
1032    structure = (
1033        ('StructureSize','<H=4'),
1034        ('Reserved','<H=0'),
1035    )
1036
1037# SMB2_IOCTL
1038class SMB2Ioctl(Structure):
1039    SIZE = 56
1040    structure = (
1041        ('StructureSize','<H=57'),
1042        ('Reserved','<H=0'),
1043        ('CtlCode','<L=0'),
1044        ('FileID',':',SMB2_FILEID),
1045        ('InputOffset','<L=(self.SIZE + 64 + len(self["AlignPad"]))'),
1046        ('InputCount','<L=0'),
1047        ('MaxInputResponse','<L=0'),
1048        ('OutputOffset','<L=(self.SIZE + 64 + len(self["AlignPad"]) + self["InputCount"])'),
1049        ('OutputCount','<L=0'),
1050        ('MaxOutputResponse','<L=0'),
1051        ('Flags','<L=0'),
1052        ('Reserved2','<L=0'),
1053        #('_AlignPad','_-AlignPad','self["InputOffset"] + self["OutputOffset"] - (64 + self["StructureSize"] - 1)'),
1054        #('AlignPad',':=""'),
1055        ('_Buffer','_-Buffer','self["InputCount"]+self["OutputCount"]'),
1056        ('Buffer',':'),
1057    )
1058    def __init__(self, data = None):
1059        Structure.__init__(self,data)
1060        if data is None:
1061            self['AlignPad'] = ''
1062
1063class FSCTL_PIPE_WAIT_STRUCTURE(Structure):
1064    structure = (
1065        ('Timeout','<q=0'),
1066        ('NameLength','<L=0'),
1067        ('TimeoutSpecified','<B=0'),
1068        ('Padding','<B=0'),
1069        ('_Name','_-Name','self["NameLength"]'),
1070        ('Name',':'),
1071    )
1072
1073class SRV_COPYCHUNK_COPY(Structure):
1074    structure = (
1075        ('SourceKey','24s=""'),
1076        ('ChunkCount','<L=0'),
1077        ('Reserved','<L=0'),
1078        ('_Chunks','_-Chunks', 'self["ChunkCount"]*len(SRV_COPYCHUNK)'),
1079        ('Chunks',':'),
1080    )
1081
1082class SRV_COPYCHUNK(Structure):
1083    structure = (
1084        ('SourceOffset','<Q=0'),
1085        ('TargetOffset','<Q=0'),
1086        ('Length','<L=0'),
1087        ('Reserved','<L=0'),
1088    )
1089
1090class SRV_COPYCHUNK_RESPONSE(Structure):
1091    structure = (
1092        ('ChunksWritten','<L=0'),
1093        ('ChunkBytesWritten','<L=0'),
1094        ('TotalBytesWritten','<L=0'),
1095    )
1096
1097class SRV_READ_HASH(Structure):
1098    structure = (
1099        ('HashType','<L=0'),
1100        ('HashVersion','<L=0'),
1101        ('HashRetrievalType','<L=0'),
1102        ('Length','<L=0'),
1103        ('Offset','<Q=0'),
1104    )
1105
1106class NETWORK_RESILIENCY_REQUEST(Structure):
1107    structure = (
1108        ('Timeout','<L=0'),
1109        ('Reserved','<L=0'),
1110    )
1111
1112class VALIDATE_NEGOTIATE_INFO(Structure):
1113    structure = (
1114        ('Capabilities','<L=0'),
1115        ('Guid','16s=""'),
1116        ('SecurityMode','<H=0'),
1117        #('DialectCount','<H=0'),
1118        ('Dialects','<H*<H'),
1119    )
1120
1121class SRV_SNAPSHOT_ARRAY(Structure):
1122    structure = (
1123        ('NumberOfSnapShots','<L=0'),
1124        ('NumberOfSnapShotsReturned','<L=0'),
1125        ('SnapShotArraySize','<L=0'),
1126        ('_SnapShots','_-SnapShots','self["SnapShotArraySize"]'),
1127        ('SnapShots',':'),
1128    )
1129
1130class SRV_REQUEST_RESUME_KEY(Structure):
1131    structure = (
1132        ('ResumeKey','24s=""'),
1133        ('ContextLength','<L=0'),
1134        ('_Context','_-Context','self["ContextLength"]'),
1135        ('Context',':'),
1136    )
1137
1138class HASH_HEADER(Structure):
1139    structure = (
1140        ('HashType','<L=0'),
1141        ('HashVersion','<L=0'),
1142        ('SourceFileChangeTime','<Q=0'),
1143        ('SourceFileSize','<Q=0'),
1144        ('HashBlobLength','<L=0'),
1145        ('HashBlobOffset','<L=0'),
1146        ('Dirty','<H=0'),
1147        ('SourceFileNameLength','<L=0'),
1148        ('_SourceFileName','_-SourceFileName','self["SourceFileNameLength"]',),
1149        ('SourceFileName',':'),
1150    )
1151
1152class SRV_HASH_RETRIEVE_HASH_BASED(Structure):
1153    structure = (
1154        ('Offset','<Q=0'),
1155        ('BufferLength','<L=0'),
1156        ('Reserved','<L=0'),
1157        ('_Buffer','_-Buffer','self["BufferLength"]'),
1158        ('Buffer',':'),
1159    )
1160
1161class SRV_HASH_RETRIEVE_FILE_BASED(Structure):
1162    structure = (
1163        ('FileDataOffset','<Q=0'),
1164        ('FileDataLength','<Q=0'),
1165        ('BufferLength','<L=0'),
1166        ('Reserved','<L=0'),
1167        ('_Buffer','_-Buffer','self["BufferLength"]'),
1168        ('Buffer',':'),
1169    )
1170
1171class NETWORK_INTERFACE_INFO(Structure):
1172    structure = (
1173        ('Next','<L=0'),
1174        ('IfIndex','<L=0'),
1175        ('Capability','<L=0'),
1176        ('Reserved','<L=0'),
1177        ('LinkSpeed','<Q=0'),
1178        ('SockAddr_Storage','128s=""'),
1179    )
1180
1181class SMB2Ioctl_Response(Structure):
1182    structure = (
1183        ('StructureSize','<H=49'),
1184        ('Reserved','<H=0'),
1185        ('CtlCode','<L=0'),
1186        ('FileID',':',SMB2_FILEID),
1187        ('InputOffset','<L=0'),
1188        ('InputCount','<L=0'),
1189        ('OutputOffset','<L=0'),
1190        ('OutputCount','<L=0'),
1191        ('Flags','<L=0'),
1192        ('Reserved2','<L=0'),
1193        ('_AlignPad','_-AlignPad','self["OutputOffset"] - (64 + self["StructureSize"] - 1)'),
1194        ('AlignPad',':=""'),
1195        ('_Buffer','_-Buffer','self["InputCount"]+self["OutputCount"]'),
1196        ('Buffer',':'),
1197    )
1198
1199# SMB2_QUERY_DIRECTORY
1200class SMB2QueryDirectory(Structure):
1201    SIZE = 32
1202    structure = (
1203        ('StructureSize','<H=33'),
1204        ('FileInformationClass','<B=0'),
1205        ('Flags','<B=0'),
1206        ('FileIndex','<L=0'),
1207        ('FileID',':',SMB2_FILEID),
1208        ('FileNameOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'),
1209        ('FileNameLength','<H=0'),
1210        ('OutputBufferLength','<L=0'),
1211        ('_AlignPad','_-AlignPad','self["FileNameOffset"] - (64 + self["StructureSize"] - 1)'),
1212        ('AlignPad',':=""'),
1213        ('_Buffer','_-Buffer','self["FileNameLength"]'),
1214        ('Buffer',':'),
1215    )
1216    def __init__(self, data = None):
1217        Structure.__init__(self,data)
1218        if data is None:
1219            self['AlignPad'] = ''
1220
1221class SMB2QueryDirectory_Response(Structure):
1222    structure = (
1223        ('StructureSize','<H=9'),
1224        ('OutputBufferOffset','<H=0'),
1225        ('OutputBufferLength','<L=0'),
1226        ('_AlignPad','_-AlignPad','self["OutputBufferOffset"] - (64 + self["StructureSize"] - 1)'),
1227        ('AlignPad',':=""'),
1228        ('_Buffer','_-Buffer','self["OutputBufferLength"]'),
1229        ('Buffer',':'),
1230    )
1231
1232# SMB2_CHANGE_NOTIFY
1233class SMB2ChangeNotify(Structure):
1234    structure = (
1235        ('StructureSize','<H=32'),
1236        ('Flags','<H=0'),
1237        ('OutputBufferLength','<L=0'),
1238        ('FileID',':',SMB2_FILEID),
1239        ('CompletionFilter','<L=0'),
1240        ('Reserved','<L=0'),
1241    )
1242
1243class SMB2ChangeNotify_Response(Structure):
1244    structure = (
1245        ('StructureSize','<H=9'),
1246        ('OutputBufferOffset','<H=0'),
1247        ('OutputBufferLength','<L=0'),
1248        ('_AlignPad','_-AlignPad','self["OutputBufferOffset"] - (64 + self["StructureSize"] - 1)'),
1249        ('AlignPad',':=""'),
1250        ('_Buffer','_-Buffer','self["OutputBufferLength"]'),
1251        ('Buffer',':'),
1252    )
1253
1254class FILE_NOTIFY_INFORMATION(Structure):
1255    structure = (
1256        ('NextEntryOffset','<L=0'),
1257        ('Action','<L=0'),
1258        ('FileNameLength','<L=0'),
1259        ('_FileName','_-FileName','self["FileNameLength"]',),
1260        ('FileName',':'),
1261    )
1262
1263# SMB2_QUERY_INFO
1264class SMB2QueryInfo(Structure):
1265    SIZE = 40
1266    structure = (
1267       ('StructureSize','<H=41'),
1268       ('InfoType','<B=0'),
1269       ('FileInfoClass','<B=0'),
1270       ('OutputBufferLength','<L=0'),
1271       ('InputBufferOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'),
1272       ('Reserved','<H=0'),
1273       ('InputBufferLength','<L=0'),
1274       ('AdditionalInformation','<L=0'),
1275       ('Flags','<L=0'),
1276       ('FileID',':',SMB2_FILEID),
1277       ('_AlignPad','_-AlignPad','self["InputBufferOffset"] - (64 + self["StructureSize"] - 1)'),
1278       ('AlignPad',':=""'),
1279       ('_Buffer','_-Buffer','self["InputBufferLength"]'),
1280       ('Buffer',':'),
1281    )
1282    def __init__(self, data = None):
1283        Structure.__init__(self,data)
1284        if data is None:
1285            self['AlignPad'] = ''
1286
1287
1288class SMB2_QUERY_QUOTA_INFO(Structure):
1289    structure = (
1290        ('ReturnSingle','<B=0'),
1291        ('RestartScan','<B=0'),
1292        ('Reserved','<H=0'),
1293        ('SidListLength','<L=0'),
1294        ('StartSidLength','<L=0'),
1295        ('StartSidOffset','<L=0'),
1296        # ToDo: Check 2.2.37.1 here
1297        ('SidBuffer',':'),
1298    )
1299
1300class SMB2QueryInfo_Response(Structure):
1301   structure = (
1302       ('StructureSize','<H=9'),
1303       ('OutputBufferOffset','<H=0'),
1304       ('OutputBufferLength','<L=0'),
1305       ('_AlignPad','_-AlignPad','self["OutputBufferOffset"] - (64 + self["StructureSize"] - 1)'),
1306       ('AlignPad',':=""'),
1307       ('_Buffer','_-Buffer','self["OutputBufferLength"]'),
1308       ('Buffer',':'),
1309   )
1310
1311# SMB2_SET_INFO
1312class SMB2SetInfo(Structure):
1313    SIZE = 32
1314    structure = (
1315       ('StructureSize','<H=33'),
1316       ('InfoType','<B=0'),
1317       ('FileInfoClass','<B=0'),
1318       ('BufferLength','<L=0'),
1319       ('BufferOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'),
1320       ('Reserved','<H=0'),
1321       ('AdditionalInformation','<L=0'),
1322       ('FileID',':',SMB2_FILEID),
1323       ('_AlignPad','_-AlignPad','self["BufferOffset"] - (64 + self["StructureSize"] - 1)'),
1324       ('AlignPad',':=""'),
1325       ('_Buffer','_-Buffer','self["BufferLength"]'),
1326       ('Buffer',':'),
1327    )
1328    def __init__(self, data = None):
1329        Structure.__init__(self,data)
1330        if data is None:
1331            self['AlignPad'] = ''
1332
1333class SMB2SetInfo_Response(Structure):
1334    structure = (
1335       ('StructureSize','<H=2'),
1336    )
1337
1338class FILE_RENAME_INFORMATION_TYPE_2(Structure):
1339    structure = (
1340        ('ReplaceIfExists','<B=0'),
1341        ('Reserved','7s=""'),
1342        ('RootDirectory','<Q=0'),
1343        ('FileNameLength','<L=0'),
1344        ('_FileName','_-FileName','self["FileNameLength"]'),
1345        ('FileName',':'),
1346    )
1347
1348class SMB2_TRANSFORM_HEADER(Structure):
1349    structure = (
1350        ('ProtocolID','"\xfdSMB'),
1351        ('Signature','16s=""'),
1352        ('Nonce','16s=""'),
1353        ('OriginalMessageSize','<L=0'),
1354        ('Reserved','<H=0'),
1355        ('EncryptionAlgorithm','<H=0'),
1356        ('SessionID','<Q=0'),
1357    )
1358
1359# SMB2_FILE_INTERNAL_INFO
1360class FileInternalInformation(Structure):
1361    structure = (
1362        ('IndexNumber','<q=0'),
1363    )
1364