• R/O
  • HTTP
  • SSH
  • HTTPS

MUtilities: 提交

MUtilities development repository


Commit MetaInfo

修订版aa98a2157bd9549eb0a8027cf81df20dfe909d93 (tree)
时间2018-02-18 21:17:17
作者LoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Some more work to prevent DLL pre-loading attacks. Full protection is only enabled in "static" builds. Non-static builds require that we allow DLL loading from application install directory (e.g. to load the Qt plug-ins).

更改概述

差异

--- a/src/ErrorHandler_Win32.cpp
+++ b/src/ErrorHandler_Win32.cpp
@@ -55,6 +55,33 @@ static LONG WINAPI my_exception_handler(struct _EXCEPTION_POINTERS *ExceptionInf
5555 }
5656
5757 ///////////////////////////////////////////////////////////////////////////////
58+// DEFAULT DLL DIRECTORIES
59+///////////////////////////////////////////////////////////////////////////////
60+
61+//Flags
62+#define MY_LOAD_LIBRARY_SEARCH_APPLICATION_DIR 0x200
63+#define MY_LOAD_LIBRARY_SEARCH_USER_DIRS 0x400
64+#define MY_LOAD_LIBRARY_SEARCH_SYSTEM32 0x800
65+
66+#ifdef MUTILS_STATIC_LIB
67+#define MY_LOAD_LIBRARY_FLAGS (MY_LOAD_LIBRARY_SEARCH_SYSTEM32 | MY_LOAD_LIBRARY_SEARCH_USER_DIRS)
68+#else
69+#define MY_LOAD_LIBRARY_FLAGS (MY_LOAD_LIBRARY_SEARCH_SYSTEM32 | MY_LOAD_LIBRARY_SEARCH_USER_DIRS | MY_LOAD_LIBRARY_SEARCH_APPLICATION_DIR)
70+#endif
71+
72+static void set_default_dll_directories(void)
73+{
74+ typedef BOOL(__stdcall *MySetDefaultDllDirectories)(const DWORD DirectoryFlags);
75+ if (const HMODULE kernel32 = GetModuleHandleW(L"kernel32"))
76+ {
77+ if (const MySetDefaultDllDirectories pSetDefaultDllDirectories = (MySetDefaultDllDirectories)GetProcAddress(kernel32, "SetDefaultDllDirectories"))
78+ {
79+ pSetDefaultDllDirectories(MY_LOAD_LIBRARY_FLAGS);
80+ }
81+ }
82+}
83+
84+///////////////////////////////////////////////////////////////////////////////
5885 // SETUP ERROR HANDLERS
5986 ///////////////////////////////////////////////////////////////////////////////
6087
@@ -64,15 +91,17 @@ void MUtils::ErrorHandler::initialize(void)
6491 SetUnhandledExceptionFilter(my_exception_handler);
6592 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
6693 _set_invalid_parameter_handler(my_invalid_param_handler);
67- SetDllDirectoryW(L""); /*don'tload DLL from "current" directory*/
68-
94+
95+ /*to prevent DLL pre-loading attacks*/
96+ set_default_dll_directories();
97+ SetDllDirectoryW(L"");
98+
6999 static const int signal_num[6] = { SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, SIGTERM };
70100
71101 for(size_t i = 0; i < 6; i++)
72102 {
73103 signal(signal_num[i], my_signal_handler);
74104 }
75-
76105 }
77106
78107 ///////////////////////////////////////////////////////////////////////////////
Show on old repository browser