ruby_smb 3.1.0 → 3.1.3

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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/examples/file_server.rb +6 -61
  4. data/examples/virtual_file_server.rb +91 -0
  5. data/lib/ruby_smb/client/negotiation.rb +7 -7
  6. data/lib/ruby_smb/client.rb +2 -2
  7. data/lib/ruby_smb/fscc/file_information/file_access_information.rb +15 -0
  8. data/lib/ruby_smb/fscc/file_information/file_alignment_information.rb +45 -0
  9. data/lib/ruby_smb/fscc/file_information/file_all_information.rb +23 -0
  10. data/lib/ruby_smb/fscc/file_information/file_basic_information.rb +20 -0
  11. data/lib/ruby_smb/fscc/file_information/file_both_directory_information.rb +3 -3
  12. data/lib/ruby_smb/fscc/file_information/file_directory_information.rb +3 -3
  13. data/lib/ruby_smb/fscc/file_information/file_ea_information.rb +1 -0
  14. data/lib/ruby_smb/fscc/file_information/file_full_directory_information.rb +3 -3
  15. data/lib/ruby_smb/fscc/file_information/file_id_both_directory_information.rb +3 -3
  16. data/lib/ruby_smb/fscc/file_information/file_id_full_directory_information.rb +3 -3
  17. data/lib/ruby_smb/fscc/file_information/file_internal_information.rb +15 -0
  18. data/lib/ruby_smb/fscc/file_information/file_mode_information.rb +29 -0
  19. data/lib/ruby_smb/fscc/file_information/file_name_information.rb +16 -0
  20. data/lib/ruby_smb/fscc/file_information/file_names_information.rb +1 -1
  21. data/lib/ruby_smb/fscc/file_information/file_normalized_name_information.rb +16 -0
  22. data/lib/ruby_smb/fscc/file_information/file_position_information.rb +15 -0
  23. data/lib/ruby_smb/fscc/file_information/file_rename_information.rb +1 -1
  24. data/lib/ruby_smb/fscc/file_information/file_standard_information.rb +20 -0
  25. data/lib/ruby_smb/fscc/file_information/file_stream_information.rb +3 -0
  26. data/lib/ruby_smb/fscc/file_information.rb +41 -8
  27. data/lib/ruby_smb/fscc/file_system_information/file_fs_attribute_information.rb +1 -0
  28. data/lib/ruby_smb/fscc/file_system_information/file_fs_volume_information.rb +1 -0
  29. data/lib/ruby_smb/fscc/file_system_information.rb +4 -0
  30. data/lib/ruby_smb/gss/provider/ntlm.rb +20 -3
  31. data/lib/ruby_smb/gss/provider.rb +10 -1
  32. data/lib/ruby_smb/ntlm/client.rb +74 -0
  33. data/lib/ruby_smb/ntlm.rb +1 -0
  34. data/lib/ruby_smb/server/cli.rb +121 -0
  35. data/lib/ruby_smb/server/server_client/session_setup.rb +4 -2
  36. data/lib/ruby_smb/server/server_client.rb +9 -1
  37. data/lib/ruby_smb/server/session.rb +5 -1
  38. data/lib/ruby_smb/server/share/provider/disk/processor/close.rb +9 -5
  39. data/lib/ruby_smb/server/share/provider/disk/processor/create.rb +2 -2
  40. data/lib/ruby_smb/server/share/provider/disk/processor/query.rb +2 -2
  41. data/lib/ruby_smb/server/share/provider/disk/processor/read.rb +15 -14
  42. data/lib/ruby_smb/server/share/provider/disk/processor.rb +76 -12
  43. data/lib/ruby_smb/server/share/provider/disk.rb +8 -2
  44. data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb +85 -0
  45. data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname.rb +196 -0
  46. data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_stat.rb +175 -0
  47. data/lib/ruby_smb/server/share/provider/virtual_disk.rb +116 -0
  48. data/lib/ruby_smb/server/share/provider.rb +1 -0
  49. data/lib/ruby_smb/server.rb +14 -3
  50. data/lib/ruby_smb/smb2/tree.rb +1 -0
  51. data/lib/ruby_smb/version.rb +1 -1
  52. data/spec/lib/ruby_smb/client_spec.rb +11 -2
  53. data/spec/lib/ruby_smb/fscc/file_information/file_access_information_spec.rb +21 -0
  54. data/spec/lib/ruby_smb/fscc/file_information/file_alignment_information_spec.rb +21 -0
  55. data/spec/lib/ruby_smb/fscc/file_information/file_all_information_spec.rb +61 -0
  56. data/spec/lib/ruby_smb/fscc/file_information/file_basic_information_spec.rb +41 -0
  57. data/spec/lib/ruby_smb/fscc/file_information/file_both_directory_information_spec.rb +59 -10
  58. data/spec/lib/ruby_smb/fscc/file_information/file_directory_information_spec.rb +30 -12
  59. data/spec/lib/ruby_smb/fscc/file_information/file_ea_information_spec.rb +21 -0
  60. data/spec/lib/ruby_smb/fscc/file_information/file_full_directory_information_spec.rb +30 -12
  61. data/spec/lib/ruby_smb/fscc/file_information/file_id_both_directory_information_spec.rb +63 -10
  62. data/spec/lib/ruby_smb/fscc/file_information/file_id_full_directory_information_spec.rb +30 -12
  63. data/spec/lib/ruby_smb/fscc/file_information/file_internal_information_spec.rb +21 -0
  64. data/spec/lib/ruby_smb/fscc/file_information/file_mode_information_spec.rb +21 -0
  65. data/spec/lib/ruby_smb/fscc/file_information/file_name_information_spec.rb +44 -0
  66. data/spec/lib/ruby_smb/fscc/file_information/file_names_information_spec.rb +30 -12
  67. data/spec/lib/ruby_smb/fscc/file_information/file_network_open_information_spec.rb +51 -0
  68. data/spec/lib/ruby_smb/fscc/file_information/file_normalized_name_information_spec.rb +44 -0
  69. data/spec/lib/ruby_smb/fscc/file_information/file_position_information_spec.rb +21 -0
  70. data/spec/lib/ruby_smb/fscc/file_information/file_rename_information_spec.rb +1 -1
  71. data/spec/lib/ruby_smb/fscc/file_information/file_standard_information_spec.rb +41 -0
  72. data/spec/lib/ruby_smb/fscc/file_information/file_stream_information_spec.rb +51 -0
  73. data/spec/lib/ruby_smb/fscc/file_information_spec.rb +14 -0
  74. data/spec/lib/ruby_smb/fscc/file_system_information/file_fs_attribute_information_spec.rb +46 -0
  75. data/spec/lib/ruby_smb/fscc/file_system_information/file_fs_volume_information_spec.rb +51 -0
  76. data/spec/lib/ruby_smb/fscc/file_system_information_spec.rb +14 -0
  77. data/spec/lib/ruby_smb/ntlm/client/session_spec.rb +114 -0
  78. data/spec/lib/ruby_smb/ntlm/client_spec.rb +36 -0
  79. data/spec/lib/ruby_smb/server/server_client_spec.rb +15 -0
  80. data/spec/lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname_spec.rb +581 -0
  81. data/spec/lib/ruby_smb/server/share/provider/virtual_disk/virtual_stat_spec.rb +207 -0
  82. data/spec/lib/ruby_smb/server/share/provider/virtual_disk_spec.rb +122 -0
  83. data.tar.gz.sig +2 -2
  84. metadata +63 -2
  85. metadata.gz.sig +0 -0
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::NTLM::Client::Session do
4
+ let(:message) { Net::NTLM::Message.decode64(%Q{
5
+ TlRMTVNTUAACAAAADAAMADgAAAA1goni+fNfw+cInOgAAAAAAAAAAJoAmgBE
6
+ AAAACgBjRQAAAA9NAFMARgBMAEEAQgACAAwATQBTAEYATABBAEIAAQAeAFcA
7
+ SQBOAC0AMwBNAFMAUAA4AEsAMgBMAEMARwBDAAQAGABtAHMAZgBsAGEAYgAu
8
+ AGwAbwBjAGEAbAADADgAVwBJAE4ALQAzAE0AUwBQADgASwAyAEwAQwBHAEMA
9
+ LgBtAHMAZgBsAGEAYgAuAGwAbwBjAGEAbAAHAAgAS6UAWjxl2AEAAAAA
10
+ }) }
11
+ subject(:client) { RubySMB::NTLM::Client.new('rubysmb', 'rubysmb', flags: RubySMB::NTLM::DEFAULT_CLIENT_FLAGS) }
12
+ subject(:session) { described_class.new(client, message) }
13
+
14
+ describe '#authenticate!' do
15
+ it 'calculates the user session key' do
16
+ expect(session).to receive(:calculate_user_session_key!).and_call_original
17
+ session.authenticate!
18
+ end
19
+
20
+ it 'checks if it is anonymous' do
21
+ expect(session).to receive(:is_anonymous?).at_least(1).times.and_call_original
22
+ session.authenticate!
23
+ end
24
+
25
+ it 'returns a Type3 message' do
26
+ expect(session.authenticate!).to be_a Net::NTLM::Message::Type3
27
+ expect(session.authenticate!).to be_a RubySMB::NTLM::Message
28
+ end
29
+
30
+ context 'when it is anonymous' do
31
+ before(:each) { allow(session).to receive(:is_anonymous?).and_return(true) }
32
+ after(:each) { session.authenticate! }
33
+
34
+ it 'uses the correct lm response' do
35
+ expect(session).to_not receive(:lmv2_resp)
36
+ expect(Net::NTLM::Message::Type3).to receive(:create).and_wrap_original do |method, params|
37
+ expect(params).to include :lm_response
38
+ expect(params[:lm_response]).to eq "\x00".b
39
+ method.call(params)
40
+ end
41
+ end
42
+
43
+ it 'uses the correct ntlm response' do
44
+ expect(session).to_not receive(:ntlmv2_resp)
45
+ expect(Net::NTLM::Message::Type3).to receive(:create).and_wrap_original do |method, params|
46
+ expect(params).to include :ntlm_response
47
+ expect(params[:ntlm_response]).to eq ''
48
+ method.call(params)
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'when it is not anonymous' do
54
+ before(:each) { allow(session).to receive(:is_anonymous?).and_return(false) }
55
+ after(:each) { session.authenticate! }
56
+
57
+ it 'uses the correct lm response' do
58
+ expect(session).to receive(:lmv2_resp).and_call_original
59
+ expect(Net::NTLM::Message::Type3).to receive(:create).and_wrap_original do |method, params|
60
+ expect(params).to include :lm_response
61
+ expect(params[:lm_response].length).to be > 16
62
+ method.call(params)
63
+ end
64
+ end
65
+
66
+ it 'uses the correct ntlm response' do
67
+ expect(session).to receive(:ntlmv2_resp).and_call_original
68
+ expect(Net::NTLM::Message::Type3).to receive(:create).and_wrap_original do |method, params|
69
+ expect(params).to include :ntlm_response
70
+ expect(params[:ntlm_response].length).to be > 16
71
+ method.call(params)
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ describe '#calculate_user_session_key!' do
78
+ it 'returns an all zero key when it is anonymous' do
79
+ expect(session).to receive(:is_anonymous?).and_return(true)
80
+ expect(session.send(:calculate_user_session_key!)).to eq "\x00".b * 16
81
+ end
82
+
83
+ it 'returns a session key' do
84
+ expect(session).to receive(:is_anonymous?).and_return(false)
85
+ expect(session.send(:calculate_user_session_key!)).to_not eq "\x00".b * 16
86
+ end
87
+ end
88
+
89
+ describe '#is_anonymous?' do
90
+ it 'returns false when the username is not blank' do
91
+ allow(session).to receive(:username).and_return('username')
92
+ allow(session).to receive(:password).and_return('')
93
+ expect(session.is_anonymous?).to be false
94
+ end
95
+
96
+ it 'returns false when the password is not blank' do
97
+ allow(session).to receive(:username).and_return('')
98
+ allow(session).to receive(:password).and_return('password')
99
+ expect(session.is_anonymous?).to be false
100
+ end
101
+
102
+ it 'returns false when the username is not blank and the password is not blank' do
103
+ allow(session).to receive(:username).and_return('username')
104
+ allow(session).to receive(:password).and_return('password')
105
+ expect(session.is_anonymous?).to be false
106
+ end
107
+
108
+ it 'returns true when the username is blank and the password is blank' do
109
+ allow(session).to receive(:username).and_return('')
110
+ allow(session).to receive(:password).and_return('')
111
+ expect(session.is_anonymous?).to be true
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::NTLM::Client do
4
+ subject(:client) { described_class.new('rubysmb', 'rubysmb', flags: RubySMB::NTLM::DEFAULT_CLIENT_FLAGS) }
5
+
6
+ describe '#init_context' do
7
+ context 'when a response is provided' do
8
+ let(:resp) { %Q{
9
+ TlRMTVNTUAACAAAADAAMADgAAAA1goni+fNfw+cInOgAAAAAAAAAAJoAmgBE
10
+ AAAACgBjRQAAAA9NAFMARgBMAEEAQgACAAwATQBTAEYATABBAEIAAQAeAFcA
11
+ SQBOAC0AMwBNAFMAUAA4AEsAMgBMAEMARwBDAAQAGABtAHMAZgBsAGEAYgAu
12
+ AGwAbwBjAGEAbAADADgAVwBJAE4ALQAzAE0AUwBQADgASwAyAEwAQwBHAEMA
13
+ LgBtAHMAZgBsAGEAYgAuAGwAbwBjAGEAbAAHAAgAS6UAWjxl2AEAAAAA
14
+ } }
15
+ it 'returns a Type3 message' do
16
+ expect(client.init_context(resp)).to be_a Net::NTLM::Message::Type3
17
+ end
18
+
19
+ it 'creates a new session object' do
20
+ expect(RubySMB::NTLM::Client::Session).to receive(:new).and_call_original
21
+ client.init_context(resp)
22
+ end
23
+ end
24
+
25
+ context 'when a response is not provided' do
26
+ it 'returns a Type1 message' do
27
+ expect(client.init_context).to be_a Net::NTLM::Message::Type1
28
+ end
29
+
30
+ it 'does not create a new session object' do
31
+ expect(RubySMB::NTLM::Client::Session).to_not receive(:new)
32
+ client.init_context
33
+ end
34
+ end
35
+ end
36
+ end
@@ -5,6 +5,7 @@ RSpec.describe RubySMB::Server::ServerClient do
5
5
  subject(:server_client) { described_class.new(server, dispatcher) }
6
6
 
7
7
  it { is_expected.to respond_to :dialect }
8
+ it { is_expected.to respond_to :dispatcher }
8
9
  it { is_expected.to respond_to :session_table }
9
10
 
10
11
  describe '#disconnect!' do
@@ -31,6 +32,20 @@ RSpec.describe RubySMB::Server::ServerClient do
31
32
  end
32
33
  end
33
34
 
35
+ describe '#peerhost' do
36
+ it 'returns the peer IP address' do
37
+ expect(server_client).to receive(:getpeername).and_return(Socket.sockaddr_in(4444, '127.0.0.1'))
38
+ expect(server_client.peerhost).to eq '127.0.0.1'
39
+ end
40
+ end
41
+
42
+ describe '#peerport' do
43
+ it 'returns the peer IP port' do
44
+ expect(server_client).to receive(:getpeername).and_return(Socket.sockaddr_in(4444, '127.0.0.1'))
45
+ expect(server_client.peerport).to eq 4444
46
+ end
47
+ end
48
+
34
49
  describe '#process_gss' do
35
50
  before(:each) do
36
51
  expect(server_client.instance_eval { @gss_authenticator }).to receive(:process).and_call_original