Solidity Delegatecall Attack
Solidity’s delegatecall is vulnerable to override the storage values in the caller contract.
Exploitation
Reference: https://github.com/Macmod/ethernaut-writeups/blob/master/4-delegation.md
1. Vulnerable Contract
Below is the example contracts from Ethernaut. That uses delegatecall
method in the fallback()
function.
2. Attack
Call the pwn
function by sending transaction because delegatecall
exists in fallback
function. This changes the owner of the DelegateA contract to msg.sender
because the delegatecall
overrides the slot value in the callee contract (it's DelegateA). In short, we can become the owner of this contract.
Upgradeable Contract Storage Overriding
If the contract is upgradeable using Proxy contract and the slot order is difference, we may be able to manipulate arbitrary slot values with delegatecall.
Last updated