@Aaron You can apply the mitigation requiring signed Microsoft binaries to a process that runs as a Windows Service through the Image File Execution Options registry key. Consequently, you don't need an intermediary between the service control manager and your service executable. The same holds true for an executable that is not a service. The policy is applied directly and no launcher process is needed.
For example -
How do I prevent .dll preloading attacks when linking at load-time?
I'm trying to figure out how to securely link a dynamic-link library(.dll) at load-time. I want to make sure that the .dll I'm linking to is in fact the one I expect, and not a malicious one.
I have read the Dynamic-link library security article, but most of it is referring to linking securely at runtime, where you make calls to LoadLibrary
, rather than load-time. So I am not using any path to the .dll or any API function to load the .dll--I am linking to the import library when I build my application, and that tells the application to link to the .dll at load-time when the app is starting.
It looks like for load-time linking, the two things you can do are DLL redirection and specify manifests. Now, DLL redirection seems to only change the search order of the directories for the .dlls; this doesn't help with the case where an attacker replaces a .dll in a given directory with a malicious .dll. I want to protect against that case by checking the signature of the .dll(again, at load-time, meaning I can't just put the signature-checking in my application code).
As far as manifests, I tried creating a manifest where I specified a dependency with a publicKeyToken
as mentioned in this StackOverflow question. However, after testing, this had no effect. I was able to link an unsigned .dll even though I had specified the publicKeyToken
for that .dll in the manifest dependency.
So how can I ensure that I only link a signed .dll at load-time?
Windows for business Windows Client for IT Pros Devices and deployment Configure application groups
Developer technologies C++
-
RLWA32 49,536 Reputation points
2023-04-20T08:52:24.25+00:00
1 additional answer
Sort by: Most helpful
-
RLWA32 49,536 Reputation points
2023-04-12T07:13:44.66+00:00 Refer to the answer and discussion at https://learn.microsoft.com/en-us/answers/questions/1189539/loadlibraryexw-returns-error-invalid-image-hash-on with respect to limiting dynamic link library loading to signed binaries. Also, take a look at How can I try to escape the disease-ridden hot-tubs known as the TEMP and Downloads directories? and the documentation for the /DEPENDENTLOADFLAG (Set default dependent load flags) linker option. You should be able to obtain a reasonable level of security by installing your application and its non-system dll dependencies in a secure file system location (i.e., C:\Program Files, etc.) and limiting dll loading to the application directory and System32 using the linker option above.