Hello kernelmode,
I've been using KeAttachProcess function to attach to target process's address space, it works nice when I need to read from the process memory,
And when I try to write to ntdll.dll( cr0 WP disabled ) after overwriting, then I restore CR0 WP and use KeDetachProcess to detach from the target process.
However, I found that not only the target process's ntdll.dll was overwritten, but all running process's ntdll.dll was overwritten, it looks like to me that ntdll.dll is shared and mmaped to a single physical page and linked to proper virtual addresses, so I have a couple of questions:
1 - Whats the diference between KeAttachProcess and KeStackAttachProcess ?
2 - How this function works internally? It only changes CR3?
3 - How to be sure when I write to an address it will not be paged out to disk?
4 - In my device driver, are local variables(Stack) Paged Pools?
5 - What about global vars are they located at paged pools?
6 - There is any function at kernel that allows me to know if some memory block is Paged or not?
7 - What happens when someone writes to ntdll from usermode(using writeprocessmemory), will ntdll be mmaped somewhere else in physical memory(by ntoskrnl)?
8 - How can I write to ntdll safely from kernelmode and overwrite the dll just in the current process?
I've been using KeAttachProcess function to attach to target process's address space, it works nice when I need to read from the process memory,
And when I try to write to ntdll.dll( cr0 WP disabled ) after overwriting, then I restore CR0 WP and use KeDetachProcess to detach from the target process.
However, I found that not only the target process's ntdll.dll was overwritten, but all running process's ntdll.dll was overwritten, it looks like to me that ntdll.dll is shared and mmaped to a single physical page and linked to proper virtual addresses, so I have a couple of questions:
1 - Whats the diference between KeAttachProcess and KeStackAttachProcess ?
2 - How this function works internally? It only changes CR3?
3 - How to be sure when I write to an address it will not be paged out to disk?
4 - In my device driver, are local variables(Stack) Paged Pools?
5 - What about global vars are they located at paged pools?
6 - There is any function at kernel that allows me to know if some memory block is Paged or not?
7 - What happens when someone writes to ntdll from usermode(using writeprocessmemory), will ntdll be mmaped somewhere else in physical memory(by ntoskrnl)?
8 - How can I write to ntdll safely from kernelmode and overwrite the dll just in the current process?