forked from Splitx12/Driver-Kernel
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDriverMain.cpp
More file actions
178 lines (159 loc) · 5.98 KB
/
Copy pathDriverMain.cpp
File metadata and controls
178 lines (159 loc) · 5.98 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "includes.h"
#include "RequestHandling/RequestHandling.h"
__int64(__fastcall* pfnWdfChildListBeginScan_original)(void* a1, void* a2);
__int64 __fastcall FirmwareTableInformationHandlerWStack(void* a1, void* StackVar1)
{
if (a1)
{
PVOID RequestBufferPtr = 0;
memcpy(&RequestBufferPtr, reinterpret_cast<SYSTEM_FIRMWARE_TABLE_INFORMATION*>(a1)->TableBuffer, sizeof(PVOID));
if (FoxUtils::GoodPtr(RequestBufferPtr))
{
if (auto req = reinterpret_cast<RequestHandling::RequestBuild*>(RequestBufferPtr)) {
if (req->MagicKey == RequestHandling::ReqMagicKey)
{
if (req->ReqType == RequestHandling::RequestTypes::ReqDrvHandShake)
{
*(bool*)req->args = true;
*req->ResultStatus = STATUS_SUCCESS;
}
else if (req->ReqType == RequestHandling::RequestTypes::ReqModuleBasicInfo)
{
auto args = reinterpret_cast<RequestHandling::pDataModule>(req->args);
*req->ResultStatus = STATUS_INVALID_PARAMETER;
if (args)
{
*req->ResultStatus = RequestHandling::HandleModule(args);
}
}
else if (req->ReqType == RequestHandling::RequestTypes::ReqMemcpy)
{
auto args = reinterpret_cast<RequestHandling::pDataMemcopy>(req->args);
*req->ResultStatus = STATUS_INVALID_PARAMETER;
if (args)
{
*req->ResultStatus = RequestHandling::HandleMemcopy(args);
}
}
else if (req->ReqType == RequestHandling::RequestTypes::ReqKernelMouseInput)
{
auto args = reinterpret_cast<RequestHandling::pDataKernelMouseInput>(req->args);
*req->ResultStatus = STATUS_INVALID_PARAMETER;
if (args)
{
*req->ResultStatus = RequestHandling::HandleKernelMouseInput(args);
}
}
return STATUS_SUCCESS;
}
}
}
}
if(pfnWdfChildListBeginScan_original)
return pfnWdfChildListBeginScan_original(a1, StackVar1);
return 0;
}
bool MainInit(MDL* MdlPtr)
{
{
ImpSet(MmIsAddressValid);
ImpSet(RtlInitUnicodeString);
ImpSet(ZwQuerySystemInformation);
ImpSet(ExAllocatePoolWithTag);
ImpSet(ExFreePoolWithTag);
ImpSet(RtlEqualUnicodeString);
ImpSet(PsLookupProcessByProcessId);
ImpSet(strcmp);
ImpSet(strlen);
ImpSet(IoGetDeviceObjectPointer);
ImpSet(KeStackAttachProcess);
ImpSet(KeUnstackDetachProcess);
ImpSet(ObfDereferenceObject);
ImpSet(MmCopyMemory);
ImpSet(DbgPrintEx);
ImpSet(ZwSetSystemInformation);
ImpSet(PsGetProcessPeb);
ImpSet(RtlCompareUnicodeString);
ImpSet(IoGetCurrentProcess);
ImpSet(MmCopyVirtualMemory);
ImpSet(ObReferenceObjectByName);
}
if(FoxUtils::GoodPtr(MdlPtr))
{
if (!FoxUtils::secure::null_pfn(MdlPtr))
return false;
}
else
{
return false;
}
if (!FoxUtils::ki.InitKiStackUtils(KrlBase))
{
return false;
}
auto GUIProcess = FoxUtils::GetGUIAttachEProcess();
if (!GUIProcess)
{
return false;
}
size_t JumpDriverSize = 0;
auto JumpDriverBase = FoxUtils::GetKernelModule("Wdf01000.sys", &JumpDriverSize);
if (!JumpDriverBase)
{
IC(ObfDereferenceObject, GUIProcess);
return false;
}
bool bSuccess = false;
UINT64 JumpFunction;
UINT64 JumpFunctionPtr;
SYSTEM_FIRMWARE_TABLE_HANDLER* pTableHandlerDataBuffer;
NTSTATUS status;
PDRIVER_OBJECT DriverObj;
auto KState = FoxUtils::ki.Attach(GUIProcess);
JumpFunction = FoxUtils::FindPatternImage(JumpDriverBase, "\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\xFF\x15\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x38\x4C\x8B\x54\x24\x00\x48\x8B\x05\x00\x00\x00\x00\x4C\x89\x54\x24\x00\xFF\x15\x00\x00\x00\x00\x48\x83\xC4\x38\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\xFF\x15\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\xFF\x15\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\xFF\x15\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\xFF\x15\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x38\x48\x8B\x05\x00\x00\x00\x00",
"xxxxxxx????xx????xxxxxxxxxxxxxxxxxxxxxxx?xxx????xxxx?xx????xxxxxxxxxxxxxxxxxxxxxxxxxxxx????xx????xxxxxxxxxxxxxxxxxxxxxx????xx????xxxxxxxxxxxxxxxxxxxxxx????xx????xxxxxxxxxxxxxxxxxxxxxx????xx????xxxxxxxxxxxxxxxxxxxxxx????");
if (!FoxUtils::GoodPtr((PVOID)JumpFunction))
{
goto exit;
}
JumpFunctionPtr = RVA(JumpFunction + 0x4, 7);
if (!FoxUtils::GoodPtr((PVOID)JumpFunctionPtr))
{
goto exit;
}
pTableHandlerDataBuffer = (SYSTEM_FIRMWARE_TABLE_HANDLER*)IC(ExAllocatePoolWithTag, NonPagedPool, sizeof(SYSTEM_FIRMWARE_TABLE_HANDLER), 'WSMB');
if (!pTableHandlerDataBuffer)
{
goto exit;
}
status = FoxUtils::GetDriverObject((L"\\Device\\RawCdRom"), &DriverObj);
if (!NT_SUCCESS(status) || !DriverObj) {
goto exit;
}
*(LONG64*)&pfnWdfChildListBeginScan_original = _InterlockedExchange64((LONG64*)JumpFunctionPtr, (LONG64)FirmwareTableInformationHandlerWStack);
pTableHandlerDataBuffer->DriverObject = DriverObj;
pTableHandlerDataBuffer->ProviderSignature = 'WDF';
pTableHandlerDataBuffer->Register = TRUE;
pTableHandlerDataBuffer->FirmwareTableHandler = reinterpret_cast<PFNFTH>(JumpFunction);
status = IC(ZwSetSystemInformation, SystemRegisterFirmwareTableInformationHandler, pTableHandlerDataBuffer, sizeof(SYSTEM_FIRMWARE_TABLE_HANDLER));
if (!NT_SUCCESS(status)) {
goto exit;
}
bSuccess = true;
exit:
FoxUtils::ki.Detach(&KState);
IC(ObfDereferenceObject, GUIProcess);
return bSuccess;
}
NTSTATUS DriverEntryA(UINT64 MDL_PTR, UINT64 CODE_DATA)
{
KrlBase = FoxUtils::direct_assembly::GetKernelBase();
if (!KrlBase)
return 0x1;
KrlSize = FoxUtils::pe::GetSizeOfModule(KrlBase);
if (!KrlSize || KrlSize < 0xF)
return 0x2;
if (!MainInit((MDL*)MDL_PTR))
return 0x3;
return STATUS_SUCCESS;
}