rad9800 / TamperingSyscalls
- четверг, 11 августа 2022 г. в 00:33:17
TamperingSyscalls is a 2 part novel project consisting of argument spoofing and syscall retrival which both abuse EH in order to subvert EDRs. This project consists of both of these projects in order to provide an alternative solution to direct syscalls.
Tampering with syscalls.
SetUnhandledExceptionFilter( OneShotHardwareBreakpointHandler );
0f05
on the Dr0 register.
We can locate the address of the syscall stub with this quick memory byte search.BYTE stub[] = { 0x0F, 0x05 };
for( unsigned int i = 0; i < (unsigned int)25; i++ )
{
if( memcmp( (LPVOID)((DWORD_PTR)function + i), stub, 2 ) == 0 ) {
return (LPVOID)((DWORD_PTR)function + i);
}
}
if( ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_SINGLE_STEP )
if( ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_SINGLE_STEP )
{
if( ExceptionInfo->ContextRecord->Dr7 & 1 ) {
if( ExceptionInfo->ContextRecord->Rip == ExceptionInfo->ContextRecord->Dr0 ) {
ExceptionInfo->ContextRecord->Dr0 = 0;
mov r10, rcx
as the RCX register is destroyed in the next instructions.case NTMAPVIEWOFSECTION_ENUM:
ExceptionInfo->ContextRecord->R10 =
(DWORD_PTR)((NtMapViewOfSectionArgs*)(StateArray[EnumState].arguments))->SectionHandle;
ExceptionInfo->ContextRecord->Rdx =
(DWORD_PTR)((NtMapViewOfSectionArgs*)(StateArray[EnumState].arguments))->ProcessHandle;
ExceptionInfo->ContextRecord->R8 =
(DWORD_PTR)((NtMapViewOfSectionArgs*)(StateArray[EnumState].arguments))->BaseAddress;
ExceptionInfo->ContextRecord->R9 =
(DWORD_PTR)((NtMapViewOfSectionArgs*)(StateArray[EnumState].arguments))->ZeroBits;
We can see in this example we are fixing the arguments for NtMapViewOfSection.
If you'd like to start to fake EDR telemetry it is possible to modify the p[FunctionName] definitions where they are currently set to NULL.
To generate the required functions, use gen.py
. This supports either:
python gen.py NtOpenSection,NtMapViewOfSection,NtUnmapViewOfSection
It will produce 3 files: TamperingSyscalls.cpp, TamperingSyscalls.h, and main.cpp. You can #include "TamperingSyscalls.h"
into your project. We can call the functions by appending the function name to p, for example pNtOpenSection(...);
We cannot set a breakpoint on NtSetThreadContext or it's variants as this is used to set the debug registers. There is a brief period where the debug registers are set, but this is very small and I do not think we will be detected for holding an open Dr0.
I have published a small blog post, touching upon these techniques. TamperingSyscall's Blog Post