smb3structs.py 40 KB

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