Mark Russinovich’s technical blog covering topics such as Windows troubleshooting, technologies and security.
I introduced the -l switch to PsExec about a year and a half ago as an easy way to execute processes with standard-user rights from an administrative account on Windows XP. In Running as Limited User – The Easy Way I described how PsExec uses the CreateRestrictedToken API to create a security context that’s a version of the one your account is using, only without membership in the local administrators group or any of the privileges, such as Debug Programs, that are assigned to administrators. A process running with that kind of security context has the privileges and accesses of a standard user account, which prevents it from modifying system files and Registry keys or exercising privileges, like loading a device driver, that only administrators can perform.
There’s only one catch to the virtual sandbox the restricted token creates: processes running in the sandbox are running as you, and so can read and write any files, Registry keys, and even other processes to which your account has access. That caveat creates major gaps in the walls of the sandbox and malicious code written with awareness of the restricted environment could take advantage of them to escape and become full administrator. An easy way out is for the malware to simply use OpenProcess to gain access to one of your processes running outside the sandbox and to inject into it code and a thread to execute the code. Because your other processes are running as you and the Windows security model creates default permissions that grant your account full access to your processes, a sandboxed process will be able to open them. Another way out is to send window messages from the limited process to a normal process, like Explorer, and drive the normal process with synthesized mouse and keyboard input so that it executes code at the direction of the malware.
Given these holes, why do I still recommend using the PsExec feature to run processes with limited rights on Windows XP if you would rather use an administrator instead of standard user account? Because this type of sandbox has not been commonly used, malware authors haven’t bothered with writing the code necessary to escape and so they run into the walls.
Windows Vista changes that, however, because it uses an enhanced form of this sandbox in User Account Control (UAC) and Protected Mode Internet Explorer (IE). Let’s look at Vista’s version of the sandbox, how PsExec’s update lets you run programs in it, and explore its security implications.
UAC creates an alternate model where all users, including administrators, run with standard user rights. Executables that require administrative rights include a requestedExecutionLevel key in their manifest - XML embedded in their executable - that specifies “requireAdministrator”. When an administrator executes such an image, in its default configuration UAC presents a Consent dialog that asks permission for the image to run with administrative rights. Standard users see a similar dialog, but must enter the credentials of an administrative account to unlock administrative rights.
The act of giving an executable administrative rights is called “elevation” in UAC. Whether you elevate from a standard user account (Over the Shoulder – OTS - elevation) or from an administrative account (Admin Approval Mode – AAM - elevation), you create processes that have administrative rights on the same desktop as those that have standard user rights. Processes elevated from a standard user account run in a different account from those with standard user rights, so the Windows security model defines a wall around the elevated process that prevents the non-elevated processes from writing code into those that are elevated. However, the standard Windows security model does not prevent non-elevated processes from sending fake input into elevated processes, nor does it create a sandbox around the non-elevated processes of administrative users to stop the processes from compromising the administrator’s elevated processes. Windows Vista therefore introduces the Windows Integrity mechanism, which supplies additional fencing for the sandbox surrounding less-privileged processes.
In Vista’s integrity model, every process runs at an integrity level (IL) and every securable object has an integrity level. The primary integrity levels are low, medium (the default), high (for elevated processes) and system. The windowing system honors integrity levels to prevent lower-IL processes from sending all but a few informational window messages to the windows owned by processes of a higher IL, calling this protection User Interface Privilege Isolation (UIPI). The security model also changes in Vista to only allow a process to open an object for write access if the process IL is equal to or higher than that of the object. Further, to prevent access to secrets stored in memory, processes can’t open processes of a higher IL for read access.
If you add the Integrity Level column to Process Explorer’s display, as seen in the screenshot below, you can see that system processes, including Windows service processes, run at System IL. Most processes of your logon session run at Medium, any processes you elevated are at High, and Internet Explorer (IE) runs at Low when you have Protected Mode enabled. You can use the built-in icacls.exe utility to view and change the ILs of files and directories and the Sysinternals AccessChk tool shows ILs of files, directories, registry keys, and processes. Objects have a default IL of medium and you can use AccessChk’s -e option to search for objects that have an explicit IL.
The new version of Psexec takes advantage of the enhanced Vista sandbox when you specify the -l switch, running the executable you specify with a standard user token at low IL. The sandbox PsExec creates is almost identical to the one surrounding Protected Mode IE and you can feel your way around the walls by launching a command prompt or Regedit at low IL and then seeing what you can modify. For example, I launched the command prompt seen below at low IL with this command: psexec -l -d cmd.exe
I first determined my profile’s temporary directory with the “set” command. When I tried to create a file in that directory I was denied access because the directory has a default IL of Medium, which is indicated by the fact that there’s no IL specified in Icacl’s output. Then I changed to Protected Mode IE’s temporary directory, which has an IL of Low, and successfully created a file.
As you experiment you’ll find that your actions are limited, but there are some design boundaries that you should be aware of. First, with the exception of processes and threads, the wall doesn’t block reads. That means that your low-IL command prompt or Protected Mode IE can read objects that your account (the standard-user version if you’re a member of the administrator’s group) can. This potentially includes a user’s documents and registry keys.
Even the ability of a process at low IL to manipulate objects of a higher IL isn’t necessarily prevented. Since processes running at different integrities are sharing the same desktop they share the same “session”. Each user logon results in a new session in which the processes of the user execute. The session also defines a local namespace through which the user’s processes can communicate via shared objects like synchronization objects and shared memory. That means that a process with a low IL could create a shared memory object (called a section or memory-mapped file) that it knows a higher IL process will open, and store data in the memory that causes the elevated process to execute arbitrary code if the elevated process doesn’t properly validate the data. That kind of escape, called a squatting attack, is sophisticated, requires the user to execute processes in a specific order and requires knowledge of the internal operation of an application that is susceptible to manipulation through shared objects.
However, let’s be clear that no matter how difficult to pull off, the mere possibility of such a breach of a sandbox wall implies that ILs, in and of themselves, do not define security boundaries. What’s a security boundary? It’s a wall through which code and data can’t pass without the authorization of a security policy. User accounts running in separate sessions are separated by a Windows security boundary, for example. One user should not be able to read or modify the data of another user, nor be able to cause other users to execute code, without the permission of the other user. If for some reason it was possible to bypass security policy, it would mean that there was a security bug in Windows (or third-party code that allows it).
It should be clear then, that neither UAC elevations nor Protected Mode IE define new Windows security boundaries. Microsoft has been communicating this but I want to make sure that the point is clearly heard. Further, as Jim Allchin pointed out in his blog post Security Features vs Convenience, Vista makes tradeoffs between security and convenience, and both UAC and Protected Mode IE have design choices that required paths to be opened in the IL wall for application compatibility and ease of use.
Not requiring a user to type Ctrl+Alt+Delete to verify that the credential dialog UAC presents for an OTS elevation is one example of security balanced against usability, but there are others, like the ones I describe in my TechEd/ITForum talk User Account Control Internals and Impact on Malware (Jim’s post describes some of the ways you can enhance security while tipping the balance against ease of use, like configuring Windows to require Ctrl+Al+Delete for the credential dialog). For instance, having your elevated AAM processes run in the same account as your other processes gives you the convenience of allowing your elevated processes access to your account’s code and data, but at the same time allows your non-elevated processes to modify that same code and data to potentially cause an elevated process to load arbitrary code.
Because elevations and ILs don’t define a security boundary, potential avenues of attack , regardless of ease or scope, are not security bugs. So if you aren’t guaranteed that your elevated processes aren’t susceptible to compromise by those running at a lower IL, why did Windows Vista go to the trouble of introducing elevations and ILs? To get us to a world where everyone runs as standard user by default and all software is written with that assumption.
Without the convenience of elevations most of us would continue to run the way we have on previous versions of Windows: with administrative rights all the time. Protected Mode IE and PsExec’s -l option simply take advantage of ILs to create a sandbox around malware that gets past other security defenses. The elevation and Protected Mode IE sandboxes might have potential avenues of attack , but they’re better than no sandbox at all. If you value security over any convenience you can, of course, leverage the security boundary of separate user accounts by running as standard user all the time and switching to dedicated accounts for unsafe browsing and administrative activities.
Look for my in-depth article on UAC internals in the June issue of TechNet Magazine, and if you want if you want to learn about other changes in Windows Vista then check out the first of my three-part Inside the Vista Kernel article series in the February issue of TechNet Magazine.
PingBack from http://blog.afaceri-pe-internet.com/00200712/vista-security-model-%e2%80%93-a-big-joke
PingBack from http://blogs.zdnet.com/security/?p=29
Mark, A thought:
How hard would it be to write a piece of code that can invade the sandbox and then lie in wait until an elevation of priviledge occurs?
Also, does a program at medium mode have acces to the file that it was run from, that is, would IE have access to iexplorer.exe?
Sounded like a "no".
I'd love to see your thoughts on both these items.
Vista UAC has screwed me ROYALLY. When I changed my main user account from an admin to regular user, all UAC prompts for admin rights tell me to enter a password but provide no means for producing a password. So basically, I cannot perform a single administrative task (including reinstalling the OS, as I downloaded it from MS Live Marketplace). I spent an hour yesterday talking with MS Support to no avail (I'm using one of MS' own F-Lock keyboards, which is apparently disabled during the Windows bootup process, so I cannot boot into Safe mode) and am waiting for an escalation callback.
So let me say, I hate, hate, HATE UAC. I disregarded all the posts about how it's annoying. Forget that - it flat out has locked me out of my system. I've even tried writing a client to impersonate the admin user, and while it can give me a token, the token belongs to me *actual* user. In fact, lemme say that my hate of UAC now goes so far that I hate all of Vista with it (tends to happen when you pay $250 to get locked out of your machine)
http://www.hotindir.com
I agree with Harry that 'just turn UAC off' becoming accepted would be bad; what irritated me when I first tested my TFind utility - a command-line file searched, linked from my name here - is that the manifest setting 'requireAdministrator' causes it to open in a *new* command window - so the search results disappear as soon as it finishes!
(The current builds lack that setting: running will just fail, unless you open an elevated command window. Apparently tools like chkdsk have similar behavior, but I'm working on a more user-friendly workaround.)
Talking of user-friendly, this blog's comments would be a lot more readable if the 'pingbacks' appeared separately from regular comments!
Microsoft has made it fairly easy to get elevated from a limited user, via Manifest or RunAs verb to ShellExecute, but I have noticed a distinct lack of ability to spawn a limited process from an elevated one. Now, I can use CreateRestrictedToken and CreateProcessAsUser to create a restricted process, a la the "run as limited" option in process explorer. But I have found that processes created in this way (including from the process explorer option) have odd "access denied" errors running things like whoami /all. These seem to be fixed in psexec -l. Can you explain what code was required to make that work right? Also, can you explain how to set the integrity level of the process, as I would like to create a process in Medium level since this is what normal limited processes are. I was trying to track though psexec -l in a debugger with the interesting function calls, and see that you call SetTokenInformation with TokenLinkedToken class. I cannot seem to get this to work, I get that I do not have a required privilege. And looking at the memory for the TOKEN_LINKED_TOKEN struct in the debugger, your token looks more like a valid pointer than any of the token handles I have been seeing. Is there some trick to this? I may have to dig into the kernel debugger to see what is going on with these...
Figured out my questions on my own:
turns out the call I thought was setting the linked token was actually setting something else (probably was the integrity level). Setting the linked token requires SeCreateTokenPrivilege. The fix which makes the whoami command start working is to add the user of the token to the token's default dacl with PROCESS_ALL_ACCESS. Setting the integrity level is done with SetTokenInformation with the TokenIntegrityLevel option, and specifying the proper integrity level Sid.
I wish there was a way to set the Linked Token and the other elevation-related properties of the token, so that code which is inspecting these properties to see if it is elevated can properly tell that it is not. Any ideas?
PingBack from http://doubt.pernick.org/2007/07/06/WindowsSecurityBoundaries.aspx
Where can I locate the Default setting for the UAC policies on all Vista editions other than Home & Enterprise for these:
1.User Account Control: Detect application installations and prompt for elevation
Default: Enabled (home) / Disabled (enterprise)
2.User Account Control: Behavior of the elevation prompt for standard users
Default: Prompt for credentials (home) / Automatically deny elevation requests (enterprise)
The above defaults are documented on the Explain Tab of the Properties Tab of each of these policies - but are INCOMPLETE
I am finding the difference between AAM and OTS less than clear. Is the article indicating that OTS leads to a security boundary due to the elevated process being launched under a separate user account i.e. the admin, or is this merely terminology to indicate which account the elevation request came from?
Thank goodness I finally came across your site. Basically, I know barely computer basics, and I don't even know how to use the command promt, but even someone as unknowledeable about computers such as myself knows that something is amiss when the hierarchy in my folders looks all messed up- I was begining to think that all this strangeness is just a figment of my imagination - My computer is acting strangely- active desktop, remote console, default user, owner, shared files, sharing files, Local C and C??? It seems as if someone is controlling my pc remotely from the console. I have learned a great deal about computers over the past few weeks just trying to unravel the fact that I am not imagining things, but a novice like me needs a lot of help fixing things.
Cool guestbook, interesting information... Keep it UP. excellent site i really like your stuff.
I am finding the difference between AAM and OTS less than clear. Is the article indicating that OTS leads to a security boundary due to the elevated process being launched under a separate user account i.e. the admin, or is this merely terminology to indicate which account the elevation request came from.
Thanxx, for taking the words out of my mouth.
But there rest is pretty amazing.