TL;DR
This paper demonstrates the first practical enclave malware that can fully and stealthily impersonate its host application. By leveraging new TSX-based primitives for memory probing and code injection, the authors bypass SGX's security guarantees, enabling attacks like data theft, encryption for ransom, and even system-level command execution. This work highlights a significant security threat posed by SGX, potentially facilitating advanced "super-malware."
What Problem Does This Paper Address?
Intel SGX (Software Guard Extensions) offers hardware-based enclaves to protect sensitive code and data from even privileged software, including the operating system. This technology is advertised for use cases like trusted cloud computing, DRM, and secure storage of credentials. However, a key assumption in SGX's threat model is that enclaves themselves are fully trusted. This paper questions the realism of this assumption, exploring whether malicious enclaves could harm the host system. While prior work has discussed potential threats, practical demonstrations of enclave malware that can attack a non-colluding host application have been lacking, partly due to perceived limitations of enclaves (e.g., inability to directly issue system calls). This paper aims to bridge this gap by demonstrating a practical and stealthy enclave malware that overcomes these limitations.
Methods
The core of the attack, dubbed SGX-ROP, involves several novel techniques:
- TSX-based Memory Probing (TAP): This primitive uses Intel Transactional Synchronization Extensions (TSX) to determine if a virtual address is accessible by the current process without triggering exceptions that would crash the enclave. It exploits TSX's ability to catch memory access faults internally, allowing the enclave to probe memory safely.
- TSX-based Writable Memory Detection (CLAW): Building on TAP, CLAW uses TSX to identify writable memory locations ("data caves"). It attempts a write operation within a TSX transaction and then explicitly aborts it. By analyzing the TSX abort reason, it can distinguish between read-only and writable pages without leaving any trace of the write.
- SGX-ROP Attack: This is a code-reuse attack (ROP) mounted from within an SGX enclave. It involves:
- Gadget Discovery: Using TAP to scan the host application's memory for ROP gadgets (small code snippets ending in a
retinstruction). - Data Cave Injection: Using CLAW to find writable memory pages and inject arbitrary malicious payloads (like shellcode or a ROP chain) into these "data caves."
- ROP Chain Construction: Assembling a ROP chain from discovered gadgets.
- Control Flow Hijacking: Injecting the ROP chain onto the host application's stack, diverting execution to it. The attack also employs a "stealthy fake stack frame" technique to ensure the original control flow can be restored after the attack, maintaining stealth.
This approach allows the enclave to bypass SGX's restrictions on direct system calls and privileged operations by leveraging the host application's capabilities through the ROP chain.
Datasets
Not discussed in the paper. The authors evaluate their techniques on real-world applications and libraries, rather than specific datasets.
Key Insights and Ideas
- SGX's Asymmetric Protection is a Weakness: While SGX protects enclaves from the host, it doesn't protect the host from the enclave. This asymmetry is the fundamental vulnerability exploited by SGX-ROP.
- TSX is a Powerful Primitive for Enclave Attacks: The authors demonstrate that TSX, often discussed for security benefits, can be repurposed for sophisticated attacks by enclaves, particularly for stealthy memory probing and manipulation.
- Enclaves Can Escape Their Sandbox: Contrary to the belief that enclaves are severely limited and cannot directly harm the system, SGX-ROP shows that they can effectively gain arbitrary code execution on the host.
- ROP Defenses are Bypassed: SGX-ROP effectively bypasses common defenses like ASLR, stack canaries, and even advanced CFI policies, as it doesn't rely on traditional memory safety violations.
- "Super-Malware" is Feasible: The techniques presented could enable highly sophisticated malware that is difficult to detect and analyze, potentially leading to a new class of "super-malware."
Key Results
- Practical SGX-ROP Attack: The authors successfully demonstrated a full exploit that, on average, takes only 20.8 seconds to execute. This exploit involves a benign application hosting a malicious enclave that finds and injects code into a data cave, then hijacks control flow to execute a ROP chain.
- Bypassed Defenses: The SGX-ROP attack successfully bypassed ASLR, stack canaries, and address sanitizers.
- Efficient Memory Scanning: TAP and CLAW are shown to be very fast, with TAP achieving a probing rate of 48.5 GB/s and locating all pages of an application within 73.5 ms on average.
- Abundant Data Caves and Gadgets: The evaluation on Graphene-SGX and the Intel SGX SDK revealed a significant number of data caves (16594 found in Graphene-SGX) and readily available ROP gadgets, making SGX-ROP feasible in practice.
- Novel Egg Hunter: TAP can be used as a highly efficient and compact egg hunter for traditional exploits, significantly outperforming existing syscall-based methods.
Limitations and Future Work
- Hardware Bug Assumption: The attack assumes no exploitation of potential hardware bugs in the SGX implementation (e.g., CVE-2017-5691).
- Untrusted Enclave Vendor: The attack relies on the possibility of a malicious third-party enclave being embedded in a legitimate application.
- Future Work: The authors suggest future research should focus on more realistic trust relationships between enclaves and non-enclave software, as well as developing robust mitigations against enclave malware. They also call for a better understanding of the threat model concerning untrusted enclaves.
Summary updated