Skip to content

Commit 405de05

Browse files
committed
Add specs for module_flavors
1 parent 17da899 commit 405de05

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

lib/msf/core/exploit/cmdstager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def generate_cmdstager(opts = {}, pl = nil)
116116
self.stager_instance = create_stager
117117
cmd_list = stager_instance.generate(opts_with_decoder(opts))
118118

119-
if (cmd_list.nil? or cmd_list.length < 1)
119+
if (cmd_list.nil? || cmd_list.length < 1)
120120
print_error("The command stager could not be generated")
121121
raise ArgumentError
122122
end

spec/lib/msf/core/exploit/cmdstager_spec.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,92 @@ def create_exploit(info ={})
147147
end
148148
end
149149

150+
describe "#module_flavors" do
151+
152+
context "when the module hasn't CmdStagerFlavor info" do
153+
154+
context "neither the target" do
155+
156+
subject do
157+
create_exploit
158+
end
159+
160+
it "returns empty array" do
161+
expect(subject.module_flavors).to eq([])
162+
end
163+
end
164+
165+
context "the target has CmdStagerFlavor info" do
166+
167+
subject do
168+
create_exploit({
169+
'DefaultTarget' => 0,
170+
'Targets' =>
171+
[
172+
['Windows',
173+
{
174+
'CmdStagerFlavor' => 'vbs'
175+
}
176+
]
177+
]
178+
})
179+
end
180+
181+
let(:expected_flavor) do
182+
['vbs']
183+
end
184+
185+
it "returns an array with the target flavor" do
186+
expect(subject.module_flavors).to eq(expected_flavor)
187+
end
188+
end
189+
end
190+
191+
context "when the module has CmdStagerFlavor info" do
192+
193+
context "but the target hasn't CmdStagerFlavor info" do
194+
195+
subject do
196+
create_exploit('CmdStagerFlavor' => 'vbs')
197+
end
198+
199+
let(:expected_flavor) do
200+
['vbs']
201+
end
202+
203+
it "returns an array with the module flavor" do
204+
expect(subject.module_flavors).to eq(expected_flavor)
205+
end
206+
end
207+
208+
context "and the target has CmdStagerFlavor info" do
209+
210+
subject do
211+
create_exploit({
212+
'CmdStagerFlavor' => 'vbs',
213+
'DefaultTarget' => 0,
214+
'Targets' =>
215+
[
216+
['Windows TFTP',
217+
{
218+
'CmdStagerFlavor' => 'tftp'
219+
}
220+
]
221+
]
222+
})
223+
end
224+
225+
let(:expected_flavor) do
226+
['vbs', 'tftp']
227+
end
228+
229+
it "returns an array with all the flavors available to the module" do
230+
expect(subject.module_flavors).to eq(expected_flavor)
231+
end
232+
end
233+
end
234+
end
235+
150236
describe "#target_flavor" do
151237

152238
context "when the module hasn't CmdStagerFlavor info" do

0 commit comments

Comments
 (0)