Explain low level hook timeout.
I'm writing a password manager for Windows which I want to protect against keyloggers. There is a timeout of 5000 ms for keyboard hooks. The hook procedure should process a message in less time than the data entry specified in the LowLevelHooksTimeout value in the following registry key:
HKEY_CURRENT_USERControl PanelDesktop
The value is in milliseconds.
(The default value of that Registry key is 5000)
Assuming a password manager running as administrator, could I suspend all programs, simulate typing a key, wait for 5 seconds and then be sure that all keyboard hooks have been disabled by Windows?
I've not found a way of unregistering all hooks via UnhookWindowsHookEx because it requires a handle that I do not have. This is why I'm resorting to unregistering them by timeout.
Regarding the low level hook timeout, there are three reasons I can see why this assumption is dicey.
- Hooks are only removed in Windows 7 and above. This is probably the least of your concern, but worth mentioning.
- The hook is silently removed, and your application has no way of knowing if these actions occurred and/or were successful.
- So even if your assumption is correct there is no way for you to know that the hooks were removed. Which means you should assume that not all of them have been removed.
- This only applies to keyboard hooks that have been registered using SetWindowsHookEx
This is the more pressing issue. A lot of malware are not going to use the built-in hooking API. They'll write their own hooks which won't be registered with the OS. Or at an even lower level for key-loggers, they'll be hooking or installing their own system level driver. Which again, will not be registering with the operating system.
Suspending all programs is possible, but again you might not be able to suspend the services that the key-logger is installed as or into. While I think that it's noble of you to try and guard against key-loggers I don't believe it is your responsibility.