[Ethernaut] Fal1out

5q1·2025년 2월 26일
// modified from recently, solidity 0.6.0 does not provided from remix.io
// should be change as "solidity over than 0.8.0"
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";

contract Fallout {
  
  using SafeMath for uint256;
  mapping (address => uint) allocations;
  address payable public owner;


  /* constructor */
  function Fal1out() public payable {
    owner = payable(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 {
    payable(msg.sender).transfer(address(this).balance);
  }

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

요구사항은 Owner가 되어야한다고 한다.
그러나 코드를 살펴보면,

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

Fal1out을 호출한다면,,? owenr가 될 수 있다고 한다.

이렇게 간단하게요..?

일단 contract.owner()를 통해, 현재 owner의 지갑주소를 알아보자

확인해보니, 0x0000...000 아무런 값이 들어있지 않은 모습을 확인할 수 있었다.
그럼 Fal1out을 호출하고, 주소를 다시 확인해보면

owner가 된 것을 확인할 수 있었다.


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의 이야기는 Ethereum 생태계에서 매우 잘 알려진 사례입니다. 회사는 이름을 'Dynamic Pyramid'에서 'Rubixi'로 변경했지만 계약의 생성자 메서드 이름을 변경하지 않았습니다.

profile
+82 02 web vulnerability tester

0개의 댓글