Windows Kernel ReadLayoutFile Heap Overflow

Advisory

1.1.1. Advisory Information

Title
Windows Kernel ReadLayoutFile Heap Overflow
Advisory ID
CORE-2011-1123
Advisory URL
http://www.coresecurity.com/content/windows-kernel-readlayoutfile
Date published
2012-05-08
Date of last update
2012-07-11
Vendors contacted
Microsoft
Release mode
Coordinated release
Authors
Nicolás Economou

1.1.2. Vulnerability Information

Class
Impact
Remotely Exploitable
No
Locally Exploitable
Yes
CVE Name
CVE-2012-1890

1.1.3. Vulnerability Description

There is a bug in the ReadLayoutFile Windows Kernel function that can be leveraged
into a local privilege escalation exploit, potentially usable in a client-side attack scenario
or after a remote intrusion by other means.

This bug is similar to another bug used by a client-side exploit in Stuxnet.

1.1.4. Vulnerable packages

1.1.5. Vendor Information, Solutions and Workarounds

Apply security patch MS12-047 [4]

1.1.6. Credits

This vulnerability was discovered and researched by Nicolás Economou from Core Security Technologies.
The publication of this advisory was coordinated by Fernando Russ.

1.1.7. Technical Description / Proof of Concept Code

There is a bug in the ReadLayoutFile Windows Kernel (win32k.sys) function that can be leveraged
into a local privilege escalation exploit, potentially usable in a client-side attack scenario,
or after a remote intrusion by other means.

Custom keyboard layouts are implemented using a .dll file exporting the KbdLayerDescriptor function which,
in theory, returns a pointer to a structure of type KBDTABLES that is stored in the .DATA sections of the PE file.
The NtUserLoadKeyboardLayoutEx is a private function used by LoadKeyboardLayout[2] to load a custom keyboard layout, as arguments NtUserLoadKeyboardLayoutEx uses an open file handle pointing to a keyboard layout library.
When the function NtUserLoadKeyboardLayoutEx is correctly called the PE file referenced by its arguments is mapped in kernel space.

The bug is due to a memory corruption: a double word can be overwritten in a position relative to the base of the allocated
memory in kernel space. We have to distinguish the following constraints for exploiting this vulnerability:

We can confirm reliable exploitation for the following Microsoft Windows versions:

1.1.8. Report Timeline

1.1.9. References

[1] http://www.exploit-db.com/exploits/18140/
[2] http://msdn.microsoft.com/en-us/library/windows/desktop/ms646305(v=vs.85).aspx
[3] http://technet.microsoft.com/en-gb/security/bulletin/ms12-034
[4] http://technet.microsoft.com/en-gb/security/bulletin/ms12-047
[5] http://blog.coresecurity.com/2012/05/10/the-big-trick-behind-exploit-ms12-034/
[6] http://technet.microsoft.com/en-us/security/bulletin/ms12-jul

1.1.10. About CoreLabs

CoreLabs, the research center of Core Security Technologies, is charged with anticipating
the future needs and requirements for information security technologies.
We conduct our research in several important areas of computer security
including system vulnerabilities, cyber attack planning and simulation,
source code auditing, and cryptography. Our results include problem
formalization, identification of vulnerabilities, novel solutions and
prototypes for new technologies. CoreLabs regularly publishes security
advisories, technical papers, project information and shared software
tools for public use at:
http://corelabs.coresecurity.com.

1.1.11. About Core Security Technologies

Core Security Technologies enables organizations to get ahead of threats
with security test and measurement solutions that continuously identify
and demonstrate real-world exposures to their most critical assets. Our
customers can gain real visibility into their security standing, real
validation of their security controls, and real metrics to more
effectively secure their organizations.

Core Security's software solutions build on over a decade of trusted
research and leading-edge threat expertise from the company's Security
Consulting Services, CoreLabs and Engineering groups. Core Security
Technologies can be reached at +1 (617) 399-6980 or on the Web at:
http://www.coresecurity.com.

1.1.12. Disclaimer

The contents of this advisory are copyright
(c) 2012 Core Security Technologies and (c) 2012 CoreLabs,
and are licensed under a Creative Commons
Attribution Non-Commercial Share-Alike 3.0 (United States) License:
http://creativecommons.org/licenses/by-nc-sa/3.0/us/

1.1.13. PGP/GPG Keys

This advisory has been signed with the GPG key of Core Security Technologies advisories
team, which is available for download at
http://www.coresecurity.com/files/attachments/core_security_advisories.asc.