I have a minifilter. I want to restrict access to driver’s IOCL (1) at least so non elevated users cannot call DeviceIoControl. The best will be (2) to restrict calls to IOCL to my user mode process only (it runs elevated), as IOCL exposes very powerful functionality.
From user mode I open driver like this:
HANDLE hDrv = CreateFileW( L"\\\\.\\DriverName", GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
Then call IOCL like this:
#define MAKE_DANGEROUS_THING_IOCL CTL_CODE( SIOCTL_TYPE, 0x804, METHOD_BUFFERED, FILE_READ_DATA|FILE_WRITE_DATA)
DeviceIoControl(hDrv, MAKE_DANGEROUS_THING_IOCL, nullptr, 0, readBuffer, sizeof(readBuffer), &dwBytesRead, NULL)
In driver I have:
extern "C" NTSTATUS DriverEntry(__in PDRIVER_OBJECT DriverObject, __in PUNICODE_STRING RegistryPath)
{
IoCreateDevice(DriverObject, 0, &DEVICE_NAME, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &gMyDevice);
IoCreateSymbolicLink(&DEVICE_SYM_LINK, &DEVICE_NAME);
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = Function_IRP_DEVICE_CONTROL;
I tried to put in the .inf file the following ACL that I expect should prevent opening driver from interactive users:
[MiniFilter.AddRegistry.security]
"O:SYG:SYD:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;LC;;;IU)(A;;CCLCSWLOCRRC;;;SU)"
But I had no luck, CreateFileW and DeviceIoControl successfully execute from the non elevated user.
What am I doing wrong? How can I restrict IOCL functionality to admins or to my process only?