Skip to content

Commit 12a99ec

Browse files
committed
Land rapid7#4796, Handle incompatible payload architecture in BES
2 parents 7b32b8b + 1835120 commit 12a99ec

File tree

2 files changed

+70
-17
lines changed

2 files changed

+70
-17
lines changed

lib/msf/core/exploit/remote/browser_exploit_server.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
module Msf
2121
module Exploit::Remote::BrowserExploitServer
2222

23+
class BESException < RuntimeError; end
24+
2325
include Msf::Exploit::Remote::HttpServer::HTML
2426
include Msf::Exploit::RopDb
2527
include Msf::Exploit::JSObfu
@@ -521,7 +523,13 @@ def on_request_uri(cli, request)
521523
try_set_target(profile)
522524
bad_reqs = get_bad_requirements(profile)
523525
if bad_reqs.empty?
524-
method(:on_request_exploit).call(cli, request, profile)
526+
begin
527+
method(:on_request_exploit).call(cli, request, profile)
528+
rescue BESException => e
529+
elog("BESException: #{e.message}\n#{e.backtrace * "\n"}")
530+
send_not_found(cli)
531+
print_error("BESException: #{e.message}")
532+
end
525533
else
526534
print_warning("Exploit requirement(s) not met: #{bad_reqs * ', '}. For more info: http://r-7.co/PVbcgx")
527535
if bad_reqs.include?(:vuln_test)
@@ -586,7 +594,15 @@ def get_payload(cli, browser_info)
586594
platform = platform.gsub(/^Mac OS X$/, 'OSX')
587595
platform = platform.gsub(/^Windows.*$/, 'Windows')
588596

589-
regenerate_payload(cli, platform, arch).encoded
597+
p = regenerate_payload(cli, platform, arch)
598+
599+
unless p.arch.include?(arch)
600+
err = "The payload arch (#{p.arch * ", "}) is incompatible with the #{arch} target. "
601+
err << "Please check your payload setting."
602+
raise BESException, err
603+
end
604+
605+
return p.encoded
590606
end
591607

592608
# @return [String] custom Javascript to check if a vulnerability is present

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

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
describe Msf::Exploit::Remote::BrowserExploitServer do
55

66
subject(:server) do
7-
mod = Msf::Exploit.allocate
7+
mod = Msf::Exploit::Remote.allocate
88
mod.extend described_class
99
mod.send(:initialize, {})
1010
mod
@@ -17,6 +17,10 @@
1717
service
1818
end
1919

20+
let(:expected_user_agent) do
21+
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)'
22+
end
23+
2024
let(:profile_name) do
2125
'random'
2226
end
@@ -25,26 +29,22 @@
2529
'linux'
2630
end
2731

28-
let(:expected_user_agent) do
29-
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)'
30-
end
31-
3232
let(:exploit_page) do
3333
server.instance_variable_get(:@exploit_receiver_page)
3434
end
3535

3636
let(:expected_profile) do
3737
{
38-
:source=>'script',
39-
:os_name=>'Windows XP',
40-
:ua_name=>'MSIE',
41-
:ua_ver=>'8.0',
42-
:arch=>'x86',
43-
:office=>'null',
44-
:activex=>'true',
45-
:proxy=>false,
46-
:language=>'en-us',
47-
:tried=>true
38+
:source =>'script',
39+
:os_name =>'Windows XP',
40+
:ua_name =>'MSIE',
41+
:ua_ver =>'8.0',
42+
:arch =>'x86',
43+
:office =>'null',
44+
:activex =>'true',
45+
:proxy =>false,
46+
:language =>'en-us',
47+
:tried => true
4848
}
4949
end
5050

@@ -296,6 +296,43 @@
296296
server.on_request_uri(cli, request)
297297
end
298298
end
299+
300+
301+
describe '#get_payload' do
302+
let(:cli) {
303+
Rex::Socket::Tcp
304+
}
305+
306+
before(:each) do
307+
allow(cli).to receive(:peerhost).and_return('0.0.0.0')
308+
allow(cli).to receive(:peerport).and_return(4444)
309+
end
310+
311+
let(:encoded) { '@EXE@' }
312+
313+
let(:x86_payload) {
314+
double(:encoded => encoded, :arch => ['x86'])
315+
}
316+
317+
let(:x86_64_payload) {
318+
double(:encoded => encoded, :arch => ['x86_64'])
319+
}
320+
321+
context 'when the payload supports the visitor\'s browser architecture' do
322+
it 'returns a payload' do
323+
allow(server).to receive(:regenerate_payload).and_return(x86_payload)
324+
expect(server.get_payload(cli, expected_profile)).to eq(encoded)
325+
end
326+
end
327+
328+
context 'when the payload does not support the visitor\'s browser architecture' do
329+
it 'raises a BESException' do
330+
allow(server).to receive(:regenerate_payload).and_return(x86_64_payload)
331+
expect{server.get_payload(cli, expected_profile)}.to raise_error(Msf::Exploit::Remote::BrowserExploitServer::BESException)
332+
end
333+
end
334+
end
335+
299336
end
300337

301338
end

0 commit comments

Comments
 (0)