Prevent_Process_Creation
Prevent_Process_Creation copied to clipboard
Record & prevent process creation in kernel mode
Prevent_Process_Creation
Record & prevent process creation in kernel mode
Study Notes
- Use
PsSetCreateProcessNotifyRoutineExto register a routine.PsSetCreateProcessNotifyRoutinehas limited functionality. - Using
PsSetCreateProcessNotifyRoutineExrequires the image that contains the callback pointer to haveIMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITYset in its image header. Otherwise, the function call will returnSTATUS_ACCESS_DENIED. (https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/nf-ntddk-pssetcreateprocessnotifyroutineex#return-value) To do this, add/integritycheckin linker parameters. (https://social.technet.microsoft.com/wiki/contents/articles/255.forced-integrity-signing-of-portable-executable-pe-files.aspx) - To print
PCUNICODE_STRINGusingDbgPrint, use%wZformat specifier. - To turn off "Spectre Mitigation", go to project properties - C/C++ - Code Generation - set "Spectre Mitigation" to "Disabled".
- Loading a x86 driver on a x64 system will fail.
StartServicewill give an error code 1275, which is "This driver has been blocked from loading". When you meet this error, think about architecture first, then think about if the system is really blocking it from loading. - Remember to set
DriverObject->DriverUnloadin DriverEntry, or the driver won't be unloaded correctly. Some drivers I previously wrote didn't do this, so those drivers can't unload correctly. If the driver is not unloaded correctly, you won't be able to load it for a second time andCreateServicewill give an error code 1073, which is "The specified service already exists". - If
DriverEntrydoesn't returnSTATUS_SUCCESS, user mode process that calledStartServicewill receive an error even the code in the driver is executed. - To prevent a process creation, modify
CreateInfoparameter inPcreateProcessNotifyRoutineExroutine. (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) e.g.
CreateInfo->CreationStatus = STATUS_ACCESS_DENIED;
- The above
CreationStatuswill cause a error popup when you trying to create a new process. To avoid a error message popup, we can setCreateInfo0>CreationStatustoSTATUS_ACCESS_DISABLED_NO_SAFER_UI_BY_POLICY. (https://blog.csdn.net/a907763895/article/details/52863952) - This method is only available for Windows Vista and above. I havn't test it on Windows XP. (https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntddk/nf-ntddk-pssetcreateprocessnotifyroutineex#requirements)
Notes for Windbg
Finally I figured it out how to use Windbg... (I am too stupid XD)
- You need to install the correct version of WDK. Using the newest version is strongly suggested... Or the debugger will likely fail to connect.
- How to set host computer IP:
bcdedit /dbgsettings net hostip:w.x.y.z port:n(https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/setting-up-a-network-debugging-connection#setting-up-the-target-computer) DbgPrintprints nothing: Entered nt!KD_DEFAULT_MASK 8in Windbg to enable verbose output. (https://reverseengineering.stackexchange.com/questions/16685/how-can-i-receive-dbgprint-messages-in-windbg-on-windows-10)- Using
x /D xx!yyto show symbols. - Load symbols:
.sympath+ folder, then.reload - Good reference: https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debug-universal-drivers--kernel-mode-
- We can use
!processto list processes.!process PID verbose_level
What I want to do
Now I finally figured it out how to prevent process creation in Windows 10 x64. I am going to figure it out how to prevent file creation / deletion using kernel mode driver. I will need to learn more about file system minifilter. After doing that, I may make a simple driver that communicates with my user-mode process to show warnings when it detects process creation and file creation.