RustVEHSyscalls
A Rust port of LayeredSyscall — performs indirect syscalls while generating legitimate API call stack frames by abusing VEH.
Install / Use
/learn @safedv/RustVEHSyscallsREADME
RustVEHSyscalls
RustVEHSyscalls is a Rust-based port of the LayeredSyscall project. This tool performs indirect syscalls while generating legitimate API call stack frames by abusing Vectored Exception Handling (VEH) to bypass user-land EDR hooks in Windows.
How It Works
RustVEHSyscalls performs indirect syscalls by abusing Vectored Exception Handling (VEH) to generate legitimate API call stack frames. By calling a standard Windows API function and setting a hardware breakpoint within it, the function's call stack is captured. This breakpoint then lets VEH redirect the process to a syscall wrapper in ntdll.dll, preserving the original API's call stack structure. This approach enables syscalls to appear as if they originate from legitimate Windows API calls.
Setup and Cleanup Functions
RustVEHSyscalls provides functions to initialize and clean up the Vectored Exception Handling environment necessary for syscall interception. These functions establish the hooks needed to capture and handle indirect syscalls, ensuring clean operation and teardown.
initialize_hooks():- Sets up two vectored exception handlers for adding and managing hardware breakpoints in the system call path. This function allocates memory for the CPU context and retrieves
ntdll.dll's base and end addresses for tracing purposes.
- Sets up two vectored exception handlers for adding and managing hardware breakpoints in the system call path. This function allocates memory for the CPU context and retrieves
destroy_hooks():- Cleans up by removing the added vectored exception handlers.
Syscall Wrapper
RustVEHSyscalls provides a syscall! macro that wraps several key steps:
- Resolving the Syscall Address and SSN: The macro uses the PEB to locate
ntdll.dlland parses its Exception Directory and Export Address Table to retrieve both the syscall’s address and System Service Number (SSN). - Setting Hardware Breakpoint: Once the syscall address and SSN are resolved, the macro sets a hardware breakpoint, allowing RustVEHSyscalls to intercept the syscall execution.
- Invoking the Syscall: Finally, the macro invokes the syscall with the specified parameters, completing the indirect syscall path.
Usage
To initialize syscall interception, call initialize_hooks() at the start of your main function and destroy_hooks() to clean up once you're done. You can also adjust the legitimate call stack by modifying the demofunction() in the hooks.rs module.
/// Example function designed to maintain a clean call stack.
/// This function can be modified to call different legitimate Windows APIs.
pub unsafe extern "C" fn demofunction() {
MessageBoxA(null_mut(), null_mut(), null_mut(), 0);
}
Example: Calling NtCreateUserProcess
The following example demonstrates how to invoke the NtCreateUserProcess syscall. Full test code is available in lib.rs.
fn main() {
initialize_hooks(); // Set up necessary hooks
// Initialize all necessary parameters here...
// Call NtCreateUserProcess syscall
let status = syscall!(
"NtCreateUserProcess",
OrgNtCreateUserProcess,
&mut process_handle,
&mut thread_handle,
desired_access,
desired_access,
null_mut(),
null_mut(),
0,
0,
process_parameters,
&mut create_info,
attribute_list
);
destroy_hooks(); // Clean up hooks when done
}
Disclaimer
This project is intended for educational and research purposes only. Use it responsibly, as any misuse is solely your responsibility—not mine! Always follow ethical guidelines and legal frameworks when doing security research (and, you know, just in general).
Credits
Special thanks to:
- LayeredSyscall by White Knight Labs for their work.
- Resolving System Service Numbers Using The Exception Directory by MDsec for their insights on resolving SSNs.
Contributing
Contributions are welcome! If you want to help improve RustVEHSyscalls or report bugs, feel free to open an issue or a pull request in the repository.
Related Skills
node-connect
350.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
