> For the complete documentation index, see [llms.txt](https://ret2basic.gitbook.io/ctfnote/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ret2basic.gitbook.io/ctfnote/red-teaming/privilege-escalation/windows-privilege-escalation/uac-bypass.md).

# UAC Bypass

## What is Process Integrity Level?

In Windows Vista and later, processes run at three different levels of integrity:

* **High:** administrator rights
* **Medium:** standard user rights
* **Low:** very restricted rights

## What is UAC?

To perform a privileged action, a program must run another program and request the high integrity level at that time. There are four UAC settings:

* **Always Notify**
  * This setting is the highest UAC setting. It will prompt the user when any program, including a built-in Windows program wants higher privileges.
* **Notify me only when programs try to make changes to my computer**
  * This is the default UAC setting. This setting does not prompt the user when some built-in Windows program want higher privileges. It will prompt the user when any other program wants higher privileges. This distinction is important and it plays into the UAC bypass attack that we will cover in a moment.
* **Notify me only when programs try to make changes to my computer (do not dim my desktop)**
  * This is the same as the default setting, except the user’s desktop does not dim when the UAC elevation prompt comes up. This setting exists for computers that lack the computing power to dim the desktop and show a dialog on top of it.
* **Never notify**
  * This option takes us back to life before Windows Vista. On Windows 7, if a user is an administrator, all of their programs will run with high integrity. On Windows 8, programs run at the medium integrity level, but anything run by an Administrator that requests elevated rights gets them without a prompt.

## Limitations

### UAC Notification Levels

The UAC bypass only works when the UAC notification level is set to default value or lower (in which case we don't need to bypass it):

![UAC notification levels](/files/y1rpJENAHmMzKwqnXhJk)

{% hint style="warning" %}
At "Always notify", in which case `ConsentPromptBehaviorAdmin` = 2 and `PromptOnSecureDesktop` = 1, UAC bypass will not work.
{% endhint %}

### Caveat: Windows Vista

{% hint style="info" %}
The Bypass UAC attack does NOT work on Windows Vista.
{% endhint %}

In Windows Vista, **the user has to acknowledge every privileged action**. This is the same as the Always Notify option in Windows 7 and later. The UAC settings in Windows 7 came about because UAC became a symbol of what was “wrong” with Windows Vista. Microsoft created UAC settings and made some of their built-in programs auto-elevate by default to prompt the user less often. These changes for user convenience created the loophole described in this post.

## Enumeration

Confirm UAC by reading the registry:

```powershell
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System
```

If UAC is enabled, the output will look like this:

![Enumerate UAC by reading the registry](/files/1oHdRGSCGUacovvPwMXZ)

Now notice the three highlighted keys above and their values:

1. `EnableLUA` tells us whether UAC is enabled. If 0 we don’t need to bypass it at all can just PsExec to SYSTEM. If it’s 1 however, then check the other 2 keys
2. `ConsentPromptBehaviorAdmin` can theoretically take on [6 possible values](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-gpsb/341747f5-6b5d-4d30-85fc-fa1cc04038d4) (readable explanation [here](https://www.tenforums.com/tutorials/112621-change-uac-prompt-behavior-administrators-windows.html)), but from configuring the UAC slider in Windows settings it takes on either 0, 2 or 5.
3. `PromptOnSecureDesktop` is binary, either 0 or 1.

## Exploitation (Metasploit)

In Metasploit, the UAC bypass module is:

```
msf6 > use exploit/windows/local/bypassuac_eventvwr
```

Note that UAC bypass oftentimes exists in an AD chain. For the OSCP exam, we don't want to waste the only Metasploit chance on AD chain, so we should do it manually.

## Exploitation (Manually)

The easiest way of manual UAC bypass is simply uploading `bypassuac-x86.exe` or `bypassuac-x64.exe` and execute it. Locate these two executables in your system:

![bypassuac executables](/files/f8irdvLQCVYytBqjezUY)

## Reference

{% embed url="<https://www.cobaltstrike.com/blog/user-account-control-what-penetration-testers-should-know/>" %}

{% embed url="<https://ivanitlearning.wordpress.com/2019/07/07/bypassing-default-uac-settings-manually/>" %}
Bypassing default UAC settings manually
{% endembed %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ret2basic.gitbook.io/ctfnote/red-teaming/privilege-escalation/windows-privilege-escalation/uac-bypass.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
