7#ifndef PROCESS_TERMINATE
8#define PROCESS_TERMINATE 0x0001
11static PDEVICE_OBJECT g_DeviceObject;
14static NTSTATUS CompleteRequest(PIRP Irp, NTSTATUS Status)
16 Irp->IoStatus.Status = Status;
17 Irp->IoStatus.Information = 0;
18 IoCompleteRequest(Irp, IO_NO_INCREMENT);
22static NTSTATUS TerminateProcessById(UINT64 ProcessId)
26 return STATUS_ACCESS_DENIED;
30 NTSTATUS status = PsLookupProcessByProcessId((HANDLE)(ULONG_PTR)ProcessId, &process);
31 if (!NT_SUCCESS(status)) {
36 status = ObOpenObjectByPointer(
44 ObDereferenceObject(process);
45 if (!NT_SUCCESS(status)) {
49 status = ZwTerminateProcess(processHandle, STATUS_SUCCESS);
50 ZwClose(processHandle);
54static NTSTATUS DeviceCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)
56 UNREFERENCED_PARAMETER(DeviceObject);
57 return CompleteRequest(Irp, STATUS_SUCCESS);
62static NTSTATUS DeviceCleanupClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)
64 UNREFERENCED_PARAMETER(DeviceObject);
66 return CompleteRequest(Irp, STATUS_SUCCESS);
69static NTSTATUS DeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
71 UNREFERENCED_PARAMETER(DeviceObject);
72 PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp);
75 switch (irpSp->Parameters.DeviceIoControl.IoControlCode) {
79 status = STATUS_BUFFER_TOO_SMALL;
84 status = TerminateProcessById(request->ProcessId);
85 if (!NT_SUCCESS(status)) {
86 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[-] Panoptes: Failed to terminate PID %llu with status 0x%X\n", request->ProcessId, status);
92 status =
InjectExclusionsSet(Irp->AssociatedIrp.SystemBuffer, irpSp->Parameters.DeviceIoControl.InputBufferLength);
93 if (!NT_SUCCESS(status)) {
94 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[-] Panoptes: Failed to set the injection exclusion list with status 0x%X\n", status);
100 status =
FilterSetFileEvents(Irp->AssociatedIrp.SystemBuffer, irpSp->Parameters.DeviceIoControl.InputBufferLength);
101 if (!NT_SUCCESS(status)) {
102 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[-] Panoptes: Failed to set the file event groups with status 0x%X\n", status);
117 status = STATUS_INVALID_DEVICE_REQUEST;
121 return CompleteRequest(Irp, status);
130 NTSTATUS status = IoCreateDeviceSecure(
135 FILE_DEVICE_SECURE_OPEN,
137 &SDDL_DEVOBJ_SYS_ALL_ADM_ALL,
140 if (!NT_SUCCESS(status)) {
141 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[!] Panoptes: Failed to create the device object with status 0x%X\n", status);
145 status = IoCreateSymbolicLink(&g_SymbolicLink, &deviceName);
146 if (!NT_SUCCESS(status)) {
147 DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
"[!] Panoptes: Failed to create the device symbolic link with status 0x%X\n", status);
148 IoDeleteDevice(g_DeviceObject);
149 g_DeviceObject = NULL;
153 DriverObject->MajorFunction[IRP_MJ_CREATE] = DeviceCreate;
154 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = DeviceCleanupClose;
155 DriverObject->MajorFunction[IRP_MJ_CLOSE] = DeviceCleanupClose;
156 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DeviceControl;
158 return STATUS_SUCCESS;
164 if (g_DeviceObject == NULL) {
168 IoDeleteSymbolicLink(&g_SymbolicLink);
169 IoDeleteDevice(g_DeviceObject);
170 g_DeviceObject = NULL;
void EventQueueCleanupFile(PFILE_OBJECT FileObject)
Handles IRP_MJ_CLEANUP for a handle to the device: cancels the GET_EVENT requests still parked for it...
BOOLEAN EventQueueReceiveRequest(PIRP Irp, NTSTATUS *Status)
Queues a GET_EVENT request. Call from the IOCTL dispatch routine. On success the IRP is either comple...
NTSTATUS InjectExclusionsSet(_In_reads_bytes_(Length) PVOID Buffer, _In_ ULONG Length)
Replaces the list with the names in a PANO_INJECTION_EXCLUSIONS.
#define PROCESS_TERMINATE
void RemoveDriverLink()
Deletes the device and symbolic link created by InitializeDriverLink.
NTSTATUS InitializeDriverLink(PDRIVER_OBJECT DriverObject)
Creates the \Device\Panoptes device and symbolic link and registers the IOCTL dispatch routines.
struct _PANO_TERMINATE_PROCESS PANO_TERMINATE_PROCESS
#define IOCTL_PANOPTES_SET_FILE_EVENTS
Sets which PANO_FILE_EVENT_GROUP bits are reported. The input buffer is a PANO_FILE_EVENTS....
#define IOCTL_PANOPTES_SET_INJECTION_EXCLUSIONS
Replaces the driver's list of process image names that the hook DLL is not injected into (the DontInj...
struct _PANO_TERMINATE_PROCESS * PPANO_TERMINATE_PROCESS
#define IOCTL_PANOPTES_TERMINATE_PROCESS
Terminates a process. The input buffer is a PANO_TERMINATE_PROCESS.
#define PANOPTES_SYMLINK_NAME
#define PANOPTES_DEVICE_NAME
#define IOCTL_PANOPTES_GET_EVENT
Waits for and returns the next event from the driver.
NTSTATUS FilterSetFileEvents(_In_reads_bytes_(Length) PVOID Buffer, _In_ ULONG Length)
Sets which PANO_FILE_EVENT_GROUP bits are reported (IOCTL_PANOPTES_SET_FILE_EVENTS).