Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# Impacket - Collection of Python classes for working with network protocols. 

2# 

3# SECUREAUTH LABS. Copyright (C) 2020 SecureAuth Corporation. All rights reserved. 

4# 

5# This software is provided under a slightly modified version 

6# of the Apache Software License. See the accompanying LICENSE file 

7# for more information. 

8# 

9# Description: 

10# SMB 2 and 3 Protocol Structures and constants [MS-SMB2] 

11# 

12# Author: 

13# Alberto Solino (@agsolino) 

14# 

15 

16from __future__ import division 

17from __future__ import print_function 

18 

19from impacket.structure import Structure 

20 

21# Constants 

22 

23# SMB Packet 

24SMB2_PACKET_SIZE = 64 

25 

26# SMB Commands 

27SMB2_NEGOTIATE = 0x0000 # 

28SMB2_SESSION_SETUP = 0x0001 # 

29SMB2_LOGOFF = 0x0002 # 

30SMB2_TREE_CONNECT = 0x0003 # 

31SMB2_TREE_DISCONNECT = 0x0004 # 

32SMB2_CREATE = 0x0005 # 

33SMB2_CLOSE = 0x0006 # 

34SMB2_FLUSH = 0x0007 # 

35SMB2_READ = 0x0008 # 

36SMB2_WRITE = 0x0009 # 

37SMB2_LOCK = 0x000A # 

38SMB2_IOCTL = 0x000B # 

39SMB2_CANCEL = 0x000C # 

40SMB2_ECHO = 0x000D # 

41SMB2_QUERY_DIRECTORY = 0x000E # 

42SMB2_CHANGE_NOTIFY = 0x000F 

43SMB2_QUERY_INFO = 0x0010 # 

44SMB2_SET_INFO = 0x0011 

45SMB2_OPLOCK_BREAK = 0x0012 

46 

47# SMB Flags 

48SMB2_FLAGS_SERVER_TO_REDIR = 0x00000001 

49SMB2_FLAGS_ASYNC_COMMAND = 0x00000002 

50SMB2_FLAGS_RELATED_OPERATIONS = 0x00000004 

51SMB2_FLAGS_SIGNED = 0x00000008 

52SMB2_FLAGS_DFS_OPERATIONS = 0x10000000 

53SMB2_FLAGS_REPLAY_OPERATION = 0x80000000 

54 

55# SMB Error SymLink Flags 

56SYMLINK_FLAG_ABSOLUTE = 0x0 

57SYMLINK_FLAG_RELATIVE = 0x1 

58 

59# SMB2_NEGOTIATE 

60# Security Modes 

61SMB2_NEGOTIATE_SIGNING_ENABLED = 0x1 

62SMB2_NEGOTIATE_SIGNING_REQUIRED = 0x2 

63 

64# SMB2_NEGOTIATE_CONTEXT 

65SMB2_PREAUTH_INTEGRITY_CAPABILITIES = 0x1 

66SMB2_ENCRYPTION_CAPABILITIES = 0x2 

67SMB2_COMPRESSION_CAPABILITIES = 0x3 

68SMB2_NETNAME_NEGOTIATE_CONTEXT_ID = 0x5 

69 

70# SMB2_COMPRESSION_CAPABILITIES 

71SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE = 0x0 

72SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED = 0x1 

73 

74# Compression Algorithms 

75COMPRESSION_ALGORITHM_NONE = 0x0 

76COMPRESSION_ALGORITHM_LZNT1 = 0x1 

77COMPRESSION_ALGORITHM_LZ77 = 0x2 

78COMPRESSION_ALGORITHM_LZ77_HUFFMAN = 0x3 

79COMPRESSION_ALGORITHM_PATTERN_V1 = 0x4 

80 

81# Capabilities 

82SMB2_GLOBAL_CAP_DFS = 0x01 

83SMB2_GLOBAL_CAP_LEASING = 0x02 

84SMB2_GLOBAL_CAP_LARGE_MTU = 0x04 

85SMB2_GLOBAL_CAP_MULTI_CHANNEL = 0x08 

86SMB2_GLOBAL_CAP_PERSISTENT_HANDLES = 0x10 

87SMB2_GLOBAL_CAP_DIRECTORY_LEASING = 0x20 

88SMB2_GLOBAL_CAP_ENCRYPTION = 0x40 

89 

90# Dialects 

91SMB2_DIALECT_002 = 0x0202 

92SMB2_DIALECT_21 = 0x0210 

93SMB2_DIALECT_30 = 0x0300 

94SMB2_DIALECT_302 = 0x0302 #SMB 3.0.2 

95SMB2_DIALECT_311 = 0x0311 #SMB 3.1.1 

96SMB2_DIALECT_WILDCARD = 0x02FF 

97 

98# SMB2_SESSION_SETUP 

99# Flags 

100SMB2_SESSION_FLAG_BINDING = 0x01 

101SMB2_SESSION_FLAG_IS_GUEST = 0x01 

102SMB2_SESSION_FLAG_IS_NULL = 0x02 

103SMB2_SESSION_FLAG_ENCRYPT_DATA = 0x04 

104 

105# SMB2_TREE_CONNECT  

106# Types 

107SMB2_SHARE_TYPE_DISK = 0x1 

108SMB2_SHARE_TYPE_PIPE = 0x2 

109SMB2_SHARE_TYPE_PRINT = 0x3 

110 

111# Share Flags 

112SMB2_SHAREFLAG_MANUAL_CACHING = 0x00000000 

113SMB2_SHAREFLAG_AUTO_CACHING = 0x00000010 

114SMB2_SHAREFLAG_VDO_CACHING = 0x00000020 

115SMB2_SHAREFLAG_NO_CACHING = 0x00000030 

116SMB2_SHAREFLAG_DFS = 0x00000001 

117SMB2_SHAREFLAG_DFS_ROOT = 0x00000002 

118SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS = 0x00000100 

119SMB2_SHAREFLAG_FORCE_SHARED_DELETE = 0x00000200 

120SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING = 0x00000400 

121SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM = 0x00000800 

122SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK = 0x00001000 

123SMB2_SHAREFLAG_ENABLE_HASH_V1 = 0x00002000 

124SMB2_SHAREFLAG_ENABLE_HASH_V2 = 0x00004000 

125SMB2_SHAREFLAG_ENCRYPT_DATA = 0x00008000 

126 

127# Capabilities 

128SMB2_SHARE_CAP_DFS = 0x00000008 

129SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY = 0x00000010 

130SMB2_SHARE_CAP_SCALEOUT = 0x00000020 

131SMB2_SHARE_CAP_CLUSTER = 0x00000040 

132 

133# SMB_CREATE  

134# Oplocks 

135SMB2_OPLOCK_LEVEL_NONE = 0x00 

136SMB2_OPLOCK_LEVEL_II = 0x01 

137SMB2_OPLOCK_LEVEL_EXCLUSIVE = 0x08 

138SMB2_OPLOCK_LEVEL_BATCH = 0x09 

139SMB2_OPLOCK_LEVEL_LEASE = 0xFF 

140 

141# Impersonation Level 

142SMB2_IL_ANONYMOUS = 0x00000000 

143SMB2_IL_IDENTIFICATION = 0x00000001 

144SMB2_IL_IMPERSONATION = 0x00000002 

145SMB2_IL_DELEGATE = 0x00000003 

146 

147# File Attributes 

148FILE_ATTRIBUTE_ARCHIVE = 0x00000020 

149FILE_ATTRIBUTE_COMPRESSED = 0x00000800 

150FILE_ATTRIBUTE_DIRECTORY = 0x00000010 

151FILE_ATTRIBUTE_ENCRYPTED = 0x00004000 

152FILE_ATTRIBUTE_HIDDEN = 0x00000002 

153FILE_ATTRIBUTE_NORMAL = 0x00000080 

154FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000 

155FILE_ATTRIBUTE_OFFLINE = 0x00001000 

156FILE_ATTRIBUTE_READONLY = 0x00000001 

157FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400 

158FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200 

159FILE_ATTRIBUTE_SYSTEM = 0x00000004 

160FILE_ATTRIBUTE_TEMPORARY = 0x00000100 

161FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x00000800 

162FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x00020000 

163 

164# Share Access 

165FILE_SHARE_READ = 0x00000001 

166FILE_SHARE_WRITE = 0x00000002 

167FILE_SHARE_DELETE = 0x00000004 

168 

169# Create Disposition 

170FILE_SUPERSEDE = 0x00000000 

171FILE_OPEN = 0x00000001 

172FILE_CREATE = 0x00000002 

173FILE_OPEN_IF = 0x00000003 

174FILE_OVERWRITE = 0x00000004 

175FILE_OVERWRITE_IF = 0x00000005 

176 

177# Create Options 

178FILE_DIRECTORY_FILE = 0x00000001 

179FILE_WRITE_THROUGH = 0x00000002 

180FILE_SEQUENTIAL_ONLY = 0x00000004 

181FILE_NO_INTERMEDIATE_BUFFERING = 0x00000008 

182FILE_SYNCHRONOUS_IO_ALERT = 0x00000010 

183FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020 

184FILE_NON_DIRECTORY_FILE = 0x00000040 

185FILE_COMPLETE_IF_OPLOCKED = 0x00000100 

186FILE_NO_EA_KNOWLEDGE = 0x00000200 

187FILE_RANDOM_ACCESS = 0x00000800 

188FILE_DELETE_ON_CLOSE = 0x00001000 

189FILE_OPEN_BY_FILE_ID = 0x00002000 

190FILE_OPEN_FOR_BACKUP_INTENT = 0x00004000 

191FILE_NO_COMPRESSION = 0x00008000 

192FILE_RESERVE_OPFILTER = 0x00100000 

193FILE_OPEN_REPARSE_POINT = 0x00200000 

194FILE_OPEN_NO_RECALL = 0x00400000 

195FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x00800000 

196 

197# File Access Mask / Desired Access 

198FILE_READ_DATA = 0x00000001 

199FILE_WRITE_DATA = 0x00000002 

200FILE_APPEND_DATA = 0x00000004 

201FILE_READ_EA = 0x00000008 

202FILE_WRITE_EA = 0x00000010 

203FILE_EXECUTE = 0x00000020 

204FILE_READ_ATTRIBUTES = 0x00000080 

205FILE_WRITE_ATTRIBUTES = 0x00000100 

206DELETE = 0x00010000 

207READ_CONTROL = 0x00020000 

208WRITE_DAC = 0x00040000 

209WRITE_OWNER = 0x00080000 

210SYNCHRONIZE = 0x00100000 

211ACCESS_SYSTEM_SECURITY = 0x01000000 

212MAXIMUM_ALLOWED = 0x02000000 

213GENERIC_ALL = 0x10000000 

214GENERIC_EXECUTE = 0x20000000 

215GENERIC_WRITE = 0x40000000 

216GENERIC_READ = 0x80000000 

217 

218# Directory Access Mask  

219FILE_LIST_DIRECTORY = 0x00000001 

220FILE_ADD_FILE = 0x00000002 

221FILE_ADD_SUBDIRECTORY = 0x00000004 

222FILE_TRAVERSE = 0x00000020 

223FILE_DELETE_CHILD = 0x00000040 

224 

225# Create Contexts 

226SMB2_CREATE_EA_BUFFER = 0x45787441 

227SMB2_CREATE_SD_BUFFER = 0x53656344 

228SMB2_CREATE_DURABLE_HANDLE_REQUEST = 0x44486e51 

229SMB2_CREATE_DURABLE_HANDLE_RECONNECT = 0x44486e43 

230SMB2_CREATE_ALLOCATION_SIZE = 0x416c5369 

231SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST = 0x4d784163 

232SMB2_CREATE_TIMEWARP_TOKEN = 0x54577270 

233SMB2_CREATE_QUERY_ON_DISK_ID = 0x51466964 

234SMB2_CREATE_REQUEST = 0x52714c73 

235SMB2_CREATE_REQUEST_LEASE_V2 = 0x52714c73 

236SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 = 0x44483251 

237SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 = 0x44483243 

238SMB2_CREATE_APP_INSTANCE_ID = 0x45BCA66AEFA7F74A9008FA462E144D74 

239 

240# Flags 

241SMB2_CREATE_FLAG_REPARSEPOINT = 0x1 

242FILE_NEED_EA = 0x80 

243 

244# CreateAction 

245FILE_SUPERSEDED = 0x00000000 

246FILE_OPENED = 0x00000001 

247FILE_CREATED = 0x00000002 

248FILE_OVERWRITTEN = 0x00000003 

249 

250# SMB2_CREATE_REQUEST_LEASE states 

251SMB2_LEASE_NONE = 0x00 

252SMB2_LEASE_READ_CACHING = 0x01 

253SMB2_LEASE_HANDLE_CACHING = 0x02 

254SMB2_LEASE_WRITE_CACHING = 0x04 

255 

256# SMB2_CREATE_REQUEST_LEASE_V2 Flags 

257SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET = 0x4 

258 

259# SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 Flags 

260SMB2_DHANDLE_FLAG_PERSISTENT = 0x02 

261 

262# SMB2_CLOSE 

263# Flags 

264SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB = 0x0001 

265 

266# SMB2_READ 

267# Channel 

268SMB2_CHANNEL_NONE = 0x00 

269SMB2_CHANNEL_RDMA_V1 = 0x01 

270 

271# SMB2_WRITE 

272# Flags 

273SMB2_WRITEFLAG_WRITE_THROUGH = 0x01 

274 

275# Lease Break Notification 

276SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED = 0x01 

277 

278# SMB_LOCK 

279# Flags 

280SMB2_LOCKFLAG_SHARED_LOCK = 0x01 

281SMB2_LOCKFLAG_EXCLUSIVE_LOCK = 0x02 

282SMB2_LOCKFLAG_UNLOCK = 0x04 

283SMB2_LOCKFLAG_FAIL_IMMEDIATELY = 0x10 

284 

285# SMB IOCTL 

286# Control Codes 

287FSCTL_DFS_GET_REFERRALS = 0x00060194 

288FSCTL_PIPE_PEEK = 0x0011400C 

289FSCTL_PIPE_WAIT = 0x00110018 

290FSCTL_PIPE_TRANSCEIVE = 0x0011C017 

291FSCTL_SRV_COPYCHUNK = 0x001440F2 

292FSCTL_SRV_ENUMERATE_SNAPSHOTS = 0x00144064 

293FSCTL_SRV_REQUEST_RESUME_KEY = 0x00140078 

294FSCTL_SRV_READ_HASH = 0x001441bb 

295FSCTL_SRV_COPYCHUNK_WRITE = 0x001480F2 

296FSCTL_LMR_REQUEST_RESILIENCY = 0x001401D4 

297FSCTL_QUERY_NETWORK_INTERFACE_INFO = 0x001401FC 

298FSCTL_SET_REPARSE_POINT = 0x000900A4 

299FSCTL_DELETE_REPARSE_POINT = 0x000900AC 

300FSCTL_DFS_GET_REFERRALS_EX = 0x000601B0 

301FSCTL_FILE_LEVEL_TRIM = 0x00098208 

302FSCTL_VALIDATE_NEGOTIATE_INFO = 0x00140204 

303 

304# Flags 

305SMB2_0_IOCTL_IS_FSCTL = 0x1 

306 

307# SRV_READ_HASH 

308# Type 

309SRV_HASH_TYPE_PEER_DIST = 0x01 

310 

311# Version 

312SRV_HASH_VER_1 = 0x1 

313SRV_HASH_VER_2 = 0x2 

314 

315# Retrieval Type 

316SRV_HASH_RETRIEVE_HASH_BASED = 0x01 

317SRV_HASH_RETRIEVE_FILE_BASED = 0x02 

318 

319# NETWORK_INTERFACE_INFO 

320# Capabilities 

321RSS_CAPABLE = 0x01 

322RDMA_CAPABLE = 0x02 

323 

324# SMB2_QUERY_DIRECTORIES 

325# Information Class 

326FILE_DIRECTORY_INFORMATION = 0x01 

327FILE_FULL_DIRECTORY_INFORMATION = 0x02 

328FILEID_FULL_DIRECTORY_INFORMATION = 0x26 

329FILE_BOTH_DIRECTORY_INFORMATION = 0x03 

330FILEID_BOTH_DIRECTORY_INFORMATION = 0x25 

331FILENAMES_INFORMATION = 0x0C 

332 

333# Flags 

334SMB2_RESTART_SCANS = 0x01 

335SMB2_RETURN_SINGLE_ENTRY = 0x02 

336SMB2_INDEX_SPECIFIED = 0x04 

337SMB2_REOPEN = 0x10 

338 

339# SMB2_CHANGE_NOTIFY 

340# Flags 

341SMB2_WATCH_TREE = 0x01 

342 

343# Filters 

344FILE_NOTIFY_CHANGE_FILE_NAME = 0x00000001 

345FILE_NOTIFY_CHANGE_DIR_NAME = 0x00000002 

346FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x00000004 

347FILE_NOTIFY_CHANGE_SIZE = 0x00000008 

348FILE_NOTIFY_CHANGE_LAST_WRITE = 0x00000010 

349FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x00000020 

350FILE_NOTIFY_CHANGE_CREATION = 0x00000040 

351FILE_NOTIFY_CHANGE_EA = 0x00000080 

352FILE_NOTIFY_CHANGE_SECURITY = 0x00000100 

353FILE_NOTIFY_CHANGE_STREAM_NAME = 0x00000200 

354FILE_NOTIFY_CHANGE_STREAM_SIZE = 0x00000400 

355FILE_NOTIFY_CHANGE_STREAM_WRITE = 0x00000800 

356 

357# FILE_NOTIFY_INFORMATION 

358# Actions 

359FILE_ACTION_ADDED = 0x00000001 

360FILE_ACTION_REMOVED = 0x00000002 

361FILE_ACTION_MODIFIED = 0x00000003 

362FILE_ACTION_RENAMED_OLD_NAME = 0x00000004 

363FILE_ACTION_RENAMED_NEW_NAME = 0x00000005 

364 

365# SMB2_QUERY_INFO 

366# InfoTypes 

367SMB2_0_INFO_FILE = 0x01 

368SMB2_0_INFO_FILESYSTEM = 0x02 

369SMB2_0_INFO_SECURITY = 0x03 

370SMB2_0_INFO_QUOTA = 0x04 

371 

372# File Information Classes 

373SMB2_SEC_INFO_00 = 0 

374SMB2_FILE_ACCESS_INFO = 8 

375SMB2_FILE_ALIGNMENT_INFO = 17 

376SMB2_FILE_ALL_INFO = 18 

377SMB2_FILE_ALLOCATION_INFO = 19 

378SMB2_FILE_ALTERNATE_NAME_INFO = 21 

379SMB2_ATTRIBUTE_TAG_INFO = 35 

380SMB2_FILE_BASIC_INFO = 4 

381SMB2_FILE_BOTH_DIRECTORY_INFO = 3 

382SMB2_FILE_COMPRESSION_INFO = 28 

383SMB2_FILE_DIRECTORY_INFO = 1 

384SMB2_FILE_DISPOSITION_INFO = 13 

385SMB2_FILE_EA_INFO = 7 

386SMB2_FILE_END_OF_FILE_INFO = 20 

387SMB2_FULL_DIRECTORY_INFO = 2 

388SMB2_FULL_EA_INFO = 15 

389SMB2_FILE_HARDLINK_INFO = 46 

390SMB2_FILE_ID_BOTH_DIRECTORY_INFO = 37 

391SMB2_FILE_ID_FULL_DIRECTORY_INFO = 38 

392SMB2_FILE_ID_GLOBAL_TX_DIRECTORY_INFO = 50 

393SMB2_FILE_INTERNAL_INFO = 6 

394SMB2_FILE_LINK_INFO = 11 

395SMB2_FILE_MAILSLOT_QUERY_INFO = 26 

396SMB2_FILE_MAILSLOT_SET_INFO = 27 

397SMB2_FILE_MODE_INFO = 16 

398SMB2_FILE_MOVE_CLUSTER_INFO = 31 

399SMB2_FILE_NAME_INFO = 9 

400SMB2_FILE_NAMES_INFO = 12 

401SMB2_FILE_NETWORK_OPEN_INFO = 34 

402SMB2_FILE_NORMALIZED_NAME_INFO = 48 

403SMB2_FILE_OBJECT_ID_INFO = 29 

404SMB2_FILE_PIPE_INFO = 23 

405SMB2_FILE_PIPE_LOCAL_INFO = 24 

406SMB2_FILE_PIPE_REMOTE_INFO = 25 

407SMB2_FILE_POSITION_INFO = 14 

408SMB2_FILE_QUOTA_INFO = 32 

409SMB2_FILE_RENAME_INFO = 10 

410SMB2_FILE_REPARSE_POINT_INFO = 33 

411SMB2_FILE_SFIO_RESERVE_INFO = 44 

412SMB2_FILE_SHORT_NAME_INFO = 45 

413SMB2_FILE_STANDARD_INFO = 5 

414SMB2_FILE_STANDARD_LINK_INFO = 54 

415SMB2_FILE_STREAM_INFO = 22 

416SMB2_FILE_TRACKING_INFO = 36 

417SMB2_FILE_VALID_DATA_LENGTH_INFO = 39 

418 

419# File System Information Classes 

420SMB2_FILESYSTEM_VOLUME_INFO = 1 

421SMB2_FILESYSTEM_LABEL_INFO = 2 

422SMB2_FILESYSTEM_SIZE_INFO = 3 

423SMB2_FILESYSTEM_DEVICE_INFO = 4 

424SMB2_FILESYSTEM_ATTRIBUTE_INFO = 5 

425SMB2_FILESYSTEM_CONTROL_INFO = 6 

426SMB2_FILESYSTEM_FULL_SIZE_INFO = 7 

427SMB2_FILESYSTEM_OBJECT_ID_INFO = 8 

428SMB2_FILESYSTEM_DRIVER_PATH_INFO = 9 

429SMB2_FILESYSTEM_SECTOR_SIZE_INFO = 11 

430 

431# Additional information 

432OWNER_SECURITY_INFORMATION = 0x00000001 

433GROUP_SECURITY_INFORMATION = 0x00000002 

434DACL_SECURITY_INFORMATION = 0x00000004 

435SACL_SECURITY_INFORMATION = 0x00000008 

436LABEL_SECURITY_INFORMATION = 0x00000010 

437 

438# Flags 

439SL_RESTART_SCAN = 0x00000001 

440SL_RETURN_SINGLE_ENTRY = 0x00000002 

441SL_INDEX_SPECIFIED = 0x00000004 

442 

443# TRANSFORM_HEADER 

444SMB2_ENCRYPTION_AES128_CCM = 0x0001 

445SMB2_ENCRYPTION_AES128_GCM = 0x0002 

446 

447 

448# STRUCtures 

449# Represents a SMB2/3 Packet 

450class SMBPacketBase(Structure): 

451 def addCommand(self,command): 

452 # Pad to 8 bytes and put the offset of another SMBPacket 

453 raise Exception('Implement This!') 

454 

455 def isValidAnswer(self, status): 

456 if self['Status'] != status: 

457 from . import smb3 

458 raise smb3.SessionError(self['Status'], self) 

459 return True 

460 

461 def __init__(self, data = None): 

462 Structure.__init__(self,data) 

463 if data is None: 

464 self['TreeID'] = 0 

465 

466 

467class SMB2PacketAsync(SMBPacketBase): 

468 structure = ( 

469 ('ProtocolID','"\xfeSMB'), 

470 ('StructureSize','<H=64'), 

471 ('CreditCharge','<H=0'), 

472 ('Status','<L=0'), 

473 ('Command','<H=0'), 

474 ('CreditRequestResponse','<H=0'), 

475 ('Flags','<L=0'), 

476 ('NextCommand','<L=0'), 

477 ('MessageID','<Q=0'), 

478 ('AsyncID','<Q=0'), 

479 ('SessionID','<Q=0'), 

480 ('Signature','16s=""'), 

481 ('Data',':=""'), 

482 ) 

483 

484class SMB3PacketAsync(SMBPacketBase): 

485 structure = ( 

486 ('ProtocolID','"\xfeSMB'), 

487 ('StructureSize','<H=64'), 

488 ('CreditCharge','<H=0'), 

489 ('ChannelSequence','<H=0'), 

490 ('Reserved','<H=0'), 

491 ('Command','<H=0'), 

492 ('CreditRequestResponse','<H=0'), 

493 ('Flags','<L=0'), 

494 ('NextCommand','<L=0'), 

495 ('MessageID','<Q=0'), 

496 ('AsyncID','<Q=0'), 

497 ('SessionID','<Q=0'), 

498 ('Signature','16s=""'), 

499 ('Data',':=""'), 

500 ) 

501 

502class SMB2Packet(SMBPacketBase): 

503 structure = ( 

504 ('ProtocolID','"\xfeSMB'), 

505 ('StructureSize','<H=64'), 

506 ('CreditCharge','<H=0'), 

507 ('Status','<L=0'), 

508 ('Command','<H=0'), 

509 ('CreditRequestResponse','<H=0'), 

510 ('Flags','<L=0'), 

511 ('NextCommand','<L=0'), 

512 ('MessageID','<Q=0'), 

513 ('Reserved','<L=0'), 

514 ('TreeID','<L=0'), 

515 ('SessionID','<Q=0'), 

516 ('Signature','16s=""'), 

517 ('Data',':=""'), 

518 ) 

519 

520class SMB3Packet(SMBPacketBase): 

521 structure = ( 

522 ('ProtocolID','"\xfeSMB'), 

523 ('StructureSize','<H=64'), 

524 ('CreditCharge','<H=0'), 

525 ('ChannelSequence','<H=0'), 

526 ('Reserved','<H=0'), 

527 ('Command','<H=0'), 

528 ('CreditRequestResponse','<H=0'), 

529 ('Flags','<L=0'), 

530 ('NextCommand','<L=0'), 

531 ('MessageID','<Q=0'), 

532 ('Reserved','<L=0'), 

533 ('TreeID','<L=0'), 

534 ('SessionID','<Q=0'), 

535 ('Signature','16s=""'), 

536 ('Data',':=""'), 

537 ) 

538 

539class SMB2Error(Structure): 

540 structure = ( 

541 ('StructureSize','<H=9'), 

542 ('Reserved','<H=0'), 

543 ('ByteCount','<L=0'), 

544 ('_ErrorData','_-ErrorData','self["ByteCount"]'), 

545 ('ErrorData','"\xff'), 

546 ) 

547 

548class SMB2ErrorSymbolicLink(Structure): 

549 structure = ( 

550 ('SymLinkLength','<L=0'), 

551 ('SymLinkErrorTag','<L=0'), 

552 ('ReparseTag','<L=0'), 

553 ('ReparseDataLenght','<H=0'), 

554 ('UnparsedPathLength','<H=0'), 

555 ('SubstituteNameOffset','<H=0'), 

556 ('SubstituteNameLength','<H=0'), 

557 ('PrintNameOffset','<H=0'), 

558 ('PrintNameLength','<H=0'), 

559 ('Flags','<L=0'), 

560 ('PathBuffer',':'), 

561 ) 

562 

563# SMB2_NEGOTIATE 

564class SMB2Negotiate(Structure): 

565 structure = ( 

566 ('StructureSize','<H=36'), 

567 ('DialectCount','<H=0'), 

568 ('SecurityMode','<H=0'), 

569 ('Reserved','<H=0'), 

570 ('Capabilities','<L=0'), 

571 ('ClientGuid','16s=""'), 

572 ('ClientStartTime','8s=""'), # or (NegotiateContextOffset/NegotiateContextCount/Reserved2) in SMB 3.1.1 

573 ('Dialects','*<H'), 

574 # SMB 3.1.1 

575 ('Padding',':=""'), 

576 ('NegotiateContextList',':=""'), 

577 ) 

578 

579class SMB311ContextData(Structure): 

580 structure = ( 

581 ('NegotiateContextOffset','<L=0'), 

582 ('NegotiateContextCount','<H=0'), 

583 ('Reserved2','<H=0'), 

584 ) 

585class SMB2Negotiate_Response(Structure): 

586 structure = ( 

587 ('StructureSize','<H=65'), 

588 ('SecurityMode','<H=0'), 

589 ('DialectRevision','<H=0'), 

590 # SMB 3.1.1 only. Otherwise Reserved 

591 ('NegotiateContextCount','<H=0'), 

592 ('ServerGuid','16s=""'), 

593 ('Capabilities','<L=0'), 

594 ('MaxTransactSize','<L=0'), 

595 ('MaxReadSize','<L=0'), 

596 ('MaxWriteSize','<L=0'), 

597 ('SystemTime','<Q=0'), 

598 ('ServerStartTime','<Q=0'), 

599 ('SecurityBufferOffset','<H=0'), 

600 ('SecurityBufferLength','<H=0'), 

601 # SMB 3.1.1 only. Otherwise Reserved 

602 ('NegotiateContextOffset','<L=0'), 

603 ('_AlignPad','_-AlignPad','self["SecurityBufferOffset"] - (64 + self["StructureSize"] - 1)'), 

604 ('AlignPad',':=""'), 

605 ('_Buffer','_-Buffer','self["SecurityBufferLength"]'), 

606 ('Buffer',':'), 

607 ('_Padding','_-Padding', '0 if self["NegotiateContextOffset"] == 0 else (self["NegotiateContextOffset"] - ' 

608 'self["SecurityBufferOffset"] - self["SecurityBufferLength"])'), 

609 ('Padding',':=""'), 

610 ('_NegotiateContextList','_-NegotiateContextList', '0 if self["NegotiateContextOffset"] == 0 else ' 

611 'len(self.rawData)-self["NegotiateContextOffset"]+64'), 

612 ('NegotiateContextList',':=""'), 

613 ) 

614 

615# SMB2 NEGOTIATE_CONTEXT 

616class SMB2NegotiateContext(Structure): 

617 structure = ( 

618 ('ContextType','<H=0'), 

619 ('DataLength','<H=0'), 

620 ('Reserved','<L=0'), 

621 ('Data',':=""'), 

622 ) 

623 

624# SMB2_PREAUTH_INTEGRITY_CAPABILITIES 

625class SMB2PreAuthIntegrityCapabilities(Structure): 

626 structure = ( 

627 ('HashAlgorithmCount','<H=0'), 

628 ('SaltLength','<H=0'), 

629 ('HashAlgorithms',':=""'), 

630 ('Salt',':=""'), 

631 ) 

632 

633# SMB2_ENCRYPTION_CAPABILITIES 

634class SMB2EncryptionCapabilities(Structure): 

635 structure = ( 

636 ('CipherCount','<H=0'), 

637 ('Ciphers','<H=0'), 

638 ) 

639 

640# SMB2_COMPRESSION_CAPABILITIES 

641class SMB2CompressionCapabilities(Structure): 

642 structure = ( 

643 ('CompressionAlgorithmCount','<H=0'), 

644 ('Padding','<H=0'), 

645 ('Flags','<L=0'), 

646 ('CompressionAlgorithms',':=""'), 

647 ) 

648 

649# SMB2_NETNAME_NEGOTIATE_CONTEXT_ID 

650class SMB2NetNameNegotiateContextID(Structure): 

651 structure = ( 

652 ('NetName',':=""'), 

653 ) 

654 

655# SMB2_SESSION_SETUP 

656class SMB2SessionSetup(Structure): 

657 SIZE = 24 

658 structure = ( 

659 ('StructureSize','<H=25'), 

660 ('Flags','<B=0'), 

661 ('SecurityMode','<B=0'), 

662 ('Capabilities','<L=0'), 

663 ('Channel','<L=0'), 

664 ('SecurityBufferOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'), 

665 ('SecurityBufferLength','<H=0'), 

666 ('PreviousSessionId','<Q=0'), 

667 ('_AlignPad','_-AlignPad','self["SecurityBufferOffset"] - (64 + self["StructureSize"] - 1)'), 

668 ('AlignPad',':=""'), 

669 ('_Buffer','_-Buffer','self["SecurityBufferLength"]'), 

670 ('Buffer',':'), 

671 ) 

672 

673 def __init__(self, data = None): 

674 Structure.__init__(self,data) 

675 if data is None: 675 ↛ exitline 675 didn't return from function '__init__', because the condition on line 675 was never false

676 self['AlignPad'] = '' 

677 

678 def getData(self): 

679 #self['AlignPad'] = '\x00' * ((8 - ((24 + SMB2_PACKET_SIZE) & 7)) & 7) 

680 #self['SecurityBufferOffset'] = 24 + SMB2_PACKET_SIZE +len(self['AlignPad']) 

681 #self['SecurityBufferLength'] += len(self['AlignPad']) 

682 return Structure.getData(self) 

683 

684 

685class SMB2SessionSetup_Response(Structure): 

686 structure = ( 

687 ('StructureSize','<H=9'), 

688 ('SessionFlags','<H=0'), 

689 ('SecurityBufferOffset','<H=0'), 

690 ('SecurityBufferLength','<H=0'), 

691 ('_AlignPad','_-AlignPad','self["SecurityBufferOffset"] - (64 + self["StructureSize"] - 1)'), 

692 ('AlignPad',':=""'), 

693 ('_Buffer','_-Buffer','self["SecurityBufferLength"]'), 

694 ('Buffer',':'), 

695 ) 

696 

697# SMB2_LOGOFF 

698class SMB2Logoff(Structure): 

699 structure = ( 

700 ('StructureSize','<H=4'), 

701 ('Reserved','<H=0'), 

702 ) 

703 

704 

705class SMB2Logoff_Response(Structure): 

706 structure = ( 

707 ('StructureSize','<H=4'), 

708 ('Reserved','<H=0'), 

709 ) 

710 

711# SMB2_TREE_CONNECT 

712class SMB2TreeConnect(Structure): 

713 SIZE = 8 

714 structure = ( 

715 ('StructureSize','<H=9'), 

716 ('Reserved','<H=0'), 

717 ('PathOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'), 

718 ('PathLength','<H=0'), 

719 ('_AlignPad','_-AlignPad','self["PathOffset"] - (64 + self.SIZE - 1)'), 

720 ('AlignPad',':=""'), 

721 ('_Buffer','_-Buffer','self["PathLength"]'), 

722 ('Buffer',':'), 

723 ) 

724 def __init__(self, data = None): 

725 Structure.__init__(self,data) 

726 if data is None: 726 ↛ exitline 726 didn't return from function '__init__', because the condition on line 726 was never false

727 self['AlignPad'] = '' 

728 

729class SMB2TreeConnect_Response(Structure): 

730 structure = ( 

731 ('StructureSize','<H=16'), 

732 ('ShareType','<B=0'), 

733 ('Reserved','<B=0'), 

734 ('ShareFlags','<L=0'), 

735 ('Capabilities','<L=0'), 

736 ('MaximalAccess','<L=0'), 

737 ) 

738 

739# SMB2_TREE_DISCONNECT 

740class SMB2TreeDisconnect(Structure): 

741 structure = ( 

742 ('StructureSize','<H=4'), 

743 ('Reserved','<H=0'), 

744 ) 

745 

746class SMB2TreeDisconnect_Response(Structure): 

747 structure = ( 

748 ('StructureSize','<H=4'), 

749 ('Reserved','<H=0'), 

750 ) 

751 

752# SMB2_CREATE 

753class SMB2Create(Structure): 

754 SIZE = 56 

755 structure = ( 

756 ('StructureSize','<H=57'), 

757 ('SecurityFlags','<B=0'), 

758 ('RequestedOplockLevel','<B=0'), 

759 ('ImpersonationLevel','<L=0'), 

760 ('SmbCreateFlags','<Q=0'), 

761 ('Reserved','<Q=0'), 

762 ('DesiredAccess','<L=0'), 

763 ('FileAttributes','<L=0'), 

764 ('ShareAccess','<L=0'), 

765 ('CreateDisposition','<L=0'), 

766 ('CreateOptions','<L=0'), 

767 ('NameOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'), 

768 ('NameLength','<H=0'), 

769 ('CreateContextsOffset','<L=0'), 

770 ('CreateContextsLength','<L=0'), 

771 ('_AlignPad','_-AlignPad','self["NameOffset"] - (64 + self["StructureSize"] - 1)'), 

772 ('AlignPad',':=""'), 

773 ('_Buffer','_-Buffer','self["CreateContextsLength"]+self["NameLength"]'), 

774 ('Buffer',':'), 

775 ) 

776 def __init__(self, data = None): 

777 Structure.__init__(self,data) 

778 if data is None: 778 ↛ exitline 778 didn't return from function '__init__', because the condition on line 778 was never false

779 self['AlignPad'] = '' 

780 

781class SMB2CreateContext(Structure): 

782 structure = ( 

783 ('Next','<L=0'), 

784 ('NameOffset','<H=0'), 

785 ('NameLength','<H=0'), 

786 ('Reserved','<H=0'), 

787 ('DataOffset','<H=0'), 

788 ('DataLength','<L=0'), 

789 ('_Buffer','_-Buffer','self["DataLength"]+self["NameLength"]'), 

790 ('Buffer',':'), 

791 ) 

792 

793class SMB2_FILEID(Structure): 

794 structure = ( 

795 ('Persistent','<Q=0'), 

796 ('Volatile','<Q=0'), 

797 ) 

798 

799class SMB2Create_Response(Structure): 

800 structure = ( 

801 ('StructureSize','<H=89'), 

802 ('OplockLevel','<B=0'), 

803 ('Flags','<B=0'), 

804 ('CreateAction','<L=0'), 

805 ('CreationTime','<Q=0'), 

806 ('LastAccessTime','<Q=0'), 

807 ('LastWriteTime','<Q=0'), 

808 ('ChangeTime','<Q=0'), 

809 ('AllocationSize','<Q=0'), 

810 ('EndOfFile','<Q=0'), 

811 ('FileAttributes','<L=0'), 

812 ('Reserved2','<L=0'), 

813 ('FileID',':',SMB2_FILEID), 

814 ('CreateContextsOffset','<L=0'), 

815 ('CreateContextsLength','<L=0'), 

816 ('_AlignPad','_-AlignPad','self["CreateContextsOffset"] - (64 + self["StructureSize"] - 1)'), 

817 ('AlignPad',':=""'), 

818 ('_Buffer','_-Buffer','self["CreateContextsLength"]'), 

819 ('Buffer',':'), 

820 ) 

821 

822class FILE_FULL_EA_INFORMATION(Structure): 

823 structure = ( 

824 ('NextEntryOffset','<L=0'), 

825 ('Flags','<B=0'), 

826 ('EaNameLength','<B=0'), 

827 ('EaValueLength','<H=0'), 

828 ('_EaName','_-EaName','self["EaNameLength"]'), 

829 ('EaName',':'), 

830 ('_EaValue','_-EaValue','self["EaValue"]'), 

831 ('EaValue',':'), 

832 ) 

833 

834 

835class SMB2_CREATE_DURABLE_HANDLE_RECONNECT(Structure): 

836 structure = ( 

837 ('Data',':',SMB2_FILEID), 

838 ) 

839 

840class SMB2_CREATE_DURABLE_HANDLE_REQUEST(Structure): 

841 structure = ( 

842 ('DurableRequest','16s=""'), 

843 ) 

844 

845class SMB2_CREATE_DURABLE_HANDLE_RESPONSE(Structure): 

846 structure = ( 

847 ('Reserved','<Q=0'), 

848 ) 

849 

850class SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST(Structure): 

851 structure = ( 

852 ('Timestamp','<Q=0'), 

853 ) 

854 

855class SMB2_CREATE_QUERY_MAXIMAL_ACCESS_RESPONSE(Structure): 

856 structure = ( 

857 ('QueryStatus','<L=0'), 

858 ('MaximalAccess','<L=0'), 

859 ) 

860 

861class SMB2_CREATE_ALLOCATION_SIZE(Structure): 

862 structure = ( 

863 ('AllocationSize','<Q=0'), 

864 ) 

865 

866class SMB2_CREATE_TIMEWARP_TOKEN(Structure): 

867 structure = ( 

868 ('Timestamp','<Q=0'), 

869 ) 

870 

871class SMB2_CREATE_REQUEST_LEASE(Structure): 

872 structure = ( 

873 ('LeaseKey','16s=""'), 

874 ('LeaseState','<L=0'), 

875 ('LeaseFlags','<L=0'), 

876 ('LeaseDuration','<Q=0'), 

877 ) 

878 

879SMB2_CREATE_RESPONSE_LEASE = SMB2_CREATE_REQUEST_LEASE 

880 

881class SMB2_CREATE_REQUEST_LEASE_V2(Structure): 

882 structure = ( 

883 ('LeaseKey','16s=""'), 

884 ('LeaseState','<L=0'), 

885 ('Flags','<L=0'), 

886 ('LeaseDuration','<Q=0'), 

887 ('ParentLeaseKey','16s=""'), 

888 ('Epoch','<H=0'), 

889 ('Reserved','<H=0'), 

890 ) 

891 

892SMB2_CREATE_RESPONSE_LEASE_V2 = SMB2_CREATE_REQUEST_LEASE_V2 

893 

894class SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2(Structure): 

895 structure = ( 

896 ('Timeout','<L=0'), 

897 ('Flags','<L=0'), 

898 ('Reserved','8s=""'), 

899 ('CreateGuid','16s=""'), 

900 ) 

901 

902class SMB2_CREATE_DURABLE_HANDLE_RESPONSE_V2(Structure): 

903 structure = ( 

904 ('Timeout','<L=0'), 

905 ('Flags','<L=0'), 

906 ) 

907 

908class SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2(Structure): 

909 structure = ( 

910 ('FileID',':', SMB2_FILEID), 

911 ('CreateGuid','16s=""'), 

912 ('Flags','<L=0'), 

913 ) 

914 

915class SMB2_CREATE_APP_INSTANCE_ID(Structure): 

916 structure = ( 

917 ('StructureSize','<H=0'), 

918 ('Reserved','<H=0'), 

919 ('AppInstanceId','16s=""'), 

920 ) 

921 

922class SMB2_CREATE_QUERY_ON_DISK_ID(Structure): 

923 structure = ( 

924 ('DiskIDBuffer','32s=""'), 

925 ) 

926 

927# Todo: Add Classes for 

928#SMB2_CREATE_SD_BUFFER 

929 

930# SMB2_CLOSE 

931class SMB2Close(Structure): 

932 structure = ( 

933 ('StructureSize','<H=24'), 

934 ('Flags','<H=0'), 

935 ('Reserved','<L=0'), 

936 ('FileID',':', SMB2_FILEID), 

937 ) 

938 

939class SMB2Close_Response(Structure): 

940 structure = ( 

941 ('StructureSize','<H=60'), 

942 ('Flags','<H=0'), 

943 ('Reserved','<L=0'), 

944 ('CreationTime','<Q=0'), 

945 ('LastAccessTime','<Q=0'), 

946 ('LastWriteTime','<Q=0'), 

947 ('ChangeTime','<Q=0'), 

948 ('AllocationSize','<Q=0'), 

949 ('EndofFile','<Q=0'), 

950 ('FileAttributes','<L=0'), 

951 ) 

952 

953# SMB2_FLUSH 

954class SMB2Flush(Structure): 

955 structure = ( 

956 ('StructureSize','<H=24'), 

957 ('Reserved1','<H=0'), 

958 ('Reserved2','<L=0'), 

959 ('FileID',':',SMB2_FILEID), 

960 ) 

961 

962class SMB2Flush_Response(Structure): 

963 structure = ( 

964 ('StructureSize','<H=4'), 

965 ('Reserved','<H=0'), 

966 ) 

967 

968# SMB2_READ 

969class SMB2Read(Structure): 

970 SIZE = 48 

971 structure = ( 

972 ('StructureSize','<H=49'), 

973 ('Padding','<B=0'), 

974 ('Reserved','<B=0'), 

975 ('Length','<L=0'), 

976 ('Offset','<Q=0'), 

977 ('FileID',':',SMB2_FILEID), 

978 ('MinimumCount','<L=0'), 

979 ('Channel','<L=0'), 

980 ('RemainingBytes','<L=0'), 

981 ('ReadChannelInfoOffset','<H=0'), 

982 ('ReadChannelInfoLength','<H=0'), 

983 ('_AlignPad','_-AlignPad','self["ReadChannelInfoOffset"] - (64 + self["StructureSize"] - 1)'), 

984 ('AlignPad',':=""'), 

985 ('_Buffer','_-Buffer','self["ReadChannelInfoLength"]'), 

986 ('Buffer',':="0"'), 

987 ) 

988 def __init__(self, data = None): 

989 Structure.__init__(self,data) 

990 if data is None: 990 ↛ exitline 990 didn't return from function '__init__', because the condition on line 990 was never false

991 self['AlignPad'] = '' 

992 

993 

994class SMB2Read_Response(Structure): 

995 structure = ( 

996 ('StructureSize','<H=17'), 

997 ('DataOffset','<B=0'), 

998 ('Reserved','<B=0'), 

999 ('DataLength','<L=0'), 

1000 ('DataRemaining','<L=0'), 

1001 ('Reserved2','<L=0'), 

1002 ('_AlignPad','_-AlignPad','self["DataOffset"] - (64 + self["StructureSize"] - 1)'), 

1003 ('AlignPad',':=""'), 

1004 ('_Buffer','_-Buffer','self["DataLength"]'), 

1005 ('Buffer',':'), 

1006 ) 

1007 

1008# SMB2_WRITE 

1009class SMB2Write(Structure): 

1010 SIZE = 48 

1011 structure = ( 

1012 ('StructureSize','<H=49'), 

1013 ('DataOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'), 

1014 ('Length','<L=0'), 

1015 ('Offset','<Q=0'), 

1016 ('FileID',':',SMB2_FILEID), 

1017 ('Channel','<L=0'), 

1018 ('RemainingBytes','<L=0'), 

1019 ('WriteChannelInfoOffset','<H=0'), 

1020 ('WriteChannelInfoLength','<H=0'), 

1021 ('_AlignPad','_-AlignPad','self["DataOffset"] + self["WriteChannelInfoOffset"] - (64 + self["StructureSize"] - 1)'), 

1022 ('AlignPad',':=""'), 

1023 ('Flags','<L=0'), 

1024 ('_Buffer','_-Buffer','self["Length"]+self["WriteChannelInfoLength"]'), 

1025 ('Buffer',':'), 

1026 ) 

1027 def __init__(self, data = None): 

1028 Structure.__init__(self,data) 

1029 if data is None: 1029 ↛ exitline 1029 didn't return from function '__init__', because the condition on line 1029 was never false

1030 self['AlignPad'] = '' 

1031 

1032 

1033class SMB2Write_Response(Structure): 

1034 structure = ( 

1035 ('StructureSize','<H=17'), 

1036 ('Reserved','<H=0'), 

1037 ('Count','<L=0'), 

1038 ('Remaining','<L=0'), 

1039 ('WriteChannelInfoOffset','<H=0'), 

1040 ('WriteChannelInfoLength','<H=0'), 

1041 ) 

1042 

1043class SMB2OplockBreakNotification(Structure): 

1044 structure = ( 

1045 ('StructureSize','<H=24'), 

1046 ('OplockLevel','<B=0'), 

1047 ('Reserved','<B=0'), 

1048 ('Reserved2','<L=0'), 

1049 ('FileID',':',SMB2_FILEID), 

1050 ) 

1051 

1052SMB2OplockBreakAcknowledgment = SMB2OplockBreakNotification 

1053SMB2OplockBreakResponse = SMB2OplockBreakNotification 

1054 

1055class SMB2LeaseBreakNotification(Structure): 

1056 structure = ( 

1057 ('StructureSize','<H=44'), 

1058 ('NewEpoch','<H=0'), 

1059 ('Flags','<L=0'), 

1060 ('LeaseKey','16s=""'), 

1061 ('CurrentLeaseState','<L=0'), 

1062 ('NewLeaseState','<L=0'), 

1063 ('BreakReason','<L=0'), 

1064 ('AccessMaskHint','<L=0'), 

1065 ('ShareMaskHint','<L=0'), 

1066 ) 

1067 

1068class SMB2LeaseBreakAcknowledgement(Structure): 

1069 structure = ( 

1070 ('StructureSize','<H=36'), 

1071 ('Reserved','<H=0'), 

1072 ('Flags','<L=0'), 

1073 ('LeaseKey','16s=""'), 

1074 ('LeaseState','<L=0'), 

1075 ('LeaseDuration','<Q=0'), 

1076 ) 

1077 

1078SMB2LeaseBreakResponse = SMB2LeaseBreakAcknowledgement 

1079 

1080# SMB2_LOCK 

1081class SMB2_LOCK_ELEMENT(Structure): 

1082 structure = ( 

1083 ('Offset','<Q=0'), 

1084 ('Length','<Q=0'), 

1085 ('Flags','<L=0'), 

1086 ('Reserved','<L=0'), 

1087 ) 

1088 

1089class SMB2Lock(Structure): 

1090 structure = ( 

1091 ('StructureSize','<H=48'), 

1092 ('LockCount','<H=0'), 

1093 ('LockSequence','<L=0'), 

1094 ('FileID',':',SMB2_FILEID), 

1095 ('_Locks','_-Locks','self["LockCount"]*24'), 

1096 ('Locks',':'), 

1097 ) 

1098 

1099class SMB2Lock_Response(Structure): 

1100 structure = ( 

1101 ('StructureSize','<H=4'), 

1102 ('Reserved','<H=0'), 

1103 ) 

1104 

1105 

1106# SMB2_ECHO 

1107class SMB2Echo(Structure): 

1108 structure = ( 

1109 ('StructureSize','<H=4'), 

1110 ('Reserved','<H=0'), 

1111 ) 

1112 

1113SMB2Echo_Response = SMB2Echo 

1114 

1115# SMB2_CANCEL` 

1116class SMB2Cancel(Structure): 

1117 structure = ( 

1118 ('StructureSize','<H=4'), 

1119 ('Reserved','<H=0'), 

1120 ) 

1121 

1122# SMB2_IOCTL 

1123class SMB2Ioctl(Structure): 

1124 SIZE = 56 

1125 structure = ( 

1126 ('StructureSize','<H=57'), 

1127 ('Reserved','<H=0'), 

1128 ('CtlCode','<L=0'), 

1129 ('FileID',':',SMB2_FILEID), 

1130 ('InputOffset','<L=(self.SIZE + 64 + len(self["AlignPad"]))'), 

1131 ('InputCount','<L=0'), 

1132 ('MaxInputResponse','<L=0'), 

1133 ('OutputOffset','<L=(self.SIZE + 64 + len(self["AlignPad"]) + self["InputCount"])'), 

1134 ('OutputCount','<L=0'), 

1135 ('MaxOutputResponse','<L=0'), 

1136 ('Flags','<L=0'), 

1137 ('Reserved2','<L=0'), 

1138 #('_AlignPad','_-AlignPad','self["InputOffset"] + self["OutputOffset"] - (64 + self["StructureSize"] - 1)'), 

1139 #('AlignPad',':=""'), 

1140 ('_Buffer','_-Buffer','self["InputCount"]+self["OutputCount"]'), 

1141 ('Buffer',':'), 

1142 ) 

1143 def __init__(self, data = None): 

1144 Structure.__init__(self,data) 

1145 if data is None: 

1146 self['AlignPad'] = '' 

1147 

1148class FSCTL_PIPE_WAIT_STRUCTURE(Structure): 

1149 structure = ( 

1150 ('Timeout','<q=0'), 

1151 ('NameLength','<L=0'), 

1152 ('TimeoutSpecified','<B=0'), 

1153 ('Padding','<B=0'), 

1154 ('_Name','_-Name','self["NameLength"]'), 

1155 ('Name',':'), 

1156 ) 

1157 

1158class SRV_COPYCHUNK_COPY(Structure): 

1159 structure = ( 

1160 ('SourceKey','24s=""'), 

1161 ('ChunkCount','<L=0'), 

1162 ('Reserved','<L=0'), 

1163 ('_Chunks','_-Chunks', 'self["ChunkCount"]*len(SRV_COPYCHUNK)'), 

1164 ('Chunks',':'), 

1165 ) 

1166 

1167class SRV_COPYCHUNK(Structure): 

1168 structure = ( 

1169 ('SourceOffset','<Q=0'), 

1170 ('TargetOffset','<Q=0'), 

1171 ('Length','<L=0'), 

1172 ('Reserved','<L=0'), 

1173 ) 

1174 

1175class SRV_COPYCHUNK_RESPONSE(Structure): 

1176 structure = ( 

1177 ('ChunksWritten','<L=0'), 

1178 ('ChunkBytesWritten','<L=0'), 

1179 ('TotalBytesWritten','<L=0'), 

1180 ) 

1181 

1182class SRV_READ_HASH(Structure): 

1183 structure = ( 

1184 ('HashType','<L=0'), 

1185 ('HashVersion','<L=0'), 

1186 ('HashRetrievalType','<L=0'), 

1187 ('Length','<L=0'), 

1188 ('Offset','<Q=0'), 

1189 ) 

1190 

1191class NETWORK_RESILIENCY_REQUEST(Structure): 

1192 structure = ( 

1193 ('Timeout','<L=0'), 

1194 ('Reserved','<L=0'), 

1195 ) 

1196 

1197class VALIDATE_NEGOTIATE_INFO(Structure): 

1198 structure = ( 

1199 ('Capabilities','<L=0'), 

1200 ('Guid','16s=""'), 

1201 ('SecurityMode','<H=0'), 

1202 #('DialectCount','<H=0'), 

1203 ('Dialects','<H*<H'), 

1204 ) 

1205 

1206class VALIDATE_NEGOTIATE_INFO_RESPONSE(Structure): 

1207 structure = ( 

1208 ('Capabilities','<L=0'), 

1209 ('Guid','16s=""'), 

1210 ('SecurityMode','<H=0'), 

1211 ('Dialect','<H'), 

1212 ) 

1213 

1214class SRV_SNAPSHOT_ARRAY(Structure): 

1215 structure = ( 

1216 ('NumberOfSnapShots','<L=0'), 

1217 ('NumberOfSnapShotsReturned','<L=0'), 

1218 ('SnapShotArraySize','<L=0'), 

1219 ('_SnapShots','_-SnapShots','self["SnapShotArraySize"]'), 

1220 ('SnapShots',':'), 

1221 ) 

1222 

1223class SRV_REQUEST_RESUME_KEY(Structure): 

1224 structure = ( 

1225 ('ResumeKey','24s=""'), 

1226 ('ContextLength','<L=0'), 

1227 ('_Context','_-Context','self["ContextLength"]'), 

1228 ('Context',':'), 

1229 ) 

1230 

1231class HASH_HEADER(Structure): 

1232 structure = ( 

1233 ('HashType','<L=0'), 

1234 ('HashVersion','<L=0'), 

1235 ('SourceFileChangeTime','<Q=0'), 

1236 ('SourceFileSize','<Q=0'), 

1237 ('HashBlobLength','<L=0'), 

1238 ('HashBlobOffset','<L=0'), 

1239 ('Dirty','<H=0'), 

1240 ('SourceFileNameLength','<L=0'), 

1241 ('_SourceFileName','_-SourceFileName','self["SourceFileNameLength"]',), 

1242 ('SourceFileName',':'), 

1243 ) 

1244 

1245class SRV_HASH_RETRIEVE_HASH_BASED(Structure): 

1246 structure = ( 

1247 ('Offset','<Q=0'), 

1248 ('BufferLength','<L=0'), 

1249 ('Reserved','<L=0'), 

1250 ('_Buffer','_-Buffer','self["BufferLength"]'), 

1251 ('Buffer',':'), 

1252 ) 

1253 

1254class SRV_HASH_RETRIEVE_FILE_BASED(Structure): 

1255 structure = ( 

1256 ('FileDataOffset','<Q=0'), 

1257 ('FileDataLength','<Q=0'), 

1258 ('BufferLength','<L=0'), 

1259 ('Reserved','<L=0'), 

1260 ('_Buffer','_-Buffer','self["BufferLength"]'), 

1261 ('Buffer',':'), 

1262 ) 

1263 

1264class NETWORK_INTERFACE_INFO(Structure): 

1265 structure = ( 

1266 ('Next','<L=0'), 

1267 ('IfIndex','<L=0'), 

1268 ('Capability','<L=0'), 

1269 ('Reserved','<L=0'), 

1270 ('LinkSpeed','<Q=0'), 

1271 ('SockAddr_Storage','128s=""'), 

1272 ) 

1273 

1274class MOUNT_POINT_REPARSE_DATA_STRUCTURE(Structure): 

1275 structure = ( 

1276 ("ReparseTag", "<L=0xA0000003"), 

1277 ("ReparseDataLen", "<H=len(self['PathBuffer']) + 8"), 

1278 ("Reserved", "<H=0"), 

1279 ("SubstituteNameOffset", "<H=0"), 

1280 ("SubstituteNameLength", "<H=0"), 

1281 ("PrintNameOffset", "<H=0"), 

1282 ("PrintNameLength", "<H=0"), 

1283 ("PathBuffer", ":") 

1284 ) 

1285 

1286class MOUNT_POINT_REPARSE_GUID_DATA_STRUCTURE(Structure): 

1287 structure = ( 

1288 ("ReparseTag", "<L=0xA0000003"), 

1289 ("ReparseDataLen", "<H=len(self['DataBuffer'])"), 

1290 ("Reserved", "<H=0"), 

1291 ("ReparseGuid", "16s=''"), 

1292 ("DataBuffer", ":") 

1293 ) 

1294 

1295class SMB2Ioctl_Response(Structure): 

1296 structure = ( 

1297 ('StructureSize','<H=49'), 

1298 ('Reserved','<H=0'), 

1299 ('CtlCode','<L=0'), 

1300 ('FileID',':',SMB2_FILEID), 

1301 ('InputOffset','<L=0'), 

1302 ('InputCount','<L=0'), 

1303 ('OutputOffset','<L=0'), 

1304 ('OutputCount','<L=0'), 

1305 ('Flags','<L=0'), 

1306 ('Reserved2','<L=0'), 

1307 ('_AlignPad','_-AlignPad','self["OutputOffset"] - (64 + self["StructureSize"] - 1)'), 

1308 ('AlignPad',':=""'), 

1309 ('_Buffer','_-Buffer','self["InputCount"]+self["OutputCount"]'), 

1310 ('Buffer',':'), 

1311 ) 

1312 

1313# SMB2_QUERY_DIRECTORY 

1314class SMB2QueryDirectory(Structure): 

1315 SIZE = 32 

1316 structure = ( 

1317 ('StructureSize','<H=33'), 

1318 ('FileInformationClass','<B=0'), 

1319 ('Flags','<B=0'), 

1320 ('FileIndex','<L=0'), 

1321 ('FileID',':',SMB2_FILEID), 

1322 ('FileNameOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'), 

1323 ('FileNameLength','<H=0'), 

1324 ('OutputBufferLength','<L=0'), 

1325 ('_AlignPad','_-AlignPad','self["FileNameOffset"] - (64 + self["StructureSize"] - 1)'), 

1326 ('AlignPad',':=""'), 

1327 ('_Buffer','_-Buffer','self["FileNameLength"]'), 

1328 ('Buffer',':'), 

1329 ) 

1330 def __init__(self, data = None): 

1331 Structure.__init__(self,data) 

1332 if data is None: 1332 ↛ exitline 1332 didn't return from function '__init__', because the condition on line 1332 was never false

1333 self['AlignPad'] = '' 

1334 

1335class SMB2QueryDirectory_Response(Structure): 

1336 structure = ( 

1337 ('StructureSize','<H=9'), 

1338 ('OutputBufferOffset','<H=0'), 

1339 ('OutputBufferLength','<L=0'), 

1340 ('_AlignPad','_-AlignPad','self["OutputBufferOffset"] - (64 + self["StructureSize"] - 1)'), 

1341 ('AlignPad',':=""'), 

1342 ('_Buffer','_-Buffer','self["OutputBufferLength"]'), 

1343 ('Buffer',':'), 

1344 ) 

1345 

1346# SMB2_CHANGE_NOTIFY 

1347class SMB2ChangeNotify(Structure): 

1348 structure = ( 

1349 ('StructureSize','<H=32'), 

1350 ('Flags','<H=0'), 

1351 ('OutputBufferLength','<L=0'), 

1352 ('FileID',':',SMB2_FILEID), 

1353 ('CompletionFilter','<L=0'), 

1354 ('Reserved','<L=0'), 

1355 ) 

1356 

1357class SMB2ChangeNotify_Response(Structure): 

1358 structure = ( 

1359 ('StructureSize','<H=9'), 

1360 ('OutputBufferOffset','<H=0'), 

1361 ('OutputBufferLength','<L=0'), 

1362 ('_AlignPad','_-AlignPad','self["OutputBufferOffset"] - (64 + self["StructureSize"] - 1)'), 

1363 ('AlignPad',':=""'), 

1364 ('_Buffer','_-Buffer','self["OutputBufferLength"]'), 

1365 ('Buffer',':'), 

1366 ) 

1367 

1368class FILE_NOTIFY_INFORMATION(Structure): 

1369 structure = ( 

1370 ('NextEntryOffset','<L=0'), 

1371 ('Action','<L=0'), 

1372 ('FileNameLength','<L=0'), 

1373 ('_FileName','_-FileName','self["FileNameLength"]',), 

1374 ('FileName',':'), 

1375 ) 

1376 

1377# SMB2_QUERY_INFO 

1378class SMB2QueryInfo(Structure): 

1379 SIZE = 40 

1380 structure = ( 

1381 ('StructureSize','<H=41'), 

1382 ('InfoType','<B=0'), 

1383 ('FileInfoClass','<B=0'), 

1384 ('OutputBufferLength','<L=0'), 

1385 ('InputBufferOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'), 

1386 ('Reserved','<H=0'), 

1387 ('InputBufferLength','<L=0'), 

1388 ('AdditionalInformation','<L=0'), 

1389 ('Flags','<L=0'), 

1390 ('FileID',':',SMB2_FILEID), 

1391 ('_AlignPad','_-AlignPad','self["InputBufferOffset"] - (64 + self["StructureSize"] - 1)'), 

1392 ('AlignPad',':=""'), 

1393 ('_Buffer','_-Buffer','self["InputBufferLength"]'), 

1394 ('Buffer',':'), 

1395 ) 

1396 def __init__(self, data = None): 

1397 Structure.__init__(self,data) 

1398 if data is None: 1398 ↛ exitline 1398 didn't return from function '__init__', because the condition on line 1398 was never false

1399 self['AlignPad'] = '' 

1400 

1401 

1402class SMB2_QUERY_QUOTA_INFO(Structure): 

1403 structure = ( 

1404 ('ReturnSingle','<B=0'), 

1405 ('RestartScan','<B=0'), 

1406 ('Reserved','<H=0'), 

1407 ('SidListLength','<L=0'), 

1408 ('StartSidLength','<L=0'), 

1409 ('StartSidOffset','<L=0'), 

1410 # ToDo: Check 2.2.37.1 here 

1411 ('SidBuffer',':'), 

1412 ) 

1413 

1414class SMB2QueryInfo_Response(Structure): 

1415 structure = ( 

1416 ('StructureSize','<H=9'), 

1417 ('OutputBufferOffset','<H=0'), 

1418 ('OutputBufferLength','<L=0'), 

1419 ('_AlignPad','_-AlignPad','self["OutputBufferOffset"] - (64 + self["StructureSize"] - 1)'), 

1420 ('AlignPad',':=""'), 

1421 ('_Buffer','_-Buffer','self["OutputBufferLength"]'), 

1422 ('Buffer',':'), 

1423 ) 

1424 

1425class FILE_BASIC_INFORMATION (Structure): 

1426 structure = ( 

1427 ('CreationTime','<q'), 

1428 ('LastAccessTime','<q'), 

1429 ('LastWriteTime','<q'), 

1430 ('ChangeTime','<q'), 

1431 ('FileAttributes','<L'), 

1432 ('Reserved','<L=0'), 

1433 ) 

1434 

1435class FILE_STANDARD_INFORMATION (Structure): 

1436 structure = ( 

1437 ('AllocationSize','<q'), 

1438 ('EndOfFile','<q'), 

1439 ('NumberOfLinks','<L'), 

1440 ('DeletePending','<B=0'), 

1441 ('Directory','<B'), 

1442 ('Reserved','<H=0'), 

1443 ) 

1444 

1445class FILE_INTERNAL_INFORMATION (Structure): 

1446 structure = ( 

1447 ('IndexNumber','<q=0'), 

1448 ) 

1449 

1450class FILE_EA_INFORMATION (Structure): 

1451 structure = ( 

1452 ('EaSize','<L'), 

1453 ) 

1454 

1455class FILE_ACCESS_INFORMATION (Structure): 

1456 structure = ( 

1457 ('AccessFlags','<L'), 

1458 ) 

1459 

1460class FILE_POSITION_INFORMATION (Structure): 

1461 structure = ( 

1462 ('CurrentByteOffset','<Q'), 

1463 ) 

1464 

1465class FILE_MODE_INFORMATION (Structure): 

1466 structure = ( 

1467 ('Mode','<L=0'), 

1468 ) 

1469 

1470class FILE_ALIGNMENT_INFORMATION (Structure): 

1471 structure = ( 

1472 ('AlignmentRequirement','<L'), 

1473 ) 

1474 

1475class FILE_NAME_INFORMATION (Structure): 

1476 structure = ( 

1477 ('FileNameLength','<L=0'), 

1478 ('_FileName','_-FileName', 'self["FileNameLength"]'), 

1479 ('FileName',':'), 

1480 ) 

1481 

1482class FILE_ALL_INFORMATION(Structure): 

1483 structure = ( 

1484 ('BasicInformation',':',FILE_BASIC_INFORMATION), 

1485 ('StandardInformation',':',FILE_STANDARD_INFORMATION), 

1486 ('InternalInformation',':',FILE_INTERNAL_INFORMATION), 

1487 ('EaInformation',':',FILE_EA_INFORMATION), 

1488 ('AccessInformation',':',FILE_ACCESS_INFORMATION), 

1489 ('PositionInformation',':',FILE_POSITION_INFORMATION), 

1490 ('ModeInformation',':',FILE_MODE_INFORMATION), 

1491 ('AlignmentInformation',':',FILE_ALIGNMENT_INFORMATION), 

1492 ('NameInformation',':',FILE_NAME_INFORMATION), 

1493 ) 

1494 

1495# SMB2_SET_INFO 

1496class SMB2SetInfo(Structure): 

1497 SIZE = 32 

1498 structure = ( 

1499 ('StructureSize','<H=33'), 

1500 ('InfoType','<B=0'), 

1501 ('FileInfoClass','<B=0'), 

1502 ('BufferLength','<L=0'), 

1503 ('BufferOffset','<H=(self.SIZE + 64 + len(self["AlignPad"]))'), 

1504 ('Reserved','<H=0'), 

1505 ('AdditionalInformation','<L=0'), 

1506 ('FileID',':',SMB2_FILEID), 

1507 ('_AlignPad','_-AlignPad','self["BufferOffset"] - (64 + self["StructureSize"] - 1)'), 

1508 ('AlignPad',':=""'), 

1509 ('_Buffer','_-Buffer','self["BufferLength"]'), 

1510 ('Buffer',':'), 

1511 ) 

1512 def __init__(self, data = None): 

1513 Structure.__init__(self,data) 

1514 if data is None: 1514 ↛ exitline 1514 didn't return from function '__init__', because the condition on line 1514 was never false

1515 self['AlignPad'] = '' 

1516 

1517class SMB2SetInfo_Response(Structure): 

1518 structure = ( 

1519 ('StructureSize','<H=2'), 

1520 ) 

1521 

1522class FILE_RENAME_INFORMATION_TYPE_2(Structure): 

1523 structure = ( 

1524 ('ReplaceIfExists','<B=0'), 

1525 ('Reserved','7s=""'), 

1526 ('RootDirectory','<Q=0'), 

1527 ('FileNameLength','<L=0'), 

1528 ('_FileName','_-FileName','self["FileNameLength"]'), 

1529 ('FileName',':'), 

1530 ) 

1531 

1532class SMB2_TRANSFORM_HEADER(Structure): 

1533 structure = ( 

1534 ('ProtocolID','"\xfdSMB'), 

1535 ('Signature','16s=""'), 

1536 ('Nonce','16s=""'), 

1537 ('OriginalMessageSize','<L=0'), 

1538 ('Reserved','<H=0'), 

1539 ('EncryptionAlgorithm','<H=0'), 

1540 ('SessionID','<Q=0'), 

1541 ) 

1542 

1543class SMB2_COMPRESSION_TRANSFORM_HEADER(Structure): 

1544 structure = ( 

1545 ('ProtocolID','<L=0'), 

1546 ('OriginalCompressedSegmentSize','<L=0'), 

1547 ('CompressionAlgorithm','<H=0'), 

1548 ('Flags','<H=0'), 

1549 ('Offset_Length','<L=0'), 

1550 ) 

1551 

1552class SMB2_COMPRESSION_PAYLOAD_HEADER(Structure): 

1553 structure = ( 

1554 ('AlgorithmId','<H=0'), 

1555 ('Reserved','<H=0'), 

1556 ('Length','<L=0'), 

1557 ) 

1558 

1559class SMB2_COMPRESSION_PATTERN_PAYLOAD_V1(Structure): 

1560 structure = ( 

1561 ('Pattern','B=0'), 

1562 ('Reserved1','B=0'), 

1563 ('Reserved2','B=0'), 

1564 ('Repetitions','<L=0'), 

1565 ) 

1566 

1567# SMB2_SEC_INFO_00 

1568class FileSecInformation(Structure): 

1569 structure = ( 

1570 ('Revision','<h=1'), 

1571 ('Type','<h=0'), 

1572 ('OffsetToOwner','<I=0'), 

1573 ('OffsetToGroup','<I=0'), 

1574 ('OffsetToSACL','<I=0'), 

1575 ('OffsetToDACL','<I=0'), 

1576 )