Need help with spectre-attack-sgx?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

215 Stars 50 Forks Apache License 2.0 5 Commits 1 Opened issues


Spectre attack against SGX enclave

Services available


Need anything else?

Contributors list


Sample code demonstrating a Spectre-like attack against an Intel SGX enclave.


Given our ongoing research on Intel SGX here in the LSDS group at Imperial College London, a question that occurred to us immediately on first hearing of the recent Meltdown and Spectre attacks is what are the security implications of speculative execution side channels for Intel SGX enclaves?

This repository contains a proof-of-concept attack (

) showing it is indeed possible to use a speculative execution side-channel to leak data from an Intel SGX enclave.

Attack Outline

The attack is similar conceptually to the conditional branch misprediction Spectre attack of Kocher et al. The main difference is that we move the secret data (

) and the victim function (
) and overflow array (
) inside the enclave. The attacker executes
using an ecall, passing it the index
used to index into

Code Layout

  • SGXSpectre/main/main.c
    : Contains the untrusted code to create the enclave and mount the SGXSpectre attack.
  • SGXSpectre/enclave/enclave_attack.c
    : Contains the enclave secret data and victim function.


  • The attack requires that the

    variable (used to verify that
    is within the bounds of
    ) must not be cached. For simplicity our proof-of-concept currently stores
    outside the enclave, allowing the attacker to flush it with a
    instruction before each invocation of the victim function. In reality this would be unsafe, since the bounds check should not rely on a value stored in untrusted memory. However the attack could be adapted to keep
    inside the enclave by using an alternative mechanism to flush it before each invocation (e.g. load other data whose address coincides in the cache).
  • For simplicity we keep the

    array whose entries are probed by the attacker outside the enclave. As mentioned in the Spectre paper, a prime+probe attack could be used to infer the accesses to
    if it is not accessible to the attacker (e.g. if it is moved inside the enclave).

How to run the code

  1. Install Intel(R) SGX SDK for Linux* OS
  2. Build the SGXSpectre project with the prepared Makefile:
    • Hardware Mode: $ make
    • Simulation Mode: $ make SGX_MODE=SIM
  3. Execute the binary directly: $ ./sgxspectre
  4. Remember to "make clean" before switching build mode


SGXSpectre is brought to you by Dan O'Keeffe, Divya Muthukumaran, Pierre-Louis Aublin, Florian Kelbert, Christian Priebe, Josh Lind, Huanzhou Zhu and Peter Pietzuch.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.