[C] 纯文本查看 复制代码
STATIC CONST BYTE KexpNtOpenKeyHook32_Win7[] = {
0xE8, 0x00, 0x00, 0x00, 0x00, 0x58, 0x83, 0xC0, 0x06, 0xEB, 0x43, 0x00, 0x38, 0x00, 0x3A, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7B, 0x00, 0x56, 0x00, 0x78, 0x00, 0x4B, 0x00, 0x65, 0x00, 0x78, 0x00,
0x50, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x61, 0x00, 0x74, 0x00,
0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x56, 0x00, 0x69, 0x00, 0x72, 0x00, 0x74, 0x00, 0x75, 0x00,
0x61, 0x00, 0x6C, 0x00, 0x4B, 0x00, 0x65, 0x00, 0x79, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x80, 0x38,
0x00, 0x75, 0x2A, 0x64, 0x8B, 0x15, 0x30, 0x00, 0x00, 0x00, 0x8B, 0x52, 0x10, 0x81, 0x62, 0x08,
0xFF, 0xBF, 0xFF, 0xFF, 0x8B, 0x54, 0x24, 0x0C, 0x8B, 0x4A, 0x04, 0x85, 0xC9, 0x74, 0x0E, 0xFE,
0x00, 0x8D, 0x48, 0x01, 0x83, 0xC0, 0x09, 0x89, 0x41, 0x04, 0x89, 0x4A, 0x08, 0xB8, 0xB6, 0x00,
0x00, 0x00, 0xBA, 0x00, 0x03, 0xFE, 0x7F, 0x83, 0x3A, 0x00, 0x74, 0x05, 0xFF, 0x12, 0xC2, 0x0C,
0x00, 0xB8, 0x0F, 0x00, 0x00, 0x00, 0x31, 0xC9, 0x8D, 0x54, 0x24, 0x04, 0x64, 0xFF, 0x15, 0xC0,
0x00, 0x00, 0x00, 0x83, 0xC4, 0x04, 0xC2, 0x0C, 0x00
};
// KexpNtOpenKeyHook64:
// cmp [.AlreadyRewritten], 0 ; Check if already rewrote key name
// jnz .DontRewrite ; If so, just syscall
//
// ; Clear RTL_USER_PROCESS_PARAMETERS_IMAGE_KEY_MISSING flag in ProcessParameters.
// ; The flag is set by the kernel to indicate that there is no IFEO key. and if it
// ; is set, the NTDll loader won't try to open the IFEO key and won't call this hook
// ; in the right way to cause proper VxKex initialization.
// mov rax, gs:0x60 ; rax = PEB address
// mov rax, [rax+0x20] ; rax = Peb->ProcessParmameters
// and dword [rax+8], ~0x4000 ; ProcessParameters->Flags &= ~RTL_USER_PROCESS_PARAMETERS_IMAGE_KEY_MISSING
//
// mov rax, [r8+0x08] ; r8 = ObjectAttributes->RootDirectory
// test eax, eax ; if RootDirectory == NULL
// jz .DontRewrite ; then don't rewrite (because it isn't the call
// ; that we want to rewrite)
// ; Now we are definitely rewriting.
// inc [.AlreadyRewritten] ; flag to future calls of this hook
// lea rax, [.PropagationVirtualKeyName] ; rax = &PropagationVirtualKeyName
// mov [rax+0x08], rax
// add qword [rax+0x08], 16 ; : PropagationVirtualKeyName->Buffer = &PropagationVirtualKeyString
// mov [r8+0x10], rax ; ObjectAttributes->ObjectName = &PropagationVirtualKeyName
//
// .DontRewrite:
// ; This is just the Ntopenkey syscall as usual.
// mov r10, rcx
// mov eax, 0x0F
// syscall
// ret
//
// .AlreadyRewritten: db 0
//
// ; NOPs for alignment of the UNICODE_STRING structure
// nop
// nop
// nop
// nop
// nop
//
// ; UNICODE_STRING structure
// .PropagationVirtualKeyName:
// dw 0x38 ; Length
// dw 0x3A ; MaximumLength
// dd 0 ; (padding)
// dq 0 ; pointer, gets filled out by code
// .PropagationVirtualKeyString
// ; {VxKexPropagationVirtualKey}
// dw '{', 'V', 'x', 'K', 'e', 'x', 'P', 'r', 'o', 'p', 'a', 'g', 'a', 't'
// dw 'i', 'o', 'n', 'V', 'i', 'r', 't', 'u', 'a', 'l', 'K', 'e', 'y', '}', 0
//
STATIC CONST BYTE KexpNtOpenKeyHook64_Win7[] = {
0x80, 0x3D, 0x43, 0x00, 0x00, 0x00, 0x00, 0x75, 0x36, 0x65, 0x48, 0x8B, 0x04, 0x25, 0x60, 0x00,
0x00, 0x00, 0x48, 0x8B, 0x40, 0x20, 0x81, 0x60, 0x08, 0xFF, 0xBF, 0xFF, 0xFF, 0x49, 0x8B, 0x40,
0x08, 0x85, 0xC0, 0x74, 0x1A, 0xFE, 0x05, 0x1F, 0x00, 0x00, 0x00, 0x48, 0x8D, 0x05, 0x1E, 0x00,
0x00, 0x00, 0x48, 0x89, 0x40, 0x08, 0x48, 0x83, 0x40, 0x08, 0x10, 0x49, 0x89, 0x40, 0x10, 0x49,
0x89, 0xCA, 0xB8, 0x0F, 0x00, 0x00, 0x00, 0x0F, 0x05, 0xC3, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90,
0x38, 0x00, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7B, 0x00, 0x56, 0x00, 0x78, 0x00, 0x4B, 0x00, 0x65, 0x00, 0x78, 0x00, 0x50, 0x00, 0x72, 0x00,
0x6F, 0x00, 0x70, 0x00, 0x61, 0x00, 0x67, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00,
0x6E, 0x00, 0x56, 0x00, 0x69, 0x00, 0x72, 0x00, 0x74, 0x00, 0x75, 0x00, 0x61, 0x00, 0x6C, 0x00,
0x4B, 0x00, 0x65, 0x00, 0x79, 0x00, 0x7D, 0x00, 0x00, 0x00
};