X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=windows%2Fwinmisc.c;h=11e2ca0f7d1353b46db523ca2d66f48b8ba85ad6;hb=9398d230339d5bfaa94093af89a17abf33b5dfad;hp=d21e1170babbc39ee32d3984d9e184a2081033ec;hpb=0bd014e456a0e5f755c45a8a5a420d6fad85c1d8;p=PuTTY.git diff --git a/windows/winmisc.c b/windows/winmisc.c index d21e1170..11e2ca0f 100644 --- a/windows/winmisc.c +++ b/windows/winmisc.c @@ -5,7 +5,9 @@ #include #include #include "putty.h" +#ifndef SECURITY_WIN32 #define SECURITY_WIN32 +#endif #include OSVERSIONINFO osVersion; @@ -69,6 +71,13 @@ Filename *filename_deserialise(void *vdata, int maxsize, int *used) return filename_from_str(data); } +char filename_char_sanitise(char c) +{ + if (strchr("<>:\"/\\|?*", c)) + return '.'; + return c; +} + #ifndef NO_SECUREZEROMEMORY /* * Windows implementation of smemclr (see misc.c) using SecureZeroMemory. @@ -140,6 +149,38 @@ char *get_username(void) return got_username ? user : NULL; } +void dll_hijacking_protection(void) +{ + /* + * If the OS provides it, call SetDefaultDllDirectories() to + * prevent DLLs from being loaded from the directory containing + * our own binary, and instead only load from system32. + * + * This is a protection against hijacking attacks, if someone runs + * PuTTY directly from their web browser's download directory + * having previously been enticed into clicking on an unwise link + * that downloaded a malicious DLL to the same directory under one + * of various magic names that seem to be things that standard + * Windows DLLs delegate to. + * + * It shouldn't break deliberate loading of user-provided DLLs + * such as GSSAPI providers, because those are specified by their + * full pathname by the user-provided configuration. + */ + static HMODULE kernel32_module; + DECL_WINDOWS_FUNCTION(static, BOOL, SetDefaultDllDirectories, (DWORD)); + + if (!kernel32_module) { + kernel32_module = load_system32_dll("kernel32.dll"); + GET_WINDOWS_FUNCTION(kernel32_module, SetDefaultDllDirectories); + } + + if (p_SetDefaultDllDirectories) { + /* LOAD_LIBRARY_SEARCH_SYSTEM32 only */ + p_SetDefaultDllDirectories(0x800); + } +} + BOOL init_winver(void) { ZeroMemory(&osVersion, sizeof(osVersion)); @@ -220,8 +261,8 @@ const char *win_strerror(int error) MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), msgtext, lenof(msgtext)-1, NULL)) { sprintf(msgtext, - "(unable to format: FormatMessage returned %d)", - GetLastError()); + "(unable to format: FormatMessage returned %u)", + (unsigned int)GetLastError()); } else { int len = strlen(msgtext); if (len > 0 && msgtext[len-1] == '\n')