Skip to content

Commit fec38b6

Browse files
barnsonrobmen
authored andcommitted
Mitigate .local DLL redirection Windows bug.
1 parent 74ef526 commit fec38b6

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/burn/stub/precomp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <dutil.h>
1111
#include <apputil.h>
12+
#include <dirutil.h>
1213
#include <strutil.h>
1314
#include <fileutil.h>
1415
#include <pathutil.h>

src/burn/stub/stub.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
#include "precomp.h"
44

5+
static const HRESULT E_SUSPECTED_TAMPERING = MAKE_HRESULT(SEVERITY_ERROR, 500/*FACILITY_WIX*/, 2001);
6+
7+
static void AvoidLocalDllRedirection(LPCWSTR wzPath);
8+
59

610
int WINAPI wWinMain(
711
__in HINSTANCE hInstance,
@@ -52,6 +56,8 @@ int WINAPI wWinMain(
5256
AppInitialize(rgsczSafelyLoadSystemDlls, countof(rgsczSafelyLoadSystemDlls));
5357
}
5458

59+
AvoidLocalDllRedirection(sczPath);
60+
5561
// call run
5662
hr = EngineRun(hInstance, hEngineFile, lpCmdLine, nCmdShow, &dwExitCode);
5763
ExitOnFailure(hr, "Failed to run application.");
@@ -63,3 +69,23 @@ int WINAPI wWinMain(
6369

6470
return FAILED(hr) ? (int)hr : (int)dwExitCode;
6571
}
72+
73+
static void AvoidLocalDllRedirection(LPCWSTR wzPath)
74+
{
75+
LPWSTR sczLocalPath = NULL;
76+
HMODULE hmodComCtl = NULL;
77+
78+
// Bail if there's a <bundle>.exe.local directory, as it's a feature of
79+
// DLL redirection that has no real use for a bundle and is a hole for
80+
// DLL hijacking attacks.
81+
82+
if (FAILED(StrAllocFormatted(&sczLocalPath, L"%ls.local", wzPath))
83+
|| DirExists(sczLocalPath, NULL)
84+
|| FileExistsEx(sczLocalPath, NULL)
85+
|| FAILED(LoadSystemLibrary(L"Comctl32.dll", &hmodComCtl)))
86+
{
87+
::ExitProcess((UINT)E_SUSPECTED_TAMPERING);
88+
}
89+
90+
ReleaseStr(sczLocalPath);
91+
}

src/burn/stub/stub.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<SwapRunFromCD>true</SwapRunFromCD>
6464
<SwapRunFromNET>true</SwapRunFromNET>
6565
<DelayLoadDLLs>cabinet.dll;crypt32.dll;msi.dll;shlwapi.dll;userenv.dll;version.dll;wininet.dll;wintrust.dll</DelayLoadDLLs>
66+
<AdditionalOptions>/DEPENDENTLOADFLAG:0x800 %(AdditionalOptions)</AdditionalOptions>
6667
</Link>
6768
</ItemDefinitionGroup>
6869

0 commit comments

Comments
 (0)