Skip to content

Commit df7c07b

Browse files
committed
Really add the specs
1 parent 4237cd2 commit df7c07b

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# -*- coding:binary -*-
2+
require 'spec_helper'
3+
4+
require 'msf/core'
5+
require 'msf/core/exploit/smb/server/share'
6+
require 'rex/proto/smb/constants'
7+
8+
describe Msf::Exploit::Remote::SMB::Server::Share do
9+
10+
subject(:mod) do
11+
mod = Msf::Exploit.new
12+
mod.extend described_class
13+
mod.send(:initialize)
14+
15+
mod
16+
end
17+
18+
let(:client_string) { '' }
19+
let(:client) { StringIO.new(client_string) }
20+
21+
let(:valid_query_path_standard_info_params) do
22+
"\xed\x03\x00\x00\x00\x00\x5c\x00\x74\x00\x65\x00\x73\x00\x74\x00" +
23+
"\x2e\x00\x65\x00\x78\x00\x65\x00\x00\x00"
24+
end
25+
let(:query_path_standard_info_res_length) { 83 }
26+
27+
let(:valid_query_path_basic_info_params) do
28+
"\xec\x03\x00\x00\x00\x00\x5c\x00\x74\x00\x65\x00\x73\x00\x74\x00" +
29+
"\x2e\x00\x65\x00\x78\x00\x65\x00\x00\x00"
30+
end
31+
let(:query_path_basic_info_res_length) { 101 }
32+
33+
let(:non_existent_query_path_basic_info_params) do
34+
"\xec\x03\x00\x00\x00\x00\x5c\x00\x74\x00\x65\x00\x73\x00\x74\x00" +
35+
"\x2e\x00\x65\x00\x78\x00\x61\x00\x00\x00"
36+
end
37+
let(:not_found_res_length) { 39 }
38+
39+
before(:each) do
40+
mod.instance_variable_set('@state', {
41+
client => {
42+
:multiplex_id => 0x41424344,
43+
:process_id => 0x45464748,
44+
:file_id => 0xdead,
45+
:dir_id => 0xbeef
46+
}
47+
})
48+
mod.lo = 0
49+
mod.hi = 0
50+
mod.share = 'test'
51+
mod.path_name = "\\"
52+
mod.file_name = 'test.exe'
53+
mod.file_contents = 'metasploit'
54+
55+
allow_any_instance_of(::StringIO).to receive(:put) do |io, data|
56+
io.write(data)
57+
end
58+
end
59+
60+
describe "#smb_cmd_trans2_query_path_information" do
61+
62+
context "when valid SMB_QUERY_PATH_STANDARD_INFO parameters" do
63+
it "returns the number of bytes answered" do
64+
expect(mod.smb_cmd_trans2_query_path_information(client, valid_query_path_standard_info_params)).to eq(query_path_standard_info_res_length)
65+
end
66+
67+
it "send SMB_QUERY_PATH_STANDARD_INFO response with the file size" do
68+
mod.smb_cmd_trans2_query_path_information(client, valid_query_path_standard_info_params)
69+
client.seek(0)
70+
res = client.read
71+
72+
trans2_res = Rex::Proto::SMB::Constants::SMB_TRANS_RES_PKT.make_struct
73+
trans2_res.from_s(res)
74+
param_count = trans2_res['Payload'].v['ParamCount']
75+
data_count = trans2_res['Payload'].v['DataCount']
76+
77+
data = trans2_res['Payload'].v['SetupData'][2 + param_count, data_count]
78+
smb_data = Rex::Proto::SMB::Constants::SMB_QUERY_FILE_STANDARD_INFO_HDR.make_struct
79+
smb_data.from_s(data)
80+
81+
expect(smb_data.v['EndOfFile']).to eq(mod.file_contents.length)
82+
end
83+
end
84+
85+
context "when valid SMB_QUERY_PATH_BASIC_INFO parameters" do
86+
it "returns the number of bytes answered" do
87+
expect(mod.smb_cmd_trans2_query_path_information(client, valid_query_path_basic_info_params)).to eq(query_path_basic_info_res_length)
88+
end
89+
90+
it "send SMB_QUERY_PATH_BASIC_INFO response with the file attributes" do
91+
mod.smb_cmd_trans2_query_path_information(client, valid_query_path_basic_info_params)
92+
client.seek(0)
93+
res = client.read
94+
95+
trans2_res = Rex::Proto::SMB::Constants::SMB_TRANS_RES_PKT.make_struct
96+
trans2_res.from_s(res)
97+
param_count = trans2_res['Payload'].v['ParamCount']
98+
data_count = trans2_res['Payload'].v['DataCount']
99+
100+
data = trans2_res['Payload'].v['SetupData'][2 + param_count, data_count]
101+
smb_data = Rex::Proto::SMB::Constants::SMB_QUERY_FILE_BASIC_INFO_HDR.make_struct
102+
smb_data.from_s(data)
103+
104+
expect(smb_data.v['ExtFileAttributes']).to eq(0x80)
105+
end
106+
end
107+
108+
context "when non existent file SMB_QUERY_PATH_BASIC_INFO parameters" do
109+
it "returns the number of bytes answered" do
110+
expect(mod.smb_cmd_trans2_query_path_information(client, non_existent_query_path_basic_info_params)).to eq(not_found_res_length)
111+
end
112+
113+
it "send TRANS2 response with error" do
114+
mod.smb_cmd_trans2_query_path_information(client, non_existent_query_path_basic_info_params)
115+
client.seek(0)
116+
res = client.read
117+
118+
trans2_res = Rex::Proto::SMB::Constants::SMB_TRANS_RES_PKT.make_struct
119+
trans2_res.from_s(res)
120+
121+
expect(trans2_res['Payload']['SMB'].v['ErrorClass']).to eq(Rex::Proto::SMB::Constants::SMB_STATUS_OBJECT_NAME_NOT_FOUND)
122+
end
123+
end
124+
end
125+
126+
end
127+
128+

0 commit comments

Comments
 (0)