by Mitja Kolsek, the 0patch Team
On April 21, security researcher Adrian Denkiewicz published an in-depth analysis of a local privilege escalation vulnerability in Windows Installer that was fixed by April 2021 Windows Updates. Adrian's analysis included a proof-of-concept.
The vulnerability is a classical symbolic-link issue, whereby a privileged process (in this case, msiexec.exe) works with a file (in this case, installer log file) that the attacker is able to "redirect" to another location where the they do not have permissions to create or modify files.
Since attacker has limited control over the content of installer log file, and cannot modify the redirected log file after it has been created, Adrian had to be creative and found a working attack scenario in creating/overwriting PowerShell profile file (C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1) that gets loaded whenever anyone, ideally admin, uses PowerShell.
In essence, Microsoft's fix included a call to function IsAdmin from function CreateLog, which is in charge of creating installer log file. Some permissions checking was already in place before in this function but was not resilient to the "bait-and-switch" symbolic link trick that has been successful against many Windows products before, and will surely be successful against many more to come.
Our micropatch does logically the same as Microsoft's fix. Here is its source code for 64-bit Windows 7 and Server 2008 R2 with its 7 CPU instructions.
MODULE_PATH "..\Affected_Modules\msi.dll_5.0.7601.24535_64bit\msi.dll"
PATCH_ID 604
PATCH_FORMAT_VER 2
VULN_ID 7058
PLATFORM win64
patchlet_start
PATCHLET_ID 1
PATCHLET_TYPE 2
PATCHLET_OFFSET 0xf5a55 ; First GetCurrentThread block in CreateLog function
; instruction lea r9, [rsp+98h+TokenHandle]
N_ORIGINALBYTES 5
JUMPOVERBYTES 0
PIT msi.dll!0xf5b31,msi.dll!0xef7f8 ; Address of block to jump to; IsAdmin function
code_start
push rax ;Save the GetCurrentThread return
push rax ;Push one more time to fix stack alignment
call PIT_0xef7f8 ;Call IsAdmin (ret 1 if admin, 0 if not)
cmp rax, 0 ;Check if user is admin
pop rax ;Restore the GetCurrentThread return and fix stack alignment again
pop rax
je PIT_0xf5b31 ;If user is not an admin, jump over the scond createfile block
code_end
patchlet_end
See the micropatch in action here:
No comments:
Post a Comment