ruby_smb 1.1.0 → 2.0.4
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 -5
- data/Gemfile +6 -2
- 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 +5 -4
- data/examples/enum_registry_values.rb +5 -4
- 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 +11 -12
- 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 +6 -5
- 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 -0
- data/lib/ruby_smb/client.rb +246 -26
- data/lib/ruby_smb/client/authentication.rb +32 -18
- data/lib/ruby_smb/client/echo.rb +2 -4
- data/lib/ruby_smb/client/encryption.rb +62 -0
- data/lib/ruby_smb/client/negotiation.rb +156 -16
- data/lib/ruby_smb/client/signing.rb +19 -0
- data/lib/ruby_smb/client/tree_connect.rb +6 -8
- data/lib/ruby_smb/client/utils.rb +24 -17
- data/lib/ruby_smb/client/winreg.rb +1 -1
- data/lib/ruby_smb/crypto.rb +30 -0
- data/lib/ruby_smb/dcerpc.rb +2 -0
- data/lib/ruby_smb/dcerpc/error.rb +3 -0
- data/lib/ruby_smb/dcerpc/ndr.rb +209 -44
- data/lib/ruby_smb/dcerpc/request.rb +13 -0
- data/lib/ruby_smb/dcerpc/rpc_security_attributes.rb +34 -0
- data/lib/ruby_smb/dcerpc/rrp_unicode_string.rb +9 -6
- 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 +98 -17
- 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 +1 -1
- data/lib/ruby_smb/dcerpc/winreg/enum_value_request.rb +1 -1
- data/lib/ruby_smb/dcerpc/winreg/enum_value_response.rb +1 -1
- data/lib/ruby_smb/dcerpc/winreg/open_root_key_request.rb +4 -4
- data/lib/ruby_smb/dcerpc/winreg/query_info_key_request.rb +1 -1
- data/lib/ruby_smb/dcerpc/winreg/query_value_request.rb +7 -6
- data/lib/ruby_smb/dcerpc/winreg/query_value_response.rb +10 -10
- 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 +49 -6
- data/lib/ruby_smb/field/stringz16.rb +17 -1
- data/lib/ruby_smb/generic_packet.rb +11 -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 +13 -28
- 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 +8 -8
- data/lib/ruby_smb/smb1/tree.rb +25 -12
- 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 +59 -77
- 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/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 +8 -20
- data/lib/ruby_smb/smb2/smb2_header.rb +1 -1
- data/lib/ruby_smb/smb2/tree.rb +44 -28
- data/lib/ruby_smb/version.rb +1 -1
- data/ruby_smb.gemspec +3 -1
- data/spec/lib/ruby_smb/client_spec.rb +1408 -70
- data/spec/lib/ruby_smb/crypto_spec.rb +25 -0
- data/spec/lib/ruby_smb/dcerpc/ndr_spec.rb +1396 -77
- data/spec/lib/ruby_smb/dcerpc/rpc_security_attributes_spec.rb +161 -0
- data/spec/lib/ruby_smb/dcerpc/rrp_unicode_string_spec.rb +49 -12
- 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/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 +0 -4
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_request_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_response_spec.rb +2 -2
- data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_request_spec.rb +9 -4
- data/spec/lib/ruby_smb/dcerpc/winreg/query_info_key_request_spec.rb +0 -4
- data/spec/lib/ruby_smb/dcerpc/winreg/query_value_request_spec.rb +17 -17
- data/spec/lib/ruby_smb/dcerpc/winreg/query_value_response_spec.rb +11 -23
- 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 +227 -41
- data/spec/lib/ruby_smb/dispatcher/socket_spec.rb +12 -12
- data/spec/lib/ruby_smb/error_spec.rb +88 -0
- data/spec/lib/ruby_smb/field/stringz16_spec.rb +12 -0
- data/spec/lib/ruby_smb/generic_packet_spec.rb +7 -0
- data/spec/lib/ruby_smb/nbss/session_header_spec.rb +4 -11
- data/spec/lib/ruby_smb/smb1/file_spec.rb +1 -3
- 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 +30 -5
- data/spec/lib/ruby_smb/smb1/tree_spec.rb +22 -0
- 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 +147 -71
- 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/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 +9 -45
- data/spec/lib/ruby_smb/smb2/smb2_header_spec.rb +2 -2
- data/spec/lib/ruby_smb/smb2/tree_spec.rb +111 -9
- metadata +194 -75
- metadata.gz.sig +2 -1
@@ -0,0 +1,110 @@
|
|
1
|
+
RSpec.describe RubySMB::Dcerpc::Winreg::RpcHkey do
|
2
|
+
subject(:packet) { described_class.new }
|
3
|
+
|
4
|
+
it 'is NdrContextHandle subclass' do
|
5
|
+
expect(described_class).to be < RubySMB::Dcerpc::Ndr::NdrContextHandle
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.describe RubySMB::Dcerpc::Winreg::CreateKeyRequest do
|
10
|
+
subject(:packet) { described_class.new }
|
11
|
+
|
12
|
+
|
13
|
+
it 'is little endian' do
|
14
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
15
|
+
end
|
16
|
+
|
17
|
+
it { is_expected.to respond_to :hkey }
|
18
|
+
it { is_expected.to respond_to :lp_sub_key }
|
19
|
+
it { is_expected.to respond_to :pad1 }
|
20
|
+
it { is_expected.to respond_to :lp_class }
|
21
|
+
it { is_expected.to respond_to :pad2 }
|
22
|
+
it { is_expected.to respond_to :dw_options }
|
23
|
+
it { is_expected.to respond_to :sam_desired }
|
24
|
+
it { is_expected.to respond_to :lp_security_attributes }
|
25
|
+
it { is_expected.to respond_to :pad3 }
|
26
|
+
it { is_expected.to respond_to :lpdw_disposition }
|
27
|
+
|
28
|
+
describe '#hkey' do
|
29
|
+
it 'is a RpcHkey structure' do
|
30
|
+
expect(packet.hkey).to be_a RubySMB::Dcerpc::Winreg::RpcHkey
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#lp_sub_key' do
|
35
|
+
it 'is a RrpUnicodeString structure' do
|
36
|
+
expect(packet.lp_sub_key).to be_a RubySMB::Dcerpc::RrpUnicodeString
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#pad1' do
|
41
|
+
it 'is a string' do
|
42
|
+
expect(packet.pad1).to be_a BinData::String
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should keep #lp_class 4-byte aligned' do
|
46
|
+
packet.lp_sub_key = "test"
|
47
|
+
expect(packet.lp_class.abs_offset % 4).to eq 0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#lp_class' do
|
52
|
+
it 'is a RrpUnicodeString structure' do
|
53
|
+
expect(packet.lp_class).to be_a RubySMB::Dcerpc::RrpUnicodeString
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#pad2' do
|
58
|
+
it 'is a string' do
|
59
|
+
expect(packet.pad1).to be_a BinData::String
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should keep #dw_options 4-byte aligned' do
|
63
|
+
packet.lp_class = "test"
|
64
|
+
expect(packet.dw_options.abs_offset % 4).to eq 0
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#dw_options' do
|
69
|
+
it 'is a 32-bit unsigned integer' do
|
70
|
+
expect(packet.dw_options).to be_a BinData::Uint32le
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#sam_desired' do
|
75
|
+
it 'is a Regsam structure' do
|
76
|
+
expect(packet.sam_desired).to be_a RubySMB::Dcerpc::Winreg::Regsam
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#lp_security_attributes' do
|
81
|
+
it 'is a PrpcSecurityAttributes structure' do
|
82
|
+
expect(packet.lp_security_attributes).to be_a RubySMB::Dcerpc::PrpcSecurityAttributes
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#pad3' do
|
87
|
+
it 'is a string' do
|
88
|
+
expect(packet.pad1).to be_a BinData::String
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should keep #lpdw_disposition 4-byte aligned' do
|
92
|
+
sc = RubySMB::Dcerpc::RpcSecurityDescriptor.new(lp_security_descriptor: [1,2,3,4])
|
93
|
+
packet.lp_security_attributes = RubySMB::Dcerpc::RpcSecurityAttributes.new(rpc_security_descriptor: sc)
|
94
|
+
expect(packet.lpdw_disposition.abs_offset % 4).to eq 0
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#lpdw_disposition' do
|
99
|
+
it 'is a NdrLpDword structure' do
|
100
|
+
expect(packet.lpdw_disposition).to be_a RubySMB::Dcerpc::Ndr::NdrLpDword
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#initialize_instance' do
|
105
|
+
it 'sets #opnum to REG_CREATE_KEY constant' do
|
106
|
+
expect(packet.opnum).to eq(RubySMB::Dcerpc::Winreg::REG_CREATE_KEY)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
RSpec.describe RubySMB::Dcerpc::Winreg::PrpcHkey do
|
2
|
+
subject(:packet) { described_class.new }
|
3
|
+
|
4
|
+
it 'is NdrContextHandle subclass' do
|
5
|
+
expect(described_class).to be < RubySMB::Dcerpc::Ndr::NdrContextHandle
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.describe RubySMB::Dcerpc::Winreg::CreateKeyResponse do
|
10
|
+
subject(:packet) { described_class.new }
|
11
|
+
|
12
|
+
it { is_expected.to respond_to :hkey }
|
13
|
+
it { is_expected.to respond_to :lpdw_disposition }
|
14
|
+
it { is_expected.to respond_to :error_status }
|
15
|
+
|
16
|
+
it 'is little endian' do
|
17
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#hkey' do
|
21
|
+
it 'is a PrpcHkey structure' do
|
22
|
+
expect(packet.hkey).to be_a RubySMB::Dcerpc::Winreg::PrpcHkey
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#lpdw_disposition' do
|
27
|
+
it 'is a NdrLpDword structure' do
|
28
|
+
expect(packet.lpdw_disposition).to be_a RubySMB::Dcerpc::Ndr::NdrLpDword
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#error_status' do
|
33
|
+
it 'is a 32-bit unsigned integer' do
|
34
|
+
expect(packet.error_status).to be_a BinData::Uint32le
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#initialize_instance' do
|
39
|
+
it 'sets #opnum to REG_CREATE_KEY constant' do
|
40
|
+
expect(packet.opnum).to eq(RubySMB::Dcerpc::Winreg::REG_CREATE_KEY)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -53,10 +53,6 @@ RSpec.describe RubySMB::Dcerpc::Winreg::EnumKeyRequest do
|
|
53
53
|
it 'is a PrrpUnicodeString structure' do
|
54
54
|
expect(packet.lp_class).to be_a RubySMB::Dcerpc::PrrpUnicodeString
|
55
55
|
end
|
56
|
-
|
57
|
-
it 'has a initial value of 0' do
|
58
|
-
expect(packet.lp_class).to eq(0)
|
59
|
-
end
|
60
56
|
end
|
61
57
|
|
62
58
|
describe '#pad2' do
|
@@ -57,8 +57,8 @@ RSpec.describe RubySMB::Dcerpc::Winreg::EnumValueRequest do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe '#lp_data' do
|
60
|
-
it 'is a
|
61
|
-
expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::
|
60
|
+
it 'is a NdrLpByteArray structure' do
|
61
|
+
expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::NdrLpByteArray
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -38,8 +38,8 @@ RSpec.describe RubySMB::Dcerpc::Winreg::EnumValueResponse do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
describe '#lp_data' do
|
41
|
-
it 'is a
|
42
|
-
expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::
|
41
|
+
it 'is a NdrLpByteArray structure' do
|
42
|
+
expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::NdrLpByteArray
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
RSpec.describe RubySMB::Dcerpc::Winreg::PRegistryServerName do
|
2
|
-
it 'is
|
3
|
-
expect(described_class).to be < RubySMB::Dcerpc::Ndr::
|
2
|
+
it 'is NdrPointer subclass' do
|
3
|
+
expect(described_class).to be < RubySMB::Dcerpc::Ndr::NdrPointer
|
4
4
|
end
|
5
5
|
|
6
6
|
subject(:packet) { described_class.new }
|
@@ -16,6 +16,11 @@ RSpec.describe RubySMB::Dcerpc::Winreg::PRegistryServerName do
|
|
16
16
|
expect(packet.referent).to be_a RubySMB::Field::String16
|
17
17
|
end
|
18
18
|
|
19
|
+
it 'only exists if #referent_id is not 0' do
|
20
|
+
packet.referent_id = 0
|
21
|
+
expect(packet.referent?).to be false
|
22
|
+
end
|
23
|
+
|
19
24
|
it 'reads 4-bytes' do
|
20
25
|
str = 'spec_test'.encode('utf-16le')
|
21
26
|
packet.referent.read(str)
|
@@ -55,8 +60,8 @@ RSpec.describe RubySMB::Dcerpc::Winreg::OpenRootKeyRequest do
|
|
55
60
|
end
|
56
61
|
end
|
57
62
|
|
58
|
-
it 'sets #p_registry_server_name.referent to
|
59
|
-
expect(packet.p_registry_server_name
|
63
|
+
it 'sets #p_registry_server_name.referent to :null' do
|
64
|
+
expect(packet.p_registry_server_name).to eq(:null)
|
60
65
|
end
|
61
66
|
|
62
67
|
context 'when #opnum is not OPEN_HKPD, OPEN_HKPT or OPEN_HKPN' do
|
@@ -25,10 +25,6 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryInfoKeyRequest do
|
|
25
25
|
it 'is a RrpUnicodeString structure' do
|
26
26
|
expect(packet.lp_class).to be_a RubySMB::Dcerpc::RrpUnicodeString
|
27
27
|
end
|
28
|
-
|
29
|
-
it 'has an initial value of 0' do
|
30
|
-
expect(packet.lp_class).to eq(0)
|
31
|
-
end
|
32
28
|
end
|
33
29
|
|
34
30
|
describe '#initialize_instance' do
|
@@ -9,9 +9,10 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueRequest do
|
|
9
9
|
|
10
10
|
it { is_expected.to respond_to :hkey }
|
11
11
|
it { is_expected.to respond_to :lp_value_name }
|
12
|
-
it { is_expected.to respond_to :
|
12
|
+
it { is_expected.to respond_to :pad1 }
|
13
13
|
it { is_expected.to respond_to :lp_type }
|
14
14
|
it { is_expected.to respond_to :lp_data }
|
15
|
+
it { is_expected.to respond_to :pad2 }
|
15
16
|
it { is_expected.to respond_to :lpcb_data }
|
16
17
|
it { is_expected.to respond_to :lpcb_len }
|
17
18
|
it { is_expected.to respond_to :opnum }
|
@@ -32,9 +33,9 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueRequest do
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
describe '#
|
36
|
+
describe '#pad1' do
|
36
37
|
it 'is a string' do
|
37
|
-
expect(packet.
|
38
|
+
expect(packet.pad1).to be_a BinData::String
|
38
39
|
end
|
39
40
|
|
40
41
|
it 'should keep #lp_type 4-byte aligned' do
|
@@ -50,8 +51,8 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueRequest do
|
|
50
51
|
end
|
51
52
|
|
52
53
|
describe '#lp_data' do
|
53
|
-
it 'is a
|
54
|
-
expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::
|
54
|
+
it 'is a NdrLpByteArray structure' do
|
55
|
+
expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::NdrLpByteArray
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
@@ -61,6 +62,17 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueRequest do
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
65
|
+
describe '#pad2' do
|
66
|
+
it 'is a string' do
|
67
|
+
expect(packet.pad2).to be_a BinData::String
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should keep #lpcb_data 4-byte aligned' do
|
71
|
+
packet.lp_data = [1, 2]
|
72
|
+
expect(packet.lpcb_data.abs_offset % 4).to eq 0
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
64
76
|
describe '#lpcb_len' do
|
65
77
|
it 'is a NdrLpDword structure' do
|
66
78
|
expect(packet.lpcb_len).to be_a RubySMB::Dcerpc::Ndr::NdrLpDword
|
@@ -72,17 +84,5 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueRequest do
|
|
72
84
|
expect(packet.opnum).to eq(RubySMB::Dcerpc::Winreg::REG_QUERY_VALUE)
|
73
85
|
end
|
74
86
|
end
|
75
|
-
|
76
|
-
describe '#pad_length' do
|
77
|
-
it 'returns 0 when #lp_type is already 4-byte aligned' do
|
78
|
-
packet.lp_value_name = 'align'
|
79
|
-
expect(packet.pad_length).to eq 0
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'returns 2 when #lp_type is only 2-byte aligned' do
|
83
|
-
packet.lp_value_name = 'align' + 'A'
|
84
|
-
expect(packet.pad_length).to eq 2
|
85
|
-
end
|
86
|
-
end
|
87
87
|
end
|
88
88
|
|
@@ -20,8 +20,8 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueResponse do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#lp_data' do
|
23
|
-
it 'is a
|
24
|
-
expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::
|
23
|
+
it 'is a NdrLpByteArray structure' do
|
24
|
+
expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::NdrLpByteArray
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -31,7 +31,7 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueResponse do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should keep #lpcb_data 4-byte aligned' do
|
34
|
-
packet.lp_data
|
34
|
+
packet.lp_data = 'spec_test'.bytes
|
35
35
|
expect(packet.lpcb_data.abs_offset % 4).to eq 0
|
36
36
|
end
|
37
37
|
end
|
@@ -60,24 +60,12 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueResponse do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
describe '#pad_length' do
|
64
|
-
it 'returns 0 when #lpcb_data is already 4-byte aligned' do
|
65
|
-
packet.lp_data.bytes = 'aligned.'.bytes
|
66
|
-
expect(packet.pad_length).to eq 0
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'returns 2 when #lpcb_data is only 2-byte aligned' do
|
70
|
-
packet.lp_data.bytes = 'not aligned'.bytes
|
71
|
-
expect(packet.pad_length).to eq 1
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
63
|
describe '#data' do
|
76
64
|
context 'when #lp_type is 1 (unicode null-terminated string)' do
|
77
65
|
it 'returns the expected value' do
|
78
66
|
str = 'spec test string'.encode('utf-16le')
|
79
67
|
packet.lp_type = 1
|
80
|
-
packet.lp_data
|
68
|
+
packet.lp_data = str.bytes
|
81
69
|
expect(packet.data).to eq(str)
|
82
70
|
end
|
83
71
|
end
|
@@ -86,7 +74,7 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueResponse do
|
|
86
74
|
it 'returns the expected value' do
|
87
75
|
str = '/%PATH%/foo'.encode('utf-16le')
|
88
76
|
packet.lp_type = 2
|
89
|
-
packet.lp_data
|
77
|
+
packet.lp_data = str.bytes
|
90
78
|
expect(packet.data).to eq(str)
|
91
79
|
end
|
92
80
|
end
|
@@ -95,7 +83,7 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueResponse do
|
|
95
83
|
it 'returns the expected value' do
|
96
84
|
bytes = [0xFF, 0xEE, 0xDD, 0xCC].pack('C*')
|
97
85
|
packet.lp_type = 3
|
98
|
-
packet.lp_data
|
86
|
+
packet.lp_data = bytes.bytes
|
99
87
|
expect(packet.data).to eq(bytes)
|
100
88
|
end
|
101
89
|
end
|
@@ -104,7 +92,7 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueResponse do
|
|
104
92
|
it 'returns the expected value' do
|
105
93
|
number = 12345
|
106
94
|
packet.lp_type = 4
|
107
|
-
packet.lp_data
|
95
|
+
packet.lp_data = [number].pack('V').bytes
|
108
96
|
expect(packet.data).to eq(number)
|
109
97
|
end
|
110
98
|
end
|
@@ -113,7 +101,7 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueResponse do
|
|
113
101
|
it 'returns the expected value' do
|
114
102
|
number = 12345
|
115
103
|
packet.lp_type = 5
|
116
|
-
packet.lp_data
|
104
|
+
packet.lp_data = [number].pack('N').bytes
|
117
105
|
expect(packet.data).to eq(number)
|
118
106
|
end
|
119
107
|
end
|
@@ -124,7 +112,7 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueResponse do
|
|
124
112
|
null_byte = "\0".encode('utf-16le')
|
125
113
|
str = (str_array + [null_byte]).join(null_byte)
|
126
114
|
packet.lp_type = 7
|
127
|
-
packet.lp_data
|
115
|
+
packet.lp_data = str.bytes
|
128
116
|
expect(packet.data).to eq(str_array)
|
129
117
|
end
|
130
118
|
end
|
@@ -133,7 +121,7 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueResponse do
|
|
133
121
|
it 'returns the expected value' do
|
134
122
|
number = 0x1234567812345678
|
135
123
|
packet.lp_type = 11
|
136
|
-
packet.lp_data
|
124
|
+
packet.lp_data = [number].pack('Q<').bytes
|
137
125
|
expect(packet.data).to eq(number)
|
138
126
|
end
|
139
127
|
end
|
@@ -142,7 +130,7 @@ RSpec.describe RubySMB::Dcerpc::Winreg::QueryValueResponse do
|
|
142
130
|
it 'returns an empty string' do
|
143
131
|
str = 'test'
|
144
132
|
packet.lp_type = 6
|
145
|
-
packet.lp_data
|
133
|
+
packet.lp_data = str.bytes
|
146
134
|
expect(packet.data).to eq('')
|
147
135
|
end
|
148
136
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
RSpec.describe RubySMB::Dcerpc::Winreg::RpcHkey do
|
2
|
+
subject(:packet) { described_class.new }
|
3
|
+
|
4
|
+
it 'is NdrContextHandle subclass' do
|
5
|
+
expect(described_class).to be < RubySMB::Dcerpc::Ndr::NdrContextHandle
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.describe RubySMB::Dcerpc::Winreg::SaveKeyRequest do
|
10
|
+
subject(:packet) { described_class.new }
|
11
|
+
|
12
|
+
|
13
|
+
it 'is little endian' do
|
14
|
+
expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
|
15
|
+
end
|
16
|
+
|
17
|
+
it { is_expected.to respond_to :hkey }
|
18
|
+
it { is_expected.to respond_to :lp_file }
|
19
|
+
it { is_expected.to respond_to :pad }
|
20
|
+
it { is_expected.to respond_to :lp_security_attributes }
|
21
|
+
|
22
|
+
describe '#hkey' do
|
23
|
+
it 'is a RpcHkey structure' do
|
24
|
+
expect(packet.hkey).to be_a RubySMB::Dcerpc::Winreg::RpcHkey
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#lp_file' do
|
29
|
+
it 'is a RrpUnicodeString structure' do
|
30
|
+
expect(packet.lp_file).to be_a RubySMB::Dcerpc::RrpUnicodeString
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#pad' do
|
35
|
+
it 'is a string' do
|
36
|
+
expect(packet.pad).to be_a BinData::String
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should keep #lp_security_attributes 4-byte aligned' do
|
40
|
+
packet.lp_file = "test"
|
41
|
+
expect(packet.lp_security_attributes.abs_offset % 4).to eq 0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#lp_security_attributes' do
|
46
|
+
it 'is a PrpcSecurityAttributes structure' do
|
47
|
+
expect(packet.lp_security_attributes).to be_a RubySMB::Dcerpc::PrpcSecurityAttributes
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#initialize_instance' do
|
52
|
+
it 'sets #opnum to REG_SAVE_KEY constant' do
|
53
|
+
expect(packet.opnum).to eq(RubySMB::Dcerpc::Winreg::REG_SAVE_KEY)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|