+ All Categories
Home > Documents > The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys...

The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys...

Date post: 22-May-2020
Category:
Upload: others
View: 8 times
Download: 1 times
Share this document with a friend
53
The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum AUGUST 11, 2019
Transcript
Page 1: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

The Ether Wars: Exploits, counter-exploits and

honeypots on EthereumAUGUST 11, 2019

Page 2: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2

About ConsenSys Diligence and MythX

• We audit smart contracts and build security tools for smart contract developers

• Other who contributed to / influenced this talk:○ Joran Honig, Nikhil Parasaram, Nathan Peercy (Mythril Core Team)○ Sam Sun (shared his bot research)○ Many other researchers○ The awesome Ethereum security community

Page 3: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

In this Talk• Fast symbolic execution of EVM bytecode• Exploit automation• Exploiting script kiddies• Exploiting those who try to exploit script kiddies

Page 4: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 4

• Distributed state machine

What is Ethereum?

Page 5: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 5

• Small programs written in a simple, stack-based language• Immutable: Once deployed they can’t be changed• Executing instructions costs gas• Computation in a single transaction is bounded by the block gas limit• However, state can be mutated over multiple transactions

EVM Smart Contracts

Page 6: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 6

Symbolic Execution (1)grantSurvival == True grantSurvival == False

JUMPI

STOP SELFDESTRUCT

CALLDATALOAD

ISZERO

ISZERO

CALLDATALOAD

ISZERO

ISZERO

JUMPI

[]

[0x1]

[0x0]

[0x1]

[]

[]

[0x0]

[0x1]

[0x0]

[]

Page 7: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 7

Symbolic Execution (2)Symbolic Calldata

JUMPI

STOP SELFDESTRUCT

CALLDATALOAD

ISZERO

ISZERO

[]

[sym_calldata]

[bool(sym_calldata == 0)]

[bool(sym_calldata == 0) == 0)]

bool(sym_calldata == 0) == 0) == True bool(sym_calldata == 0) == 0) == False

Page 8: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 8

How to Kill the Cat?Symbolic Calldata

JUMPI

STOP SELFDESTRUCT

CALLDATALOAD

ISZERO

ISZERO

[]

[sym_calldata]

[bool(sym_calldata == 0)]

[bool(sym_calldata == 0) == 0)]

bool(sym_calldata == 0) == 0) == True bool(sym_calldata == 0) == 0) == False

grantSurvival = ((0 == 0) == 0) == True

grantSurvival = (True == False) == True

grantSurvival = False

Page 9: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 9

Further Reading● Introduction to Mythril and Symbolic Execution (Joran Honig)

○ https://medium.com/@joran.honig/introduction-to-mythril-classic-and-symbolic-execution-ef59339f259b

● Smashing Smart Contracts○ https://github.com/b-mueller/smashing-smart-contracts

● teether: Gnawing at Ethereum to Automatically Exploit Smart Contracts (J. Krupp, C. Rossow)○ https://www.usenix.org/system/files/conference/usenixsecurity18/s

ec18-krupp.pdf

Page 10: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Mythril Basic Usage$ pip install mythril

$ myth analyze <solidity_file>[:contract_name]

$ myth analyze -a <address>

Page 11: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 11

Demo 1

Page 12: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 12

Demo 1

Page 13: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Mythril CLI Args$ myth -v4 analyze -t4 --execution-timeout 3600 <solidity_file>

Exhaustively execute 4 transactions

Terminate after 1 hour and return results

Verbose output

Page 14: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Demo 2• Level 1 of the Ethernaut Challenge• To practice smart contract

hacking check out these awesomepages:

https://ethernaut.openzeppelin.comhttps://capturetheether.comhttps://blockchain-ctf.securityinnovation.com/

Page 15: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Demo 2

Page 16: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Over-approximation vs. concrete state variables

Page 17: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

State Space Explosion Problem

Page 18: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Mythril Pruning Algorithms• Prune unreachable paths given concrete initial state• Prune pure functions (STOP state == initial state)• Dynamic pruning. Execute a path only if:○ It is newly discovered○ A state variable that was modified in the previous transaction is read

somewhere along the path○ Somewhere along this path, a state variable is written to that we know

is being read elsewhere

teEther uses a similar method: https://www.usenix.org/node/217465

Page 19: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Page 20: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Pruning EffectivenessFully execute 63 samples from the smart contract weakness registryhttps://smartcontractsecurity.github.io/SWC-registry/

Base Prune Pure Funcs Dynamic Pruning Speedup1 TX 297s N/A N/A N/A2 TX 2,346s 1,919s 1,152s 103.5%3 TX 9,943s 6,072s 2,242s 343.49%4 TX too long 13,312s 7,440s > 400%

Page 21: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Other Optimizations (WIP)• Parallelisation• State merging○ Merge path constraints and world state by disjunction (c1 v c2)

• Function summaries ○ Store constraints imposed on state when executing paths (“summary”)○ In subsequent runs, apply summary via conjunction instead of re-executing

the same code• FastSMT• (...)

Page 22: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Scrooge McEtherface (1)• Transform Mythril issues into runnable exploits

Page 23: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Scrooge McEtherface (2)Payload wrapper○ Hides the transactions from frontrunning bots○ Allows to revert everything if the attack fails

Page 24: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Scrooge McEtherface

DEMO!

https://github.com/b-mueller/scrooge-mcetherface

Page 25: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Early retirement unlocked?

Page 26: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum

Page 27: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 27

• Security Engineer at ConsenSys Diligence• ~2 years in the blockchain space• Developer with a hacker’s heart• @CleanUnicorn

Daniel Luca

Page 28: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 28

• Karl• Scanning the blockchain• Finding vulnerable contracts• Validate found exploits

• Theo• Transaction pool• Frontrunning transactions

Main Points

Page 29: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 29

Page 30: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 30

Karl

Page 31: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 31

Scanning the Blockchain• Understand Ethereum• Python• JSON RPC• Lots of computational resources• Lots of time

Page 32: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 32

Page 33: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 33

Get Block By Number

Page 34: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 34

Get Transaction Receipt

Page 35: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 35

Page 36: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 36

Page 37: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 37

Page 38: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 38

Page 39: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 39

#100 #101 #102

Contract

#101 #102

RealSandbox

Page 40: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 40

• Needs to have a payable method• Selfdestruct to it• Mine as the coinbase

Add Ether to a Contract

Page 41: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 41

Theo

Page 42: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 42

Page 43: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 43

Page 44: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 44

Mempool

MempoolMempool

Mempool

MempoolMempool Mempool

Transaction #1A2B

Transaction #1A2B

Transaction #1A2B

Transaction #1A2B

Page 45: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 45

● gasPrice * gas = Transaction fee● Sorted descendingly by gasPrice

Transaction Ordering

Page 46: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 46

Page 47: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 47

Frontrunning Demo

Page 48: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 48

Does This Work in the Wild?

Page 49: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 49

Does this work in the Wild? wild?

Page 50: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 50

The Victim’s Transaction

Page 51: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 51

Theo’s Transaction

Page 52: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 52

• Proxy contract• Miner adds the transaction without being in the mem pool first• Transactions are more specific (signing a key with my account)• Ethereum client decides to be unresponsive

When does it fail?

Page 53: The Ether Wars: Exploits, counter-exploits and honeypots ... CON 27/DEF CON 27... · ConsenSys Diligence | The Ether Wars: Exploits, counter-exploits and honeypots on Ethereum 2 About

Thank You!Q&A


Recommended