-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.js
More file actions
executable file
·382 lines (316 loc) · 10.2 KB
/
utils.js
File metadata and controls
executable file
·382 lines (316 loc) · 10.2 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*
* Generic utillities to make the life of a javascript exploit developer easier
*/
// Errors
var ERR_NOT_NUM = function(arg){throw arg+" must be a numeric value";};
var ERR_NOT_DEF = function(arg){throw arg+" is not defined";};
var ERR_NOT_EXPECTED = function(arg){throw arg+" is not the expected value for the provided logic flow";};
var ERR_OVERFLOW = function(arg){throw arg+" would overflow the target";};
var ERR_UNSUPPORTED = function(arg){throw arg+" is not supported at this time"};
// PWM-like sleep, useful to prevent gc()
function millis(ms)
{
var t1 = Date.now();
while(Date.now() - t1 < ms)
{
//Simply wait
}
}
/*
* Generic Hex-Dec operations
*/
function hex(b) {
return ('0' + b.toString(16)).substr(-2);
}
// Convert a decimal to a hex string
function hexify(intval = 0)
{
return '0x'+parseInt(intval).toString(16);
}
// Convert a set of bytes into a hex string
function hexlify(bytes) {
var res = [];
for (var i = 0; i < bytes.length; i++)
res.push(hex(bytes[i]));
return res.join('');
}
// Convert a hex string to a set of bytes
function unhexlify(hexstr)
{
if (hexstr.length % 2 == 1)
throw new TypeError("Invalid hex string");
var bytes = new Uint8Array(hexstr.length / 2);
for (var i = 0; i < hexstr.length; i += 2)
bytes[i/2] = parseInt(hexstr.substr(i, 2), 16);
return bytes;
}
/*
* Functions for dealing with exploit offsets and addresses
*/
// Calculate the dyld shared cache its randomization slide and return it
var dyld_cache_slide = function(addr_off = 0, addr_leak = 0)
{
dyld_cache_slide = function()
{
var slide = addr_leak - addr_off;
return slide >= 0 ? slide : 0;
};
};
// Get a slid address
var slideaddr = function(addr = 0)
{
return addr + dyld_cache_slide();
};
// Get the unslid address
var unslideaddr = function(addr = 0)
{
return addr - dyld_cache_slide();
};
/*
* Logging functionality
*/
//window.alert = function(){};
var log = {
debug: false,
debugserver: location.protocol+'//'+location.host,
debugroute: '/debug/?msg=',
error: function(msg='')
{
alert("[X] "+msg);
console.error(msg);
throw new Error(msg);
},
warn: function(msg='')
{
alert("[!] "+msg);
console.warn(msg);
},
info: function(msg = '')
{
alert("[i] "+msg);
console.info(msg);
},
debug: function(msg='')
{
if(this.debug)
{
this.info(msg);
var req = new XMLHttpRequest();
req.open('GET', this.debugserver+this.debugroute+msg, false);
req.send(null);
}
}
};
/*
* Assertions
*/
// Compare and assert if zero
function assert(rule = true)
{
if(!rule)
{
log.error("Assertion failed.");
}
}
// Assert if object is undefined.
function assert_defined(obj)
{
if((typeof obj !== 'undefined') != true)
{
log.error("Assertion failed: Object is not defined");
}
}
function detect_device()
{
var gpu = function()
{
function parseGPU(gpu) {
if(!gpu) return "Unknown GPU";
if(gpu) gpu = gpu.split('Apple ');
if(gpu.length > 1) gpu = gpu[1].split(' GPU')[0];
return gpu || "unknown";
}
var ctx = document.createElement('canvas');
ctx.gl = ctx.getContext('experimental-webgl');
ctx.ext = ctx.gl.getExtension('WEBGL_debug_renderer_info');
var _gpu = parseGPU(ctx.gl.getParameter(ctx.ext.UNMASKED_RENDERER_WEBGL));
ctx = undefined;
return _gpu;
}();
var width = window.screen.width || 0;
var height = window.screen.height || 0;
var t = "unknown";
if(navigator.userAgent.indexOf('iPhone') > -1) {
t = "iPhone";
}
if(navigator.userAgent.indexOf('iPad') > -1) {
t = "iPad";
}
if(navigator.userAgent.indexOf('iPod') > -1) {
t = "iPod";
}
if(t === "iPhone") {
if(height <= 480) return ['iPhone 2G', 'iPhone 3', 'iPhone 3GS'];
if(width === 320 && height === 480 && gpu =='A4') return ['iPhone 4'];
if(width === 320 && height === 480 && gpu == 'A5') return ['iPhone 4S'];
if(width === 320 && height === 568 && gpu == 'A5') return ['iPhone 5'];
if(width === 320 && height === 568 && gpu == 'A6') return ['iPhone 5C'];
if(width === 320 && height === 568 && gpu == 'A7') return ['iPhone 5S'];
if(width === 375 && height === 667 && gpu == 'A8') return ['iPhone 6'];
if(width === 414 && height === 736 && gpu == 'A8') return ['iPhone 6+'];
if(width === 375 && height === 667 && gpu == 'A9') return ['iPhone 6S'];
if(width === 414 && height === 736 && gpu == 'A9') return ['iPhone 6S+'];
if(width === 320 && height === 568 && gpu == 'A9') return ['iPhone SE'];
if(width === 375 && height === 667 && gpu == 'A10') return ['iPhone 7'];
if(width === 414 && height === 736 && gpu == 'A10') return ['iPhone 7+'];
if(width === 375 && height === 667 && gpu == 'A11') return ['iPhone 8'];
if(width === 414 && height === 736 && gpu == 'A11') return ['iPhone 8+'];
if(width === 375 && height === 812 && gpu == 'A11') return ['iPhone X'];
if(gpu == "A12") return ['iPhone XR and up.'];
}
else if(t === "iPad") {
/* iPads */
if(width === 768 && height === 1024 && gpu == 'A5') return ['iPad Mini', 'iPad 2'];
if(width === 768 && height === 1024 && gpu == 'A7') return ['iPad Mini 2', 'iPad Mini 3', 'iPad Air'];
if(width === 768 && height === 1024 && gpu == 'A8') return ['iPad Mini 4'];
if(width === 768 && height === 1024 && gpu == 'A5X') return ['iPad 3'];
if(width === 768 && height === 1024 && gpu == 'A6X') return ['iPad 4'];
if(width === 768 && height === 1024 && gpu == 'A8X') return ['iPad Air 2'];
if(width === 768 && height === 1024 && gpu == 'A9X') return ['9.7-inch iPad Pro'];
if(width === 768 && height === 1024 && gpu == 'A10') return ['iPad 6 (Cellular)'];
if(width === 834 && height === 1112 && gpu == 'A10X') return ['10.5-inch iPad Pro'];
if(width === 1024 && height === 1366 && gpu == 'A10X') return ['12.9-inch iPad Pro'];
} else {
if(width === 272 && height === 340 && gpu == 'S1') return ['Watch 1 38mm'];
if(width === 312 && height === 390 && gpu == 'S1') return ['Watch 1 42mm'];
if(width === 272 && height === 340 && gpu == 'S1P') return ['Watch 1 sport 38mm'];
if(width === 312 && height === 390 && gpu == 'S1P') return ['Watch 1 sport 42mm'];
if(width === 272 && height === 340 && gpu == 'S2') return ['Watch 2 38mm'];
if(width === 312 && height === 390 && gpu == 'S2') return ['Watch 2 42mm'];
if(width === 272 && height === 340 && gpu == 'S3') return ['Watch 3 38mm'];
if(width === 312 && height === 390 && gpu == 'S3') return ['Watch 3 42mm'];
}
return ["Unknown device"];
}
function detect_os()
{
return {
mobile: (typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1),
webkit: parseFloat(/AppleWebKit\/([\d.]+)/.exec(navigator.userAgent)[1]) || 0,
safari: window.navigator.userAgent.indexOf('Safari') > -1,
version: function()
{
var match = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
if(match) {
var version = [
parseInt(match[1], 10),
parseInt(match[2], 10),
parseInt(match[3] || 0, 10)
];
return parseFloat(version[0]+'.'+version[1]+version[2]);
} else {
return "unknown";
}
}()
};
}
function fingerprint_osdevice()
{
if(typeof window.currentdevice !== 'undefined')
{
return window.currentdevice;
}
var _device = detect_device();
var _os = detect_os();
window.currentdevice = {device: _device, os: _os};
return {device: _device, os: _os};
}
var supported_targets = [
];
var target = function target(device, osvers, webkitvers)
{
return {device: device, osvers: osvers, webkit: webkitvers};
};
function SupportTarget(device, osvers, webkitvers)
{
supported_targets.push(new target(device, osvers, webkitvers));
}
function issupported()
{
var d = fingerprint_osdevice();
for(i = 0; i < supported_targets.length; i++)
{
var tgt = supported_targets[i];
if(d.device.includes(tgt.device) && (tgt.osvers == d.os.version) && ((d.webkit == tgt.webkit) || tgt.webkit == "any"))
{
return true;
}
}
return false;
}
function assert_offsets()
{
function missing_offsets(req='iOS version'){
var btn = document.querySelector("#btn");
btn.innerText = "unsupported";
btn.setAttribute('class','unsupported');
btn.onclick = function(){alert('You need to add offsets for your '+req+'.');};
throw "Missing offsets";
}
// Real dirty, this should be based off device detection, see utils.js
// The offsets here are from 12.0.1 iPhone 6S
if(typeof offsets[currentdevice.os.version] === 'undefined')
{
missing_offsets();
}
if(typeof offsets[currentdevice.os.version][currentdevice.device[0]] === 'undefined')
{
missing_offsets("device");
}
}
function str2ab(str = '')
{
return new TextEncoder().encode(str).buffer;
};
function load_shellcode(url = '', async = true, name='shellcode_view', callback = function(req){})
{
var req = new XMLHttpRequest();
req.open("GET", url, async);
if(async){
req.responseType = "arraybuffer";
if(callback){
req.addEventListener('load', callback);
req.send(null);
return;
} else {
req.send(null);
}
}
else {
req.send(null);
return req.responseText;
}
};
var spectre = (typeof SharedArrayBuffer !== 'undefined');
var FPO = spectre ? 0x18 : 0x10;
function makejitfunc()
{
function target(num) {
for (var i = 2; i < num; i++) {
if (num % i === 0) {
return false;
}
}
return true;
}
for (var i = 0; i < 1000; i++) {
target(i);
}
for (var i = 0; i < 1000; i++) {
target(i);
}
for (var i = 0; i < 1000; i++) {
target(i);
}
return target;
}