티스토리 뷰

Web3/Wargame

[Ethernaut] Level 2 Fallout 풀이

Namchun 2024. 11. 19. 20:46
Claim ownership of the contract below to complete this level.

  Things that might help
- Solidity Remix IDE

Difficulty: ★☆☆☆☆

아래의 컨트랙트의 소유권을 가져오면 되는 문제이다.

(Remix IDE라는 것이 도움을 줄 수 있을 것이라고 한다)

 

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

import "openzeppelin-contracts-06/math/SafeMath.sol";

contract Fallout {
    using SafeMath for uint256;

    mapping(address => uint256) allocations;
    address payable public owner;

    /* constructor */
    function Fal1out() public payable {
        owner = msg.sender;
        allocations[owner] = msg.value;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "caller is not the owner");
        _;
    }

    function allocate() public payable {
        allocations[msg.sender] = allocations[msg.sender].add(msg.value);
    }

    function sendAllocation(address payable allocator) public {
        require(allocations[allocator] > 0);
        allocator.transfer(allocations[allocator]);
    }

    function collectAllocations() public onlyOwner {
        msg.sender.transfer(address(this).balance);
    }

    function allocatorBalance(address allocator) public view returns (uint256) {
        return allocations[allocator];
    }
}

 

owner를 변경할 수 있는 부분을 살펴보면 Fal1out() public 함수에서 owner를 msg.sender로 그냥 변경해준다. 따라서 Fal1out() 함수를 호출만 한다면 소유권을 빼앗을 수 있을 것이다.

 

함수 호출 트랜잭션을 보내는 방법은 이 전 포스팅에서 확인할 수 있다.

https://namchun.tistory.com/68

 

[Ethernaut] Level 1 Fallback 풀이

Look carefully at the contract's code below.You will beat this level if1. you claim ownership of the contract2. you reduce its balance to 0  Things that might help- How to send ether when interacting with an ABI- How to send ether outside of the ABI- Conv

namchun.tistory.com

 

owner를 성공적으로 변경하였다.

 

문제 보충 설명

That was silly wasn't it? Real world contracts must be much more secure than this and so must it be much harder to hack them right?

Well... Not quite.

The story of Rubixi is a very well known case in the Ethereum ecosystem. The company changed its name from 'Dynamic Pyramid' to 'Rubixi' but somehow they didn't rename the constructor method of its contract:

해석을 해보자면 현실 세계의 컨트랙트들은 이것보다 훨씬 더 안전할 테고, 그렇기에 해킹하기도 훨씬 어려울 것이라 생각하겠지만, Rubixi 이야기는 이더리움 생태계에서 매우 잘 알려진 사례라고 한다.

이 회사는 'Dynamic Pyramid'라는 이름을 'Rubixi'라는 이름으로 변경하면서 아래처럼 생성자 메서드의 이름은 바꾸지 않았다고 한다.

contract Rubixi {
    address private owner; 
    function DynamicPyramid() { owner = msg.sender; } 
    function collectAllFees() { owner.transfer(this.balance) } 
    ...
This allowed the attacker to call the old constructor and claim ownership of the contract, and steal some funds. Yep. Big mistakes can be made in smartcontractland.

이를 통해서 공격자는 이전의 생성자를 호출해서 소유권을 빼앗고 자금을 훔칠 수 있었다고 한다.

'Web3 > Wargame' 카테고리의 다른 글

[Ethernaut] Level 5 Token 풀이  (1) 2024.12.03
[Ethernaut] Level 4 Telephone 풀이  (0) 2024.11.22
[Ethernaut] Level 3 Coin Flip 풀이  (0) 2024.11.19
[Ethernaut] Level 1 Fallback 풀이  (0) 2024.11.19
[Ethernaut] Level 0 Hello Ethernaut 풀이  (0) 2024.11.19
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
글 보관함