I've been learning win internals and I came across an interesting thing called Write Protection.
I know Windows relies on interrupts but I don't know any other way to do this.
I decided to try it using
__writecr0(__readcr0 & ~0x10000);
Unfortunately that didn't work for me so I decided to do it directly in the memory
I allocated memory, put opcodes there so it represents
cli
mov eax, cr0
and eax, not 0x10000
mov cr0, eax
sti
This didn't work either, I even wrote a code for it.
#include <ntifs.h>
#include <ntddk.h>
NTSTATUS NTAPI
DriverEntry(
PDRIVER_OBJECT DriverObject,
PUNICODE_STRING RegistryPath
) {
UNREFERENCED_PARAMETER(DriverObject);
UNREFERENCED_PARAMETER(RegistryPath);
unsigned char Opcodes[] =
{ 0x48, 0x0F, 0x20, 0xC0, 0x48, 0x0D, 0x00, 0x00, 0x01, 0x00, 0x48, 0x0F, 0x22, 0xC0, 0xC3 };
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "cr0: %I64X", __readcr0()));
VOID* Memory = ExAllocatePool2(
POOL_FLAG_NON_PAGED, 1024, 1337
);
if (Memory == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
RtlCopyMemory(Memory, Opcodes, sizeof(Opcodes));
((VOID (*) ())Memory)();
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "cr0: %I64X", __readcr0()));
ExFreePoolWithTag(Memory, 1337);
return STATUS_SUCCESS;
}
Still nothing, don't mind the different opcodes I tried without the REX (48h)
But I noticed that whenever I set the EIP to the address of these instructions I get a BSOD instantly when it comes to "cli"
Why do I get a BSOD when I try to disable interrupts and how else can I disable write protection if not like this?
/ EDIT /
I noticed this
*** Fatal System Error: 0x00000050
(0xFFFFC88F150D88A0,0x0000000000000011,0xFFFFC88F150D88A0,0x0000000000000002)
I guess it's because of how I allocate the memory? it crashes even if I don't try to disable interrupts and even if I do.