ruby_smb 3.1.3 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/ruby_smb/client/authentication.rb +29 -4
  4. data/lib/ruby_smb/client/negotiation.rb +2 -0
  5. data/lib/ruby_smb/client.rb +16 -1
  6. data/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_request.rb +24 -0
  7. data/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_response.rb +21 -0
  8. data/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_request.rb +23 -0
  9. data/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_response.rb +21 -0
  10. data/lib/ruby_smb/dcerpc/dfsnm.rb +84 -0
  11. data/lib/ruby_smb/dcerpc/error.rb +24 -0
  12. data/lib/ruby_smb/dcerpc/fault.rb +83 -0
  13. data/lib/ruby_smb/dcerpc/ndr.rb +19 -8
  14. data/lib/ruby_smb/dcerpc/request.rb +21 -11
  15. data/lib/ruby_smb/dcerpc/rrp_rpc_unicode_string.rb +5 -0
  16. data/lib/ruby_smb/dcerpc/samr/samr_create_user2_in_domain_request.rb +24 -0
  17. data/lib/ruby_smb/dcerpc/samr/samr_create_user2_in_domain_response.rb +24 -0
  18. data/lib/ruby_smb/dcerpc/samr/samr_delete_user_request.rb +21 -0
  19. data/lib/ruby_smb/dcerpc/samr/samr_delete_user_response.rb +22 -0
  20. data/lib/ruby_smb/dcerpc/samr/samr_enumerate_domains_in_sam_server_request.rb +25 -0
  21. data/lib/ruby_smb/dcerpc/samr/samr_enumerate_domains_in_sam_server_response.rb +25 -0
  22. data/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_response.rb +0 -31
  23. data/lib/ruby_smb/dcerpc/samr/samr_get_alias_membership_response.rb +1 -14
  24. data/lib/ruby_smb/dcerpc/samr/samr_lookup_names_in_domain_request.rb +23 -0
  25. data/lib/ruby_smb/dcerpc/samr/samr_lookup_names_in_domain_response.rb +23 -0
  26. data/lib/ruby_smb/dcerpc/samr/samr_set_information_user2_request.rb +23 -0
  27. data/lib/ruby_smb/dcerpc/samr/samr_set_information_user2_response.rb +21 -0
  28. data/lib/ruby_smb/dcerpc/samr.rb +453 -83
  29. data/lib/ruby_smb/dcerpc.rb +2 -0
  30. data/lib/ruby_smb/error.rb +25 -11
  31. data/lib/ruby_smb/gss.rb +1 -0
  32. data/lib/ruby_smb/smb1/packet/session_setup_request.rb +11 -0
  33. data/lib/ruby_smb/smb1/pipe.rb +6 -1
  34. data/lib/ruby_smb/smb2/pipe.rb +6 -2
  35. data/lib/ruby_smb/version.rb +1 -1
  36. data/spec/lib/ruby_smb/client_spec.rb +1 -0
  37. data/spec/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_request_spec.rb +57 -0
  38. data/spec/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_add_std_root_response_spec.rb +34 -0
  39. data/spec/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_request_spec.rb +49 -0
  40. data/spec/lib/ruby_smb/dcerpc/dfsnm/netr_dfs_remove_std_root_response_spec.rb +34 -0
  41. data/spec/lib/ruby_smb/dcerpc/samr/samr_create_user2_in_domain_request_spec.rb +69 -0
  42. data/spec/lib/ruby_smb/dcerpc/samr/samr_create_user2_in_domain_response_spec.rb +69 -0
  43. data/spec/lib/ruby_smb/dcerpc/samr/samr_delete_user_request_spec.rb +42 -0
  44. data/spec/lib/ruby_smb/dcerpc/samr/samr_delete_user_response_spec.rb +51 -0
  45. data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_domains_in_sam_server_request_spec.rb +60 -0
  46. data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_domains_in_sam_server_response_spec.rb +75 -0
  47. data/spec/lib/ruby_smb/dcerpc/samr/samr_enumerate_users_in_domain_response_spec.rb +0 -195
  48. data/spec/lib/ruby_smb/dcerpc/samr/samr_lookup_names_in_domain_request_spec.rb +62 -0
  49. data/spec/lib/ruby_smb/dcerpc/samr/samr_lookup_names_in_domain_response_spec.rb +54 -0
  50. data/spec/lib/ruby_smb/dcerpc/samr/samr_set_information_user2_request_spec.rb +67 -0
  51. data/spec/lib/ruby_smb/dcerpc/samr/samr_set_information_user2_response_spec.rb +35 -0
  52. data/spec/lib/ruby_smb/dcerpc/samr_spec.rb +194 -0
  53. data.tar.gz.sig +2 -2
  54. metadata +46 -2
  55. metadata.gz.sig +0 -0
@@ -1,197 +1,3 @@
1
- RSpec.describe RubySMB::Dcerpc::Samr::SamprRidEnumeration do
2
- subject(:packet) { described_class.new }
3
-
4
- it { is_expected.to respond_to :relative_id }
5
- it { is_expected.to respond_to :name }
6
-
7
- it 'is little endian' do
8
- expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
9
- end
10
- it 'is a Ndr::NdrStruct' do
11
- expect(packet).to be_a(RubySMB::Dcerpc::Ndr::NdrStruct)
12
- end
13
- it 'is four-byte aligned' do
14
- expect(packet.eval_parameter(:byte_align)).to eq(4)
15
- end
16
- describe '#relative_id' do
17
- it 'is a NdrUint32 structure' do
18
- expect(packet.relative_id).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
19
- end
20
- end
21
- describe '#name' do
22
- it 'is a RpcUnicodeString structure' do
23
- expect(packet.name).to be_a RubySMB::Dcerpc::RpcUnicodeString
24
- end
25
- end
26
- it 'reads itself' do
27
- new_packet = described_class.new(relative_id: 4, name: 'Test String')
28
- expected_output = {
29
- relative_id: 4,
30
- name: {
31
- buffer_length: 22,
32
- maximum_length: 22,
33
- buffer: "Test String".encode('utf-16le')
34
- }
35
- }
36
- expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
37
- end
38
- end
39
-
40
- RSpec.describe RubySMB::Dcerpc::Samr::SamprRidEnumerationArray do
41
- subject(:packet) { described_class.new }
42
-
43
- it 'is a Ndr::NdrConfArray' do
44
- expect(packet).to be_a(RubySMB::Dcerpc::Ndr::NdrConfArray)
45
- end
46
- it 'has element of type SamprRidEnumeration' do
47
- packet << {relative_id: 4, name: ''}
48
- expect(packet[0]).to be_a(RubySMB::Dcerpc::Samr::SamprRidEnumeration)
49
- end
50
- it 'reads itself' do
51
- new_packet = described_class.new([
52
- {relative_id: 4, name: 'Test1'},
53
- {relative_id: 1, name: 'Test2'}
54
- ])
55
- expected_output = [
56
- {
57
- relative_id: 4,
58
- name: {
59
- buffer_length: 10,
60
- maximum_length: 10,
61
- buffer: "Test1".encode('utf-16le')
62
- }
63
- },
64
- {
65
- relative_id: 1,
66
- name: {
67
- buffer_length: 10,
68
- maximum_length: 10,
69
- buffer: "Test2".encode('utf-16le')
70
- }
71
- }]
72
- expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
73
- end
74
- end
75
-
76
- RSpec.describe RubySMB::Dcerpc::Samr::PsamprRidEnumerationArray do
77
- subject(:packet) { described_class.new }
78
-
79
- it 'is a SamprRidEnumerationArray' do
80
- expect(packet).to be_a(RubySMB::Dcerpc::Samr::SamprRidEnumerationArray)
81
- end
82
- it 'is a NdrPointer' do
83
- expect(described_class).to be_a(RubySMB::Dcerpc::Ndr::PointerClassPlugin)
84
- expect(packet).to be_a(RubySMB::Dcerpc::Ndr::PointerPlugin)
85
- end
86
- it 'is four-byte aligned' do
87
- expect(packet.eval_parameter(:byte_align)).to eq(4)
88
- end
89
- it 'reads itself' do
90
- new_packet = described_class.new([
91
- {relative_id: 4, name: 'Test1'},
92
- {relative_id: 1, name: 'Test2'}
93
- ])
94
- expected_output = [
95
- {
96
- relative_id: 4,
97
- name: {
98
- buffer_length: 10,
99
- maximum_length: 10,
100
- buffer: "Test1".encode('utf-16le')
101
- }
102
- },
103
- {
104
- relative_id: 1,
105
- name: {
106
- buffer_length: 10,
107
- maximum_length: 10,
108
- buffer: "Test2".encode('utf-16le')
109
- }
110
- }]
111
- expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
112
- end
113
- end
114
-
115
- RSpec.describe RubySMB::Dcerpc::Samr::SamprEnumerationBuffer do
116
- subject(:packet) { described_class.new }
117
-
118
- it { is_expected.to respond_to :entries_read }
119
- it { is_expected.to respond_to :buffer }
120
-
121
- it 'is little endian' do
122
- expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
123
- end
124
- it 'is a Ndr::NdrStruct' do
125
- expect(packet).to be_a(RubySMB::Dcerpc::Ndr::NdrStruct)
126
- end
127
- it 'is four-byte aligned' do
128
- expect(packet.eval_parameter(:byte_align)).to eq(4)
129
- end
130
- describe '#entries_read' do
131
- it 'is a NdrUint32 structure' do
132
- expect(packet.entries_read).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
133
- end
134
- end
135
- describe '#buffer' do
136
- it 'is a PsamprRidEnumerationArray structure' do
137
- expect(packet.buffer).to be_a RubySMB::Dcerpc::Samr::PsamprRidEnumerationArray
138
- end
139
- end
140
- it 'reads itself' do
141
- new_packet = described_class.new(
142
- entries_read: 3,
143
- buffer: [
144
- { relative_id: 500, name: "Administrator" },
145
- { relative_id: 501, name: "Guest" },
146
- { relative_id: 1001, name: "WIN-DP0M1BC768$" }
147
- ]
148
- )
149
- expected_output = {
150
- entries_read: 3,
151
- buffer: [
152
- {relative_id: 500, name: { buffer_length: 26, maximum_length: 26, buffer: "Administrator".encode('utf-16le') }},
153
- {relative_id: 501, name: { buffer_length: 10, maximum_length: 10, buffer: "Guest".encode('utf-16le') }},
154
- {relative_id: 1001, name: { buffer_length: 30, maximum_length: 30, buffer: "WIN-DP0M1BC768$".encode('utf-16le') }}
155
- ]
156
- }
157
- expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
158
- end
159
- end
160
-
161
- RSpec.describe RubySMB::Dcerpc::Samr::PsamprEnumerationBuffer do
162
- subject(:packet) { described_class.new }
163
-
164
- it 'is a SamprEnumerationBuffer' do
165
- expect(packet).to be_a(RubySMB::Dcerpc::Samr::SamprEnumerationBuffer)
166
- end
167
- it 'is a NdrPointer' do
168
- expect(described_class).to be_a(RubySMB::Dcerpc::Ndr::PointerClassPlugin)
169
- expect(packet).to be_a(RubySMB::Dcerpc::Ndr::PointerPlugin)
170
- end
171
- it 'is four-byte aligned' do
172
- expect(packet.eval_parameter(:byte_align)).to eq(4)
173
- end
174
- it 'reads itself' do
175
- new_packet = described_class.new(
176
- entries_read: 3,
177
- buffer: [
178
- { relative_id: 500, name: "Administrator" },
179
- { relative_id: 501, name: "Guest" },
180
- { relative_id: 1001, name: "WIN-DP0M1BC768$" }
181
- ]
182
- )
183
- expected_output = {
184
- entries_read: 3,
185
- buffer: [
186
- {relative_id: 500, name: { buffer_length: 26, maximum_length: 26, buffer: "Administrator".encode('utf-16le') }},
187
- {relative_id: 501, name: { buffer_length: 10, maximum_length: 10, buffer: "Guest".encode('utf-16le') }},
188
- {relative_id: 1001, name: { buffer_length: 30, maximum_length: 30, buffer: "WIN-DP0M1BC768$".encode('utf-16le') }}
189
- ]
190
- }
191
- expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
192
- end
193
- end
194
-
195
1
  RSpec.describe RubySMB::Dcerpc::Samr::SamrEnumerateUsersInDomainResponse do
196
2
  subject(:packet) { described_class.new }
197
3
 
@@ -262,4 +68,3 @@ RSpec.describe RubySMB::Dcerpc::Samr::SamrEnumerateUsersInDomainResponse do
262
68
  expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
263
69
  end
264
70
  end
265
-
@@ -0,0 +1,62 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrLookupNamesInDomainRequest do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :domain_handle }
5
+ it { is_expected.to respond_to :names_count }
6
+ it { is_expected.to respond_to :names }
7
+ it { is_expected.to respond_to :opnum }
8
+
9
+ it 'is little endian' do
10
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
11
+ end
12
+
13
+ it 'is a BinData::Record' do
14
+ expect(packet).to be_a(BinData::Record)
15
+ end
16
+
17
+ describe '#domain_handle' do
18
+ it 'is a SamprHandle structure' do
19
+ expect(packet.domain_handle).to be_a RubySMB::Dcerpc::Samr::SamprHandle
20
+ end
21
+ end
22
+
23
+ describe '#names_count' do
24
+ it 'is a NdrUint32 structure' do
25
+ expect(packet.names_count).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
26
+ end
27
+ end
28
+
29
+ describe '#names' do
30
+ it 'is a RpcUnicodeStringConfVarArray structure' do
31
+ expect(packet.names).to be_a RubySMB::Dcerpc::RpcUnicodeStringConfVarArray
32
+ end
33
+ end
34
+
35
+ describe '#initialize_instance' do
36
+ it 'sets #opnum to SAMR_LOOKUP_NAMES_IN_DOMAIN constant' do
37
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_LOOKUP_NAMES_IN_DOMAIN)
38
+ end
39
+ end
40
+
41
+ it 'reads itself' do
42
+ new_packet = described_class.new({
43
+ domain_handle: {
44
+ context_handle_attributes: 0,
45
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
46
+ },
47
+ names_count: 1,
48
+ names: [ 'TEST' ]
49
+ })
50
+ expected_output = {
51
+ domain_handle: {
52
+ context_handle_attributes: 0,
53
+ context_handle_uuid: "fc873b90-d9a9-46a4-b9ea-f44bb1c272a7"
54
+ },
55
+ names_count: 1,
56
+ names: [
57
+ { buffer_length: 8, maximum_length: 8, buffer: "TEST".encode('utf-16le') }
58
+ ]
59
+ }
60
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
61
+ end
62
+ end
@@ -0,0 +1,54 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrLookupNamesInDomainResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :relative_ids }
5
+ it { is_expected.to respond_to :use }
6
+ it { is_expected.to respond_to :error_status }
7
+ it { is_expected.to respond_to :opnum }
8
+
9
+ it 'is little endian' do
10
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
11
+ end
12
+
13
+ it 'is a BinData::Record' do
14
+ expect(packet).to be_a(BinData::Record)
15
+ end
16
+
17
+ describe '#relative_ids' do
18
+ it 'is a SamprHandle structure' do
19
+ expect(packet.relative_ids).to be_a RubySMB::Dcerpc::Samr::SamprUlongArray
20
+ end
21
+ end
22
+
23
+ describe '#use' do
24
+ it 'is a SamprHandle structure' do
25
+ expect(packet.use).to be_a RubySMB::Dcerpc::Samr::SamprUlongArray
26
+ end
27
+ end
28
+
29
+ describe '#error_status' do
30
+ it 'is a NdrUint32 structure' do
31
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
32
+ end
33
+ end
34
+
35
+ describe '#initialize_instance' do
36
+ it 'sets #opnum to SAMR_LOOKUP_NAMES_IN_DOMAIN constant' do
37
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_LOOKUP_NAMES_IN_DOMAIN)
38
+ end
39
+ end
40
+
41
+ it 'reads itself' do
42
+ new_packet = described_class.new({
43
+ relative_ids: { element_count: 2, elements: [ 500, 501 ] },
44
+ use: { element_count: 2, elements: [ 1, 2 ] },
45
+ error_status: 0x11223344
46
+ })
47
+ expected_output = {
48
+ relative_ids: { element_count: 2, elements: [ 500, 501 ] },
49
+ use: { element_count: 2, elements: [ 1, 2 ] },
50
+ error_status: 0x11223344
51
+ }
52
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
53
+ end
54
+ end
@@ -0,0 +1,67 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrSetInformationUser2Request do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :user_handle }
5
+ it { is_expected.to respond_to :user_information_class }
6
+ it { is_expected.to respond_to :buffer }
7
+ it { is_expected.to respond_to :opnum }
8
+
9
+ it 'is little endian' do
10
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
11
+ end
12
+
13
+ it 'is a BinData::Record' do
14
+ expect(packet).to be_a(BinData::Record)
15
+ end
16
+
17
+ describe '#user_handle' do
18
+ it 'is a SamprHandle structure' do
19
+ expect(packet.user_handle).to be_a RubySMB::Dcerpc::Samr::SamprHandle
20
+ end
21
+ end
22
+
23
+ describe '#user_information_class' do
24
+ it 'is a NdrUint16 structure' do
25
+ expect(packet.user_information_class).to be_a RubySMB::Dcerpc::Ndr::NdrUint16
26
+ end
27
+ end
28
+
29
+ describe '#buffer' do
30
+ it 'is a SamprUserInfoBuffer structure' do
31
+ expect(packet.buffer).to be_a RubySMB::Dcerpc::Samr::SamprUserInfoBuffer
32
+ end
33
+ end
34
+
35
+ describe '#initialize_instance' do
36
+ it 'sets #opnum to SAMR_SET_INFORMATION_USER2 constant' do
37
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_SET_INFORMATION_USER2)
38
+ end
39
+ end
40
+
41
+ it 'reads itself' do
42
+ new_class = described_class.new(
43
+ user_handle: {
44
+ context_handle_attributes: 0,
45
+ context_handle_uuid: '2ef54a87-e29e-4d24-90e9-9da49b94449e'
46
+ },
47
+ user_information_class: RubySMB::Dcerpc::Samr::USER_CONTROL_INFORMATION,
48
+ buffer: {
49
+ tag: RubySMB::Dcerpc::Samr::USER_CONTROL_INFORMATION,
50
+ member: { user_account_control: RubySMB::Dcerpc::Samr::USER_WORKSTATION_TRUST_ACCOUNT }
51
+ }
52
+ )
53
+ expect(packet.read(new_class.to_binary_s)).to eq(
54
+ {
55
+ user_handle: {
56
+ context_handle_attributes: 0,
57
+ context_handle_uuid: '2ef54a87-e29e-4d24-90e9-9da49b94449e'
58
+ },
59
+ user_information_class: RubySMB::Dcerpc::Samr::USER_CONTROL_INFORMATION,
60
+ buffer: {
61
+ tag: RubySMB::Dcerpc::Samr::USER_CONTROL_INFORMATION,
62
+ member: { user_account_control: RubySMB::Dcerpc::Samr::USER_WORKSTATION_TRUST_ACCOUNT }
63
+ }
64
+ }
65
+ )
66
+ end
67
+ end
@@ -0,0 +1,35 @@
1
+ RSpec.describe RubySMB::Dcerpc::Samr::SamrSetInformationUser2Response do
2
+ subject(:packet) { described_class.new }
3
+
4
+ it { is_expected.to respond_to :error_status }
5
+ it { is_expected.to respond_to :opnum }
6
+
7
+ it 'is little endian' do
8
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
9
+ end
10
+
11
+ it 'is a BinData::Record' do
12
+ expect(packet).to be_a(BinData::Record)
13
+ end
14
+
15
+ describe '#error_status' do
16
+ it 'is a NdrUint32 structure' do
17
+ expect(packet.error_status).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
18
+ end
19
+ end
20
+
21
+ describe '#initialize_instance' do
22
+ it 'sets #opnum to SAMR_SET_INFORMATION_USER2 constant' do
23
+ expect(packet.opnum).to eq(RubySMB::Dcerpc::Samr::SAMR_SET_INFORMATION_USER2)
24
+ end
25
+ end
26
+
27
+ it 'reads itself' do
28
+ new_class = described_class.new(error_status: 0x11223344)
29
+ expect(packet.read(new_class.to_binary_s)).to eq(
30
+ {
31
+ error_status: 0x11223344
32
+ }
33
+ )
34
+ end
35
+ end
@@ -7,6 +7,200 @@ RSpec.describe RubySMB::Dcerpc::Samr do
7
7
  )
8
8
  end
9
9
 
10
+ describe described_class::SamprRidEnumeration do
11
+ subject(:packet) { described_class.new }
12
+
13
+ it { is_expected.to respond_to :relative_id }
14
+ it { is_expected.to respond_to :name }
15
+
16
+ it 'is little endian' do
17
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
18
+ end
19
+ it 'is a Ndr::NdrStruct' do
20
+ expect(packet).to be_a(RubySMB::Dcerpc::Ndr::NdrStruct)
21
+ end
22
+ it 'is four-byte aligned' do
23
+ expect(packet.eval_parameter(:byte_align)).to eq(4)
24
+ end
25
+ describe '#relative_id' do
26
+ it 'is a NdrUint32 structure' do
27
+ expect(packet.relative_id).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
28
+ end
29
+ end
30
+ describe '#name' do
31
+ it 'is a RpcUnicodeString structure' do
32
+ expect(packet.name).to be_a RubySMB::Dcerpc::RpcUnicodeString
33
+ end
34
+ end
35
+ it 'reads itself' do
36
+ new_packet = described_class.new(relative_id: 4, name: 'Test String')
37
+ expected_output = {
38
+ relative_id: 4,
39
+ name: {
40
+ buffer_length: 22,
41
+ maximum_length: 22,
42
+ buffer: "Test String".encode('utf-16le')
43
+ }
44
+ }
45
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
46
+ end
47
+ end
48
+
49
+ describe described_class::SamprRidEnumerationArray do
50
+ subject(:packet) { described_class.new }
51
+
52
+ it 'is a Ndr::NdrConfArray' do
53
+ expect(packet).to be_a(RubySMB::Dcerpc::Ndr::NdrConfArray)
54
+ end
55
+ it 'has element of type SamprRidEnumeration' do
56
+ packet << {relative_id: 4, name: ''}
57
+ expect(packet[0]).to be_a(RubySMB::Dcerpc::Samr::SamprRidEnumeration)
58
+ end
59
+ it 'reads itself' do
60
+ new_packet = described_class.new([
61
+ {relative_id: 4, name: 'Test1'},
62
+ {relative_id: 1, name: 'Test2'}
63
+ ])
64
+ expected_output = [
65
+ {
66
+ relative_id: 4,
67
+ name: {
68
+ buffer_length: 10,
69
+ maximum_length: 10,
70
+ buffer: "Test1".encode('utf-16le')
71
+ }
72
+ },
73
+ {
74
+ relative_id: 1,
75
+ name: {
76
+ buffer_length: 10,
77
+ maximum_length: 10,
78
+ buffer: "Test2".encode('utf-16le')
79
+ }
80
+ }]
81
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
82
+ end
83
+ end
84
+
85
+ describe described_class::PsamprRidEnumerationArray do
86
+ subject(:packet) { described_class.new }
87
+
88
+ it 'is a SamprRidEnumerationArray' do
89
+ expect(packet).to be_a(RubySMB::Dcerpc::Samr::SamprRidEnumerationArray)
90
+ end
91
+ it 'is a NdrPointer' do
92
+ expect(described_class).to be_a(RubySMB::Dcerpc::Ndr::PointerClassPlugin)
93
+ expect(packet).to be_a(RubySMB::Dcerpc::Ndr::PointerPlugin)
94
+ end
95
+ it 'is four-byte aligned' do
96
+ expect(packet.eval_parameter(:byte_align)).to eq(4)
97
+ end
98
+ it 'reads itself' do
99
+ new_packet = described_class.new([
100
+ {relative_id: 4, name: 'Test1'},
101
+ {relative_id: 1, name: 'Test2'}
102
+ ])
103
+ expected_output = [
104
+ {
105
+ relative_id: 4,
106
+ name: {
107
+ buffer_length: 10,
108
+ maximum_length: 10,
109
+ buffer: "Test1".encode('utf-16le')
110
+ }
111
+ },
112
+ {
113
+ relative_id: 1,
114
+ name: {
115
+ buffer_length: 10,
116
+ maximum_length: 10,
117
+ buffer: "Test2".encode('utf-16le')
118
+ }
119
+ }]
120
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
121
+ end
122
+ end
123
+
124
+ describe described_class::SamprEnumerationBuffer do
125
+ subject(:packet) { described_class.new }
126
+
127
+ it { is_expected.to respond_to :entries_read }
128
+ it { is_expected.to respond_to :buffer }
129
+
130
+ it 'is little endian' do
131
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
132
+ end
133
+ it 'is a Ndr::NdrStruct' do
134
+ expect(packet).to be_a(RubySMB::Dcerpc::Ndr::NdrStruct)
135
+ end
136
+ it 'is four-byte aligned' do
137
+ expect(packet.eval_parameter(:byte_align)).to eq(4)
138
+ end
139
+ describe '#entries_read' do
140
+ it 'is a NdrUint32 structure' do
141
+ expect(packet.entries_read).to be_a RubySMB::Dcerpc::Ndr::NdrUint32
142
+ end
143
+ end
144
+ describe '#buffer' do
145
+ it 'is a PsamprRidEnumerationArray structure' do
146
+ expect(packet.buffer).to be_a RubySMB::Dcerpc::Samr::PsamprRidEnumerationArray
147
+ end
148
+ end
149
+ it 'reads itself' do
150
+ new_packet = described_class.new(
151
+ entries_read: 3,
152
+ buffer: [
153
+ { relative_id: 500, name: "Administrator" },
154
+ { relative_id: 501, name: "Guest" },
155
+ { relative_id: 1001, name: "WIN-DP0M1BC768$" }
156
+ ]
157
+ )
158
+ expected_output = {
159
+ entries_read: 3,
160
+ buffer: [
161
+ {relative_id: 500, name: { buffer_length: 26, maximum_length: 26, buffer: "Administrator".encode('utf-16le') }},
162
+ {relative_id: 501, name: { buffer_length: 10, maximum_length: 10, buffer: "Guest".encode('utf-16le') }},
163
+ {relative_id: 1001, name: { buffer_length: 30, maximum_length: 30, buffer: "WIN-DP0M1BC768$".encode('utf-16le') }}
164
+ ]
165
+ }
166
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
167
+ end
168
+ end
169
+
170
+ describe described_class::PsamprEnumerationBuffer do
171
+ subject(:packet) { described_class.new }
172
+
173
+ it 'is a SamprEnumerationBuffer' do
174
+ expect(packet).to be_a(RubySMB::Dcerpc::Samr::SamprEnumerationBuffer)
175
+ end
176
+ it 'is a NdrPointer' do
177
+ expect(described_class).to be_a(RubySMB::Dcerpc::Ndr::PointerClassPlugin)
178
+ expect(packet).to be_a(RubySMB::Dcerpc::Ndr::PointerPlugin)
179
+ end
180
+ it 'is four-byte aligned' do
181
+ expect(packet.eval_parameter(:byte_align)).to eq(4)
182
+ end
183
+ it 'reads itself' do
184
+ new_packet = described_class.new(
185
+ entries_read: 3,
186
+ buffer: [
187
+ { relative_id: 500, name: "Administrator" },
188
+ { relative_id: 501, name: "Guest" },
189
+ { relative_id: 1001, name: "WIN-DP0M1BC768$" }
190
+ ]
191
+ )
192
+ expected_output = {
193
+ entries_read: 3,
194
+ buffer: [
195
+ {relative_id: 500, name: { buffer_length: 26, maximum_length: 26, buffer: "Administrator".encode('utf-16le') }},
196
+ {relative_id: 501, name: { buffer_length: 10, maximum_length: 10, buffer: "Guest".encode('utf-16le') }},
197
+ {relative_id: 1001, name: { buffer_length: 30, maximum_length: 30, buffer: "WIN-DP0M1BC768$".encode('utf-16le') }}
198
+ ]
199
+ }
200
+ expect(packet.read(new_packet.to_binary_s)).to eq(expected_output)
201
+ end
202
+ end
203
+
10
204
  describe described_class::SamprHandle do
11
205
  it 'is a Ndr::NdrContextHandle' do
12
206
  expect(described_class).to be < RubySMB::Dcerpc::Ndr::NdrContextHandle
data.tar.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- ��組��IF�hvh����Pwv}�!��D��*�(B�a%�"�'G`�^P w���
2
- �h$byj}�������D6���pW[dy.«����M���d)�@��\��٧
1
+
2
+ �$�fO��(���t0