-
Notifications
You must be signed in to change notification settings - Fork 11
/
Test.c
119 lines (106 loc) · 3.91 KB
/
Test.c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "Main.h"
#include "Toolset.h"
#include "Detour.h"
// Global declarations
typedef NTSTATUS (NTAPI *NtQueryValueKey_t)( IN HANDLE KeyHandle,
IN PUNICODE_STRING ValueName,
IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
OUT PVOID KeyValueInformation,
IN ULONG Length,
OUT PULONG ResultLength );
typedef NTSTATUS (NTAPI *NtOpenKey_t)( OUT PHANDLE pKeyHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes );
NtQueryValueKey_t ogNtQueryValueKey = NULL;
NtOpenKey_t ogNtOpenKey = NULL;
DetourObject_t* dtNtQueryValueKey = NULL;
DetourObject_t* dtNtOpenKey = NULL;
NTSTATUS
NTAPI
hkNtOpenKey( OUT PHANDLE pKeyHandle,
IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes )
{
char szProcessName[32];
GetProcessName( szProcessName, PsGetCurrentProcess() );
if( !strcmp(szProcessName, "SGLAC.exe") )
{
//KdPrint(("OpenKey: 0x%08x %wZ", *pKeyHandle, ObjectAttributes->ObjectName));
}
return ogNtOpenKey(pKeyHandle, DesiredAccess, ObjectAttributes);
}
NTSTATUS
NTAPI
hkNtQueryValueKey( IN HANDLE KeyHandle,
IN PUNICODE_STRING ValueName,
IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
OUT PVOID KeyValueInformation,
IN ULONG Length,
OUT PULONG ResultLength )
{
char szProcessName[32];
ULONG NameOffset;
ULONG NameSizeOffset;
PULONG KeyNameLength;
WCHAR* KeyNamePtr;
PBYTE key = (PBYTE)KeyValueInformation;
NTSTATUS ntReturn = ogNtQueryValueKey(KeyHandle, ValueName, KeyValueInformationClass, KeyValueInformation, Length, ResultLength);
wchar_t wszNewIdentifier[] = L"x86 Family 12 Model 2 Stepping 3\0";
GetProcessName( szProcessName, PsGetCurrentProcess() );
if( !strcmp(szProcessName, "SGLAC.exe") )
{
switch( KeyValueInformationClass )
{
case KeyValueBasicInformation:
NameOffset = ((ULONG)&(((PKEY_VALUE_BASIC_INFORMATION)key)->Name)) - ((ULONG)key);
NameSizeOffset = ((ULONG)&(((PKEY_VALUE_BASIC_INFORMATION)key)->NameLength))
- ((ULONG)key);
break;
case KeyValueFullInformation:
NameOffset = ((ULONG)&(((PKEY_VALUE_FULL_INFORMATION)key)->Name)) - ((ULONG)key);
NameSizeOffset = ((ULONG)&(((PKEY_VALUE_FULL_INFORMATION)key)->NameLength))
- ((ULONG)key);
break;
case KeyValuePartialInformation:
NameOffset = ((ULONG)&(((PKEY_VALUE_PARTIAL_INFORMATION)key)->Data)) - ((ULONG)key);
NameSizeOffset = ((ULONG)&(((PKEY_VALUE_PARTIAL_INFORMATION)key)->DataLength))
- ((ULONG)key);
}
KeyNamePtr = (WCHAR*)((PBYTE)key + NameOffset);
KeyNameLength = (PULONG) ((PBYTE)key + NameSizeOffset);
KdPrint(("QueryValueKey: 0x%08x %wZ %ws", KeyHandle, ValueName, KeyNamePtr));
//if( !wcscmp(ValueName->Buffer, L"Identifier") )
//{
// KdPrint(("Found Identifier...changing!"));
// __try
// {
// *KeyNameLength = (ULONG)wcslen(wszNewIdentifier);
// wcscpy(KeyNamePtr, wszNewIdentifier);
// }
// __except(EXCEPTION_EXECUTE_HANDLER)
// {
// KdPrint(("Error changing identifier!"));
// return STATUS_UNSUCCESSFUL;
// }
//}
}
return ntReturn;
}
BOOLEAN TestHook( void )
{
// DWORD dwNtOpenKey = 0, dwNtQueryValueKey = 0;
//#define SYSCALL_INDEX(_Function) *(PULONG)((PUCHAR)_Function+1)
// dwNtOpenKey = (DWORD)KeServiceDescriptorTable.ServiceTable[SYSCALL_INDEX(ZwOpenKey)];
// dwNtQueryValueKey = (DWORD)KeServiceDescriptorTable.ServiceTable[SYSCALL_INDEX(ZwQueryValueKey)];
//
// KdPrint(("NtOpenKey: 0x%08x NtQueryValueKey: 0x%08x", dwNtOpenKey, dwNtQueryValueKey));
//
// dtNtOpenKey = DtCreateDetour( dwNtOpenKey, (ULONG)hkNtOpenKey );
// dtNtQueryValueKey = DtCreateDetour( dwNtQueryValueKey, (ULONG)hkNtQueryValueKey );
// if( !dtNtOpenKey || !dtNtQueryValueKey )
// return FALSE;
//
// ogNtOpenKey = (NtOpenKey_t)dtNtOpenKey->Trampoline;
// ogNtQueryValueKey = (NtQueryValueKey_t)dtNtQueryValueKey->Trampoline;
return TRUE;
}