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

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

## 561 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# SECUREAUTH LABS. Copyright 2018 SecureAuth Corporation. All rights reserved.

2#

3# This software is provided under under a slightly modified version

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

5# for more information.

6#

7# Author: Alberto Solino (@agsolino)

8#

9# Description:

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

11#

12 from __future__ import division

13 from __future__ import print_function

14

15 from impacket.structure import Structure

16

17# Constants

18

19# SMB Packet

20 SMB2_PACKET_SIZE = 64

21

22# SMB Commands

23 SMB2_NEGOTIATE = 0x0000 #

24 SMB2_SESSION_SETUP = 0x0001 #

25 SMB2_LOGOFF = 0x0002 #

26 SMB2_TREE_CONNECT = 0x0003 #

27 SMB2_TREE_DISCONNECT = 0x0004 #

28 SMB2_CREATE = 0x0005 #

29 SMB2_CLOSE = 0x0006 #

30 SMB2_FLUSH = 0x0007 #

31 SMB2_READ = 0x0008 #

32 SMB2_WRITE = 0x0009 #

33 SMB2_LOCK = 0x000A #

34 SMB2_IOCTL = 0x000B #

35 SMB2_CANCEL = 0x000C #

36 SMB2_ECHO = 0x000D #

37 SMB2_QUERY_DIRECTORY = 0x000E #

38 SMB2_CHANGE_NOTIFY = 0x000F

39 SMB2_QUERY_INFO = 0x0010 #

40 SMB2_SET_INFO = 0x0011

41 SMB2_OPLOCK_BREAK = 0x0012

42

43# SMB Flags

44 SMB2_FLAGS_SERVER_TO_REDIR = 0x00000001

45 SMB2_FLAGS_ASYNC_COMMAND = 0x00000002

46 SMB2_FLAGS_RELATED_OPERATIONS = 0x00000004

47 SMB2_FLAGS_SIGNED = 0x00000008

48 SMB2_FLAGS_DFS_OPERATIONS = 0x10000000

49 SMB2_FLAGS_REPLAY_OPERATION = 0x80000000

50

51# SMB Error SymLink Flags

52 SYMLINK_FLAG_ABSOLUTE = 0x0

53 SYMLINK_FLAG_RELATIVE = 0x1

54

55# SMB2_NEGOTIATE

56# Security Modes

57 SMB2_NEGOTIATE_SIGNING_ENABLED = 0x1

58 SMB2_NEGOTIATE_SIGNING_REQUIRED = 0x2

59

60# SMB2_NEGOTIATE_CONTEXT

61 SMB2_PREAUTH_INTEGRITY_CAPABILITIES = 0x1

62 SMB2_ENCRYPTION_CAPABILITIES = 0x2

63 SMB2_COMPRESSION_CAPABILITIES = 0x3

64 SMB2_NETNAME_NEGOTIATE_CONTEXT_ID = 0x5

65

66# SMB2_COMPRESSION_CAPABILITIES

67 SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE = 0x0

68 SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED = 0x1

69

70# Compression Algorithms

71 COMPRESSION_ALGORITHM_NONE = 0x0

72 COMPRESSION_ALGORITHM_LZNT1 = 0x1

73 COMPRESSION_ALGORITHM_LZ77 = 0x2

74 COMPRESSION_ALGORITHM_LZ77_HUFFMAN = 0x3

75 COMPRESSION_ALGORITHM_PATTERN_V1 = 0x4

76

77# Capabilities

78 SMB2_GLOBAL_CAP_DFS = 0x01

79 SMB2_GLOBAL_CAP_LEASING = 0x02

80 SMB2_GLOBAL_CAP_LARGE_MTU = 0x04

81 SMB2_GLOBAL_CAP_MULTI_CHANNEL = 0x08

82 SMB2_GLOBAL_CAP_PERSISTENT_HANDLES = 0x10

83 SMB2_GLOBAL_CAP_DIRECTORY_LEASING = 0x20

84 SMB2_GLOBAL_CAP_ENCRYPTION = 0x40

85

86# Dialects

87 SMB2_DIALECT_002 = 0x0202

88 SMB2_DIALECT_21 = 0x0210

89 SMB2_DIALECT_30 = 0x0300

90 SMB2_DIALECT_302 = 0x0302 #SMB 3.0.2

91 SMB2_DIALECT_311 = 0x0311 #SMB 3.1.1

92 SMB2_DIALECT_WILDCARD = 0x02FF

93

94# SMB2_SESSION_SETUP

95# Flags

96 SMB2_SESSION_FLAG_BINDING = 0x01

97 SMB2_SESSION_FLAG_IS_GUEST = 0x01

98 SMB2_SESSION_FLAG_IS_NULL = 0x02

99 SMB2_SESSION_FLAG_ENCRYPT_DATA = 0x04

100

101# SMB2_TREE_CONNECT

102# Types

103 SMB2_SHARE_TYPE_DISK = 0x1

104 SMB2_SHARE_TYPE_PIPE = 0x2

105 SMB2_SHARE_TYPE_PRINT = 0x3

106

107# Share Flags

108 SMB2_SHAREFLAG_MANUAL_CACHING = 0x00000000

109 SMB2_SHAREFLAG_AUTO_CACHING = 0x00000010

110 SMB2_SHAREFLAG_VDO_CACHING = 0x00000020

111 SMB2_SHAREFLAG_NO_CACHING = 0x00000030

112 SMB2_SHAREFLAG_DFS = 0x00000001

113 SMB2_SHAREFLAG_DFS_ROOT = 0x00000002

114 SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS = 0x00000100

115 SMB2_SHAREFLAG_FORCE_SHARED_DELETE = 0x00000200

116 SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING = 0x00000400

117 SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM = 0x00000800

118 SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK = 0x00001000

119 SMB2_SHAREFLAG_ENABLE_HASH_V1 = 0x00002000

120 SMB2_SHAREFLAG_ENABLE_HASH_V2 = 0x00004000

121 SMB2_SHAREFLAG_ENCRYPT_DATA = 0x00008000

122

123# Capabilities

124 SMB2_SHARE_CAP_DFS = 0x00000008

125 SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY = 0x00000010

126 SMB2_SHARE_CAP_SCALEOUT = 0x00000020

127 SMB2_SHARE_CAP_CLUSTER = 0x00000040

128

129# SMB_CREATE

130# Oplocks

131 SMB2_OPLOCK_LEVEL_NONE = 0x00

132 SMB2_OPLOCK_LEVEL_II = 0x01

133 SMB2_OPLOCK_LEVEL_EXCLUSIVE = 0x08

134 SMB2_OPLOCK_LEVEL_BATCH = 0x09

135 SMB2_OPLOCK_LEVEL_LEASE = 0xFF

136

137# Impersonation Level

138 SMB2_IL_ANONYMOUS = 0x00000000

139 SMB2_IL_IDENTIFICATION = 0x00000001

140 SMB2_IL_IMPERSONATION = 0x00000002

141 SMB2_IL_DELEGATE = 0x00000003

142

143# File Attributes

144 FILE_ATTRIBUTE_ARCHIVE = 0x00000020

145 FILE_ATTRIBUTE_COMPRESSED = 0x00000800

146 FILE_ATTRIBUTE_DIRECTORY = 0x00000010

147 FILE_ATTRIBUTE_ENCRYPTED = 0x00004000

148 FILE_ATTRIBUTE_HIDDEN = 0x00000002

149 FILE_ATTRIBUTE_NORMAL = 0x00000080

150 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000

151 FILE_ATTRIBUTE_OFFLINE = 0x00001000

152 FILE_ATTRIBUTE_READONLY = 0x00000001

153 FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400

154 FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200

155 FILE_ATTRIBUTE_SYSTEM = 0x00000004

156 FILE_ATTRIBUTE_TEMPORARY = 0x00000100

157 FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x00000800

158 FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x00020000

159

160# Share Access

161 FILE_SHARE_READ = 0x00000001

162 FILE_SHARE_WRITE = 0x00000002

163 FILE_SHARE_DELETE = 0x00000004

164

165# Create Disposition

166 FILE_SUPERSEDE = 0x00000000

167 FILE_OPEN = 0x00000001

168 FILE_CREATE = 0x00000002

169 FILE_OPEN_IF = 0x00000003

170 FILE_OVERWRITE = 0x00000004

171 FILE_OVERWRITE_IF = 0x00000005

172

173# Create Options

174 FILE_DIRECTORY_FILE = 0x00000001

175 FILE_WRITE_THROUGH = 0x00000002

176 FILE_SEQUENTIAL_ONLY = 0x00000004

177 FILE_NO_INTERMEDIATE_BUFFERING = 0x00000008

178 FILE_SYNCHRONOUS_IO_ALERT = 0x00000010

179 FILE_SYNCHRONOUS_IO_NONALERT = 0x00000020

180 FILE_NON_DIRECTORY_FILE = 0x00000040

181 FILE_COMPLETE_IF_OPLOCKED = 0x00000100

182 FILE_NO_EA_KNOWLEDGE = 0x00000200

183 FILE_RANDOM_ACCESS = 0x00000800

184 FILE_DELETE_ON_CLOSE = 0x00001000

185 FILE_OPEN_BY_FILE_ID = 0x00002000

186 FILE_OPEN_FOR_BACKUP_INTENT = 0x00004000

187 FILE_NO_COMPRESSION = 0x00008000

188 FILE_RESERVE_OPFILTER = 0x00100000

189 FILE_OPEN_REPARSE_POINT = 0x00200000

190 FILE_OPEN_NO_RECALL = 0x00400000

191 FILE_OPEN_FOR_FREE_SPACE_QUERY = 0x00800000

192

193# File Access Mask / Desired Access

194 FILE_READ_DATA = 0x00000001

195 FILE_WRITE_DATA = 0x00000002

196 FILE_APPEND_DATA = 0x00000004

197 FILE_READ_EA = 0x00000008

198 FILE_WRITE_EA = 0x00000010

199 FILE_EXECUTE = 0x00000020

200 FILE_READ_ATTRIBUTES = 0x00000080

201 FILE_WRITE_ATTRIBUTES = 0x00000100

202 DELETE = 0x00010000

203 READ_CONTROL = 0x00020000

204 WRITE_DAC = 0x00040000

205 WRITE_OWNER = 0x00080000

206 SYNCHRONIZE = 0x00100000

207 ACCESS_SYSTEM_SECURITY = 0x01000000

208 MAXIMUM_ALLOWED = 0x02000000

209 GENERIC_ALL = 0x10000000

210 GENERIC_EXECUTE = 0x20000000

211 GENERIC_WRITE = 0x40000000

212 GENERIC_READ = 0x80000000

213

214# Directory Access Mask

215 FILE_LIST_DIRECTORY = 0x00000001

216 FILE_ADD_FILE = 0x00000002

217 FILE_ADD_SUBDIRECTORY = 0x00000004

218 FILE_TRAVERSE = 0x00000020

219 FILE_DELETE_CHILD = 0x00000040

220

221# Create Contexts

222 SMB2_CREATE_EA_BUFFER = 0x45787441

223 SMB2_CREATE_SD_BUFFER = 0x53656344

224 SMB2_CREATE_DURABLE_HANDLE_REQUEST = 0x44486e51

225 SMB2_CREATE_DURABLE_HANDLE_RECONNECT = 0x44486e43

226 SMB2_CREATE_ALLOCATION_SIZE = 0x416c5369

227 SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST = 0x4d784163

228 SMB2_CREATE_TIMEWARP_TOKEN = 0x54577270

229 SMB2_CREATE_QUERY_ON_DISK_ID = 0x51466964

230 SMB2_CREATE_REQUEST = 0x52714c73

231 SMB2_CREATE_REQUEST_LEASE_V2 = 0x52714c73

232 SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 = 0x44483251

233 SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 = 0x44483243

234 SMB2_CREATE_APP_INSTANCE_ID = 0x45BCA66AEFA7F74A9008FA462E144D74

235

236# Flags

237 SMB2_CREATE_FLAG_REPARSEPOINT = 0x1

238 FILE_NEED_EA = 0x80

239

240# CreateAction

241 FILE_SUPERSEDED = 0x00000000

242 FILE_OPENED = 0x00000001

243 FILE_CREATED = 0x00000002

244 FILE_OVERWRITTEN = 0x00000003

245

246# SMB2_CREATE_REQUEST_LEASE states

247 SMB2_LEASE_NONE = 0x00

248 SMB2_LEASE_READ_CACHING = 0x01

249 SMB2_LEASE_HANDLE_CACHING = 0x02

250 SMB2_LEASE_WRITE_CACHING = 0x04

251

252# SMB2_CREATE_REQUEST_LEASE_V2 Flags

253 SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET = 0x4

254

255# SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 Flags

256 SMB2_DHANDLE_FLAG_PERSISTENT = 0x02

257

258# SMB2_CLOSE

259# Flags

260 SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB = 0x0001

261

262# SMB2_READ

263# Channel

264 SMB2_CHANNEL_NONE = 0x00

265 SMB2_CHANNEL_RDMA_V1 = 0x01

266

267# SMB2_WRITE

268# Flags

269 SMB2_WRITEFLAG_WRITE_THROUGH = 0x01

270

271# Lease Break Notification

272 SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED = 0x01

273

274# SMB_LOCK

275# Flags

276 SMB2_LOCKFLAG_SHARED_LOCK = 0x01

277 SMB2_LOCKFLAG_EXCLUSIVE_LOCK = 0x02

278 SMB2_LOCKFLAG_UNLOCK = 0x04

279 SMB2_LOCKFLAG_FAIL_IMMEDIATELY = 0x10

280

281# SMB IOCTL

282# Control Codes

283 FSCTL_DFS_GET_REFERRALS = 0x00060194

284 FSCTL_PIPE_PEEK = 0x0011400C

285 FSCTL_PIPE_WAIT = 0x00110018

286 FSCTL_PIPE_TRANSCEIVE = 0x0011C017

287 FSCTL_SRV_COPYCHUNK = 0x001440F2

288 FSCTL_SRV_ENUMERATE_SNAPSHOTS = 0x00144064

289 FSCTL_SRV_REQUEST_RESUME_KEY = 0x00140078

290 FSCTL_SRV_READ_HASH = 0x001441bb

291 FSCTL_SRV_COPYCHUNK_WRITE = 0x001480F2

292 FSCTL_LMR_REQUEST_RESILIENCY = 0x001401D4

293 FSCTL_QUERY_NETWORK_INTERFACE_INFO = 0x001401FC

294 FSCTL_SET_REPARSE_POINT = 0x000900A4

295 FSCTL_DELETE_REPARSE_POINT = 0x000900AC

296 FSCTL_DFS_GET_REFERRALS_EX = 0x000601B0

297 FSCTL_FILE_LEVEL_TRIM = 0x00098208

298 FSCTL_VALIDATE_NEGOTIATE_INFO = 0x00140204

299

300# Flags

301 SMB2_0_IOCTL_IS_FSCTL = 0x1

302

303# SRV_READ_HASH

304# Type

305 SRV_HASH_TYPE_PEER_DIST = 0x01

306

307# Version

308 SRV_HASH_VER_1 = 0x1

309 SRV_HASH_VER_2 = 0x2

310

311# Retrieval Type

312 SRV_HASH_RETRIEVE_HASH_BASED = 0x01

313 SRV_HASH_RETRIEVE_FILE_BASED = 0x02

314

315# NETWORK_INTERFACE_INFO

316# Capabilities

317 RSS_CAPABLE = 0x01

318 RDMA_CAPABLE = 0x02

319

320# SMB2_QUERY_DIRECTORIES

321# Information Class

322 FILE_DIRECTORY_INFORMATION = 0x01

323 FILE_FULL_DIRECTORY_INFORMATION = 0x02

324 FILEID_FULL_DIRECTORY_INFORMATION = 0x26

325 FILE_BOTH_DIRECTORY_INFORMATION = 0x03

326 FILEID_BOTH_DIRECTORY_INFORMATION = 0x25

327 FILENAMES_INFORMATION = 0x0C

328

329# Flags

330 SMB2_RESTART_SCANS = 0x01

331 SMB2_RETURN_SINGLE_ENTRY = 0x02

332 SMB2_INDEX_SPECIFIED = 0x04

333 SMB2_REOPEN = 0x10

334

335# SMB2_CHANGE_NOTIFY

336# Flags

337 SMB2_WATCH_TREE = 0x01

338

339# Filters

340 FILE_NOTIFY_CHANGE_FILE_NAME = 0x00000001

341 FILE_NOTIFY_CHANGE_DIR_NAME = 0x00000002

342 FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x00000004

343 FILE_NOTIFY_CHANGE_SIZE = 0x00000008

344 FILE_NOTIFY_CHANGE_LAST_WRITE = 0x00000010

345 FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x00000020

346 FILE_NOTIFY_CHANGE_CREATION = 0x00000040

347 FILE_NOTIFY_CHANGE_EA = 0x00000080

348 FILE_NOTIFY_CHANGE_SECURITY = 0x00000100

349 FILE_NOTIFY_CHANGE_STREAM_NAME = 0x00000200

350 FILE_NOTIFY_CHANGE_STREAM_SIZE = 0x00000400

351 FILE_NOTIFY_CHANGE_STREAM_WRITE = 0x00000800

352

353# FILE_NOTIFY_INFORMATION

354# Actions

355 FILE_ACTION_ADDED = 0x00000001

356 FILE_ACTION_REMOVED = 0x00000002

357 FILE_ACTION_MODIFIED = 0x00000003

358 FILE_ACTION_RENAMED_OLD_NAME = 0x00000004

359 FILE_ACTION_RENAMED_NEW_NAME = 0x00000005

360

361# SMB2_QUERY_INFO

362# InfoTypes

363 SMB2_0_INFO_FILE = 0x01

364 SMB2_0_INFO_FILESYSTEM = 0x02

365 SMB2_0_INFO_SECURITY = 0x03

366 SMB2_0_INFO_QUOTA = 0x04

367

368# File Information Classes

369 SMB2_SEC_INFO_00 = 0

370 SMB2_FILE_ACCESS_INFO = 8

371 SMB2_FILE_ALIGNMENT_INFO = 17

372 SMB2_FILE_ALL_INFO = 18

373 SMB2_FILE_ALLOCATION_INFO = 19

374 SMB2_FILE_ALTERNATE_NAME_INFO = 21

375 SMB2_ATTRIBUTE_TAG_INFO = 35

376 SMB2_FILE_BASIC_INFO = 4

377 SMB2_FILE_BOTH_DIRECTORY_INFO = 3

378 SMB2_FILE_COMPRESSION_INFO = 28

379 SMB2_FILE_DIRECTORY_INFO = 1

380 SMB2_FILE_DISPOSITION_INFO = 13

381 SMB2_FILE_EA_INFO = 7

382 SMB2_FILE_END_OF_FILE_INFO = 20

383 SMB2_FULL_DIRECTORY_INFO = 2

384 SMB2_FULL_EA_INFO = 15

385 SMB2_FILE_HARDLINK_INFO = 46

386 SMB2_FILE_ID_BOTH_DIRECTORY_INFO = 37

387 SMB2_FILE_ID_FULL_DIRECTORY_INFO = 38

388 SMB2_FILE_ID_GLOBAL_TX_DIRECTORY_INFO = 50

389 SMB2_FILE_INTERNAL_INFO = 6

390 SMB2_FILE_LINK_INFO = 11

391 SMB2_FILE_MAILSLOT_QUERY_INFO = 26

392 SMB2_FILE_MAILSLOT_SET_INFO = 27

393 SMB2_FILE_MODE_INFO = 16

394 SMB2_FILE_MOVE_CLUSTER_INFO = 31

395 SMB2_FILE_NAME_INFO = 9

396 SMB2_FILE_NAMES_INFO = 12

397 SMB2_FILE_NETWORK_OPEN_INFO = 34

398 SMB2_FILE_NORMALIZED_NAME_INFO = 48

399 SMB2_FILE_OBJECT_ID_INFO = 29

400 SMB2_FILE_PIPE_INFO = 23

401 SMB2_FILE_PIPE_LOCAL_INFO = 24

402 SMB2_FILE_PIPE_REMOTE_INFO = 25

403 SMB2_FILE_POSITION_INFO = 14

404 SMB2_FILE_QUOTA_INFO = 32

405 SMB2_FILE_RENAME_INFO = 10

406 SMB2_FILE_REPARSE_POINT_INFO = 33

407 SMB2_FILE_SFIO_RESERVE_INFO = 44

408 SMB2_FILE_SHORT_NAME_INFO = 45

409 SMB2_FILE_STANDARD_INFO = 5

410 SMB2_FILE_STANDARD_LINK_INFO = 54

411 SMB2_FILE_STREAM_INFO = 22

412 SMB2_FILE_TRACKING_INFO = 36

413 SMB2_FILE_VALID_DATA_LENGTH_INFO = 39

414

415# File System Information Classes

416 SMB2_FILESYSTEM_VOLUME_INFO = 1

417 SMB2_FILESYSTEM_LABEL_INFO = 2

418 SMB2_FILESYSTEM_SIZE_INFO = 3

419 SMB2_FILESYSTEM_DEVICE_INFO = 4

420 SMB2_FILESYSTEM_ATTRIBUTE_INFO = 5

421 SMB2_FILESYSTEM_CONTROL_INFO = 6

422 SMB2_FILESYSTEM_FULL_SIZE_INFO = 7

423 SMB2_FILESYSTEM_OBJECT_ID_INFO = 8

424 SMB2_FILESYSTEM_DRIVER_PATH_INFO = 9

425 SMB2_FILESYSTEM_SECTOR_SIZE_INFO = 11

426

427# Additional information

428 OWNER_SECURITY_INFORMATION = 0x00000001

429 GROUP_SECURITY_INFORMATION = 0x00000002

430 DACL_SECURITY_INFORMATION = 0x00000004

431 SACL_SECURITY_INFORMATION = 0x00000008

432 LABEL_SECURITY_INFORMATION = 0x00000010

433

434# Flags

435 SL_RESTART_SCAN = 0x00000001

436 SL_RETURN_SINGLE_ENTRY = 0x00000002

437 SL_INDEX_SPECIFIED = 0x00000004

438

439# TRANSFORM_HEADER

440 SMB2_ENCRYPTION_AES128_CCM = 0x0001

441 SMB2_ENCRYPTION_AES128_GCM = 0x0002

442

443

444# STRUCtures

445# Represents a SMB2/3 Packet

446 class SMBPacketBase(Structure):

447 def addCommand(self,command):

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

449 raise Exception('Implement This!')

450

451 def isValidAnswer(self, status):

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

453 from . import smb3

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

455 return True

456

457 def __init__(self, data = None):

458 Structure.__init__(self,data)

459 if data is None:

460 self['TreeID'] = 0

461

462

463 class SMB2PacketAsync(SMBPacketBase):

464 structure = (

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

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

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

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

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

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

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

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

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

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

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

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

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

478 )

479

480 class SMB3PacketAsync(SMBPacketBase):

481 structure = (

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

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

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

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

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

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

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

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

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

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

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

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

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

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

496 )

497

498 class SMB2Packet(SMBPacketBase):

499 structure = (

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

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

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

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

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

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

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

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

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

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

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

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

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

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

514 )

515

516 class SMB3Packet(SMBPacketBase):

517 structure = (

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

533 )

534

535 class SMB2Error(Structure):

536 structure = (

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

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

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

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

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

542 )

543

544 class SMB2ErrorSymbolicLink(Structure):

545 structure = (

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

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

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

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

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

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

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

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

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

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

556 ('PathBuffer',':'),

557 )

558

559# SMB2_NEGOTIATE

560 class SMB2Negotiate(Structure):

561 structure = (

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

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

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

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

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

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

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

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

570 # SMB 3.1.1

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

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

573 )

574

575 class SMB311ContextData(Structure):

576 structure = (

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

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

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

580 )

581 class SMB2Negotiate_Response(Structure):

582 structure = (

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

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

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

586 # SMB 3.1.1 only. Otherwise Reserved

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

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

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

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

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

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

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

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

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

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

597 # SMB 3.1.1 only. Otherwise Reserved

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

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

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

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

602 ('Buffer',':'),

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

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

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

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

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

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

609 )

610

611# SMB2 NEGOTIATE_CONTEXT

612 class SMB2NegotiateContext(Structure):

613 structure = (

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

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

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

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

618 )

619

620# SMB2_PREAUTH_INTEGRITY_CAPABILITIES

621 class SMB2PreAuthIntegrityCapabilities(Structure):

622 structure = (

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

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

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

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

627 )

628

629# SMB2_ENCRYPTION_CAPABILITIES

630 class SMB2EncryptionCapabilities(Structure):

631 structure = (

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

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

634 )

635

636# SMB2_COMPRESSION_CAPABILITIES

637 class SMB2CompressionCapabilities(Structure):

638 structure = (

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

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

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

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

643 )

644

645# SMB2_NETNAME_NEGOTIATE_CONTEXT_ID

646 class SMB2NetNameNegotiateContextID(Structure):

647 structure = (

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

649 )

650

651# SMB2_SESSION_SETUP

652 class SMB2SessionSetup(Structure):

653 SIZE = 24

654 structure = (

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

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

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

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

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

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

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

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

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

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

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

666 ('Buffer',':'),

667 )

668

669 def __init__(self, data = None):

670 Structure.__init__(self,data)

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

672 self['AlignPad'] = ''

673

674 def getData(self):

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

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

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

678 return Structure.getData(self)

679

680

681 class SMB2SessionSetup_Response(Structure):

682 structure = (

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

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

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

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

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

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

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

690 ('Buffer',':'),

691 )

692

693# SMB2_LOGOFF

694 class SMB2Logoff(Structure):

695 structure = (

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

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

698 )

699

700

701 class SMB2Logoff_Response(Structure):

702 structure = (

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

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

705 )

706

707# SMB2_TREE_CONNECT

708 class SMB2TreeConnect(Structure):

709 SIZE = 8

710 structure = (

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

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

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

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

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

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

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

718 ('Buffer',':'),

719 )

720 def __init__(self, data = None):

721 Structure.__init__(self,data)

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

723 self['AlignPad'] = ''

724

725 class SMB2TreeConnect_Response(Structure):

726 structure = (

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

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

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

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

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

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

733 )

734

735# SMB2_TREE_DISCONNECT

736 class SMB2TreeDisconnect(Structure):

737 structure = (

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

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

740 )

741

742 class SMB2TreeDisconnect_Response(Structure):

743 structure = (

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

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

746 )

747

748# SMB2_CREATE

749 class SMB2Create(Structure):

750 SIZE = 56

751 structure = (

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

770 ('Buffer',':'),

771 )

772 def __init__(self, data = None):

773 Structure.__init__(self,data)

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

775 self['AlignPad'] = ''

776

777 class SMB2CreateContext(Structure):

778 structure = (

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

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

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

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

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

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

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

786 ('Buffer',':'),

787 )

788

789 class SMB2_FILEID(Structure):

790 structure = (

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

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

793 )

794

795 class SMB2Create_Response(Structure):

796 structure = (

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

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

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

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

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

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

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

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

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

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

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

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

809 ('FileID',':',SMB2_FILEID),

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

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

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

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

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

815 ('Buffer',':'),

816 )

817

818 class FILE_FULL_EA_INFORMATION(Structure):

819 structure = (

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

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

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

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

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

825 ('EaName',':'),

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

827 ('EaValue',':'),

828 )

829

830

831 class SMB2_CREATE_DURABLE_HANDLE_RECONNECT(Structure):

832 structure = (

833 ('Data',':',SMB2_FILEID),

834 )

835

836 class SMB2_CREATE_DURABLE_HANDLE_REQUEST(Structure):

837 structure = (

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

839 )

840

841 class SMB2_CREATE_DURABLE_HANDLE_RESPONSE(Structure):

842 structure = (

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

844 )

845

846 class SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST(Structure):

847 structure = (

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

849 )

850

851 class SMB2_CREATE_QUERY_MAXIMAL_ACCESS_RESPONSE(Structure):

852 structure = (

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

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

855 )

856

857 class SMB2_CREATE_ALLOCATION_SIZE(Structure):

858 structure = (

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

860 )

861

862 class SMB2_CREATE_TIMEWARP_TOKEN(Structure):

863 structure = (

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

865 )

866

867 class SMB2_CREATE_REQUEST_LEASE(Structure):

868 structure = (

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

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

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

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

873 )

874

875 SMB2_CREATE_RESPONSE_LEASE = SMB2_CREATE_REQUEST_LEASE

876

877 class SMB2_CREATE_REQUEST_LEASE_V2(Structure):

878 structure = (

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

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

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

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

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

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

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

886 )

887

888 SMB2_CREATE_RESPONSE_LEASE_V2 = SMB2_CREATE_REQUEST_LEASE_V2

889

890 class SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2(Structure):

891 structure = (

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

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

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

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

896 )

897

898 class SMB2_CREATE_DURABLE_HANDLE_RESPONSE_V2(Structure):

899 structure = (

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

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

902 )

903

904 class SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2(Structure):

905 structure = (

906 ('FileID',':', SMB2_FILEID),

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

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

909 )

910

911 class SMB2_CREATE_APP_INSTANCE_ID(Structure):

912 structure = (

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

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

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

916 )

917

918 class SMB2_CREATE_QUERY_ON_DISK_ID(Structure):

919 structure = (

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

921 )

922

923# Todo: Add Classes for

924#SMB2_CREATE_SD_BUFFER

925

926# SMB2_CLOSE

927 class SMB2Close(Structure):

928 structure = (

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

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

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

932 ('FileID',':', SMB2_FILEID),

933 )

934

935 class SMB2Close_Response(Structure):

936 structure = (

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

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

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

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

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

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

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

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

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

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

947 )

948

949# SMB2_FLUSH

950 class SMB2Flush(Structure):

951 structure = (

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

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

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

955 ('FileID',':',SMB2_FILEID),

956 )

957

958 class SMB2Flush_Response(Structure):

959 structure = (

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

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

962 )

963

964# SMB2_READ

965 class SMB2Read(Structure):

966 SIZE = 48

967 structure = (

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

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

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

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

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

973 ('FileID',':',SMB2_FILEID),

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

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

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

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

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

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

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

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

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

983 )

984 def __init__(self, data = None):

985 Structure.__init__(self,data)

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

987 self['AlignPad'] = ''

988

989

990 class SMB2Read_Response(Structure):

991 structure = (

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

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

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

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

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

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

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

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

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

1001 ('Buffer',':'),

1002 )

1003

1004# SMB2_WRITE

1005 class SMB2Write(Structure):

1006 SIZE = 48

1007 structure = (

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

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

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

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

1012 ('FileID',':',SMB2_FILEID),

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

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

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

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

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

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

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

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

1021 ('Buffer',':'),

1022 )

1023 def __init__(self, data = None):

1024 Structure.__init__(self,data)

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

1026 self['AlignPad'] = ''

1027

1028

1029 class SMB2Write_Response(Structure):

1030 structure = (

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

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

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

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

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

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

1037 )

1038

1039 class SMB2OplockBreakNotification(Structure):

1040 structure = (

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

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

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

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

1045 ('FileID',':',SMB2_FILEID),

1046 )

1047

1048 SMB2OplockBreakAcknowledgment = SMB2OplockBreakNotification

1049 SMB2OplockBreakResponse = SMB2OplockBreakNotification

1050

1051 class SMB2LeaseBreakNotification(Structure):

1052 structure = (

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

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

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

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

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

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

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

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

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

1062 )

1063

1064 class SMB2LeaseBreakAcknowledgement(Structure):

1065 structure = (

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

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

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

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

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

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

1072 )

1073

1074 SMB2LeaseBreakResponse = SMB2LeaseBreakAcknowledgement

1075

1076# SMB2_LOCK

1077 class SMB2_LOCK_ELEMENT(Structure):

1078 structure = (

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

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

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

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

1083 )

1084

1085 class SMB2Lock(Structure):

1086 structure = (

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

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

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

1090 ('FileID',':',SMB2_FILEID),

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

1092 ('Locks',':'),

1093 )

1094

1095 class SMB2Lock_Response(Structure):

1096 structure = (

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

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

1099 )

1100

1101

1102# SMB2_ECHO

1103 class SMB2Echo(Structure):

1104 structure = (

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

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

1107 )

1108

1109 SMB2Echo_Response = SMB2Echo

1110

1111# SMB2_CANCEL`

1112 class SMB2Cancel(Structure):

1113 structure = (

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

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

1116 )

1117

1118# SMB2_IOCTL

1119 class SMB2Ioctl(Structure):

1120 SIZE = 56

1121 structure = (

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

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

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

1125 ('FileID',':',SMB2_FILEID),

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

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

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

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

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

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

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

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

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

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

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

1137 ('Buffer',':'),

1138 )

1139 def __init__(self, data = None):

1140 Structure.__init__(self,data)

1141 if data is None:

1142 self['AlignPad'] = ''

1143

1144 class FSCTL_PIPE_WAIT_STRUCTURE(Structure):

1145 structure = (

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

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

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

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

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

1151 ('Name',':'),

1152 )

1153

1154 class SRV_COPYCHUNK_COPY(Structure):

1155 structure = (

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

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

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

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

1160 ('Chunks',':'),

1161 )

1162

1163 class SRV_COPYCHUNK(Structure):

1164 structure = (

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

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

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

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

1169 )

1170

1171 class SRV_COPYCHUNK_RESPONSE(Structure):

1172 structure = (

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

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

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

1176 )

1177

1178 class SRV_READ_HASH(Structure):

1179 structure = (

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

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

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

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

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

1185 )

1186

1187 class NETWORK_RESILIENCY_REQUEST(Structure):

1188 structure = (

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

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

1191 )

1192

1193 class VALIDATE_NEGOTIATE_INFO(Structure):

1194 structure = (

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

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

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

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

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

1200 )

1201

1202 class VALIDATE_NEGOTIATE_INFO_RESPONSE(Structure):

1203 structure = (

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

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

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

1207 ('Dialect','<H'),

1208 )

1209

1210 class SRV_SNAPSHOT_ARRAY(Structure):

1211 structure = (

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

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

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

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

1216 ('SnapShots',':'),

1217 )

1218

1219 class SRV_REQUEST_RESUME_KEY(Structure):

1220 structure = (

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

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

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

1224 ('Context',':'),

1225 )

1226

1227 class HASH_HEADER(Structure):

1228 structure = (

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

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

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

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

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

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

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

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

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

1238 ('SourceFileName',':'),

1239 )

1240

1241 class SRV_HASH_RETRIEVE_HASH_BASED(Structure):

1242 structure = (

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

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

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

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

1247 ('Buffer',':'),

1248 )

1249

1250 class SRV_HASH_RETRIEVE_FILE_BASED(Structure):

1251 structure = (

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

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

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

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

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

1257 ('Buffer',':'),

1258 )

1259

1260 class NETWORK_INTERFACE_INFO(Structure):

1261 structure = (

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

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

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

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

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

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

1268 )

1269

1270 class MOUNT_POINT_REPARSE_DATA_STRUCTURE(Structure):

1271 structure = (

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

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

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

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

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

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

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

1279 ("PathBuffer", ":")

1280 )

1281

1282 class MOUNT_POINT_REPARSE_GUID_DATA_STRUCTURE(Structure):

1283 structure = (

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

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

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

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

1288 ("DataBuffer", ":")

1289 )

1290

1291 class SMB2Ioctl_Response(Structure):

1292 structure = (

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

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

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

1296 ('FileID',':',SMB2_FILEID),

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

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

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

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

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

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

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

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

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

1306 ('Buffer',':'),

1307 )

1308

1309# SMB2_QUERY_DIRECTORY

1310 class SMB2QueryDirectory(Structure):

1311 SIZE = 32

1312 structure = (

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

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

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

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

1317 ('FileID',':',SMB2_FILEID),

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

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

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

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

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

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

1324 ('Buffer',':'),

1325 )

1326 def __init__(self, data = None):

1327 Structure.__init__(self,data)

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

1329 self['AlignPad'] = ''

1330

1331 class SMB2QueryDirectory_Response(Structure):

1332 structure = (

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

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

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

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

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

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

1339 ('Buffer',':'),

1340 )

1341

1342# SMB2_CHANGE_NOTIFY

1343 class SMB2ChangeNotify(Structure):

1344 structure = (

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

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

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

1348 ('FileID',':',SMB2_FILEID),

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

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

1351 )

1352

1353 class SMB2ChangeNotify_Response(Structure):

1354 structure = (

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

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

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

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

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

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

1361 ('Buffer',':'),

1362 )

1363

1364 class FILE_NOTIFY_INFORMATION(Structure):

1365 structure = (

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

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

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

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

1370 ('FileName',':'),

1371 )

1372

1373# SMB2_QUERY_INFO

1374 class SMB2QueryInfo(Structure):

1375 SIZE = 40

1376 structure = (

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

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

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

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

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

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

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

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

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

1386 ('FileID',':',SMB2_FILEID),

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

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

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

1390 ('Buffer',':'),

1391 )

1392 def __init__(self, data = None):

1393 Structure.__init__(self,data)

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

1395 self['AlignPad'] = ''

1396

1397

1398 class SMB2_QUERY_QUOTA_INFO(Structure):

1399 structure = (

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

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

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

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

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

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

1406 # ToDo: Check 2.2.37.1 here

1407 ('SidBuffer',':'),

1408 )

1409

1410 class SMB2QueryInfo_Response(Structure):

1411 structure = (

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

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

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

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

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

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

1418 ('Buffer',':'),

1419 )

1420

1421# SMB2_SET_INFO

1422 class SMB2SetInfo(Structure):

1423 SIZE = 32

1424 structure = (

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

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

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

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

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

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

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

1432 ('FileID',':',SMB2_FILEID),

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

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

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

1436 ('Buffer',':'),

1437 )

1438 def __init__(self, data = None):

1439 Structure.__init__(self,data)

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

1441 self['AlignPad'] = ''

1442

1443 class SMB2SetInfo_Response(Structure):

1444 structure = (

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

1446 )

1447

1448 class FILE_RENAME_INFORMATION_TYPE_2(Structure):

1449 structure = (

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

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

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

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

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

1455 ('FileName',':'),

1456 )

1457

1458 class SMB2_TRANSFORM_HEADER(Structure):

1459 structure = (

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

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

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

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

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

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

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

1467 )

1468

1469 class SMB2_COMPRESSION_TRANSFORM_HEADER(Structure):

1470 structure = (

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

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

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

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

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

1476 )

1477

1478 class SMB2_COMPRESSION_PAYLOAD_HEADER(Structure):

1479 structure = (

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

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

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

1483 )

1484

1485 class SMB2_COMPRESSION_PATTERN_PAYLOAD_V1(Structure):

1486 structure = (

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

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

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

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

1491 )

1492

1493# SMB2_FILE_INTERNAL_INFO

1494 class FileInternalInformation(Structure):

1495 structure = (

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

1497 )

1498

1499# SMB2_SEC_INFO_00

1500 class FileSecInformation(Structure):

1501 structure = (

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

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

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

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

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

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

1508 )