Skip to content

Commit 8328c5c

Browse files
committed
Add specs for SMB_FIND_FILE_BOTH_DIRECTORY_INFO requests
1 parent 597f99a commit 8328c5c

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/rex/proto/smb/constants.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,17 +1360,20 @@ def self.make_nbs (template)
13601360
['Parameters', 'ByteCount', nil, true]
13611361
)
13621362

1363+
# A template for SMB_Parameters blocks of the SMB_COM_TRANSACTION2 QUERY_PATH_INFO responses
13631364
SMB_TRANS2_QUERY_PATH_PARAMETERS = Rex::Struct2::CStructTemplate.new(
13641365
['uint16v', 'InformationLevel', 0],
13651366
['uint32v', 'Reserved', 0],
13661367
['string', 'FileName', nil, '']
13671368
)
13681369

1370+
# A template for SMB_Parameters blocks of the SMB_COM_TRANSACTION2 QUERY_FILE_INFO responses
13691371
SMB_TRANS2_QUERY_FILE_PARAMETERS = Rex::Struct2::CStructTemplate.new(
13701372
['uint16v', 'FID', 0],
13711373
['uint16v', 'InformationLevel', 0]
13721374
)
13731375

1376+
# A template for SMB_Parameters blocks of the SMB_COM_TRANSACTION2 FIND_FIRST2 responses
13741377
SMB_TRANS2_FIND_FIRST2_PARAMETERS = Rex::Struct2::CStructTemplate.new(
13751378
['uint16v', 'SearchAttributes', 0],
13761379
['uint16v', 'SearchCount', 0],
@@ -1380,6 +1383,7 @@ def self.make_nbs (template)
13801383
['string', 'FileName', nil, '']
13811384
)
13821385

1386+
# A template for SMB Tree Connect commands in responses
13831387
SMB_TREE_CONN_ANDX_RES_PKT = Rex::Struct2::CStructTemplate.new(
13841388
['uint8', 'WordCount', 0],
13851389
['uint8', 'AndXCommand', 0],

spec/lib/msf/core/exploit/smb/server/share/command/trans2/find_first2_spec.rb

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
""
2323
end
2424

25-
let(:valid_find_file_both_directory_info_request) do
26-
""
25+
let(:valid_find_file_both_directory_info_params) do
26+
"\x16\x00\x56\x05\x07\x00\x04\x01\x00\x00\x00\x00\x5c\x00\x74\x00" +
27+
"\x65\x00\x73\x00\x74\x00\x2e\x00\x65\x00\x78\x00\x65\x00\x00\x00"
2728
end
29+
let(:find_file_both_directory_info_res_length) { 179 }
2830

2931
let(:valid_find_file_full_directory_info_request) do
3032
""
@@ -53,8 +55,27 @@
5355

5456
describe "#smb_cmd_trans2_find_first2" do
5557

56-
context "when valid SMB_FIND_FILE_BOTH_DIRECTORY_INFO request" do
58+
context "when valid SMB_FIND_FILE_BOTH_DIRECTORY_INFO parameters" do
59+
it "returns the number of bytes answered" do
60+
expect(mod.smb_cmd_trans2_find_first2(client, valid_find_file_both_directory_info_params)).to eq(find_file_both_directory_info_res_length)
61+
end
62+
63+
it "send TRANSACTIONS2 response with the file name found in the SMB_Data" do
64+
mod.smb_cmd_trans2_find_first2(client, valid_find_file_both_directory_info_params)
65+
client.seek(0)
66+
res = client.read
67+
68+
trans2_res = Rex::Proto::SMB::Constants::SMB_TRANS_RES_PKT.make_struct
69+
trans2_res.from_s(res)
70+
param_count = trans2_res['Payload'].v['ParamCount']
71+
data_count = trans2_res['Payload'].v['DataCount']
72+
73+
data = trans2_res['Payload'].v['SetupData'][2 + param_count, data_count]
74+
smb_data = Rex::Proto::SMB::Constants::SMB_FIND_FILE_BOTH_DIRECTORY_INFO_HDR.make_struct
75+
smb_data.from_s(data)
5776

77+
expect(smb_data.v['FileName']).to eq(Rex::Text.to_unicode(mod.file_name))
78+
end
5879
end
5980
end
6081

0 commit comments

Comments
 (0)