ruby_smb 0.0.21 → 0.0.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/examples/net_share_enum_all.rb +5 -2
- data/lib/ruby_smb.rb +1 -1
- data/lib/ruby_smb/client.rb +4 -35
- data/lib/ruby_smb/dcerpc.rb +7 -22
- data/lib/ruby_smb/dcerpc/bind.rb +30 -36
- data/lib/ruby_smb/dcerpc/bind_ack.rb +72 -0
- data/lib/ruby_smb/dcerpc/error.rb +15 -0
- data/lib/ruby_smb/dcerpc/ndr.rb +31 -30
- data/lib/ruby_smb/dcerpc/p_syntax_id_t.rb +11 -0
- data/lib/ruby_smb/dcerpc/pdu_header.rb +29 -0
- data/lib/ruby_smb/dcerpc/ptypes.rb +26 -0
- data/lib/ruby_smb/dcerpc/request.rb +17 -30
- data/lib/ruby_smb/dcerpc/response.rb +15 -34
- data/lib/ruby_smb/dcerpc/srvsvc.rb +5 -7
- data/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all.rb +8 -4
- data/lib/ruby_smb/dcerpc/uuid.rb +31 -13
- data/lib/ruby_smb/smb1/bit_field.rb +0 -1
- data/lib/ruby_smb/smb1/bit_field/trans_flags.rb +3 -2
- data/lib/ruby_smb/smb1/data_block.rb +5 -0
- data/lib/ruby_smb/smb1/dcerpc.rb +67 -0
- data/lib/ruby_smb/smb1/packet.rb +1 -0
- data/lib/ruby_smb/smb1/packet/trans.rb +7 -1
- data/lib/ruby_smb/smb1/packet/trans/data_block.rb +19 -7
- data/lib/ruby_smb/smb1/packet/trans/request.rb +36 -25
- data/lib/ruby_smb/smb1/packet/trans/response.rb +22 -21
- data/lib/ruby_smb/smb1/packet/trans/subcommands.rb +1 -0
- data/lib/ruby_smb/smb1/packet/trans/transact_nmpipe_request.rb +61 -0
- data/lib/ruby_smb/smb1/packet/trans/transact_nmpipe_response.rb +44 -0
- data/lib/ruby_smb/smb1/packet/trans2/request.rb +1 -1
- data/lib/ruby_smb/smb1/pipe.rb +3 -0
- data/lib/ruby_smb/smb2/dcerpc.rb +68 -0
- data/lib/ruby_smb/smb2/pipe.rb +3 -0
- data/lib/ruby_smb/version.rb +1 -1
- data/spec/lib/ruby_smb/client_spec.rb +53 -6
- data/spec/lib/ruby_smb/dcerpc/bind_ack_spec.rb +224 -0
- data/spec/lib/ruby_smb/dcerpc/bind_spec.rb +255 -7
- data/spec/lib/ruby_smb/dcerpc/p_syntax_id_t_spec.rb +31 -0
- data/spec/lib/ruby_smb/dcerpc/pdu_header_spec.rb +84 -0
- data/spec/lib/ruby_smb/dcerpc/request_spec.rb +106 -13
- data/spec/lib/ruby_smb/dcerpc/response_spec.rb +89 -8
- data/spec/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all_spec.rb +176 -0
- data/spec/lib/ruby_smb/dcerpc/uuid_spec.rb +97 -1
- data/spec/lib/ruby_smb/smb1/data_block_spec.rb +43 -3
- data/spec/lib/ruby_smb/smb1/packet/trans/data_block_spec.rb +137 -0
- data/spec/lib/ruby_smb/smb1/packet/trans/request_spec.rb +239 -13
- data/spec/lib/ruby_smb/smb1/packet/trans/response_spec.rb +122 -13
- data/spec/lib/ruby_smb/smb1/packet/trans/transact_nmpipe_request_spec.rb +254 -0
- data/spec/lib/ruby_smb/smb1/packet/trans/transact_nmpipe_response_spec.rb +122 -0
- data/spec/lib/ruby_smb/smb1/packet/trans2/request_spec.rb +2 -2
- data/spec/lib/ruby_smb/smb1/pipe_spec.rb +199 -1
- data/spec/lib/ruby_smb/smb2/file_spec.rb +2 -1
- data/spec/lib/ruby_smb/smb2/pipe_spec.rb +196 -1
- metadata +25 -10
- metadata.gz.sig +0 -0
- data/lib/ruby_smb/dcerpc/handle.rb +0 -60
- data/lib/ruby_smb/smb1/bit_field/trans2_flags.rb +0 -15
- data/spec/lib/ruby_smb/dcerpc/handle_spec.rb +0 -31
- data/spec/lib/ruby_smb/dcerpc/srvsvc_spec.rb +0 -13
- data/spec/lib/ruby_smb/smb1/bit_field/trans2_flags_spec.rb +0 -26
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
RSpec.describe RubySMB::SMB1::Packet::Trans::Request do
|
4
2
|
subject(:packet) { described_class.new }
|
5
3
|
|
@@ -10,7 +8,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans::Request do
|
|
10
8
|
expect(header).to be_a RubySMB::SMB1::SMBHeader
|
11
9
|
end
|
12
10
|
|
13
|
-
it 'should have the command set to
|
11
|
+
it 'should have the command set to SMB_COM_TRANSACTION' do
|
14
12
|
expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION
|
15
13
|
end
|
16
14
|
|
@@ -31,44 +29,147 @@ RSpec.describe RubySMB::SMB1::Packet::Trans::Request do
|
|
31
29
|
it { is_expected.to respond_to :max_parameter_count }
|
32
30
|
it { is_expected.to respond_to :max_data_count }
|
33
31
|
it { is_expected.to respond_to :max_setup_count }
|
32
|
+
it { is_expected.to respond_to :flags }
|
34
33
|
it { is_expected.to respond_to :timeout }
|
35
34
|
it { is_expected.to respond_to :parameter_count }
|
36
35
|
it { is_expected.to respond_to :parameter_offset }
|
37
36
|
it { is_expected.to respond_to :data_count }
|
38
37
|
it { is_expected.to respond_to :data_offset }
|
39
38
|
it { is_expected.to respond_to :setup_count }
|
39
|
+
it { is_expected.to respond_to :setup }
|
40
|
+
|
41
|
+
describe '#total_parameter_count' do
|
42
|
+
it 'is a 16-bit unsigned integer' do
|
43
|
+
expect(parameter_block.total_parameter_count).to be_a BinData::Uint16le
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'has a default value equal to #parameter_count' do
|
47
|
+
parameter_block.parameter_count = 5
|
48
|
+
expect(parameter_block.total_parameter_count).to eq 5
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#total_data_count' do
|
53
|
+
it 'is a 16-bit unsigned integer' do
|
54
|
+
expect(parameter_block.total_data_count).to be_a BinData::Uint16le
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'has a default value equal to #data_count' do
|
58
|
+
parameter_block.data_count = 5
|
59
|
+
expect(parameter_block.total_data_count).to eq 5
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#max_parameter_count' do
|
64
|
+
it 'is a 16-bit unsigned integer' do
|
65
|
+
expect(parameter_block.max_parameter_count).to be_a BinData::Uint16le
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'has the default value MAX_PARAMETER_COUNT' do
|
69
|
+
expect(parameter_block.max_parameter_count).to eq RubySMB::SMB1::Packet::Trans::MAX_PARAMETER_COUNT
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#max_data_count' do
|
74
|
+
it 'is a 16-bit unsigned integer' do
|
75
|
+
expect(parameter_block.max_data_count).to be_a BinData::Uint16le
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'has the default value MAX_DATA_COUNT' do
|
79
|
+
expect(parameter_block.max_data_count).to eq RubySMB::SMB1::Packet::Trans::MAX_DATA_COUNT
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#max_setup_count' do
|
84
|
+
it 'is a 8-bit unsigned integer' do
|
85
|
+
expect(parameter_block.max_setup_count).to be_a BinData::Uint8
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'has the default value MAX_SETUP_COUNT' do
|
89
|
+
expect(parameter_block.max_setup_count).to eq RubySMB::SMB1::Packet::Trans::MAX_SETUP_COUNT
|
90
|
+
end
|
91
|
+
end
|
40
92
|
|
41
|
-
describe 'flags' do
|
93
|
+
describe '#flags' do
|
42
94
|
it 'is a trans_flags BitField' do
|
43
95
|
expect(parameter_block.flags).to be_a RubySMB::SMB1::BitField::TransFlags
|
44
96
|
end
|
45
97
|
end
|
46
98
|
|
47
|
-
describe '
|
99
|
+
describe '#timeout' do
|
100
|
+
it 'is a 32-bit unsigned integer' do
|
101
|
+
expect(parameter_block.timeout).to be_a BinData::Uint32le
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'has a default value of 0x00000000' do
|
105
|
+
expect(parameter_block.timeout).to eq 0x00000000
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#parameter_count' do
|
110
|
+
it 'is a 16-bit unsigned integer' do
|
111
|
+
expect(parameter_block.parameter_count).to be_a BinData::Uint16le
|
112
|
+
end
|
113
|
+
|
48
114
|
it 'is a count of bytes in the data_block trans_parameters field' do
|
49
115
|
packet.data_block.trans_parameters = "\x00\x01\x02\x03"
|
50
116
|
expect(parameter_block.parameter_count).to eq 4
|
51
117
|
end
|
52
118
|
end
|
53
119
|
|
54
|
-
describe 'parameter_offset' do
|
120
|
+
describe '#parameter_offset' do
|
121
|
+
it 'is a 16-bit unsigned integer' do
|
122
|
+
expect(parameter_block.parameter_offset).to be_a BinData::Uint16le
|
123
|
+
end
|
124
|
+
|
55
125
|
it ' contains the absolute_offset to the data_block trans_parameters field' do
|
56
126
|
expect(parameter_block.parameter_offset).to eq packet.data_block.trans_parameters.abs_offset
|
57
127
|
end
|
58
128
|
end
|
59
129
|
|
60
|
-
describe 'data_count' do
|
130
|
+
describe '#data_count' do
|
131
|
+
it 'is a 16-bit unsigned integer' do
|
132
|
+
expect(parameter_block.data_count).to be_a BinData::Uint16le
|
133
|
+
end
|
134
|
+
|
61
135
|
it 'is a count of bytes in the data_block trans_data field' do
|
62
136
|
packet.data_block.trans_data = "\x00\x01\x02\x03"
|
63
137
|
expect(parameter_block.data_count).to eq 4
|
64
138
|
end
|
65
139
|
end
|
66
140
|
|
67
|
-
describe 'data_offset' do
|
141
|
+
describe '#data_offset' do
|
142
|
+
it 'is a 16-bit unsigned integer' do
|
143
|
+
expect(parameter_block.data_offset).to be_a BinData::Uint16le
|
144
|
+
end
|
145
|
+
|
68
146
|
it 'contains the absolute_offset to the data_block trans_data field' do
|
69
147
|
expect(parameter_block.data_offset).to eq packet.data_block.trans_data.abs_offset
|
70
148
|
end
|
71
149
|
end
|
150
|
+
|
151
|
+
describe '#setup_count' do
|
152
|
+
it 'is a 8-bit unsigned integer' do
|
153
|
+
expect(parameter_block.setup_count).to be_a BinData::Uint8
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'is a count of words in setup field' do
|
157
|
+
parameter_block.setup << 0x0102
|
158
|
+
parameter_block.setup << 0x0304
|
159
|
+
expect(parameter_block.setup_count).to eq 2
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#setup' do
|
164
|
+
it 'is an Array' do
|
165
|
+
expect(parameter_block.setup).to be_a BinData::Array
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'has #setup_count elements' do
|
169
|
+
parameter_block.setup_count = 3
|
170
|
+
expect(parameter_block.setup.length).to eq 3
|
171
|
+
end
|
172
|
+
end
|
72
173
|
end
|
73
174
|
|
74
175
|
describe '#data_block' do
|
@@ -82,13 +183,138 @@ RSpec.describe RubySMB::SMB1::Packet::Trans::Request do
|
|
82
183
|
it { is_expected.to respond_to :trans_parameters }
|
83
184
|
it { is_expected.to respond_to :trans_data }
|
84
185
|
|
85
|
-
|
86
|
-
|
186
|
+
describe '#pad_name' do
|
187
|
+
context 'when the UNICODE flag is not set in the Flags2 field of the SMB Header' do
|
188
|
+
it 'does not exists' do
|
189
|
+
expect(data_block).to_not be_pad_name
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'when the UNICODE flag is set in the Flags2 field of the SMB Header' do
|
194
|
+
before :example do
|
195
|
+
packet.smb_header.flags2.unicode = 1
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'exists' do
|
199
|
+
expect(data_block).to be_pad_name
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'is one null byte when #name is not 2-byte aligned' do
|
203
|
+
expect(data_block.pad_name).to eq("\x00")
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should keep #name 2-byte aligned' do
|
207
|
+
expect(data_block.name.abs_offset % 2).to eq 0
|
208
|
+
end
|
209
|
+
end
|
87
210
|
end
|
88
211
|
|
89
|
-
|
90
|
-
|
91
|
-
|
212
|
+
describe '#name' do
|
213
|
+
context 'when the UNICODE flag is not set in the Flags2 field of the SMB Header' do
|
214
|
+
it 'is a Stringz' do
|
215
|
+
expect(data_block.name.current_choice).to be_a BinData::Stringz
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'is ASCII encoded' do
|
219
|
+
expect(data_block.name.encoding.name).to eq("ASCII-8BIT")
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'is set to "\\PIPE\\\x00" by default' do
|
223
|
+
expect(data_block.name.to_binary_s).to eq("\\PIPE\\\x00")
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'adds a NULL terminator to the string' do
|
227
|
+
str = "test"
|
228
|
+
data_block.name = str
|
229
|
+
expect(data_block.name.to_binary_s).to eq(str + "\x00")
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
context 'when the UNICODE flag is set in the Flags2 field of the SMB Header' do
|
234
|
+
before :example do
|
235
|
+
packet.smb_header.flags2.unicode = 1
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'is a Stringz16' do
|
239
|
+
expect(data_block.name.current_choice).to be_a RubySMB::Field::Stringz16
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'is UTF-16LE encoded' do
|
243
|
+
expect(data_block.name.encoding.name).to eq("UTF-16LE")
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'is set to the null terminated unicode string "\\PIPE\\" by default' do
|
247
|
+
binary_str = "\\PIPE\\\x00".encode('utf-16le').force_encoding('ASCII')
|
248
|
+
expect(data_block.name.to_binary_s).to eq(binary_str)
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'adds a NULL terminator to the string' do
|
252
|
+
str = "test"
|
253
|
+
data_block.name = str
|
254
|
+
binary_str = (str + "\x00").encode('utf-16le').force_encoding('ASCII')
|
255
|
+
expect(data_block.name.to_binary_s).to eq(binary_str)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'when switching from ASCII to UNICODE' do
|
260
|
+
it 'encodes the same string to UNICODE' do
|
261
|
+
packet = RubySMB::SMB1::Packet::Trans::Request.new
|
262
|
+
data_block = packet.data_block
|
263
|
+
|
264
|
+
str = "test"
|
265
|
+
data_block.name = str
|
266
|
+
expect(data_block.name.to_binary_s).to eq(str + "\x00")
|
267
|
+
packet.smb_header.flags2.unicode = 1
|
268
|
+
binary_str = (str + "\x00").encode('utf-16le').force_encoding('ASCII')
|
269
|
+
expect(data_block.name.to_binary_s).to eq(binary_str)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe '#trans_parameters' do
|
275
|
+
it 'is a String' do
|
276
|
+
expect(data_block.trans_parameters).to be_a BinData::String
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'reads the number of bytes specified in parameter_block parameter_count field' do
|
280
|
+
packet.parameter_block.parameter_count = 3
|
281
|
+
data_block.trans_parameters.read("ABCDEF")
|
282
|
+
expect(data_block.trans_parameters).to eq("ABC")
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
describe '#trans_data' do
|
287
|
+
it 'is a String' do
|
288
|
+
expect(data_block.trans_data).to be_a BinData::String
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'reads the number of bytes specified in parameter_block parameter_count field' do
|
292
|
+
packet.parameter_block.data_count = 3
|
293
|
+
data_block.trans_data.read("ABCDEF")
|
294
|
+
expect(data_block.trans_data).to eq("ABC")
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
describe '#pad1' do
|
299
|
+
it 'should keep #trans_parameters 4-byte aligned' do
|
300
|
+
expect(data_block.trans_parameters.abs_offset % 4).to eq 0
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
describe '#pad2' do
|
305
|
+
it 'should keep #trans_data 4-byte aligned' do
|
306
|
+
data_block.trans_parameters = 'a'
|
307
|
+
expect(data_block.trans_data.abs_offset % 4).to eq 0
|
308
|
+
end
|
92
309
|
end
|
93
310
|
end
|
311
|
+
|
312
|
+
it 'reads its own binary representation and output the same packet' do
|
313
|
+
# Adding some data to the DataBlock to make sure paddings are handled correctly
|
314
|
+
packet.data_block.trans_parameters = 'a'
|
315
|
+
packet.data_block.trans_data = 'b'
|
316
|
+
binary = packet.to_binary_s
|
317
|
+
expect(described_class.read(binary)).to eq(packet)
|
318
|
+
end
|
94
319
|
end
|
320
|
+
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
RSpec.describe RubySMB::SMB1::Packet::Trans::Response do
|
4
2
|
subject(:packet) { described_class.new }
|
5
3
|
|
@@ -10,7 +8,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans::Response do
|
|
10
8
|
expect(header).to be_a RubySMB::SMB1::SMBHeader
|
11
9
|
end
|
12
10
|
|
13
|
-
it 'should have the command set to
|
11
|
+
it 'should have the command set to SMB_COM_TRANSACTION' do
|
14
12
|
expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION
|
15
13
|
end
|
16
14
|
|
@@ -35,51 +33,162 @@ RSpec.describe RubySMB::SMB1::Packet::Trans::Response do
|
|
35
33
|
it { is_expected.to respond_to :data_offset }
|
36
34
|
it { is_expected.to respond_to :parameter_displacement }
|
37
35
|
it { is_expected.to respond_to :setup_count }
|
36
|
+
it { is_expected.to respond_to :setup }
|
37
|
+
|
38
|
+
describe '#total_parameter_count' do
|
39
|
+
it 'is a 16-bit unsigned integer' do
|
40
|
+
expect(parameter_block.total_parameter_count).to be_a BinData::Uint16le
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'has a default value equal to #parameter_count' do
|
44
|
+
parameter_block.parameter_count = 5
|
45
|
+
expect(parameter_block.total_parameter_count).to eq 5
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#total_data_count' do
|
50
|
+
it 'is a 16-bit unsigned integer' do
|
51
|
+
expect(parameter_block.total_data_count).to be_a BinData::Uint16le
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'has a default value equal to #data_count' do
|
55
|
+
parameter_block.data_count = 5
|
56
|
+
expect(parameter_block.total_data_count).to eq 5
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#parameter_count' do
|
61
|
+
it 'is a 16-bit unsigned integer' do
|
62
|
+
expect(parameter_block.parameter_count).to be_a BinData::Uint16le
|
63
|
+
end
|
38
64
|
|
39
|
-
describe 'parameter_count' do
|
40
65
|
it 'is a count of bytes in the data_block trans_parameters field' do
|
41
66
|
packet.data_block.trans_parameters = "\x00\x01\x02\x03"
|
42
67
|
expect(parameter_block.parameter_count).to eq 4
|
43
68
|
end
|
44
69
|
end
|
45
70
|
|
46
|
-
describe 'parameter_offset' do
|
71
|
+
describe '#parameter_offset' do
|
72
|
+
it 'is a 16-bit unsigned integer' do
|
73
|
+
expect(parameter_block.parameter_offset).to be_a BinData::Uint16le
|
74
|
+
end
|
75
|
+
|
47
76
|
it ' contains the absolute_offset to the data_block trans_parameters field' do
|
48
77
|
expect(parameter_block.parameter_offset).to eq packet.data_block.trans_parameters.abs_offset
|
49
78
|
end
|
50
79
|
end
|
51
80
|
|
52
|
-
describe '
|
81
|
+
describe '#parameter_displacement' do
|
82
|
+
it 'is a 16-bit unsigned integer' do
|
83
|
+
expect(parameter_block.parameter_displacement).to be_a BinData::Uint16le
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#data_count' do
|
88
|
+
it 'is a 16-bit unsigned integer' do
|
89
|
+
expect(parameter_block.data_count).to be_a BinData::Uint16le
|
90
|
+
end
|
91
|
+
|
53
92
|
it 'is a count of bytes in the data_block trans_data field' do
|
54
93
|
packet.data_block.trans_data = "\x00\x01\x02\x03"
|
55
94
|
expect(parameter_block.data_count).to eq 4
|
56
95
|
end
|
57
96
|
end
|
58
97
|
|
59
|
-
describe 'data_offset' do
|
98
|
+
describe '#data_offset' do
|
99
|
+
it 'is a 16-bit unsigned integer' do
|
100
|
+
expect(parameter_block.data_offset).to be_a BinData::Uint16le
|
101
|
+
end
|
102
|
+
|
60
103
|
it 'contains the absolute_offset to the data_block trans_data field' do
|
61
104
|
expect(parameter_block.data_offset).to eq packet.data_block.trans_data.abs_offset
|
62
105
|
end
|
63
106
|
end
|
107
|
+
|
108
|
+
describe '#data_displacement' do
|
109
|
+
it 'is a 16-bit unsigned integer' do
|
110
|
+
expect(parameter_block.data_displacement).to be_a BinData::Uint16le
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#setup_count' do
|
115
|
+
it 'is a 8-bit unsigned integer' do
|
116
|
+
expect(parameter_block.setup_count).to be_a BinData::Uint8
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'is a count of words in setup field' do
|
120
|
+
parameter_block.setup << 0x0102
|
121
|
+
parameter_block.setup << 0x0304
|
122
|
+
expect(parameter_block.setup_count).to eq 2
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '#setup' do
|
127
|
+
it 'is an Array' do
|
128
|
+
expect(parameter_block.setup).to be_a BinData::Array
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'has #setup_count elements' do
|
132
|
+
parameter_block.setup_count = 3
|
133
|
+
expect(parameter_block.setup.length).to eq 3
|
134
|
+
end
|
135
|
+
end
|
64
136
|
end
|
65
137
|
|
66
138
|
describe '#data_block' do
|
67
139
|
subject(:data_block) { packet.data_block }
|
68
140
|
|
69
|
-
it 'is a Trans DataBlock' do
|
141
|
+
it 'is a Packet Trans DataBlock' do
|
70
142
|
expect(data_block).to be_a RubySMB::SMB1::Packet::Trans::DataBlock
|
71
143
|
end
|
72
144
|
|
73
145
|
it { is_expected.to respond_to :trans_parameters }
|
74
146
|
it { is_expected.to respond_to :trans_data }
|
75
147
|
|
76
|
-
|
77
|
-
|
148
|
+
describe '#trans_parameters' do
|
149
|
+
it 'is a String' do
|
150
|
+
expect(data_block.trans_parameters).to be_a BinData::String
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'reads the number of bytes specified in parameter_block parameter_count field' do
|
154
|
+
packet.parameter_block.parameter_count = 3
|
155
|
+
data_block.trans_parameters.read("ABCDEF")
|
156
|
+
expect(data_block.trans_parameters).to eq("ABC")
|
157
|
+
end
|
78
158
|
end
|
79
159
|
|
80
|
-
|
81
|
-
|
82
|
-
|
160
|
+
describe '#trans_data' do
|
161
|
+
it 'is a String' do
|
162
|
+
expect(data_block.trans_data).to be_a BinData::String
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'reads the number of bytes specified in parameter_block parameter_count field' do
|
166
|
+
packet.parameter_block.data_count = 3
|
167
|
+
data_block.trans_data.read("ABCDEF")
|
168
|
+
expect(data_block.trans_data).to eq("ABC")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe '#pad1' do
|
173
|
+
it 'should keep #trans_parameters 4-byte aligned' do
|
174
|
+
expect(data_block.trans_parameters.abs_offset % 4).to eq 0
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '#pad2' do
|
179
|
+
it 'should keep #trans_data 4-byte aligned' do
|
180
|
+
data_block.trans_parameters = 'a'
|
181
|
+
expect(data_block.trans_data.abs_offset % 4).to eq 0
|
182
|
+
end
|
83
183
|
end
|
84
184
|
end
|
185
|
+
|
186
|
+
it 'reads its own binary representation and output the same packet' do
|
187
|
+
# Adding some data to the DataBlock to make sure paddings are handled correctly
|
188
|
+
packet.data_block.trans_parameters = 'a'
|
189
|
+
packet.data_block.trans_data = 'b'
|
190
|
+
binary = packet.to_binary_s
|
191
|
+
expect(described_class.read(binary)).to eq(packet)
|
192
|
+
end
|
85
193
|
end
|
194
|
+
|