Skip to content

Commit b2d723e

Browse files
committed
Rspec
1 parent b1208e1 commit b2d723e

File tree

1 file changed

+63
-5
lines changed

1 file changed

+63
-5
lines changed

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

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def mock_note_destroy
14-
# The destory method doesn't pass the note as an argument like framework.jobs_stop_job.
14+
# The destory method doesn't pass the note as an argument startlike framework.jobs_stop_job.
1515
# So here's I'm just gonna clear them all, and that sort of mimics #destroy.
1616
framework = double('Msf::Framework', datastore: {})
1717

@@ -91,6 +91,19 @@ def create_fake_exploit(opts={})
9191
mod
9292
end
9393

94+
def create_fake_multi_handler
95+
compat_payloads = [
96+
[windows_meterpreter_reverse_tcp, create_fake_windows_meterpreter]
97+
]
98+
99+
create_fake_exploit(
100+
full_name: 'multi/handler',
101+
short_name: 'multi/handler',
102+
compat_payloads: compat_payloads,
103+
job_id: 0,
104+
)
105+
end
106+
94107
def create_fake_ms14_064
95108
compat_payloads = [
96109
[windows_meterpreter_reverse_tcp, create_fake_windows_meterpreter]
@@ -168,6 +181,7 @@ def create_fake_payload(opts={})
168181
allow(p).to receive(:fullname).and_return(fullname)
169182
allow(p).to receive(:shoftname).and_return(shortname)
170183
allow(p).to receive(:workspace).and_return(workspace)
184+
allow(p).to receive(:exploit_simple)
171185

172186
p
173187
end
@@ -238,6 +252,7 @@ def mock_exploit_create(full_name)
238252
exploits << create_fake_ms14_064
239253
exploits << create_fake_flash_uncompress_zlib_uaf
240254
exploits << create_fake_flash_net_connection_confusion
255+
exploits << create_fake_multi_handler
241256

242257
exploits
243258
}.call
@@ -382,6 +397,7 @@ def mock_exploit_create(full_name)
382397
mod.send(:initialize)
383398
mod.send(:datastore=, autopwn_datastore_options)
384399
allow(mod).to receive(:fullname).and_return('multi/browser/autopwn')
400+
allow(mod).to receive(:datastore).and_return(autopwn_datastore_options)
385401
mod
386402
end
387403

@@ -561,7 +577,30 @@ def mock_exploit_create(full_name)
561577
end
562578
end
563579

564-
skip '#start_payload_listeners' do
580+
describe '#start_payload_listeners' do
581+
let(:active_payload) do
582+
create_fake_windows_meterpreter
583+
end
584+
585+
let(:wanted_payloads) do
586+
[{
587+
payload_name: active_payload.fullname,
588+
payload_lport: active_payload.datastore['LPORT']
589+
}]
590+
end
591+
592+
before(:each) do
593+
subject.instance_variable_set(:@wanted_payloads, wanted_payloads)
594+
subject.instance_variable_set(:@payload_job_ids, [])
595+
end
596+
597+
context 'when a payload is listening' do
598+
it 'adds the job ID to the payload job ID list' do
599+
expect(subject.instance_variable_get(:@payload_job_ids).length).to eq(0)
600+
subject.start_payload_listeners
601+
expect(subject.instance_variable_get(:@payload_job_ids).length).to eq(1)
602+
end
603+
end
565604
end
566605

567606
describe '#parse_rank' do
@@ -656,8 +695,20 @@ def mock_exploit_create(full_name)
656695
end
657696
end
658697

659-
skip '#select_payload' do
660-
698+
describe '#select_payload' do
699+
before(:each) do
700+
subject.instance_variable_set(:@wanted_payloads, [])
701+
end
702+
703+
context 'when a ms14_064 is given' do
704+
it 'returns a windows payload' do
705+
m = create_fake_ms14_064
706+
expected_payload = m.compatible_payloads.first.first
707+
selected_payload = subject.select_payload(m)
708+
expect(selected_payload.length).to eq(1)
709+
expect(selected_payload.first[:payload_name]).to eq(expected_payload)
710+
end
711+
end
661712
end
662713

663714
describe '#start_exploits' do
@@ -724,7 +775,14 @@ def get_stdout(&block)
724775
end
725776

726777
skip '#start_service' do
727-
# You got me, I don't know how to implement this one because the super"
778+
it 'prints the BrowserAutopwn URL' do
779+
# This code blows up, por que??
780+
# 3 threads exist(s) when only 1 thread expected after suite runs
781+
allow_any_instance_of(Msf::Exploit::Remote::BrowserExploitServer).to receive(:super)
782+
allow(subject).to receive(:show_ready_exploits)
783+
allow_any_instance_of(Rex::Socket).to receive(:source_address).and_return(nil)
784+
subject.start_service
785+
end
728786
end
729787

730788
end

0 commit comments

Comments
 (0)