Skip to content

Commit eabf561

Browse files
committed
Fix some BES rspec
1 parent 5a858d6 commit eabf561

File tree

1 file changed

+141
-29
lines changed

1 file changed

+141
-29
lines changed

spec/lib/msf/core/exploit/remote/browser_exploit_server_spec.rb

Lines changed: 141 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,38 @@
33

44
describe Msf::Exploit::Remote::BrowserExploitServer do
55

6-
# When unpacked, this gives us:
7-
# {
8-
# "BAP.1433806920.Client.blLGFIlwYrxfvcY" =>
9-
# {
10-
# "source" => "script",
11-
# "os_name" => "Windows 8.1",
12-
# "os_vendor" => "undefined",
13-
# "os_device" => "undefined",
14-
# "ua_name" => "Firefox",
15-
# "ua_ver" => "35.0",
16-
# "arch" => "x86",
17-
# "java" => "1.7",
18-
# "silverlight" => "false",
19-
# "flash" => "14.0",
20-
# "vuln_test" => "true",
21-
# "proxy" => false,
22-
# "language" => "en-US,en;q=0.5",
23-
# "tried" => true,
24-
# "activex" => [{"clsid"=>"{D27CDB6E-AE6D-11cf-96B8-444553540000}", "method"=>"LoadMovie"}]
25-
# }}
26-
let(:first_packed_profile) do
27-
"\x81\xD9%BAP.1433806920.Client.blLGFIlwYrxfvcY\x8F\xA6source\xA6script\xA7os_name\xABWindows 8.1\xA9os_vendor\xA9undefined\xA9os_device\xA9undefined\xA7ua_name\xA7Firefox\xA6ua_ver\xA435.0\xA4arch\xA3x86\xA4java\xA31.7\xABsilverlight\xA5false\xA5flash\xA414.0\xA9vuln_test\xA4true\xA5proxy\xC2\xA8language\xC4\x0Een-US,en;q=0.5\xA5tried\xC3\xA7activex\x91\x82\xA5clsid\xD9&{D27CDB6E-AE6D-11cf-96B8-444553540000}\xA6method\xA9LoadMovie"
6+
let(:in_memory_profile) do
7+
{
8+
"BAP.1433806920.Client.blLGFIlwYrxfvcY" =>
9+
{
10+
source: "script",
11+
os_name: "Windows 8.1",
12+
os_vendor: "undefined",
13+
os_device: "undefined",
14+
ua_name: "Firefox",
15+
ua_ver: "35.0",
16+
arch: "x86",
17+
java: "1.7",
18+
silverlight: "false",
19+
flash: "14.0",
20+
vuln_test: "true",
21+
proxy: false,
22+
language: "en-US,en;q=0.5",
23+
tried: true,
24+
activex: [{"clsid"=>"{D27CDB6E-AE6D-11cf-96B8-444553540000}", "method"=>"LoadMovie"}]
25+
}}
2826
end
2927

3028
let(:default_note_type_prefix) do
31-
MessagePack.unpack(first_packed_profile).keys.first.split('.')[0,3] * "."
29+
in_memory_profile.keys.first.split('.')[0,3] * "."
3230
end
3331

3432
let(:first_profile_tag) do
35-
MessagePack.unpack(first_packed_profile).keys.first.split('.')[3]
33+
in_memory_profile.keys.first.split('.')[3]
3634
end
3735

3836
let(:first_profile_info) do
39-
MessagePack.unpack(first_packed_profile).values.first
37+
in_memory_profile.values.first
4038
end
4139

4240
let(:cli) do
@@ -46,6 +44,10 @@
4644
sock
4745
end
4846

47+
let(:shortname) do
48+
'browser_exploit_server'
49+
end
50+
4951
def create_fake_note(tag, data)
5052
note = double('note')
5153
allow(note).to receive(:ntype).and_return(tag)
@@ -57,14 +59,15 @@ def create_fake_note(tag, data)
5759

5860
before(:each) do
5961
allow_any_instance_of(described_class).to receive(:vprint_status)
60-
@notes = [create_fake_note(first_profile_tag, first_packed_profile)]
62+
@notes = [create_fake_note(first_profile_tag, in_memory_profile)]
6163
end
6264

6365
subject(:server) do
6466
mod = Msf::Exploit::Remote.allocate
6567
mod.extend described_class
6668
mod.send(:initialize)
6769
mod.send(:datastore=, {'NoteTypePrefix' => default_note_type_prefix})
70+
allow(mod).to receive(:shortname).and_return(shortname)
6871
mod
6972
end
7073

@@ -99,14 +102,14 @@ def create_fake_note(tag, data)
99102

100103
describe '#has_bad_activex?' do
101104
context 'when there is a bad activex' do
102-
let(:js_ax_value) { "#{first_profile_info['activex'][0][:clsid]}=>#{first_profile_info['activex'][0][:method]}=>false" }
105+
let(:js_ax_value) { "#{first_profile_info[:activex][0][:clsid]}=>#{first_profile_info[:activex][0][:method]}=>false" }
103106
it 'returns false' do
104107
expect(server.has_bad_activex?(js_ax_value)).to be_truthy
105108
end
106109
end
107110

108111
context 'when there is no bad activex' do
109-
let(:js_ax_value) { "#{first_profile_info['activex'][0][:clsid]}=>#{first_profile_info['activex'][0][:method]}=>true" }
112+
let(:js_ax_value) { "#{first_profile_info[:activex][0][:clsid]}=>#{first_profile_info[:activex][0][:method]}=>true" }
110113
it 'returns true' do
111114
expect(server.has_bad_activex?(js_ax_value)).to be_falsey
112115
end
@@ -194,7 +197,7 @@ def create_fake_note(tag, data)
194197

195198
describe '#on_request_uri' do
196199
before(:each) do
197-
allow(server).to receive(:get_profile_info) { MessagePack.unpack(first_packed_profile) }
200+
allow(server).to receive(:get_profile_info) { in_memory_profile }
198201
allow(server).to receive(:init_profile).with(kind_of(String))
199202
allow(server).to receive(:update_profile)
200203
allow(server).to receive(:process_browser_info)
@@ -260,4 +263,113 @@ def create_fake_note(tag, data)
260263
end
261264
end
262265
end
266+
267+
describe '#browser_profile_prefix' do
268+
it 'returns a BES prefix' do
269+
expect(subject.browser_profile_prefix).to include(shortname)
270+
end
271+
end
272+
273+
describe '#get_custom_404_url' do
274+
let(:custom_404) do
275+
'http://example.com'
276+
end
277+
278+
before(:each) do
279+
allow(subject).to receive(:datastore).and_return({'Custom404'=>custom_404})
280+
end
281+
282+
context 'when a custom 404 URL is set' do
283+
it 'returns the URL' do
284+
expect(subject.get_custom_404_url).to eq(custom_404)
285+
end
286+
end
287+
end
288+
289+
describe '#get_module_uri' do
290+
let(:exploit_receiver_page) do
291+
'exploit_receiver_page'
292+
end
293+
294+
before(:each) do
295+
subject.instance_variable_set(:@exploit_receiver_page, exploit_receiver_page)
296+
allow(subject).to receive(:get_uri).and_return('')
297+
end
298+
299+
it 'returns a module URI' do
300+
expect(subject.get_module_uri).to include(exploit_receiver_page)
301+
end
302+
end
303+
304+
describe '#try_set_target' do
305+
let(:aux_mod) do
306+
mod = Msf::Auxiliary.allocate
307+
mod.extend described_class
308+
mod.send(:initialize)
309+
mod
310+
end
311+
312+
let(:target_options) do
313+
{ua_name: 'Firefox'}
314+
end
315+
316+
let(:target) do
317+
t = double('target')
318+
allow(t).to receive(:opts).and_return(target_options)
319+
t
320+
end
321+
322+
let(:default_auto_target) do
323+
# The default auto target is always the first on the list.
324+
# In a module this would be the "Automatic" target.
325+
t = double('target')
326+
allow(t).to receive(:opts).and_return({})
327+
t
328+
end
329+
330+
let(:targets) do
331+
[ default_auto_target, target ]
332+
end
333+
334+
context 'when an auxiliary uses BES' do
335+
it 'returns nil' do
336+
expect(aux_mod.try_set_target(first_profile_info)).to be_nil
337+
end
338+
end
339+
340+
context 'when an exploit uses BES' do
341+
it 'sets the instance variable @target' do
342+
expect(subject.instance_variable_get(:@target)).to be_nil
343+
allow(subject).to receive(:targets).and_return(targets)
344+
subject.try_set_target(first_profile_info)
345+
expect(subject.instance_variable_get(:@target)).to eq(target)
346+
end
347+
end
348+
end
349+
350+
skip '#get_bad_requirements' do
351+
end
352+
353+
skip '#process_browser_info' do
354+
end
355+
356+
skip '#has_proxy?' do
357+
end
358+
359+
skip '#cookie_name' do
360+
end
361+
362+
skip '#cookie_header' do
363+
end
364+
365+
skip '#send_exploit_html' do
366+
end
367+
368+
skip '#send_not_found' do
369+
end
370+
371+
skip '#js_vuln_test' do
372+
end
373+
263374
end
375+

0 commit comments

Comments
 (0)