ucsb-seclab/greed
GitHub: ucsb-seclab/greed
面向 EVM 智能合约的符号执行引擎,用于深度分析字节码并自动检测逻辑漏洞。
Stars: 118 | Forks: 20
# greed

[](https://www.python.org)

[](https://github.com/ucsb-seclab/greed/actions/workflows/python-app.yml)
[]([https://pypi.org/project/ethpwn/](https://raw.githubusercontent.com/ethpwn/ethpwn/main/LICENSE))
[](https://ucsb-seclab.github.io/greed/)
### ⚡️ 安装
```
# Clone this repo
git clone git@github.com:ucsb-seclab/greed.git
# 创建 virtual environment(例如,使用 virtualenvwrapper)
mkvirtualenv greed
# 激活 virtual environment
workon greed
# 安装 greed(将 setup gigahorse、yices 以及 `pip install -e greed`)
cd greed
./setup.sh
```
### 🚀 使用
首先,合约需要使用 `gigahorse` 进行预处理。这可以通过两种方式完成:
```
# 重要提示:创建一个新文件夹。分析会污染当前工作目录
mkdir /tmp/test_contract
cd /tmp/test_contract/
# 选项 1:从 solidity source
cp contract.sol
analyze_source.sh contract.sol
# 选项 2:从 contract bytecode
cp contract.hex
analyze_hex.sh contract.hex
```
然后,在你的 python 项目中使用 `greed`:
```
from greed import Project
p = Project(target_dir="/tmp/test_contract/")
entry_state = p.factory.entry_state(xid=0)
simgr = p.factory.simgr(entry_state=entry_state)
simgr.run()
```
或者从命令行运行 `greed`:
```
greed /tmp/test_contract [--debug] [--find ]
```
### 🚦 测试
```
cd greed/tests
# 使用 pytest 运行完整测试套件
pytest
# 或者手动运行单个测试
./test_math.py --debug
```
### 🧱 架构
#### 离线表示
* `Project`:调用 TAC_Parser 从 Gigahorse 解析函数、基本块和语句
* `Factory`:用于访问多种对象
* `Function(s)`:包含基本块 + 过程内 CFG
* `Block(s)`:包含语句
* `Statement(s)`:代表 TAC 操作。每个语句都有一个 `.handle(state)` 方法,给定一个状态,应用这些操作以推导其后继状态
#### 运行时表示
* `SimulationManager`:在 "stashes" 中存储和管理状态
* `State(s)`:在每一步持有交易上下文
* `Storage`:模 2^256 的符号存储
* `Memory`:模 2^256 的符号存储
* `Registers`:模 2^256 的符号存储
### 🎓 学术引用
如果你在学术出版物中使用 greed,我们非常感谢引用以下著作:
```
@inproceedings{gritti2023confusum,
title={Confusum contractum: confused deputy vulnerabilities in ethereum smart contracts},
author={Gritti, Fabio and Ruaro, Nicola and McLaughlin, Robert and Bose, Priyanka and Das, Dipanjan and Grishchenko, Ilya and Kruegel, Christopher and Vigna, Giovanni},
booktitle={32nd USENIX Security Symposium (USENIX Security 23)},
pages={1793--1810},
year={2023}
}
@inproceedings{ruaro2024crush,
title={Not your Type! Detecting Storage Collision Vulnerabilities in Ethereum Smart Contracts},
author={Ruaro, Nicola and Gritti, Fabio and McLaughlin, Robert and Grishchenko, Ilya and Kruegel, Christopher and Vigna, Giovanni},
booktitle={Network and Distributed Systems Security (NDSS) Symposium 2024},
year={2024}
}
```
### ⚡️ 安装
```
# Clone this repo
git clone git@github.com:ucsb-seclab/greed.git
# 创建 virtual environment(例如,使用 virtualenvwrapper)
mkvirtualenv greed
# 激活 virtual environment
workon greed
# 安装 greed(将 setup gigahorse、yices 以及 `pip install -e greed`)
cd greed
./setup.sh
```
### 🚀 使用
首先,合约需要使用 `gigahorse` 进行预处理。这可以通过两种方式完成:
```
# 重要提示:创建一个新文件夹。分析会污染当前工作目录
mkdir /tmp/test_contract
cd /tmp/test_contract/
# 选项 1:从 solidity source
cp 标签:DNS 反向解析, EVM, Gigahorse, Python, Wayback Machine, 二进制分析, 云安全监控, 云安全运维, 以太坊, 区块链安全, 反汇编, 可配置连接, 合约验证, 安全规则引擎, 密码管理, 形式化验证, 无后门, 智能合约, 程序分析, 符号执行, 误配置预防, 逆向工具, 静态分析