-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify DllHijack mitigation and ensure urlmon is delay loaded
First update the project to reduce the number of linked libraries and ensure the most likely non-OS loaded DLLS are delay loaded. Then simplify the DLL hijack mitigation to always dynamically link to SetDefaultDllDirectories in case Squirrel is used on and old Win7 that is missing the necessary KB.
- Loading branch information
Showing
2 changed files
with
14 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,22 +23,26 @@ void PreloadLibs() | |
std::wstring version = (std::wstring(sys32Folder) + L"\\version.dll"); | ||
std::wstring logoncli = (std::wstring(sys32Folder) + L"\\logoncli.dll"); | ||
std::wstring sspicli = (std::wstring(sys32Folder) + L"\\sspicli.dll"); | ||
std::wstring urlmon = (std::wstring(sys32Folder) + L"\\urlmon.dll"); | ||
|
||
LoadLibrary(version.c_str()); | ||
LoadLibrary(logoncli.c_str()); | ||
LoadLibrary(sspicli.c_str()); | ||
LoadLibrary(urlmon.c_str()); | ||
} | ||
|
||
void MitigateDllHijacking() | ||
{ | ||
// Set the default DLL lookup directory to System32 for ourselves and kernel32.dll | ||
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32); | ||
|
||
HMODULE hKernel32 = LoadLibrary(L"kernel32.dll"); | ||
ATLASSERT(hKernel32 != NULL); | ||
|
||
SetDefaultDllDirectoriesFunction pfn = (SetDefaultDllDirectoriesFunction)GetProcAddress(hKernel32, "SetDefaultDllDirectories"); | ||
if (pfn) { (*pfn)(LOAD_LIBRARY_SEARCH_SYSTEM32); } | ||
if (hKernel32) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
robmen
Author
Contributor
|
||
{ | ||
SetDefaultDllDirectoriesFunction pfn = (SetDefaultDllDirectoriesFunction)GetProcAddress(hKernel32, "SetDefaultDllDirectories"); | ||
if (pfn) | ||
{ | ||
(*pfn)(LOAD_LIBRARY_SEARCH_SYSTEM32); | ||
} | ||
} | ||
|
||
PreloadLibs(); | ||
} | ||
|
This can never be false unless something very very Weird has happened 😅