// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Recovery {
//generate tokens
function generateToken(string memory _name, uint256 _initialSupply) public {
new SimpleToken(_name, msg.sender, _initialSupply);
}
}
contract SimpleToken {
string public name;
mapping (address => uint) public balances;
// constructor
constructor(string memory _name, address _creator, uint256 _initialSupply) {
name = _name;
balances[_creator] = _initialSupply;
}
// collect ether in return for tokens
receive() external payable {
balances[msg.sender] = msg.value * 10;
}
// allow transfers of tokens
function transfer(address _to, uint _amount) public {
require(balances[msg.sender] >= _amount);
balances[msg.sender] = balances[msg.sender] - _amount;
balances[_to] = _amount;
}
// clean up after ourselves
function destroy(address payable _to) public {
selfdestruct(_to);
}
}
A contract creator has built a very simple token factory contract. Anyone can create new tokens with ease. After deploying the first token contract, the creator sent 0.001 ether to obtain more tokens. They have since lost the contract address.
This level will be completed if you can recover (or remove) the 0.001 ether from the lost contract address.
이번 문제는 SimpleToken을 이용하여 첫번째 토큰 계약을 배포한 계약자의 주소를 찾고 해당 주소 안에 있는 0.001 ether를 탈취하면 되는 문제이다.
그렇다면 계약자의 주소를 이더스캔을 통하여 찾고 해당 주소 안에 계약으로 구축된 컨트랙트 내부의 destroy 함수를 통하여 나의 EOA 주소로 0.001 ether를 전송하면 문제를 풀 수 있을거 같다.
우선 인스턴스의 주소를 이더스캔에 검색해보도록 하겠다.
Internal Transaction을 살펴보게 된다면 두가지의 트랜잭션을 볼 수 있었다. 맨 아래의 트랜잭션은 인스턴스를 생성하고 배포하는 과정의 트랜잭션이니 무시를 할 것이고 그렇다면 가장 위의 트랜잭션이 초기에 토큰 계약을 체결한 트랜잭션, 즉 우리가 구해야 하는 계약자의 주소가 될 것이다.
그래서 주소를 살펴보면 주소 안에는 0.001 ETH가 있는 것을 알 수 있다.
인터페이스를 상호작용 시킬 수 있도록 구한 주소의 값을 집어넣어준다.
이제 나의 EOA 주소를 인자로 하고 destroy 함수를 호출해준다면 나의 EOA로 0.001 ETH가 들어갈 수 있게된다.
위의 사진처럼 트랜잭션이 체결되고 이렇게 문제를 풀 수 있었다.
🚩
'Write Up > Ethernaut - 블록체인 워게임' 카테고리의 다른 글
Ethernaut - 16단계 (Preservation) (0) | 2023.11.28 |
---|---|
Ethernaut - 15단계 (Naught Coin) (4) | 2023.11.23 |
Ethernaut - 14단계 (Gatekeeper Two) (2) | 2023.11.21 |
Ethernaut - 13단계 (Gatekeeper One) (1) | 2023.11.20 |
Ethernaut - 12단계 (Privacy) (0) | 2023.11.18 |