rex 2.0.7 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cc2f7d9e9457482ffe5b8935f8b93c4e57560cc
4
- data.tar.gz: b6e6ee56e59286b54a62d28540e92fa6363dd6ae
3
+ metadata.gz: 22c520a8b58476a0eec77db5441cfded29f8b2f3
4
+ data.tar.gz: 51e9bbbaf02d8bd0fb56dcf478afd3e309e149e8
5
5
  SHA512:
6
- metadata.gz: 17d81b1cda43811ec7acc076f4c903da5cb48316c399dd08abf2839df6e979b9de977f321e004ec1391fe86d472b450af2262f9be6a30aad8ddc30c2358a107e
7
- data.tar.gz: f921d0e028d10c3b96eaaa65eff57a39d085dae29067d7e5b64addef567aff2043fc4079801a0cf11053abea603055a3d1ffcaeb9c3bf7788644bf44c0011d1c
6
+ metadata.gz: afa5bb9719866c18f8372147f7e50c6156453a8b5b882eadd083f5bfa6d7ca7bced4ca7a6c6381bb48ca90d71ff89fc579c1a12751f319ae9de25f3b8593803e
7
+ data.tar.gz: d0c9d1a506cad9ce76cd82770939d15d6652a03a8a4714284fa20f50e0b4ab534134e52ca0bd68f318b9b85763603342199d54ed169abe93a2913eb0d6c7b15b
@@ -18,7 +18,7 @@ end
18
18
  class BoundsError < ElfError
19
19
  end
20
20
 
21
- class WtfError < ElfError
21
+ class ElfParseyError < ElfError
22
22
  end
23
23
 
24
24
  end
@@ -94,7 +94,7 @@ class JmpRegScanner < Generic
94
94
  return 3
95
95
  end
96
96
 
97
- raise "wtf"
97
+ raise "Cannot read at offset: #{offset}"
98
98
  end
99
99
 
100
100
  def _parse_ret(data)
@@ -136,7 +136,7 @@ class JmpRegScanner < Generic
136
136
  message = "push #{regname}; " + _parse_ret(elf.read(offset+2, retsize))
137
137
  offset += 2 + retsize
138
138
  else
139
- raise "wtf"
139
+ raise "Unexpected value at #{offset}"
140
140
  end
141
141
  else
142
142
  regname = Rex::Arch::X86.reg_name32(byte1 & 0x7)
@@ -18,9 +18,6 @@ end
18
18
  class BoundsError < MachError
19
19
  end
20
20
 
21
- #class WtfError < MachError
22
- #end
23
-
24
21
  class FatError < ::RuntimeError
25
22
  end
26
23
 
@@ -125,7 +125,7 @@ class JmpRegScanner < Generic
125
125
  message = "push #{regname}; " + _parse_ret(mach.read(offset+2, retsize))
126
126
  offset += 2 + retsize
127
127
  else
128
- raise "wtf"
128
+ raise "Unexpected value at offset: #{offset}"
129
129
  end
130
130
  else
131
131
  regname = Rex::Arch::X86.reg_name32(byte1 & 0x7)
@@ -21,7 +21,7 @@ end
21
21
  class BoundsError < PeError
22
22
  end
23
23
 
24
- class WtfError < PeError
24
+ class PeParseyError < PeError
25
25
  end
26
26
 
27
27
  class SkipError < PeError
@@ -1196,7 +1196,7 @@ class PeBase
1196
1196
  return section.rva_to_file_offset(rva)
1197
1197
  end
1198
1198
  end
1199
- raise WtfError, "wtf!", caller
1199
+ raise PeParseyError, "No section contains RVA", caller
1200
1200
  end
1201
1201
 
1202
1202
  def vma_to_file_offset(vma)
@@ -1205,7 +1205,7 @@ class PeBase
1205
1205
 
1206
1206
  def file_offset_to_rva(foffset)
1207
1207
  if foffset < 0
1208
- raise WtfError, "lame", caller
1208
+ raise PeParseyError, "Offset should not be less than 0. The value is: #{foffset}", caller
1209
1209
  end
1210
1210
 
1211
1211
  all_sections.each do |section|
@@ -1214,7 +1214,7 @@ class PeBase
1214
1214
  end
1215
1215
  end
1216
1216
 
1217
- raise WtfError, "wtf! #{foffset}", caller
1217
+ raise PeParseyError, "No section contains file offset #{foffset}", caller
1218
1218
  end
1219
1219
 
1220
1220
  def file_offset_to_vma(foffset)
@@ -1245,7 +1245,7 @@ class PeBase
1245
1245
  section = _find_section_by_rva(rva)
1246
1246
 
1247
1247
  if !section
1248
- raise WtfError, "Cannot find rva! #{rva}", caller
1248
+ raise PeParseyError, "Cannot find rva! #{rva}", caller
1249
1249
  end
1250
1250
 
1251
1251
  return section
@@ -30,7 +30,7 @@ module Search
30
30
 
31
31
  begin
32
32
  buf = pe.read_rva(@address, suf)
33
- rescue ::Rex::PeParsey::WtfError
33
+ rescue ::Rex::PeParsey::PeParseyError
34
34
  return
35
35
  end
36
36
 
@@ -89,7 +89,6 @@ class Registry
89
89
  request.add_tlv(TLV_TYPE_TARGET_HOST, target_host)
90
90
  request.add_tlv(TLV_TYPE_ROOT_KEY, root_key)
91
91
 
92
-
93
92
  response = client.send_request(request)
94
93
 
95
94
  return Rex::Post::Meterpreter::Extensions::Stdapi::Sys::RegistrySubsystem::RemoteRegistryKey.new(
@@ -166,6 +165,24 @@ class Registry
166
165
  return keys
167
166
  end
168
167
 
168
+ def Registry.enum_key_direct(root_key, base_key, perm = KEY_READ)
169
+ request = Packet.create_request('stdapi_registry_enum_key_direct')
170
+ keys = []
171
+
172
+ request.add_tlv(TLV_TYPE_ROOT_KEY, root_key)
173
+ request.add_tlv(TLV_TYPE_BASE_KEY, base_key)
174
+ request.add_tlv(TLV_TYPE_PERMISSION, perm)
175
+
176
+ response = client.send_request(request)
177
+
178
+ # Enumerate through all of the registry keys
179
+ response.each(TLV_TYPE_KEY_NAME) do |key_name|
180
+ keys << key_name.value
181
+ end
182
+
183
+ keys
184
+ end
185
+
169
186
  ##
170
187
  #
171
188
  # Registry value interaction
@@ -195,10 +212,55 @@ class Registry
195
212
  return true
196
213
  end
197
214
 
215
+ def Registry.set_value_direct(root_key, base_key, name, type, data, perm = KEY_WRITE)
216
+ request = Packet.create_request('stdapi_registry_set_value_direct')
217
+
218
+ request.add_tlv(TLV_TYPE_ROOT_KEY, root_key)
219
+ request.add_tlv(TLV_TYPE_BASE_KEY, base_key)
220
+ request.add_tlv(TLV_TYPE_PERMISSION, perm)
221
+ request.add_tlv(TLV_TYPE_VALUE_NAME, name)
222
+ request.add_tlv(TLV_TYPE_VALUE_TYPE, type)
223
+
224
+ if type == REG_SZ
225
+ data += "\x00"
226
+ elsif type == REG_DWORD
227
+ data = [data.to_i].pack('V')
228
+ end
229
+
230
+ request.add_tlv(TLV_TYPE_VALUE_DATA, data)
231
+
232
+ response = client.send_request(request)
233
+
234
+ true
235
+ end
236
+
198
237
  #
199
238
  # Queries the registry value supplied in name and returns an
200
239
  # initialized RegistryValue instance if a match is found.
201
240
  #
241
+ def Registry.query_value_direct(root_key, base_key, name, perm = KEY_READ)
242
+ request = Packet.create_request('stdapi_registry_query_value_direct')
243
+
244
+ request.add_tlv(TLV_TYPE_ROOT_KEY, root_key)
245
+ request.add_tlv(TLV_TYPE_BASE_KEY, base_key)
246
+ request.add_tlv(TLV_TYPE_PERMISSION, perm)
247
+ request.add_tlv(TLV_TYPE_VALUE_NAME, name)
248
+
249
+ response = client.send_request(request)
250
+
251
+ type = response.get_tlv(TLV_TYPE_VALUE_TYPE).value
252
+ data = response.get_tlv(TLV_TYPE_VALUE_DATA).value
253
+
254
+ if type == REG_SZ
255
+ data = data[0..-2]
256
+ elsif type == REG_DWORD
257
+ data = data.unpack('N')[0]
258
+ end
259
+
260
+ Rex::Post::Meterpreter::Extensions::Stdapi::Sys::RegistrySubsystem::RegistryValue.new(
261
+ client, 0, name, type, data)
262
+ end
263
+
202
264
  def Registry.query_value(hkey, name)
203
265
  request = Packet.create_request('stdapi_registry_query_value')
204
266
 
@@ -207,8 +269,8 @@ class Registry
207
269
 
208
270
  response = client.send_request(request)
209
271
 
210
- data = response.get_tlv(TLV_TYPE_VALUE_DATA).value;
211
- type = response.get_tlv(TLV_TYPE_VALUE_TYPE).value;
272
+ data = response.get_tlv(TLV_TYPE_VALUE_DATA).value
273
+ type = response.get_tlv(TLV_TYPE_VALUE_TYPE).value
212
274
 
213
275
  if (type == REG_SZ)
214
276
  data = data[0..-2]
@@ -272,6 +334,24 @@ class Registry
272
334
  return values
273
335
  end
274
336
 
337
+ def Registry.enum_value_direct(root_key, base_key, perm = KEY_READ)
338
+ request = Packet.create_request('stdapi_registry_enum_value_direct')
339
+ values = []
340
+
341
+ request.add_tlv(TLV_TYPE_ROOT_KEY, root_key)
342
+ request.add_tlv(TLV_TYPE_BASE_KEY, base_key)
343
+ request.add_tlv(TLV_TYPE_PERMISSION, perm)
344
+
345
+ response = client.send_request(request)
346
+
347
+ response.each(TLV_TYPE_VALUE_NAME) do |value_name|
348
+ values << Rex::Post::Meterpreter::Extensions::Stdapi::Sys::RegistrySubsystem::RegistryValue.new(
349
+ client, 0, value_name.value)
350
+ end
351
+
352
+ values
353
+ end
354
+
275
355
  #
276
356
  # Return the key value associated with the supplied string. This is useful
277
357
  # for converting HKLM as a string into its actual integer representation.
@@ -81,7 +81,6 @@ class Server
81
81
  "htm" => "text/htm",
82
82
  "jpg" => "image/jpeg",
83
83
  "jpeg" => "image/jpeg",
84
- "jpeg" => "image/jpeg",
85
84
  "gif" => "image/gif",
86
85
  "png" => "image/png",
87
86
  "bmp" => "image/bmp",
@@ -1,4 +1,5 @@
1
1
  # -*- coding: binary -*-
2
+
2
3
  # https://en.wikipedia.org/wiki/Printer_Job_Language
3
4
  # See external links for PJL spec
4
5
 
@@ -25,7 +26,10 @@ module Rex::Proto::PJL
25
26
  RDYMSG = "#{PREFIX} RDYMSG"
26
27
 
27
28
  FSINIT = "#{PREFIX} FSINIT"
29
+ FSQUERY = "#{PREFIX} FSQUERY"
28
30
  FSDIRLIST = "#{PREFIX} FSDIRLIST"
29
31
  FSUPLOAD = "#{PREFIX} FSUPLOAD"
32
+ FSDOWNLOAD = "#{PREFIX} FSDOWNLOAD"
33
+ FSDELETE = "#{PREFIX} FSDELETE"
30
34
 
31
35
  end
@@ -1,12 +1,11 @@
1
1
  # -*- coding: binary -*-
2
+
2
3
  # https://en.wikipedia.org/wiki/Printer_Job_Language
3
4
  # See external links for PJL spec
4
5
 
5
6
  module Rex::Proto::PJL
6
7
  class Client
7
8
 
8
- attr_reader :sock
9
-
10
9
  def initialize(sock)
11
10
  @sock = sock
12
11
  end
@@ -117,19 +116,39 @@ class Client
117
116
  @sock.put(%Q{#{FSINIT} VOLUME = "#{volume}"\n})
118
117
  end
119
118
 
119
+ # Query a file
120
+ #
121
+ # @param path [String] Remote path
122
+ # @return [Boolean] True if file exists
123
+ def fsquery(path)
124
+ if path !~ /^[0-2]:/
125
+ raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
126
+ end
127
+
128
+ file = false
129
+
130
+ @sock.put(%Q{#{FSQUERY} NAME = "#{path}"\n})
131
+
132
+ if @sock.get(DEFAULT_TIMEOUT) =~ /TYPE=(FILE|DIR)/m
133
+ file = true
134
+ end
135
+
136
+ file
137
+ end
138
+
120
139
  # List a directory
121
140
  #
122
- # @param pathname [String] Pathname
141
+ # @param path [String] Remote path
123
142
  # @param count [Fixnum] Number of entries to list
124
143
  # @return [String] Directory listing
125
- def fsdirlist(pathname, count = COUNT_MAX)
126
- if pathname !~ /^[0-2]:/
127
- raise ArgumentError, "Pathname must begin with 0:, 1:, or 2:"
144
+ def fsdirlist(path, count = COUNT_MAX)
145
+ if path !~ /^[0-2]:/
146
+ raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
128
147
  end
129
148
 
130
149
  listing = nil
131
150
 
132
- @sock.put(%Q{#{FSDIRLIST} NAME = "#{pathname}" ENTRY=1 COUNT=#{count}\n})
151
+ @sock.put(%Q{#{FSDIRLIST} NAME = "#{path}" ENTRY=1 COUNT=#{count}\n})
133
152
 
134
153
  if @sock.get(DEFAULT_TIMEOUT) =~ /ENTRY=1\r?\n(.*?)\f/m
135
154
  listing = $1
@@ -140,17 +159,16 @@ class Client
140
159
 
141
160
  # Download a file
142
161
  #
143
- # @param pathname [String] Pathname
144
- # @param size [Fixnum] Size of file
162
+ # @param path [String] Remote path
145
163
  # @return [String] File as a string
146
- def fsupload(pathname, size = SIZE_MAX)
147
- if pathname !~ /^[0-2]:/
148
- raise ArgumentError, "Pathname must begin with 0:, 1:, or 2:"
164
+ def fsupload(path)
165
+ if path !~ /^[0-2]:/
166
+ raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
149
167
  end
150
168
 
151
169
  file = nil
152
170
 
153
- @sock.put(%Q{#{FSUPLOAD} NAME = "#{pathname}" OFFSET=0 SIZE=#{size}\n})
171
+ @sock.put(%Q{#{FSUPLOAD} NAME = "#{path}" OFFSET=0 SIZE=#{SIZE_MAX}\n})
154
172
 
155
173
  if @sock.get(DEFAULT_TIMEOUT) =~ /SIZE=\d+\r?\n(.*)\f/m
156
174
  file = $1
@@ -159,5 +177,41 @@ class Client
159
177
  file
160
178
  end
161
179
 
180
+ # Upload a file
181
+ #
182
+ # @param lpath [String] Local path
183
+ # @param rpath [String] Remote path
184
+ # @return [Boolean] True if the file was uploaded
185
+ def fsdownload(lpath, rpath)
186
+ if rpath !~ /^[0-2]:/
187
+ raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
188
+ end
189
+
190
+ file = File.read(lpath)
191
+
192
+ @sock.put(
193
+ %Q{#{FSDOWNLOAD} FORMAT:BINARY SIZE=#{file.length} NAME = "#{rpath}"\n}
194
+ )
195
+
196
+ @sock.put(file)
197
+ @sock.put(UEL)
198
+
199
+ fsquery(rpath)
200
+ end
201
+
202
+ # Delete a file
203
+ #
204
+ # @param path [String] Remote path
205
+ # @return [Boolean] True if the file was deleted
206
+ def fsdelete(path)
207
+ if path !~ /^[0-2]:/
208
+ raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
209
+ end
210
+
211
+ @sock.put(%Q{#{FSDELETE} NAME = "#{path}"\n})
212
+
213
+ !fsquery(path)
214
+ end
215
+
162
216
  end
163
217
  end
@@ -4,1058 +4,1399 @@ module Proto
4
4
  module SMB
5
5
  class Constants
6
6
 
7
- require 'rex/struct2'
8
-
9
- # SMB Commands
10
- SMB_COM_CREATE_DIRECTORY = 0x00
11
- SMB_COM_DELETE_DIRECTORY = 0x01
12
- SMB_COM_OPEN = 0x02
13
- SMB_COM_CREATE = 0x03
14
- SMB_COM_CLOSE = 0x04
15
- SMB_COM_FLUSH = 0x05
16
- SMB_COM_DELETE = 0x06
17
- SMB_COM_RENAME = 0x07
18
- SMB_COM_QUERY_INFORMATION = 0x08
19
- SMB_COM_SET_INFORMATION = 0x09
20
- SMB_COM_READ = 0x0a
21
- SMB_COM_WRITE = 0x0b
22
- SMB_COM_LOCK_BYTE_RANGE = 0x0c
23
- SMB_COM_UNLOCK_BYTE_RANGE = 0x0d
24
- SMB_COM_CREATE_TEMPORARY = 0x0e
25
- SMB_COM_CREATE_NEW = 0x0f
26
- SMB_COM_CHECK_DIRECTORY = 0x10
27
- SMB_COM_PROCESS_EXIT = 0x11
28
- SMB_COM_SEEK = 0x12
29
- SMB_COM_LOCK_AND_READ = 0x13
30
- SMB_COM_WRITE_AND_UNLOCK = 0x14
31
- SMB_COM_READ_RAW = 0x1a
32
- SMB_COM_READ_MPX = 0x1b
33
- SMB_COM_READ_MPX_SECONDARY = 0x1c
34
- SMB_COM_WRITE_RAW = 0x1d
35
- SMB_COM_WRITE_MPX = 0x1e
36
- SMB_COM_WRITE_MPX_SECONDARY = 0x1f
37
- SMB_COM_WRITE_COMPLETE = 0x20
38
- SMB_COM_QUERY_SERVER = 0x21
39
- SMB_COM_SET_INFORMATION2 = 0x22
40
- SMB_COM_QUERY_INFORMATION2 = 0x23
41
- SMB_COM_LOCKING_ANDX = 0x24
42
- SMB_COM_TRANSACTION = 0x25
43
- SMB_COM_TRANSACTION_SECONDARY = 0x26
44
- SMB_COM_IOCTL = 0x27
45
- SMB_COM_IOCTL_SECONDARY = 0x28
46
- SMB_COM_COPY = 0x29
47
- SMB_COM_MOVE = 0x2a
48
- SMB_COM_ECHO = 0x2b
49
- SMB_COM_WRITE_AND_CLOSE = 0x2c
50
- SMB_COM_OPEN_ANDX = 0x2d
51
- SMB_COM_READ_ANDX = 0x2e
52
- SMB_COM_WRITE_ANDX = 0x2f
53
- SMB_COM_NEW_FILE_SIZE = 0x30
54
- SMB_COM_CLOSE_AND_TREE_DISC = 0x31
55
- SMB_COM_TRANSACTION2 = 0x32
56
- SMB_COM_TRANSACTION2_SECONDARY = 0x33
57
- SMB_COM_FIND_CLOSE2 = 0x34
58
- SMB_COM_FIND_NOTIFY_CLOSE = 0x35
59
- SMB_COM_TREE_CONNECT = 0x70
60
- SMB_COM_TREE_DISCONNECT = 0x71
61
- SMB_COM_NEGOTIATE = 0x72
62
- SMB_COM_SESSION_SETUP_ANDX = 0x73
63
- SMB_COM_LOGOFF_ANDX = 0x74
64
- SMB_COM_TREE_CONNECT_ANDX = 0x75
65
- SMB_COM_QUERY_INFORMATION_DISK = 0x80
66
- SMB_COM_SEARCH = 0x81
67
- SMB_COM_FIND = 0x82
68
- SMB_COM_FIND_UNIQUE = 0x83
69
- SMB_COM_FIND_CLOSE = 0x84
70
- SMB_COM_NT_TRANSACT = 0xa0
71
- SMB_COM_NT_TRANSACT_SECONDARY = 0xa1
72
- SMB_COM_NT_CREATE_ANDX = 0xa2
73
- SMB_COM_NT_CANCEL = 0xa4
74
- SMB_COM_NT_RENAME = 0xa5
75
- SMB_COM_OPEN_PRINT_FILE = 0xc0
76
- SMB_COM_WRITE_PRINT_FILE = 0xc1
77
- SMB_COM_CLOSE_PRINT_FILE = 0xc2
78
- SMB_COM_GET_PRINT_QUEUE = 0xc3
79
- SMB_COM_READ_BULK = 0xd8
80
- SMB_COM_WRITE_BULK = 0xd9
81
- SMB_COM_NO_ANDX_COMMAND = 0xff
82
-
83
-
84
- # SMB Version 2 Commands
85
- SMB2_OP_NEGPROT = 0x00
86
- SMB2_OP_SESSSETUP = 0x01
87
- SMB2_OP_LOGOFF = 0x02
88
- SMB2_OP_TCON = 0x03
89
- SMB2_OP_TDIS = 0x04
90
- SMB2_OP_CREATE = 0x05
91
- SMB2_OP_CLOSE = 0x06
92
- SMB2_OP_FLUSH = 0x07
93
- SMB2_OP_READ = 0x08
94
- SMB2_OP_WRITE = 0x09
95
- SMB2_OP_LOCK = 0x0a
96
- SMB2_OP_IOCTL = 0x0b
97
- SMB2_OP_CANCEL = 0x0c
98
- SMB2_OP_KEEPALIVE = 0x0d
99
- SMB2_OP_FIND = 0x0e
100
- SMB2_OP_NOTIFY = 0x0f
101
- SMB2_OP_GETINFO = 0x10
102
- SMB2_OP_SETINFO = 0x11
103
- SMB2_OP_BREAK = 0x12
104
-
105
-
106
- # SMB_COM_NT_TRANSACT Subcommands
107
- NT_TRANSACT_CREATE = 1 # File open/create
108
- NT_TRANSACT_IOCTL = 2 # Device IOCTL
109
- NT_TRANSACT_SET_SECURITY_DESC = 3 # Set security descriptor
110
- NT_TRANSACT_NOTIFY_CHANGE = 4 # Start directory watch
111
- NT_TRANSACT_RENAME = 5 # Reserved (Handle-based)
112
- NT_TRANSACT_QUERY_SECURITY_DESC = 6 # Retrieve security
113
- NT_TRANSACT_GET_USER_QUOTA = 7 # Get quota
114
- NT_TRANSACT_SET_USER_QUOTA = 8 # Set quota
115
-
116
- # Open Modes
117
- OPEN_MODE_CREAT = 0x10 # Create the file if file does not exists. Otherwise, operation fails.
118
- OPEN_MODE_EXCL = 0x00 # When used with SMB_O_CREAT, operation fails if file exists. Cannot be used with SMB_O_OPEN.
119
- OPEN_MODE_OPEN = 0x01 # Open the file if the file exists
120
- OPEN_MODE_TRUNC = 0x02 # Truncate the file if the file exists
121
-
122
- # Shared Access
123
- OPEN_SHARE_COMPAT = 0x00
124
- OPEN_SHARE_DENY_EXCL = 0x10
125
- OPEN_SHARE_DENY_WRITE = 0x20
126
- OPEN_SHARE_DENY_READEXEC = 0x30
127
- OPEN_SHARE_DENY_NONE = 0x40
128
-
129
-
130
- # File Access
131
- OPEN_ACCESS_READ = 0x00
132
- OPEN_ACCESS_WRITE = 0x01
133
- OPEN_ACCESS_READWRITE = 0x02
134
- OPEN_ACCESS_EXEC = 0x03
135
-
136
- # Create Disposition
137
- CREATE_ACCESS_SUPERSEDE = 0x00 # Replace any previously existing file
138
- CREATE_ACCESS_EXIST = 0x01 # Open existing file and fail if it does not exist
139
- CREATE_ACCESS_CREATE = 0x02 # Create the file, fail if it already exists
140
- CREATE_ACCESS_OPENCREATE = 0x03 # Open existing file or create it if it does not exist
141
- CREATE_ACCESS_OVEREXIST = 0x04 # Overwrite existing file and fail if it does not exist
142
- CREATE_ACCESS_OVERCREATE = 0x05 # Overwrite existing file or create it if it does not exist
143
-
144
-
145
- # Wildcard NetBIOS name
146
- NETBIOS_REDIR = 'CACACACACACACACACACACACACACACAAA'
147
-
148
-
149
-
150
- # 0 = open2
151
- # 1 = find_first
152
- # 2 = find_next
153
- # 3 = query_fs_info
154
- # 4 = set_fs_quota
155
- # 5 = query_path_info
156
- # 6 = set_path_info
157
- # 7 = query_file_info
158
- # 8 = set_file_info
159
- # 9 = fsctl
160
- # 10 = ioctl2
161
- # 11 = find_notify_first
162
- # 12 = find_notify_next
163
- # 13 = create_directory
164
- # 14 = session_setup
165
-
166
-
167
- # SMB_COM_TRANSACTION2 Commands
168
- TRANS2_OPEN2 = 0
169
- TRANS2_FIND_FIRST2 = 1
170
- TRANS2_FIND_NEXT2 = 2
171
- TRANS2_QUERY_FS_INFO = 3
172
- TRANS2_SET_PATH_INFO = 6
173
-
174
- TRANS2_CREATE_DIRECTORY = 13
175
-
176
- # SMB_COM_TRANSACTION2 QUERY_FS_INFO information levels
177
- SMB_INFO_ALLOCATION = 1
178
- SMB_INFO_VOLUME = 2
179
- SMB_QUERY_FS_VOLUME_INFO = 0x102
180
- SMB_QUERY_FS_SIZE_INFO = 0x103
181
- SMB_QUERY_FS_DEVICE_INFO = 0x104
182
- SMB_QUERY_FS_ATTRIBUTE_INFO = 0x105
183
-
184
- # SMB_COM_TRANSACTION2 QUERY_PATH_INFO information levels
185
- SMB_INFO_STANDARD = 1
186
- SMB_INFO_QUERY_EA_SIZE = 2
187
- SMB_INFO_QUERY_EAS_FROM_LIST = 3
188
- SMB_INFO_QUERY_ALL_EAS = 4
189
- SMB_INFO_IS_NAME_VALID = 6
190
- SMB_QUERY_FILE_BASIC_INFO = 0x101
191
- SMB_QUERY_FILE_STANDARD_INFO = 0x102
192
- SMB_QUERY_FILE_EA_INFO = 0x103
193
- SMB_QUERY_FILE_NAME_INFO = 0x104
194
- SMB_QUERY_FILE_ALL_INFO = 0x107
195
- SMB_QUERY_FILE_ALT_NAME_INFO = 0x108
196
- SMB_QUERY_FILE_STREAM_INFO = 0x109
197
- SMB_QUERY_FILE_COMPRESSION_INFO = 0x10B
198
- SMB_QUERY_FILE_UNIX_BASIC = 0x200
199
- SMB_QUERY_FILE_UNIX_LINK = 0x201
200
- SMB_INFO_PASSTHROUGH = 0x1000
201
-
202
-
203
- # Device Types
204
- FILE_DEVICE_BEEP = 0x00000001
205
- FILE_DEVICE_CD_ROM = 0x00000002
206
- FILE_DEVICE_CD_ROM_FILE_SYSTEM = 0x00000003
207
- FILE_DEVICE_CONTROLLER = 0x00000004
208
- FILE_DEVICE_DATALINK = 0x00000005
209
- FILE_DEVICE_DFS = 0x00000006
210
- FILE_DEVICE_DISK = 0x00000007
211
- FILE_DEVICE_DISK_FILE_SYSTEM = 0x00000008
212
- FILE_DEVICE_FILE_SYSTEM = 0x00000009
213
- FILE_DEVICE_INPORT_PORT = 0x0000000A
214
- FILE_DEVICE_KEYBOARD = 0x0000000B
215
- FILE_DEVICE_MAILSLOT = 0x0000000C
216
- FILE_DEVICE_MIDI_IN = 0x0000000D
217
- FILE_DEVICE_MIDI_OUT = 0x0000000E
218
- FILE_DEVICE_MOUSE = 0x0000000F
219
- FILE_DEVICE_MULTI_UNC_PROVIDER = 0x00000010
220
- FILE_DEVICE_NAMED_PIPE = 0x00000011
221
- FILE_DEVICE_NETWORK = 0x00000012
222
- FILE_DEVICE_NETWORK_BROWSER = 0x00000013
223
- FILE_DEVICE_NETWORK_FILE_SYSTEM = 0x00000014
224
- FILE_DEVICE_NULL = 0x00000015
225
- FILE_DEVICE_PARALLEL_PORT = 0x00000016
226
- FILE_DEVICE_PHYSICAL_NETCARD = 0x00000017
227
- FILE_DEVICE_PRINTER = 0x00000018
228
- FILE_DEVICE_SCANNER = 0x00000019
229
- FILE_DEVICE_SERIAL_MOUSE_PORT = 0x0000001A
230
- FILE_DEVICE_SERIAL_PORT = 0x0000001B
231
- FILE_DEVICE_SCREEN = 0x0000001C
232
- FILE_DEVICE_SOUND = 0x0000001D
233
- FILE_DEVICE_STREAMS = 0x0000001E
234
- FILE_DEVICE_TAPE = 0x0000001F
235
- FILE_DEVICE_TAPE_FILE_SYSTEM = 0x00000020
236
- FILE_DEVICE_TRANSPORT = 0x00000021
237
- FILE_DEVICE_UNKNOWN = 0x00000022
238
- FILE_DEVICE_VIDEO = 0x00000023
239
- FILE_DEVICE_VIRTUAL_DISK = 0x00000024
240
- FILE_DEVICE_WAVE_IN = 0x00000025
241
- FILE_DEVICE_WAVE_OUT = 0x00000026
242
- FILE_DEVICE_8042_PORT = 0x00000027
243
- FILE_DEVICE_NETWORK_REDIRECTOR = 0x00000028
244
- FILE_DEVICE_BATTERY = 0x00000029
245
- FILE_DEVICE_BUS_EXTENDER = 0x0000002A
246
- FILE_DEVICE_MODEM = 0x0000002B
247
- FILE_DEVICE_VDM = 0x0000002C
248
-
249
- # File and Device Attributes
250
- FILE_REMOVABLE_MEDIA = 0x00000001
251
- FILE_READ_ONLY_DEVICE = 0x00000002
252
- FILE_FLOPPY_DISKETTE = 0x00000004
253
- FILE_WRITE_ONE_MEDIA = 0x00000008
254
- FILE_REMOTE_DEVICE = 0x00000010
255
- FILE_DEVICE_IS_MOUNTED = 0x00000020
256
- FILE_VIRTUAL_VOLUME = 0x00000040
257
- FILE_CASE_SENSITIVE_SEARCH = 0x00000001
258
- FILE_CASE_PRESERVED_NAMES = 0x00000002
259
- FILE_PERSISTENT_ACLS = 0x00000004
260
- FILE_FILE_COMPRESSION = 0x00000008
261
- FILE_VOLUME_QUOTAS = 0x00000010
262
- FILE_VOLUME_IS_COMPRESSED = 0x00008000
263
-
264
- # SMB_EXT_FILE_ATTR
265
- # http://msdn.microsoft.com/en-us/library/ee878573(prot.20).aspx
266
- SMB_EXT_FILE_ATTR_READONLY = 0x00000001
267
- SMB_EXT_FILE_ATTR_HIDDEN = 0x00000002
268
- SMB_EXT_FILE_ATTR_SYSTEM = 0x00000004
269
- SMB_EXT_FILE_ATTR_DIRECTORY = 0x00000010
270
- SMB_EXT_FILE_ATTR_ARCHIVE = 0x00000020
271
- SMB_EXT_FILE_ATTR_NORMAL = 0x00000080
272
- SMB_EXT_FILE_ATTR_TEMPORARY = 0x00000100
273
- SMB_EXT_FILE_ATTR_COMPRESSED = 0x00000800
274
- SMB_EXT_FILE_POSIX_SEMANTICS = 0x01000000
275
- SMB_EXT_FILE_BACKUP_SEMANTICS = 0x02000000
276
- SMB_EXT_FILE_DELETE_ON_CLOSE = 0x04000000
277
- SMB_EXT_FILE_SEQUENTIAL_SCAN = 0x08000000
278
- SMB_EXT_FILE_RANDOM_ACCESS = 0x10000000
279
- SMB_EXT_FILE_NO_BUFFERING = 0x20000000
280
- SMB_EXT_FILE_WRITE_THROUGH = 0x80000000
281
-
282
- # SMB Error Codes
283
- SMB_STATUS_SUCCESS = 0x00000000
284
- SMB_ERROR_BUFFER_OVERFLOW = 0x80000005
285
- SMB_STATUS_MORE_PROCESSING_REQUIRED = 0xC0000016
286
- SMB_STATUS_ACCESS_DENIED = 0xC0000022
287
- SMB_STATUS_LOGON_FAILURE = 0xC000006D
288
-
289
- # SMB Dialect Compatibility
290
- DIALECT = {}
291
-
292
- DIALECT['PC NETWORK PROGRAM 1.0'] = [
293
- SMB_COM_CHECK_DIRECTORY,
294
- SMB_COM_CLOSE,
295
- SMB_COM_CLOSE_PRINT_FILE,
296
- SMB_COM_CREATE,
297
- SMB_COM_CREATE_DIRECTORY,
298
- SMB_COM_CREATE_NEW,
299
- SMB_COM_CREATE_TEMPORARY,
300
- SMB_COM_DELETE,
301
- SMB_COM_DELETE_DIRECTORY,
302
- SMB_COM_FLUSH,
303
- SMB_COM_GET_PRINT_QUEUE,
304
- SMB_COM_LOCK_BYTE_RANGE,
305
- SMB_COM_NEGOTIATE,
306
- SMB_COM_OPEN,
307
- SMB_COM_OPEN_PRINT_FILE,
308
- SMB_COM_PROCESS_EXIT,
309
- SMB_COM_QUERY_INFORMATION,
310
- SMB_COM_QUERY_INFORMATION_DISK,
311
- SMB_COM_READ,
312
- SMB_COM_RENAME,
313
- SMB_COM_SEARCH,
314
- SMB_COM_SEEK,
315
- SMB_COM_SET_INFORMATION,
316
- SMB_COM_TREE_CONNECT,
317
- SMB_COM_TREE_DISCONNECT,
318
- SMB_COM_UNLOCK_BYTE_RANGE,
319
- SMB_COM_WRITE,
320
- SMB_COM_WRITE_PRINT_FILE
321
- ]
322
-
323
- DIALECT['LANMAN 1.0'] = DIALECT['PC NETWORK PROGRAM 1.0'] + [
324
- SMB_COM_COPY,
325
- SMB_COM_ECHO,
326
- SMB_COM_FIND,
327
- SMB_COM_FIND_CLOSE,
328
- SMB_COM_FIND_UNIQUE,
329
- SMB_COM_IOCTL,
330
- SMB_COM_IOCTL_SECONDARY,
331
- SMB_COM_LOCK_AND_READ,
332
- SMB_COM_LOCKING_ANDX,
333
- SMB_COM_MOVE,
334
- SMB_COM_OPEN_ANDX,
335
- SMB_COM_QUERY_INFORMATION2,
336
- SMB_COM_READ_ANDX,
337
- SMB_COM_READ_MPX,
338
- SMB_COM_READ_RAW,
339
- SMB_COM_SESSION_SETUP_ANDX,
340
- SMB_COM_SET_INFORMATION2,
341
- SMB_COM_TRANSACTION,
342
- SMB_COM_TRANSACTION_SECONDARY,
343
- SMB_COM_TREE_CONNECT_ANDX,
344
- SMB_COM_WRITE_AND_CLOSE,
345
- SMB_COM_WRITE_AND_UNLOCK,
346
- SMB_COM_WRITE_ANDX,
347
- SMB_COM_WRITE_COMPLETE,
348
- SMB_COM_WRITE_MPX,
349
- SMB_COM_WRITE_MPX_SECONDARY,
350
- SMB_COM_WRITE_RAW
351
- ]
352
-
353
- DIALECT['LM1.2X002'] = DIALECT['LANMAN 1.0'] + [
354
- SMB_COM_FIND_CLOSE2,
355
- SMB_COM_LOGOFF_ANDX,
356
- SMB_COM_TRANSACTION2,
357
- SMB_COM_TRANSACTION2_SECONDARY
358
- ]
359
-
360
- DIALECT['NTLM 0.12'] = DIALECT['LM1.2X002'] + [
361
- SMB_COM_NT_CANCEL,
362
- SMB_COM_NT_CREATE_ANDX,
363
- SMB_COM_NT_RENAME,
364
- SMB_COM_NT_TRANSACT,
365
- SMB_COM_NT_TRANSACT_SECONDARY
366
- ]
367
-
368
- # Create a NetBIOS session packet template
369
- def self.make_nbs (template)
370
- Rex::Struct2::CStructTemplate.new(
371
- [ 'uint8', 'Type', 0 ],
372
- [ 'uint8', 'Flags', 0 ],
373
- [ 'uint16n', 'PayloadLen', 0 ],
374
- [ 'template', 'Payload', template ]
7
+ require 'rex/struct2'
8
+
9
+ # SMB Commands
10
+ SMB_COM_CREATE_DIRECTORY = 0x00
11
+ SMB_COM_DELETE_DIRECTORY = 0x01
12
+ SMB_COM_OPEN = 0x02
13
+ SMB_COM_CREATE = 0x03
14
+ SMB_COM_CLOSE = 0x04
15
+ SMB_COM_FLUSH = 0x05
16
+ SMB_COM_DELETE = 0x06
17
+ SMB_COM_RENAME = 0x07
18
+ SMB_COM_QUERY_INFORMATION = 0x08
19
+ SMB_COM_SET_INFORMATION = 0x09
20
+ SMB_COM_READ = 0x0a
21
+ SMB_COM_WRITE = 0x0b
22
+ SMB_COM_LOCK_BYTE_RANGE = 0x0c
23
+ SMB_COM_UNLOCK_BYTE_RANGE = 0x0d
24
+ SMB_COM_CREATE_TEMPORARY = 0x0e
25
+ SMB_COM_CREATE_NEW = 0x0f
26
+ SMB_COM_CHECK_DIRECTORY = 0x10
27
+ SMB_COM_PROCESS_EXIT = 0x11
28
+ SMB_COM_SEEK = 0x12
29
+ SMB_COM_LOCK_AND_READ = 0x13
30
+ SMB_COM_WRITE_AND_UNLOCK = 0x14
31
+ SMB_COM_READ_RAW = 0x1a
32
+ SMB_COM_READ_MPX = 0x1b
33
+ SMB_COM_READ_MPX_SECONDARY = 0x1c
34
+ SMB_COM_WRITE_RAW = 0x1d
35
+ SMB_COM_WRITE_MPX = 0x1e
36
+ SMB_COM_WRITE_MPX_SECONDARY = 0x1f
37
+ SMB_COM_WRITE_COMPLETE = 0x20
38
+ SMB_COM_QUERY_SERVER = 0x21
39
+ SMB_COM_SET_INFORMATION2 = 0x22
40
+ SMB_COM_QUERY_INFORMATION2 = 0x23
41
+ SMB_COM_LOCKING_ANDX = 0x24
42
+ SMB_COM_TRANSACTION = 0x25
43
+ SMB_COM_TRANSACTION_SECONDARY = 0x26
44
+ SMB_COM_IOCTL = 0x27
45
+ SMB_COM_IOCTL_SECONDARY = 0x28
46
+ SMB_COM_COPY = 0x29
47
+ SMB_COM_MOVE = 0x2a
48
+ SMB_COM_ECHO = 0x2b
49
+ SMB_COM_WRITE_AND_CLOSE = 0x2c
50
+ SMB_COM_OPEN_ANDX = 0x2d
51
+ SMB_COM_READ_ANDX = 0x2e
52
+ SMB_COM_WRITE_ANDX = 0x2f
53
+ SMB_COM_NEW_FILE_SIZE = 0x30
54
+ SMB_COM_CLOSE_AND_TREE_DISC = 0x31
55
+ SMB_COM_TRANSACTION2 = 0x32
56
+ SMB_COM_TRANSACTION2_SECONDARY = 0x33
57
+ SMB_COM_FIND_CLOSE2 = 0x34
58
+ SMB_COM_FIND_NOTIFY_CLOSE = 0x35
59
+ SMB_COM_TREE_CONNECT = 0x70
60
+ SMB_COM_TREE_DISCONNECT = 0x71
61
+ SMB_COM_NEGOTIATE = 0x72
62
+ SMB_COM_SESSION_SETUP_ANDX = 0x73
63
+ SMB_COM_LOGOFF_ANDX = 0x74
64
+ SMB_COM_TREE_CONNECT_ANDX = 0x75
65
+ SMB_COM_QUERY_INFORMATION_DISK = 0x80
66
+ SMB_COM_SEARCH = 0x81
67
+ SMB_COM_FIND = 0x82
68
+ SMB_COM_FIND_UNIQUE = 0x83
69
+ SMB_COM_FIND_CLOSE = 0x84
70
+ SMB_COM_NT_TRANSACT = 0xa0
71
+ SMB_COM_NT_TRANSACT_SECONDARY = 0xa1
72
+ SMB_COM_NT_CREATE_ANDX = 0xa2
73
+ SMB_COM_NT_CANCEL = 0xa4
74
+ SMB_COM_NT_RENAME = 0xa5
75
+ SMB_COM_OPEN_PRINT_FILE = 0xc0
76
+ SMB_COM_WRITE_PRINT_FILE = 0xc1
77
+ SMB_COM_CLOSE_PRINT_FILE = 0xc2
78
+ SMB_COM_GET_PRINT_QUEUE = 0xc3
79
+ SMB_COM_READ_BULK = 0xd8
80
+ SMB_COM_WRITE_BULK = 0xd9
81
+ SMB_COM_NO_ANDX_COMMAND = 0xff
82
+
83
+
84
+ # SMB Version 2 Commands
85
+ SMB2_OP_NEGPROT = 0x00
86
+ SMB2_OP_SESSSETUP = 0x01
87
+ SMB2_OP_LOGOFF = 0x02
88
+ SMB2_OP_TCON = 0x03
89
+ SMB2_OP_TDIS = 0x04
90
+ SMB2_OP_CREATE = 0x05
91
+ SMB2_OP_CLOSE = 0x06
92
+ SMB2_OP_FLUSH = 0x07
93
+ SMB2_OP_READ = 0x08
94
+ SMB2_OP_WRITE = 0x09
95
+ SMB2_OP_LOCK = 0x0a
96
+ SMB2_OP_IOCTL = 0x0b
97
+ SMB2_OP_CANCEL = 0x0c
98
+ SMB2_OP_KEEPALIVE = 0x0d
99
+ SMB2_OP_FIND = 0x0e
100
+ SMB2_OP_NOTIFY = 0x0f
101
+ SMB2_OP_GETINFO = 0x10
102
+ SMB2_OP_SETINFO = 0x11
103
+ SMB2_OP_BREAK = 0x12
104
+
105
+
106
+ # SMB_COM_NT_TRANSACT Subcommands
107
+ NT_TRANSACT_CREATE = 1 # File open/create
108
+ NT_TRANSACT_IOCTL = 2 # Device IOCTL
109
+ NT_TRANSACT_SET_SECURITY_DESC = 3 # Set security descriptor
110
+ NT_TRANSACT_NOTIFY_CHANGE = 4 # Start directory watch
111
+ NT_TRANSACT_RENAME = 5 # Reserved (Handle-based)
112
+ NT_TRANSACT_QUERY_SECURITY_DESC = 6 # Retrieve security
113
+ NT_TRANSACT_GET_USER_QUOTA = 7 # Get quota
114
+ NT_TRANSACT_SET_USER_QUOTA = 8 # Set quota
115
+
116
+ # NT Flags bits - cifs6.txt section 3.1.1
117
+ FLAGS_REQ_RES = 0x80
118
+ FLAGS_NOTIFY = 0x40
119
+ FLAGS_OP_LOCKS = 0x20
120
+ FLAGS_PATH_NORMALIZED = 0x10
121
+ FLAGS_CASE_SENSITIVE = 0x8
122
+ FLAGS_RESERVED = 0x4
123
+ FLAGS_POSTED = 0x2
124
+ FLAGS_LOCK_SUPPORT = 0x1
125
+
126
+ # NT Flags2 bits - cifs6.txt section 3.1.2
127
+ FLAGS2_LONG_PATH_COMPONENTS = 0x0001
128
+ FLAGS2_EXTENDED_ATTRIBUTES = 0x0002
129
+ FLAGS2_SMB_SECURITY_SIGNATURES = 0x0004
130
+ FLAGS2_SMB_SECURITY_SIGNATURES_REQUIRED = 0x0010
131
+ FLAGS2_IS_LONG_NAME = 0x0040
132
+ FLAGS2_EXTENDED_SECURITY = 0x0800
133
+ FLAGS2_DFS_PATHNAMES = 0x1000
134
+ FLAGS2_READ_PERMIT_EXECUTE = 0x2000
135
+ FLAGS2_32_BIT_ERROR_CODES = 0x4000
136
+ FLAGS2_UNICODE_STRINGS = 0x8000
137
+ FLAGS2_WIN2K_SIGNATURE = 0xC852
138
+
139
+ # SMB Negotiate Security Modes
140
+ NEG_SECURITY_SHARE = 1
141
+ NEG_SECURITY_PASSWORD = 2
142
+
143
+ # SMB Setup Actions
144
+ SMB_SETUP_GUEST = 1
145
+ SMB_SETUP_USE_LANMAN_KEY = 2
146
+
147
+ # SMB Negotiate Capabilities
148
+ # The server supports SMB_COM_READ_RAW and SMB_COM_WRITE_RAW
149
+ CAP_RAW_MODE = 0x0001
150
+ # The server supports SMB_COM_READ_MPX and SMB_COM_WRITE_MPX
151
+ CAP_MPX_MODE = 0x0002
152
+ # The server supports Unicode strings
153
+ CAP_UNICODE = 0x0004
154
+ # The server supports large files with 64 bit offsets
155
+ CAP_LARGE_FILES = 0x0008
156
+ # The server supports the SMBs particular to the NT LM 0.12 dialect
157
+ CAP_NT_SMBS = 0x0010
158
+ # The sever supports remote API requests via RPC
159
+ CAP_RPC_REMOTE_APIS = 0x0020
160
+ # The server can respond with 32 bit status codes in Status.Status
161
+ CAP_STATUS32 = 0x0040
162
+ # The server supports level 2 oplocks
163
+ CAP_LEVEL_II_OPLOCKS = 0x0080
164
+ # The server supports the SMB_COM_LOCK_AND_READ SMB
165
+ CAP_LOCK_AND_READ = 0x0100
166
+ CAP_NT_FIND = 0x0200
167
+ # This server is DFS aware
168
+ CAP_DFS = 0x1000
169
+ CAP_PASSTHRU = 0x2000
170
+ CAP_LARGE_READX = 0x4000
171
+ CAP_LARGE_WRITEX = 0x8000
172
+ CAP_UNIX_EXTENSIONS = 0x800000
173
+
174
+ # Open Modes
175
+ OPEN_MODE_CREAT = 0x10 # Create the file if file does not exists. Otherwise, operation fails.
176
+ OPEN_MODE_EXCL = 0x00 # When used with SMB_O_CREAT, operation fails if file exists. Cannot be used with SMB_O_OPEN.
177
+ OPEN_MODE_OPEN = 0x01 # Open the file if the file exists
178
+ OPEN_MODE_TRUNC = 0x02 # Truncate the file if the file exists
179
+
180
+ # Shared Access
181
+ OPEN_SHARE_COMPAT = 0x00
182
+ OPEN_SHARE_DENY_EXCL = 0x10
183
+ OPEN_SHARE_DENY_WRITE = 0x20
184
+ OPEN_SHARE_DENY_READEXEC = 0x30
185
+ OPEN_SHARE_DENY_NONE = 0x40
186
+
187
+ # OpLock Levels
188
+ NO_OPLOCK = 0x00
189
+ EXCLUSIVE_OPLOCK = 0x01
190
+ BATCH_OPLOCK = 0x02
191
+ LEVEL_II_OPLOCK = 0x03
192
+
193
+ # Dispositions, action to take if the file already exists or if the file is a new file and does not already exist
194
+ FILE_SUPERSEDE = 0x00000000
195
+ FILE_OPEN = 0x00000001
196
+ FILE_CREATE = 0x00000002
197
+ FILE_OPEN_IF = 0x00000003
198
+ FILE_OVERWRITE = 0x00000004
199
+ FILE_OVERWRITE_IF = 0x00000005
200
+
201
+ # File Access
202
+ OPEN_ACCESS_READ = 0x00
203
+ OPEN_ACCESS_WRITE = 0x01
204
+ OPEN_ACCESS_READWRITE = 0x02
205
+ OPEN_ACCESS_EXEC = 0x03
206
+
207
+ # Create Disposition
208
+ CREATE_ACCESS_SUPERSEDE = 0x00 # Replace any previously existing file
209
+ CREATE_ACCESS_EXIST = 0x01 # Open existing file and fail if it does not exist
210
+ CREATE_ACCESS_CREATE = 0x02 # Create the file, fail if it already exists
211
+ CREATE_ACCESS_OPENCREATE = 0x03 # Open existing file or create it if it does not exist
212
+ CREATE_ACCESS_OVEREXIST = 0x04 # Overwrite existing file and fail if it does not exist
213
+ CREATE_ACCESS_OVERCREATE = 0x05 # Overwrite existing file or create it if it does not exist
214
+
215
+ # Access Rights
216
+ SMB_READ_ACCESS = 1
217
+ SMB_WRITE_ACCESS = 2
218
+ SMB_APPEND_ACCESS = 4
219
+ SMB_READ_EA_ACCESS = 8
220
+ SMB_WRITE_EA_ACCESS = 0x10
221
+ SMB_EXECUTE_ACCESS = 0x20
222
+ SMB_DELETE_CHILD_ACCESS = 0x40
223
+ SMB_READ_ATTRIBUTES_ACCESS = 0x80
224
+ SMB_WRITE_ATTRIBUTES_ACCESS = 0x100
225
+ SMB_DELETE_ACCESS = 0x10000
226
+ SMB_READ_CONTROL_ACCESS = 0x20000
227
+ SMB_WRITE_DAC_ACCESS = 0x40000
228
+ SMB_WRITE_OWNER_ACCESS = 0x80000
229
+ SMB_SYNC_ACCESS = 0x100000
230
+
231
+ # Wildcard NetBIOS name
232
+ NETBIOS_REDIR = 'CACACACACACACACACACACACACACACAAA'
233
+
234
+
235
+
236
+ # 0 = open2
237
+ # 1 = find_first
238
+ # 2 = find_next
239
+ # 3 = query_fs_info
240
+ # 4 = set_fs_quota
241
+ # 5 = query_path_info
242
+ # 6 = set_path_info
243
+ # 7 = query_file_info
244
+ # 8 = set_file_info
245
+ # 9 = fsctl
246
+ # 10 = ioctl2
247
+ # 11 = find_notify_first
248
+ # 12 = find_notify_next
249
+ # 13 = create_directory
250
+ # 14 = session_setup
251
+
252
+ # SMB_COM_TRANSACTION2 SubCommands
253
+ TRANS2_OPEN2 = 0
254
+ TRANS2_FIND_FIRST2 = 1
255
+ TRANS2_FIND_NEXT2 = 2
256
+ TRANS2_QUERY_FS_INFO = 3
257
+ TRANS2_SET_FS_INFO = 4
258
+ TRANS2_QUERY_PATH_INFO = 5
259
+ TRANS2_SET_PATH_INFO = 6
260
+ TRANS2_QUERY_FILE_INFO = 7
261
+ TRANS2_SET_FILE_INFO = 8
262
+ TRANS2_FSCTL = 9
263
+ TRANS2_IOCTL2 = 10
264
+ TRANS2_FIND_NOTIFY_FIRST = 11
265
+ TRANS2_FIND_NOTIFY_NEXT = 12
266
+ TRANS2_CREATE_DIRECTORY = 13
267
+ TRANS2_SESSION_SETUP = 14
268
+ TRANS2_GET_DFS_REFERRAL = 16
269
+ TRANS2_REPORT_DFS_INCONSISTENCY = 17
270
+
271
+ # SMB_COM_TRANSACTION2 QUERY_FS_INFO information levels
272
+ SMB_INFO_ALLOCATION = 1
273
+ SMB_INFO_VOLUME = 2
274
+ SMB_QUERY_FS_VOLUME_INFO = 0x102
275
+ SMB_QUERY_FS_SIZE_INFO = 0x103
276
+ SMB_QUERY_FS_DEVICE_INFO = 0x104
277
+ SMB_QUERY_FS_ATTRIBUTE_INFO = 0x105
278
+
279
+ # SMB_COM_TRANSACTION2 QUERY_PATH_INFO information levels
280
+ SMB_INFO_STANDARD = 1
281
+ SMB_INFO_QUERY_EA_SIZE = 2
282
+ SMB_INFO_QUERY_EAS_FROM_LIST = 3
283
+ SMB_INFO_QUERY_ALL_EAS = 4
284
+ SMB_INFO_IS_NAME_VALID = 6
285
+ SMB_QUERY_FILE_BASIC_INFO = 0x101
286
+ SMB_QUERY_FILE_STANDARD_INFO = 0x102
287
+ SMB_QUERY_FILE_EA_INFO = 0x103
288
+ SMB_QUERY_FILE_NAME_INFO = 0x104
289
+ SMB_QUERY_FILE_ALL_INFO = 0x107
290
+ SMB_QUERY_FILE_ALT_NAME_INFO = 0x108
291
+ SMB_QUERY_FILE_STREAM_INFO = 0x109
292
+ SMB_QUERY_FILE_COMPRESSION_INFO = 0x10B
293
+ SMB_QUERY_FILE_UNIX_BASIC = 0x200
294
+ SMB_QUERY_FILE_UNIX_LINK = 0x201
295
+ SMB_QUERY_FILE_BASIC_INFO_ALIAS = 0x3EC # alias for 0x101
296
+ SMB_SET_FILE_BASIC_INFO_ALIAS = 0x3EC # alias for 0x101
297
+ SMB_QUERY_FILE_STANDARD_INFO_ALIAS = 0x3ED # alias for 0x102
298
+ SMB_QUERY_FILE_INTERNAL_INFO_ALIAS = 0x3EE # alias for 0x103
299
+ SMB_QUERY_FILE_EA_INFO_ALIAS = 0x3EF # alias for 0x103
300
+ SMB_QUERY_FILE_NAME_INFO_ALIAS = 0x3F1 # alias for 0x104
301
+ SMB_QUERY_FILE_NETWORK_OPEN_INFO = 0x40A
302
+ SMB_INFO_PASSTHROUGH = 0x1000
303
+
304
+ # SMB_COM_TRANSACTION2 MAX DATA COUNT information levels
305
+ SMB_QUERY_BASIC_MDC = 0x0028
306
+ SMB_QUERY_STANDARD_MDC1 = 0x0018
307
+ SMB_QUERY_STANDARD_MDC2 = 0x0102
308
+ SMB_QUERY_FILE_INTERNAL_INFO_MDC = 0x0008
309
+ SMB_QUERY_FILE_NETWORK_INFO_MDC = 0x0038
310
+
311
+ # SMB_COM_TRANS2 FIND_FIRST information levels
312
+ SMB_FIND_FILE_DIRECTORY_INFO = 0x101
313
+ SMB_FIND_FILE_FULL_DIRECTORY_INFO = 0x102
314
+ SMB_FIND_FILE_NAMES_INFO = 0x103
315
+ SMB_FIND_FILE_BOTH_DIRECTORY_INFO = 0x104
316
+ SMB_FIND_ID_FULL_DIRECTORY_INFO = 0x105
317
+ SMB_FIND_ID_BOTH_DIRECTORY_INFO = 0x106
318
+
319
+ # Device Types
320
+ FILE_DEVICE_BEEP = 0x00000001
321
+ FILE_DEVICE_CD_ROM = 0x00000002
322
+ FILE_DEVICE_CD_ROM_FILE_SYSTEM = 0x00000003
323
+ FILE_DEVICE_CONTROLLER = 0x00000004
324
+ FILE_DEVICE_DATALINK = 0x00000005
325
+ FILE_DEVICE_DFS = 0x00000006
326
+ FILE_DEVICE_DISK = 0x00000007
327
+ FILE_DEVICE_DISK_FILE_SYSTEM = 0x00000008
328
+ FILE_DEVICE_FILE_SYSTEM = 0x00000009
329
+ FILE_DEVICE_INPORT_PORT = 0x0000000A
330
+ FILE_DEVICE_KEYBOARD = 0x0000000B
331
+ FILE_DEVICE_MAILSLOT = 0x0000000C
332
+ FILE_DEVICE_MIDI_IN = 0x0000000D
333
+ FILE_DEVICE_MIDI_OUT = 0x0000000E
334
+ FILE_DEVICE_MOUSE = 0x0000000F
335
+ FILE_DEVICE_MULTI_UNC_PROVIDER = 0x00000010
336
+ FILE_DEVICE_NAMED_PIPE = 0x00000011
337
+ FILE_DEVICE_NETWORK = 0x00000012
338
+ FILE_DEVICE_NETWORK_BROWSER = 0x00000013
339
+ FILE_DEVICE_NETWORK_FILE_SYSTEM = 0x00000014
340
+ FILE_DEVICE_NULL = 0x00000015
341
+ FILE_DEVICE_PARALLEL_PORT = 0x00000016
342
+ FILE_DEVICE_PHYSICAL_NETCARD = 0x00000017
343
+ FILE_DEVICE_PRINTER = 0x00000018
344
+ FILE_DEVICE_SCANNER = 0x00000019
345
+ FILE_DEVICE_SERIAL_MOUSE_PORT = 0x0000001A
346
+ FILE_DEVICE_SERIAL_PORT = 0x0000001B
347
+ FILE_DEVICE_SCREEN = 0x0000001C
348
+ FILE_DEVICE_SOUND = 0x0000001D
349
+ FILE_DEVICE_STREAMS = 0x0000001E
350
+ FILE_DEVICE_TAPE = 0x0000001F
351
+ FILE_DEVICE_TAPE_FILE_SYSTEM = 0x00000020
352
+ FILE_DEVICE_TRANSPORT = 0x00000021
353
+ FILE_DEVICE_UNKNOWN = 0x00000022
354
+ FILE_DEVICE_VIDEO = 0x00000023
355
+ FILE_DEVICE_VIRTUAL_DISK = 0x00000024
356
+ FILE_DEVICE_WAVE_IN = 0x00000025
357
+ FILE_DEVICE_WAVE_OUT = 0x00000026
358
+ FILE_DEVICE_8042_PORT = 0x00000027
359
+ FILE_DEVICE_NETWORK_REDIRECTOR = 0x00000028
360
+ FILE_DEVICE_BATTERY = 0x00000029
361
+ FILE_DEVICE_BUS_EXTENDER = 0x0000002A
362
+ FILE_DEVICE_MODEM = 0x0000002B
363
+ FILE_DEVICE_VDM = 0x0000002C
364
+
365
+ # File and Device Attributes
366
+ FILE_REMOVABLE_MEDIA = 0x00000001
367
+ FILE_READ_ONLY_DEVICE = 0x00000002
368
+ FILE_FLOPPY_DISKETTE = 0x00000004
369
+ FILE_WRITE_ONE_MEDIA = 0x00000008
370
+ FILE_REMOTE_DEVICE = 0x00000010
371
+ FILE_DEVICE_IS_MOUNTED = 0x00000020
372
+ FILE_VIRTUAL_VOLUME = 0x00000040
373
+ FILE_CASE_SENSITIVE_SEARCH = 0x00000001
374
+ FILE_CASE_PRESERVED_NAMES = 0x00000002
375
+ FILE_PERSISTENT_ACLS = 0x00000004
376
+ FILE_FILE_COMPRESSION = 0x00000008
377
+ FILE_VOLUME_QUOTAS = 0x00000010
378
+ FILE_VOLUME_IS_COMPRESSED = 0x00008000
379
+
380
+ # SMB_EXT_FILE_ATTR
381
+ # http://msdn.microsoft.com/en-us/library/ee878573(prot.20).aspx
382
+ SMB_EXT_FILE_ATTR_READONLY = 0x00000001
383
+ SMB_EXT_FILE_ATTR_HIDDEN = 0x00000002
384
+ SMB_EXT_FILE_ATTR_SYSTEM = 0x00000004
385
+ SMB_EXT_FILE_ATTR_DIRECTORY = 0x00000010
386
+ SMB_EXT_FILE_ATTR_ARCHIVE = 0x00000020
387
+ SMB_EXT_FILE_ATTR_NORMAL = 0x00000080
388
+ SMB_EXT_FILE_ATTR_TEMPORARY = 0x00000100
389
+ SMB_EXT_FILE_ATTR_COMPRESSED = 0x00000800
390
+ SMB_EXT_FILE_POSIX_SEMANTICS = 0x01000000
391
+ SMB_EXT_FILE_BACKUP_SEMANTICS = 0x02000000
392
+ SMB_EXT_FILE_DELETE_ON_CLOSE = 0x04000000
393
+ SMB_EXT_FILE_SEQUENTIAL_SCAN = 0x08000000
394
+ SMB_EXT_FILE_RANDOM_ACCESS = 0x10000000
395
+ SMB_EXT_FILE_NO_BUFFERING = 0x20000000
396
+ SMB_EXT_FILE_WRITE_THROUGH = 0x80000000
397
+
398
+ # SMB Error Codes
399
+ SMB_STATUS_SUCCESS = 0x00000000
400
+ SMB_ERROR_BUFFER_OVERFLOW = 0x80000005
401
+ SMB_STATUS_MORE_PROCESSING_REQUIRED = 0xC0000016
402
+ SMB_STATUS_ACCESS_DENIED = 0xC0000022
403
+ SMB_STATUS_LOGON_FAILURE = 0xC000006D
404
+ SMB_STATUS_NO_SUCH_FILE = 0xC000000F
405
+ SMB_STATUS_OBJECT_NAME_NOT_FOUND = 0xc0000034
406
+ SMB_NT_STATUS_NOT_FOUND = 0xc0000225
407
+
408
+ # SMB Resource types
409
+ SMB_RESOURCE_FILE_TYPE_DISK = 0x0000
410
+ SMB_RESOURCE_FILE_TYPE_BYTE_MODE_PIPE = 0x0001
411
+ SMB_RESOURCE_FILE_TYPE_MESSAGE_MODE_PIPE = 0x0002
412
+ SMB_RESOURCE_FILE_TYPE_PRINTER = 0x0003
413
+ SMB_RESOURCE_FILE_TYPE_COMM_DEVICE = 0x0004
414
+
415
+ # Word count values
416
+ SMB_NEGOTIATE_RES_WORD_COUNT = 0x11
417
+ SMB_CLOSE_RES_WORD_COUNT = 0x00
418
+ SMB_NT_CREATE_ANDX_RES_WORD_COUNT = 0x22
419
+ SMB_READ_ANDX_RES_WORD_COUNT = 0x0c
420
+ SMB_TREE_CONN_ANDX_WORD_COUNT = 0x07
421
+ SMB_SESSION_SETUP_ANDX_RES_WORD_COUNT = 0x03
422
+ SMB_TRANS2_RES_WORD_COUNT = 0x0a
423
+
424
+ # SMB Dialect Compatibility
425
+ DIALECT = {}
426
+
427
+ DIALECT['PC NETWORK PROGRAM 1.0'] = [
428
+ SMB_COM_CHECK_DIRECTORY,
429
+ SMB_COM_CLOSE,
430
+ SMB_COM_CLOSE_PRINT_FILE,
431
+ SMB_COM_CREATE,
432
+ SMB_COM_CREATE_DIRECTORY,
433
+ SMB_COM_CREATE_NEW,
434
+ SMB_COM_CREATE_TEMPORARY,
435
+ SMB_COM_DELETE,
436
+ SMB_COM_DELETE_DIRECTORY,
437
+ SMB_COM_FLUSH,
438
+ SMB_COM_GET_PRINT_QUEUE,
439
+ SMB_COM_LOCK_BYTE_RANGE,
440
+ SMB_COM_NEGOTIATE,
441
+ SMB_COM_OPEN,
442
+ SMB_COM_OPEN_PRINT_FILE,
443
+ SMB_COM_PROCESS_EXIT,
444
+ SMB_COM_QUERY_INFORMATION,
445
+ SMB_COM_QUERY_INFORMATION_DISK,
446
+ SMB_COM_READ,
447
+ SMB_COM_RENAME,
448
+ SMB_COM_SEARCH,
449
+ SMB_COM_SEEK,
450
+ SMB_COM_SET_INFORMATION,
451
+ SMB_COM_TREE_CONNECT,
452
+ SMB_COM_TREE_DISCONNECT,
453
+ SMB_COM_UNLOCK_BYTE_RANGE,
454
+ SMB_COM_WRITE,
455
+ SMB_COM_WRITE_PRINT_FILE
456
+ ]
457
+
458
+ DIALECT['LANMAN 1.0'] = DIALECT['PC NETWORK PROGRAM 1.0'] + [
459
+ SMB_COM_COPY,
460
+ SMB_COM_ECHO,
461
+ SMB_COM_FIND,
462
+ SMB_COM_FIND_CLOSE,
463
+ SMB_COM_FIND_UNIQUE,
464
+ SMB_COM_IOCTL,
465
+ SMB_COM_IOCTL_SECONDARY,
466
+ SMB_COM_LOCK_AND_READ,
467
+ SMB_COM_LOCKING_ANDX,
468
+ SMB_COM_MOVE,
469
+ SMB_COM_OPEN_ANDX,
470
+ SMB_COM_QUERY_INFORMATION2,
471
+ SMB_COM_READ_ANDX,
472
+ SMB_COM_READ_MPX,
473
+ SMB_COM_READ_RAW,
474
+ SMB_COM_SESSION_SETUP_ANDX,
475
+ SMB_COM_SET_INFORMATION2,
476
+ SMB_COM_TRANSACTION,
477
+ SMB_COM_TRANSACTION_SECONDARY,
478
+ SMB_COM_TREE_CONNECT_ANDX,
479
+ SMB_COM_WRITE_AND_CLOSE,
480
+ SMB_COM_WRITE_AND_UNLOCK,
481
+ SMB_COM_WRITE_ANDX,
482
+ SMB_COM_WRITE_COMPLETE,
483
+ SMB_COM_WRITE_MPX,
484
+ SMB_COM_WRITE_MPX_SECONDARY,
485
+ SMB_COM_WRITE_RAW
486
+ ]
487
+
488
+ DIALECT['LM1.2X002'] = DIALECT['LANMAN 1.0'] + [
489
+ SMB_COM_FIND_CLOSE2,
490
+ SMB_COM_LOGOFF_ANDX,
491
+ SMB_COM_TRANSACTION2,
492
+ SMB_COM_TRANSACTION2_SECONDARY
493
+ ]
494
+
495
+ DIALECT['NTLM 0.12'] = DIALECT['LM1.2X002'] + [
496
+ SMB_COM_NT_CANCEL,
497
+ SMB_COM_NT_CREATE_ANDX,
498
+ SMB_COM_NT_RENAME,
499
+ SMB_COM_NT_TRANSACT,
500
+ SMB_COM_NT_TRANSACT_SECONDARY
501
+ ]
502
+
503
+ # Create a NetBIOS session packet template
504
+ def self.make_nbs (template)
505
+ Rex::Struct2::CStructTemplate.new(
506
+ [ 'uint8', 'Type', 0 ],
507
+ [ 'uint8', 'Flags', 0 ],
508
+ [ 'uint16n', 'PayloadLen', 0 ],
509
+ [ 'template', 'Payload', template ]
510
+ ).create_restraints(
511
+ [ 'Payload', 'PayloadLen', nil, true ]
512
+ )
513
+ end
514
+
515
+
516
+ # A raw NetBIOS session template
517
+ NBRAW_HDR_PKT = Rex::Struct2::CStructTemplate.new(
518
+ [ 'string', 'Payload', nil, '']
519
+ )
520
+ NBRAW_PKT = self.make_nbs(NBRAW_HDR_PKT)
521
+
522
+
523
+ # The SMB header template
524
+ SMB_HDR = Rex::Struct2::CStructTemplate.new(
525
+ [ 'uint32n', 'Magic', 0xff534d42 ],
526
+ [ 'uint8', 'Command', 0 ],
527
+ [ 'uint32v', 'ErrorClass', 0 ],
528
+ [ 'uint8', 'Flags1', 0 ],
529
+ [ 'uint16v', 'Flags2', 0 ],
530
+ [ 'uint16v', 'ProcessIDHigh', 0 ],
531
+ [ 'uint32v', 'Signature1', 0 ],
532
+ [ 'uint32v', 'Signature2', 0 ],
533
+ [ 'uint16v', 'Reserved1', 0 ],
534
+ [ 'uint16v', 'TreeID', 0 ],
535
+ [ 'uint16v', 'ProcessID', 0 ],
536
+ [ 'uint16v', 'UserID', 0 ],
537
+ [ 'uint16v', 'MultiplexID', 0 ],
538
+ [ 'uint8', 'WordCount', 0 ]
539
+ )
540
+
541
+ SMB_HDR_LENGTH = 33
542
+
543
+ # The SMB2 header template
544
+ SMB2_HDR = Rex::Struct2::CStructTemplate.new(
545
+ [ 'uint32n', 'Magic', 0xfe534d42 ],
546
+ [ 'uint16v', 'HeaderLen', 64 ],
547
+ [ 'uint16v', 'Reserved0', 0 ],
548
+ [ 'uint32v', 'NTStatus', 0 ],
549
+
550
+ [ 'uint16v', 'Opcode', 0 ],
551
+ [ 'uint16v', 'Reserved1', 0 ],
552
+
553
+ [ 'uint16v', 'Flags1', 0 ],
554
+ [ 'uint16v', 'Flags2', 0 ],
555
+
556
+ [ 'uint32v', 'ChainOffset', 0 ],
557
+
558
+ [ 'uint32v', 'SequenceHigh', 0 ],
559
+ [ 'uint32v', 'SequenceLow', 0 ],
560
+
561
+ [ 'uint32v', 'ProcessID', 0 ],
562
+ [ 'uint32v', 'TreeID', 0 ],
563
+ [ 'uint32v', 'UserIDHigh', 0 ],
564
+ [ 'uint32v', 'UserIDLow', 0 ],
565
+
566
+ [ 'uint32v', 'SignatureA', 0 ],
567
+ [ 'uint32v', 'SignatureB', 0 ],
568
+ [ 'uint32v', 'SignatureC', 0 ],
569
+ [ 'uint32v', 'SignatureD', 0 ],
570
+ [ 'string', 'Payload', nil, '']
571
+ )
572
+
573
+ # A basic SMB template to read all responses
574
+ SMB_BASE_HDR_PKT = Rex::Struct2::CStructTemplate.new(
575
+ [ 'template', 'SMB', SMB_HDR ],
576
+ [ 'uint16v', 'ByteCount', 0 ],
577
+ [ 'string', 'Payload', nil, '' ]
375
578
  ).create_restraints(
376
- [ 'Payload', 'PayloadLen', nil, true ]
579
+ [ 'Payload', 'ByteCount', nil, true ]
580
+ )
581
+ SMB_BASE_PKT = self.make_nbs(SMB_BASE_HDR_PKT)
582
+
583
+
584
+ # A SMB template for SMB Dialect negotiation
585
+ SMB_NEG_HDR_PKT = Rex::Struct2::CStructTemplate.new(
586
+
587
+ [ 'template', 'SMB', SMB_HDR ],
588
+ [ 'uint16v', 'ByteCount', 0 ],
589
+ [ 'string', 'Payload', nil, '' ]
590
+ ).create_restraints(
591
+ [ 'Payload', 'ByteCount', nil, true ]
592
+ )
593
+ SMB_NEG_PKT = self.make_nbs(SMB_NEG_HDR_PKT)
594
+
595
+
596
+ # A SMB template for SMB Dialect negotiation responses (LANMAN)
597
+ SMB_NEG_RES_LM_HDR_PKT = Rex::Struct2::CStructTemplate.new(
598
+ [ 'template', 'SMB', SMB_HDR ],
599
+ [ 'uint16v', 'Dialect', 0 ],
600
+ [ 'uint16v', 'SecurityMode', 0 ],
601
+ [ 'uint16v', 'MaxBuff', 0 ],
602
+ [ 'uint16v', 'MaxMPX', 0 ],
603
+ [ 'uint16v', 'MaxVCS', 0 ],
604
+ [ 'uint16v', 'RawMode', 0 ],
605
+ [ 'uint32v', 'SessionKey', 0 ],
606
+ [ 'uint16v', 'DosTime', 0 ],
607
+ [ 'uint16v', 'DosDate', 0 ],
608
+ [ 'uint16v', 'Timezone', 0 ],
609
+ [ 'uint16v', 'KeyLength', 0 ],
610
+ [ 'uint16v', 'Reserved1', 0 ],
611
+ [ 'uint16v', 'ByteCount', 0 ],
612
+ [ 'string', 'EncryptionKey', nil, '' ]
613
+ ).create_restraints(
614
+ [ 'EncryptionKey', 'ByteCount', nil, true ]
615
+ )
616
+ SMB_NEG_RES_LM_PKT = self.make_nbs(SMB_NEG_RES_LM_HDR_PKT)
617
+
618
+
619
+ # A SMB template for SMB Dialect negotiation responses (NTLM)
620
+ SMB_NEG_RES_NT_HDR_PKT = Rex::Struct2::CStructTemplate.new(
621
+ [ 'template', 'SMB', SMB_HDR ],
622
+ [ 'uint16v', 'Dialect', 0 ],
623
+ [ 'uint8', 'SecurityMode', 0 ],
624
+ [ 'uint16v', 'MaxMPX', 0 ],
625
+ [ 'uint16v', 'MaxVCS', 0 ],
626
+ [ 'uint32v', 'MaxBuff', 0 ],
627
+ [ 'uint32v', 'MaxRaw', 0 ],
628
+ [ 'uint32v', 'SessionKey', 0 ],
629
+ [ 'uint32v', 'Capabilities', 0 ],
630
+ [ 'uint32v', 'SystemTimeLow', 0 ],
631
+ [ 'uint32v', 'SystemTimeHigh', 0 ],
632
+ [ 'uint16v', 'ServerTimeZone', 0 ],
633
+ [ 'uint8', 'KeyLength', 0 ],
634
+ [ 'uint16v', 'ByteCount', 0 ],
635
+ [ 'string', 'Payload', nil, '' ]
636
+ ).create_restraints(
637
+ [ 'Payload', 'ByteCount', nil, true ]
638
+ )
639
+ SMB_NEG_RES_NT_PKT = self.make_nbs(SMB_NEG_RES_NT_HDR_PKT)
640
+
641
+
642
+ # A SMB template for SMB Dialect negotiation responses (ERROR)
643
+ SMB_NEG_RES_ERR_HDR_PKT = Rex::Struct2::CStructTemplate.new(
644
+ [ 'template', 'SMB', SMB_HDR ],
645
+ [ 'uint16v', 'Dialect', 0 ],
646
+ [ 'uint16v', 'ByteCount', 0 ]
647
+ )
648
+ SMB_NEG_RES_ERR_PKT = self.make_nbs(SMB_NEG_RES_ERR_HDR_PKT)
649
+
650
+
651
+ # A SMB template for SMB Session Setup responses (LANMAN/NTLMV1)
652
+ SMB_SETUP_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
653
+ [ 'template', 'SMB', SMB_HDR ],
654
+ [ 'uint8', 'AndX', 0 ],
655
+ [ 'uint8', 'Reserved1', 0 ],
656
+ [ 'uint16v', 'AndXOffset', 0 ],
657
+ [ 'uint16v', 'Action', 0 ],
658
+ [ 'uint16v', 'ByteCount', 0 ],
659
+ [ 'string', 'Payload', nil, '' ]
660
+ ).create_restraints(
661
+ [ 'Payload', 'ByteCount', nil, true ]
662
+ )
663
+ SMB_SETUP_RES_PKT = self.make_nbs(SMB_SETUP_RES_HDR_PKT)
664
+
665
+
666
+ # A SMB template for SMB Session Setup requests (LANMAN)
667
+ SMB_SETUP_LANMAN_HDR_PKT = Rex::Struct2::CStructTemplate.new(
668
+ [ 'template', 'SMB', SMB_HDR ],
669
+ [ 'uint8', 'AndX', 0 ],
670
+ [ 'uint8', 'Reserved1', 0 ],
671
+ [ 'uint16v', 'AndXOffset', 0 ],
672
+ [ 'uint16v', 'MaxBuff', 0 ],
673
+ [ 'uint16v', 'MaxMPX', 0 ],
674
+ [ 'uint16v', 'VCNum', 0 ],
675
+ [ 'uint32v', 'SessionKey', 0 ],
676
+ [ 'uint16v', 'PasswordLen', 0 ],
677
+ [ 'uint32v', 'Reserved2', 0 ],
678
+ [ 'uint16v', 'ByteCount', 0 ],
679
+ [ 'string', 'Payload', nil, '' ]
680
+ ).create_restraints(
681
+ [ 'Payload', 'ByteCount', nil, true ]
682
+ )
683
+ SMB_SETUP_LANMAN_PKT = self.make_nbs(SMB_SETUP_LANMAN_HDR_PKT)
684
+
685
+
686
+ # A SMB template for SMB Session Setup requests (NTLMV1)
687
+ SMB_SETUP_NTLMV1_HDR_PKT = Rex::Struct2::CStructTemplate.new(
688
+ [ 'template', 'SMB', SMB_HDR ],
689
+ [ 'uint8', 'AndX', 0 ],
690
+ [ 'uint8', 'Reserved1', 0 ],
691
+ [ 'uint16v', 'AndXOffset', 0 ],
692
+ [ 'uint16v', 'MaxBuff', 0 ],
693
+ [ 'uint16v', 'MaxMPX', 0 ],
694
+ [ 'uint16v', 'VCNum', 0 ],
695
+ [ 'uint32v', 'SessionKey', 0 ],
696
+ [ 'uint16v', 'PasswordLenLM', 0 ],
697
+ [ 'uint16v', 'PasswordLenNT', 0 ],
698
+ [ 'uint32v', 'Reserved2', 0 ],
699
+ [ 'uint32v', 'Capabilities', 0 ],
700
+ [ 'uint16v', 'ByteCount', 0 ],
701
+ [ 'string', 'Payload', nil, '' ]
702
+ ).create_restraints(
703
+ [ 'Payload', 'ByteCount', nil, true ]
704
+ )
705
+ SMB_SETUP_NTLMV1_PKT = self.make_nbs(SMB_SETUP_NTLMV1_HDR_PKT)
706
+
707
+
708
+ # A SMB template for SMB Session Setup requests (When extended security is being used)
709
+ SMB_SETUP_NTLMV2_HDR_PKT = Rex::Struct2::CStructTemplate.new(
710
+ [ 'template', 'SMB', SMB_HDR ],
711
+ [ 'uint8', 'AndX', 0 ],
712
+ [ 'uint8', 'Reserved1', 0 ],
713
+ [ 'uint16v', 'AndXOffset', 0 ],
714
+ [ 'uint16v', 'MaxBuff', 0 ],
715
+ [ 'uint16v', 'MaxMPX', 0 ],
716
+ [ 'uint16v', 'VCNum', 0 ],
717
+ [ 'uint32v', 'SessionKey', 0 ],
718
+ [ 'uint16v', 'SecurityBlobLen', 0 ],
719
+ [ 'uint32v', 'Reserved2', 0 ],
720
+ [ 'uint32v', 'Capabilities', 0 ],
721
+ [ 'uint16v', 'ByteCount', 0 ],
722
+ [ 'string', 'Payload', nil, '' ]
723
+ ).create_restraints(
724
+ [ 'Payload', 'ByteCount', nil, true ]
725
+ )
726
+ SMB_SETUP_NTLMV2_PKT = self.make_nbs(SMB_SETUP_NTLMV2_HDR_PKT)
727
+
728
+
729
+ # A SMB template for SMB Session Setup responses (When extended security is being used)
730
+ SMB_SETUP_NTLMV2_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
731
+ [ 'template', 'SMB', SMB_HDR ],
732
+ [ 'uint8', 'AndX', 0 ],
733
+ [ 'uint8', 'Reserved1', 0 ],
734
+ [ 'uint16v', 'AndXOffset', 0 ],
735
+ [ 'uint16v', 'Action', 0 ],
736
+ [ 'uint16v', 'SecurityBlobLen', 0 ],
737
+ [ 'uint16v', 'ByteCount', 0 ],
738
+ [ 'string', 'Payload', nil, '' ]
739
+ ).create_restraints(
740
+ [ 'Payload', 'ByteCount', nil, true ]
741
+ )
742
+ SMB_SETUP_NTLMV2_RES_PKT = self.make_nbs(SMB_SETUP_NTLMV2_RES_HDR_PKT)
743
+
744
+
745
+ # A SMB template for SMB Tree Connect requests
746
+ SMB_TREE_CONN_HDR_PKT = Rex::Struct2::CStructTemplate.new(
747
+ [ 'template', 'SMB', SMB_HDR ],
748
+ [ 'uint8', 'AndX', 0 ],
749
+ [ 'uint8', 'Reserved1', 0 ],
750
+ [ 'uint16v', 'AndXOffset', 0 ],
751
+ [ 'uint16v', 'Flags', 0 ],
752
+ [ 'uint16v', 'PasswordLen', 0 ],
753
+ [ 'uint16v', 'ByteCount', 0 ],
754
+ [ 'string', 'Payload', nil, '' ]
755
+ ).create_restraints(
756
+ [ 'Payload', 'ByteCount', nil, true ]
757
+ )
758
+ SMB_TREE_CONN_PKT = self.make_nbs(SMB_TREE_CONN_HDR_PKT)
759
+
760
+
761
+ # A SMB template for SMB Tree Connect requests
762
+ SMB_TREE_CONN_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
763
+ [ 'template', 'SMB', SMB_HDR ],
764
+ [ 'uint8', 'AndX', 0 ],
765
+ [ 'uint8', 'Reserved1', 0 ],
766
+ [ 'uint16v', 'AndXOffset', 0 ],
767
+ [ 'uint16v', 'OptionalSupport', 0 ],
768
+ [ 'string', 'SupportWords', nil, '' ],
769
+ [ 'uint16v', 'ByteCount', 0 ],
770
+ [ 'string', 'Payload', nil, '' ]
771
+ ).create_restraints(
772
+ [ 'Payload', 'ByteCount', nil, true ]
773
+ )
774
+ SMB_TREE_CONN_RES_PKT = self.make_nbs(SMB_TREE_CONN_RES_HDR_PKT)
775
+
776
+
777
+ # A SMB template for SMB Tree Disconnect requests
778
+ SMB_TREE_DISCONN_HDR_PKT = Rex::Struct2::CStructTemplate.new(
779
+ [ 'template', 'SMB', SMB_HDR ],
780
+ [ 'uint16v', 'ByteCount', 0 ],
781
+ [ 'string', 'Payload', nil, '' ]
782
+ ).create_restraints(
783
+ [ 'Payload', 'ByteCount', nil, true ]
784
+ )
785
+ SMB_TREE_DISCONN_PKT = self.make_nbs(SMB_TREE_DISCONN_HDR_PKT)
786
+
787
+
788
+ # A SMB template for SMB Tree Disconnect requests
789
+ SMB_TREE_DISCONN_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
790
+ [ 'template', 'SMB', SMB_HDR ],
791
+ [ 'uint16v', 'ByteCount', 0 ],
792
+ [ 'string', 'Payload', nil, '' ]
793
+ ).create_restraints(
794
+ [ 'Payload', 'ByteCount', nil, true ]
795
+ )
796
+ SMB_TREE_DISCONN_RES_PKT = self.make_nbs(SMB_TREE_DISCONN_RES_HDR_PKT)
797
+
798
+
799
+ # A SMB template for SMB Transaction requests
800
+ SMB_TRANS_HDR_PKT = Rex::Struct2::CStructTemplate.new(
801
+ [ 'template', 'SMB', SMB_HDR ],
802
+ [ 'uint16v', 'ParamCountTotal', 0 ],
803
+ [ 'uint16v', 'DataCountTotal', 0 ],
804
+ [ 'uint16v', 'ParamCountMax', 0 ],
805
+ [ 'uint16v', 'DataCountMax', 0 ],
806
+ [ 'uint8', 'SetupCountMax', 0 ],
807
+ [ 'uint8', 'Reserved1', 0 ],
808
+ [ 'uint16v', 'Flags', 0 ],
809
+ [ 'uint32v', 'Timeout', 0 ],
810
+ [ 'uint16v', 'Reserved2', 0 ],
811
+ [ 'uint16v', 'ParamCount', 0 ],
812
+ [ 'uint16v', 'ParamOffset', 0 ],
813
+ [ 'uint16v', 'DataCount', 0 ],
814
+ [ 'uint16v', 'DataOffset', 0 ],
815
+ [ 'uint8', 'SetupCount', 0 ],
816
+ [ 'uint8', 'Reserved3', 0 ],
817
+ [ 'string', 'SetupData', nil, '' ],
818
+ [ 'uint16v', 'ByteCount', 0 ],
819
+ [ 'string', 'Payload', nil, '' ]
820
+ ).create_restraints(
821
+ [ 'Payload', 'ByteCount', nil, true ]
822
+ )
823
+ SMB_TRANS_PKT = self.make_nbs(SMB_TRANS_HDR_PKT)
824
+
825
+
826
+ # A SMB template for SMB Transaction responses
827
+ SMB_TRANS_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
828
+ [ 'template', 'SMB', SMB_HDR ],
829
+ [ 'uint16v', 'ParamCountTotal', 0 ],
830
+ [ 'uint16v', 'DataCountTotal', 0 ],
831
+ [ 'uint16v', 'Reserved1', 0 ],
832
+ [ 'uint16v', 'ParamCount', 0 ],
833
+ [ 'uint16v', 'ParamOffset', 0 ],
834
+ [ 'uint16v', 'ParamDisplace', 0 ],
835
+ [ 'uint16v', 'DataCount', 0 ],
836
+ [ 'uint16v', 'DataOffset', 0 ],
837
+ [ 'uint16v', 'DataDisplace', 0 ],
838
+ [ 'uint8', 'SetupCount', 0 ],
839
+ [ 'uint8', 'Reserved2', 0 ],
840
+ [ 'string', 'SetupData', nil, '' ],
841
+ [ 'uint16v', 'ByteCount', 0 ],
842
+ [ 'string', 'Payload', nil, '' ]
843
+ ).create_restraints(
844
+ [ 'Payload', 'ByteCount', nil, true ]
845
+ )
846
+ SMB_TRANS_RES_PKT = self.make_nbs(SMB_TRANS_RES_HDR_PKT)
847
+
848
+ SMB_TRANS_RES_PKT_LENGTH = SMB_HDR_LENGTH + 22
849
+
850
+ # A SMB template for SMB Transaction2 requests
851
+ SMB_TRANS2_HDR_PKT = Rex::Struct2::CStructTemplate.new(
852
+ [ 'template', 'SMB', SMB_HDR ],
853
+ [ 'uint16v', 'ParamCountTotal', 0 ],
854
+ [ 'uint16v', 'DataCountTotal', 0 ],
855
+ [ 'uint16v', 'ParamCountMax', 0 ],
856
+ [ 'uint16v', 'DataCountMax', 0 ],
857
+ [ 'uint8', 'SetupCountMax', 0 ],
858
+ [ 'uint8', 'Reserved1', 0 ],
859
+ [ 'uint16v', 'Flags', 0 ],
860
+ [ 'uint32v', 'Timeout', 0 ],
861
+ [ 'uint16v', 'Reserved2', 0 ],
862
+ [ 'uint16v', 'ParamCount', 0 ],
863
+ [ 'uint16v', 'ParamOffset', 0 ],
864
+ [ 'uint16v', 'DataCount', 0 ],
865
+ [ 'uint16v', 'DataOffset', 0 ],
866
+ [ 'uint8', 'SetupCount', 0 ],
867
+ [ 'uint8', 'Reserved3', 0 ],
868
+ [ 'string', 'SetupData', nil, '' ],
869
+ [ 'uint16v', 'ByteCount', 0 ],
870
+ [ 'string', 'Payload', nil, '' ]
871
+ ).create_restraints(
872
+ [ 'Payload', 'ByteCount', nil, true ]
873
+ )
874
+ SMB_TRANS2_PKT = self.make_nbs(SMB_TRANS2_HDR_PKT)
875
+
876
+
877
+ # A SMB template for SMB NTTransaction requests
878
+ SMB_NTTRANS_HDR_PKT = Rex::Struct2::CStructTemplate.new(
879
+ [ 'template', 'SMB', SMB_HDR ],
880
+ [ 'uint8', 'SetupCountMax', 0 ],
881
+ [ 'uint16v', 'Reserved1', 0 ],
882
+ [ 'uint32v', 'ParamCountTotal', 0 ],
883
+ [ 'uint32v', 'DataCountTotal', 0 ],
884
+ [ 'uint32v', 'ParamCountMax', 0 ],
885
+ [ 'uint32v', 'DataCountMax', 0 ],
886
+ [ 'uint32v', 'ParamCount', 0 ],
887
+ [ 'uint32v', 'ParamOffset', 0 ],
888
+ [ 'uint32v', 'DataCount', 0 ],
889
+ [ 'uint32v', 'DataOffset', 0 ],
890
+ [ 'uint8', 'SetupCount', 0 ],
891
+ [ 'uint16v', 'Subcommand', 0 ],
892
+ [ 'string', 'SetupData', nil, '' ],
893
+ [ 'uint16v', 'ByteCount', 0 ],
894
+ [ 'string', 'Payload', nil, '' ]
895
+ ).create_restraints(
896
+ [ 'Payload', 'ByteCount', nil, true ]
897
+ )
898
+ SMB_NTTRANS_PKT = self.make_nbs(SMB_NTTRANS_HDR_PKT)
899
+
900
+
901
+ # A SMB template for SMB NTTransaction responses
902
+ SMB_NTTRANS_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
903
+ [ 'template', 'SMB', SMB_HDR ],
904
+ [ 'uint8', 'Reserved1', 0 ],
905
+ [ 'uint16v', 'Reserved2', 0 ],
906
+ [ 'uint32v', 'ParamCountTotal', 0 ],
907
+ [ 'uint32v', 'DataCountTotal', 0 ],
908
+ [ 'uint32v', 'ParamCount', 0 ],
909
+ [ 'uint32v', 'ParamOffset', 0 ],
910
+ [ 'uint32v', 'ParamDisplace', 0 ],
911
+ [ 'uint32v', 'DataCount', 0 ],
912
+ [ 'uint32v', 'DataOffset', 0 ],
913
+ [ 'uint32v', 'DataDisplace', 0 ],
914
+ [ 'uint8', 'Reserved3', 0 ],
915
+ [ 'uint16v', 'ByteCount', 0 ],
916
+ [ 'string', 'Payload', nil, '' ]
917
+ ).create_restraints(
918
+ [ 'Payload', 'ByteCount', nil, true ]
919
+ )
920
+ SMB_NTTRANS_RES_PKT = self.make_nbs(SMB_NTTRANS_RES_HDR_PKT)
921
+
922
+ # A SMB template for SMB NTTransaction_Secondary requests
923
+ SMB_NTTRANS_SECONDARY_HDR_PKT = Rex::Struct2::CStructTemplate.new(
924
+ [ 'template', 'SMB', SMB_HDR ],
925
+ [ 'uint8', 'Reserved1', 0 ],
926
+ [ 'uint16v', 'Reserved2', 0 ],
927
+ [ 'uint32v', 'ParamCountTotal', 0 ],
928
+ [ 'uint32v', 'DataCountTotal', 0 ],
929
+ [ 'uint32v', 'ParamCount', 0 ],
930
+ [ 'uint32v', 'ParamOffset', 0 ],
931
+ [ 'uint32v', 'ParamDisplace', 0 ],
932
+ [ 'uint32v', 'DataCount', 0 ],
933
+ [ 'uint32v', 'DataOffset', 0 ],
934
+ [ 'uint32v', 'DataDisplace', 0 ],
935
+ [ 'uint8', 'SetupCount', 0 ],
936
+ [ 'string', 'SetupData', nil, '' ],
937
+ [ 'uint16v', 'ByteCount', 0 ],
938
+ [ 'string', 'Payload', nil, '' ]
939
+ ).create_restraints(
940
+ [ 'Payload', 'ByteCount', nil, true ]
941
+ )
942
+ SMB_NTTRANS_SECONDARY_PKT = self.make_nbs(SMB_NTTRANS_SECONDARY_HDR_PKT)
943
+
944
+ # A SMB template for SMB Create requests
945
+ SMB_CREATE_HDR_PKT = Rex::Struct2::CStructTemplate.new(
946
+ [ 'template', 'SMB', SMB_HDR ],
947
+ [ 'uint8', 'AndX', 0 ],
948
+ [ 'uint8', 'Reserved1', 0 ],
949
+ [ 'uint16v', 'AndXOffset', 0 ],
950
+ [ 'uint8', 'Reserved2', 0 ],
951
+ [ 'uint16v', 'FileNameLen', 0 ],
952
+ [ 'uint32v', 'CreateFlags', 0 ],
953
+ [ 'uint32v', 'RootFileID', 0 ],
954
+ [ 'uint32v', 'AccessMask', 0 ],
955
+ [ 'uint32v', 'AllocLow', 0 ],
956
+ [ 'uint32v', 'AllocHigh', 0 ],
957
+ [ 'uint32v', 'Attributes', 0 ],
958
+ [ 'uint32v', 'ShareAccess', 0 ],
959
+ [ 'uint32v', 'Disposition', 0 ],
960
+ [ 'uint32v', 'CreateOptions', 0 ],
961
+ [ 'uint32v', 'Impersonation', 0 ],
962
+ [ 'uint8', 'SecurityFlags', 0 ],
963
+ [ 'uint16v', 'ByteCount', 0 ],
964
+ [ 'string', 'Payload', nil, '' ]
965
+ ).create_restraints(
966
+ [ 'Payload', 'ByteCount', nil, true ]
967
+ )
968
+ SMB_CREATE_PKT = self.make_nbs(SMB_CREATE_HDR_PKT)
969
+
970
+
971
+ # A SMB template for SMB Create responses
972
+ SMB_CREATE_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
973
+ [ 'template', 'SMB', SMB_HDR ],
974
+ [ 'uint8', 'AndX', 0 ],
975
+ [ 'uint8', 'Reserved1', 0 ],
976
+ [ 'uint16v', 'AndXOffset', 0 ],
977
+ [ 'uint8', 'OpLock', 0 ],
978
+ [ 'uint16v', 'FileID', 0 ],
979
+ [ 'uint32v', 'Action', 0 ],
980
+ [ 'uint32v', 'CreateTimeLow', 0 ],
981
+ [ 'uint32v', 'CreateTimeHigh', 0 ],
982
+ [ 'uint32v', 'AccessTimeLow', 0 ],
983
+ [ 'uint32v', 'AccessTimeHigh', 0 ],
984
+ [ 'uint32v', 'WriteTimeLow', 0 ],
985
+ [ 'uint32v', 'WriteTimeHigh', 0 ],
986
+ [ 'uint32v', 'ChangeTimeLow', 0 ],
987
+ [ 'uint32v', 'ChangeTimeHigh', 0 ],
988
+ [ 'uint32v', 'Attributes', 0 ],
989
+ [ 'uint32v', 'AllocLow', 0 ],
990
+ [ 'uint32v', 'AllocHigh', 0 ],
991
+ [ 'uint32v', 'EOFLow', 0 ],
992
+ [ 'uint32v', 'EOFHigh', 0 ],
993
+ [ 'uint16v', 'FileType', 0 ],
994
+ [ 'uint16v', 'IPCState', 0 ],
995
+ [ 'uint8', 'IsDirectory', 0 ],
996
+ [ 'uint16v', 'ByteCount', 0 ],
997
+ [ 'string', 'Payload', nil, '' ]
998
+ ).create_restraints(
999
+ [ 'Payload', 'ByteCount', nil, true ]
1000
+ )
1001
+ SMB_CREATE_RES_PKT = self.make_nbs(SMB_CREATE_RES_HDR_PKT)
1002
+
1003
+ # A SMB template for SMB Create ANDX responses
1004
+ SMB_CREATE_ANDX_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1005
+ [ 'template', 'SMB', SMB_HDR ],
1006
+ [ 'uint8', 'AndX', 0 ],
1007
+ [ 'uint8', 'Reserved1', 0 ],
1008
+ [ 'uint16v', 'AndXOffset', 0 ],
1009
+ [ 'uint8', 'OpLock', 0 ],
1010
+ [ 'uint16v', 'FileID', 0 ],
1011
+ [ 'uint32v', 'Action', 0 ],
1012
+ [ 'uint32v', 'CreateTimeLow', 0 ],
1013
+ [ 'uint32v', 'CreateTimeHigh', 0 ],
1014
+ [ 'uint32v', 'AccessTimeLow', 0 ],
1015
+ [ 'uint32v', 'AccessTimeHigh', 0 ],
1016
+ [ 'uint32v', 'WriteTimeLow', 0 ],
1017
+ [ 'uint32v', 'WriteTimeHigh', 0 ],
1018
+ [ 'uint32v', 'ChangeTimeLow', 0 ],
1019
+ [ 'uint32v', 'ChangeTimeHigh', 0 ],
1020
+ [ 'uint32v', 'Attributes', 0 ],
1021
+ [ 'uint32v', 'AllocLow', 0 ],
1022
+ [ 'uint32v', 'AllocHigh', 0 ],
1023
+ [ 'uint32v', 'EOFLow', 0 ],
1024
+ [ 'uint32v', 'EOFHigh', 0 ],
1025
+ [ 'uint16v', 'FileType', 0 ],
1026
+ [ 'uint16v', 'IPCState', 0 ],
1027
+ [ 'uint8', 'IsDirectory', 0 ],
1028
+ [ 'string', 'VolumeGUID', 16, '', "\x00"],
1029
+ [ 'uint64v', '64bitFID', 0 ],
1030
+ [ 'uint32v', 'MaxAccess', 0 ],
1031
+ [ 'uint32v', 'GuestAccess', 0 ],
1032
+ [ 'uint16v', 'ByteCount', 0 ],
1033
+ [ 'string', 'Payload', nil, '' ]
1034
+ ).create_restraints(
1035
+ [ 'Payload', 'ByteCount', nil, true ]
1036
+ )
1037
+ SMB_CREATE_ANDX_RES_PKT = self.make_nbs(SMB_CREATE_ANDX_RES_HDR_PKT)
1038
+
1039
+ # A SMB template for SMB Write requests
1040
+ SMB_WRITE_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1041
+ [ 'template', 'SMB', SMB_HDR ],
1042
+ [ 'uint8', 'AndX', 0 ],
1043
+ [ 'uint8', 'Reserved1', 0 ],
1044
+ [ 'uint16v', 'AndXOffset', 0 ],
1045
+ [ 'uint16v', 'FileID', 0 ],
1046
+ [ 'uint32v', 'Offset', 0 ],
1047
+ [ 'uint32v', 'Reserved2', 0 ],
1048
+ [ 'uint16v', 'WriteMode', 0 ],
1049
+ [ 'uint16v', 'Remaining', 0 ],
1050
+ [ 'uint16v', 'DataLenHigh', 0 ],
1051
+ [ 'uint16v', 'DataLenLow', 0 ],
1052
+ [ 'uint16v', 'DataOffset', 0 ],
1053
+ [ 'uint32v', 'DataOffsetHigh', 0 ],
1054
+ [ 'uint16v', 'ByteCount', 0 ],
1055
+ [ 'string', 'Payload', nil, '' ]
1056
+ ).create_restraints(
1057
+ [ 'Payload', 'ByteCount', nil, true ]
1058
+ )
1059
+ SMB_WRITE_PKT = self.make_nbs(SMB_WRITE_HDR_PKT)
1060
+
1061
+
1062
+ # A SMB template for SMB Write responses
1063
+ SMB_WRITE_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1064
+ [ 'template', 'SMB', SMB_HDR ],
1065
+ [ 'uint8', 'AndX', 0 ],
1066
+ [ 'uint8', 'Reserved1', 0 ],
1067
+ [ 'uint16v', 'AndXOffset', 0 ],
1068
+ [ 'uint16v', 'CountLow', 0 ],
1069
+ [ 'uint16v', 'Remaining', 0 ],
1070
+ [ 'uint16v', 'CountHigh', 0 ],
1071
+ [ 'uint16v', 'Reserved2', 0 ],
1072
+ [ 'uint16v', 'ByteCount', 0 ],
1073
+ [ 'string', 'Payload', nil, '' ]
1074
+ ).create_restraints(
1075
+ [ 'Payload', 'ByteCount', nil, true ]
1076
+ )
1077
+ SMB_WRITE_RES_PKT = self.make_nbs(SMB_WRITE_RES_HDR_PKT)
1078
+
1079
+
1080
+ # A SMB template for SMB OPEN requests
1081
+ SMB_OPEN_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1082
+ [ 'template', 'SMB', SMB_HDR ],
1083
+ [ 'uint8', 'AndX', 0 ],
1084
+ [ 'uint8', 'Reserved1', 0 ],
1085
+ [ 'uint16v', 'AndXOffset', 0 ],
1086
+ [ 'uint16v', 'Flags', 0 ],
1087
+ [ 'uint16v', 'Access', 0 ],
1088
+ [ 'uint16v', 'SearchAttributes', 0 ],
1089
+ [ 'uint16v', 'FileAttributes', 0 ],
1090
+ [ 'uint32v', 'CreateTime', 0 ],
1091
+ [ 'uint16v', 'OpenFunction', 0 ],
1092
+ [ 'uint32v', 'AllocSize', 0 ],
1093
+ [ 'uint32v', 'Reserved2', 0 ],
1094
+ [ 'uint32v', 'Reserved3', 0 ],
1095
+ [ 'uint16v', 'ByteCount', 0 ],
1096
+ [ 'string', 'Payload', nil, '' ]
1097
+ ).create_restraints(
1098
+ [ 'Payload', 'ByteCount', nil, true ]
1099
+ )
1100
+ SMB_OPEN_PKT = self.make_nbs(SMB_OPEN_HDR_PKT)
1101
+
1102
+
1103
+ # A SMB template for SMB OPEN responses
1104
+ SMB_OPEN_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1105
+ [ 'template', 'SMB', SMB_HDR ],
1106
+ [ 'uint8', 'AndX', 0 ],
1107
+ [ 'uint8', 'Reserved1', 0 ],
1108
+ [ 'uint16v', 'AndXOffset', 0 ],
1109
+ [ 'uint16v', 'FileID', 0 ],
1110
+ [ 'uint16v', 'FileAttributes', 0 ],
1111
+ [ 'uint32v', 'WriteTime', 0 ],
1112
+ [ 'uint32v', 'FileSize', 0 ],
1113
+ [ 'uint16v', 'FileAccess', 0 ],
1114
+ [ 'uint16v', 'FileType', 0 ],
1115
+ [ 'uint16v', 'IPCState', 0 ],
1116
+ [ 'uint16v', 'Action', 0 ],
1117
+ [ 'uint32v', 'ServerFileID', 0 ],
1118
+ [ 'uint16v', 'Reserved2', 0 ],
1119
+ [ 'uint16v', 'ByteCount', 0 ],
1120
+ [ 'string', 'Payload', nil, '' ]
1121
+ ).create_restraints(
1122
+ [ 'Payload', 'ByteCount', nil, true ]
1123
+ )
1124
+ SMB_OPEN_RES_PKT = self.make_nbs(SMB_OPEN_RES_HDR_PKT)
1125
+
1126
+
1127
+ # A SMB template for SMB Close requests
1128
+ SMB_CLOSE_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1129
+ [ 'template', 'SMB', SMB_HDR ],
1130
+ [ 'uint16v', 'FileID', 0 ],
1131
+ [ 'uint32v', 'LastWrite', 0 ],
1132
+ [ 'uint16v', 'ByteCount', 0 ],
1133
+ [ 'string', 'Payload', nil, '' ]
1134
+ ).create_restraints(
1135
+ [ 'Payload', 'ByteCount', nil, true ]
1136
+ )
1137
+ SMB_CLOSE_PKT = self.make_nbs(SMB_CLOSE_HDR_PKT)
1138
+
1139
+
1140
+ # A SMB template for SMB Close responses
1141
+ SMB_CLOSE_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1142
+ [ 'template', 'SMB', SMB_HDR ],
1143
+ [ 'uint16v', 'ByteCount', 0 ],
1144
+ [ 'string', 'Payload', nil, '' ]
1145
+ ).create_restraints(
1146
+ [ 'Payload', 'ByteCount', nil, true ]
1147
+ )
1148
+ SMB_CLOSE_RES_PKT = self.make_nbs(SMB_CLOSE_RES_HDR_PKT)
1149
+
1150
+
1151
+ # A SMB template for SMB Delete requests
1152
+ SMB_DELETE_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1153
+ [ 'template', 'SMB', SMB_HDR ],
1154
+ [ 'uint16v', 'SearchAttribute', 0 ],
1155
+ [ 'uint16v', 'ByteCount', 0 ],
1156
+ [ 'uint8', 'BufferFormat', 0 ],
1157
+ [ 'string', 'Payload', nil, '' ]
1158
+ ).create_restraints(
1159
+ [ 'Payload', 'ByteCount', nil, true ]
1160
+ )
1161
+ SMB_DELETE_PKT = self.make_nbs(SMB_DELETE_HDR_PKT)
1162
+
1163
+
1164
+ # A SMB template for SMB Delete responses
1165
+ SMB_DELETE_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1166
+ [ 'template', 'SMB', SMB_HDR ],
1167
+ [ 'uint16v', 'ByteCount', 0 ],
1168
+ [ 'string', 'Payload', nil, '' ]
1169
+ ).create_restraints(
1170
+ [ 'Payload', 'ByteCount', nil, true ]
1171
+ )
1172
+ SMB_DELETE_RES_PKT = self.make_nbs(SMB_DELETE_RES_HDR_PKT)
1173
+
1174
+
1175
+
1176
+ # A SMB template for SMB Read requests
1177
+ SMB_READ_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1178
+ [ 'template', 'SMB', SMB_HDR ],
1179
+ [ 'uint8', 'AndX', 0 ],
1180
+ [ 'uint8', 'Reserved1', 0 ],
1181
+ [ 'uint16v', 'AndXOffset', 0 ],
1182
+ [ 'uint16v', 'FileID', 0 ],
1183
+ [ 'uint32v', 'Offset', 0 ],
1184
+ [ 'uint16v', 'MaxCountLow', 0 ],
1185
+ [ 'uint16v', 'MinCount', 0 ],
1186
+ [ 'uint32v', 'Reserved2', 0 ],
1187
+ [ 'uint16v', 'Remaining', 0 ],
1188
+ [ 'uint32v', 'MaxCountHigh', 0 ],
1189
+ [ 'uint16v', 'ByteCount', 0 ],
1190
+ [ 'string', 'Payload', nil, '' ]
1191
+ ).create_restraints(
1192
+ [ 'Payload', 'ByteCount', nil, true ]
1193
+ )
1194
+ SMB_READ_PKT = self.make_nbs(SMB_READ_HDR_PKT)
1195
+
1196
+
1197
+ # A SMB template for SMB Read responses
1198
+ SMB_READ_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1199
+ [ 'template', 'SMB', SMB_HDR ],
1200
+ [ 'uint8', 'AndX', 0 ],
1201
+ [ 'uint8', 'Reserved1', 0 ],
1202
+ [ 'uint16v', 'AndXOffset', 0 ],
1203
+ [ 'uint16v', 'Remaining', 0 ],
1204
+ [ 'uint16v', 'DataCompaction', 0 ],
1205
+ [ 'uint16v', 'Reserved2', 0 ],
1206
+ [ 'uint16v', 'DataLenLow', 0 ],
1207
+ [ 'uint16v', 'DataOffset', 0 ],
1208
+ [ 'uint32v', 'DataLenHigh', 0 ],
1209
+ [ 'uint32v', 'Reserved3', 0 ],
1210
+ [ 'uint16v', 'Reserved4', 0 ],
1211
+ [ 'uint16v', 'ByteCount', 0 ],
1212
+ [ 'string', 'Payload', nil, '' ]
1213
+ ).create_restraints(
1214
+ [ 'Payload', 'ByteCount', nil, true ]
1215
+ )
1216
+ SMB_READ_RES_PKT = self.make_nbs(SMB_READ_RES_HDR_PKT)
1217
+
1218
+ SMB_READ_RES_HDR_PKT_LENGTH = SMB_HDR_LENGTH + 26
1219
+
1220
+ # A SMB template for SMB Search requests
1221
+ SMB_SEARCH_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1222
+ [ 'template', 'SMB', SMB_HDR ],
1223
+ [ 'uint16v', 'MaxCount', 0 ],
1224
+ [ 'uint16v', 'Attributes', 0 ],
1225
+ [ 'uint16v', 'ByteCount', 0 ],
1226
+ [ 'string', 'Payload', nil, '' ]
1227
+ ).create_restraints(
1228
+ [ 'Payload', 'ByteCount', nil, true ]
1229
+ )
1230
+ SMB_SEARCH_PKT = self.make_nbs(SMB_SEARCH_HDR_PKT)
1231
+
1232
+ # A template for SMB TRANS2_FIND_FIRST response parameters
1233
+ SMB_TRANS2_FIND_FIRST2_RES_PARAMETERS = Rex::Struct2::CStructTemplate.new(
1234
+ ['uint16v', 'SID', 0],
1235
+ ['uint16v', 'SearchCount', 0],
1236
+ ['uint16v', 'EndOfSearch', 0],
1237
+ ['uint16v', 'EaErrorOffset', 0],
1238
+ ['uint16v', 'LastNameOffset', 0]
1239
+ )
1240
+
1241
+ # A template for SMB_FIND_FILE_BOTH_DIRECTORY_INFO Find information level
1242
+ SMB_FIND_FILE_BOTH_DIRECTORY_INFO_HDR = Rex::Struct2::CStructTemplate.new(
1243
+ ['uint32v', 'NextEntryOffset', 0],
1244
+ ['uint32v', 'FileIndex', 0],
1245
+ ['uint32v', 'loCreationTime', 0],
1246
+ ['uint32v', 'hiCreationTime', 0],
1247
+ ['uint32v', 'loLastAccessTime', 0],
1248
+ ['uint32v', 'hiLastAccessTime', 0],
1249
+ ['uint32v', 'loLastWriteTime', 0],
1250
+ ['uint32v', 'hiLastWriteTime', 0],
1251
+ ['uint32v', 'loLastChangeTime', 0],
1252
+ ['uint32v', 'hiLastChangeTime', 0],
1253
+ ['uint64v', 'EndOfFile', 0],
1254
+ ['uint64v', 'AllocationSize', 0],
1255
+ ['uint32v', 'ExtFileAttributes', 0],
1256
+ ['uint32v', 'FileNameLength', 0],
1257
+ ['uint32v', 'EaSize', 0],
1258
+ ['uint8', 'ShortNameLength', 0],
1259
+ ['uint8', 'Reserved', 0],
1260
+ ['string', 'ShortName', 24, '', "\x00"],
1261
+ ['string', 'FileName', nil, '' ]
1262
+ ).create_restraints(
1263
+ ['FileName', 'FileNameLength', nil, true]
1264
+ )
1265
+
1266
+ SMB_FIND_FILE_BOTH_DIRECTORY_INFO_HDR_LENGTH = 94
1267
+
1268
+ # A template for SMB_FIND_FILE_BOTH_DIRECTORY_INFO Find information level
1269
+ SMB_FIND_FILE_NAMES_INFO_HDR = Rex::Struct2::CStructTemplate.new(
1270
+ ['uint32v', 'NextEntryOffset', 0],
1271
+ ['uint32v', 'FileIndex', 0],
1272
+ ['uint32v', 'FileNameLength', 0],
1273
+ ['string', 'FileName', nil, '' ]
1274
+ ).create_restraints(
1275
+ ['FileName', 'FileNameLength', nil, true]
1276
+ )
1277
+
1278
+ SMB_FIND_FILE_NAMES_INFO_HDR_LENGTH = 12
1279
+
1280
+ # A template for SMB_FIND_FILE_FULL_DIRECTORY_INFO Find information level
1281
+ SMB_FIND_FILE_FULL_DIRECTORY_INFO_HDR = Rex::Struct2::CStructTemplate.new(
1282
+ ['uint32v', 'NextEntryOffset', 0],
1283
+ ['uint32v', 'FileIndex', 0],
1284
+ ['uint32v', 'loCreationTime', 0],
1285
+ ['uint32v', 'hiCreationTime', 0],
1286
+ ['uint32v', 'loLastAccessTime', 0],
1287
+ ['uint32v', 'hiLastAccessTime', 0],
1288
+ ['uint32v', 'loLastWriteTime', 0],
1289
+ ['uint32v', 'hiLastWriteTime', 0],
1290
+ ['uint32v', 'loLastChangeTime', 0],
1291
+ ['uint32v', 'hiLastChangeTime', 0],
1292
+ ['uint64v', 'EndOfFile', 0],
1293
+ ['uint64v', 'AllocationSize', 0],
1294
+ ['uint32v', 'ExtFileAttributes', 0],
1295
+ ['uint32v', 'FileNameLength', 0],
1296
+ ['uint32v', 'EaSize', 0],
1297
+ ['string', 'FileName', nil, '' ]
1298
+ ).create_restraints(
1299
+ ['FileName', 'FileNameLength', nil, true]
1300
+ )
1301
+
1302
+ SMB_FIND_FILE_FULL_DIRECTORY_INFO_HDR_LENGTH = 68
1303
+
1304
+ # A template for SMB FIND_FIRST2 TRANS2 response parameters
1305
+ SMB_TRANS2_QUERY_PATH_INFORMATION_RES_PARAMETERS = Rex::Struct2::CStructTemplate.new(
1306
+ ['uint16v', 'EaErrorOffset', 0]
1307
+ )
1308
+
1309
+ # A template for SMB_QUERY_FILE_NETWORK_INFO query path information level
1310
+ SMB_QUERY_FILE_NETWORK_INFO_HDR = Rex::Struct2::CStructTemplate.new(
1311
+ ['uint32v', 'loCreationTime', 0],
1312
+ ['uint32v', 'hiCreationTime', 0],
1313
+ ['uint32v', 'loLastAccessTime', 0],
1314
+ ['uint32v', 'hiLastAccessTime', 0],
1315
+ ['uint32v', 'loLastWriteTime', 0],
1316
+ ['uint32v', 'hiLastWriteTime', 0],
1317
+ ['uint32v', 'loLastChangeTime', 0],
1318
+ ['uint32v', 'hiLastChangeTime', 0],
1319
+ ['uint64v', 'AllocationSize', 0],
1320
+ ['uint64v', 'EndOfFile', 0],
1321
+ ['uint32v', 'ExtFileAttributes', 0],
1322
+ ['uint32v', 'Reserved', 0]
1323
+ )
1324
+
1325
+ SMB_QUERY_FILE_NETWORK_INFO_HDR_LENGTH = 56
1326
+
1327
+ # A template for SMB_QUERY_FILE_BASIC_INFO query path information level
1328
+ SMB_QUERY_FILE_BASIC_INFO_HDR = Rex::Struct2::CStructTemplate.new(
1329
+ ['uint32v', 'loCreationTime', 0],
1330
+ ['uint32v', 'hiCreationTime', 0],
1331
+ ['uint32v', 'loLastAccessTime', 0],
1332
+ ['uint32v', 'hiLastAccessTime', 0],
1333
+ ['uint32v', 'loLastWriteTime', 0],
1334
+ ['uint32v', 'hiLastWriteTime', 0],
1335
+ ['uint32v', 'loLastChangeTime', 0],
1336
+ ['uint32v', 'hiLastChangeTime', 0],
1337
+ ['uint32v', 'ExtFileAttributes', 0],
1338
+ ['uint32v', 'Reserved', 0]
1339
+ )
1340
+
1341
+ SMB_QUERY_FILE_BASIC_INFO_HDR_LENGTH = 40
1342
+
1343
+ # A template for SMB_QUERY_FILE_STANDARD_INFO query path information level
1344
+ SMB_QUERY_FILE_STANDARD_INFO_HDR = Rex::Struct2::CStructTemplate.new(
1345
+ ['uint64v', 'AllocationSize', 0],
1346
+ ['uint64v', 'EndOfFile', 0],
1347
+ ['uint32v', 'NumberOfLinks', 0],
1348
+ ['uint8', 'DeletePending', 0],
1349
+ ['uint8', 'Directory', 0]
1350
+ )
1351
+
1352
+ SMB_QUERY_FILE_STANDARD_INFO_HDR_LENGTH = 22
1353
+
1354
+ # A template for SMB_Data blocks of the SMB_COM_TRANSACTION2 requests
1355
+ SMB_DATA_TRANS2 = Rex::Struct2::CStructTemplate.new(
1356
+ ['uint16v', 'SubCommand', 0],
1357
+ ['uint16v', 'ByteCount', 0],
1358
+ ['string', 'Parameters', nil, '']
1359
+ ).create_restraints(
1360
+ ['Parameters', 'ByteCount', nil, true]
1361
+ )
1362
+
1363
+ # A template for SMB_Parameters blocks of the SMB_COM_TRANSACTION2 QUERY_PATH_INFO responses
1364
+ SMB_TRANS2_QUERY_PATH_PARAMETERS = Rex::Struct2::CStructTemplate.new(
1365
+ ['uint16v', 'InformationLevel', 0],
1366
+ ['uint32v', 'Reserved', 0],
1367
+ ['string', 'FileName', nil, '']
377
1368
  )
378
- end
379
1369
 
1370
+ # A template for SMB_Parameters blocks of the SMB_COM_TRANSACTION2 QUERY_FILE_INFO responses
1371
+ SMB_TRANS2_QUERY_FILE_PARAMETERS = Rex::Struct2::CStructTemplate.new(
1372
+ ['uint16v', 'FID', 0],
1373
+ ['uint16v', 'InformationLevel', 0]
1374
+ )
380
1375
 
381
- # A raw NetBIOS session template
382
- NBRAW_HDR_PKT = Rex::Struct2::CStructTemplate.new(
383
- [ 'string', 'Payload', nil, '']
384
- )
385
- NBRAW_PKT = self.make_nbs(NBRAW_HDR_PKT)
386
-
387
-
388
- # The SMB header template
389
- SMB_HDR = Rex::Struct2::CStructTemplate.new(
390
- [ 'uint32n', 'Magic', 0xff534d42 ],
391
- [ 'uint8', 'Command', 0 ],
392
- [ 'uint32v', 'ErrorClass', 0 ],
393
- [ 'uint8', 'Flags1', 0 ],
394
- [ 'uint16v', 'Flags2', 0 ],
395
- [ 'uint16v', 'ProcessIDHigh', 0 ],
396
- [ 'uint32v', 'Signature1', 0 ],
397
- [ 'uint32v', 'Signature2', 0 ],
398
- [ 'uint16v', 'Reserved1', 0 ],
399
- [ 'uint16v', 'TreeID', 0 ],
400
- [ 'uint16v', 'ProcessID', 0 ],
401
- [ 'uint16v', 'UserID', 0 ],
402
- [ 'uint16v', 'MultiplexID', 0 ],
403
- [ 'uint8', 'WordCount', 0 ]
404
- )
405
-
406
-
407
- # The SMB2 header template
408
- SMB2_HDR = Rex::Struct2::CStructTemplate.new(
409
- [ 'uint32n', 'Magic', 0xfe534d42 ],
410
- [ 'uint16v', 'HeaderLen', 64 ],
411
- [ 'uint16v', 'Reserved0', 0 ],
412
- [ 'uint32v', 'NTStatus', 0 ],
413
-
414
- [ 'uint16v', 'Opcode', 0 ],
415
- [ 'uint16v', 'Reserved1', 0 ],
416
-
417
- [ 'uint16v', 'Flags1', 0 ],
418
- [ 'uint16v', 'Flags2', 0 ],
419
-
420
- [ 'uint32v', 'ChainOffset', 0 ],
421
-
422
- [ 'uint32v', 'SequenceHigh', 0 ],
423
- [ 'uint32v', 'SequenceLow', 0 ],
424
-
425
- [ 'uint32v', 'ProcessID', 0 ],
426
- [ 'uint32v', 'TreeID', 0 ],
427
- [ 'uint32v', 'UserIDHigh', 0 ],
428
- [ 'uint32v', 'UserIDLow', 0 ],
429
-
430
- [ 'uint32v', 'SignatureA', 0 ],
431
- [ 'uint32v', 'SignatureB', 0 ],
432
- [ 'uint32v', 'SignatureC', 0 ],
433
- [ 'uint32v', 'SignatureD', 0 ],
434
- [ 'string', 'Payload', nil, '']
435
- )
436
-
437
- # A basic SMB template to read all responses
438
- SMB_BASE_HDR_PKT = Rex::Struct2::CStructTemplate.new(
439
- [ 'template', 'SMB', SMB_HDR ],
440
- [ 'uint16v', 'ByteCount', 0 ],
441
- [ 'string', 'Payload', nil, '' ]
442
- ).create_restraints(
443
- [ 'Payload', 'ByteCount', nil, true ]
444
- )
445
- SMB_BASE_PKT = self.make_nbs(SMB_BASE_HDR_PKT)
446
-
447
-
448
- # A SMB template for SMB Dialect negotiation
449
- SMB_NEG_HDR_PKT = Rex::Struct2::CStructTemplate.new(
450
-
451
- [ 'template', 'SMB', SMB_HDR ],
452
- [ 'uint16v', 'ByteCount', 0 ],
453
- [ 'string', 'Payload', nil, '' ]
454
- ).create_restraints(
455
- [ 'Payload', 'ByteCount', nil, true ]
456
- )
457
- SMB_NEG_PKT = self.make_nbs(SMB_NEG_HDR_PKT)
458
-
459
-
460
- # A SMB template for SMB Dialect negotiation responses (LANMAN)
461
- SMB_NEG_RES_LM_HDR_PKT = Rex::Struct2::CStructTemplate.new(
462
- [ 'template', 'SMB', SMB_HDR ],
463
- [ 'uint16v', 'Dialect', 0 ],
464
- [ 'uint16v', 'SecurityMode', 0 ],
465
- [ 'uint16v', 'MaxBuff', 0 ],
466
- [ 'uint16v', 'MaxMPX', 0 ],
467
- [ 'uint16v', 'MaxVCS', 0 ],
468
- [ 'uint16v', 'RawMode', 0 ],
469
- [ 'uint32v', 'SessionKey', 0 ],
470
- [ 'uint16v', 'DosTime', 0 ],
471
- [ 'uint16v', 'DosDate', 0 ],
472
- [ 'uint16v', 'Timezone', 0 ],
473
- [ 'uint16v', 'KeyLength', 0 ],
474
- [ 'uint16v', 'Reserved1', 0 ],
475
- [ 'uint16v', 'ByteCount', 0 ],
476
- [ 'string', 'EncryptionKey', nil, '' ]
477
- ).create_restraints(
478
- [ 'EncryptionKey', 'ByteCount', nil, true ]
479
- )
480
- SMB_NEG_RES_LM_PKT = self.make_nbs(SMB_NEG_RES_LM_HDR_PKT)
481
-
482
-
483
- # A SMB template for SMB Dialect negotiation responses (NTLM)
484
- SMB_NEG_RES_NT_HDR_PKT = Rex::Struct2::CStructTemplate.new(
485
- [ 'template', 'SMB', SMB_HDR ],
486
- [ 'uint16v', 'Dialect', 0 ],
487
- [ 'uint8', 'SecurityMode', 0 ],
488
- [ 'uint16v', 'MaxMPX', 0 ],
489
- [ 'uint16v', 'MaxVCS', 0 ],
490
- [ 'uint32v', 'MaxBuff', 0 ],
491
- [ 'uint32v', 'MaxRaw', 0 ],
492
- [ 'uint32v', 'SessionKey', 0 ],
493
- [ 'uint32v', 'Capabilities', 0 ],
494
- [ 'uint32v', 'SystemTimeLow', 0 ],
495
- [ 'uint32v', 'SystemTimeHigh', 0 ],
496
- [ 'uint16v', 'ServerTimeZone', 0 ],
497
- [ 'uint8', 'KeyLength', 0 ],
498
- [ 'uint16v', 'ByteCount', 0 ],
499
- [ 'string', 'Payload', nil, '' ]
500
- ).create_restraints(
501
- [ 'Payload', 'ByteCount', nil, true ]
502
- )
503
- SMB_NEG_RES_NT_PKT = self.make_nbs(SMB_NEG_RES_NT_HDR_PKT)
504
-
505
-
506
- # A SMB template for SMB Dialect negotiation responses (ERROR)
507
- SMB_NEG_RES_ERR_HDR_PKT = Rex::Struct2::CStructTemplate.new(
508
- [ 'template', 'SMB', SMB_HDR ],
509
- [ 'uint16v', 'Dialect', 0 ],
510
- [ 'uint16v', 'ByteCount', 0 ]
511
- )
512
- SMB_NEG_RES_ERR_PKT = self.make_nbs(SMB_NEG_RES_ERR_HDR_PKT)
513
-
514
-
515
- # A SMB template for SMB Session Setup responses (LANMAN/NTLMV1)
516
- SMB_SETUP_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
517
- [ 'template', 'SMB', SMB_HDR ],
518
- [ 'uint8', 'AndX', 0 ],
519
- [ 'uint8', 'Reserved1', 0 ],
520
- [ 'uint16v', 'AndXOffset', 0 ],
521
- [ 'uint16v', 'Action', 0 ],
522
- [ 'uint16v', 'ByteCount', 0 ],
523
- [ 'string', 'Payload', nil, '' ]
524
- ).create_restraints(
525
- [ 'Payload', 'ByteCount', nil, true ]
526
- )
527
- SMB_SETUP_RES_PKT = self.make_nbs(SMB_SETUP_RES_HDR_PKT)
528
-
529
-
530
- # A SMB template for SMB Session Setup requests (LANMAN)
531
- SMB_SETUP_LANMAN_HDR_PKT = Rex::Struct2::CStructTemplate.new(
532
- [ 'template', 'SMB', SMB_HDR ],
533
- [ 'uint8', 'AndX', 0 ],
534
- [ 'uint8', 'Reserved1', 0 ],
535
- [ 'uint16v', 'AndXOffset', 0 ],
536
- [ 'uint16v', 'MaxBuff', 0 ],
537
- [ 'uint16v', 'MaxMPX', 0 ],
538
- [ 'uint16v', 'VCNum', 0 ],
539
- [ 'uint32v', 'SessionKey', 0 ],
540
- [ 'uint16v', 'PasswordLen', 0 ],
541
- [ 'uint32v', 'Reserved2', 0 ],
542
- [ 'uint16v', 'ByteCount', 0 ],
543
- [ 'string', 'Payload', nil, '' ]
544
- ).create_restraints(
545
- [ 'Payload', 'ByteCount', nil, true ]
546
- )
547
- SMB_SETUP_LANMAN_PKT = self.make_nbs(SMB_SETUP_LANMAN_HDR_PKT)
548
-
549
-
550
- # A SMB template for SMB Session Setup requests (NTLMV1)
551
- SMB_SETUP_NTLMV1_HDR_PKT = Rex::Struct2::CStructTemplate.new(
552
- [ 'template', 'SMB', SMB_HDR ],
553
- [ 'uint8', 'AndX', 0 ],
554
- [ 'uint8', 'Reserved1', 0 ],
555
- [ 'uint16v', 'AndXOffset', 0 ],
556
- [ 'uint16v', 'MaxBuff', 0 ],
557
- [ 'uint16v', 'MaxMPX', 0 ],
558
- [ 'uint16v', 'VCNum', 0 ],
559
- [ 'uint32v', 'SessionKey', 0 ],
560
- [ 'uint16v', 'PasswordLenLM', 0 ],
561
- [ 'uint16v', 'PasswordLenNT', 0 ],
562
- [ 'uint32v', 'Reserved2', 0 ],
563
- [ 'uint32v', 'Capabilities', 0 ],
564
- [ 'uint16v', 'ByteCount', 0 ],
565
- [ 'string', 'Payload', nil, '' ]
566
- ).create_restraints(
567
- [ 'Payload', 'ByteCount', nil, true ]
568
- )
569
- SMB_SETUP_NTLMV1_PKT = self.make_nbs(SMB_SETUP_NTLMV1_HDR_PKT)
570
-
571
-
572
- # A SMB template for SMB Session Setup requests (When extended security is being used)
573
- SMB_SETUP_NTLMV2_HDR_PKT = Rex::Struct2::CStructTemplate.new(
574
- [ 'template', 'SMB', SMB_HDR ],
575
- [ 'uint8', 'AndX', 0 ],
576
- [ 'uint8', 'Reserved1', 0 ],
577
- [ 'uint16v', 'AndXOffset', 0 ],
578
- [ 'uint16v', 'MaxBuff', 0 ],
579
- [ 'uint16v', 'MaxMPX', 0 ],
580
- [ 'uint16v', 'VCNum', 0 ],
581
- [ 'uint32v', 'SessionKey', 0 ],
582
- [ 'uint16v', 'SecurityBlobLen', 0 ],
583
- [ 'uint32v', 'Reserved2', 0 ],
584
- [ 'uint32v', 'Capabilities', 0 ],
585
- [ 'uint16v', 'ByteCount', 0 ],
586
- [ 'string', 'Payload', nil, '' ]
587
- ).create_restraints(
588
- [ 'Payload', 'ByteCount', nil, true ]
589
- )
590
- SMB_SETUP_NTLMV2_PKT = self.make_nbs(SMB_SETUP_NTLMV2_HDR_PKT)
591
-
592
-
593
- # A SMB template for SMB Session Setup responses (When extended security is being used)
594
- SMB_SETUP_NTLMV2_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
595
- [ 'template', 'SMB', SMB_HDR ],
596
- [ 'uint8', 'AndX', 0 ],
597
- [ 'uint8', 'Reserved1', 0 ],
598
- [ 'uint16v', 'AndXOffset', 0 ],
599
- [ 'uint16v', 'Action', 0 ],
600
- [ 'uint16v', 'SecurityBlobLen', 0 ],
601
- [ 'uint16v', 'ByteCount', 0 ],
602
- [ 'string', 'Payload', nil, '' ]
603
- ).create_restraints(
604
- [ 'Payload', 'ByteCount', nil, true ]
605
- )
606
- SMB_SETUP_NTLMV2_RES_PKT = self.make_nbs(SMB_SETUP_NTLMV2_RES_HDR_PKT)
607
-
608
-
609
- # A SMB template for SMB Tree Connect requests
610
- SMB_TREE_CONN_HDR_PKT = Rex::Struct2::CStructTemplate.new(
611
- [ 'template', 'SMB', SMB_HDR ],
612
- [ 'uint8', 'AndX', 0 ],
613
- [ 'uint8', 'Reserved1', 0 ],
614
- [ 'uint16v', 'AndXOffset', 0 ],
615
- [ 'uint16v', 'Flags', 0 ],
616
- [ 'uint16v', 'PasswordLen', 0 ],
617
- [ 'uint16v', 'ByteCount', 0 ],
618
- [ 'string', 'Payload', nil, '' ]
619
- ).create_restraints(
620
- [ 'Payload', 'ByteCount', nil, true ]
621
- )
622
- SMB_TREE_CONN_PKT = self.make_nbs(SMB_TREE_CONN_HDR_PKT)
623
-
624
-
625
- # A SMB template for SMB Tree Connect requests
626
- SMB_TREE_CONN_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
627
- [ 'template', 'SMB', SMB_HDR ],
628
- [ 'uint8', 'AndX', 0 ],
629
- [ 'uint8', 'Reserved1', 0 ],
630
- [ 'uint16v', 'AndXOffset', 0 ],
631
- [ 'uint16v', 'OptionalSupport', 0 ],
632
- [ 'string', 'SupportWords', nil, '' ],
633
- [ 'uint16v', 'ByteCount', 0 ],
634
- [ 'string', 'Payload', nil, '' ]
635
- ).create_restraints(
636
- [ 'Payload', 'ByteCount', nil, true ]
637
- )
638
- SMB_TREE_CONN_RES_PKT = self.make_nbs(SMB_TREE_CONN_RES_HDR_PKT)
639
-
640
-
641
- # A SMB template for SMB Tree Disconnect requests
642
- SMB_TREE_DISCONN_HDR_PKT = Rex::Struct2::CStructTemplate.new(
643
- [ 'template', 'SMB', SMB_HDR ],
644
- [ 'uint16v', 'ByteCount', 0 ],
645
- [ 'string', 'Payload', nil, '' ]
646
- ).create_restraints(
647
- [ 'Payload', 'ByteCount', nil, true ]
648
- )
649
- SMB_TREE_DISCONN_PKT = self.make_nbs(SMB_TREE_DISCONN_HDR_PKT)
650
-
651
-
652
- # A SMB template for SMB Tree Disconnect requests
653
- SMB_TREE_DISCONN_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
654
- [ 'template', 'SMB', SMB_HDR ],
655
- [ 'uint16v', 'ByteCount', 0 ],
656
- [ 'string', 'Payload', nil, '' ]
657
- ).create_restraints(
658
- [ 'Payload', 'ByteCount', nil, true ]
659
- )
660
- SMB_TREE_DISCONN_RES_PKT = self.make_nbs(SMB_TREE_DISCONN_RES_HDR_PKT)
661
-
662
-
663
- # A SMB template for SMB Transaction requests
664
- SMB_TRANS_HDR_PKT = Rex::Struct2::CStructTemplate.new(
665
- [ 'template', 'SMB', SMB_HDR ],
666
- [ 'uint16v', 'ParamCountTotal', 0 ],
667
- [ 'uint16v', 'DataCountTotal', 0 ],
668
- [ 'uint16v', 'ParamCountMax', 0 ],
669
- [ 'uint16v', 'DataCountMax', 0 ],
670
- [ 'uint8', 'SetupCountMax', 0 ],
671
- [ 'uint8', 'Reserved1', 0 ],
672
- [ 'uint16v', 'Flags', 0 ],
673
- [ 'uint32v', 'Timeout', 0 ],
674
- [ 'uint16v', 'Reserved2', 0 ],
675
- [ 'uint16v', 'ParamCount', 0 ],
676
- [ 'uint16v', 'ParamOffset', 0 ],
677
- [ 'uint16v', 'DataCount', 0 ],
678
- [ 'uint16v', 'DataOffset', 0 ],
679
- [ 'uint8', 'SetupCount', 0 ],
680
- [ 'uint8', 'Reserved3', 0 ],
681
- [ 'string', 'SetupData', nil, '' ],
682
- [ 'uint16v', 'ByteCount', 0 ],
683
- [ 'string', 'Payload', nil, '' ]
684
- ).create_restraints(
685
- [ 'Payload', 'ByteCount', nil, true ]
686
- )
687
- SMB_TRANS_PKT = self.make_nbs(SMB_TRANS_HDR_PKT)
688
-
689
-
690
- # A SMB template for SMB Transaction responses
691
- SMB_TRANS_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
692
- [ 'template', 'SMB', SMB_HDR ],
693
- [ 'uint16v', 'ParamCountTotal', 0 ],
694
- [ 'uint16v', 'DataCountTotal', 0 ],
695
- [ 'uint16v', 'Reserved1', 0 ],
696
- [ 'uint16v', 'ParamCount', 0 ],
697
- [ 'uint16v', 'ParamOffset', 0 ],
698
- [ 'uint16v', 'ParamDisplace', 0 ],
699
- [ 'uint16v', 'DataCount', 0 ],
700
- [ 'uint16v', 'DataOffset', 0 ],
701
- [ 'uint16v', 'DataDisplace', 0 ],
702
- [ 'uint8', 'SetupCount', 0 ],
703
- [ 'uint8', 'Reserved2', 0 ],
704
- [ 'string', 'SetupData', nil, '' ],
705
- [ 'uint16v', 'ByteCount', 0 ],
706
- [ 'string', 'Payload', nil, '' ]
707
- ).create_restraints(
708
- [ 'Payload', 'ByteCount', nil, true ]
709
- )
710
- SMB_TRANS_RES_PKT = self.make_nbs(SMB_TRANS_RES_HDR_PKT)
711
-
712
- # A SMB template for SMB Transaction2 requests
713
- SMB_TRANS2_HDR_PKT = Rex::Struct2::CStructTemplate.new(
714
- [ 'template', 'SMB', SMB_HDR ],
715
- [ 'uint16v', 'ParamCountTotal', 0 ],
716
- [ 'uint16v', 'DataCountTotal', 0 ],
717
- [ 'uint16v', 'ParamCountMax', 0 ],
718
- [ 'uint16v', 'DataCountMax', 0 ],
719
- [ 'uint8', 'SetupCountMax', 0 ],
720
- [ 'uint8', 'Reserved1', 0 ],
721
- [ 'uint16v', 'Flags', 0 ],
722
- [ 'uint32v', 'Timeout', 0 ],
723
- [ 'uint16v', 'Reserved2', 0 ],
724
- [ 'uint16v', 'ParamCount', 0 ],
725
- [ 'uint16v', 'ParamOffset', 0 ],
726
- [ 'uint16v', 'DataCount', 0 ],
727
- [ 'uint16v', 'DataOffset', 0 ],
728
- [ 'uint8', 'SetupCount', 0 ],
729
- [ 'uint8', 'Reserved3', 0 ],
730
- [ 'string', 'SetupData', nil, '' ],
731
- [ 'uint16v', 'ByteCount', 0 ],
732
- [ 'string', 'Payload', nil, '' ]
733
- ).create_restraints(
734
- [ 'Payload', 'ByteCount', nil, true ]
735
- )
736
- SMB_TRANS2_PKT = self.make_nbs(SMB_TRANS2_HDR_PKT)
737
-
738
-
739
- # A SMB template for SMB NTTransaction requests
740
- SMB_NTTRANS_HDR_PKT = Rex::Struct2::CStructTemplate.new(
741
- [ 'template', 'SMB', SMB_HDR ],
742
- [ 'uint8', 'SetupCountMax', 0 ],
743
- [ 'uint16v', 'Reserved1', 0 ],
744
- [ 'uint32v', 'ParamCountTotal', 0 ],
745
- [ 'uint32v', 'DataCountTotal', 0 ],
746
- [ 'uint32v', 'ParamCountMax', 0 ],
747
- [ 'uint32v', 'DataCountMax', 0 ],
748
- [ 'uint32v', 'ParamCount', 0 ],
749
- [ 'uint32v', 'ParamOffset', 0 ],
750
- [ 'uint32v', 'DataCount', 0 ],
751
- [ 'uint32v', 'DataOffset', 0 ],
752
- [ 'uint8', 'SetupCount', 0 ],
753
- [ 'uint16v', 'Subcommand', 0 ],
754
- [ 'string', 'SetupData', nil, '' ],
755
- [ 'uint16v', 'ByteCount', 0 ],
756
- [ 'string', 'Payload', nil, '' ]
757
- ).create_restraints(
758
- [ 'Payload', 'ByteCount', nil, true ]
759
- )
760
- SMB_NTTRANS_PKT = self.make_nbs(SMB_NTTRANS_HDR_PKT)
761
-
762
-
763
- # A SMB template for SMB NTTransaction responses
764
- SMB_NTTRANS_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
765
- [ 'template', 'SMB', SMB_HDR ],
766
- [ 'uint8', 'Reserved1', 0 ],
767
- [ 'uint16v', 'Reserved2', 0 ],
768
- [ 'uint32v', 'ParamCountTotal', 0 ],
769
- [ 'uint32v', 'DataCountTotal', 0 ],
770
- [ 'uint32v', 'ParamCount', 0 ],
771
- [ 'uint32v', 'ParamOffset', 0 ],
772
- [ 'uint32v', 'ParamDisplace', 0 ],
773
- [ 'uint32v', 'DataCount', 0 ],
774
- [ 'uint32v', 'DataOffset', 0 ],
775
- [ 'uint32v', 'DataDisplace', 0 ],
776
- [ 'uint8', 'Reserved3', 0 ],
777
- [ 'uint16v', 'ByteCount', 0 ],
778
- [ 'string', 'Payload', nil, '' ]
779
- ).create_restraints(
780
- [ 'Payload', 'ByteCount', nil, true ]
781
- )
782
- SMB_NTTRANS_RES_PKT = self.make_nbs(SMB_NTTRANS_RES_HDR_PKT)
783
-
784
- # A SMB template for SMB NTTransaction_Secondary requests
785
- SMB_NTTRANS_SECONDARY_HDR_PKT = Rex::Struct2::CStructTemplate.new(
786
- [ 'template', 'SMB', SMB_HDR ],
787
- [ 'uint8', 'Reserved1', 0 ],
788
- [ 'uint16v', 'Reserved2', 0 ],
789
- [ 'uint32v', 'ParamCountTotal', 0 ],
790
- [ 'uint32v', 'DataCountTotal', 0 ],
791
- [ 'uint32v', 'ParamCount', 0 ],
792
- [ 'uint32v', 'ParamOffset', 0 ],
793
- [ 'uint32v', 'ParamDisplace', 0 ],
794
- [ 'uint32v', 'DataCount', 0 ],
795
- [ 'uint32v', 'DataOffset', 0 ],
796
- [ 'uint32v', 'DataDisplace', 0 ],
797
- [ 'uint8', 'SetupCount', 0 ],
798
- [ 'string', 'SetupData', nil, '' ],
799
- [ 'uint16v', 'ByteCount', 0 ],
800
- [ 'string', 'Payload', nil, '' ]
801
- ).create_restraints(
802
- [ 'Payload', 'ByteCount', nil, true ]
803
- )
804
- SMB_NTTRANS_SECONDARY_PKT = self.make_nbs(SMB_NTTRANS_SECONDARY_HDR_PKT)
805
-
806
- # A SMB template for SMB Create requests
807
- SMB_CREATE_HDR_PKT = Rex::Struct2::CStructTemplate.new(
808
- [ 'template', 'SMB', SMB_HDR ],
809
- [ 'uint8', 'AndX', 0 ],
810
- [ 'uint8', 'Reserved1', 0 ],
811
- [ 'uint16v', 'AndXOffset', 0 ],
812
- [ 'uint8', 'Reserved2', 0 ],
813
- [ 'uint16v', 'FileNameLen', 0 ],
814
- [ 'uint32v', 'CreateFlags', 0 ],
815
- [ 'uint32v', 'RootFileID', 0 ],
816
- [ 'uint32v', 'AccessMask', 0 ],
817
- [ 'uint32v', 'AllocLow', 0 ],
818
- [ 'uint32v', 'AllocHigh', 0 ],
819
- [ 'uint32v', 'Attributes', 0 ],
820
- [ 'uint32v', 'ShareAccess', 0 ],
821
- [ 'uint32v', 'Disposition', 0 ],
822
- [ 'uint32v', 'CreateOptions', 0 ],
823
- [ 'uint32v', 'Impersonation', 0 ],
824
- [ 'uint8', 'SecurityFlags', 0 ],
825
- [ 'uint16v', 'ByteCount', 0 ],
826
- [ 'string', 'Payload', nil, '' ]
827
- ).create_restraints(
828
- [ 'Payload', 'ByteCount', nil, true ]
829
- )
830
- SMB_CREATE_PKT = self.make_nbs(SMB_CREATE_HDR_PKT)
831
-
832
-
833
- # A SMB template for SMB Create responses
834
- SMB_CREATE_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
835
- [ 'template', 'SMB', SMB_HDR ],
836
- [ 'uint8', 'AndX', 0 ],
837
- [ 'uint8', 'Reserved1', 0 ],
838
- [ 'uint16v', 'AndXOffset', 0 ],
839
- [ 'uint8', 'OpLock', 0 ],
840
- [ 'uint16v', 'FileID', 0 ],
841
- [ 'uint32v', 'Action', 0 ],
842
- [ 'uint32v', 'CreateTimeLow', 0 ],
843
- [ 'uint32v', 'CreateTimeHigh', 0 ],
844
- [ 'uint32v', 'AccessTimeLow', 0 ],
845
- [ 'uint32v', 'AccessTimeHigh', 0 ],
846
- [ 'uint32v', 'WriteTimeLow', 0 ],
847
- [ 'uint32v', 'WriteTimeHigh', 0 ],
848
- [ 'uint32v', 'ChangeTimeLow', 0 ],
849
- [ 'uint32v', 'ChangeTimeHigh', 0 ],
850
- [ 'uint32v', 'Attributes', 0 ],
851
- [ 'uint32v', 'AllocLow', 0 ],
852
- [ 'uint32v', 'AllocHigh', 0 ],
853
- [ 'uint32v', 'EOFLow', 0 ],
854
- [ 'uint32v', 'EOFHigh', 0 ],
855
- [ 'uint16v', 'FileType', 0 ],
856
- [ 'uint16v', 'IPCState', 0 ],
857
- [ 'uint8', 'IsDirectory', 0 ],
858
- [ 'uint16v', 'ByteCount', 0 ],
859
- [ 'string', 'Payload', nil, '' ]
860
- ).create_restraints(
861
- [ 'Payload', 'ByteCount', nil, true ]
862
- )
863
- SMB_CREATE_RES_PKT = self.make_nbs(SMB_CREATE_RES_HDR_PKT)
864
-
865
-
866
- # A SMB template for SMB Write requests
867
- SMB_WRITE_HDR_PKT = Rex::Struct2::CStructTemplate.new(
868
- [ 'template', 'SMB', SMB_HDR ],
869
- [ 'uint8', 'AndX', 0 ],
870
- [ 'uint8', 'Reserved1', 0 ],
871
- [ 'uint16v', 'AndXOffset', 0 ],
872
- [ 'uint16v', 'FileID', 0 ],
873
- [ 'uint32v', 'Offset', 0 ],
874
- [ 'uint32v', 'Reserved2', 0 ],
875
- [ 'uint16v', 'WriteMode', 0 ],
876
- [ 'uint16v', 'Remaining', 0 ],
877
- [ 'uint16v', 'DataLenHigh', 0 ],
878
- [ 'uint16v', 'DataLenLow', 0 ],
879
- [ 'uint16v', 'DataOffset', 0 ],
880
- [ 'uint32v', 'DataOffsetHigh', 0 ],
881
- [ 'uint16v', 'ByteCount', 0 ],
882
- [ 'string', 'Payload', nil, '' ]
883
- ).create_restraints(
884
- [ 'Payload', 'ByteCount', nil, true ]
885
- )
886
- SMB_WRITE_PKT = self.make_nbs(SMB_WRITE_HDR_PKT)
887
-
888
-
889
- # A SMB template for SMB Write responses
890
- SMB_WRITE_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
891
- [ 'template', 'SMB', SMB_HDR ],
892
- [ 'uint8', 'AndX', 0 ],
893
- [ 'uint8', 'Reserved1', 0 ],
894
- [ 'uint16v', 'AndXOffset', 0 ],
895
- [ 'uint16v', 'CountLow', 0 ],
896
- [ 'uint16v', 'Remaining', 0 ],
897
- [ 'uint16v', 'CountHigh', 0 ],
898
- [ 'uint16v', 'Reserved2', 0 ],
899
- [ 'uint16v', 'ByteCount', 0 ],
900
- [ 'string', 'Payload', nil, '' ]
901
- ).create_restraints(
902
- [ 'Payload', 'ByteCount', nil, true ]
903
- )
904
- SMB_WRITE_RES_PKT = self.make_nbs(SMB_WRITE_RES_HDR_PKT)
905
-
906
-
907
- # A SMB template for SMB OPEN requests
908
- SMB_OPEN_HDR_PKT = Rex::Struct2::CStructTemplate.new(
909
- [ 'template', 'SMB', SMB_HDR ],
910
- [ 'uint8', 'AndX', 0 ],
911
- [ 'uint8', 'Reserved1', 0 ],
912
- [ 'uint16v', 'AndXOffset', 0 ],
913
- [ 'uint16v', 'Flags', 0 ],
914
- [ 'uint16v', 'Access', 0 ],
915
- [ 'uint16v', 'SearchAttributes', 0 ],
916
- [ 'uint16v', 'FileAttributes', 0 ],
917
- [ 'uint32v', 'CreateTime', 0 ],
918
- [ 'uint16v', 'OpenFunction', 0 ],
919
- [ 'uint32v', 'AllocSize', 0 ],
920
- [ 'uint32v', 'Reserved2', 0 ],
921
- [ 'uint32v', 'Reserved3', 0 ],
922
- [ 'uint16v', 'ByteCount', 0 ],
923
- [ 'string', 'Payload', nil, '' ]
924
- ).create_restraints(
925
- [ 'Payload', 'ByteCount', nil, true ]
926
- )
927
- SMB_OPEN_PKT = self.make_nbs(SMB_OPEN_HDR_PKT)
928
-
929
-
930
- # A SMB template for SMB OPEN responses
931
- SMB_OPEN_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
932
- [ 'template', 'SMB', SMB_HDR ],
933
- [ 'uint8', 'AndX', 0 ],
934
- [ 'uint8', 'Reserved1', 0 ],
935
- [ 'uint16v', 'AndXOffset', 0 ],
936
- [ 'uint16v', 'FileID', 0 ],
937
- [ 'uint16v', 'FileAttributes', 0 ],
938
- [ 'uint32v', 'WriteTime', 0 ],
939
- [ 'uint32v', 'FileSize', 0 ],
940
- [ 'uint16v', 'FileAccess', 0 ],
941
- [ 'uint16v', 'FileType', 0 ],
942
- [ 'uint16v', 'IPCState', 0 ],
943
- [ 'uint16v', 'Action', 0 ],
944
- [ 'uint32v', 'ServerFileID', 0 ],
945
- [ 'uint16v', 'Reserved2', 0 ],
946
- [ 'uint16v', 'ByteCount', 0 ],
947
- [ 'string', 'Payload', nil, '' ]
948
- ).create_restraints(
949
- [ 'Payload', 'ByteCount', nil, true ]
950
- )
951
- SMB_OPEN_RES_PKT = self.make_nbs(SMB_OPEN_RES_HDR_PKT)
952
-
953
-
954
- # A SMB template for SMB Close requests
955
- SMB_CLOSE_HDR_PKT = Rex::Struct2::CStructTemplate.new(
956
- [ 'template', 'SMB', SMB_HDR ],
957
- [ 'uint16v', 'FileID', 0 ],
958
- [ 'uint32v', 'LastWrite', 0 ],
959
- [ 'uint16v', 'ByteCount', 0 ],
960
- [ 'string', 'Payload', nil, '' ]
961
- ).create_restraints(
962
- [ 'Payload', 'ByteCount', nil, true ]
963
- )
964
- SMB_CLOSE_PKT = self.make_nbs(SMB_CLOSE_HDR_PKT)
965
-
966
-
967
- # A SMB template for SMB Close responses
968
- SMB_CLOSE_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
969
- [ 'template', 'SMB', SMB_HDR ],
970
- [ 'uint16v', 'ByteCount', 0 ],
971
- [ 'string', 'Payload', nil, '' ]
972
- ).create_restraints(
973
- [ 'Payload', 'ByteCount', nil, true ]
974
- )
975
- SMB_CLOSE_RES_PKT = self.make_nbs(SMB_CLOSE_RES_HDR_PKT)
976
-
977
-
978
- # A SMB template for SMB Delete requests
979
- SMB_DELETE_HDR_PKT = Rex::Struct2::CStructTemplate.new(
980
- [ 'template', 'SMB', SMB_HDR ],
981
- [ 'uint16v', 'SearchAttribute', 0 ],
982
- [ 'uint16v', 'ByteCount', 0 ],
983
- [ 'uint8', 'BufferFormat', 0 ],
984
- [ 'string', 'Payload', nil, '' ]
985
- ).create_restraints(
986
- [ 'Payload', 'ByteCount', nil, true ]
987
- )
988
- SMB_DELETE_PKT = self.make_nbs(SMB_DELETE_HDR_PKT)
989
-
990
-
991
- # A SMB template for SMB Delete responses
992
- SMB_DELETE_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
993
- [ 'template', 'SMB', SMB_HDR ],
994
- [ 'uint16v', 'ByteCount', 0 ],
995
- [ 'string', 'Payload', nil, '' ]
996
- ).create_restraints(
997
- [ 'Payload', 'ByteCount', nil, true ]
998
- )
999
- SMB_DELETE_RES_PKT = self.make_nbs(SMB_DELETE_RES_HDR_PKT)
1000
-
1001
-
1002
-
1003
- # A SMB template for SMB Read requests
1004
- SMB_READ_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1005
- [ 'template', 'SMB', SMB_HDR ],
1006
- [ 'uint8', 'AndX', 0 ],
1007
- [ 'uint8', 'Reserved1', 0 ],
1008
- [ 'uint16v', 'AndXOffset', 0 ],
1009
- [ 'uint16v', 'FileID', 0 ],
1010
- [ 'uint32v', 'Offset', 0 ],
1011
- [ 'uint16v', 'MaxCountLow', 0 ],
1012
- [ 'uint16v', 'MinCount', 0 ],
1013
- [ 'uint32v', 'Reserved2', 0 ],
1014
- [ 'uint16v', 'Remaining', 0 ],
1015
- [ 'uint32v', 'MaxCountHigh', 0 ],
1016
- [ 'uint16v', 'ByteCount', 0 ],
1017
- [ 'string', 'Payload', nil, '' ]
1018
- ).create_restraints(
1019
- [ 'Payload', 'ByteCount', nil, true ]
1020
- )
1021
- SMB_READ_PKT = self.make_nbs(SMB_READ_HDR_PKT)
1022
-
1023
-
1024
- # A SMB template for SMB Read responses
1025
- SMB_READ_RES_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1026
- [ 'template', 'SMB', SMB_HDR ],
1027
- [ 'uint8', 'AndX', 0 ],
1028
- [ 'uint8', 'Reserved1', 0 ],
1029
- [ 'uint16v', 'AndXOffset', 0 ],
1030
- [ 'uint16v', 'Remaining', 0 ],
1031
- [ 'uint16v', 'DataCompaction', 0 ],
1032
- [ 'uint16v', 'Reserved2', 0 ],
1033
- [ 'uint16v', 'DataLenLow', 0 ],
1034
- [ 'uint16v', 'DataOffset', 0 ],
1035
- [ 'uint32v', 'DataLenHigh', 0 ],
1036
- [ 'uint32v', 'Reserved3', 0 ],
1037
- [ 'uint16v', 'Reserved4', 0 ],
1038
- [ 'uint16v', 'ByteCount', 0 ],
1039
- [ 'string', 'Payload', nil, '' ]
1040
- ).create_restraints(
1041
- [ 'Payload', 'ByteCount', nil, true ]
1042
- )
1043
- SMB_READ_RES_PKT = self.make_nbs(SMB_READ_RES_HDR_PKT)
1044
-
1045
-
1046
-
1047
- # A SMB template for SMB Search requests
1048
- SMB_SEARCH_HDR_PKT = Rex::Struct2::CStructTemplate.new(
1049
- [ 'template', 'SMB', SMB_HDR ],
1050
- [ 'uint16v', 'MaxCount', 0 ],
1051
- [ 'uint16v', 'Attributes', 0 ],
1052
- [ 'uint16v', 'ByteCount', 0 ],
1053
- [ 'string', 'Payload', nil, '' ]
1054
- ).create_restraints(
1055
- [ 'Payload', 'ByteCount', nil, true ]
1056
- )
1057
- SMB_SEARCH_PKT = self.make_nbs(SMB_SEARCH_HDR_PKT)
1376
+ # A template for SMB_Parameters blocks of the SMB_COM_TRANSACTION2 FIND_FIRST2 responses
1377
+ SMB_TRANS2_FIND_FIRST2_PARAMETERS = Rex::Struct2::CStructTemplate.new(
1378
+ ['uint16v', 'SearchAttributes', 0],
1379
+ ['uint16v', 'SearchCount', 0],
1380
+ ['uint16v', 'Flags', 0],
1381
+ ['uint16v', 'InformationLevel', 0],
1382
+ ['uint32v', 'SearchStorageType', 0],
1383
+ ['string', 'FileName', nil, '']
1384
+ )
1058
1385
 
1386
+ # A template for SMB Tree Connect commands in responses
1387
+ SMB_TREE_CONN_ANDX_RES_PKT = Rex::Struct2::CStructTemplate.new(
1388
+ ['uint8', 'WordCount', 0],
1389
+ ['uint8', 'AndXCommand', 0],
1390
+ ['uint8', 'AndXReserved', 0],
1391
+ ['uint16v', 'AndXOffset', 0],
1392
+ ['uint16v', 'OptionalSupport', 0],
1393
+ ['uint32v', 'AccessRights', 0],
1394
+ ['uint32v', 'GuestAccessRights', 0],
1395
+ ['uint16v', 'ByteCount', 0],
1396
+ ['string', 'Payload', nil, '']
1397
+ ).create_restraints(
1398
+ [ 'Payload', 'ByteCount', nil, true ]
1399
+ )
1059
1400
 
1060
1401
  end
1061
1402
  end