diff options
author | Rob Mensching <rob@firegiant.com> | 2024-03-20 23:51:53 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2024-03-22 14:25:14 -0700 |
commit | 75a8c75d4e02ea219008dc5af7d03869291d61f7 (patch) | |
tree | c51a05a3cb878de83a2043e24a4641bddd181495 /src/dtf | |
parent | 2e5960b575881567a8807e6b8b9c513138b19742 (diff) | |
download | wix-75a8c75d4e02ea219008dc5af7d03869291d61f7.tar.gz wix-75a8c75d4e02ea219008dc5af7d03869291d61f7.tar.bz2 wix-75a8c75d4e02ea219008dc5af7d03869291d61f7.zip |
Protect elevated working folder from malicious data
When running elevated, Burn uses the Windows Temp folder as its working folder
to prevent normal processes from tampering with the files. Windows Temp does
allow non-elevated processes to write to the folder but they cannot see the
files there. Unfortunately, contrary to our belief, non-elevated processes
can read the files in Windows Temp by watching for directory changes. This
allows a malicious process to lie in wait, watching the Windows Temp folder
until a Burn process is launched elevated, then attack the working folder.
Mitigate that attack by protecting the working folder to only elevated users.
Managed custom actions also fall back to using the Windows Temp folder in
some cases and thus can be exposed in a similar fashion as an elevated Burn
process. Remove that possibility.
Diffstat (limited to 'src/dtf')
-rw-r--r-- | src/dtf/SfxCA/SfxUtil.cpp | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/src/dtf/SfxCA/SfxUtil.cpp b/src/dtf/SfxCA/SfxUtil.cpp index 2e6b0555..32dc6e04 100644 --- a/src/dtf/SfxCA/SfxUtil.cpp +++ b/src/dtf/SfxCA/SfxUtil.cpp | |||
@@ -164,38 +164,18 @@ bool ExtractToTempDirectory(__in MSIHANDLE hSession, __in HMODULE hModule, | |||
164 | StringCchCopy(szTempDir, cchTempDirBuf, szModule); | 164 | StringCchCopy(szTempDir, cchTempDirBuf, szModule); |
165 | StringCchCat(szTempDir, cchTempDirBuf, L"-"); | 165 | StringCchCat(szTempDir, cchTempDirBuf, L"-"); |
166 | 166 | ||
167 | BOOL fCreatedDirectory = FALSE; | ||
167 | DWORD cchTempDir = (DWORD) wcslen(szTempDir); | 168 | DWORD cchTempDir = (DWORD) wcslen(szTempDir); |
168 | for (int i = 0; DirectoryExists(szTempDir); i++) | 169 | for (int i = 0; i < 10000 && !fCreatedDirectory; i++) |
169 | { | 170 | { |
170 | swprintf_s(szTempDir + cchTempDir, cchTempDirBuf - cchTempDir, L"%d", i); | 171 | swprintf_s(szTempDir + cchTempDir, cchTempDirBuf - cchTempDir, L"%d", i); |
172 | fCreatedDirectory = ::CreateDirectory(szTempDir, NULL); | ||
171 | } | 173 | } |
172 | 174 | ||
173 | if (!CreateDirectory(szTempDir, NULL)) | 175 | if (!fCreatedDirectory) |
174 | { | 176 | { |
175 | cchCopied = GetTempPath(cchTempDirBuf, szTempDir); | 177 | Log(hSession, L"Failed to create temp directory. Error code %d", ::GetLastError()); |
176 | if (cchCopied == 0 || cchCopied >= cchTempDirBuf) | 178 | return false; |
177 | { | ||
178 | Log(hSession, L"Failed to get temp directory. Error code %d", GetLastError()); | ||
179 | return false; | ||
180 | } | ||
181 | |||
182 | wchar_t* szModuleName = wcsrchr(szModule, L'\\'); | ||
183 | if (szModuleName == NULL) szModuleName = szModule; | ||
184 | else szModuleName = szModuleName + 1; | ||
185 | StringCchCat(szTempDir, cchTempDirBuf, szModuleName); | ||
186 | StringCchCat(szTempDir, cchTempDirBuf, L"-"); | ||
187 | |||
188 | cchTempDir = (DWORD) wcslen(szTempDir); | ||
189 | for (int i = 0; DirectoryExists(szTempDir); i++) | ||
190 | { | ||
191 | swprintf_s(szTempDir + cchTempDir, cchTempDirBuf - cchTempDir, L"%d", i); | ||
192 | } | ||
193 | |||
194 | if (!CreateDirectory(szTempDir, NULL)) | ||
195 | { | ||
196 | Log(hSession, L"Failed to create temp directory. Error code %d", GetLastError()); | ||
197 | return false; | ||
198 | } | ||
199 | } | 179 | } |
200 | 180 | ||
201 | Log(hSession, L"Extracting custom action to temporary directory: %s\\", szTempDir); | 181 | Log(hSession, L"Extracting custom action to temporary directory: %s\\", szTempDir); |