NTSTATUS
TriggerUninitializedMemoryStack(
_In_ PVOID UserBuffer
)
{
ULONG UserValue
=
0
;
ULONG MagicValue
=
0xBAD0B0B0
;
NTSTATUS Status
=
STATUS_SUCCESS;
/
/
/
/
Secure Note: This
is
secure because the developer
is
properly initializing
/
/
UNINITIALIZED_MEMORY_STACK to NULL
and
checks
for
NULL pointer before calling
/
/
the callback
/
/
UNINITIALIZED_MEMORY_STACK UninitializedMemory
=
{
0
};
/
/
安全版本: 栈变量初始化了
/
/
/
/
Vulnerability Note: This
is
a vanilla Uninitialized Memory
in
Stack vulnerability
/
/
because the developer
is
not
initializing
'UNINITIALIZED_MEMORY_STACK'
structure
/
/
before calling the callback when
'MagicValue'
does
not
match
'UserValue'
/
/
UNINITIALIZED_MEMORY_STACK UninitializedMemory;
/
/
不安全版本: 栈变量未初始化
PAGED_CODE();
__try
{
/
/
/
/
Verify
if
the
buffer
resides
in
user mode
/
/
ProbeForRead(UserBuffer, sizeof(UNINITIALIZED_MEMORY_STACK), (ULONG)__alignof(UCHAR));
/
/
/
/
Get the value
from
user mode
/
/
UserValue
=
*
(PULONG)UserBuffer;
DbgPrint(
"[+] UserValue: 0x%p\n"
, UserValue);
DbgPrint(
"[+] UninitializedMemory Address: 0x%p\n"
, &UninitializedMemory);
/
/
/
/
Validate the magic value
/
/
if
(UserValue
=
=
MagicValue) {
UninitializedMemory.Value
=
UserValue;
UninitializedMemory.Callback
=
&UninitializedMemoryStackObjectCallback;
}
DbgPrint(
"[+] UninitializedMemory.Value: 0x%p\n"
, UninitializedMemory.Value);
DbgPrint(
"[+] UninitializedMemory.Callback: 0x%p\n"
, UninitializedMemory.Callback);
DbgPrint(
"[+] Triggering Uninitialized Memory in Stack\n"
);
/
/
/
/
Call the callback function
/
/
if
(UninitializedMemory.Callback)
/
/
在此处判断回调函数是否为
0
,否则可利用
0
页内存,
{
UninitializedMemory.Callback();
}
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
Status
=
GetExceptionCode();
DbgPrint(
"[-] Exception Code: 0x%X\n"
, Status);
}
return
Status;
}