Ethernaut: 2. 낙진
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import '@openzeppelin/contracts/math/SafeMath.sol';
contract Fallout {
using SafeMath for uint256;
mapping (address => uint) 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 (uint) {
return allocations[allocator];
}
}
constructor 함수 이전에는 컨트랙트와 이름이 같은 함수로 생성자를 사용했습니다. 그러나 만일 생성자 함수의 이름이 다른 경우 공격에 노출될 수 있습니다! 이 경우 이름은 Fallout이지만 함수는 Fal1out로 작성됩니다.이것은 실제로 Rubixi에 발생했습니다. 작성자는 처음에 DynamicPyramid를 계약 이름으로 사용했고 따라서 생성자를 사용했습니다. 나중에 그는 계약 이름만 Rubixi로 변경하고 DynamicPyramid 생성자를 있는 그대로 잊어버렸습니다. 누군가가 결국 잡았습니다.
Reference
이 문제에 관하여(Ethernaut: 2. 낙진), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/erhant/ethernaut-2-fallout-587m텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)