Esoteric Hooks
Esoteric Hooks
Esoteric Hooks
Only one Chinese Forum site talks about the Shim Engine hooks:
◦ http://bbs.pediy.com/showpost.php?p=1199075&postcount=1
◦ Accurate for Windows 8
Enhanced in Windows 8
◦ Supported by the kernel and even boot
loader
Loader (Ntdll.dll) parses the API Set during any DLL load operation
◦ LdrpApplyFileNameRedirection
DLL names include API Set Name (api-ms-win) and Version (LX-X-X)
1/26/2016 COPYRIGHT 2015 ALEX IONESCU. ALL RIGHTS RESERVED. 12
API Set Redirection (Win 8)
Windows 8 introduces 365 new redirected DLLs
Includes concept of “Extension” Sets, not just “API” Sets
Extensions are used by API Set libraries based on their presence (using
ApiSetQueryApiSetPresence) and provide functionality that may exist
only on certain operating systems
◦ New loader function: LdrpPreprocessDllName
nameString.Length = (USHORT)valueEntry->NameLength;
nameString.Buffer = (PWCHAR)((ULONG_PTR)ApiSetMap + valueEntry->NameOffset);
valueEntry++;
}
nsEntry++;
}
Parse the API Set Map and locate the API Set Host that contains the API to
hook
Replace the string associated with the Value Entry with your own custom
DLL
Careful: Value Entry Names are aliased! Changing the *buffer* will redirect
multiple API Set Hosts
Instead, allocate additional memory past the end of the API Set Map, and
change the offset to your new blob
There is a registry key that allows installing custom API Set Schemas
Many parts of the kernel query for “API Set Presence” and optionally
call certain add-on/plug-in functions, if present
The right API Set DLL can allow hooking all system calls, process
creation/deletion, thread creation/destruction, and more
include ksamd64.inc
EXTERN InstrumentationCHook:PROC
mov rdx, r11 ; These comments are for the copy pastas out there
jmp r10
end
When CFG was introduced, the following new fields were added to
IMAGE_LOAD_CONFIG_DIRECTORY:
◦ ULONGLONG GuardCFCheckFunctionPointer;
◦ ULONGLONG GuardCFFunctionTable;
◦ ULONGLONG GuardCFFunctionCount;
◦ DWORD GuardFlags;
include ksamd64.inc
EXTERN CfgCHook:PROC
ret
end
This override can be set early at boot by the kernel, based on the
following registry modification
◦ HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\ImageExecutionOptions = 1 (REG_DWORD)