jthuraisamy/SysWhispers
GitHub: jthuraisamy/SysWhispers
SysWhispers 是一个生成直接系统调用头文件和汇编代码的工具,用于绕过 AV/EDR 的用户态 API Hook 检测。
Stars: 1992 | Forks: 275
# SysWhispers
SysWhispers 通过生成头文件/ASM文件来辅助规避检测,植入程序可以利用这些文件进行直接系统调用。
支持从 Windows XP 到 Windows 10 19042 (20H2) 的所有核心系统调用。示例生成文件可在 `example-output/` 文件夹中找到。
## 简介
各种安全产品在用户模式 API 中放置钩子,使其能够将执行流重定向到其引擎并检测可疑行为。`ntdll.dll` 中执行系统调用的函数仅由几条汇编指令组成,因此在植入程序中重新实现它们可以绕过那些安全产品钩子的触发。这项技术由 [@Cn33liz](https://twitter.com/Cneelis) 推广,他的 [blog post](https://outflank.nl/blog/2019/06/19/red-team-tactics-combining-direct-system-calls-and-srdi-to-bypass-av-edr/) 有更多值得阅读的技术细节。
SysWhispers 为红队人员提供了为核心内核镜像 (`ntoskrnl.exe`) 中的任何系统调用生成头文件/ASM文件对的能力,支持从 XP 开始的任何 Windows 版本。头文件还将包含必要的类型定义。
此工具与 [Dumpert](https://github.com/outflanknl/Dumpert) POC 之间的主要实现差异在于,它不调用 `RtlGetVersion` 来查询操作系统版本,而是通过直接查询 PEB 在汇编代码中完成。这样做的好处是能够调用一个支持多个 Windows 版本的函数,而不是调用多个各自仅支持一个版本的函数。
## 安装
```
> git clone https://github.com/jthuraisamy/SysWhispers.git
> cd SysWhispers
> pip3 install -r .\requirements.txt
> py .\syswhispers.py --help
```
## 用法与示例
### 命令行
```
# 导出所有函数,并兼容所有支持的 Windows 版本(参见 example-output/)。
py .\syswhispers.py --preset all -o syscalls_all
# 仅导出常见函数,并兼容 Windows 7、8 和 10。
py .\syswhispers.py --preset common -o syscalls_common
# 导出 NtProtectVirtualMemory 和 NtWriteVirtualMemory,并兼容所有版本。
py .\syswhispers.py --functions NtProtectVirtualMemory,NtWriteVirtualMemory -o syscalls_mem
# 导出所有函数,并兼容 Windows 7、8 和 10。
py .\syswhispers.py --versions 7,8,10 -o syscalls_78X
```
### 脚本输出
```
PS C:\Projects\SysWhispers> py .\syswhispers.py --preset common --out-file syscom
, , ,_ /_ . , ,_ _ ,_ ,
_/_)__(_/__/_)__/_/_/ / (__/__/_)__/_)__(/__/ (__/_)__
_/_ /
(/ / @Jackson_T, 2019
SysWhispers: Why call the kernel when you can whisper?
Common functions selected.
Complete! Files written to:
syscom.asm
syscom.h
```
### 经典 `CreateRemoteThread` DLL 注入的前后对比示例
```
py .\syswhispers.py -f NtAllocateVirtualMemory,NtWriteVirtualMemory,NtCreateThreadEx -o syscalls
```
```
#include
void InjectDll(const HANDLE hProcess, const char* dllPath)
{
LPVOID lpBaseAddress = VirtualAllocEx(hProcess, NULL, strlen(dllPath), MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
LPVOID lpStartAddress = GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryA");
WriteProcessMemory(hProcess, lpBaseAddress, dllPath, strlen(dllPath), nullptr);
CreateRemoteThread(hProcess, nullptr, 0, (LPTHREAD_START_ROUTINE)lpStartAddress, lpBaseAddress, 0, nullptr);
}
```
```
#include
#include "syscalls.h" // Import the generated header.
void InjectDll(const HANDLE hProcess, const char* dllPath)
{
HANDLE hThread = NULL;
LPVOID lpAllocationStart = nullptr;
SIZE_T szAllocationSize = strlen(dllPath);
LPVOID lpStartAddress = GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryA");
NtAllocateVirtualMemory(hProcess, &lpAllocationStart, 0, (PULONG)&szAllocationSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
NtWriteVirtualMemory(hProcess, lpAllocationStart, (PVOID)dllPath, strlen(dllPath), nullptr);
NtCreateThreadEx(&hThread, GENERIC_EXECUTE, NULL, hProcess, lpStartAddress, lpAllocationStart, FALSE, 0, 0, 0, nullptr);
}
```
## 常用函数
使用 `--preset common` 开关将创建一个包含以下函数的头文件/ASM文件对:
## 导入 Visual Studio
1. 将生成的 H/ASM 文件复制到项目文件夹中。
2. 在 Visual Studio 中,转到 *项目* → *生成自定义...* 并启用 MASM。
3. 在 *解决方案资源管理器* 中,分别将 .h 和 .asm 文件作为头文件和源文件添加到项目中。
4. 转到 ASM 文件的属性,将 *项类型* 设置为 *Microsoft Macro Assembler*。
5. 确保项目平台设置为 x64。目前不支持 32 位项目。
## 注意事项与限制
- 目前仅支持 64 位 Windows。
- 不支持来自图形子系统 (`win32k.sys`) 的系统调用。
- 在 Visual Studio 2019 (v142) 和 Windows 10 SDK 上测试通过。
## 故障排除
- Python 脚本中出现 `ModuleNotFoundError`。
- 确保已使用 `pip3 install -r requirements.txt` 安装所需模块。
- 类型重定义错误:如果 `syscalls.h` 中的 typedef 已被定义,项目可能无法编译。
- 确保仅包含所需的函数(即 `--preset all` 很少是必要的)。
- 如果某个 typedef 已在另一个使用的头文件中定义,则可以将其从 `syscalls.h` 中移除。
## 致谢
此脚本由 [@Jackson_T](https://twitter.com/Jackson_T) 开发,但建立在许多其他人的工作之上:
- [@j00ru](https://twitter.com/j00ru) 以机器可读格式维护系统调用号。
- [@FoxHex0ne](https://twitter.com/FoxHex0ne) 以机器可读格式编目了许多函数原型和 typedef。
- [@PetrBenes](https://twitter.com/PetrBenes)、[NTInternals.net team](https://undocumented.ntinternals.net/) 和 [MSDN](https://docs.microsoft.com/en-us/windows/) 提供了额外的原型和 typedef。
- [@Cn33liz](https://twitter.com/Cneelis) 提供了最初的 [Dumpert](https://github.com/outflanknl/Dumpert) POC 实现。
特别感谢 [@Dcept905](https://twitter.com/Dcept905) 的测试和建议。
## 相关文章与项目
- [@0x00dtm](https://twitter.com/0x00dtm): [Userland API Monitoring and Code Injection Detection](https://0x00sec.org/t/userland-api-monitoring-and-code-injection-detection/5565)
- [@0x00dtm](https://twitter.com/0x00dtm): [Defeating Userland Hooks (ft. Bitdefender)](https://0x00sec.org/t/defeating-userland-hooks-ft-bitdefender/12496) ([Code](https://github.com/NtRaiseHardError/Antimalware-Research/tree/master/Generic/Userland%20Hooking/AntiHook))
- [@Cn33liz](https://twitter.com/Cneelis): [Combining Direct System Calls and sRDI to bypass AV/EDR](https://outflank.nl/blog/2019/06/19/red-team-tactics-combining-direct-system-calls-and-srdi-to-bypass-av-edr/) ([Code](https://github.com/outflanknl/Dumpert))
- [@mrgretzky](https://twitter.com/mrgretzky): [Defeating Antivirus Real-time Protection From The Inside](https://breakdev.org/defeating-antivirus-real-time-protection-from-the-inside/)
- [@SpecialHoang](https://twitter.com/SpecialHoang): [Bypass EDR’s memory protection, introduction to hooking](https://medium.com/@fsx30/bypass-edrs-memory-protection-introduction-to-hooking-2efb21acffd6) ([Code](https://github.com/hoangprod/AndrewSpecial/tree/master))
- [@xpn](https://twitter.com/_xpn_) 和 [@domchell](https://twitter.com/domchell): [Silencing Cylance: A Case Study in Modern EDRs](https://www.mdsec.co.uk/2019/03/silencing-cylance-a-case-study-in-modern-edrs/)
- [@mrjefftang](https://twitter.com/mrjefftang): [Universal Unhooking: Blinding Security Software](https://threatvector.cylance.com/en_us/home/universal-unhooking-blinding-security-software.html) ([Code](https://github.com/CylanceVulnResearch/ReflectiveDLLRefresher))
- [@spotheplanet](https://twitter.com/spotheplanet): [Full DLL Unhooking with C++](https://ired.team/offensive-security/defense-evasion/how-to-unhook-a-dll-using-c++)
- [@hasherezade](https://twitter.com/hasherezade): [Floki Bot and the stealthy dropper](https://blog.malwarebytes.com/threat-analysis/2016/11/floki-bot-and-the-stealthy-dropper/)
- [@hodg87](https://twitter.com/hodg87): [Latest Trickbot Variant has New Tricks Up Its Sleeve](https://www.cyberbit.com/blog/endpoint-security/latest-trickbot-variant-has-new-tricks-up-its-sleeve/)
- [@hodg87](https://twitter.com/hodg87): [Malware Mitigation when Direct System Calls are Used](https://www.cyberbit.com/blog/endpoint-security/malware-mitigation-when-direct-system-calls-are-used/)
## 许可证
本项目采用 Apache License 2.0 授权。
点击展开函数列表。
- NtCreateProcess (CreateProcess) - NtCreateThreadEx (CreateRemoteThread) - NtOpenProcess (OpenProcess) - NtOpenThread (OpenThread) - NtSuspendProcess - NtSuspendThread (SuspendThread) - NtResumeProcess - NtResumeThread (ResumeThread) - NtGetContextThread (GetThreadContext) - NtSetContextThread (SetThreadContext) - NtClose (CloseHandle) - NtReadVirtualMemory (ReadProcessMemory) - NtWriteVirtualMemory (WriteProcessMemory) - NtAllocateVirtualMemory (VirtualAllocEx) - NtProtectVirtualMemory (VirtualProtectEx) - NtFreeVirtualMemory (VirtualFreeEx) - NtQuerySystemInformation (GetSystemInfo) - NtQueryDirectoryFile - NtQueryInformationFile - NtQueryInformationProcess - NtQueryInformationThread - NtCreateSection (CreateFileMapping) - NtOpenSection - NtMapViewOfSection - NtUnmapViewOfSection - NtAdjustPrivilegesToken (AdjustTokenPrivileges) - NtDeviceIoControlFile (DeviceIoControl) - NtQueueApcThread (QueueUserAPC) - NtWaitForMultipleObjects (WaitForMultipleObjectsEx)标签:0day挖掘, AV绕过, C/C++, Conpot, DNS 反向解析, EDR绕过, FastAPI, Hpfeeds, ntdll.dll, React, Red Teaming, Syscalls, UML, Windows安全, 事务性I/O, 云资产清单, 人工智能, 免杀技术, 内核安全, 安全AI, 安全报告生成, 安全报告生成, 安全测试, 安全测试, 恶意样本开发, 攻击性安全, 攻击性安全, 暴力破解检测, 汇编生成, 用户模式Hook绕过, 私有化部署, 系统调用, 自动回退, 逆向工具, 逆向工程, 防御规避, 风险发现, 高交互蜜罐