Coverage for /root/GitHubProjects/impacket/impacket/smb3structs.py: 98%

# Coverage for /root/GitHubProjects/impacket/impacket/smb3structs.py : 98%

## 579 statements

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

16 from __future__ import division

17 from __future__ import print_function

18

19 from impacket.structure import Structure

20

21# Constants

22

23# SMB Packet

24 SMB2_PACKET_SIZE = 64

25

26# SMB Commands

27 SMB2_NEGOTIATE = 0x0000 #

28 SMB2_SESSION_SETUP = 0x0001 #

29 SMB2_LOGOFF = 0x0002 #

30 SMB2_TREE_CONNECT = 0x0003 #

31 SMB2_TREE_DISCONNECT = 0x0004 #

32 SMB2_CREATE = 0x0005 #

33 SMB2_CLOSE = 0x0006 #

34 SMB2_FLUSH = 0x0007 #

35 SMB2_READ = 0x0008 #

36 SMB2_WRITE = 0x0009 #

37 SMB2_LOCK = 0x000A #

38 SMB2_IOCTL = 0x000B #

39 SMB2_CANCEL = 0x000C #

40 SMB2_ECHO = 0x000D #

41 SMB2_QUERY_DIRECTORY = 0x000E #

42 SMB2_CHANGE_NOTIFY = 0x000F

43 SMB2_QUERY_INFO = 0x0010 #

44 SMB2_SET_INFO = 0x0011

45 SMB2_OPLOCK_BREAK = 0x0012

46

47# SMB Flags

48 SMB2_FLAGS_SERVER_TO_REDIR = 0x00000001

49 SMB2_FLAGS_ASYNC_COMMAND = 0x00000002

50 SMB2_FLAGS_RELATED_OPERATIONS = 0x00000004

51 SMB2_FLAGS_SIGNED = 0x00000008

52 SMB2_FLAGS_DFS_OPERATIONS = 0x10000000

53 SMB2_FLAGS_REPLAY_OPERATION = 0x80000000

54

55# SMB Error SymLink Flags

56 SYMLINK_FLAG_ABSOLUTE = 0x0

57 SYMLINK_FLAG_RELATIVE = 0x1

58

59# SMB2_NEGOTIATE

60# Security Modes

61 SMB2_NEGOTIATE_SIGNING_ENABLED = 0x1

62 SMB2_NEGOTIATE_SIGNING_REQUIRED = 0x2

63

64# SMB2_NEGOTIATE_CONTEXT

65 SMB2_PREAUTH_INTEGRITY_CAPABILITIES = 0x1

66 SMB2_ENCRYPTION_CAPABILITIES = 0x2

67 SMB2_COMPRESSION_CAPABILITIES = 0x3

68 SMB2_NETNAME_NEGOTIATE_CONTEXT_ID = 0x5

69

70# SMB2_COMPRESSION_CAPABILITIES

71 SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE = 0x0

72 SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED = 0x1

73

74# Compression Algorithms

75 COMPRESSION_ALGORITHM_NONE = 0x0

76 COMPRESSION_ALGORITHM_LZNT1 = 0x1

77 COMPRESSION_ALGORITHM_LZ77 = 0x2

78 COMPRESSION_ALGORITHM_LZ77_HUFFMAN = 0x3

79 COMPRESSION_ALGORITHM_PATTERN_V1 = 0x4

80

81# Capabilities

82 SMB2_GLOBAL_CAP_DFS = 0x01

83 SMB2_GLOBAL_CAP_LEASING = 0x02

84 SMB2_GLOBAL_CAP_LARGE_MTU = 0x04

85 SMB2_GLOBAL_CAP_MULTI_CHANNEL = 0x08

86 SMB2_GLOBAL_CAP_PERSISTENT_HANDLES = 0x10

87 SMB2_GLOBAL_CAP_DIRECTORY_LEASING = 0x20

88 SMB2_GLOBAL_CAP_ENCRYPTION = 0x40

89

90# Dialects

91 SMB2_DIALECT_002 = 0x0202

92 SMB2_DIALECT_21 = 0x0210

93 SMB2_DIALECT_30 = 0x0300

94 SMB2_DIALECT_302 = 0x0302 #SMB 3.0.2

95 SMB2_DIALECT_311 = 0x0311 #SMB 3.1.1

96 SMB2_DIALECT_WILDCARD = 0x02FF

97

98# SMB2_SESSION_SETUP

99# Flags

100 SMB2_SESSION_FLAG_BINDING = 0x01

101 SMB2_SESSION_FLAG_IS_GUEST = 0x01

102 SMB2_SESSION_FLAG_IS_NULL = 0x02

103 SMB2_SESSION_FLAG_ENCRYPT_DATA = 0x04

104

105# SMB2_TREE_CONNECT

106# Types

107 SMB2_SHARE_TYPE_DISK = 0x1

108 SMB2_SHARE_TYPE_PIPE = 0x2

109 SMB2_SHARE_TYPE_PRINT = 0x3

110

111# Share Flags

112 SMB2_SHAREFLAG_MANUAL_CACHING = 0x00000000

113 SMB2_SHAREFLAG_AUTO_CACHING = 0x00000010

114 SMB2_SHAREFLAG_VDO_CACHING = 0x00000020

115 SMB2_SHAREFLAG_NO_CACHING = 0x00000030

116 SMB2_SHAREFLAG_DFS = 0x00000001

117 SMB2_SHAREFLAG_DFS_ROOT = 0x00000002

118 SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS = 0x00000100

119 SMB2_SHAREFLAG_FORCE_SHARED_DELETE = 0x00000200

120 SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING = 0x00000400

121 SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM = 0x00000800

122 SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK = 0x00001000

123 SMB2_SHAREFLAG_ENABLE_HASH_V1 = 0x00002000

124 SMB2_SHAREFLAG_ENABLE_HASH_V2 = 0x00004000

125 SMB2_SHAREFLAG_ENCRYPT_DATA = 0x00008000

126

127# Capabilities

128 SMB2_SHARE_CAP_DFS = 0x00000008

129 SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY = 0x00000010

130 SMB2_SHARE_CAP_SCALEOUT = 0x00000020

131 SMB2_SHARE_CAP_CLUSTER = 0x00000040

132

133# SMB_CREATE

134# Oplocks

135 SMB2_OPLOCK_LEVEL_NONE = 0x00

136 SMB2_OPLOCK_LEVEL_II = 0x01

137 SMB2_OPLOCK_LEVEL_EXCLUSIVE = 0x08

138 SMB2_OPLOCK_LEVEL_BATCH = 0x09

139 SMB2_OPLOCK_LEVEL_LEASE = 0xFF

140

141# Impersonation Level

142 SMB2_IL_ANONYMOUS = 0x00000000

143 SMB2_IL_IDENTIFICATION = 0x00000001

144 SMB2_IL_IMPERSONATION = 0x00000002

145 SMB2_IL_DELEGATE = 0x00000003

146

147# File Attributes

148 FILE_ATTRIBUTE_ARCHIVE = 0x00000020

149 FILE_ATTRIBUTE_COMPRESSED = 0x00000800

150 FILE_ATTRIBUTE_DIRECTORY = 0x00000010

151 FILE_ATTRIBUTE_ENCRYPTED = 0x00004000

152 FILE_ATTRIBUTE_HIDDEN = 0x00000002

153 FILE_ATTRIBUTE_NORMAL = 0x00000080

154 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000

155 FILE_ATTRIBUTE_OFFLINE = 0x00001000

156 FILE_ATTRIBUTE_READONLY = 0x00000001

157 FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400

158 FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200

159 FILE_ATTRIBUTE_SYSTEM = 0x00000004

160 FILE_ATTRIBUTE_TEMPORARY = 0x00000100

161 FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x00000800

162 FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x00020000

163

164# Share Access

165 FILE_SHARE_READ = 0x00000001

166 FILE_SHARE_WRITE = 0x00000002

167 FILE_SHARE_DELETE = 0x00000004

168

169# Create Disposition

170 FILE_SUPERSEDE = 0x00000000

171 FILE_OPEN = 0x00000001

172 FILE_CREATE = 0x00000002

173 FILE_OPEN_IF = 0x00000003

174 FILE_OVERWRITE = 0x00000004

175 FILE_OVERWRITE_IF = 0x00000005

176

177# Create Options

178 FILE_DIRECTORY_FILE = 0x00000001

179 FILE_WRITE_THROUGH = 0x00000002

180 FILE_SEQUENTIAL_ONLY = 0x00000004

181 FILE_NO_INTERMEDIATE_BUFFERING = 0x00000008

182 FILE_SYNCHRONOUS_IO_ALERT = 0x00000010

183 FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020

184 FILE_NON_DIRECTORY_FILE = 0x00000040

185 FILE_COMPLETE_IF_OPLOCKED = 0x00000100

186 FILE_NO_EA_KNOWLEDGE = 0x00000200

187 FILE_RANDOM_ACCESS = 0x00000800

188 FILE_DELETE_ON_CLOSE = 0x00001000

189 FILE_OPEN_BY_FILE_ID = 0x00002000

190 FILE_OPEN_FOR_BACKUP_INTENT = 0x00004000

191 FILE_NO_COMPRESSION = 0x00008000

192 FILE_RESERVE_OPFILTER = 0x00100000

193 FILE_OPEN_REPARSE_POINT = 0x00200000

194 FILE_OPEN_NO_RECALL = 0x00400000

195 FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x00800000

196

197# File Access Mask / Desired Access

198 FILE_READ_DATA = 0x00000001

199 FILE_WRITE_DATA = 0x00000002

200 FILE_APPEND_DATA = 0x00000004

201 FILE_READ_EA = 0x00000008

202 FILE_WRITE_EA = 0x00000010

203 FILE_EXECUTE = 0x00000020

204 FILE_READ_ATTRIBUTES = 0x00000080

205 FILE_WRITE_ATTRIBUTES = 0x00000100

206 DELETE = 0x00010000

207 READ_CONTROL = 0x00020000

208 WRITE_DAC = 0x00040000

209 WRITE_OWNER = 0x00080000

210 SYNCHRONIZE = 0x00100000

211 ACCESS_SYSTEM_SECURITY = 0x01000000

212 MAXIMUM_ALLOWED = 0x02000000

213 GENERIC_ALL = 0x10000000

214 GENERIC_EXECUTE = 0x20000000

215 GENERIC_WRITE = 0x40000000

216 GENERIC_READ = 0x80000000

217

218# Directory Access Mask

219 FILE_LIST_DIRECTORY = 0x00000001

220 FILE_ADD_FILE = 0x00000002

221 FILE_ADD_SUBDIRECTORY = 0x00000004

222 FILE_TRAVERSE = 0x00000020

223 FILE_DELETE_CHILD = 0x00000040

224

225# Create Contexts

226 SMB2_CREATE_EA_BUFFER = 0x45787441

227 SMB2_CREATE_SD_BUFFER = 0x53656344

228 SMB2_CREATE_DURABLE_HANDLE_REQUEST = 0x44486e51

229 SMB2_CREATE_DURABLE_HANDLE_RECONNECT = 0x44486e43

230 SMB2_CREATE_ALLOCATION_SIZE = 0x416c5369

231 SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST = 0x4d784163

232 SMB2_CREATE_TIMEWARP_TOKEN = 0x54577270

233 SMB2_CREATE_QUERY_ON_DISK_ID = 0x51466964

234 SMB2_CREATE_REQUEST = 0x52714c73

235 SMB2_CREATE_REQUEST_LEASE_V2 = 0x52714c73

236 SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 = 0x44483251

237 SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 = 0x44483243

238 SMB2_CREATE_APP_INSTANCE_ID = 0x45BCA66AEFA7F74A9008FA462E144D74

239

240# Flags

241 SMB2_CREATE_FLAG_REPARSEPOINT = 0x1

242 FILE_NEED_EA = 0x80

243

244# CreateAction

245 FILE_SUPERSEDED = 0x00000000

246 FILE_OPENED = 0x00000001

247 FILE_CREATED = 0x00000002

248 FILE_OVERWRITTEN = 0x00000003

249

250# SMB2_CREATE_REQUEST_LEASE states

251 SMB2_LEASE_NONE = 0x00

252 SMB2_LEASE_READ_CACHING = 0x01

253 SMB2_LEASE_HANDLE_CACHING = 0x02

254 SMB2_LEASE_WRITE_CACHING = 0x04

255

256# SMB2_CREATE_REQUEST_LEASE_V2 Flags

257 SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET = 0x4

258

259# SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 Flags

260 SMB2_DHANDLE_FLAG_PERSISTENT = 0x02

261

262# SMB2_CLOSE

263# Flags

264 SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB = 0x0001

265

266# SMB2_READ

267# Channel

268 SMB2_CHANNEL_NONE = 0x00

269 SMB2_CHANNEL_RDMA_V1 = 0x01

270

271# SMB2_WRITE

272# Flags

273 SMB2_WRITEFLAG_WRITE_THROUGH = 0x01

274

275# Lease Break Notification

276 SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED = 0x01

277

278# SMB_LOCK

279# Flags

280 SMB2_LOCKFLAG_SHARED_LOCK = 0x01

281 SMB2_LOCKFLAG_EXCLUSIVE_LOCK = 0x02

282 SMB2_LOCKFLAG_UNLOCK = 0x04

283 SMB2_LOCKFLAG_FAIL_IMMEDIATELY = 0x10

284

285# SMB IOCTL

286# Control Codes

287 FSCTL_DFS_GET_REFERRALS = 0x00060194

288 FSCTL_PIPE_PEEK = 0x0011400C

289 FSCTL_PIPE_WAIT = 0x00110018

290 FSCTL_PIPE_TRANSCEIVE = 0x0011C017

291 FSCTL_SRV_COPYCHUNK = 0x001440F2

292 FSCTL_SRV_ENUMERATE_SNAPSHOTS = 0x00144064

293 FSCTL_SRV_REQUEST_RESUME_KEY = 0x00140078

294 FSCTL_SRV_READ_HASH = 0x001441bb

295 FSCTL_SRV_COPYCHUNK_WRITE = 0x001480F2

296 FSCTL_LMR_REQUEST_RESILIENCY = 0x001401D4

297 FSCTL_QUERY_NETWORK_INTERFACE_INFO = 0x001401FC

298 FSCTL_SET_REPARSE_POINT = 0x000900A4

299 FSCTL_DELETE_REPARSE_POINT = 0x000900AC

300 FSCTL_DFS_GET_REFERRALS_EX = 0x000601B0

301 FSCTL_FILE_LEVEL_TRIM = 0x00098208

302 FSCTL_VALIDATE_NEGOTIATE_INFO = 0x00140204

303

304# Flags

305 SMB2_0_IOCTL_IS_FSCTL = 0x1

306

307# SRV_READ_HASH

308# Type

309 SRV_HASH_TYPE_PEER_DIST = 0x01

310

311# Version

312 SRV_HASH_VER_1 = 0x1

313 SRV_HASH_VER_2 = 0x2

314

315# Retrieval Type

316 SRV_HASH_RETRIEVE_HASH_BASED = 0x01

317 SRV_HASH_RETRIEVE_FILE_BASED = 0x02

318

319# NETWORK_INTERFACE_INFO

320# Capabilities

321 RSS_CAPABLE = 0x01

322 RDMA_CAPABLE = 0x02

323

324# SMB2_QUERY_DIRECTORIES

325# Information Class

326 FILE_DIRECTORY_INFORMATION = 0x01

327 FILE_FULL_DIRECTORY_INFORMATION = 0x02

328 FILEID_FULL_DIRECTORY_INFORMATION = 0x26

329 FILE_BOTH_DIRECTORY_INFORMATION = 0x03

330 FILEID_BOTH_DIRECTORY_INFORMATION = 0x25

331 FILENAMES_INFORMATION = 0x0C

332

333# Flags

334 SMB2_RESTART_SCANS = 0x01

335 SMB2_RETURN_SINGLE_ENTRY = 0x02

336 SMB2_INDEX_SPECIFIED = 0x04

337 SMB2_REOPEN = 0x10

338

339# SMB2_CHANGE_NOTIFY

340# Flags

341 SMB2_WATCH_TREE = 0x01

342

343# Filters

344 FILE_NOTIFY_CHANGE_FILE_NAME = 0x00000001

345 FILE_NOTIFY_CHANGE_DIR_NAME = 0x00000002

346 FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x00000004

347 FILE_NOTIFY_CHANGE_SIZE = 0x00000008

348 FILE_NOTIFY_CHANGE_LAST_WRITE = 0x00000010

349 FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x00000020

350 FILE_NOTIFY_CHANGE_CREATION = 0x00000040

351 FILE_NOTIFY_CHANGE_EA = 0x00000080

352 FILE_NOTIFY_CHANGE_SECURITY = 0x00000100

353 FILE_NOTIFY_CHANGE_STREAM_NAME = 0x00000200

354 FILE_NOTIFY_CHANGE_STREAM_SIZE = 0x00000400

355 FILE_NOTIFY_CHANGE_STREAM_WRITE = 0x00000800

356

357# FILE_NOTIFY_INFORMATION

358# Actions

359 FILE_ACTION_ADDED = 0x00000001

360 FILE_ACTION_REMOVED = 0x00000002

361 FILE_ACTION_MODIFIED = 0x00000003

362 FILE_ACTION_RENAMED_OLD_NAME = 0x00000004

363 FILE_ACTION_RENAMED_NEW_NAME = 0x00000005

364

365# SMB2_QUERY_INFO

366# InfoTypes

367 SMB2_0_INFO_FILE = 0x01

368 SMB2_0_INFO_FILESYSTEM = 0x02

369 SMB2_0_INFO_SECURITY = 0x03

370 SMB2_0_INFO_QUOTA = 0x04

371

372# File Information Classes

373 SMB2_SEC_INFO_00 = 0

374 SMB2_FILE_ACCESS_INFO = 8

375 SMB2_FILE_ALIGNMENT_INFO = 17

376 SMB2_FILE_ALL_INFO = 18

377 SMB2_FILE_ALLOCATION_INFO = 19

378 SMB2_FILE_ALTERNATE_NAME_INFO = 21

379 SMB2_ATTRIBUTE_TAG_INFO = 35

380 SMB2_FILE_BASIC_INFO = 4

381 SMB2_FILE_BOTH_DIRECTORY_INFO = 3

382 SMB2_FILE_COMPRESSION_INFO = 28

383 SMB2_FILE_DIRECTORY_INFO = 1

384 SMB2_FILE_DISPOSITION_INFO = 13

385 SMB2_FILE_EA_INFO = 7

386 SMB2_FILE_END_OF_FILE_INFO = 20

387 SMB2_FULL_DIRECTORY_INFO = 2

388 SMB2_FULL_EA_INFO = 15

389 SMB2_FILE_HARDLINK_INFO = 46

390 SMB2_FILE_ID_BOTH_DIRECTORY_INFO = 37

391 SMB2_FILE_ID_FULL_DIRECTORY_INFO = 38

392 SMB2_FILE_ID_GLOBAL_TX_DIRECTORY_INFO = 50

393 SMB2_FILE_INTERNAL_INFO = 6

394 SMB2_FILE_LINK_INFO = 11

395 SMB2_FILE_MAILSLOT_QUERY_INFO = 26

396 SMB2_FILE_MAILSLOT_SET_INFO = 27

397 SMB2_FILE_MODE_INFO = 16

398 SMB2_FILE_MOVE_CLUSTER_INFO = 31

399 SMB2_FILE_NAME_INFO = 9

400 SMB2_FILE_NAMES_INFO = 12

401 SMB2_FILE_NETWORK_OPEN_INFO = 34

402 SMB2_FILE_NORMALIZED_NAME_INFO = 48

403 SMB2_FILE_OBJECT_ID_INFO = 29

404 SMB2_FILE_PIPE_INFO = 23

405 SMB2_FILE_PIPE_LOCAL_INFO = 24

406 SMB2_FILE_PIPE_REMOTE_INFO = 25

407 SMB2_FILE_POSITION_INFO = 14

408 SMB2_FILE_QUOTA_INFO = 32

409 SMB2_FILE_RENAME_INFO = 10

410 SMB2_FILE_REPARSE_POINT_INFO = 33

411 SMB2_FILE_SFIO_RESERVE_INFO = 44

412 SMB2_FILE_SHORT_NAME_INFO = 45

413 SMB2_FILE_STANDARD_INFO = 5

414 SMB2_FILE_STANDARD_LINK_INFO = 54

415 SMB2_FILE_STREAM_INFO = 22

416 SMB2_FILE_TRACKING_INFO = 36

417 SMB2_FILE_VALID_DATA_LENGTH_INFO = 39

418

419# File System Information Classes

420 SMB2_FILESYSTEM_VOLUME_INFO = 1

421 SMB2_FILESYSTEM_LABEL_INFO = 2

422 SMB2_FILESYSTEM_SIZE_INFO = 3

423 SMB2_FILESYSTEM_DEVICE_INFO = 4

424 SMB2_FILESYSTEM_ATTRIBUTE_INFO = 5

425 SMB2_FILESYSTEM_CONTROL_INFO = 6

426 SMB2_FILESYSTEM_FULL_SIZE_INFO = 7

427 SMB2_FILESYSTEM_OBJECT_ID_INFO = 8

428 SMB2_FILESYSTEM_DRIVER_PATH_INFO = 9

429 SMB2_FILESYSTEM_SECTOR_SIZE_INFO = 11

430

431# Additional information

432 OWNER_SECURITY_INFORMATION = 0x00000001

433 GROUP_SECURITY_INFORMATION = 0x00000002

434 DACL_SECURITY_INFORMATION = 0x00000004

435 SACL_SECURITY_INFORMATION = 0x00000008

436 LABEL_SECURITY_INFORMATION = 0x00000010

437

438# Flags

439 SL_RESTART_SCAN = 0x00000001

440 SL_RETURN_SINGLE_ENTRY = 0x00000002

441 SL_INDEX_SPECIFIED = 0x00000004

442

443# TRANSFORM_HEADER

444 SMB2_ENCRYPTION_AES128_CCM = 0x0001

445 SMB2_ENCRYPTION_AES128_GCM = 0x0002

446

447

448# STRUCtures

449# Represents a SMB2/3 Packet

450 class 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

467 class 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

484 class 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

502 class 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

520 class 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

539 class 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

548 class 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

564 class 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

579 class SMB311ContextData(Structure):

580 structure = (

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

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

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

584 )

585 class 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

616 class 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

625 class SMB2PreAuthIntegrityCapabilities(Structure):

626 structure = (

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

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

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

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

631 )

632

633# SMB2_ENCRYPTION_CAPABILITIES

634 class SMB2EncryptionCapabilities(Structure):

635 structure = (

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

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

638 )

639

640# SMB2_COMPRESSION_CAPABILITIES

641 class 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

650 class SMB2NetNameNegotiateContextID(Structure):

651 structure = (

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

653 )

654

655# SMB2_SESSION_SETUP

656 class 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

685 class 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

698 class SMB2Logoff(Structure):

699 structure = (

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

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

702 )

703

704

705 class SMB2Logoff_Response(Structure):

706 structure = (

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

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

709 )

710

711# SMB2_TREE_CONNECT

712 class 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

729 class 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

740 class SMB2TreeDisconnect(Structure):

741 structure = (

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

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

744 )

745

746 class SMB2TreeDisconnect_Response(Structure):

747 structure = (

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

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

750 )

751

752# SMB2_CREATE

753 class 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

781 class 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

793 class SMB2_FILEID(Structure):

794 structure = (

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

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

797 )

798

799 class 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

822 class 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

835 class SMB2_CREATE_DURABLE_HANDLE_RECONNECT(Structure):

836 structure = (

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

838 )

839

840 class SMB2_CREATE_DURABLE_HANDLE_REQUEST(Structure):

841 structure = (

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

843 )

844

845 class SMB2_CREATE_DURABLE_HANDLE_RESPONSE(Structure):

846 structure = (

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

848 )

849

850 class SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST(Structure):

851 structure = (

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

853 )

854

855 class SMB2_CREATE_QUERY_MAXIMAL_ACCESS_RESPONSE(Structure):

856 structure = (

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

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

859 )

860

861 class SMB2_CREATE_ALLOCATION_SIZE(Structure):

862 structure = (

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

864 )

865

866 class SMB2_CREATE_TIMEWARP_TOKEN(Structure):

867 structure = (

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

869 )

870

871 class SMB2_CREATE_REQUEST_LEASE(Structure):

872 structure = (

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

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

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

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

877 )

878

879 SMB2_CREATE_RESPONSE_LEASE = SMB2_CREATE_REQUEST_LEASE

880

881 class 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

892 SMB2_CREATE_RESPONSE_LEASE_V2 = SMB2_CREATE_REQUEST_LEASE_V2

893

894 class 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

902 class SMB2_CREATE_DURABLE_HANDLE_RESPONSE_V2(Structure):

903 structure = (

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

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

906 )

907

908 class SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2(Structure):

909 structure = (

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

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

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

913 )

914

915 class SMB2_CREATE_APP_INSTANCE_ID(Structure):

916 structure = (

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

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

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

920 )

921

922 class 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

931 class SMB2Close(Structure):

932 structure = (

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

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

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

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

937 )

938

939 class 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

954 class SMB2Flush(Structure):

955 structure = (

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

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

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

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

960 )

961

962 class SMB2Flush_Response(Structure):

963 structure = (

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

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

966 )

967

968# SMB2_READ

969 class 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

994 class 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

1009 class 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

1033 class 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

1043 class 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

1052 SMB2OplockBreakAcknowledgment = SMB2OplockBreakNotification

1053 SMB2OplockBreakResponse = SMB2OplockBreakNotification

1054

1055 class 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

1068 class 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

1078 SMB2LeaseBreakResponse = SMB2LeaseBreakAcknowledgement

1079

1080# SMB2_LOCK

1081 class SMB2_LOCK_ELEMENT(Structure):

1082 structure = (

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

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

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

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

1087 )

1088

1089 class 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

1099 class SMB2Lock_Response(Structure):

1100 structure = (

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

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

1103 )

1104

1105

1106# SMB2_ECHO

1107 class SMB2Echo(Structure):

1108 structure = (

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

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

1111 )

1112

1113 SMB2Echo_Response = SMB2Echo

1114

1115# SMB2_CANCEL`

1116 class SMB2Cancel(Structure):

1117 structure = (

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

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

1120 )

1121

1122# SMB2_IOCTL

1123 class 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

1148 class 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

1158 class 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

1167 class SRV_COPYCHUNK(Structure):

1168 structure = (

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

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

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

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

1173 )

1174

1175 class SRV_COPYCHUNK_RESPONSE(Structure):

1176 structure = (

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

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

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

1180 )

1181

1182 class 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

1191 class NETWORK_RESILIENCY_REQUEST(Structure):

1192 structure = (

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

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

1195 )

1196

1197 class 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

1206 class VALIDATE_NEGOTIATE_INFO_RESPONSE(Structure):

1207 structure = (

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

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

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

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

1212 )

1213

1214 class 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

1223 class SRV_REQUEST_RESUME_KEY(Structure):

1224 structure = (

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

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

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

1228 ('Context',':'),

1229 )

1230

1231 class 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

1245 class 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

1254 class 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

1264 class 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

1274 class 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

1286 class 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

1295 class 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

1314 class 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

1335 class 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

1347 class 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

1357 class 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

1368 class 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

1378 class 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

1402 class 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

1414 class 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

1425 class 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

1435 class 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

1445 class FILE_INTERNAL_INFORMATION (Structure):

1446 structure = (

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

1448 )

1449

1450 class FILE_EA_INFORMATION (Structure):

1451 structure = (

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

1453 )

1454

1455 class FILE_ACCESS_INFORMATION (Structure):

1456 structure = (

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

1458 )

1459

1460 class FILE_POSITION_INFORMATION (Structure):

1461 structure = (

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

1463 )

1464

1465 class FILE_MODE_INFORMATION (Structure):

1466 structure = (

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

1468 )

1469

1470 class FILE_ALIGNMENT_INFORMATION (Structure):

1471 structure = (

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

1473 )

1474

1475 class FILE_NAME_INFORMATION (Structure):

1476 structure = (

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

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

1479 ('FileName',':'),

1480 )

1481

1482 class 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

1496 class 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

1517 class SMB2SetInfo_Response(Structure):

1518 structure = (

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

1520 )

1521

1522 class 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

1532 class 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

1543 class 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

1552 class SMB2_COMPRESSION_PAYLOAD_HEADER(Structure):

1553 structure = (

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

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

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

1557 )

1558

1559 class 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

1568 class 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 )