ruby_smb 3.1.1 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -2
- data/examples/file_server.rb +6 -61
- data/examples/virtual_file_server.rb +91 -0
- data/lib/ruby_smb/client/authentication.rb +12 -2
- data/lib/ruby_smb/client/negotiation.rb +2 -0
- data/lib/ruby_smb/client.rb +8 -2
- data/lib/ruby_smb/error.rb +4 -0
- data/lib/ruby_smb/fscc/file_information/file_access_information.rb +15 -0
- data/lib/ruby_smb/fscc/file_information/file_alignment_information.rb +45 -0
- data/lib/ruby_smb/fscc/file_information/file_all_information.rb +23 -0
- data/lib/ruby_smb/fscc/file_information/file_basic_information.rb +20 -0
- data/lib/ruby_smb/fscc/file_information/file_both_directory_information.rb +3 -3
- data/lib/ruby_smb/fscc/file_information/file_directory_information.rb +3 -3
- data/lib/ruby_smb/fscc/file_information/file_ea_information.rb +1 -0
- data/lib/ruby_smb/fscc/file_information/file_full_directory_information.rb +3 -3
- data/lib/ruby_smb/fscc/file_information/file_id_both_directory_information.rb +3 -3
- data/lib/ruby_smb/fscc/file_information/file_id_full_directory_information.rb +3 -3
- data/lib/ruby_smb/fscc/file_information/file_internal_information.rb +15 -0
- data/lib/ruby_smb/fscc/file_information/file_mode_information.rb +29 -0
- data/lib/ruby_smb/fscc/file_information/file_name_information.rb +16 -0
- data/lib/ruby_smb/fscc/file_information/file_names_information.rb +1 -1
- data/lib/ruby_smb/fscc/file_information/file_normalized_name_information.rb +16 -0
- data/lib/ruby_smb/fscc/file_information/file_position_information.rb +15 -0
- data/lib/ruby_smb/fscc/file_information/file_rename_information.rb +1 -1
- data/lib/ruby_smb/fscc/file_information/file_standard_information.rb +20 -0
- data/lib/ruby_smb/fscc/file_information/file_stream_information.rb +3 -0
- data/lib/ruby_smb/fscc/file_information.rb +41 -8
- data/lib/ruby_smb/fscc/file_system_information/file_fs_attribute_information.rb +1 -0
- data/lib/ruby_smb/fscc/file_system_information/file_fs_volume_information.rb +1 -0
- data/lib/ruby_smb/fscc/file_system_information.rb +4 -0
- data/lib/ruby_smb/gss/provider/ntlm.rb +16 -3
- data/lib/ruby_smb/gss/provider.rb +10 -1
- data/lib/ruby_smb/gss.rb +1 -0
- data/lib/ruby_smb/ntlm/client.rb +74 -0
- data/lib/ruby_smb/ntlm.rb +1 -0
- data/lib/ruby_smb/server/cli.rb +121 -0
- data/lib/ruby_smb/server/server_client/session_setup.rb +4 -2
- data/lib/ruby_smb/server/server_client.rb +9 -1
- data/lib/ruby_smb/server/session.rb +5 -1
- data/lib/ruby_smb/server/share/provider/disk/processor/close.rb +9 -5
- data/lib/ruby_smb/server/share/provider/disk/processor/create.rb +2 -2
- data/lib/ruby_smb/server/share/provider/disk/processor/query.rb +2 -2
- data/lib/ruby_smb/server/share/provider/disk/processor/read.rb +15 -14
- data/lib/ruby_smb/server/share/provider/disk/processor.rb +76 -12
- data/lib/ruby_smb/server/share/provider/disk.rb +8 -2
- data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb +85 -0
- data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname.rb +196 -0
- data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_stat.rb +175 -0
- data/lib/ruby_smb/server/share/provider/virtual_disk.rb +116 -0
- data/lib/ruby_smb/server/share/provider.rb +1 -0
- data/lib/ruby_smb/server.rb +14 -3
- data/lib/ruby_smb/smb1/packet/session_setup_request.rb +11 -0
- data/lib/ruby_smb/smb2/tree.rb +1 -0
- data/lib/ruby_smb/version.rb +1 -1
- data/spec/lib/ruby_smb/fscc/file_information/file_access_information_spec.rb +21 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_alignment_information_spec.rb +21 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_all_information_spec.rb +61 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_basic_information_spec.rb +41 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_both_directory_information_spec.rb +59 -10
- data/spec/lib/ruby_smb/fscc/file_information/file_directory_information_spec.rb +30 -12
- data/spec/lib/ruby_smb/fscc/file_information/file_ea_information_spec.rb +21 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_full_directory_information_spec.rb +30 -12
- data/spec/lib/ruby_smb/fscc/file_information/file_id_both_directory_information_spec.rb +63 -10
- data/spec/lib/ruby_smb/fscc/file_information/file_id_full_directory_information_spec.rb +30 -12
- data/spec/lib/ruby_smb/fscc/file_information/file_internal_information_spec.rb +21 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_mode_information_spec.rb +21 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_name_information_spec.rb +44 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_names_information_spec.rb +30 -12
- data/spec/lib/ruby_smb/fscc/file_information/file_network_open_information_spec.rb +51 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_normalized_name_information_spec.rb +44 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_position_information_spec.rb +21 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_rename_information_spec.rb +1 -1
- data/spec/lib/ruby_smb/fscc/file_information/file_standard_information_spec.rb +41 -0
- data/spec/lib/ruby_smb/fscc/file_information/file_stream_information_spec.rb +51 -0
- data/spec/lib/ruby_smb/fscc/file_information_spec.rb +14 -0
- data/spec/lib/ruby_smb/fscc/file_system_information/file_fs_attribute_information_spec.rb +46 -0
- data/spec/lib/ruby_smb/fscc/file_system_information/file_fs_volume_information_spec.rb +51 -0
- data/spec/lib/ruby_smb/fscc/file_system_information_spec.rb +14 -0
- data/spec/lib/ruby_smb/ntlm/client/session_spec.rb +114 -0
- data/spec/lib/ruby_smb/ntlm/client_spec.rb +36 -0
- data/spec/lib/ruby_smb/server/server_client_spec.rb +15 -0
- data/spec/lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname_spec.rb +581 -0
- data/spec/lib/ruby_smb/server/share/provider/virtual_disk/virtual_stat_spec.rb +207 -0
- data/spec/lib/ruby_smb/server/share/provider/virtual_disk_spec.rb +122 -0
- data.tar.gz.sig +0 -0
- metadata +63 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 587f03eec26c36a6ca67ffde30bb05881a456609dff32873b912e7763d266f25
|
|
4
|
+
data.tar.gz: 18c3b50b89657fe874d0a13904dad2b36c01c49089f01b5a3821d1733eb07c61
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cd6f94e4b093ecab453e6e7f2056bfb7b52fbf2cfec51a26eceb2761b98c78bfd0fe273f083b1ec7db69f553ac7b8fb594e4d7c31ea8468e02337611b0bd4541
|
|
7
|
+
data.tar.gz: 4b5d924834a9168458ad50afcf6b27df5ba9ab50632b4b81db1e226235c7ebe80540e05fdc4aa6a6a608a6365e83f937304e0289a9d8e5689480f3021f6dd07e
|
checksums.yaml.gz.sig
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
�|�A�C���\�~ۀ.�T)? ~\G��kG��z��� ����}'>
|
|
1
|
+
2�Q�k��� :�x_��'{Ѷ?����Y������;�}���5
|
data/examples/file_server.rb
CHANGED
|
@@ -3,74 +3,19 @@
|
|
|
3
3
|
require 'bundler/setup'
|
|
4
4
|
require 'optparse'
|
|
5
5
|
require 'ruby_smb'
|
|
6
|
-
require 'ruby_smb/gss/provider/ntlm'
|
|
7
6
|
|
|
8
7
|
# we just need *a* default encoding to handle the strings from the NTLM messages
|
|
9
8
|
Encoding.default_internal = 'UTF-8' if Encoding.default_internal.nil?
|
|
10
9
|
|
|
11
|
-
options = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
password: 'password',
|
|
16
|
-
share_name: 'home',
|
|
17
|
-
share_path: '.',
|
|
18
|
-
smbv1: true,
|
|
19
|
-
smbv2: true,
|
|
20
|
-
smbv3: true
|
|
21
|
-
}
|
|
22
|
-
OptionParser.new do |opts|
|
|
23
|
-
opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
|
|
24
|
-
opts.on("--path PATH", "The path to share (default: #{options[:share_path]})") do |path|
|
|
10
|
+
options = RubySMB::Server::Cli.parse(defaults: { share_path: '.' }) do |options, parser|
|
|
11
|
+
parser.banner = "Usage: #{File.basename(__FILE__)} [options]"
|
|
12
|
+
|
|
13
|
+
parser.on("--share-path SHARE_PATH", "The path to share (default: #{options[:share_path]})") do |path|
|
|
25
14
|
options[:share_path] = path
|
|
26
15
|
end
|
|
27
|
-
opts.on("--share SHARE", "The share name (default: #{options[:share_name]})") do |share|
|
|
28
|
-
options[:share_name] = share
|
|
29
|
-
end
|
|
30
|
-
opts.on("--[no-]anonymous", "Allow anonymous access (default: #{options[:allow_anonymous]})") do |allow_anonymous|
|
|
31
|
-
options[:allow_anonymous] = allow_anonymous
|
|
32
|
-
end
|
|
33
|
-
opts.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{options[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1|
|
|
34
|
-
options[:smbv1] = smbv1
|
|
35
|
-
end
|
|
36
|
-
opts.on("--[no-]smbv2", "Enable or disable SMBv2 (default: #{options[:smbv2] ? 'Enabled' : 'Disabled'})") do |smbv2|
|
|
37
|
-
options[:smbv2] = smbv2
|
|
38
|
-
end
|
|
39
|
-
opts.on("--[no-]smbv3", "Enable or disable SMBv3 (default: #{options[:smbv3] ? 'Enabled' : 'Disabled'})") do |smbv3|
|
|
40
|
-
options[:smbv3] = smbv3
|
|
41
|
-
end
|
|
42
|
-
opts.on("--username USERNAME", "The account's username (default: #{options[:username]})") do |username|
|
|
43
|
-
if username.include?('\\')
|
|
44
|
-
options[:domain], options[:username] = username.split('\\', 2)
|
|
45
|
-
else
|
|
46
|
-
options[:username] = username
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
opts.on("--password PASSWORD", "The account's password (default: #{options[:password]})") do |password|
|
|
50
|
-
options[:password] = password
|
|
51
|
-
end
|
|
52
|
-
end.parse!
|
|
53
|
-
|
|
54
|
-
ntlm_provider = RubySMB::Gss::Provider::NTLM.new(allow_anonymous: options[:allow_anonymous])
|
|
55
|
-
ntlm_provider.put_account(options[:username], options[:password], domain: options[:domain]) # password can also be an NTLM hash
|
|
56
|
-
|
|
57
|
-
server = RubySMB::Server.new(
|
|
58
|
-
gss_provider: ntlm_provider,
|
|
59
|
-
logger: :stdout
|
|
60
|
-
)
|
|
61
|
-
server.dialects.select! { |dialect| RubySMB::Dialect[dialect].family != RubySMB::Dialect::FAMILY_SMB1 } unless options[:smbv1]
|
|
62
|
-
server.dialects.select! { |dialect| RubySMB::Dialect[dialect].family != RubySMB::Dialect::FAMILY_SMB2 } unless options[:smbv2]
|
|
63
|
-
server.dialects.select! { |dialect| RubySMB::Dialect[dialect].family != RubySMB::Dialect::FAMILY_SMB3 } unless options[:smbv3]
|
|
64
|
-
|
|
65
|
-
if server.dialects.empty?
|
|
66
|
-
puts "at least one version must be enabled"
|
|
67
|
-
exit false
|
|
68
16
|
end
|
|
69
17
|
|
|
18
|
+
server = RubySMB::Server::Cli.build(options)
|
|
70
19
|
server.add_share(RubySMB::Server::Share::Provider::Disk.new(options[:share_name], options[:share_path]))
|
|
71
|
-
puts "server is running"
|
|
72
|
-
server.run do
|
|
73
|
-
puts "received connection"
|
|
74
|
-
true
|
|
75
|
-
end
|
|
76
20
|
|
|
21
|
+
RubySMB::Server::Cli.run(server)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/ruby
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'optparse'
|
|
5
|
+
require 'ruby_smb'
|
|
6
|
+
|
|
7
|
+
# we just need *a* default encoding to handle the strings from the NTLM messages
|
|
8
|
+
Encoding.default_internal = 'UTF-8' if Encoding.default_internal.nil?
|
|
9
|
+
|
|
10
|
+
# see: https://en.wikipedia.org/wiki/Magic_8-ball#Possible_answers
|
|
11
|
+
MAGIC_8_BALL_ANSWERS = [
|
|
12
|
+
'It is certain.',
|
|
13
|
+
'It is decidedly so.',
|
|
14
|
+
'Without a doubt.',
|
|
15
|
+
'Yes definitely.',
|
|
16
|
+
'You may rely on it.',
|
|
17
|
+
'As I see it, yes.',
|
|
18
|
+
'Most likely.',
|
|
19
|
+
'Outlook good.',
|
|
20
|
+
'Yes.',
|
|
21
|
+
'Signs point to yes.',
|
|
22
|
+
'Reply hazy, try again.',
|
|
23
|
+
'Ask again later.',
|
|
24
|
+
'Better not tell you now.',
|
|
25
|
+
'Cannot predict now.',
|
|
26
|
+
'Concentrate and ask again.',
|
|
27
|
+
'Don\'t count on it.',
|
|
28
|
+
'My reply is no.',
|
|
29
|
+
'My sources say no.',
|
|
30
|
+
'Outlook not so good.',
|
|
31
|
+
'Very doubtful'
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
options = RubySMB::Server::Cli.parse do |options, parser|
|
|
35
|
+
parser.banner = "Usage: #{File.basename(__FILE__)} [options]"
|
|
36
|
+
|
|
37
|
+
parser.on("--virtual-content CONTENT", "The virtual share contents") do |virtual_content|
|
|
38
|
+
options[:virtual_content] = virtual_content
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
parser.on("--virtual-name NAME", "The virtual share file name") do |virtual_name|
|
|
42
|
+
options[:virtual_name] = virtual_name
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
parser.on("--virtual-type TYPE", "The virtual share type") do |virtual_type|
|
|
46
|
+
options[:virtual_type] = virtual_type
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
server = RubySMB::Server::Cli.build(options)
|
|
51
|
+
virtual_disk = RubySMB::Server::Share::Provider::VirtualDisk.new(options[:share_name])
|
|
52
|
+
|
|
53
|
+
# greeting is a static text file
|
|
54
|
+
virtual_disk.add_static_file('greeting', 'Hello World!')
|
|
55
|
+
|
|
56
|
+
# self is this example file, it's read when it's added and its #stat object is copied over
|
|
57
|
+
virtual_disk.add_static_file('self/static', File.open(__FILE__))
|
|
58
|
+
|
|
59
|
+
# self is this example file, it's mapped in using a real Pathname object
|
|
60
|
+
virtual_disk.add_mapped_file('self/mapped', Pathname.new(File.expand_path(__FILE__)))
|
|
61
|
+
|
|
62
|
+
# magic_8_ball is a dynamic file that is generated each time it is open
|
|
63
|
+
virtual_disk.add_dynamic_file('magic_8_ball') do
|
|
64
|
+
MAGIC_8_BALL_ANSWERS.sample
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
if options[:virtual_content] && options[:virtual_name] && options[:virtual_type]
|
|
68
|
+
case options[:virtual_type].downcase
|
|
69
|
+
when 'static'
|
|
70
|
+
# for static, content is left as is
|
|
71
|
+
virtual_disk.add_static_file(options[:virtual_name], options[:virtual_content])
|
|
72
|
+
when 'mapped'
|
|
73
|
+
# for mapped, content is a file path
|
|
74
|
+
virtual_disk.add_mapped_file(options[:virtual_name], Pathname.new(File.expand_path(options[:virtual_content])))
|
|
75
|
+
when 'dynamic'
|
|
76
|
+
# for dynamic, content is a file path
|
|
77
|
+
virtual_disk.add_dynamic_file(options[:virtual_name]) do
|
|
78
|
+
File.read(options[:virtual_content])
|
|
79
|
+
end
|
|
80
|
+
else
|
|
81
|
+
puts "virtual type: #{options[:virtual_type]}, must be one of static, mapped, or dynamic"
|
|
82
|
+
exit false
|
|
83
|
+
end
|
|
84
|
+
elsif options[:virtual_content] || options[:virtual_name] || options[:virtual_type]
|
|
85
|
+
puts 'the --virtual-* flags are only used when all are specified'
|
|
86
|
+
exit false
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
server.add_share(virtual_disk)
|
|
90
|
+
|
|
91
|
+
RubySMB::Server::Cli.run(server)
|
|
@@ -146,7 +146,7 @@ module RubySMB
|
|
|
146
146
|
end
|
|
147
147
|
|
|
148
148
|
# Takes the raw binary string and returns a {RubySMB::SMB1::Packet::SessionSetupResponse}
|
|
149
|
-
def
|
|
149
|
+
def smb1_session_setup_response(raw_response)
|
|
150
150
|
packet = RubySMB::SMB1::Packet::SessionSetupResponse.read(raw_response)
|
|
151
151
|
|
|
152
152
|
unless packet.valid?
|
|
@@ -159,6 +159,11 @@ module RubySMB
|
|
|
159
159
|
packet
|
|
160
160
|
end
|
|
161
161
|
|
|
162
|
+
# Takes the raw binary string and returns a {RubySMB::SMB1::Packet::SessionSetupResponse}
|
|
163
|
+
def smb1_ntlmssp_final_packet(raw_response)
|
|
164
|
+
smb1_session_setup_response(raw_response)
|
|
165
|
+
end
|
|
166
|
+
|
|
162
167
|
# Takes the raw binary string and returns a {RubySMB::SMB1::Packet::SessionSetupResponse}
|
|
163
168
|
def smb1_ntlmssp_challenge_packet(raw_response)
|
|
164
169
|
packet = RubySMB::SMB1::Packet::SessionSetupResponse.read(raw_response)
|
|
@@ -235,7 +240,7 @@ module RubySMB
|
|
|
235
240
|
end
|
|
236
241
|
|
|
237
242
|
# Takes the raw binary string and returns a {RubySMB::SMB2::Packet::SessionSetupResponse}
|
|
238
|
-
def
|
|
243
|
+
def smb2_session_setup_response(raw_response)
|
|
239
244
|
packet = RubySMB::SMB2::Packet::SessionSetupResponse.read(raw_response)
|
|
240
245
|
unless packet.valid?
|
|
241
246
|
raise RubySMB::Error::InvalidPacket.new(
|
|
@@ -248,6 +253,11 @@ module RubySMB
|
|
|
248
253
|
packet
|
|
249
254
|
end
|
|
250
255
|
|
|
256
|
+
# Takes the raw binary string and returns a {RubySMB::SMB2::Packet::SessionSetupResponse}
|
|
257
|
+
def smb2_ntlmssp_final_packet(raw_response)
|
|
258
|
+
smb2_session_setup_response(raw_response)
|
|
259
|
+
end
|
|
260
|
+
|
|
251
261
|
# Takes the raw binary string and returns a {RubySMB::SMB2::Packet::SessionSetupResponse}
|
|
252
262
|
def smb2_ntlmssp_challenge_packet(raw_response)
|
|
253
263
|
packet = RubySMB::SMB2::Packet::SessionSetupResponse.read(raw_response)
|
|
@@ -118,6 +118,7 @@ module RubySMB
|
|
|
118
118
|
self.server_max_buffer_size = packet.parameter_block.max_buffer_size - 260
|
|
119
119
|
self.negotiated_smb_version = 1
|
|
120
120
|
self.session_encrypt_data = false
|
|
121
|
+
self.negotiation_security_buffer = packet.data_block.security_blob
|
|
121
122
|
'SMB1'
|
|
122
123
|
when RubySMB::SMB2::Packet::NegotiateResponse
|
|
123
124
|
self.smb1 = false
|
|
@@ -137,6 +138,7 @@ module RubySMB
|
|
|
137
138
|
self.server_start_time = packet.server_start_time.to_time if packet.server_start_time != 0
|
|
138
139
|
self.server_system_time = packet.system_time.to_time if packet.system_time != 0
|
|
139
140
|
self.server_supports_multi_credit = self.dialect != '0x0202' && packet&.capabilities&.large_mtu == 1
|
|
141
|
+
self.negotiation_security_buffer = packet.security_buffer
|
|
140
142
|
case self.dialect
|
|
141
143
|
when '0x02ff'
|
|
142
144
|
when '0x0300', '0x0302'
|
data/lib/ruby_smb/client.rb
CHANGED
|
@@ -295,6 +295,12 @@ module RubySMB
|
|
|
295
295
|
# false otherwise
|
|
296
296
|
attr_accessor :server_supports_multi_credit
|
|
297
297
|
|
|
298
|
+
# The negotiated security buffer. This is nil until the negotiation process
|
|
299
|
+
# has finished.
|
|
300
|
+
# @!attribute [rw] negotiation_security_buffer
|
|
301
|
+
# @return [String] The raw security buffer bytes
|
|
302
|
+
attr_accessor :negotiation_security_buffer
|
|
303
|
+
|
|
298
304
|
# @param dispatcher [RubySMB::Dispatcher::Socket] the packet dispatcher to use
|
|
299
305
|
# @param smb1 [Boolean] whether or not to enable SMB1 support
|
|
300
306
|
# @param smb2 [Boolean] whether or not to enable SMB2 support
|
|
@@ -332,7 +338,7 @@ module RubySMB
|
|
|
332
338
|
# session setup response is received
|
|
333
339
|
@session_encrypt_data = always_encrypt
|
|
334
340
|
|
|
335
|
-
@ntlm_client =
|
|
341
|
+
@ntlm_client = RubySMB::NTLM::Client.new(
|
|
336
342
|
@username,
|
|
337
343
|
@password,
|
|
338
344
|
workstation: @local_workstation,
|
|
@@ -404,7 +410,7 @@ module RubySMB
|
|
|
404
410
|
@password = pass.encode('utf-8') || ''.encode('utf-8')
|
|
405
411
|
@username = user.encode('utf-8') || ''.encode('utf-8')
|
|
406
412
|
|
|
407
|
-
@ntlm_client =
|
|
413
|
+
@ntlm_client = RubySMB::NTLM::Client.new(
|
|
408
414
|
@username,
|
|
409
415
|
@password,
|
|
410
416
|
workstation: @local_workstation,
|
data/lib/ruby_smb/error.rb
CHANGED
|
@@ -99,6 +99,10 @@ module RubySMB
|
|
|
99
99
|
# unsupported protocol.
|
|
100
100
|
class NegotiationFailure < RubySMBError; end
|
|
101
101
|
|
|
102
|
+
# Raised when Authentication fails, possibly due to an
|
|
103
|
+
# unsupported GSS mechanism type.
|
|
104
|
+
class AuthenticationFailure < RubySMBError; end
|
|
105
|
+
|
|
102
106
|
# Raised when trying to parse raw binary into a BitField and the data
|
|
103
107
|
# is invalid.
|
|
104
108
|
class InvalidBitField < RubySMBError; end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module RubySMB
|
|
2
|
+
module Fscc
|
|
3
|
+
module FileInformation
|
|
4
|
+
# The FileAccessInformation Class as defined in
|
|
5
|
+
# [2.4.1 FileAccessInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/01cf43d2-deb3-40d3-a39b-9e68693d7c90)
|
|
6
|
+
class FileAccessInformation < BinData::Record
|
|
7
|
+
CLASS_LEVEL = FileInformation::FILE_ACCESS_INFORMATION
|
|
8
|
+
|
|
9
|
+
endian :little
|
|
10
|
+
|
|
11
|
+
uint32 :access_flags, label: 'Access Flags'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module RubySMB
|
|
2
|
+
module Fscc
|
|
3
|
+
module FileInformation
|
|
4
|
+
# The FileAlignmentInformation Class as defined in
|
|
5
|
+
# [2.4.3 FileAlignmentInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/9b0b9971-85aa-4651-8438-f1c4298bcb0d)
|
|
6
|
+
class FileAlignmentInformation < BinData::Record
|
|
7
|
+
CLASS_LEVEL = FileInformation::FILE_ALIGNMENT_INFORMATION
|
|
8
|
+
|
|
9
|
+
# If this value is specified, there are no alignment requirements for the device.
|
|
10
|
+
FILE_BYTE_ALIGNMENT = 0x00000000 # 0
|
|
11
|
+
|
|
12
|
+
# If this value is specified, data MUST be aligned on a 2-byte boundary.
|
|
13
|
+
FILE_WORD_ALIGNMENT = 0x00000001 # 1
|
|
14
|
+
|
|
15
|
+
# If this value is specified, data MUST be aligned on a 4-byte boundary.
|
|
16
|
+
FILE_LONG_ALIGNMENT = 0x00000003 # 3
|
|
17
|
+
|
|
18
|
+
# If this value is specified, data MUST be aligned on an 8-byte boundary.
|
|
19
|
+
FILE_QUAD_ALIGNMENT = 0x00000007 # 7
|
|
20
|
+
|
|
21
|
+
# If this value is specified, data MUST be aligned on a 16-byte boundary.
|
|
22
|
+
FILE_OCTA_ALIGNMENT = 0X0000000F # 15
|
|
23
|
+
|
|
24
|
+
# If this value is specified, data MUST be aligned on a 32-byte boundary.
|
|
25
|
+
FILE_32_BYTE_ALIGNMENT = 0X0000001F # 31
|
|
26
|
+
|
|
27
|
+
# If this value is specified, data MUST be aligned on a 64-byte boundary.
|
|
28
|
+
FILE_64_BYTE_ALIGNMENT = 0X0000003F # 63
|
|
29
|
+
|
|
30
|
+
# If this value is specified, data MUST be aligned on a 128-byte boundary.
|
|
31
|
+
FILE_128_BYTE_ALIGNMENT = 0X0000007F # 127
|
|
32
|
+
|
|
33
|
+
# If this value is specified, data MUST be aligned on a 256-byte boundary.
|
|
34
|
+
FILE_256_BYTE_ALIGNMENT = 0X000000FF # 255
|
|
35
|
+
|
|
36
|
+
# If this value is specified, data MUST be aligned on a 512-byte boundary.
|
|
37
|
+
FILE_512_BYTE_ALIGNMENT = 0X000001FF # 511
|
|
38
|
+
|
|
39
|
+
endian :little
|
|
40
|
+
|
|
41
|
+
uint32 :alignment_requirement, label: 'Alignment Requirement', initial_value: FILE_BYTE_ALIGNMENT
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module RubySMB
|
|
2
|
+
module Fscc
|
|
3
|
+
module FileInformation
|
|
4
|
+
# The FileAllInformation Class as defined in
|
|
5
|
+
# [2.4.2 FileAllInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/95f3056a-ebc1-4f5d-b938-3f68a44677a6)
|
|
6
|
+
class FileAllInformation < BinData::Record
|
|
7
|
+
CLASS_LEVEL = FileInformation::FILE_ALL_INFORMATION
|
|
8
|
+
|
|
9
|
+
endian :little
|
|
10
|
+
|
|
11
|
+
file_basic_information :basic_information, label: 'Basic Information'
|
|
12
|
+
file_standard_information :standard_information, label: 'Standard Information'
|
|
13
|
+
file_internal_information :internal_information, label: 'Internal Information'
|
|
14
|
+
file_ea_information :ea_information, label: 'EA Information'
|
|
15
|
+
file_access_information :access_information, label: 'Access Information'
|
|
16
|
+
file_position_information :position_information, label: 'Position Information'
|
|
17
|
+
file_mode_information :mode_information, label: 'Mode Information'
|
|
18
|
+
file_alignment_information :alignment_information, label: 'Alignment Information'
|
|
19
|
+
file_name_information :name_information, label: 'Name Information'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module RubySMB
|
|
2
|
+
module Fscc
|
|
3
|
+
module FileInformation
|
|
4
|
+
# The FileBasicInformation Class as defined in
|
|
5
|
+
# [2.4.7 FileBasicInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/16023025-8a78-492f-8b96-c873b042ac50)
|
|
6
|
+
class FileBasicInformation < BinData::Record
|
|
7
|
+
CLASS_LEVEL = FileInformation::FILE_BASIC_INFORMATION
|
|
8
|
+
|
|
9
|
+
endian :little
|
|
10
|
+
|
|
11
|
+
file_time :create_time, label: 'Create Time'
|
|
12
|
+
file_time :last_access, label: 'Last Accessed Time'
|
|
13
|
+
file_time :last_write, label: 'Last Write Time'
|
|
14
|
+
file_time :last_change, label: 'Last Modified Time'
|
|
15
|
+
file_attributes :file_attributes, label: 'File Attributes'
|
|
16
|
+
string :reserved, label: 'Reserved', length: 4
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -2,7 +2,7 @@ module RubySMB
|
|
|
2
2
|
module Fscc
|
|
3
3
|
module FileInformation
|
|
4
4
|
# The FileBothDirectoryInformation Class as defined in
|
|
5
|
-
# [2.4.8 FileBothDirectoryInformation](https://
|
|
5
|
+
# [2.4.8 FileBothDirectoryInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/270df317-9ba5-4ccb-ba00-8d22be139bc5)
|
|
6
6
|
class FileBothDirectoryInformation < BinData::Record
|
|
7
7
|
CLASS_LEVEL = FileInformation::FILE_BOTH_DIRECTORY_INFORMATION
|
|
8
8
|
|
|
@@ -14,8 +14,8 @@ module RubySMB
|
|
|
14
14
|
file_time :last_access, label: 'Last Accessed Time'
|
|
15
15
|
file_time :last_write, label: 'Last Write Time'
|
|
16
16
|
file_time :last_change, label: 'Last Modified Time'
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
int64 :end_of_file, label: 'End of File'
|
|
18
|
+
int64 :allocation_size, label: 'Allocated Size'
|
|
19
19
|
file_attributes :file_attributes, label: 'File Attributes'
|
|
20
20
|
uint32 :file_name_length, label: 'File Name Length', initial_value: -> { file_name.do_num_bytes }
|
|
21
21
|
uint32 :ea_size, label: 'Extended Attributes Size'
|
|
@@ -2,7 +2,7 @@ module RubySMB
|
|
|
2
2
|
module Fscc
|
|
3
3
|
module FileInformation
|
|
4
4
|
# The FileDirectoryInformation Class as defined in
|
|
5
|
-
# [2.4.10 FileDirectoryInformation](https://
|
|
5
|
+
# [2.4.10 FileDirectoryInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/b38bf518-9057-4c88-9ddd-5e2d3976a64b)
|
|
6
6
|
class FileDirectoryInformation < BinData::Record
|
|
7
7
|
CLASS_LEVEL = FileInformation::FILE_DIRECTORY_INFORMATION
|
|
8
8
|
|
|
@@ -14,8 +14,8 @@ module RubySMB
|
|
|
14
14
|
file_time :last_access, label: 'Last Accessed Time'
|
|
15
15
|
file_time :last_write, label: 'Last Write Time'
|
|
16
16
|
file_time :last_change, label: 'Last Modified Time'
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
int64 :end_of_file, label: 'End of File'
|
|
18
|
+
int64 :allocation_size, label: 'Allocated Size'
|
|
19
19
|
file_attributes :file_attributes, label: 'File Attributes'
|
|
20
20
|
uint32 :file_name_length, label: 'File Name Length', initial_value: -> { file_name.do_num_bytes }
|
|
21
21
|
string16 :file_name, label: 'File Name', read_length: -> { file_name_length }
|
|
@@ -2,7 +2,7 @@ module RubySMB
|
|
|
2
2
|
module Fscc
|
|
3
3
|
module FileInformation
|
|
4
4
|
# The FileFullDirectoryInformation Class as defined in
|
|
5
|
-
# [2.4.14 FileFullDirectoryInformation](https://
|
|
5
|
+
# [2.4.14 FileFullDirectoryInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/e8d926d1-3a22-4654-be9c-58317a85540b)
|
|
6
6
|
class FileFullDirectoryInformation < BinData::Record
|
|
7
7
|
CLASS_LEVEL = FileInformation::FILE_FULL_DIRECTORY_INFORMATION
|
|
8
8
|
|
|
@@ -14,8 +14,8 @@ module RubySMB
|
|
|
14
14
|
file_time :last_access, label: 'Last Accessed Time'
|
|
15
15
|
file_time :last_write, label: 'Last Write Time'
|
|
16
16
|
file_time :last_change, label: 'Last Modified Time'
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
int64 :end_of_file, label: 'End of File'
|
|
18
|
+
int64 :allocation_size, label: 'Allocated Size'
|
|
19
19
|
file_attributes :file_attributes, label: 'File Attributes'
|
|
20
20
|
uint32 :file_name_length, label: 'File Name Length', initial_value: -> { file_name.do_num_bytes }
|
|
21
21
|
uint32 :ea_size, label: 'Extended Attributes Size'
|
|
@@ -14,8 +14,8 @@ module RubySMB
|
|
|
14
14
|
file_time :last_access, label: 'Last Accessed Time'
|
|
15
15
|
file_time :last_write, label: 'Last Write Time'
|
|
16
16
|
file_time :last_change, label: 'Last Modified Time'
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
int64 :end_of_file, label: 'End of File'
|
|
18
|
+
int64 :allocation_size, label: 'Allocated Size'
|
|
19
19
|
file_attributes :file_attributes, label: 'File Attributes'
|
|
20
20
|
uint32 :file_name_length, label: 'File Name Length', initial_value: -> { file_name.do_num_bytes }
|
|
21
21
|
uint32 :ea_size, label: 'Extended Attributes Size'
|
|
@@ -23,7 +23,7 @@ module RubySMB
|
|
|
23
23
|
uint8 :reserved, label: 'Reserved Space'
|
|
24
24
|
string16 :short_name, label: 'File Short Name', length: 24
|
|
25
25
|
uint16 :reserved2, label: 'Reserved Space'
|
|
26
|
-
uint64 :file_id, label: 'File
|
|
26
|
+
uint64 :file_id, label: 'File ID'
|
|
27
27
|
string16 :file_name, label: 'File Name', read_length: -> { file_name_length }
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -2,7 +2,7 @@ module RubySMB
|
|
|
2
2
|
module Fscc
|
|
3
3
|
module FileInformation
|
|
4
4
|
# The FileIdDirectoryInformation Class as defined in
|
|
5
|
-
# [2.4.18 FileIdFullDirectoryInformation](https://
|
|
5
|
+
# [2.4.18 FileIdFullDirectoryInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/ab8e7558-899c-4be1-a7c5-3a9ae8ab76a0)
|
|
6
6
|
class FileIdFullDirectoryInformation < BinData::Record
|
|
7
7
|
CLASS_LEVEL = FileInformation::FILE_ID_FULL_DIRECTORY_INFORMATION
|
|
8
8
|
|
|
@@ -14,8 +14,8 @@ module RubySMB
|
|
|
14
14
|
file_time :last_access, label: 'Last Accessed Time'
|
|
15
15
|
file_time :last_write, label: 'Last Write Time'
|
|
16
16
|
file_time :last_change, label: 'Last Modified Time'
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
int64 :end_of_file, label: 'End of File'
|
|
18
|
+
int64 :allocation_size, label: 'Allocated Size'
|
|
19
19
|
file_attributes :file_attributes, label: 'File Attributes'
|
|
20
20
|
uint32 :file_name_length, label: 'File Name Length', initial_value: -> { file_name.do_num_bytes }
|
|
21
21
|
uint32 :ea_size, label: 'Extended Attributes Size'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module RubySMB
|
|
2
|
+
module Fscc
|
|
3
|
+
module FileInformation
|
|
4
|
+
# The FileInternalInformation Class as defined in
|
|
5
|
+
# [2.4.22 FileInternalInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/7d796611-2fa5-41ac-8178-b6fea3a017b3)
|
|
6
|
+
class FileInternalInformation < BinData::Record
|
|
7
|
+
CLASS_LEVEL = FileInformation::FILE_INTERNAL_INFORMATION
|
|
8
|
+
|
|
9
|
+
endian :little
|
|
10
|
+
|
|
11
|
+
uint64 :file_id, label: 'File ID'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module RubySMB
|
|
2
|
+
module Fscc
|
|
3
|
+
module FileInformation
|
|
4
|
+
# The FileModeInformation Class as defined in
|
|
5
|
+
# [2.4.26 FileModeInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/52df7798-8330-474b-ac31-9afe8075640c)
|
|
6
|
+
class FileModeInformation < BinData::Record
|
|
7
|
+
CLASS_LEVEL = FileInformation::FILE_MODE_INFORMATION
|
|
8
|
+
|
|
9
|
+
endian :little
|
|
10
|
+
|
|
11
|
+
struct :flags do
|
|
12
|
+
bit2 :reserved
|
|
13
|
+
bit1 :file_synchronous_io_nonalert, label: 'File Synchronous IO Nonalert'
|
|
14
|
+
bit1 :file_synchronous_io_alert, label: 'File Synchronous IO Alert'
|
|
15
|
+
bit1 :file_no_intermediate_buffering, label: 'File No Intermediate Buffering'
|
|
16
|
+
bit1 :file_sequential_only, label: 'File Sequential Only'
|
|
17
|
+
bit1 :file_write_through, label: 'File Write Through'
|
|
18
|
+
bit1 :reserved2
|
|
19
|
+
# byte boundary
|
|
20
|
+
bit3 :reserved3
|
|
21
|
+
bit1 :file_delete_on_close, label: 'File Delete On Close'
|
|
22
|
+
bit4 :reserved4
|
|
23
|
+
# byte boundary
|
|
24
|
+
bit16 :reserved5
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module RubySMB
|
|
2
|
+
module Fscc
|
|
3
|
+
module FileInformation
|
|
4
|
+
# The FileNameInformation Class as defined in
|
|
5
|
+
# [2.4.27 FileNameInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/cb30e415-54c5-4483-a346-822ea90e1e89)
|
|
6
|
+
class FileNameInformation < BinData::Record
|
|
7
|
+
CLASS_LEVEL = FileInformation::FILE_NAME_INFORMATION
|
|
8
|
+
|
|
9
|
+
endian :little
|
|
10
|
+
|
|
11
|
+
uint32 :file_name_length, label: 'File Name Length', initial_value: -> { file_name.do_num_bytes }
|
|
12
|
+
string16 :file_name, label: 'File Name', read_length: -> { file_name_length }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -2,7 +2,7 @@ module RubySMB
|
|
|
2
2
|
module Fscc
|
|
3
3
|
module FileInformation
|
|
4
4
|
# The FileNamesInformation Class as defined in
|
|
5
|
-
# [2.4.
|
|
5
|
+
# [2.4.28 FileNamesInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/a289f7a8-83d2-4927-8c88-b2d328dde5a5)
|
|
6
6
|
class FileNamesInformation < BinData::Record
|
|
7
7
|
CLASS_LEVEL = FileInformation::FILE_NAMES_INFORMATION
|
|
8
8
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module RubySMB
|
|
2
|
+
module Fscc
|
|
3
|
+
module FileInformation
|
|
4
|
+
# The FileNormalizedNameInformation Class as defined in
|
|
5
|
+
# [2.4.30 FileNormalizedNameInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/20bcadba-808c-4880-b757-4af93e41edf6)
|
|
6
|
+
class FileNormalizedNameInformation < BinData::Record
|
|
7
|
+
CLASS_LEVEL = FileInformation::FILE_NORMALIZED_NAME_INFORMATION
|
|
8
|
+
|
|
9
|
+
endian :little
|
|
10
|
+
|
|
11
|
+
uint32 :file_name_length, label: 'File Name Length', initial_value: -> { file_name.do_num_bytes }
|
|
12
|
+
string16 :file_name, label: 'File Name', read_length: -> { file_name_length }
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module RubySMB
|
|
2
|
+
module Fscc
|
|
3
|
+
module FileInformation
|
|
4
|
+
# The FilePositionInformation Class as defined in
|
|
5
|
+
# [2.4.35 FilePositionInformation](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/e3ce4a39-327e-495c-99b6-6b61606b6f16)
|
|
6
|
+
class FilePositionInformation < BinData::Record
|
|
7
|
+
CLASS_LEVEL = FileInformation::FILE_POSITION_INFORMATION
|
|
8
|
+
|
|
9
|
+
endian :little
|
|
10
|
+
|
|
11
|
+
int64 :current_byte_offset, label: 'Current Byte Offset'
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -4,7 +4,7 @@ module RubySMB
|
|
|
4
4
|
# The FileRenameInformation Class as defined in
|
|
5
5
|
# [2.4.34.2 FileRenameInformation](https://msdn.microsoft.com/en-us/library/cc704597.aspx)
|
|
6
6
|
class FileRenameInformation < BinData::Record
|
|
7
|
-
CLASS_LEVEL = FileInformation::
|
|
7
|
+
CLASS_LEVEL = FileInformation::FILE_RENAME_INFORMATION
|
|
8
8
|
|
|
9
9
|
endian :little
|
|
10
10
|
|