You can be an iOS hacker: Stack Pivots and JOP/ROPs
Lina Lau (Founder · XINTRA)
BSides Canberra VII (2024) · Day 3 · Main Track
Overview
In this compelling talk at BSides Canberra, Lina Lau, founder of XINTRA, demystifies the notoriously opaque world of iOS exploitation, focusing specifically on stack pivoting and Jump/Return-Oriented Programming (JOP/ROP) techniques. Titled "You can be an iOS hacker: Stack Pivots and JOP/ROPs," her presentation addresses the significant barriers to entry for aspiring iOS security researchers and provides a crucial technical deep dive into advanced exploitation primitives. Lau highlights the stark contrast between the wealth of publicly available information for Windows exploitation and the scarcity of resources for iOS, attributing this gap to both the complexity of the platform and the immense financial incentives for keeping iOS exploits private.

Key moments
- 0:00 Introduction and iPhone security importance
- 3:50 The difficulty of learning iOS exploitation
- 9:00 Understanding the lucrative iOS exploit market
- 14:00 Demystifying stack pivoting for Heap exploitation
- 20:00 The 'jigsaw puzzle' of finding ROP gadgets
- 33:50 Practical tools for hunting ROP gadgets
- 38:00 Effective strategy: working backwards to build chains
- 43:00 Concluding thoughts on iOS exploitation challenges
You can be an iOS hacker: Stack Pivots and JOP/ROPs
Speakers: Lina Lau, Founder, XINTRA
Conference: BSides Canberra
YouTube: https://www.youtube.com/watch?v=2f9KQIL5jFs
Overview
In this compelling talk at BSides Canberra, Lina Lau, founder of XINTRA, demystifies the notoriously opaque world of iOS exploitation, focusing specifically on stack pivoting and Jump/Return-Oriented Programming (JOP/ROP) techniques. Titled "You can be an iOS hacker: Stack Pivots and JOP/ROPs," her presentation addresses the significant barriers to entry for aspiring iOS security researchers and provides a crucial technical deep dive into advanced exploitation primitives. Lau highlights the stark contrast between the wealth of publicly available information for Windows exploitation and the scarcity of resources for iOS, attributing this gap to both the complexity of the platform and the immense financial incentives for keeping iOS exploits private.
The talk is particularly relevant in today's threat landscape, where mobile devices, especially iPhones, have become prime targets for sophisticated attackers, including state-sponsored groups. With phones serving as comprehensive "catalogs of personal life," the ability to compromise them offers unparalleled access to sensitive data. Lau underscores the ethical dilemmas surrounding the disclosure of zero-day vulnerabilities and the lucrative market for mobile exploits, which can fetch millions of dollars. By dissecting the intricacies of memory corruption vulnerabilities and demonstrating how to construct sophisticated exploit chains, Lau not only educates the audience on cutting-edge attack methodologies but also empowers defenders to better understand and mitigate these advanced threats.
This presentation serves as a vital resource for anyone looking to bridge the knowledge gap in iOS security. It moves beyond high-level concepts to provide concrete examples and a practical methodology for approaching iOS exploit development. Through her clear explanations of assembly, register manipulation, and gadget chaining, Lina Lau illustrates that while challenging, becoming an iOS hacker is an achievable goal for dedicated security professionals.
Background
▶ Watch: Introduction and iPhone security importance (0:00)
The pervasive nature of mobile phones in modern life makes them an irresistible target for adversaries. Lina Lau points out that in countries like Australia and the United States, iPhones hold a dominant market share, and globally, mobile devices account for approximately 60% of all internet traffic. A significant portion of the population are "mobile-only" users, relying solely on their phones for digital interactions, making these devices repositories of intimate personal data. This reality elevates mobile phones to a critical target for various organizations, from criminal enterprises to nation-states.
The threat posed by sophisticated mobile spyware, such as Pegasus developed by the Israeli NSO Group, vividly illustrates the gravity of the situation. NSO Group's activities, including their blacklisting by the U.S. government and reports of their spyware being used against journalists and activists, highlight the real-world implications of mobile exploitation. Lau also touches upon the irony of the U.S. government having previously purchased NSO Group's spyware through a front company, "Cleopatra." This context sets the stage for understanding the high stakes involved in iOS security.
A major challenge for aspiring iOS hackers and security researchers is the sheer lack of transparent, up-to-date information. Unlike Windows exploitation, where countless blogs, videos, and PoCs exist, iOS resources are scarce and often outdated. Lau praises Google's Project Zero blog posts as a valuable, albeit beginner-unfriendly, source of information. She cites a poll indicating that only 0-5% of software developers can comprehend Project Zero's highly technical write-ups, underscoring the high bar for entry. The debate surrounding Project Zero's public disclosure policy – with arguments about burning counter-terrorism operations versus proactively informing the public about potential abuses by various governments – further illustrates the complex ethical landscape of vulnerability research.
The financial incentives also play a significant role in the secrecy surrounding iOS exploits. Companies like Zerodium offer substantial bounties, paying up to $2.5 million USD for an Android full-chain, zero-click exploit with persistence, and a projected $10 million USD for future mobile compromises. This dwarfs bounties for server or desktop exploits, significantly reducing the incentive for researchers to publicly disclose their findings. This lucrative market, combined with the difficulty of development, contributes to the scarcity of public knowledge. Lau's analysis of Project Zero's public spreadsheet of zero-days in the wild over the last five years (2019-2024) reveals a striking pattern: nearly all, except for three, are memory corruption vulnerabilities. Furthermore, many lack detailed root cause analyses, providing only a CVE link, reinforcing the challenge for defenders and researchers.
Lau provides a concise distinction between the stack and the heap, two fundamental memory regions. The stack is described as a "flight's departure board," tracking program execution flow, while the heap is for dynamically allocated memory (e.g., via malloc, calloc). The prevalence of memory corruption bugs, particularly those affecting the heap, creates a unique challenge on iOS. Unlike Windows, where arbitrary code injection (e.g., loading a DLL) is feasible, iOS's stringent security measures prevent direct code injection. This necessitates the use of gadget chaining, a technique where legitimate, existing code segments on the device are repurposed and linked together to achieve an attacker's objectives.
Key Findings
▶ Watch: Understanding the lucrative iOS exploit market (9:00)
The central problem addressed by Lina Lau is the difficulty of chaining a large number of gadgets on the heap when exploiting memory corruption vulnerabilities on iOS. Since program execution typically returns to the stack after a function call, directly executing an extensive ROP chain from a controlled heap region is challenging. The innovative solution presented is stack pivoting, a technique that effectively tricks the system into treating a controlled portion of the heap as the execution stack.
Lau elucidates the core mechanism of stack pivoting: at the top of the stack resides the stack pointer (SP), which indicates the current execution point. An attacker, having achieved a heap vulnerability (e.g., through a heap spray), can manipulate this stack pointer to point to an address within the controlled heap region. From this point, the program believes the heap is now the stack, allowing the attacker to execute an extensive chain of gadgets that have been carefully arranged within that heap region. After executing their malicious actions, the attacker must then restore the stack pointer to its original location on the actual stack to ensure program stability and avoid detection.
The benefits of stack pivoting are significant. It provides attackers with greater control over execution flow, enables the chaining of numerous gadgets on the heap, and can help bypass certain stack protections. Lau distinguishes between two primary forms of gadget chaining: Return-Oriented Programming (ROP) and Jump-Oriented Programming (JOP). ROP gadgets typically end with a ret instruction, returning control to the next address on the stack. JOP gadgets, more common in ARM architectures due to the absence of a direct jump instruction, end with a br (branch to register) instruction, effectively jumping to an address stored in a specified register. Both techniques achieve similar goals by repurposing existing code.
Lau emphasizes that successful iOS exploitation rarely involves a single vulnerability. Instead, it's a complex process of chaining multiple exploits and techniques. She references a Securlist write-up where a zero-click PDF exploit on iMessage led to a series of chained vulnerabilities, including a ROP/JOP component to set up subsequent exploits, such as a PAC (Pointer Authentication Codes) bypass. This illustrates that stack pivoting and ROP/JOP are not standalone exploits but rather critical techniques that facilitate the construction of more reliable and comprehensive exploit chains. The ultimate goal, as Lau outlines, is to find a sequence of ROP/JOP gadgets that, when combined, enable the crucial stack pivot, opening the door for further arbitrary code execution.
Technical Deep Dive
▶ Watch: The 'jigsaw puzzle' of finding ROP gadgets (20:00)
Understanding iOS exploitation necessitates a grasp of ARM64 assembly and register architecture. Lina Lau provides a concise overview of key registers: x0 through x28 are general-purpose registers for holding various data (memory addresses, decimals, ASCII). x16 is used for syscalls, though less relevant for this specific talk. Crucially, three registers are essential for stack pivoting: x29 (the frame pointer), which points to the stack frame within a function call; x30 (the link register), which stores the return address for function calls; and X31 (the stack pointer, or SP), which always points to the top of the current stack. Lau assures the audience that while assembly might appear daunting, it is "not as difficult as it looks" once its unapproachable vibe is overcome.
The process of constructing a stack pivot chain is akin to a "jigsaw puzzle." The attacker's starting point is usually control over x0, which often contains a heap address after a dynamic memory allocation (e.g., malloc). The end goal is to execute a stack pivot, allowing an extensive ROP payload to run from the heap. The challenge lies in finding and chaining the right gadgets – legitimate, existing code segments on the iPhone – to bridge this gap.
Lau presents two primary examples of stack pivot chains found in the wild:
- Project Zero (2019, Remote iOS Exploitation): This chain, six gadgets long, starts with a heap spray. The crucial stack pivot occurs when a gadget pops values off the stack into
x29andx30, then returns. Thex30register, now containing the address of the next gadget, leads to a subsequent gadget that moves the value ofx29(which was loaded with the controlled heap address) into the SP register. This effectively redirects the stack pointer to the attacker-controlled heap region. The initial setup ensures that the desired heap address is strategically placed to be loaded intox29at the right moment.
- Alibaba Security (Older blog post): A more succinct four-gadget chain, where the core pivot is
move sp, x2. This means the attacker needs to find preceding gadgets to ensure that the target heap address is loaded intox2before this instruction executes. Lau notes this is an "elegant" but less "effective" example, as the specific gadgets may no longer exist on modern iOS versions.
The scarcity of public stack pivot examples (Lau could only find these two) is attributed to the high monetary value of such techniques, discouraging public disclosure.
To find these crucial gadgets, researchers must look within the dyld shared cache. On iOS versions 3.1 and later, all dynamic libraries (dylibs) are cached into a single file. This file must first be extracted (using tools like dyld_shared_cache_extractor or dyld_extractor), and then the individual dylibs, often numbering over 2,000, can be analyzed. Once the dylibs are accessible, tools like ropper (Lau's preference) or RopGadget are used to search for specific assembly instructions. For a stack pivot, one might search for move sp to identify potential gadgets that directly manipulate the stack pointer. These tools output a list of static addresses and the corresponding gadget code. It's crucial to remember that these are static addresses and must be calculated at runtime using techniques like ASLR bypasses.
A significant challenge in chaining gadgets on the heap is dealing with non-contiguous memory or needing to skip over padding. This is where dispatcher gadgets come into play. A dispatcher is a specialized JOP gadget that modifies a register (e.g., x0) by adding an offset, and then branches to the address now stored in that register. For example, a dispatcher might take x0, add 0x18 (24 bytes) to it, and then br x0. If x0 initially pointed to a dispatcher, this sequence would cause execution to jump 24 bytes forward, allowing the attacker to skip over unwanted data or jump to the next desired gadget in their payload. This iterative use of dispatchers enables the attacker to navigate their controlled heap region and execute a complex sequence of gadgets.
Lau strongly advocates for a "work backwards" approach when constructing these chains. Starting with the desired stack pivot gadget (e.g., one that moves x29 into sp) and knowing that x0 contains the initial heap address, the attacker can then identify the intermediate gadgets needed to manipulate registers (like x1, x2, x8, x29, x30) to set up the final pivot. This systematic approach is more efficient than starting from x0 and hoping to stumble upon the necessary gadgets. She highlights the "trial and error" nature of this process, where one missing or incompatible gadget can unravel the entire chain.
Lau concludes this section by illustrating her own 8-gadget stack pivot payload. The actual payload itself was 272 bytes, with the "fake stack" (the controlled heap region acting as the stack) starting at 304 bytes. This complex arrangement of gadgets, dispatchers, and register manipulations demonstrates the intricate and often non-sequential nature of real-world iOS exploit development.
Demo / Proof of Concept
▶ Watch: Practical tools for hunting ROP gadgets (33:50)
While the talk did not feature a live, interactive demonstration of an exploit being chained and executed on an iOS device, Lina Lau provided a comprehensive conceptual walkthrough of how a stack pivot payload is constructed and visualized. She meticulously detailed the assembly instructions and logical flow of her own 8-gadget stack pivot chain, which she developed for her personal research.
Lau presented a high-level diagram showcasing the memory layout of her payload. This included the initial memory region pointed to by x0, the subsequent 272 bytes comprising the exploit payload, and the crucial "fake stack" starting at 304 bytes into the controlled heap region. This fake stack is where the actual ROP chain would reside, ready for execution once the stack pivot successfully redirects the stack pointer. The visualization also included how she tracks register states (x81 notation) throughout the execution flow, emphasizing the need for meticulous planning and debugging in this complex domain.
Her explanation of the "jigsaw puzzle" analogy directly translates to the proof-of-concept phase, where individual gadgets are identified, their effects on registers are analyzed, and they are then linked together using dispatcher gadgets to form a coherent execution path. The process, while described conceptually, highlighted the practical challenges of trial and error, the selection of effective (rather than merely elegant) gadgets, and the continuous need to adjust the chain to account for superfluous instructions or incompatible register states. This detailed breakdown, though not a live demo, serves as a powerful proof of concept for the feasibility and methodology of building sophisticated iOS stack pivot exploits.
Defensive Implications
▶ Watch: Concluding thoughts on iOS exploitation challenges (43:00)
Lina Lau's talk provides critical insights for defenders grappling with advanced iOS threats. The overarching takeaway is that iOS exploitation is extremely difficult, time-consuming, and often unpredictable. The inherent complexity, coupled with the secrecy surrounding discovered vulnerabilities and exploitation techniques, creates a significant information asymmetry that heavily favors attackers.
For defenders, the lack of public information about iOS exploits makes it incredibly challenging to develop effective detection and prevention mechanisms. Lau explicitly states that "in order to really defend something or be able to detect something, you kind of need to know how everything works." This highlights the necessity for security teams to invest in deep technical understanding of iOS internals, memory management, and common exploitation primitives like stack pivoting, ROP, and JOP. Relying solely on vendor patches or high-level security advisories is insufficient against sophisticated adversaries.
Key defensive implications include:
- Understanding Memory Corruption: Given that over 90% of iOS zero-days in the last five years are memory corruption vulnerabilities, defenders must prioritize understanding these bug classes, their root causes, and how they can be exploited. This includes familiarity with heap management, stack behavior, and how data layout influences exploitability.
- Appreciating Exploit Chains: iOS exploitation is rarely a single CVE. Defenders should expect and prepare for multi-stage exploit chains that combine several techniques (e.g., a heap overflow, followed by a stack pivot, then a PAC bypass, leading to arbitrary code execution). Defense strategies must consider the entire attack kill chain, not just individual vulnerabilities.
- Monitoring Advanced Research: Despite the scarcity of public PoCs, resources like Google's Project Zero blog posts, Citizen Lab reports, and Amnesty International's research remain invaluable. Defenders should actively follow these sources for insights into the latest iOS vulnerabilities and exploitation techniques, even if the content is highly technical.
- Reliability Challenges: Lau notes that exploits may not run correctly 100% of the time, especially when dealing with the unpredictable nature of the heap. While attackers strive for reliability, this inherent challenge can offer a small window for detection. Defenders should look for anomalous behavior, even if an exploit doesn't immediately achieve its full objective.
- Focus on Mitigation Bypasses: Techniques like Pointer Authentication Codes (PAC) are designed to make ROP/JOP harder, but attackers actively develop bypasses. Defenders need to understand how these mitigations work, how they can be circumvented, and what artifacts might indicate an attempted bypass.
- Internal Research and Training: Given the external information drought, organizations defending critical iOS assets should consider investing in internal research capabilities or specialized training (like Lina Lau's course) to develop a deeper understanding of iOS exploitation. This knowledge is crucial for threat hunting, incident response, and designing more resilient applications.
Ultimately, Lau's talk serves as a call to action for defenders: confront the complexity, dive into the assembly, and bridge the knowledge gap to effectively counter the high-value threats targeting iOS devices.
Key Takeaways
- iOS Exploitation is Highly Complex and Opaque: Unlike other platforms, publicly available information, PoCs, and beginner-friendly resources for iOS exploitation are extremely scarce, making it a difficult field to enter and defend against.
- Stack Pivoting is a Critical Technique: To overcome limitations in chaining numerous gadgets on the heap due to iOS's security architecture, stack pivoting is essential. It enables attackers to redirect the stack pointer to a controlled heap region, allowing for extensive ROP/JOP payload execution.
- Assembly and Gadget Chaining are Fundamental: Understanding ARM64 assembly, manipulating registers (especially SP, x29, x30), and meticulously constructing gadget chains (ROP/JOP) using dispatcher gadgets are non-negotiable skills for iOS exploit development.
- High Financial Stakes Drive Secrecy: The immense monetary value of iOS zero-days (up to $2.5M from Zerodium, projected $10M+) creates a strong disincentive for public disclosure, contributing to the field's opaqueness.
- Memory Corruption Dominates iOS Vulnerabilities: The vast majority of in-the-wild iOS zero-days (over 90% in the last 5 years) are memory corruption vulnerabilities, often impacting the heap, making them a primary focus for both attackers and defenders.
- Defenders Need Deep Technical Understanding: To effectively detect and mitigate advanced iOS threats, defenders must overcome the information asymmetry by developing a deep technical understanding of exploitation techniques, including assembly, register manipulation, and how exploit chains are constructed.
About the Speaker(s)
Lina Lau, known online as "inverse," is the founder of XINTRA, a company focused on security research and training. She is a passionate security researcher who describes herself as a "masochist" who enjoys the process of learning complex new topics from scratch. Lau is dedicated to demystifying difficult subjects like iOS exploitation, as evidenced by her detailed technical talk. She also teaches an in-depth course on iOS exploitation, which includes reconstructing real-world exploits, such as the "forced entry" exploit used by the NSO Group. Lina encourages engagement and can be reached on Discord or X (formerly Twitter).