Skip to content

Commit a7424c9

Browse files
committed
Update BES rspec
1 parent 8d40d30 commit a7424c9

File tree

1 file changed

+82
-25
lines changed

1 file changed

+82
-25
lines changed

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

Lines changed: 82 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@
4444
sock
4545
end
4646

47+
let(:user_agent) do
48+
'Mozilla/5.0 (Windows NT 6.3; rv:39.0) Gecko/20100101 Firefox/35.0'
49+
end
50+
51+
let(:cli_request) do
52+
req = Rex::Proto::Http::Request.new
53+
req.headers['Cookie'] = cookie
54+
req.headers['User-Agent'] = user_agent
55+
req
56+
end
57+
58+
let(:tag) do
59+
'tag'
60+
end
61+
62+
let(:cookie) do
63+
"__ua=#{tag};"
64+
end
65+
4766
let(:shortname) do
4867
'browser_exploit_server'
4968
end
@@ -59,6 +78,7 @@ def create_fake_note(tag, data)
5978

6079
before(:each) do
6180
allow_any_instance_of(described_class).to receive(:vprint_status)
81+
allow_any_instance_of(described_class).to receive(:vprint_line)
6282
@notes = [create_fake_note(first_profile_tag, in_memory_profile)]
6383
end
6484

@@ -68,9 +88,15 @@ def create_fake_note(tag, data)
6888
mod.send(:initialize)
6989
mod.send(:datastore=, {'NoteTypePrefix' => default_note_type_prefix})
7090
allow(mod).to receive(:shortname).and_return(shortname)
91+
allow(mod).to receive(:fullname).and_return(fullname)
92+
allow(mod).to receive(:report_client)
7193
mod
7294
end
7395

96+
let(:fullname) do
97+
'auxiliary/server/browser_autopwn2'
98+
end
99+
74100
let(:service_double) do
75101
service = double('service')
76102
allow(service).to receive(:server_name=)
@@ -164,20 +190,6 @@ def create_fake_note(tag, data)
164190

165191
describe '#retrieve_tag' do
166192
context 'when the browser has a cookie that contains our tag' do
167-
let(:tag) do
168-
'tag'
169-
end
170-
171-
let(:cookie) do
172-
"__ua=#{tag};"
173-
end
174-
175-
let(:cli_request) do
176-
req = Rex::Proto::Http::Request.new
177-
req.headers['Cookie'] = cookie
178-
req
179-
end
180-
181193
it 'returns the tag from the cookie' do
182194
expect(server.retrieve_tag(cli, cli_request)).to eq(tag)
183195
end
@@ -214,6 +226,7 @@ def create_fake_note(tag, data)
214226
@on_request_exploit_called = false
215227
@send_not_found_called = false
216228
@on_request_exploit_called = false
229+
@report_client = nil
217230
end
218231

219232

@@ -347,28 +360,72 @@ def create_fake_note(tag, data)
347360
end
348361
end
349362

350-
skip '#get_bad_requirements' do
351-
end
363+
describe '#get_bad_requirements' do
364+
context 'when there is a bad requirement' do
365+
it 'returns a bad requirement' do
366+
requirements = { ua_ver: '34' }
367+
subject.instance_variable_set(:@requirements, requirements)
368+
expect(subject.get_bad_requirements(first_profile_info)).to include(:ua_ver)
369+
end
370+
end
352371

353-
skip '#process_browser_info' do
372+
context 'when there is no bad requirement' do
373+
it 'returns an empty hash' do
374+
requirements = { ua_ver: first_profile_info[:ua_ver] }
375+
subject.instance_variable_set(:@requirements, requirements)
376+
expect(subject.get_bad_requirements(first_profile_info)).to be_empty
377+
end
378+
end
354379
end
355380

356-
skip '#has_proxy?' do
357-
end
381+
describe '#process_browser_info' do
382+
before(:each) do
383+
allow(subject).to receive(:report_client) { |args| @report_client = args }
384+
allow(subject).to receive(:browser_profile).and_return(Hash.new)
385+
end
358386

359-
skip '#cookie_name' do
360-
end
387+
context 'when source is :script' do
388+
context 'when no profile is found' do
389+
it 'reports an empty ua_ver' do
390+
subject.process_browser_info(:script, cli, cli_request)
391+
expect(@report_client[:ua_ver]).to eq('[]')
392+
end
393+
end
394+
end
361395

362-
skip '#cookie_header' do
396+
context 'when source is :headers' do
397+
context 'when user-agent says the browser is FF 35.0' do
398+
it 'reports ua_ver as 35.0' do
399+
subject.process_browser_info(:headers, cli, cli_request)
400+
expect(@report_client[:ua_ver]).to eq('35.0')
401+
end
402+
end
403+
end
363404
end
364405

365-
skip '#send_exploit_html' do
406+
describe '#has_proxy?' do
407+
context 'when there is no proxy' do
408+
it 'returns false' do
409+
expect(subject.has_proxy?(cli_request)).to be_falsey
410+
end
411+
end
366412
end
367413

368-
skip '#send_not_found' do
414+
describe '#cookie_name' do
415+
before(:each) do
416+
subject.datastore.merge!({'CookieName'=>cookie})
417+
end
418+
419+
it 'returns a cookiename' do
420+
expect(subject.cookie_name).to eq(cookie)
421+
end
369422
end
370423

371-
skip '#js_vuln_test' do
424+
describe '#cookie_header' do
425+
it 'returns a cookie' do
426+
tag = 'TAG'
427+
expect(subject.cookie_header(tag)).to include(tag)
428+
end
372429
end
373430

374431
end

0 commit comments

Comments
 (0)