Tuesday, August 25, 2015

Windows 10^H^H Symbolic Link Mitigations

Posted by James Forshaw, abusing symbolic links like it’s 1999.

For cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 past couple of years I’ve been researching Windows elevation of privilege attacks. This might be escaping sandboxing or gaining system privileges. One of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 techniques I’ve used multiple times is abusing cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 symbolic link facilities of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 Windows operating system to redirect privileged code to create files or registry keys to escape cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 restrictive execution context. Symbolic links in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365mselves are not vulnerabilities, instead cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y’re useful primitives for exploiting different classes of vulnerabilities such as resource planting or time-of-check time-of-use.

This blog post contains details of a few changes Microsoft has made to Windows 10, and now back ported (in MS15-090) as far back as Windows Vista which changes who can use certain types of symbolic links. There’s not been many mitigations of this type which get back ported to so many older versions of Windows. Therefore I feel this is a good example of a vendor developing mitigations in response to increased attacks using certain techniques which wouldn’t have traditionally been considered before for mitigations.

Quick Overview of Windows Symbolic Link Support

If you already know all about Windows Symbolic Link support you can always skip this, or perhaps view my presentation I made at this year’s Infiltrate conference about abusing cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m. If not continue on. There are three types of symbolic links you can access from a low privileged user, Object Manager Symbolic Links, Registry Key Symbolic Links and NTFS Mount Points. There’s actually a fourth type, NTFS Symbolic Links, however you can only create this type if you’re an administrator making cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m of little use for privilege escalation. These symbolic link types have been added over cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 many years of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 NT development as shown below.

Symbolic Link History (1).png

Object Manager Symbolic Links

From a user perspective Windows supports multiple drives, such as C:. But that’s not really what’s seen under cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 hood. Behind cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 facade of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 explorer shell and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 Win32 API is anocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r filesystem like structure, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 object manager namespace. This is used to hold named resources such as devices and events, but crucially it has support for symbolic links. One of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 main users of symbolic links is cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 aforementioned drive letters. If you look at cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 namespace using a tool such as WinObj you can find cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 drive letter symlinks and see cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m redirect to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 real mounted device.

Object Manager Symbolic Links.png

While cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365se symbolic links are supposed to be used only for system purposes it’s possible to create cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m as a low privileged user, as long as you have access to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 target area of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 object manager namespace. While cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re’s a few attacks which can be facilitated with cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m it’s easiest to exploit in file attacks. An simple example is CVE-2015-0055 which was an information disclosure issue in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 IE EPM sandbox which abused symbolic links to bypass a security check.

Registry Key Symbolic Links

The Windows Registry is used to store configuration information for cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 system and isn’t something which your normal user of Windows needs to worry about. While reasonably well documented it does have some features which cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 normal Win32 APIs do not document, one of which is unsurprisingly symbolic links between keys. This is used by cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 system to map in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 current system configuration at boot time (cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 well known, CurrentControlSet) but it’s not really used outside of that.

createregsymlink.PNG

The fact that a low privilege process can create cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365se types of symbolic links has been abused before (see MS10-020) which removed cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 ability to create symbolic links between a untrusted registry hive such as cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 current user’s hive and trusted system hive, but it didn’t do anything to block cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 sandbox case where cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 symbolic link attacks cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 same user’s hive at different privilege levels. An example of a vulnerability exploitable using this type of link was CVE-2014-6322 which was an issue with cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 Windows Audio Server which could be exploited from cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 IE EPM sandbox.

NTFS Mount Points

The final type of symbolic link allows a directory on cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 NTFS file system to be linked to anocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r directory eicá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r on cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 same volume or on a completely different volume. It can’t be used to directly link to a single file (at least without some tricks) but it’s still useful. For example if you can find a privilege process which can be used to drop a file in a specified directory cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 write can be re-directed to somewhere cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 attacker controls.

mount_point.PNG

The only requirement on creating cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 mount point is a writable handle to a directory on cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 filesystem which is usually easy enough to achieve. This is probably cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 most used type of symbolic link for vulnerability exploitation, at least being used against Chrome, IE, and Adobe Reader sandboxes before now. An example is CVE-2014-0568 which was an issue I found in Adobe Reader which allows you to create an arbitrary file which could be used to escape cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 sandbox.

Technical Details of Mitigations

Now let’s go into some technical details of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 mitigations, what cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y do and what cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y don’t. The root of all cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 mitigations is a new exported kernel function, RtlIsSandboxToken. This function determines if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 current caller is considered to be in a sandbox, which in this case means eicá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r running at a integrity level below medium integrity or running within an AppContainer. The check is made by capturing cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 current subject context and calling SeAccessCheck with a Security Descriptor requiring medium integrity level. This shouldn’t be easily bypassable.

At this point you might assume that all cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 mitigations will do is call cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 method when creating a symbolic link and refuse to create cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m, but due to application compatibility it isn’t that simple. It’s easy to find cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 interactions by looking at cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 reference to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 function in IDA or similar. I’ll briefly describe how each one is applied and compromises being made.

references.PNG

Registry Key Symbolic Link Mitigation (CVE-2015-2429)

The simplest mitigation implementation is for registry keys. Effectively a sandboxed process is not allowed to ever create a registry key symbolic link. This is implemented by calling RtlIsSandboxToken function when creating a new key (you need to specific a special flag when creating a key symbolic link). It’s also called when setting cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 SymbolicLinkValue value which contains cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 link target. This second check is necessary to prevent modifying existing symbolic links, although it would be unlikely to be something found on a real system.

Object Manager Symbolic Link Mitigation (CVE-2015-2428)

If an application tries to create an object manager symbolic link from a sandbox process it will still seem to work, however if you look at where cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 check is called you’ll find it doing something interesting. When cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 symbolic link is created cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 RtlIsSandboxToken function is called but cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 kernel doesn’t immediately return an error. Instead it uses it to set a flag inside cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 symbolic link kernel object which indicates to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 object manager a sandboxed process has created this link.

This flag is cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n used in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 ObpParseSymbolicLink function which is called when cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 object manager is resolving cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 target of a symbolic link. The RtlIsSandboxToken is called again, if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 current caller is not in a sandbox but cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 creator was in a sandbox cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 kernel will return an error and not resolve cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 symbolic link, effective making cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 link useless for a sandboxed to unsandboxed elevation.

The behaviour is likely for applications running in AppContainers which might need to create symbolic links, but only ocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r sandbox processes would need to follow cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 links. It’s quite a pragmatic way of mitigating cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 issue without breaking application compatibility. However it does bring an additional performance cost, every time a symbolic link is resolved (such as cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 C: drive) an access check must be performed, presumably this has been measured to have a negligible impact.

NTFS Mount Point Mitigation (CVE-2015-2430)

The final mitigation is for NTFS mount points. In early technical previews of Windows 10 (I first spotted cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 change in 10130) cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 check was in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 NTFS driver itself and explicitly blocked cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 creation of mount points from a sandboxed process. Again for presumably application compatibility reasons this restriction has been relaxed in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 final release and cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 back ported mitigations.

Instead of completely blocking creation cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 kernel function IopXxxControlFile has been modified so whenever it sees cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 FSCTL_SET_REPARSE_POINT file system control code being passed to a driver with a mount point reparse tag it tries to verify if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 sandboxed caller has write access to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 target directory. If access is not granted, or cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 directory doesn’t exist cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n setting cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 mount point fails. This ensures that in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 majority of situations cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 sandboxed application couldn’t elevate privileges, as it could already write to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 directory already. There’s obviously a cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365oretical issue in that cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 target could later be deleted and replaced by something important for a higher privileged process but that’s not very likely to occur in a practical, reliable exploit.

Conclusions

These targeted mitigations gives a clear indication that bug hunting and disclosing cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 details of how to exploit certain types of vulnerabilities can lead into mitigation development, even if cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y’re not traditional memory corruption bugs. While I didn’t have a hand in cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 actual development of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 mitigation It’s likely my research was partially responsible for Microsoft acting to develop cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365m. It’s very interesting that 3 different approaches ended up being taken, reflecting cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 potential application compatibility issues which might arise.

Excluding any bypasses which might come to light cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365se should make entire classes of resource planting bugs unexploitable from a compromised sandboxed process and would make things like time-of-check time-of-use harder to exploit. Also it shows cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 level of effort that implementing mitigations without breaking backwards compatibility requires. The fact that cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365se only target sandboxes and not system level escalation is particularly telling in this regard.

3 comments:

  1. Yes, cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365re had been a bunch of vulnerabilities lately using symbolic links, file junctions etc.
    Found one myself: http://www.zerodayinitiative.com/advisories/ZDI-15-377

    Its a shame that it got patched (Although it is probably for cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 better!). I'm pretty sure that much was inspired by your research, at least for me it was. Good to see researchers sharing cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365ir work, helps out beginners like myself a great deal, wouldn't know where to start ocá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365rwise!

    ReplyDelete
  2. Note that Powershell and Robocopy incorrectly delete through symbolic links and junctions, thus exposing admins to destruction of system files and loss of data when using eicá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365r of cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365ses tools for system maintainance.

    ReplyDelete
  3. >>For cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 past couple of years I’ve been researching Windows elevation of privilege attacks.

    I did had cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 bad? idea last week to challenge myself to do so too, I managed to find a vector attack that can run code as SYSTEM, because it only requires you to run a program with no elevation it doesnt qualify for cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 ms bounty program (which states that it is for remote code execution)
    I thought cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365 right thing to do would be cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365n inform ms, but according to cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365ir info (https://technet.microsoft.com/en-us/security/ff852094.aspx) cá cược thể thao bet365_cách nạp tiền vào bet365_ đăng ký bet365y're not interested, as you have to actually run a program
    As i'm not a security expert or researcher I really don't know what to do, what would you suggest?

    -Mat

    ReplyDelete