ruby_smb 2.0.10 → 2.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/examples/auth_capture.rb +71 -0
  4. data/lib/ruby_smb/client/negotiation.rb +1 -1
  5. data/lib/ruby_smb/client.rb +9 -8
  6. data/lib/ruby_smb/dialect.rb +45 -0
  7. data/lib/ruby_smb/dispatcher/base.rb +1 -1
  8. data/lib/ruby_smb/gss/provider/authenticator.rb +42 -0
  9. data/lib/ruby_smb/gss/provider/ntlm.rb +303 -0
  10. data/lib/ruby_smb/gss/provider.rb +35 -0
  11. data/lib/ruby_smb/gss.rb +56 -63
  12. data/lib/ruby_smb/ntlm.rb +45 -0
  13. data/lib/ruby_smb/server/server_client/negotiation.rb +155 -0
  14. data/lib/ruby_smb/server/server_client/session_setup.rb +82 -0
  15. data/lib/ruby_smb/server/server_client.rb +163 -0
  16. data/lib/ruby_smb/server.rb +54 -0
  17. data/lib/ruby_smb/signing.rb +59 -0
  18. data/lib/ruby_smb/smb1/packet/negotiate_response.rb +11 -11
  19. data/lib/ruby_smb/smb1/packet/negotiate_response_extended.rb +1 -1
  20. data/lib/ruby_smb/smb1/packet/session_setup_request.rb +1 -1
  21. data/lib/ruby_smb/smb2/negotiate_context.rb +18 -2
  22. data/lib/ruby_smb/smb2/packet/negotiate_request.rb +9 -0
  23. data/lib/ruby_smb/smb2/packet/negotiate_response.rb +0 -1
  24. data/lib/ruby_smb/smb2/packet/session_setup_response.rb +2 -2
  25. data/lib/ruby_smb/smb2/packet/tree_connect_request.rb +1 -1
  26. data/lib/ruby_smb/smb2.rb +3 -1
  27. data/lib/ruby_smb/version.rb +1 -1
  28. data/lib/ruby_smb.rb +2 -1
  29. data/spec/lib/ruby_smb/client_spec.rb +7 -9
  30. data/spec/lib/ruby_smb/gss/provider/ntlm/account_spec.rb +32 -0
  31. data/spec/lib/ruby_smb/gss/provider/ntlm/authenticator_spec.rb +101 -0
  32. data/spec/lib/ruby_smb/gss/provider/ntlm/os_version_spec.rb +32 -0
  33. data/spec/lib/ruby_smb/gss/provider/ntlm_spec.rb +113 -0
  34. data/spec/lib/ruby_smb/server/server_client_spec.rb +156 -0
  35. data/spec/lib/ruby_smb/server_spec.rb +32 -0
  36. data/spec/lib/ruby_smb/smb2/negotiate_context_spec.rb +2 -2
  37. data.tar.gz.sig +0 -0
  38. metadata +25 -3
  39. metadata.gz.sig +0 -0
  40. data/lib/ruby_smb/client/signing.rb +0 -64
@@ -0,0 +1,32 @@
1
+ RSpec.describe RubySMB::Server do
2
+ before(:each) do
3
+ allow(::TCPServer).to receive(:new).and_return(::TCPServer.new(0))
4
+ end
5
+
6
+ it { is_expected.to respond_to :dialects }
7
+ it { is_expected.to respond_to :gss_provider }
8
+ it { is_expected.to respond_to :guid }
9
+
10
+ describe '#initialize' do
11
+ it 'should bind to TCP port 445 by default' do
12
+ expect(::TCPServer).to receive(:new).with(445).and_return(::TCPServer.new(0))
13
+ described_class.new
14
+ end
15
+
16
+ it 'should create a new NTLM GSS provider by default' do
17
+ expect(RubySMB::Gss::Provider::NTLM).to receive(:new).and_call_original
18
+ described_class.new
19
+ end
20
+
21
+ it 'should generate a random 16-byte GUID' do
22
+ server_guid = described_class.new.guid
23
+ expect(server_guid).to be_a String
24
+ expect(server_guid.length).to eq 16
25
+ expect(server_guid).to_not eq described_class.new.guid
26
+ end
27
+
28
+ it 'should support some dialects' do
29
+ expect(described_class.new.dialects).to_not be_empty
30
+ end
31
+ end
32
+ end
@@ -162,7 +162,7 @@ RSpec.describe RubySMB::SMB2::CompressionCapabilities do
162
162
  end
163
163
  end
164
164
 
165
- RSpec.describe RubySMB::SMB2::NetnameNegotiateContextId do
165
+ RSpec.describe RubySMB::SMB2::NetnameNegotiateContextId do
166
166
  subject(:capability) { described_class.new }
167
167
 
168
168
  it { is_expected.to respond_to :net_name }
@@ -173,7 +173,7 @@ RSpec.describe RubySMB::SMB2::NetnameNegotiateContextId do
173
173
 
174
174
  describe '#net_name' do
175
175
  it 'is a unicode string' do
176
- expect(capability.net_name).to be_a RubySMB::Field::Stringz16
176
+ expect(capability.net_name).to be_a RubySMB::Field::String16
177
177
  end
178
178
  end
179
179
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_smb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10
4
+ version: 2.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Metasploit Hackers
@@ -97,7 +97,7 @@ cert_chain:
97
97
  EknWpNgVhohbot1lfVAMmIhdtOVaRVcQQixWPwprDj/ydB8ryDMDosIMcw+fkoXU
98
98
  9GJsSaSRRYQ9UUkVL27b64okU8D48m8=
99
99
  -----END CERTIFICATE-----
100
- date: 2021-05-28 00:00:00.000000000 Z
100
+ date: 2021-08-25 00:00:00.000000000 Z
101
101
  dependencies:
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: redcarpet
@@ -258,6 +258,7 @@ files:
258
258
  - Rakefile
259
259
  - examples/anonymous_auth.rb
260
260
  - examples/append_file.rb
261
+ - examples/auth_capture.rb
261
262
  - examples/authenticate.rb
262
263
  - examples/delete_file.rb
263
264
  - examples/enum_registry_key.rb
@@ -280,7 +281,6 @@ files:
280
281
  - lib/ruby_smb/client/echo.rb
281
282
  - lib/ruby_smb/client/encryption.rb
282
283
  - lib/ruby_smb/client/negotiation.rb
283
- - lib/ruby_smb/client/signing.rb
284
284
  - lib/ruby_smb/client/tree_connect.rb
285
285
  - lib/ruby_smb/client/utils.rb
286
286
  - lib/ruby_smb/client/winreg.rb
@@ -347,6 +347,7 @@ files:
347
347
  - lib/ruby_smb/dcerpc/winreg/regsam.rb
348
348
  - lib/ruby_smb/dcerpc/winreg/save_key_request.rb
349
349
  - lib/ruby_smb/dcerpc/winreg/save_key_response.rb
350
+ - lib/ruby_smb/dialect.rb
350
351
  - lib/ruby_smb/dispatcher.rb
351
352
  - lib/ruby_smb/dispatcher/base.rb
352
353
  - lib/ruby_smb/dispatcher/socket.rb
@@ -381,12 +382,21 @@ files:
381
382
  - lib/ruby_smb/fscc/file_information/file_rename_information.rb
382
383
  - lib/ruby_smb/generic_packet.rb
383
384
  - lib/ruby_smb/gss.rb
385
+ - lib/ruby_smb/gss/provider.rb
386
+ - lib/ruby_smb/gss/provider/authenticator.rb
387
+ - lib/ruby_smb/gss/provider/ntlm.rb
384
388
  - lib/ruby_smb/impersonation_levels.rb
385
389
  - lib/ruby_smb/nbss.rb
386
390
  - lib/ruby_smb/nbss/negative_session_response.rb
387
391
  - lib/ruby_smb/nbss/netbios_name.rb
388
392
  - lib/ruby_smb/nbss/session_header.rb
389
393
  - lib/ruby_smb/nbss/session_request.rb
394
+ - lib/ruby_smb/ntlm.rb
395
+ - lib/ruby_smb/server.rb
396
+ - lib/ruby_smb/server/server_client.rb
397
+ - lib/ruby_smb/server/server_client/negotiation.rb
398
+ - lib/ruby_smb/server/server_client/session_setup.rb
399
+ - lib/ruby_smb/signing.rb
390
400
  - lib/ruby_smb/smb1.rb
391
401
  - lib/ruby_smb/smb1/andx_block.rb
392
402
  - lib/ruby_smb/smb1/bit_field.rb
@@ -613,10 +623,16 @@ files:
613
623
  - spec/lib/ruby_smb/fscc/file_information/file_rename_information_spec.rb
614
624
  - spec/lib/ruby_smb/fscc/fscc_file_attributes_spec.rb
615
625
  - spec/lib/ruby_smb/generic_packet_spec.rb
626
+ - spec/lib/ruby_smb/gss/provider/ntlm/account_spec.rb
627
+ - spec/lib/ruby_smb/gss/provider/ntlm/authenticator_spec.rb
628
+ - spec/lib/ruby_smb/gss/provider/ntlm/os_version_spec.rb
629
+ - spec/lib/ruby_smb/gss/provider/ntlm_spec.rb
616
630
  - spec/lib/ruby_smb/nbss/negative_session_response_spec.rb
617
631
  - spec/lib/ruby_smb/nbss/netbios_name_spec.rb
618
632
  - spec/lib/ruby_smb/nbss/session_header_spec.rb
619
633
  - spec/lib/ruby_smb/nbss/session_request_spec.rb
634
+ - spec/lib/ruby_smb/server/server_client_spec.rb
635
+ - spec/lib/ruby_smb/server_spec.rb
620
636
  - spec/lib/ruby_smb/smb1/andx_block_spec.rb
621
637
  - spec/lib/ruby_smb/smb1/bit_field/capabilities_spec.rb
622
638
  - spec/lib/ruby_smb/smb1/bit_field/create_options_spec.rb
@@ -848,10 +864,16 @@ test_files:
848
864
  - spec/lib/ruby_smb/fscc/file_information/file_rename_information_spec.rb
849
865
  - spec/lib/ruby_smb/fscc/fscc_file_attributes_spec.rb
850
866
  - spec/lib/ruby_smb/generic_packet_spec.rb
867
+ - spec/lib/ruby_smb/gss/provider/ntlm/account_spec.rb
868
+ - spec/lib/ruby_smb/gss/provider/ntlm/authenticator_spec.rb
869
+ - spec/lib/ruby_smb/gss/provider/ntlm/os_version_spec.rb
870
+ - spec/lib/ruby_smb/gss/provider/ntlm_spec.rb
851
871
  - spec/lib/ruby_smb/nbss/negative_session_response_spec.rb
852
872
  - spec/lib/ruby_smb/nbss/netbios_name_spec.rb
853
873
  - spec/lib/ruby_smb/nbss/session_header_spec.rb
854
874
  - spec/lib/ruby_smb/nbss/session_request_spec.rb
875
+ - spec/lib/ruby_smb/server/server_client_spec.rb
876
+ - spec/lib/ruby_smb/server_spec.rb
855
877
  - spec/lib/ruby_smb/smb1/andx_block_spec.rb
856
878
  - spec/lib/ruby_smb/smb1/bit_field/capabilities_spec.rb
857
879
  - spec/lib/ruby_smb/smb1/bit_field/create_options_spec.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,64 +0,0 @@
1
- module RubySMB
2
- class Client
3
- # Contains the methods for handling packet signing
4
- module Signing
5
- # The NTLM Session Key used for signing
6
- # @!attribute [rw] session_key
7
- # @return [String]
8
- attr_accessor :session_key
9
-
10
- # Take an SMB1 packet and checks to see if it should be signed.
11
- # If signing is enabled and we have a session key already, then
12
- # it will sign the packet appropriately.
13
- #
14
- # @param packet [RubySMB::GenericPacket] the packet to sign
15
- # @return [RubySMB::GenericPacket] the packet, signed if needed
16
- def smb1_sign(packet)
17
- if signing_required && !session_key.empty?
18
- # Pack the Sequence counter into a int64le
19
- packed_sequence_counter = [sequence_counter].pack('Q<')
20
- packet.smb_header.security_features = packed_sequence_counter
21
- signature = OpenSSL::Digest::MD5.digest(session_key + packet.to_binary_s)[0, 8]
22
- packet.smb_header.security_features = signature
23
- self.sequence_counter += 1
24
- end
25
- packet
26
- end
27
-
28
- # Take an SMB2 packet and checks to see if it should be signed.
29
- # If signing is enabled and we have a session key already, then
30
- # it will sign the packet appropriately.
31
- #
32
- # @param packet [RubySMB::GenericPacket] the packet to sign
33
- # @return [RubySMB::GenericPacket] the packet, signed if needed
34
- def smb2_sign(packet)
35
- if signing_required && !session_key.empty?
36
- packet.smb2_header.flags.signed = 1
37
- packet.smb2_header.signature = "\x00" * 16
38
- hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, session_key, packet.to_binary_s)
39
- packet.smb2_header.signature = hmac[0, 16]
40
- end
41
- packet
42
- end
43
-
44
- def smb3_sign(packet)
45
- if !session_key.empty? && (signing_required || packet.is_a?(RubySMB::SMB2::Packet::TreeConnectRequest))
46
- case @dialect
47
- when '0x0300', '0x0302'
48
- signing_key = RubySMB::Crypto::KDF.counter_mode(@session_key, "SMB2AESCMAC\x00", "SmbSign\x00")
49
- when '0x0311'
50
- signing_key = RubySMB::Crypto::KDF.counter_mode(@session_key, "SMBSigningKey\x00", @preauth_integrity_hash_value)
51
- else
52
- raise RubySMB::Error::SigningError.new('Dialect is incompatible with SMBv3 signing')
53
- end
54
-
55
- packet.smb2_header.flags.signed = 1
56
- packet.smb2_header.signature = "\x00" * 16
57
- hmac = OpenSSL::CMAC.digest('AES', signing_key, packet.to_binary_s)
58
- packet.smb2_header.signature = hmac[0, 16]
59
- end
60
- packet
61
- end
62
- end
63
- end
64
- end