Application Security Blog | Technical Insights | Corellium

Corellium Empowers MidnightSunCTF to Add iOS Exploitation Challenges

Written by HackingForSoju | Jun 29, 2024 4:54:56 PM

On June 15-16th, Midnight Sun's HackingForSoju hosted their Capture The Flag Finals. CTF finalists from around the world were invited to compete head to head, after qualifying in April.

Two of the challenges centered around PAC on iOS with Corellium.

They had to be solved remotely, with only binary code provided. Each team was provided their own virtual iPhone 15 as a debug host by Corellium. The teams did great and solved both challenges during the contest.

Challenge Accepted: See how the top teams stacked up in the CTF Finals. 

CTF Victory: celebrating the champions, Tokyo Westerns.

Overview of PAC

iOS Applications like Messages are executed with hardening for memory corruption. One of these layers is Pointer Authentication (or PAC).

It's akin to Address Space Layout Randomization where the addresses of code and data are randomized to extend the work of attackers when they exploit memory corruption.

One of the weaknesses of ASLR, though, is that memory corruption often leads to arbitrary memory reads, which in turn defeat the protection mechanism. Guard pages can help mitigate this but are not a complete solution.

Pointer Authentication uses a key that's not readable by userland processes to "sign" pointers and later "authenticate" them.

The keys are also 128-bits long, so they are sufficiently large enough that a memory leak can't be used to brute force keys offline.

ARMv8.3 provides four abstract signing keys: IA, IB, DA, and DB. The architecture designates IA and IB for signing code pointers and DA and DB for signing data pointers.

The "B" keys can be thought of as "ROP killers" since they sign return addresses or potentially frame pointers, and are randomized per-process execution.

The "A" keys are more of a stop-gap against remote exploitation only since a local program escalating userland privileges would likely be able to forge everything needed with a stack leak.

Still PAC has some notable weaknesses. First, that key signing oracles can appear where code gadgets can authenticate a pointer, often due to a callback or a more unusual integration between an external library call.

Next, PAC’s small signatures mean that  PAC fundamentally does not eliminate attacks, but instead it slows them down significantly. And in practice the number of attempts and crashes should make an attack attempt with brute force unlikely, but this may not always be true.

Lastly, side channels may exist which can be used to brute force PAC signatures or leak keys.

Signing Oracles

For the first task, a hand-rolled structure has been created with function pointers signed and stored in memory. To call them they are authenticated in-memory and then branched into.

If a flaw exists in the callee then that callee can modify the naked function pointer, which will be re-signed for the subsequent execution.

Challenge 1 

Signature Forging

For the second task, players forged a signature with brute force against a forking server. 

Challenge 2

Pointer signatures are about 17 bits. That makes 2^17 = 131072 different values to sweep through. The server further forks, which means the IB key is not randomized.

This is useful for chaining multiple gadgets without restarting across attempts, and also greatly reduces the number of attempts.

With key randomization, roughly 400,000 tries would be needed for a 95% success rate. Without key randomization, the total search is then 1/4th the size.

What's next for PAC

ARMv9 improves support for BTI with PAC.  BTI is Branch Target Identification, which ensures that dynamic breaches land onto entry point opcodes specified by the compiler.

The br instruction expects to land on a bti j opcode. The blr instruction expects to land on a bti c instruction. The paciasp and pacibsp instructions can also be used as targets with BTI.

Are you interested in learning more about Corellium? The Corellium Virtual Hardware platform provides never-before-possible security vulnerability research for iOS and Android phones. See all our mobile security research capabilities to discover more.


References:

Pointer Authentication

Pointer authentication for arm64e

Enhancing Chromium's Control Flow Integrity with Armv9

PACMAN: Attacking ARM Pointer Authentication with Speculative Execution

Advance Your Mobile Security Research with Corellium

Experience Corellium’s groundbreaking virtualization technology for mobile devices and discover never-before-possible mobile vulnerability and threat research for iOS and Android phones. Book a meeting today to explore how our platform can optimize mobile security research and malware analysis.