ruby_smb 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/examples/anonymous_auth.rb +3 -3
  5. data/examples/append_file.rb +10 -8
  6. data/examples/authenticate.rb +9 -5
  7. data/examples/delete_file.rb +8 -6
  8. data/examples/enum_registry_key.rb +5 -4
  9. data/examples/enum_registry_values.rb +5 -4
  10. data/examples/list_directory.rb +8 -6
  11. data/examples/negotiate_with_netbios_service.rb +9 -5
  12. data/examples/net_share_enum_all.rb +6 -4
  13. data/examples/pipes.rb +11 -12
  14. data/examples/query_service_status.rb +64 -0
  15. data/examples/read_file.rb +8 -6
  16. data/examples/read_registry_key_value.rb +6 -5
  17. data/examples/rename_file.rb +9 -7
  18. data/examples/tree_connect.rb +7 -5
  19. data/examples/write_file.rb +9 -7
  20. data/lib/ruby_smb/client.rb +72 -43
  21. data/lib/ruby_smb/client/negotiation.rb +1 -0
  22. data/lib/ruby_smb/dcerpc.rb +2 -0
  23. data/lib/ruby_smb/dcerpc/error.rb +3 -0
  24. data/lib/ruby_smb/dcerpc/ndr.rb +209 -44
  25. data/lib/ruby_smb/dcerpc/request.rb +13 -0
  26. data/lib/ruby_smb/dcerpc/rpc_security_attributes.rb +34 -0
  27. data/lib/ruby_smb/dcerpc/rrp_unicode_string.rb +9 -6
  28. data/lib/ruby_smb/dcerpc/svcctl.rb +479 -0
  29. data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request.rb +48 -0
  30. data/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response.rb +26 -0
  31. data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_request.rb +25 -0
  32. data/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response.rb +26 -0
  33. data/lib/ruby_smb/dcerpc/svcctl/control_service_request.rb +26 -0
  34. data/lib/ruby_smb/dcerpc/svcctl/control_service_response.rb +26 -0
  35. data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request.rb +35 -0
  36. data/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response.rb +23 -0
  37. data/lib/ruby_smb/dcerpc/svcctl/open_service_w_request.rb +31 -0
  38. data/lib/ruby_smb/dcerpc/svcctl/open_service_w_response.rb +23 -0
  39. data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request.rb +25 -0
  40. data/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response.rb +44 -0
  41. data/lib/ruby_smb/dcerpc/svcctl/query_service_status_request.rb +23 -0
  42. data/lib/ruby_smb/dcerpc/svcctl/query_service_status_response.rb +27 -0
  43. data/lib/ruby_smb/dcerpc/svcctl/service_status.rb +25 -0
  44. data/lib/ruby_smb/dcerpc/svcctl/start_service_w_request.rb +27 -0
  45. data/lib/ruby_smb/dcerpc/svcctl/start_service_w_response.rb +25 -0
  46. data/lib/ruby_smb/dcerpc/winreg.rb +98 -17
  47. data/lib/ruby_smb/dcerpc/winreg/create_key_request.rb +73 -0
  48. data/lib/ruby_smb/dcerpc/winreg/create_key_response.rb +36 -0
  49. data/lib/ruby_smb/dcerpc/winreg/enum_key_request.rb +1 -1
  50. data/lib/ruby_smb/dcerpc/winreg/enum_value_request.rb +1 -1
  51. data/lib/ruby_smb/dcerpc/winreg/enum_value_response.rb +1 -1
  52. data/lib/ruby_smb/dcerpc/winreg/open_root_key_request.rb +4 -4
  53. data/lib/ruby_smb/dcerpc/winreg/query_info_key_request.rb +1 -1
  54. data/lib/ruby_smb/dcerpc/winreg/query_value_request.rb +7 -6
  55. data/lib/ruby_smb/dcerpc/winreg/query_value_response.rb +10 -10
  56. data/lib/ruby_smb/dcerpc/winreg/save_key_request.rb +37 -0
  57. data/lib/ruby_smb/dcerpc/winreg/save_key_response.rb +23 -0
  58. data/lib/ruby_smb/dispatcher/base.rb +1 -1
  59. data/lib/ruby_smb/dispatcher/socket.rb +1 -1
  60. data/lib/ruby_smb/field/stringz16.rb +17 -1
  61. data/lib/ruby_smb/nbss/session_header.rb +4 -4
  62. data/lib/ruby_smb/smb1/file.rb +2 -10
  63. data/lib/ruby_smb/smb1/pipe.rb +2 -0
  64. data/lib/ruby_smb/smb2/file.rb +25 -17
  65. data/lib/ruby_smb/smb2/pipe.rb +3 -0
  66. data/lib/ruby_smb/smb2/tree.rb +9 -3
  67. data/lib/ruby_smb/version.rb +1 -1
  68. data/spec/lib/ruby_smb/client_spec.rb +161 -60
  69. data/spec/lib/ruby_smb/dcerpc/ndr_spec.rb +1396 -77
  70. data/spec/lib/ruby_smb/dcerpc/rpc_security_attributes_spec.rb +161 -0
  71. data/spec/lib/ruby_smb/dcerpc/rrp_unicode_string_spec.rb +49 -12
  72. data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_request_spec.rb +191 -0
  73. data/spec/lib/ruby_smb/dcerpc/svcctl/change_service_config_w_response_spec.rb +38 -0
  74. data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_request_spec.rb +30 -0
  75. data/spec/lib/ruby_smb/dcerpc/svcctl/close_service_handle_response_spec.rb +38 -0
  76. data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_request_spec.rb +39 -0
  77. data/spec/lib/ruby_smb/dcerpc/svcctl/control_service_response_spec.rb +38 -0
  78. data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_request_spec.rb +78 -0
  79. data/spec/lib/ruby_smb/dcerpc/svcctl/open_sc_manager_w_response_spec.rb +38 -0
  80. data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_request_spec.rb +59 -0
  81. data/spec/lib/ruby_smb/dcerpc/svcctl/open_service_w_response_spec.rb +38 -0
  82. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_request_spec.rb +38 -0
  83. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_config_w_response_spec.rb +152 -0
  84. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_request_spec.rb +30 -0
  85. data/spec/lib/ruby_smb/dcerpc/svcctl/query_service_status_response_spec.rb +38 -0
  86. data/spec/lib/ruby_smb/dcerpc/svcctl/service_status_spec.rb +72 -0
  87. data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_request_spec.rb +46 -0
  88. data/spec/lib/ruby_smb/dcerpc/svcctl/start_service_w_response_spec.rb +30 -0
  89. data/spec/lib/ruby_smb/dcerpc/svcctl_spec.rb +512 -0
  90. data/spec/lib/ruby_smb/dcerpc/winreg/create_key_request_spec.rb +110 -0
  91. data/spec/lib/ruby_smb/dcerpc/winreg/create_key_response_spec.rb +44 -0
  92. data/spec/lib/ruby_smb/dcerpc/winreg/enum_key_request_spec.rb +0 -4
  93. data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_request_spec.rb +2 -2
  94. data/spec/lib/ruby_smb/dcerpc/winreg/enum_value_response_spec.rb +2 -2
  95. data/spec/lib/ruby_smb/dcerpc/winreg/open_root_key_request_spec.rb +9 -4
  96. data/spec/lib/ruby_smb/dcerpc/winreg/query_info_key_request_spec.rb +0 -4
  97. data/spec/lib/ruby_smb/dcerpc/winreg/query_value_request_spec.rb +17 -17
  98. data/spec/lib/ruby_smb/dcerpc/winreg/query_value_response_spec.rb +11 -23
  99. data/spec/lib/ruby_smb/dcerpc/winreg/save_key_request_spec.rb +57 -0
  100. data/spec/lib/ruby_smb/dcerpc/winreg/save_key_response_spec.rb +22 -0
  101. data/spec/lib/ruby_smb/dcerpc/winreg_spec.rb +215 -41
  102. data/spec/lib/ruby_smb/dispatcher/socket_spec.rb +10 -10
  103. data/spec/lib/ruby_smb/field/stringz16_spec.rb +12 -0
  104. data/spec/lib/ruby_smb/nbss/session_header_spec.rb +4 -11
  105. data/spec/lib/ruby_smb/smb1/pipe_spec.rb +7 -0
  106. data/spec/lib/ruby_smb/smb2/file_spec.rb +60 -6
  107. data/spec/lib/ruby_smb/smb2/pipe_spec.rb +7 -0
  108. data/spec/lib/ruby_smb/smb2/tree_spec.rb +35 -1
  109. metadata +72 -2
  110. metadata.gz.sig +0 -0
@@ -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 NdrLpByte structure' do
61
- expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::NdrLpByte
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 NdrLpByte structure' do
42
- expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::NdrLpByte
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 NdrTopLevelFullPointer subclass' do
3
- expect(described_class).to be < RubySMB::Dcerpc::Ndr::NdrTopLevelFullPointer
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 NULL unicode value' do
59
- expect(packet.p_registry_server_name.referent).to eq("\0\0".encode('utf-16le'))
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 :pad }
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 '#pad' do
36
+ describe '#pad1' do
36
37
  it 'is a string' do
37
- expect(packet.pad).to be_a BinData::String
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 NdrLpByte structure' do
54
- expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::NdrLpByte
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 NdrLpByte structure' do
24
- expect(packet.lp_data).to be_a RubySMB::Dcerpc::Ndr::NdrLpByte
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.bytes = 'spec_test'.bytes
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.bytes = str.bytes
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.bytes = str.bytes
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.bytes = bytes.bytes
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.bytes = [number].pack('V').bytes
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.bytes = [number].pack('N').bytes
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.bytes = str.bytes
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.bytes = [number].pack('Q<').bytes
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.bytes = str.bytes
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
+