ruby_smb 1.0.5 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.travis.yml +3 -2
- data/Gemfile +6 -2
- data/README.md +35 -47
- data/examples/anonymous_auth.rb +3 -3
- data/examples/append_file.rb +10 -8
- data/examples/authenticate.rb +9 -5
- data/examples/delete_file.rb +8 -6
- data/examples/enum_registry_key.rb +29 -0
- data/examples/enum_registry_values.rb +31 -0
- data/examples/list_directory.rb +8 -6
- data/examples/negotiate.rb +51 -8
- data/examples/negotiate_with_netbios_service.rb +9 -5
- data/examples/net_share_enum_all.rb +6 -4
- data/examples/pipes.rb +13 -13
- data/examples/query_service_status.rb +64 -0
- data/examples/read_file.rb +8 -6
- data/examples/read_file_encryption.rb +56 -0
- data/examples/read_registry_key_value.rb +33 -0
- data/examples/rename_file.rb +9 -7
- data/examples/tree_connect.rb +7 -5
- data/examples/write_file.rb +9 -7
- data/lib/ruby_smb.rb +4 -1
- data/lib/ruby_smb/client.rb +239 -21
- data/lib/ruby_smb/client/authentication.rb +27 -8
- data/lib/ruby_smb/client/encryption.rb +62 -0
- data/lib/ruby_smb/client/negotiation.rb +154 -12
- data/lib/ruby_smb/client/signing.rb +19 -0
- data/lib/ruby_smb/client/tree_connect.rb +4 -4
- data/lib/ruby_smb/client/utils.rb +8 -7
- data/lib/ruby_smb/client/winreg.rb +46 -0
- data/lib/ruby_smb/crypto.rb +30 -0
- data/lib/ruby_smb/dcerpc.rb +40 -0
- data/lib/ruby_smb/dcerpc/bind.rb +2 -2
- data/lib/ruby_smb/dcerpc/bind_ack.rb +2 -2
- data/lib/ruby_smb/dcerpc/error.rb +6 -0
- data/lib/ruby_smb/dcerpc/ndr.rb +260 -16
- data/lib/ruby_smb/dcerpc/pdu_header.rb +1 -1
- data/lib/ruby_smb/dcerpc/request.rb +41 -9
- data/lib/ruby_smb/dcerpc/rpc_security_attributes.rb +34 -0
- data/lib/ruby_smb/dcerpc/rrp_unicode_string.rb +38 -0
- data/lib/ruby_smb/dcerpc/srvsvc.rb +10 -0
- data/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all.rb +9 -0
- data/lib/ruby_smb/dcerpc/svcctl.rb +479 -0
- data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request.rb +48 -0
- data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response.rb +26 -0
- data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_request.rb +25 -0
- data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response.rb +26 -0
- data/lib/ruby_smb/dcerpc/svcctl/control_service_request.rb +26 -0
- data/lib/ruby_smb/dcerpc/svcctl/control_service_response.rb +26 -0
- data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request.rb +35 -0
- data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response.rb +23 -0
- data/lib/ruby_smb/dcerpc/svcctl/open_service_w_request.rb +31 -0
- data/lib/ruby_smb/dcerpc/svcctl/open_service_w_response.rb +23 -0
- data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request.rb +25 -0
- data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response.rb +44 -0
- data/lib/ruby_smb/dcerpc/svcctl/query_service_status_request.rb +23 -0
- data/lib/ruby_smb/dcerpc/svcctl/query_service_status_response.rb +27 -0
- data/lib/ruby_smb/dcerpc/svcctl/service_status.rb +25 -0
- data/lib/ruby_smb/dcerpc/svcctl/start_service_w_request.rb +27 -0
- data/lib/ruby_smb/dcerpc/svcctl/start_service_w_response.rb +25 -0
- data/lib/ruby_smb/dcerpc/winreg.rb +421 -0
- data/lib/ruby_smb/dcerpc/winreg/close_key_request.rb +24 -0
- data/lib/ruby_smb/dcerpc/winreg/close_key_response.rb +27 -0
- data/lib/ruby_smb/dcerpc/winreg/create_key_request.rb +73 -0
- data/lib/ruby_smb/dcerpc/winreg/create_key_response.rb +36 -0
- data/lib/ruby_smb/dcerpc/winreg/enum_key_request.rb +45 -0
- data/lib/ruby_smb/dcerpc/winreg/enum_key_response.rb +42 -0
- data/lib/ruby_smb/dcerpc/winreg/enum_value_request.rb +39 -0
- data/lib/ruby_smb/dcerpc/winreg/enum_value_response.rb +36 -0
- data/lib/ruby_smb/dcerpc/winreg/open_key_request.rb +34 -0
- data/lib/ruby_smb/dcerpc/winreg/open_key_response.rb +25 -0
- data/lib/ruby_smb/dcerpc/winreg/open_root_key_request.rb +43 -0
- data/lib/ruby_smb/dcerpc/winreg/open_root_key_response.rb +35 -0
- data/lib/ruby_smb/dcerpc/winreg/query_info_key_request.rb +27 -0
- data/lib/ruby_smb/dcerpc/winreg/query_info_key_response.rb +40 -0
- data/lib/ruby_smb/dcerpc/winreg/query_value_request.rb +40 -0
- data/lib/ruby_smb/dcerpc/winreg/query_value_response.rb +57 -0
- data/lib/ruby_smb/dcerpc/winreg/regsam.rb +40 -0
- data/lib/ruby_smb/dcerpc/winreg/save_key_request.rb +37 -0
- data/lib/ruby_smb/dcerpc/winreg/save_key_response.rb +23 -0
- data/lib/ruby_smb/dispatcher/base.rb +1 -1
- data/lib/ruby_smb/dispatcher/socket.rb +5 -4
- data/lib/ruby_smb/error.rb +28 -1
- data/lib/ruby_smb/field/stringz16.rb +17 -1
- data/lib/ruby_smb/nbss/session_header.rb +4 -4
- data/lib/ruby_smb/smb1/commands.rb +1 -1
- data/lib/ruby_smb/smb1/file.rb +8 -14
- data/lib/ruby_smb/smb1/packet/session_setup_legacy_request.rb +1 -1
- data/lib/ruby_smb/smb1/packet/session_setup_legacy_response.rb +2 -2
- data/lib/ruby_smb/smb1/packet/session_setup_request.rb +1 -1
- data/lib/ruby_smb/smb1/packet/session_setup_response.rb +2 -2
- data/lib/ruby_smb/smb1/packet/write_andx_request.rb +1 -1
- data/lib/ruby_smb/smb1/pipe.rb +81 -3
- data/lib/ruby_smb/smb1/tree.rb +12 -3
- data/lib/ruby_smb/smb2/bit_field/session_flags.rb +2 -1
- data/lib/ruby_smb/smb2/bit_field/share_flags.rb +6 -4
- data/lib/ruby_smb/smb2/file.rb +51 -61
- data/lib/ruby_smb/smb2/negotiate_context.rb +108 -0
- data/lib/ruby_smb/smb2/packet.rb +2 -0
- data/lib/ruby_smb/smb2/packet/compression_transform_header.rb +41 -0
- data/lib/ruby_smb/smb2/packet/error_packet.rb +2 -4
- data/lib/ruby_smb/smb2/packet/negotiate_request.rb +51 -14
- data/lib/ruby_smb/smb2/packet/negotiate_response.rb +50 -4
- data/lib/ruby_smb/smb2/packet/transform_header.rb +84 -0
- data/lib/ruby_smb/smb2/packet/tree_connect_request.rb +92 -6
- data/lib/ruby_smb/smb2/packet/tree_connect_response.rb +8 -26
- data/lib/ruby_smb/smb2/pipe.rb +80 -3
- data/lib/ruby_smb/smb2/smb2_header.rb +1 -1
- data/lib/ruby_smb/smb2/tree.rb +32 -20
- data/lib/ruby_smb/version.rb +1 -1
- data/ruby_smb.gemspec +5 -3
- data/spec/lib/ruby_smb/client_spec.rb +1583 -102
- data/spec/lib/ruby_smb/crypto_spec.rb +25 -0
- data/spec/lib/ruby_smb/dcerpc/bind_ack_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/bind_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/ndr_spec.rb +1729 -0
- data/spec/lib/ruby_smb/dcerpc/request_spec.rb +50 -7
- data/spec/lib/ruby_smb/dcerpc/rpc_security_attributes_spec.rb +161 -0
- data/spec/lib/ruby_smb/dcerpc/rrp_unicode_string_spec.rb +135 -0
- data/spec/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all_spec.rb +13 -0
- data/spec/lib/ruby_smb/dcerpc/srvsvc_spec.rb +60 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request_spec.rb +191 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_request_spec.rb +30 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_request_spec.rb +39 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request_spec.rb +78 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_request_spec.rb +59 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response_spec.rb +152 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_request_spec.rb +30 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/service_status_spec.rb +72 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_request_spec.rb +46 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_response_spec.rb +30 -0
- data/spec/lib/ruby_smb/dcerpc/svcctl_spec.rb +512 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/close_key_request_spec.rb +28 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/close_key_response_spec.rb +36 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/create_key_request_spec.rb +110 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/create_key_response_spec.rb +44 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_request_spec.rb +104 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_response_spec.rb +97 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_request_spec.rb +94 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_response_spec.rb +82 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/open_key_request_spec.rb +74 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/open_key_response_spec.rb +35 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_request_spec.rb +95 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_response_spec.rb +38 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/query_info_key_request_spec.rb +35 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/query_info_key_response_spec.rb +113 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/query_value_request_spec.rb +88 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/query_value_response_spec.rb +138 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/regsam_spec.rb +32 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/save_key_request_spec.rb +57 -0
- data/spec/lib/ruby_smb/dcerpc/winreg/save_key_response_spec.rb +22 -0
- data/spec/lib/ruby_smb/dcerpc/winreg_spec.rb +884 -0
- data/spec/lib/ruby_smb/dcerpc_spec.rb +81 -0
- data/spec/lib/ruby_smb/dispatcher/socket_spec.rb +12 -12
- data/spec/lib/ruby_smb/error_spec.rb +59 -0
- data/spec/lib/ruby_smb/field/stringz16_spec.rb +12 -0
- data/spec/lib/ruby_smb/nbss/session_header_spec.rb +4 -11
- data/spec/lib/ruby_smb/smb1/file_spec.rb +9 -1
- data/spec/lib/ruby_smb/smb1/packet/session_setup_legacy_request_spec.rb +2 -2
- data/spec/lib/ruby_smb/smb1/packet/session_setup_legacy_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/smb1/packet/session_setup_request_spec.rb +2 -2
- data/spec/lib/ruby_smb/smb1/packet/session_setup_response_spec.rb +1 -1
- data/spec/lib/ruby_smb/smb1/pipe_spec.rb +216 -147
- data/spec/lib/ruby_smb/smb2/bit_field/session_flags_spec.rb +9 -0
- data/spec/lib/ruby_smb/smb2/bit_field/share_flags_spec.rb +27 -0
- data/spec/lib/ruby_smb/smb2/file_spec.rb +146 -68
- data/spec/lib/ruby_smb/smb2/negotiate_context_spec.rb +332 -0
- data/spec/lib/ruby_smb/smb2/packet/compression_transform_header_spec.rb +108 -0
- data/spec/lib/ruby_smb/smb2/packet/error_packet_spec.rb +3 -24
- data/spec/lib/ruby_smb/smb2/packet/negotiate_request_spec.rb +138 -3
- data/spec/lib/ruby_smb/smb2/packet/negotiate_response_spec.rb +120 -2
- data/spec/lib/ruby_smb/smb2/packet/transform_header_spec.rb +220 -0
- data/spec/lib/ruby_smb/smb2/packet/tree_connect_request_spec.rb +339 -9
- data/spec/lib/ruby_smb/smb2/packet/tree_connect_response_spec.rb +3 -30
- data/spec/lib/ruby_smb/smb2/pipe_spec.rb +226 -148
- data/spec/lib/ruby_smb/smb2/smb2_header_spec.rb +2 -2
- data/spec/lib/ruby_smb/smb2/tree_spec.rb +88 -9
- metadata +257 -81
- metadata.gz.sig +0 -0
- data/lib/ruby_smb/smb1/dcerpc.rb +0 -72
- data/lib/ruby_smb/smb2/dcerpc.rb +0 -75
@@ -0,0 +1,108 @@
|
|
1
|
+
RSpec.describe RubySMB::SMB2::Packet::CompressionTransformHeader do
|
2
|
+
subject(:packet) { described_class.new }
|
3
|
+
|
4
|
+
it { is_expected.to respond_to :protocol }
|
5
|
+
it { is_expected.to respond_to :original_compressed_segment_size }
|
6
|
+
it { is_expected.to respond_to :compression_algorithm }
|
7
|
+
it { is_expected.to respond_to :flags }
|
8
|
+
it { is_expected.to respond_to :offset }
|
9
|
+
|
10
|
+
it 'is little endian' do
|
11
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#protocol' do
|
15
|
+
it 'is a 32-bit field' do
|
16
|
+
expect(packet.protocol).to be_a BinData::Bit32
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'is initialized with the value 0xFC534D42' do
|
20
|
+
expect(packet.protocol).to eq(0xFC534D42)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#original_compressed_segment_size ' do
|
25
|
+
it 'is a 32-bit unsigned integer' do
|
26
|
+
expect(packet.original_compressed_segment_size).to be_a BinData::Uint32le
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#compression_algorithm ' do
|
31
|
+
it 'is a 16-bit unsigned integer' do
|
32
|
+
expect(packet.compression_algorithm).to be_a BinData::Uint16le
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#flags ' do
|
37
|
+
it 'is a 16-bit unsigned integer' do
|
38
|
+
expect(packet.flags).to be_a BinData::Uint16le
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#offset' do
|
43
|
+
it 'is a 32-bit unsigned integer' do
|
44
|
+
expect(packet.offset).to be_a BinData::Uint32le
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'reads binary data as expected' do
|
49
|
+
data = described_class.new
|
50
|
+
expect(described_class.read(data.to_binary_s)).to eq(data)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
RSpec.describe RubySMB::SMB2::Packet::Smb2CompressionPayloadHeader do
|
55
|
+
subject(:packet) { described_class.new }
|
56
|
+
|
57
|
+
it { is_expected.to respond_to :algorithm_id }
|
58
|
+
it { is_expected.to respond_to :payload_length }
|
59
|
+
|
60
|
+
it 'is little endian' do
|
61
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#algorithm_id ' do
|
65
|
+
it 'is a 16-bit unsigned integer' do
|
66
|
+
expect(packet.algorithm_id).to be_a BinData::Uint16le
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#payload_length' do
|
71
|
+
it 'is a 32-bit unsigned integer' do
|
72
|
+
expect(packet.payload_length).to be_a BinData::Uint32le
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'reads binary data as expected' do
|
77
|
+
data = described_class.new
|
78
|
+
expect(described_class.read(data.to_binary_s)).to eq(data)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
RSpec.describe RubySMB::SMB2::Packet::Smb2CompressionPatternPayloadV1 do
|
83
|
+
subject(:packet) { described_class.new }
|
84
|
+
|
85
|
+
it { is_expected.to respond_to :pattern }
|
86
|
+
it { is_expected.to respond_to :repetitions }
|
87
|
+
|
88
|
+
it 'is little endian' do
|
89
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#pattern' do
|
93
|
+
it 'is a 8-bit unsigned integer' do
|
94
|
+
expect(packet.pattern).to be_a BinData::Uint8
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#repetitions' do
|
99
|
+
it 'is a 32-bit unsigned integer' do
|
100
|
+
expect(packet.repetitions).to be_a BinData::Uint32le
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'reads binary data as expected' do
|
105
|
+
data = described_class.new
|
106
|
+
expect(described_class.read(data.to_binary_s)).to eq(data)
|
107
|
+
end
|
108
|
+
end
|
@@ -35,17 +35,6 @@ RSpec.describe RubySMB::SMB2::Packet::ErrorPacket do
|
|
35
35
|
it 'should be a 32-bit unsigned integer' do
|
36
36
|
expect(packet.byte_count).to be_a BinData::Uint32le
|
37
37
|
end
|
38
|
-
|
39
|
-
it 'should be the number of bytes in #error_data' do
|
40
|
-
str = 'testing'
|
41
|
-
packet.error_data = str
|
42
|
-
expect(packet.byte_count).to eq str.size
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should be 0 when #error_data is 1-byte long' do
|
46
|
-
packet.error_data = "\x00"
|
47
|
-
expect(packet.byte_count).to eq 0
|
48
|
-
end
|
49
38
|
end
|
50
39
|
|
51
40
|
describe '#error_data' do
|
@@ -53,20 +42,10 @@ RSpec.describe RubySMB::SMB2::Packet::ErrorPacket do
|
|
53
42
|
expect(packet.error_data).to be_a BinData::String
|
54
43
|
end
|
55
44
|
|
56
|
-
it 'should
|
57
|
-
expect(packet.error_data).to eq "\x00"
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should read 1 byte when #byte_count is 0' do
|
61
|
-
packet.error_data = 'test'
|
62
|
-
packet.byte_count = 0
|
63
|
-
expect(described_class.read(packet.to_binary_s).error_data.size).to eq 1
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should read #byte_count bytes when #byte_count is not 0' do
|
45
|
+
it 'should read #byte_count bytes' do
|
67
46
|
packet.error_data = 'test'
|
68
|
-
packet.byte_count =
|
69
|
-
expect(described_class.read(packet.to_binary_s).error_data.size).to eq
|
47
|
+
packet.byte_count = 3
|
48
|
+
expect(described_class.read(packet.to_binary_s).error_data.size).to eq 3
|
70
49
|
end
|
71
50
|
end
|
72
51
|
|
@@ -8,6 +8,7 @@ RSpec.describe RubySMB::SMB2::Packet::NegotiateRequest do
|
|
8
8
|
it { is_expected.to respond_to :reserved1 }
|
9
9
|
it { is_expected.to respond_to :capabilities }
|
10
10
|
it { is_expected.to respond_to :client_guid }
|
11
|
+
it { is_expected.to respond_to :negotiate_context_info}
|
11
12
|
it { is_expected.to respond_to :client_start_time }
|
12
13
|
it { is_expected.to respond_to :dialects }
|
13
14
|
|
@@ -45,6 +46,11 @@ RSpec.describe RubySMB::SMB2::Packet::NegotiateRequest do
|
|
45
46
|
it 'should be a 16-bit unsigned integer' do
|
46
47
|
expect(packet.dialect_count).to be_a BinData::Uint16le
|
47
48
|
end
|
49
|
+
|
50
|
+
it 'is initially set to the #dialects array size' do
|
51
|
+
packet.dialects = [1,2,3]
|
52
|
+
expect(packet.dialect_count).to eq(3)
|
53
|
+
end
|
48
54
|
end
|
49
55
|
|
50
56
|
describe '#security_mode' do
|
@@ -69,7 +75,65 @@ RSpec.describe RubySMB::SMB2::Packet::NegotiateRequest do
|
|
69
75
|
end
|
70
76
|
end
|
71
77
|
|
78
|
+
describe '#negotiate_context_info' do
|
79
|
+
it 'only exists if the 0x0311 dialect is included' do
|
80
|
+
packet.dialects << 0x0311
|
81
|
+
expect(packet.negotiate_context_info?).to be true
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'does not exist if the 0x0311 dialect is not included' do
|
85
|
+
packet.dialects << 0x0300
|
86
|
+
expect(packet.negotiate_context_info?).to be false
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should be a Struct field' do
|
90
|
+
expect(packet.negotiate_context_info).to be_a BinData::Struct
|
91
|
+
end
|
92
|
+
|
93
|
+
subject(:struct) do
|
94
|
+
packet.dialects << 0x0311
|
95
|
+
packet.negotiate_context_info
|
96
|
+
end
|
97
|
+
it { is_expected.to respond_to :negotiate_context_offset }
|
98
|
+
it { is_expected.to respond_to :negotiate_context_count }
|
99
|
+
|
100
|
+
describe '#negotiate_context_offset' do
|
101
|
+
it 'should be a 32-bit unsigned integer' do
|
102
|
+
expect(struct.negotiate_context_offset).to be_a BinData::Uint32le
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'is set to the #negotiate_context_list absolute offset' do
|
106
|
+
expect(struct.negotiate_context_offset).to eq(packet.negotiate_context_list.abs_offset)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#negotiate_context_count' do
|
111
|
+
it 'should be a 16-bit unsigned integer' do
|
112
|
+
expect(struct.negotiate_context_count).to be_a BinData::Uint16le
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'is set to the #negotiate_context_list array size' do
|
116
|
+
nc = RubySMB::SMB2::NegotiateContext.new(
|
117
|
+
context_type: RubySMB::SMB2::NegotiateContext::SMB2_PREAUTH_INTEGRITY_CAPABILITIES
|
118
|
+
)
|
119
|
+
packet.negotiate_context_list << nc
|
120
|
+
packet.negotiate_context_list << nc
|
121
|
+
expect(struct.negotiate_context_count).to eq(2)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
72
126
|
describe '#client_start_time' do
|
127
|
+
it 'does not exist if the 0x0311 dialect is included' do
|
128
|
+
packet.dialects << 0x0311
|
129
|
+
expect(packet.client_start_time?).to be false
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'only exists if the 0x0311 dialect is not included' do
|
133
|
+
packet.dialects << 0x0300
|
134
|
+
expect(packet.client_start_time?).to be true
|
135
|
+
end
|
136
|
+
|
73
137
|
it 'should be a Filetime field' do
|
74
138
|
expect(packet.client_start_time).to be_a RubySMB::Field::FileTime
|
75
139
|
end
|
@@ -85,15 +149,51 @@ RSpec.describe RubySMB::SMB2::Packet::NegotiateRequest do
|
|
85
149
|
end
|
86
150
|
end
|
87
151
|
|
152
|
+
describe '#pad' do
|
153
|
+
it 'only exists if the 0x0311 dialect is included' do
|
154
|
+
packet.dialects << 0x0311
|
155
|
+
expect(packet.pad?).to be true
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'does not exist if the 0x0311 dialect is not included' do
|
159
|
+
packet.dialects << 0x0300
|
160
|
+
expect(packet.pad?).to be false
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should be a binary string' do
|
164
|
+
expect(packet.pad).to be_a BinData::String
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should keep #negotiate_context_list 8-byte aligned' do
|
168
|
+
packet.dialects << 0x0311
|
169
|
+
expect(packet.negotiate_context_list.abs_offset % 8).to eq 0
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#negotiate_context_list' do
|
174
|
+
it 'only exists if the 0x0311 dialect is included' do
|
175
|
+
packet.dialects << 0x0311
|
176
|
+
expect(packet.negotiate_context_list?).to be true
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'does not exist if the 0x0311 dialect is not included' do
|
180
|
+
packet.dialects << 0x0300
|
181
|
+
expect(packet.negotiate_context_list?).to be false
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'is an array field as per the SMB spec' do
|
185
|
+
expect(packet.negotiate_context_list).to be_a BinData::Array
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
88
189
|
describe '#add_dialect' do
|
89
190
|
it 'adds the dialect to the Dialects array' do
|
90
191
|
packet.add_dialect 0x0201
|
91
192
|
expect(packet.dialects).to include(0x0201)
|
92
193
|
end
|
93
194
|
|
94
|
-
it '
|
95
|
-
packet.add_dialect
|
96
|
-
expect(packet.dialect_count).to eq 1
|
195
|
+
it 'raises an ArgumentError exceptionif it is not an Integer' do
|
196
|
+
expect { packet.add_dialect('dialect') }.to raise_error(ArgumentError)
|
97
197
|
end
|
98
198
|
end
|
99
199
|
|
@@ -119,4 +219,39 @@ RSpec.describe RubySMB::SMB2::Packet::NegotiateRequest do
|
|
119
219
|
expect(packet.dialect_count).to eq 3
|
120
220
|
end
|
121
221
|
end
|
222
|
+
|
223
|
+
describe '#add_negotiate_context' do
|
224
|
+
it 'raises an ArgumentError exceptionif it is not a NegotiateContext structure' do
|
225
|
+
expect { packet.add_negotiate_context('nc') }.to raise_error(ArgumentError)
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'updates the NegotiateContext#pad length to make sure the structure is 8-byte aligned' do
|
229
|
+
packet.dialects << 0x0311
|
230
|
+
[
|
231
|
+
RubySMB::SMB2::NegotiateContext::SMB2_PREAUTH_INTEGRITY_CAPABILITIES,
|
232
|
+
RubySMB::SMB2::NegotiateContext::SMB2_ENCRYPTION_CAPABILITIES,
|
233
|
+
RubySMB::SMB2::NegotiateContext::SMB2_COMPRESSION_CAPABILITIES,
|
234
|
+
RubySMB::SMB2::NegotiateContext::SMB2_NETNAME_NEGOTIATE_CONTEXT_ID
|
235
|
+
].each do |context_type|
|
236
|
+
nc = RubySMB::SMB2::NegotiateContext.new(context_type: context_type)
|
237
|
+
packet.add_negotiate_context(nc)
|
238
|
+
expect(packet.negotiate_context_list.last.context_type.abs_offset % 8).to eq 0
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'reads binary data as expected' do
|
244
|
+
data = described_class.new
|
245
|
+
data.set_dialects([0x0202, 0x0210, 0x0311])
|
246
|
+
[
|
247
|
+
RubySMB::SMB2::NegotiateContext::SMB2_PREAUTH_INTEGRITY_CAPABILITIES,
|
248
|
+
RubySMB::SMB2::NegotiateContext::SMB2_ENCRYPTION_CAPABILITIES,
|
249
|
+
RubySMB::SMB2::NegotiateContext::SMB2_COMPRESSION_CAPABILITIES,
|
250
|
+
RubySMB::SMB2::NegotiateContext::SMB2_NETNAME_NEGOTIATE_CONTEXT_ID
|
251
|
+
].each do |context_type|
|
252
|
+
nc = RubySMB::SMB2::NegotiateContext.new(context_type: context_type)
|
253
|
+
data.add_negotiate_context(nc)
|
254
|
+
expect(described_class.read(data.to_binary_s)).to eq(data)
|
255
|
+
end
|
256
|
+
end
|
122
257
|
end
|
@@ -61,12 +61,28 @@ RSpec.describe RubySMB::SMB2::Packet::NegotiateResponse do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe '#negotiate_context_count' do
|
64
|
+
it 'only exists if the 0x0311 dialect is included' do
|
65
|
+
packet.dialect_revision = 0x0311
|
66
|
+
expect(packet.negotiate_context_count?).to be true
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'does not exist if the 0x0311 dialect is not included' do
|
70
|
+
packet.dialect_revision = 0x0300
|
71
|
+
expect(packet.negotiate_context_count?).to be false
|
72
|
+
end
|
73
|
+
|
64
74
|
it 'is a 16-bit unsigned integer' do
|
65
75
|
expect(packet.negotiate_context_count).to be_a BinData::Uint16le
|
66
76
|
end
|
67
77
|
|
68
|
-
it '
|
69
|
-
|
78
|
+
it 'is set to the #negotiate_context_list array size' do
|
79
|
+
packet.dialect_revision = 0x0311
|
80
|
+
nc = RubySMB::SMB2::NegotiateContext.new(
|
81
|
+
context_type: RubySMB::SMB2::NegotiateContext::SMB2_PREAUTH_INTEGRITY_CAPABILITIES
|
82
|
+
)
|
83
|
+
packet.negotiate_context_list << nc
|
84
|
+
packet.negotiate_context_list << nc
|
85
|
+
expect(packet.negotiate_context_count).to eq(2)
|
70
86
|
end
|
71
87
|
end
|
72
88
|
|
@@ -134,6 +150,16 @@ RSpec.describe RubySMB::SMB2::Packet::NegotiateResponse do
|
|
134
150
|
end
|
135
151
|
|
136
152
|
describe '#negotiate_context_offset' do
|
153
|
+
it 'only exists if the 0x0311 dialect is included' do
|
154
|
+
packet.dialect_revision = 0x0311
|
155
|
+
expect(packet.negotiate_context_offset?).to be true
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'does not exist if the 0x0311 dialect is not included' do
|
159
|
+
packet.dialect_revision = 0x0300
|
160
|
+
expect(packet.negotiate_context_offset?).to be false
|
161
|
+
end
|
162
|
+
|
137
163
|
it 'is a 32-bit unsigned integer' do
|
138
164
|
expect(packet.negotiate_context_offset).to be_a BinData::Uint32le
|
139
165
|
end
|
@@ -144,4 +170,96 @@ RSpec.describe RubySMB::SMB2::Packet::NegotiateResponse do
|
|
144
170
|
expect(packet.security_buffer).to be_a BinData::String
|
145
171
|
end
|
146
172
|
end
|
173
|
+
|
174
|
+
describe '#pad' do
|
175
|
+
it 'only exists if the 0x0311 dialect is included' do
|
176
|
+
packet.dialect_revision = 0x0311
|
177
|
+
expect(packet.pad?).to be true
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'does not exist if the 0x0311 dialect is not included' do
|
181
|
+
packet.dialect_revision = 0x0300
|
182
|
+
expect(packet.pad?).to be false
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should be a binary string' do
|
186
|
+
expect(packet.pad).to be_a BinData::String
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'should keep #negotiate_context_list 8-byte aligned' do
|
190
|
+
packet.dialect_revision = 0x0311
|
191
|
+
expect(packet.negotiate_context_list.abs_offset % 8).to eq 0
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe '#negotiate_context_list' do
|
196
|
+
it 'only exists if the 0x0311 dialect is included' do
|
197
|
+
packet.dialect_revision = 0x0311
|
198
|
+
expect(packet.negotiate_context_list?).to be true
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'does not exist if the 0x0311 dialect is not included' do
|
202
|
+
packet.dialect_revision = 0x0300
|
203
|
+
expect(packet.negotiate_context_list?).to be false
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'is an array field as per the SMB spec' do
|
207
|
+
expect(packet.negotiate_context_list).to be_a BinData::Array
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
describe '#find_negotiate_context' do
|
212
|
+
before :example do
|
213
|
+
packet.add_negotiate_context(
|
214
|
+
RubySMB::SMB2::NegotiateContext.new(context_type: RubySMB::SMB2::NegotiateContext::SMB2_PREAUTH_INTEGRITY_CAPABILITIES)
|
215
|
+
)
|
216
|
+
packet.add_negotiate_context(
|
217
|
+
RubySMB::SMB2::NegotiateContext.new(context_type: RubySMB::SMB2::NegotiateContext::SMB2_ENCRYPTION_CAPABILITIES)
|
218
|
+
)
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'returns the expected Negotiate Context structure' do
|
222
|
+
expect(packet.find_negotiate_context(RubySMB::SMB2::NegotiateContext::SMB2_ENCRYPTION_CAPABILITIES)).to eq(packet.negotiate_context_list[1])
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'returns nil if the Negotiate Context structure is not found' do
|
226
|
+
expect(packet.find_negotiate_context(10)).to be nil
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
describe '#add_negotiate_context' do
|
231
|
+
it 'raises an ArgumentError exception if it is not a NegotiateContext structure' do
|
232
|
+
expect { packet.add_negotiate_context('nc') }.to raise_error(ArgumentError)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'updates the NegotiateContext#pad length to make sure the structure is 8-byte aligned' do
|
236
|
+
packet.dialect_revision = 0x0311
|
237
|
+
[
|
238
|
+
RubySMB::SMB2::NegotiateContext::SMB2_PREAUTH_INTEGRITY_CAPABILITIES,
|
239
|
+
RubySMB::SMB2::NegotiateContext::SMB2_ENCRYPTION_CAPABILITIES,
|
240
|
+
RubySMB::SMB2::NegotiateContext::SMB2_COMPRESSION_CAPABILITIES,
|
241
|
+
RubySMB::SMB2::NegotiateContext::SMB2_NETNAME_NEGOTIATE_CONTEXT_ID
|
242
|
+
].each do |context_type|
|
243
|
+
nc = RubySMB::SMB2::NegotiateContext.new(context_type: context_type)
|
244
|
+
packet.add_negotiate_context(nc)
|
245
|
+
expect(packet.negotiate_context_list.last.context_type.abs_offset % 8).to eq 0
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'reads binary data as expected' do
|
251
|
+
data = described_class.new
|
252
|
+
data.dialect_revision = 0x0311
|
253
|
+
data.security_buffer = 'security buf test'
|
254
|
+
[
|
255
|
+
RubySMB::SMB2::NegotiateContext::SMB2_PREAUTH_INTEGRITY_CAPABILITIES,
|
256
|
+
RubySMB::SMB2::NegotiateContext::SMB2_ENCRYPTION_CAPABILITIES,
|
257
|
+
RubySMB::SMB2::NegotiateContext::SMB2_COMPRESSION_CAPABILITIES,
|
258
|
+
RubySMB::SMB2::NegotiateContext::SMB2_NETNAME_NEGOTIATE_CONTEXT_ID
|
259
|
+
].each do |context_type|
|
260
|
+
nc = RubySMB::SMB2::NegotiateContext.new(context_type: context_type)
|
261
|
+
data.add_negotiate_context(nc)
|
262
|
+
expect(described_class.read(data.to_binary_s)).to eq(data)
|
263
|
+
end
|
264
|
+
end
|
147
265
|
end
|