LoadLibraryExW returns ERROR_INVALID_IMAGE_HASH on official Microsoft DLLs

Freedom Sy 26 Reputation points
2023-03-14T16:22:31.49+00:00

I have this issue with where LoadLibraryExW is not able to verify the signature of some official Microsoft Windows DLLs when LOAD_LIBRARY_REQUIRE_SIGNED_TARGET is used.

Get-AuthenticodeSignature says the image is valid.

SignerCertificate Status Path


745A64E580C00EE694639E92FC9C8AC1BEAC5E5D Valid mswsock.dll

I tried both "mswsock.dll" and the absolute path, neither worked.

Windows development Windows API - Win32
{count} votes

Accepted answer
  1. RLWA32 49,536 Reputation points
    2023-03-14T20:13:14.1633333+00:00

    Try calling SetProcessMitigationPolicy function with ProcessSignaturePolicy and PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY structure during process startup.

    For example,

    PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY policy{};
    policy.MicrosoftSignedOnly = TRUE;
    
    if (!SetProcessMitigationPolicy(ProcessSignaturePolicy, &policy, sizeof policy))
    {
        // Handle error
    }
    

    When this is successful, using LoadLibrary to load a non-Microsoft DLL caused the system to display the following -

    SystemError

    and GetLastError returned the following right after LoadLibrary failed -

    GetLastErrorText

    3 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.