Ghidra-Evm in the last few years, attacks on deployed smart contracts in the Ethereum blockchain have ended up in a significant amount of stolen funds due to programming mistakes. Since smart contracts, once compiled and deployed, are complex to modify and update different practitioners have suggested the importance of reviewing their security in the blockchain where only Ethereum Virtual Machine (EVM) bytecode is available. In this respect, reverse engineering through disassemble and de-compilation can be effective.
ghidra-EVM is a Ghidra module for reverse engineering smart contracts. It can be used to download Ethereum Virtual Machine (EVM) bytecode from the Ethereum blockchain and disassemble and decompile the smart contract. Further, it can analyze creation code, find contract methods and locate insecure instructions.
It comprises a processor module, custom loader and plugin(s) that disassembles Ethereum VM (EVM) bytecode and generates a control-flow graph (CFG) of a smart contract.
The last version uses the Ghidra 9.1.2 API. It relies on the crytic evm_cfg_builder library (https://github.com/crytic/evm_cfg_builder) to assist Ghidra in the CFG generation process.
Ghidra-evm consists of:
Script | Description |
---|---|
search_codecopy.py | When analyzing creation code in a smart contract we can only see the _dispatcher function that uses CODECOPY in order to write the run time code into memory. This script looks for useful CODECOPY instructions and finds the smart contract methods hidden in the runtime part of the contract. |
search_dangerous_instructions.py | Instructions such as CALL, CALLCODE, SELFDESTRUCT and DELEGATECALL can sometimed be abused to transfer funds to another contract. This script finds them and creates afor each occurrence. |
load_external_contract.py | Downloads smart contract byte code from the blockchain into a .evm_h file that can be loaded into ghidra-evm |
Installation Instructions
Compilation Instructions
The contents of the ghidra-evm directory can be used to create a Ghidra module in Eclipse with processor and loader in order to extend or debug ghidra_evm.
Tutorials
Tutorial | Description |
---|---|
Utilization | Simple utilization instructions with test.evm |
Analyzing creation bytecode | Using search_codecopy.py to analyze creation code and finding hidden methods |
Looking for dangerous instructions | Using search_dangerous_instructions.py to analyze a SELFDESTRUCT ocurrence |
Downloading smart contract bytecode from the blockchain into Ghidra | Using load_external_contract.py to download EVM byte code from the blockchain into a .evm_h file |
Integration With External Symbolic Execution Tools
Script | Description |
---|---|
teether | It marks the critical path in Ghidra before generating the exploit. Requires teether. |
Notes
shadow-rs is a Windows kernel rootkit written in Rust, demonstrating advanced techniques for kernel manipulation…
Extract and execute a PE embedded within a PNG file using an LNK file. The…
Embark on the journey of becoming a certified Red Team professional with our definitive guide.…
This repository contains proof of concept exploits for CVE-2024-5836 and CVE-2024-6778, which are vulnerabilities within…
This took me like 4 days (+2 days for an update), but I got it…
MaLDAPtive is a framework for LDAP SearchFilter parsing, obfuscation, deobfuscation and detection. Its foundation is…