
Ferramenta de análise de segurança para módulo WebAssembly (wasm) e Contratos Inteligentes de Blockchain (BTC/ETH/NEO/EOS)
Muitos agradecimentos à QuoScient por ter patrocinado este projeto.
Octopus é um framework de análise de segurança para módulos WebAssembly e Smart Contracts de Blockchain.
O objetivo do Octopus é fornecer uma maneira fácil de analisar módulos WebAssembly de código fechado e bytecode de smart contracts para compreender mais profundamente seus comportamentos internos.
Octopus suporta os seguintes tipos de programas/smart contracts:
| BTC | ETH (EVM) | ETH (WASM) | EOS | NEO | WASM | ||
|---|---|---|---|---|---|---|---|
| Explorer | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ⭕ | |
| Disassembler | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | |
| Control Flow Analysis | ✖️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | |
| Call Flow Analysis | ✖️ | ➕ | ✔️ | ✔️ | ➕ | ✔️ | |
| IR conversion (SSA) | ✖️ | ✔️ | ➕ | ➕ | ✖️ | ✔️ | |
| Symbolic Execution | ✖️ | ➕ | ➕ | ➕ | ✖️ | ➕ |
✔️ DONE / ➕ WIP / ✖️ TODO / ⭕ N/A
Octopus é suportado em Linux (idealmente Ubuntu 16.04) e requer Python >=3.5 (idealmente 3.6).
Dependências:
sudo apt-get update && sudo apt-get install python-pip graphviz xdg-utils -y
- Instalar o Octopus:```
# Download Octopus
git clone https://github.com/pventuzelo/octopus
cd octopus
# Install Octopus library/CLI and its dependencies
python3 setup.py install
ou```
pip3 install octopus
- Executar testes```
# Run tests for all platforms (disassembly, CFG, ...)
./run_tests.sh
# Run tests that require internet access (explorer tests)
./run_explorer_tests.sh
# Run tests for only one platforms
# {btc, eth, eos, neo, wasm}_run_tests.sh
cd octopus/tests/
./wasm_run_tests.sh
Um contêiner Docker que fornece o conjunto de ferramentas está disponível em docker hub. Em um terminal, execute os seguintes comandos:``` docker pull smartbugs/octopus docker run -it smartbugs/octopus cd octopus python3 octopus_eth_evm.py -s -f examples/ETH/evm_bytecode/61EDCDf5bb737ADffE5043706e7C5bb1f1a56eEA.bytecode
## Ferramentas de linha de comando
* WebAssembly: [octopus_wasm.py](https://github.com/fuzzinglabs/octopus/blob/master/octopus_wasm.py)
* Ethereum (EVM): [octopus_eth_evm.py](https://github.com/fuzzinglabs/octopus/blob/master/octopus_eth_evm.py)
## Exemplos detalhados usando APIs
<details><summary>WebAssembly</summary>
<p>
#### Desmontador
Desmontagem de um módulo Wasm:```python
from octopus.arch.wasm.disassembler import WasmDisassembler
FILE = "examples/wasm/samples/helloworld.wasm"
with open(FILE, 'rb') as f:
module_bytecode = f.read()
disasm = WasmDisassembler()
# return list of functions instructions (list)
print(disasm.disassemble_module(module_bytecode))
#[[<octopus.arch.wasm.instruction.WasmInstruction at 0x7f85e4904278>,<octopus.arch.wasm.instruction.WasmInstruction at 0x7f85e4904f60>,<octopus.arch.wasm.instruction.WasmInstruction at 0x7f85e4904ef0>]]
print()
# return text of functions code
print(disasm.disassemble_module(module_bytecode, r_format='text'))
# func 0
# i32.const 0
# call 0
# end
Desmontagem do bytecode wasm:```python from octopus.arch.wasm.disassembler import WasmDisassembler
bytecode = b'\x02\x7fA\x18\x10\x1cA\x00\x0f\x0b'
disasm = WasmDisassembler(bytecode)
print(disasm.disassemble())
#[<octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4904eb8>, <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4904278>, <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4904390>, <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4904ef0>, <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4904f60>, <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4901048>] print() print(disasm.disassemble(r_format='reverse'))
#{0: <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4901048>, 1: <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4904240>, 2: <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4904f60>, 3: <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4904ef0>, 4: <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4904278>, 5: <octopus.arch.wasm.instruction.WasmInstruction object at 0x7f85e4904390>} print() print(disasm.disassemble(r_format='text'))
#### ModuleAnalyzer```python
from octopus.arch.wasm.analyzer import WasmModuleAnalyzer
FILE = "examples/wasm/samples/hello_wasm_studio.wasm"
with open(FILE, 'rb') as f:
module_bytecode = f.read()
# return list of functions instructions (list)
# attributes analysis=True by default
analyzer = WasmModuleAnalyzer(module_bytecode)