This repository demonstrates a proof-of-concept attack leveraging a Spectre-like vulnerability to steal a secret key of homomorphic encryption (HE) from an Intel SGX enclave. This work extends the SGXSpectre
attack originally developed by Dan O'Keeffe, Divya Muthukumaran, Pierre-Louis Aublin, Florian Kelbert, Christian Priebe, Josh Lind, Huanzhou Zhu, and Peter Pietzuch.
In this project, we explore the security implications of speculative execution side channels for Intel SGX enclaves, specifically focusing on the HE-secret keys stealing. Our proof-of-concept attack shows that it is possible to extract sensitive data, such as secret keys, from within an SGX enclave using speculative execution side channels.
The attack builds on the concepts of the conditional branch misprediction Spectre attack by Kocher et al. Our implementation relocates the secret key and the victim function inside the enclave, while the attacker code remains outside the enclave. The attacker code executes the victim function via ecalls, using speculative execution to leak the secret key.
main/main.cpp
: Contains the untrusted code responsible for creating the enclave and mounting the SGXSpectre attack.enclave/enclave_attack.c
: Contains the enclave's secret key and the victim function.
- The
array1_size
variable used to verify the bounds of the indexx
must not be cached. In this proof-of-concept,array1_size
is stored outside the enclave, allowing the attacker to flush it before each invocation of the victim function. For a secure implementation, this value should be stored within the enclave. - The
array2
array, probed by the attacker, is kept outside the enclave for simplicity. As noted in the Spectre paper, a prime+probe attack could be used to infer accesses toarray2
if it were inside the enclave.
- CPU: Intel Core i7-8700
- g++==9.4.0
- SGXdriver==2.11
- SGXSDK==2.24.100.3
- SEAL==4.1.1
- OS: Ubuntu 20.04
- kernel: 5.15.0-113-generic
- Install the Intel(R) SGX SDK for Linux* OS.
- Install Microsoft SEAL (version 4.1.1)
- Get the original SGXSpectre code
git submodule init git submodule update
- Copy the original SGXSpectre code and apply our patch
cp -r spectre-attack-sgx/SGXSpectre src patch -p1 -d src < change.diff
- Make the program
cd src make PREFIX_FOR_SEAL=${HOME}/.local
PREFIX_FOR_SEAL
is set to the path to the directory where Microsoft SEAL is installed (the path is the same as the value of-DMAKE_INSTALL_PREFIX
option for building Microsoft SEAL.)- Use
SGX_MODE=SIM
formake
to execute the program with simulation mode. - Clean the build before switching modes by
make clean
- Configure key size:
- Modify the values of
N
andLEN
inutils.hpp
inmain
directory andenclave_attack.c
inenclave
directory. - Copy
parms
,secret_key
, andciphertext
in the corresponding directory, such as64KiB
, to the current directory.
- Modify the values of
- Execute the binary directly
./sgxspectre
This project is based on the original SGXSpectre
attack by Dan O'Keeffe, Divya Muthukumaran, Pierre-Louis Aublin, Florian Kelbert, Christian Priebe, Josh Lind, Huanzhou Zhu, and Peter Pietzuch from the LSDS group at Imperial College London.