forked from ethobis/KernelExploitDriver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKernelExploitDriver.c
More file actions
166 lines (136 loc) · 3.59 KB
/
Copy pathKernelExploitDriver.c
File metadata and controls
166 lines (136 loc) · 3.59 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
#include "KernelExploitDriver.h"
#include "ArbitraryOverwrite.h"
#include "NullPointerDereference.h"
#include "UseAfterFree.h"
NTSTATUS NTAPI
DeviceIOControlHandler(
_In_ PDEVICE_OBJECT pDeviceObject,
_In_ PIRP pIrp
)
{
NTSTATUS status = STATUS_SUCCESS;
PIO_STACK_LOCATION pStackLocation = NULL;
ULONG ulControlCode = 0;
UNREFERENCED_PARAMETER(pDeviceObject);
pStackLocation = IoGetCurrentIrpStackLocation(pIrp);
if (NULL == pStackLocation)
{
goto _RET;
}
ulControlCode = pStackLocation->Parameters.DeviceIoControl.IoControlCode;
switch (ulControlCode)
{
case ARBITRARY_OVERWRITE_CONTROL_CODE:
status = ArbitaryOverWriteHandler(pIrp, pStackLocation);
break;
case RESTORE_ARBITRARY_OVERWRITE_CONTROL_CODE:
RestoreArbitaryOverWrite();
break;
case NULL_POINTER_DEREFERENCE_CONTROL_CODE:
status = NullPointerDereferenceHandler(pIrp, pStackLocation);
break;
case USE_AFTER_FREE_CONTROL_CODE:
status = UseAfterFreeHandler(pIrp, pStackLocation);
break;
case USE_AFTER_FREE_ALLOCATE_CONTROL_CODE:
status = AllocateUAFObject();
break;
case USE_AFTER_FREE_CALL_CONTROL_CODE:
status = CallUAFObject();
break;
case USE_AFTER_FREE_FREE_CONTROL_CODE:
status = FreeUAFObject();
break;
default:
break;
}
pIrp->IoStatus.Status = status;
pIrp->IoStatus.Information = 0;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
_RET:
return status;
}
NTSTATUS NTAPI
DefaultHandler(
_In_ PDEVICE_OBJECT pDeviceObject,
_In_ PIRP pIrp
)
{
UNREFERENCED_PARAMETER(pDeviceObject);
pIrp->IoStatus.Information = 0;
pIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_NOT_SUPPORTED;
}
NTSTATUS NTAPI
CreateCloseHandler(
_In_ PDEVICE_OBJECT pDeviceObject,
_In_ PIRP pIrp
)
{
UNREFERENCED_PARAMETER(pDeviceObject);
pIrp->IoStatus.Information = 0;
pIrp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
VOID
DriverUnload(
_In_ PDRIVER_OBJECT pDriverObject
)
{
UNICODE_STRING uniDosDeviceName = { 0, };
UNREFERENCED_PARAMETER(pDriverObject);
RtlInitUnicodeString(&uniDosDeviceName, L"\\DosDevices\\KernelExploitDriver");
IoDeleteSymbolicLink(&uniDosDeviceName);
IoDeleteDevice(pDriverObject->DeviceObject);
return;
}
NTSTATUS
DriverEntry(
_In_ PDRIVER_OBJECT pDriverObject,
_In_ PUNICODE_STRING puniRegistryPath
)
{
NTSTATUS status = STATUS_SUCCESS;
UNICODE_STRING uniDeviceName = { 0, };
UNICODE_STRING uniDosDeviceName = { 0, };
PDEVICE_OBJECT pDeviceObject = NULL;
ULONG ulIndex = 0;
UNREFERENCED_PARAMETER(puniRegistryPath);
for (ulIndex = 0; ulIndex < IRP_MJ_MAXIMUM_FUNCTION; ++ulIndex)
{
pDriverObject->MajorFunction[ulIndex] = DefaultHandler;
}
pDriverObject->MajorFunction[IRP_MJ_CREATE] = CreateCloseHandler;
pDriverObject->MajorFunction[IRP_MJ_CLOSE] = CreateCloseHandler;
pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DeviceIOControlHandler;
pDriverObject->DriverUnload = DriverUnload;
RtlInitUnicodeString(&uniDeviceName, L"\\Device\\KernelExploitDriver");
RtlInitUnicodeString(&uniDosDeviceName, L"\\DosDevices\\KernelExploitDriver");
status = IoCreateDevice(
pDriverObject,
0,
&uniDeviceName,
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&pDeviceObject
);
if (!NT_SUCCESS(status))
{
goto _RET;
}
//pDeviceObject->Flags |= DO_BUFFERED_IO;
pDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
status = IoCreateSymbolicLink(&uniDosDeviceName, &uniDeviceName);
if (!NT_SUCCESS(status))
{
goto _RET;
}
return status;
_RET:
IoDeleteSymbolicLink(&uniDosDeviceName);
IoDeleteDevice(pDriverObject->DeviceObject);
return status;
}