A forum for reverse engineering, OS internals and malware analysis 

Ask your beginner questions here.
 #26642  by SirZoidberg
 Tue Sep 01, 2015 11:38 pm
Hello,

i wonder if there are any legitimate ways to achieve similar functionality to kernel mode hooks. I'm thinking of developing a small software which some function to monitor behavior of processes similar to good anti virus solution eg. avoid WriteProcessMemory to other processes and installation of drivers. Additionally some functions to disable certain functions similar to a child protection software.

(Skip the next part, its just an explanation why i want to do this)
Some of my friends to ask to "fix" their computer have often the same problems with malware/spyware that often comes with free software or from fake "free software"/"free updates" sites. Some of them have good anti virus software - but the software often ask so often/many times that they eventually allow thinks the shouldn't. I have some knowledge about rootkit (usermode & kernelmode) and the techniques the proactive anti virus software used 3-4 years ago. I think it would be a nice hobby to try to develop such software. I read many new posts in this forums and others how to achieve such functionality in current Windows x64 versions. But i only found ways used in game hacks or malware to get into the kernel mode and create such hooks. So even if i would buy a certificate for my driver, there is still the problems to make the hooks because of PatchGuard. I read about ways to disable PatchGuard but none of them seemed "right" because my goal is to make the computer safer. By disabling PatchGuard i would do the opposite. I know their are ways to do this in usermode eg. to laod my dll in every process but its much harder this way to defend my tool against malware who unhooks things or load the api's addresses it self.

So my question is: How can i do something like this the 'legitimate' way without compromising/disabling any security features of windows? And if possible, do it with kernel right to be sure my software has more right than any process they might start. Since their are so many anti virus product, even from microsoft, i hope their must be a way to implement this that isn't "dirty".
I don't look for finished solution just for tips, suggestions or keywords so that i can continue searching ways. I wasn't able to find a good one, yet.

Thanks & Greetings,
Sir Zoidberg
 #26643  by Brock
 Wed Sep 02, 2015 3:17 am
Hi,
You can harness a lot of power through system callbacks. Basically, you register a callback function and the underlying OS will call your function pre and post operations, in some cases. See ObRegisterCallbacks() for an example of this, also FsRtlRegisterFileSystemFilterCallbacks(), PsSetCreateProcessNotifyRoutine(Ex), PsSetCreateThreadNotifyRoutine(), PsSetLoadImageNotifyRoutine() will help you while doing process and thread "stuff". Search this forum too, a lot of these kernel functions have been mentioned and code examples exist as well. I don't blame you for wanting to avoid hooks and as you mentioned KPP/PG doesn't help things on x64
 #26645  by Vrtule
 Wed Sep 02, 2015 11:00 am
Hello,

if you need to monitor/filter/alter registry operations, look at CmRegisterCallback(Ex) routine.

If you wish to monitor/filter/alter file system operations, have a look at File System Minifilter Drivers. If you need something more advanced, you can always attach a device object to device stack of a driver responsible for the device you wish to monitorfilter...

If you wish to monitor/filter network traffic, search for the Windows Filtering Platform interface. Well, the APIs are kinda tough sometimes but WDK contains several samples that will help you to develop your own network filter driver.

These are legitimate ways of doing certain (usual, I believe) things that cannot be solved by kernel hooking anymore. Certain specific tasks may be also solved by other methods that are not very documented but are not considered as "kernel hooks" (certain things can be accomplished quite well mostly by usermode hooking, or you can find kernel structures containing callbacks that are not protected by KPP yet).