Jump to content
Nytro

Local privilege escalation for OS X 10.11.6 via PEGASUS

Recommended Posts

Local privilege escalation for OS X 10.11.6 via PEGASUS

 

Author: Min (Spark) Zheng @ Team OverSky

 

0x00 Introduction

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.

 

0x01 CVE-2016-4655 kernel info leak

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:

 

43019hhutg40.png

 

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.

 

430176q1pma0.png

 

0x02 CVE-2016-4656 kernel UAF

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:

 

43017a34fd70.png

 

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.

 

43017eiala50.png

 

For the ROP part, we can reuse the code of tpwn and rootsh to achieve local privilege escalation on OS X.

 

d36gnurpf8q.png

 

0x03 Running the Exploit

Here is the test environment: OS X EI Capitan 10.11.6 (15G31).

 

43017gqehmf0.png

 

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

 

43017hvl40j0.png

 

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

 

0x04 Summary

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.

 

Last but not least, the exploit source code can be downloaded at:https://github.com/zhengmin1989/OS-X-10.11.6-Exp-via-PEGASUS

 

0x05 Reference

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

 

Sursa: https://jaq.alibaba.com/community/art/show?articleid=532

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...