-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdriver.c
93 lines (76 loc) · 2.06 KB
/
driver.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
#include <ntddk.h>
/*
==============================================================
Function prototypes
==============================================================
*/
NTSTATUS
DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
);
void
badboyDriverUnload(
PDRIVER_OBJECT DriverObject
);
void PcreateProcessNotifyRoutineEx(
PEPROCESS Process,
HANDLE ProcessId,
PPS_CREATE_NOTIFY_INFO CreateInfo
);
/*
==============================================================
Function implementations
==============================================================
*/
NTSTATUS
DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
{
UNREFERENCED_PARAMETER(RegistryPath);
NTSTATUS status;
DriverObject->DriverUnload = badboyDriverUnload;
status = STATUS_SUCCESS;
DbgPrint("Driver loaded!\n");
// https://webcache.googleusercontent.com/search?q=cache:4vxTVzmlrd4J:https://bitnuts.de/articles/blocking_process_creation_using_a_windows_kernel_driver.html+&cd=11&hl=en&ct=clnk&gl=ca
NTSTATUS result;
result = PsSetCreateProcessNotifyRoutineEx(PcreateProcessNotifyRoutineEx, FALSE);
if (STATUS_SUCCESS == result) {
DbgPrint("Added routine!\n");
}
else {
DbgPrint("Failed to add routine! Error: %i\n", result);
}
return status;
}
void
badboyDriverUnload(
PDRIVER_OBJECT DriverObject
)
{
UNREFERENCED_PARAMETER(DriverObject);
if (STATUS_SUCCESS == (PsSetCreateProcessNotifyRoutineEx(PcreateProcessNotifyRoutineEx, TRUE))) {
DbgPrint("Removed routine!\n");
}
else {
DbgPrint("Failed to remove routine!\n");
}
DbgPrint("Driver unloaded!\n");
}
void PcreateProcessNotifyRoutineEx(
PEPROCESS Process,
HANDLE ProcessId,
PPS_CREATE_NOTIFY_INFO CreateInfo
)
{
UNREFERENCED_PARAMETER(Process);
/*
CreateInfo is non-NULL indicates a new process is being created
*/
if (CreateInfo) {
DbgPrint("[Process Create] %i: %wZ\n", ProcessId, CreateInfo->CommandLine);
CreateInfo->CreationStatus = STATUS_ACCESS_DENIED;
}
}