Coder Social home page Coder Social logo

mustakimur / coin-attacks Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 12.0 134.79 MB

COIN Attacks: on Insecurity of Enclave Untrusted Interfaces in SGX - ASPLOS 2020

Home Page: https://dl.acm.org/doi/abs/10.1145/3373376.3378486

License: GNU General Public License v3.0

CMake 0.35% C++ 46.48% CSS 0.02% JavaScript 0.02% Python 1.57% Emacs Lisp 0.01% C 12.23% Batchfile 0.01% Objective-C 0.73% Objective-C++ 0.19% HTML 0.36% MATLAB 0.01% Cuda 0.11% Forth 0.01% Mercury 0.01% LLVM 27.17% Assembly 10.75% Rust 0.01% M 0.01% Cool 0.01%
sgx-sdk intel-sgx triton symbolic-execution

coin-attacks's Introduction

COIN ATTACKS [ASPLOS 2020]

IMPORTANT: Licensing

This project is licensed in GPLv3 with the following additional conditions:

  1. If you plan to benchmark, compare, evaluate this project with intention to publish the results (including in a paper), you must contact us with your real identity, affiliation, and advisors, and a short description of how you will use our source code before using and/or downloading this project. In addition, you will provide an opportunity for us to comment on and help with technical and other issues related to this project you have during the development. Examples include but are not limited to failure to compile or incomplete protection.

  2. If you use any part of this project (excluding third-party software) and published a paper about it, you agree to open-source your project within one month of the official paper publication.

If you do not agree to these conditions, please do not use our source code.

Justfication: this is a research prototype. Its sole purpose is to demonstrate that the original idea works. It is expected to have implementation flaws. We welcome efforts to re-produce/evaluate our results but request an opportunity to fix implementation flaws. Generally speaking, we value design flaws more but will try to fix implementation issues. If you plan to use this project in production, we would love to hear about it and provide help if needed.

COIN attacks demonstrates the weakness in SGX enclave software model. We define three attacks in the enclave interface:

  • (C)oncurrent ECALLs
  • (O)rder of ECALLs
  • (In)put manipulation

We have developed an extensible framework to independently analyze an enclave on the presence of COIN attacks. Our prototype have implemented 8 security policies that could detect:

  • Heap memory leak
  • Stack memory leak
  • Ineffectual condition
  • Use-after-free
  • Double free
  • Stack overflow
  • Heap overflow
  • Null pointer dereference

The paper will be appeared in the ASPLOS 2020 conference. This repository is for the framework source code.

Prototype

The prototype is built for following system:

  • Intel x86-64 machine (64GB memory)
  • Linux Distribution (preferably 4.15.0)
  • Intel SGX SDK

Note: It is not required to use a real Intel SGX machine.

Source

COIN Attack
|
|--src
      |
      |--semantics
                  |
                  |--llvm_src
                             |
                             |--llvm/lib/Transforms/EnclaveSemantics/EnclaveSemantics.cpp
                  |
                  |--pyedl
                          |
                          |--edlParse.py
      |
      |--core
             |
             |--Triton/src/enclaveCoverage/coverage.py
             |
             |--Triton/src/enclaveCoverage/policies.py
|
|--scripts
          |
          |--PoCs
          |
          |--SGX_SQLite
|
|--PoCs
       |
       |--df_enclave
       |
       |--hl_enclave
       |
       |--ho_enclave
       |
       |--ie_enclave
       |
       |--nd_enclave
       |
       |--sl_enclave
       |
       |--so_enclave
       |
       |--uaf_enclave

Build

export PROJECT_ROOT=path_to_repository_head

LLVM Tool

  1. Install required library for Gold plugin:
sudo apt-get install linux-headers-$(uname -r) csh gawk automake libtool bison flex libncurses5-dev
# Check 'makeinfo -v'. If 'makeinfo' does not exist
sudo apt-get install apt-file texinfo texi2html
sudo apt-file update
sudo apt-file search makeinfo
  1. Download binutils source code:
cd ~
git clone --depth 1 git://sourceware.org/git/binutils-gdb.git binutils
  1. Build binutils:
mkdir build
cd build
../binutils/configure --enable-gold --enable-plugins --disable-werror
make
  1. Build the compiler (use the binutils directory if you already have one):
cd $PROJECT_ROOT/src/semantics/llvm_src/
mkdir build
cd build
cmake -DLLVM_ENABLE_PROJECTS=clang -DLLVM_BINUTILS_INCDIR="path_to_binutils/include" -G "Unix Makefiles" ../llvm
make -j8
  1. Backup ar, nm, ld and ranlib:
cd ~
mkdir backup
cd /usr/bin/
cp ar ~/backup/
cp nm ~/backup/
cp ld ~/backup/
cp ranlib ~/backup/
  1. Replace ar, nm, ld and ranlib:
cd /usr/bin/
sudo cp ~/build/binutils/ar ./
sudo rm nm
sudo cp ~/build/binutils/nm-new ./nm
sudo cp ~/build/binutils/ranlib ./
sudo cp ~/build/gold/ld-new ./ld
  1. Install LLVMgold.so to /usr/lib/bfd-plugins:
cd /usr/lib
sudo mkdir bfd-plugins
cd bfd-plugins
sudo cp $PROJECT_ROOT/src/semantics/llvm_src/build/lib/LLVMgold.so ./
sudo cp $PROJECT_ROOT/src/semantics/llvm_src/build/lib/libLTO.* ./

Triton

Pre-requisite:

sudo apt-get install python-pip libcapstone-dev libboost-all-dev libz3-dev
  1. Python LIEF library install.
sudo pip install lief==0.9.0
  1. Build z3 solver from the source:
cd $PROJECT_ROOT/src/core/
git clone https://github.com/Z3Prover/z3.git
cd z3
python scripts/mk_make.py
cd build
make
sudo make install
  1. Build the Triton symbolic engine.
cd $PROJECT_ROOT/src/core/Triton
mkdir build
cd build
cmake ..
sudo make -j2 install

SGX SDK

Install the Intel SGX SDK (into /opt/intel/sgxsdk/) following the guideline: https://github.com/intel/linux-sgx

Usage

export PROJECT_ROOT=path_to_repository_head

There are scripts available to run PoCs and GitHub projects into the system. For example, to test SGX_SQLite projects, use:

cd $PROJECT_ROOT/scripts/SGX_SQLite/
./run.sh

Note: Source codes are unmodified but Makefiles to build the projects with CLang/LLVM.

Screenshots

Note: Some part of this project was developed while I was intern at Baidu X-lab.

coin-attacks's People

Contributors

mustakimur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

coin-attacks's Issues

potential defect in the oob detection policy implementation

I wonder if the oob detection policy wasn't implemented as expected.

In the policy implementation, it is considered that either oob or uaf would be detected if the accessed memory region in heap isn't in certain allocated memory region in heap (which is recorded and the information is maintained in heap_map). While the implementation detects oob using alloc_start and alloc_end, which was assigned by the last iteration of the previous for loop, so the memory access is considered to be an oob case, only comparing memory boundaries with the last entry in heap_map. I wonder if an iteration was forgotten here.

see relevant code below

if (addr_start >= BASE_ALLOC
and addr_end < BASE_ALLOC + current_heap_alloc - 0x1):
isFlagged = True
alloc_start = 0
alloc_end = 0
for alloc_mem, alloc_size in heap_map.iteritems():
alloc_start = alloc_mem
alloc_end = alloc_mem + alloc_size - 0x1
if (addr_start >= alloc_start and addr_start <= alloc_end
and addr_end >= alloc_start
and addr_end <= alloc_end):
isFlagged = False
if (isFlagged):
msg = ""
if (addr_start >= alloc_start and addr_start <= alloc_end
and addr_end > alloc_end):
msg = '[ERROR] Potential Out of Bound (OOB) at ' + hex(
inst.getAddress()) + ': ' + inst.getDisassembly(
) + '\nTry to use memory at ' + hex(
addr_start) + ' - ' + hex(
addr_end
) + '\nAllocated Memory range is ' + hex(
alloc_start) + ' - ' + hex(
alloc_end) + '\n'
else:
for st_alloc_mem, st_alloc_info in heap_story.iteritems(
):
st_alloc_start = st_alloc_mem
st_alloc_end = st_alloc_mem + st_alloc_info[1]
if (addr_start >= st_alloc_start
and addr_start <= st_alloc_end
and addr_end >= st_alloc_start
and addr_end <= st_alloc_end):
msg = '[UAF-REPORT] Potential Use-after-free (UAF) at ' + hex(
inst.getAddress()
) + ': ' + inst.getDisassembly(
) + '\nTry to use memory at ' + hex(
addr_start) + ' - ' + hex(
addr_end
) + '\nAllocated memory range is ' + hex(
st_alloc_start) + ' - ' + hex(
st_alloc_end
) + '\nAllocated memory at ' + hex(
st_alloc_info[0]
) + ' and Freed at ' + hex(
st_alloc_info[2]) + '\n'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.