freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

SysWhispers2:通过直接系统调用实现AVEDR绕过
2021-01-26 17:11:00

SysWhispers2

SysWhispers2可以生成能够进行直接系统调用的Heder/ASM文件植入来帮助广大研究人员实现AV/EDR绕过。

当前的SysWhispers2支持所有的核心系统调用,并且在该项目的example-output/目录下提供了预生成的样本文件。

SysWhispers1和SysWhispers2之间的区别

它的用法与SysWhispers1几乎相同,但现在我们无需指定要支持哪些版本的Windows。这两个版本之间的大多数改变都是用户不可见的,并且不再依赖于@j00ru系统调用表,而使用的是@modexpblog推广的“按系统调用地址排序”技术,这将大大减少系统调用存根的大小。

SysWhispers2中的具体实现是基于@modexpblog代码的变种版本,其中的一个区别在于函数名哈希在每一代上都是随机的。@ElephantSe4l之前也发布过这种技术,并基于C++17实现了类似的功能,值得一看。

原来的SysWhispers存储库仍然可以访问,但将来可能会被弃用。

技术介绍

各种安全产品会在用户模式API函数中放置钩子,这就允许它们将执行数据流重定向到它们的引擎并检测可疑行为。ntdll.dll中能够执行系统调用的函数仅由几个汇编指令组成,因此我们可以在自己的移植程序中重新实现它们以绕过这些安全产品设置的钩子。

在SysWhispers的帮助下,红队研究人员可以在核心内核映像(ntoskrnl.exe)中针对任何系统调用生成Header/ASM文件,Header中还会包含必要的类型定义。

工具安装

广大研究人员可以使用下列命令将该项目源码克隆至本地,并完成工具的安装和配置:

> git clone https://github.com/jthuraisamy/SysWhispers2.git

> cd SysWhispers2

> py .\syswhispers.py --help

工具使用

命令行:

# 针对所有支持的Windows操作系统版本导出所有兼容的函数功能(具体请查看example-output/目录)

py .\syswhispers.py --preset all -o syscalls_all

 

# 导出常见函数

py .\syswhispers.py --preset common -o syscalls_common

 

# 导出兼容所有版本的NtProtectVirtualMemory和NtWriteVirtualMemory

py .\syswhispers.py --functions NtProtectVirtualMemory,NtWriteVirtualMemory -o syscalls_mem

脚本输出

PS C:\Projects\SysWhispers2> py .\syswhispers.py --preset common --out-file syscalls_common

 

                  .                         ,--.

,-. . . ,-. . , , |-. o ,-. ,-. ,-. ,-. ,-.    /

`-. | | `-. |/|/  | | | `-. | | |-' |   `-. ,-'  

`-' `-| `-' ' '   ' ' ' `-' |-' `-' '   `-' `---

     /|                     |  @Jackson_T                 

    `-'                     '  @modexpblog, 2021

 

SysWhispers2: Why call the kernel when you can whisper?

 

Common functions selected.

 

Complete! Files written to:

        syscalls_common.h

        syscalls_common.c

        syscalls_common_stubs.asm

CreateRemoteThread DLL注入样例

py .\syswhispers.py -f NtAllocateVirtualMemory,NtWriteVirtualMemory,NtCreateThreadEx -o syscalls
#include <Windows.h>

 

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 <Windows.h>

#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选项将会使用下列函数创建一个Header/ASM对:

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)

导入Visual Studio

将生成的H/C/ASM文件拷贝到项目目录中。

在Visual Studio中,点击“Project → Build Customizations...”,并启用MASM。

在Solution Explorer中,将.h和.c/.asm文件以Header和源文件的形式添加至项目中。

点击ASM文件的属性,将Item Type设置为Microsoft Macro Assembler。

确保项目平台设置为了x64,因为目前还不支持32位项目。

工具限制

目前仅支持64位Windows系统;

目前还不支持来自图像子系统(sys)的系统调用;

已在Visual Studio 2019(v14)Window 10 SDK中进行了测试;

许可证协议

本项目的开发与发布遵循Apache License 2.0开源许可证协议。

项目地址

SysWhispers2:【GitHub传送门

# 绕过杀毒软件 # AVEDR绕过
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者
文章目录