How HWSyscalls works
masterHWSyscalls is a method for executing indirect syscalls designed to bypass EDR/AV detections that look for direct access to ntdll.
Unlike standard indirect syscalls that jump directly to ntdll, HWSyscalls uses three components to create a synthetic trampoline in kernel32:
- Hardware Breakpoints (HWBP) and Vectored Exception Handler (VEH): Used to control the execution flow.
- HalosGate: Used to locate syscall numbers (SSNs) and addresses.
- Synthetic Trampoline: Created in
kernel32using hardware breakpoints to ensure the execution flow appears legitimate.
The implementation includes stack manipulation magic to ensure the stack remains unwindable. When a syscall is triggered, it hits a hardware breakpoint in an NTAPI function, creates a new stack frame, and sets the return address to a gadget (e.g., ADD RSP, 68; RET) found in kernel32 or kernelbase. This allows the stack to unwind naturally through kernel32 on the way back from ntdll.