天天看点

Local privilege escalation for OS X 10.11.6 via PEGASUS

because of the pegasus apt issue on ios, trident exploit is very hot recently. from lookout’s report, there are three vulnerabilities in the trident exploit:

cve-2016-4657: visiting a maliciously crafted website may lead to arbitrary code execution.

cve-2016-4655: an application may be able to disclose kernel memory.

cve-2016-4656: an application may be able to execute arbitrary code with kernel privileges.

although lookout didn’t release the malware, stefan esser and pangu still found the vulnerabilities of cve-2016-4655 and cve-2016-4656. therefore, we can use these two vulnerabilities to achieve local privilege escalation for os x 10.11.6 and jailbreak for ios 9.3.4.

because xnu kernel doesn’t check the length of serialized osnumber in the osunserializebinary() function, we can create an osnumber with a very long length:

    uint32_t data[] = {

    0x000000d3,                        

    0x81000001,                        

    0x08000004, 0x006e696d,

    0x84000200,    //change the length of osnumber

    0x41414141, 0x41414141

  };

after sending the serialized osnumber to the kernel, we can use io_registry_entry_get_property_bytes() to get the data back from the kernel:

Local privilege escalation for OS X 10.11.6 via PEGASUS

because we can control the length of returned data, we can get extra data from the kernel stack. some useful information like function return address can help us to calculate the kernel slide and break the kalsr protection.

Local privilege escalation for OS X 10.11.6 via PEGASUS

for cve-2016-4656, stefan esser introduced two ways to trigger the uaf vulnerability. we will use the sample way to exploit the kernel in this article.

we know that osunserializebinary() supports osstring and ossymbol as the keys for the dictionary and we can use an osobject to point to an old key. however, the osstring key will be freed when it convents into an ossymbol. therefore, if we create an osobject and point it to a freed osstring, it will trigger uaf in the kernel. here is the crash point when the system wants to retain an osobject that points to a freed osstring:

Local privilege escalation for OS X 10.11.6 via PEGASUS

therefore, we can create a crafted dictionary:

<dict>

<string>a</string>

<bool>true</bool>

<key>b</key>

<data>vtable data...</data>

<object>1</object>

</dict>

then we send this crafted dictionary to the kernel, rip will be set to the vtable entry at index 4 while rax points to the start of the vtable.

Local privilege escalation for OS X 10.11.6 via PEGASUS

for the rop part, we can reuse the code of tpwn and rootsh to achieve local privilege escalation on os x.

Local privilege escalation for OS X 10.11.6 via PEGASUS

here is the test environment: os x ei capitan 10.11.6 (15g31).

Local privilege escalation for OS X 10.11.6 via PEGASUS

note that if you want to test this exp, you should not install security update 2016-001 (like ios 9.3.5 patch for pegasus). and i hardcoded a kernel address to calculate the kslide, it may be different on your mac.

then we compile the exploit and run it:

clang -framework iokit -framework foundation -framework corefoundation -m32 -wl,-pagezero_size,0 -o3 exp.m lsym.m -o exp

Local privilege escalation for OS X 10.11.6 via PEGASUS

as you can see, our exploit got the root privilege successfully.

in this article, we introduced how to use cve-2016-4655 and cve-2016-4656 to achieve local privilege escalation on os x 10.11.6.

1. http://blog.pangu.io/cve-2016-4655/

2. https://sektioneins.de/en/blog/16-09-02-pegasus-ios-kernel-vulnerability-explained.html

3. https://bazad.github.io/2016/05/mac-os-x-use-after-free/

4. https://github.com/kpwn/tpwn

继续阅读