A forum for reverse engineering, OS internals and malware analysis 

Forum for discussion about kernel-mode development.
 #26165  by sima
 Wed Jun 24, 2015 2:13 pm
Hi2all. I have a windows filtering platform (WFP) based driver for traffic monitoring. Windows has the service Base Filtering Engine (BFE) that controls the operation of the Windows Filtering Platform. I wonder how I can protect this service from stopping? I figured out that any user mode app can easily do it via OpenSCManager->OpenService->ControlService. I need to do it from kernel mode but if you give me ANY initials I would be thankful.
 #26168  by sima
 Wed Jun 24, 2015 3:23 pm
EP_X0FF wrote:https://msdn.microsoft.com/en-us/librar ... s.85).aspx
or CmRegistryCallback and service configured to auto-restart on any error.
Thanks for you answer. I mean protecting for standard windows BFE service not mine. I don't understand what you mean about CmRegisterCallback and how can I configure service with this function or registered callback.
 #26169  by t4L
 Wed Jun 24, 2015 5:26 pm
He means you would have to protect the BFE's service registry values so that others cannot tamper them in order to stop the service. Services' information are stored in registry, so that CmRegisterCallback registers registry customized callbacks and therefore you will get notification whenever someone try to open/close/read/write/etc on registry, hence you might prevent those modifications.
 #26170  by EP_X0FF
 Wed Jun 24, 2015 5:41 pm
Yes I mean this. I missed initial point about protecting BFE not your own service. Also take a hint that BFE service process can be simple terminated. Thats why I mentioned service configuration for auto-restart on any error.
 #26174  by sima
 Wed Jun 24, 2015 7:13 pm
t4L wrote:He means you would have to protect the BFE's service registry values so that others cannot tamper them in order to stop the service. Services' information are stored in registry, so that CmRegisterCallback registers registry customized callbacks and therefore you will get notification whenever someone try to open/close/read/write/etc on registry, hence you might prevent those modifications.
I checked with procmon - when my simple test program do OpenService->ControlService(..., SERVICE_CONTROL_STOP,...) I get only read registry event from its host process svchost.exe. I can't block this type of action. But I agree that I should use CmRegisterCallback for protection registry key from modification of its values.
 #26175  by sima
 Wed Jun 24, 2015 7:17 pm
EP_X0FF wrote:Yes I mean this. I missed initial point about protecting BFE not your own service. Also take a hint that BFE service process can be simple terminated. Thats why I mentioned service configuration for auto-restart on any error.
I see. Im going to use PsSetCreateProcessNotifyRoutineEx for this purpose. Thanks.
 #26178  by cziter15
 Thu Jun 25, 2015 6:50 am
Use ObRegisterCallbacks and revoke PROCESS_TERMINATE rights in your callback.
Of course you should block other accesses, like VM_WRITE, VM_OPERATION to prevent termination using "tricks" like zeroing pages.

Each usermode service has a control pipe. It is used to send / receive service commands like STOP, START etc..
You should take a look at this and maybe play with mini-filter driver API.
 #26179  by sima
 Thu Jun 25, 2015 7:02 am
cziter15 wrote:Use ObRegisterCallbacks and revoke PROCESS_TERMINATE rights in your callback.
Of course you should block other accesses, like VM_WRITE, VM_OPERATION to prevent termination using "tricks" like zeroing pages.

Each usermode service has a control pipe. It is used to send / receive service commands like STOP, START etc..
You should take a look at this and maybe play with mini-filter driver API.
ControlService doesn't terminate BFE's svchost.exe process and it continues its execution.

It is interesting about service's pipes, I didn't know it and will research it. Thanks for your answer.
 #26205  by cziter15
 Mon Jun 29, 2015 9:12 am
A lot of information can be found at ReactOS repository. They have reverse engineered NTOS kernel and then they have build their own based on that. Google for it :) and then look at SCM (Service control manager) sources.